📄 netmain.c
字号:
/* * FILENAME: netmain.c * * Copyright 1998- 2004 By InterNiche Technologies Inc. All rights reserved * * Main file for the Generic Multitasking systems port of * NicheTask Operating System * * MODULE: MISCLIB * * ROUTINES: netmain(), num_net_tasks(), * ROUTINES: ...and all the "tk_xxx" application tasks * * * PORTABLE: yes */#define IN_NETMAIN_C 1 /* some ipport.h ports need to know this */#include "license.h"#include "ipport.h"#ifdef NTF/* * Task Information for sample applications */extern task * to_task1;TK_OBJECT(to_task1);TK_ENTRY(tk_task1);long task1_wakes = 0;extern task * to_task2;TK_OBJECT(to_task2);TK_ENTRY(tk_task2);long task2_wakes = 0;#endif /* NTF *//* Multitasking systems should use these functions, however superloop *systems need to be able to ifdef it away */#ifdef NTFunsigned NDEBUG = 0; /* Debugging...*/#endif /* NTF */#ifdef OSPORT_H#include OSPORT_H#else
#error Need to define OSPORT_H
#endif/* various entry points */extern void netmain_init(void); /* initialize all modules */extern int create_apptasks(void);extern int prep_modules(void);void inet_timer(void);
extern int net_system_exit; /* TRUE if system is shutting down */
#ifndef TK_RETURN_UNREACHABLE#define TK_RETURN_UNREACHABLE() TK_RETURN_OK()#endif#ifndef APP_STACK_SIZE#define APP_STACK_SIZE 4096 /* default on the large side */#endif#ifndef SYS_SHORT_SLEEP#define SYS_SHORT_SLEEP 1#endif/* Define thread prototypes. */#ifndef NO_INET_STACKTK_OBJECT(to_netmain);TK_ENTRY(tk_netmain);long netmain_wakes = 0;#endif /* NO_INET_STACK */#ifndef NO_INET_TICK
TK_OBJECT(to_nettick);TK_ENTRY(tk_nettick);long nettick_wakes = 0;#endif /* NO_INET_TICK */struct inet_taskinfo nettasks[] = {#ifndef NO_INET_STACK { &to_netmain, /* netmain should always be first in this array */ "Inet main", tk_netmain, NET_PRIORITY, NET_STACK_SIZE, },#endif /* NO_INET_STACK */#ifndef NO_INET_TICK { &to_nettick, "clock tick", tk_nettick, NET_PRIORITY, CLOCK_STACK_SIZE, },#endif /* NO_INET_TICK */#ifdef NTF { &to_task1, "task1", tk_task1, NET_PRIORITY - 1, IO_STACK_SIZE, }, { &to_task2, "task2", tk_task2, NET_PRIORITY - 1, IO_STACK_SIZE, }# endif /* NTF */};int num_net_tasks = sizeof(nettasks)/sizeof(struct inet_taskinfo);int iniche_net_ready = FALSE;/* FUNCTION: netmain() * * PARAM1: * * RETURNS: */intnetmain(void){ int i; int e; iniche_net_ready = FALSE; e = prep_modules(); /* Create the threads for net, timer, and apps */ for (i = 0; i < num_net_tasks; i++) { e = TK_NEWTASK(&nettasks[i]); if (e != 0) { dprintf("task create error\n"); panic("netmain"); return -1; /* compiler warnings */ } } e = create_apptasks(); if (e != 0) { dprintf("task create error\n"); panic("netmain"); return -1; /* compiler warnings */ }#ifdef MAIN_TASK_IS_NET tk_netmain(TK_NETMAINPARM); panic("net task return"); return -1;#else
return 0;#endif}/* FUNCTION: tk_netmain() * * Main thread for starting the net. After startup, it settles into * a loop handling received packets. This loop sleeps until a packet * has been queued in rcvdq; at which time it should be awakend by the * driver which queued the packet. * * PARAM1: n/a * * RETURNS: n/a */#ifndef NO_INET_STACKTK_ENTRY(tk_netmain){ netmain_init(); /* initialize all modules */ iniche_net_ready = TRUE; /* let the other threads spin */ for (;;) {#ifdef NTF tk_block();#else TK_NETRX_BLOCK();#endif /* NTF */ netmain_wakes++; /* count wakeups */ } TK_RETURN_UNREACHABLE(); USE_ARG(parm);}#endif /* NO_INET_STACK *//* FUNCTION: tk_nettick * * PARAM1: n/a * * RETURNS: n/a */#ifdef DHCP_CLIENTextern int dhc_second(void);#endif#ifndef NO_INET_TICKTK_ENTRY(tk_nettick){ /* wait till the stack is initialized */ while (!iniche_net_ready) { /* The DHCP Client state machine might need some cycles * at this point. This is needed when we start by sending a * request and then we receive a NAK. At this point the DHCP * client is reset to INIT state and dhc_second() needs to be * run to restart it. */#ifdef DHCP_CLIENT dhc_second();#endif TK_SLEEP(1); } for (;;) { TK_SLEEP(SYS_SHORT_SLEEP); nettick_wakes++; /* count wakeups */ inet_timer(); /* let various timeouts occur */ /* do not kill timers on net_system_exit. They may be * vital to a clean shutdown */ } TK_RETURN_UNREACHABLE(); USE_ARG(parm);}#endif /* NO_INET_TICK */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -