📄 targ300.c
字号:
/* FILENAME: targ300.c
*
* Copyright 2002 InterNiche Technologies Inc. All rights reserved.
*
* Target board support routines for InterNiche TCP/IP.
* This one for Samsung SNDS300 board running NicheTask.
*
* PORTABLE: no
*/
#include "ipport.h"
#include "memwrap.h"
#include "nvparms.h"
#include "osport.h"
#ifdef USE_PPP
#include "comline.h"
#include "ppp_port.h"
#include "../mppp/mppp.h"
extern int (*ppp_type_callback)(LINEP);
int ppp_setup_callback(LINEP line);
#ifdef USE_MODEM
#include "../modem/mdmport.h"
#include "../modem/modem.h"
#endif /* USE_MODEM */
#endif /* USE_PPP */
#include "zprint.h"
extern void initkb(void);
unsigned long cticks = 0; /* master tick counter */
unsigned int memtrapsize = 0;
extern void panic(char *);
void sams_nv_defaults(void);
char static_heap[HEAP_SIZE];
extern char * name;
extern char * prompt;
extern int (*port_prep)(int);
/* Static net structs, so we can patch in IP address. */
extern struct net netstatic[STATIC_NETS];
#ifdef USE_AUTOIP
/* Auto IP vars so we can patch in a sane address pool */
extern u_long dBASE_AUTO_IP_ADDRESS;
extern u_long dMAX_AUTO_IP_ADDRESS;
#endif
void
samsung_setup( void )
{
/* init keyboard */
initkb();
/* set up heap we'll be using for net. See memory map on pg 3.2
* of the data book.
*/
mheap_init((char*)static_heap, (long)HEAP_SIZE);
/* set up Interniche NV parameters */
/* bypass NV system for now, fix later -JB- */
sams_nv_defaults(); /* set Samsung port callback */
#ifdef USE_AUTOIP
/* Auto IP spec says to use network 169.254.0.0; and that's what
* the code in ../autoip4 does. In reality it's a lot more useful
* to use a 10 net, so set this up here:
*/
dBASE_AUTO_IP_ADDRESS = 0x0A000100; /* 10.0.1.0 */
dMAX_AUTO_IP_ADDRESS = 0x0AFEFEFF; /* 10.254.254.255 */
#endif
/* preset buffer counts; may overwrite from command line */
bigbufs = 5; /* 5; */
lilbufs = 25; /* 25; */
bigbufsiz = 1536;
lilbufsiz = 128;
/* port_prep = snds300_prep;*/
port_prep = prep_ppp;
return;
}
#if 0 /* #if 0 */
/* Port_prep() routine callback for Samsung board */
int
snds300_prep(int index)
{
int new_index;
new_index = ethers3c_prep(index);
if(new_index == index)
return index;
#ifdef USE_PPP
index = prep_ppp(new_index);
return index;
#else
return new_index;
#endif
}
#endif /* #if 0 */
/* yaxon add */
void ErrPrint(char *errinf);
void InitErrUART(void);
/*void
dtrap()*/ /* (yaxon modify) */
void
dtrap(char *inf)
{
/*InitErrUART();
ErrPrint("\n");
ErrPrint("dtrap\n");
ErrPrint(inf);
ErrPrint("dtrap\n");
ErrPrint("\n");
netexit(0);*/
Printu("\r\ndtrap%s\r\ndtrap\r\n", inf);
netexit(0);
}
void
ENTER_CRIT_SECTION(void * p)
{
p = p;
OSSchedLock();
}
void
EXIT_CRIT_SECTION(void * p)
{
p = p;
OSSchedUnlock();
}
#ifdef INICHE_TASKS
int crit_nesting = 0; /* number of nested crit section calls */
u_long crit_mask = 0; /* int mask at entry to first crit section */
extern int inside_ISR;
void
ENTER_CRIT_SECTION(void * p)
{
u_long mask; /* local copy of mask on entry */
mask = INTMASK; /* save mask on entry to prevent race condition */
INTMASK |= GLOBAL_INT; /* disable all interrupts (global bit) */
/* if this is the first call, then save the original int mask */
if(crit_nesting++ == 0)
crit_mask = mask;
return;
}
void
EXIT_CRIT_SECTION(void * p)
{
if(--crit_nesting == 0)
{
INTMASK = crit_mask;
}
}
#endif /* INICHE_TASKS */
/* FUNCTION: npalloc()
*
* PARAM1: unsigned size
*
* RETURNS:
*/
char *
npalloc(unsigned size)
{
char * ptr; /* pointer to return to caller */
#ifdef MEM_WRAPPERS
ptr = wrap_alloc(size, calloc1);
#else
ptr = calloc1(size);
#endif
if (ptr) /* zero memory before returning */
MEMSET(ptr, 0, size);
return ptr;
}
/* FUNCTION: npfree()
*
* PARAM1: void * ptr
*
* RETURNS:
*/
void
npfree(void * ptr)
{
#ifdef MEM_WRAPPERS
wrap_free((char*)ptr, mem_free);
#else
mem_free(ptr);
#endif
}
void
exit_os(unsigned short code)
{
//dprintf("exit called with code %d \n", code);
// ResetCPU();
Printu("exit called with code %d \n", code);
for(;;) ;
}
void
sams_nv_defaults(void)
{
#ifdef INCLUDE_NVPARMS /* INCLUDE_NVPARMS */
int iface = 0;
/* store default IP info */
/* Ethernet */
inet_nvparms.ifs[iface].ipaddr = htonl(0x0A00000E); /* 10.0.0.14 */
inet_nvparms.ifs[iface].subnet = htonl(0xFFFF0000);
inet_nvparms.ifs[iface].gateway = htonl(0);
#ifdef DHCP_CLIENT
inet_nvparms.ifs[iface].client_dhcp = TRUE;
#else
inet_nvparms.ifs[iface].client_dhcp = FALSE;
#endif
dprintf("nv_defaults: set net %d IP to %u.%u.%u.%u\n",
iface, PUSH_IPADDR(inet_nvparms.ifs[iface].ipaddr) );
iface++; /* done with first iface, move on.... */
/* PPP */
#ifdef USE_PPP
inet_nvparms.ifs[iface].ipaddr = htonl(0x0);
inet_nvparms.ifs[iface].subnet = htonl(0xFFFFFF00);
inet_nvparms.ifs[iface].gateway = htonl(0xCC9C8001); /* 204.156.128.1 */
inet_nvparms.ifs[iface].client_dhcp = FALSE;
iface++;
#ifdef USE_PPPOE
inet_nvparms.ifs[iface].ipaddr = htonl(0x0A64000E); /* 10.100.0.14 */
inet_nvparms.ifs[iface].subnet = htonl(0xFFFF0000);
inet_nvparms.ifs[iface].gateway = htonl(0x0A640076); /* 10.100.0.118 */
inet_nvparms.ifs[iface].client_dhcp = FALSE;
iface++;
#endif /* USE_PPPOE */
ppp_nvparms.line_tmo = 300;
ppp_nvparms.ppp_ConsoleLog = 0; /* Log Modem & PPP events to console */
ppp_nvparms.ppp_FileLog = 0; /* Log Modem & PPP events to file */
ppp_nvparms.ppp_keepalive = 0; /* seconds between PPP echos, 0=disable */
ppp_nvparms.ppp_client_tmo = 500; /* timeout for connects as client */
strcpy(ppp_nvparms.username, "ch/iniche.com");
strcpy(ppp_nvparms.password, "07336");
#ifdef PPP_VJC
ppp_nvparms.ppp_request_vj = 1; /* request that the other side do VJ compression */
#endif /* PPP_VJC */
#ifdef PAP_SUPPORT
ppp_nvparms.require_pap = 0;
#endif /* PAP_SUPPORT */
#endif /* USE_PPP */
/* loopback */
inet_nvparms.ifs[iface].ipaddr = htonl(0x7f000001);
inet_nvparms.ifs[iface].subnet = htonl(0xFF000000);
inet_nvparms.ifs[iface].gateway = htonl(0);
inet_nvparms.ifs[iface].client_dhcp = FALSE;
#ifdef USE_MODEM
strcpy(modem_nvparms.dial_phone, "4900610\n");
strcpy(modem_nvparms.modem_init, "AT&D2&C1\n");
// strcpy(modem_nvparms.loginfile, logfilename);
// strcpy(modem_nvparms.logservefile, srvfilename);
#endif /* USE_MODEM */
#ifdef USE_COMPORT
comport_nvparms.LineProtocol = 1;
comport_nvparms.comport = '2';
#endif /* USE_COMPORT */
#ifdef NATRT
natrt_nvparms.nat_enabled = 1;
natrt_nvparms.nat_inet = 1;
natrt_nvparms.nat_localnet = 0;
natrt_nvparms.tcp_timeout = 300;
natrt_nvparms.udp_timeout = 500;
/* create the required NAT NV file */
nv_fopen("natdb.nv", "w+");
/* more here later? */
#endif /* NATRT */
#endif /* INCLUDE_NVPARMS */
return;
}
#ifndef SUPERLOOP
#include "osport.h"
extern int (*port_prep)(int);
extern char * name;
/* hardware setup called form main before anything else (e.g.
before tasks, printf, memory alloc, etc.
Return NULL if OK, else brief error message
*/
/*extern u_long tcp_sendspace;*/ /* ?????? */
/*extern u_long tcp_recvspace;*/
char *
pre_task_setup()
{
/* since we have lot of buffers, open up the TCP windows. */
/* tcp_sendspace = 1024*32;*/
/* tcp_recvspace = 1024*16;*/
#ifdef USE_PPP
/* Install the InterNiche PPP callback hooks */
ppp_default_type = LN_PORTSET; /* indicate port needs callback */
ppp_type_callback = ppp_setup_callback; /* install callback */
#ifdef USE_PPPOE
ppp_static = 2; /* 1 modem and 1 PPPoE */
#else
ppp_static = 1; /* 1 modem only */
#endif /* USE_PPPOE */
#endif /* USE_PPP */
return NULL;
}
/* More setup called after tasks are set up
Return NULL if OK, else brief error message
*/
char *
post_task_setup()
{
#ifdef USE_PPPOE
/* add an IP route so the 10.100.0.X PPPoE packets go out the right net.
* If we use a system with real IP addresses (instead of all 10 net)
* then this is not required; but for testing it makes life easier.
*/
add_route(nets[2]->n_ipaddr, 0xFFFF0000, nets[2]->n_ipaddr, 2, IPRP_OTHER);
#endif /* USE_PPPOE */
#ifdef MINI_TCP
#ifdef WEBPORT
http_init();
#endif /* WEBPORT */
#ifdef FTP_SERVER
ftps_init();
#endif /* FTP_SERVER */
#endif /* MINI_TCP */
return NULL;
}
#endif /* SUPERLOOP */
#ifdef USE_PROFILER
/* high-granularity tick return for InterNiche profiler */
u_long last_t0; /* last value read from t0 in get_ptick */
u_long last_ctick; /* cticks during last call to get_pticks */
u_long getpt_calls = 0;
u_long getpt_wraps = 0;
#define T0_MASK ~((TIMER0_VALUE) + (TIMER0_VALUE - 1)) /* 0100 -> FE00 */
u_long
get_ptick()
{
u_long t0; /* value read from timer 0 reg */
u_long timeval;
getpt_calls++; /* count calls, maybe remove later */
/* get value remaining in 32bit "countdown" timer */
t0 = TCNT0;
timeval = TIMER0_VALUE - t0;
ENTER_CRIT_SECTION(&cticks);
/* If counter wrapped and cticks didn't increment yet, then adjust
* for this.
*/
if(t0 > last_t0)
{
if(last_ctick == cticks)
{
getpt_wraps++;
timeval += TIMER0_VALUE;
}
last_ctick = cticks;
}
last_t0 = t0;
/* Since this timer wraps to zero each time it increments cticks,
* add the lower bits of cticks to the upper timer bits
*/
timeval += (cticks * TIMER0_VALUE);
/* OK for cticks to change now */
EXIT_CRIT_SECTION(&cticks);
return timeval;
}
#endif /* USE_PROFILER */
#if 0 /* #if 0 */
/* Alloce a non-chaced buffer for snds. Buffers in the free queues need to
* come from this to ensure that data for ethernet sends is not cached
* when the ethernet tried to send it.
*
* Syntax is identical to npalloc();
*/
char *
snds_alloc(unsigned size)
{
char * buf;
/* get a regular buffer from the heap */
buf = npalloc(size);
if(buf == NULL)
return NULL;
/* Got a good buffer, set the "no cache" bit and return it. The rest of the
* code can just write to this address normally and the data will not be
* cached.
*/
return (char*)((u_long)buf | 0x04000000);
}
/* snds_free() - unused */
#ifdef NOTDEF
void
snds_free(void * ptr)
{
npfree((void*)((u_long)ptr & ~0x04000000));
}
#endif /* NOTDEF */
#endif /* #if 0 */
#ifdef USE_PPP
/* The PPP Type callback routine. This is used for PPP system
* configuration in complaex systems like this one) which can use
* PPPoE or map modems to non-zero uarts. See PPp code and manual
* for a full explanation.
*/
int pppset_calls = 0;
#ifdef USE_PPPOE
extern int ifmap_bind(NET, NET);
#endif
int
ppp_setup_callback(LINEP line)
{
pppset_calls++;
/* On Samsung snds300 board,
* we map PPP sessions first to UART 1 w/modem (if USE_MODEM defined),
* then PPPoE (if USE_PPPOE defined)
*/
#ifdef USE_MODEM
#define MODEM_CALL 1
#ifdef USE_PPPOE
#define PPPOE_CALL 2
#endif
#else
#ifdef USE_PPPOE
#define PPPOE_CALL 1
#endif
#endif
#ifdef USE_MODEM
if(pppset_calls == MODEM_CALL)
{
int unit = 0; /* Hardcode unit to SIO-1 for now */
/* int unit = 1; Hardcode unit to SIO-1 for now */
/* set type as MODEM and map modem to unit */
line->lower_type = LN_ATMODEM; /* set PPP line type */
line->lower_unit = unit; /* set ppp line unit number */
/* Setting the modem line pointer allows us to use a non-zero
* modem unit, but we need to do basic initialization of the
* modem structure as well.
*/
MEMSET(&modems[unit], 0, sizeof (struct atmodem));
modems[unit].upperline = line; /* set modem backpointer */
return 0; /* done w/PPP modem setup */
}
#endif
#ifdef USE_PPPOE
if(pppset_calls == PPPOE_CALL) /* call is to be mapped to PPPoE link */
{
M_PPP mppp;
line->lower_type = LN_PPPOE;
/* bind PPP iface for this line (upper) to ethernet (nets[0]) */
mppp = (M_PPP)(line->upper_unit);
ifmap_bind(mppp->ifp, nets[0]);
return 0;
}
#endif /* USE_PPPOE */
/* get here if we got more than two PPP calls */
dtrap("targ300 0\n"); /* bug? */
return -1;
}
#endif /* USE_PPP */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -