📄 exec.c
字号:
//--------------------------------------------------------------------------
// Ip Stack
//--------------------------------------------------------------------------
// EXEC.C
//
// Dispatch Executive
//
// Author: Michael A. Denio
// Copyright 1999 by Texas Instruments Inc.
//-------------------------------------------------------------------------
#include <stkmain.h>
// Configuration Structure
IPCONFIG _ipcfg = { DEF_ICMP_DO_REDIRECT,
DEF_ICMP_TTL,
DEF_ICMP_TTL_ECHO,
DEF_IP_INDEX,
DEF_IP_FORWARDING,
DEF_IP_NATENABLE,
DEF_IP_FILTERENABLE,
DEF_IP_REASM_MAXTIME,
DEF_IP_REASM_MAXSIZE,
DEF_RTC_ENABLE_DEBUG,
DEF_RTC_RTADV_TIME,
DEF_RTC_RTADV_LIFE,
DEF_RTC_RTADV_PREF,
DEF_LLI_ARP_DOWN_TIME,
DEF_LLI_KEEPALIVE_TIMEOUT,
DEF_ROUTE_CLONE_TIMEOUT,
DEF_ROUTE_DEFAULT_MTU,
DEF_SOCK_TTL_DEFAULT,
DEF_SOCK_TOS_DEFAULT,
DEF_SOCK_MAXCONNECT,
DEF_SOCK_TIMECONNECT,
DEF_SOCK_TIMEIO,
DEF_SOCK_BUFMAX,
DEF_SOCK_BUFMINTX,
DEF_SOCK_BUFMINRX,
DEF_PIPE_TIMEIO,
DEF_PIPE_BUFSIZE,
DEF_PIPE_BUFMINTX,
DEF_PIPE_BUFMINRX
};
// Task Structure
typedef struct {
void (*pHandler)( uint );
uint TaskId; // Task ID
} TASK;
#define NUM_TASKS ID_LAST
void LLIMsg( uint );
void RouteMsg( uint );
void NatMsg( uint );
void IPMsg( uint );
void TcpMsg( uint );
void RTCMsg( uint );
static TASK tasks[NUM_TASKS] = {
{ &LLIMsg, ID_LLI },
{ &IPMsg, ID_IP },
{ &RouteMsg, ID_ROUTE },
{ &NatMsg, ID_NAT },
{ &TcpMsg, ID_TCP },
{ &RTCMsg, ID_RTC } };
// Exec Status Codes
#define ES_CLOSED 0
#define ES_READY 1
#define ES_OPEN 2
static uint ExecStatus = ES_CLOSED;
// Broadcast Message Flags
// When set, Exec will broadcast related message with static resources
static uint fCritRes = 0;
static void ExecBroadcast( uint Msg );
//--------------------------------------------------------------------
// ExecOpen()
//
// Prepare for execution
//--------------------------------------------------------------------
void ExecOpen()
{
if( ExecStatus != ES_CLOSED )
{
DbgPrintf(DBG_ERROR,"ExecStart: Already Open");
return;
}
// Clear any stray flags
fCritRes = 0;
// Mark exec status as started
ExecStatus = ES_READY;
// Init the Task List
ExecBroadcast( MSG_EXEC_SYSTEM_INIT );
// Init the device Index/Handle mapping
IFInit();
// Mark exec status as open
ExecStatus = ES_OPEN;
}
//--------------------------------------------------------------------
// ExecClose()
//
// Shutdown the system
//--------------------------------------------------------------------
void ExecClose()
{
SockPcbCleanup();
ExecBroadcast( MSG_EXEC_SYSTEM_SHUTDOWN );
ExecStatus = ES_CLOSED;
}
//--------------------------------------------------------------------
// ExecEvent()
//
// Process New Events
//--------------------------------------------------------------------
int ExecEvent( uint llFlags )
{
if( ExecStatus != ES_OPEN )
{
DbgPrintf(DBG_ERROR,"ExecEvent: Not Open");
return(-1);
}
// Check for packet event
if( llFlags & EXEC_EVENT_PACKET )
llPacketService();
// Check for timer event
if( llFlags & EXEC_EVENT_TIMER )
TimerHSTick();
// Check for message broadcast condition
// Resource condition
if( fCritRes )
{
ExecBroadcast( MSG_EXEC_LOW_RESOURCES );
SockPcbCleanup();
fCritRes = 0;
}
return( 1 );
}
//--------------------------------------------------------------------
// ExecHRef()
//
// References a handle, adding to the reference count
//--------------------------------------------------------------------
void ExecHRef( HANDLE h )
{
HDATA* ph = (HDATA *)h;
#ifdef _STRONG_CHECKING
if( !(ph->Type & HTYPE_FLAG_REFSUPPORT) )
{
DbgPrintf(DBG_ERROR,"ExecHRef: HTYPE %04x",ph->Type);
return;
}
#endif
// Standard Ref
if( ph->RefCount != 65535 )
ph->RefCount++;
}
//--------------------------------------------------------------------
// ExecLowResource()
//
// Serious resource problem!
//--------------------------------------------------------------------
void ExecLowResource()
{
// This is a problem, but there's not much we can do. Some tasks
// like IP and TCP may be holding an inordinate amount of resources,
// so we notify everyone of the problem, and they should free up
// all but essential memory.
// The resource message is handled via a broadcast flag since it is
// very important that all tasks get the message.
fCritRes = 1;
}
//--------------------------------------------------------------------
// ExecBroadcast()
//
// Call every task in the Task List with the supplied message value,
// using the system static message.
//--------------------------------------------------------------------
static void ExecBroadcast( uint Msg )
{
int tmp1;
// Notify the Task List with broadcast message
for( tmp1=1; tmp1<=NUM_TASKS; tmp1++ )
(*tasks[tmp1-1].pHandler)(Msg);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -