/** C Source **************************************************************** * * NAME * ucosping.c * * DESCRIPTION * Rabbit TCP/IP and uC-OS II PING demo program. * * When the program is running on the target, you should be able to * ping it. * * Set your IP address and netmask etc. in the tcp_config() statements * in main(). * * TARGET * ZWorld TCP/IP Development Kit Rabbit board * OR * Rabbitcore modules with ethernet. * * TOOLS * ZWorld Dynamic C 7.05P * * Editor tab stop = 4. Tabs converted to spaces. * * REVISION LOG * yyyy mmm dd Who Ver. Description * 2001 Sep 25 ssk 1.00 Created. * 2001 Sep 27 ssk 1.01 tcp_listen() added to avoid socket lock. * mainTask() added for demo. * 2001 Oct 24 ssk 1.02 OSInit() called before sockinit() to fix crashing. * Tasks now have void* pointer. * 2001 Nov 08 ssk 1.03 #define DISABLE_DNS added because of DNS.LIB bug. * ***************************************************************************** * The software contained in this file is released to the public domain * July 2001 by Scot Kornak, Calgary, Alberta, Canada . * * This is unsupported software and it is provided without warranty. * It may be freely used and modified for private or commercial applications. * If you modify it, I encourage you to publicly release the modified version. *****************************************************************************/ /** OS Configuration ********************************************************/ /* Redefine uC/OS-II configuration constants as necessary */ #define OS_MAX_EVENTS 10 /* Maximum number of events (semaphores, queues, mailboxes) */ #define OS_MAX_TASKS 10 /* Maximum number of tasks system can create (less stat and idle tasks) */ #define OS_MAX_QS 0 /* Maximum number of queues in system */ #define OS_MAX_MEM_PART 0 /* Maximum number of memory partions in system */ #define OS_TASK_CREATE_EN 1 /* Enable normal task creation */ #define OS_TASK_CREATE_EXT_EN 0 /* Disable extended task creation */ #define OS_TASK_DEL_EN 0 /* Disable task deletion */ #define OS_TASK_STAT_EN 0 /* Disable statistics task creation */ #define OS_Q_EN 0 /* Disable queue usage */ #define OS_MEM_EN 0 /* Disable memory manager */ #define OS_MBOX_EN 1 /* Enable mailboxes */ #define OS_SEM_EN 1 /* Enable semaphores */ #define OS_TICKS_PER_SEC 64 /* # of ticks in one second */ #define STACK_CNT_256 1 /* # 256 byte stacks (idle task) */ #define STACK_CNT_512 11 /* # 512 byte stacks (initial program + most tasks + statistics) */ #define STACK_CNT_1K 0 /* # 1K stacks */ #define STACK_CNT_2K 0 /* # 2K stacks */ #define STACK_CNT_4K 1 /* # 4K stacks (tcpTickTask) */ #define DISABLE_DNS /* Disable DNS because of bug in DNS.LIB in Dynamic C 7.05P. See YAHOO Rabbit Semi Group Message 1937. If DNS.LIB is required, download a newer version from the YAHOO group files section. */ /** Include Files ***********************************************************/ #use "ucos2.lib" /* uC-OS II RTOS */ /* Define dummy IP address to avoid DCRTCP.LIB warnings */ #define MY_IP_ADDRESS "172.16.10.xx" #define MY_NETMASK "255.255.0.0" #define MAX_TCP_SOCKET_BUFFERS (1) /* Specify number of TCP stacks used */ #use "dcrtcp.lib" /** Local Constants and types ***********************************************/ #define TCP_PORT 80 /** Local Variable Declarations *********************************************/ /** Function Prototypes *****************************************************/ void main( void ); void mainTask( void *taskData ); void tcpTickTask( void *taskData ); /** Functions ***************************************************************/ #memmap xmem /** Function **************************************************************** * * NAME * main - Main routine for program. * * DESCRIPTION * Initialize system and start tasks. * * The USE_UCOSII define determines whether the tcp_tick occurs in * a uC-OS task or whether tcpTickTask() is simply called without task * switching. * * INPUTS None. * * OUTPUTS * None, does not exit. * * HISTORY * yyyy mmm dd Who Description * 2001 Sep 25 ssk Created. * 2001 Oct 24 ssk OSInit() called before sockinit() to fix crashing. ****************************************************************************/ void main( void ) { OSInit(); /* Initialize uC/OS-II, must be before sockinit() */ sock_init(); tcp_config( MY_IP, "172.16.10.31" ); tcp_config( NETMASK, "255.255.0.0" ); tcp_config( NAMESERVER, "172.16.0.1" ); tcp_config( GATEWAY, "139.142.15.2" ); /* Note: the OSTaskCreate() description in the uC/OS-II book is different than the UCOS2.LIB implementation. The book version takes a pointer to the stack and the Rabbit .LIB version takes the stack size instead. */ OSTaskCreate( mainTask, /* Task subroutine */ (void *)0, /* Data to task subroutine, not used */ 512, /* Task stack size */ 10 ); /* Task priority (low # = high priority). Each task has a unique priority in the range 4 to 59 (0 to 3 and 60 to 63 are reserved by uC/OS, see the uC/OS-II book page 317). */ OSTaskCreate( tcpTickTask, /* Task subroutine */ (void *)0, /* Data to task subroutine, not used */ 4096, /* Task stack size */ 20 ); /* Task priority (low # = high priority) */ OSStart(); /* Start uC-OS II task switching */ } /** Function **************************************************************** * * NAME * mainTask() - main program task. * * DESCRIPTION * This routine loops and simply yields to lower priority tasks every OS * tick. * * INPUTS * None. * *taskData not used. * * OUTPUTS * None, does not exit. * * HISTORY * yyyy mmm dd Who Description * 2001 sep 17 ssk Created. * 2001 Oct 24 ssk Now accepts void* taskData parameter. *****************************************************************************/ void mainTask( void *taskData ) { while( 1 ) { /* Task code */ /* Let lower priority tasks run */ OSTimeDly( 1 ); } } /** Function **************************************************************** * * NAME * tcpTickTask() - TCP/IP main loop. * * DESCRIPTION * This routine loops and calls the TCP/IP state-machine tcp_tick(). * * This task is the lowest priority task. Higher priority tasks * must yield control with OSTimeDly() when they are idle to give this * task time to run. * * INPUTS * None. * *taskData not used. * * OUTPUTS * None, does not exit. * * HISTORY * yyyy mmm dd Who Description * 2001 sep 17 ssk Created. * 2001 Sep 27 ssk tcp_listen() added to avoid socket lock. * 2001 Oct 24 ssk Now accepts void* taskData parameter. *****************************************************************************/ #define USE_NULL 0 void tcpTickTask( void *taskData ) { /* To respond to PINGs, one can either open a socket and use tcp_tick() with that socket or just call tcp_tick( NULL ). The USE_NULL parameter selects one or the other. */ #if !USE_NULL static tcp_Socket tcpSocket; tcp_listen( &tcpSocket, /* Socket to use */ TCP_PORT, /* Port to listen on */ 0, /* Remote host IP to accept, 0 = all */ 0, /* Remote port to accept, 0 = all */ NULL, /* Ptr to signal handler fn for close/reset */ 0 ); /* Reserved for future */ while( 1 ) { tcp_tick( &tcpSocket ); OSTimeDly( 1 ); /* Optional since this is the lowest priority task */ } #else while( 1 ) { tcp_tick( NULL ); OSTimeDly( 1 ); /* Optional since this is the lowest priority task */ } #endif } /* EOF */