NIC Driver Outline
The basic driver outline below lists all of the main routines required for a NIC driver under RT-TCP/IP.
The DrvXmitThread routine is optional in some drivers, depending on implementation. If the driver requires that a packet be completed (transmitted) before the next packet is handed to the RtndTransmit routine, then a transmit thread which calls RtnTransmitDone after the transmit done interrupt will be required. RtnTransmitDone cannot be called from the transmit interrupt itself, since it will likely to invoke a deadlock between critical sections.
Example: RtxTcpIp Driver functions
#include "drvutl.h"
// Force the export of RTNDPROC functions
#define RTNDPROC __declspec ( dllexport )
#include "Rt3c905.h"
#include <stdio.h>
#include <stdlib.h>
int
RtndInitialize (
short* StackIniFile,
char* pszSectionName,
int fDisplayErrorMessages,
char *DeviceName,
RtndConfigStruct *RtCfg )
{
// local configuration structure…
}
int
RtndConfigure (
void *ndp )
{
// Initialize NIC card. Start Receive thread and optionally
// start transmit thread…
}
int
RtndUpDown (
void *ndp,
unsigned short flags,
char *options )
{
// Bring a NIC card online and attach interrupt vector,
// or bring NIC down and release interrupt vector
//depending on flags parameter….
}
int
RtndIoctl (
void *ndp,
int cmd,
char *addr )
{
// Perform Device IO Control.
//Used primarily to add or delete multicast groups.
}
int
RtndTransmit (
void *mp )
{
// Transmit a packet (or start transmit) via the NIC
}
static
ULONG
WINAPI
DrvRecvThread (
DRVDEV* pCardInfo )
{
// Process Received Packets. Notified by interrupt thread when
// a packet has been received for (;;)
{
WaitForSingleObject (pCardInfo->hRecvEvent, INFINITE);
// pulls packets from card and queues them
drv_RecvPackets (pCardInfo);
// process the queued packets
RtnProcessRecvQueue (pCardInfo->ndp);
}
}
static
ULONG
WINAPI
DrvTransThread(
DRVDEV* pCardInfo )
{
// Post Process Transmitted Packets.
//Notified by interrupt thread when a packet transmit is done.
// This code calls RtnTransmitDone to free the most recently
//transmitted packet and to start the next packet transmit,
//if there is one.
for (;;)
{
WaitForSingleObject (pCardInfo->hTransEvent, INFINITE);
while (pCardInfo->XmitCount > 0)
{
RtnTransmitDone (pCardInfo->ndp);
pCardInfo->XmitCount--;
}// while
}// for
}
static
void
WINAPI
DrvISR(
DRVDEV* pCardInfo )
{
// Interrupt Service Thread for driver. If a transmit or receive
// interrupt fires, then signal the waiting transmit or
// receive thread.
// Do NOT call RtnTransmitDone from this routine.
// If Transmit Interrupt then do the following:
SetEvent(pCardInfo->hTransEvent);
// If Receive Interrupt then do the following:
SetEvent(pCardInfo->hRecvEvent);
}
See Also
RtndInitialize
RtndConfigure
RtndUpDown
RtndIoctl
RtndTransmit
DrvISR