📄 client.c
字号:
/*
* Copyright 2006 by Texas Instruments Incorporated.
* All rights reserved. Property of Texas Instruments Incorporated.
* Restricted rights to use, duplicate or disclose this code are
* granted through contract.
*
* @(#) TCP/IP_Network_Developers_Kit 1.91.00.08 08-22-2006 (ndk-a08)
*/
//--------------------------------------------------------------------------
// IP Stack Test Program
//--------------------------------------------------------------------------
// Router.c
//
// Multi-port Router Test
//
// This code initializes the router and the default router tasks.
//
// Author: Michael A. Denio
// Copyright 1999, 2000 by Texas Instruments Inc.
//-------------------------------------------------------------------------
#include <stdio.h>
#include <netmain.h>
#include <_stack.h>
#include <csl.h>
#include "client.h"
#include "../../../tools/common/console/console.h"
#include "../../../tools/common/servers/servers.h"
//---------------------------------------------------------------------------
// Version String
//
char *VerStr = "\nTCP/IP Stack Example HDLC Serial Client\n";
//---------------------------------------------------------------------------
// Configuration
//
static char *HostName = "user";
static void NetworkOpen();
static void NetworkClose();
static void NetworkIPAddr( IPN IPAddr, uint IfIdx, uint fAdd );
static void ServiceReport( uint Item, uint Status, uint Report, HANDLE h );
//---------------------------------------------------------------------
// Main Entry Point
//---------------------------------------------------------------------
int main()
{}
void client_init()
{
CSL_init();
}
//
// Main Thread
//
int StackTest()
{
int rc;
HANDLE hCfg;
CI_SERVICE_TELNET telnet;
//
// THIS MUST BE THE ABSOLUTE FIRST THING DONE IN AN APPLICATION!!
//
rc = NC_SystemOpen( NC_PRIORITY_LOW, NC_OPMODE_INTERRUPT );
if( rc )
{
printf("NC_SystemOpen Failed (%d)\n",rc);
for(;;);
}
// Print a banner
printf(VerStr);
// Enable the EDMA interrupt - since the EDMA interrupt
// is configurable, this one line of code has no home.
//
// NOTE: This code is not required for DM642, nor any
// driver environment that does not use EMDA sharing.
// However, it doesn't hurt to turn it on.
C62_enableIER( 1<<8 );
//
// Create and build the system configuration from scratch.
//
// Create a new configuration
hCfg = CfgNew();
if( !hCfg )
{
printf("Unable to create configuration\n");
goto main_exit;
}
// We better validate the length of the supplied names
if( strlen( HostName ) >= CFG_HOSTNAME_MAX )
{
printf("Names too long\n");
goto main_exit;
}
// Add our global hostname to hCfg (to be claimed in all connected domains)
CfgAddEntry( hCfg, CFGTAG_SYSINFO, CFGITEM_DHCP_HOSTNAME, 0,
strlen(HostName), (UINT8 *)HostName, 0 );
// Specify TELNET service for our Console example
bzero( &telnet, sizeof(telnet) );
telnet.cisargs.IPAddr = INADDR_ANY;
telnet.cisargs.pCbSrv = &ServiceReport;
telnet.param.MaxCon = 2;
telnet.param.Callback = &ConsoleOpen;
CfgAddEntry( hCfg, CFGTAG_SERVICE, CFGITEM_SERVICE_TELNET, 0,
sizeof(telnet), (UINT8 *)&telnet, 0 );
//
// Configure IPStack/OS Options
//
// We don't want to see debug messages less than WARNINGS
rc = DBG_WARN;
CfgAddEntry( hCfg, CFGTAG_OS, CFGITEM_OS_DBGPRINTLEVEL,
CFG_ADDMODE_UNIQUE, sizeof(uint), (UINT8 *)&rc, 0 );
//
// Boot the system using this configuration
//
// We keep booting until the function returns 0. This allows
// us to have a "reboot" command.
//
do
{
rc = NC_NetStart( hCfg, NetworkOpen, NetworkClose, NetworkIPAddr );
} while( rc > 0 );
// Delete Configuration
CfgFree( hCfg );
// Close the OS
main_exit:
NC_SystemClose();
return(0);
}
//
// System Task Code
//
static HANDLE hEcho=0,hData=0,hNull=0,hOob=0;
static HANDLE hIo=0;
//
// NetworkOpen
//
// This function is called after the configuration has booted
//
static void NetworkOpen()
{
// Create our local servers
hEcho = TaskCreate( echosrv, "EchoSrv", OS_TASKPRINORM, 0x1400, 0, 0, 0 );
hData = TaskCreate( datasrv, "DataSrv", OS_TASKPRINORM, 0x1400, 0, 0, 0 );
hNull = TaskCreate( nullsrv, "NullSrv", OS_TASKPRINORM, 0x1400, 0, 0, 0 );
hOob = TaskCreate( oobsrv, "OobSrv", OS_TASKPRINORM, 0x1000, 0, 0, 0 );
hIo = TaskCreate( sctrl, "SerialCtrl", OS_TASKPRINORM, 0x1000, 0, 0, 0 );
}
//
// NetworkClose
//
// This function is called when the network is shutting down,
// or when it no longer has any IP addresses assigned to it.
//
static void NetworkClose()
{
// Close the serial port operation
sctrlAbort();
fdCloseSession( hIo );
fdCloseSession( hOob );
fdCloseSession( hNull );
fdCloseSession( hData );
fdCloseSession( hEcho );
// Kill any active console
ConsoleClose();
// If we opened NETCTRL as NC_PRIORITY_HIGH, we can't
// kill our task threads until we've given them the
// opportunity to shutdown. We do this by manually
// setting our task priority to NC_PRIORITY_LOW.
TaskSetPri( TaskSelf(), NC_PRIORITY_LOW );
TaskDestroy( hIo );
TaskDestroy( hOob );
TaskDestroy( hNull );
TaskDestroy( hData );
TaskDestroy( hEcho );
}
//
// NetworkIPAddr
//
// This function is called whenever an IP address binding is
// added or removed from the system.
//
static void NetworkIPAddr( IPN IPAddr, uint IfIdx, uint fAdd )
{
IPN IPTmp;
if( fAdd )
printf("Network Added: ");
else
printf("Network Removed: ");
// Print a message
IPTmp = ntohl( IPAddr );
printf("If-%d:%d.%d.%d.%d\n", IfIdx,
(UINT8)(IPTmp>>24)&0xFF, (UINT8)(IPTmp>>16)&0xFF,
(UINT8)(IPTmp>>8)&0xFF, (UINT8)IPTmp&0xFF );
}
//
// Service Status Reports
//
// Here's a quick example of using service status updates
//
static char *TaskName[] = { "Telnet","HTTP","NAT","DHCPS","DHCPC","DNS" };
static char *ReportStr[] = { "","Running","Updated","Complete","Fault" };
static char *StatusStr[] = { "Disabled","Waiting","IPTerm","Failed","Enabled" };
static void ServiceReport( uint Item, uint Status, uint Report, HANDLE h )
{
printf( "Service Status: %-9s: %-9s: %-9s: %03d\n",
TaskName[Item-1], StatusStr[Status],
ReportStr[Report/256], Report&0xFF );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -