fixed the compiling error while defined RT_USING_PPP

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2467 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
dzzxzz@gmail.com 2012-12-08 02:55:31 +00:00
parent 34a2c02ac2
commit f39686ebf8
2 changed files with 345 additions and 279 deletions

View File

@ -47,8 +47,6 @@ src/core/snmp/mib_structs.c
src/core/snmp/msg_in.c src/core/snmp/msg_in.c
src/core/snmp/msg_out.c src/core/snmp/msg_out.c
""") """)
if GetDepend(['RT_LWIP_PPP']):
src += ppp_src
ppp_src = Split(""" ppp_src = Split("""
src/netif/ppp/auth.c src/netif/ppp/auth.c
@ -67,18 +65,18 @@ src/netif/ppp/vj.c
""") """)
# The set of source files associated with this SConscript file. # The set of source files associated with this SConscript file.
path = [RTT_ROOT + '/components/net/lwip/src', path = [GetCurrentDir() + '/src',
RTT_ROOT + '/components/net/lwip/src/include', GetCurrentDir() + '/src/include',
RTT_ROOT + '/components/net/lwip/src/include/ipv4', GetCurrentDir() + '/src/include/ipv4',
RTT_ROOT + '/components/net/lwip/src/arch/include', GetCurrentDir() + '/src/arch/include',
RTT_ROOT + '/components/net/lwip/src/include/netif'] GetCurrentDir() + '/src/include/netif']
if GetDepend(['RT_LWIP_SNMP']): if GetDepend(['RT_LWIP_SNMP']):
src += snmp_src src += snmp_src
if GetDepend(['RT_LWIP_PPP']): if GetDepend(['RT_LWIP_PPP']):
src += ppp_src src += ppp_src
path += [RTT_ROOT + '/components/net/lwip/src/netif/ppp'] path += [GetCurrentDir() + '/src/netif/ppp']
# For testing apps # For testing apps
if GetDepend(['RT_USING_NETUTILS']): if GetDepend(['RT_USING_NETUTILS']):

View File

@ -9,98 +9,101 @@
#include "lwip/netif.h" #include "lwip/netif.h"
#include "lwip/tcpip.h" #include "lwip/tcpip.h"
#include "netif/ethernetif.h" #include "netif/ethernetif.h"
#include "lwip/sio.h"
#include <string.h> #include <string.h>
static err_t netif_device_init(struct netif *netif) static err_t netif_device_init(struct netif *netif)
{ {
struct eth_device *ethif; struct eth_device *ethif;
ethif = (struct eth_device*)netif->state; ethif = (struct eth_device *)netif->state;
if (ethif != RT_NULL) if (ethif != RT_NULL)
{ {
rt_device_t device; rt_device_t device;
/* get device object */ /* get device object */
device = (rt_device_t) ethif; device = (rt_device_t) ethif;
if (rt_device_init(device) != RT_EOK) if (rt_device_init(device) != RT_EOK)
{ {
return ERR_IF; return ERR_IF;
} }
/* copy device flags to netif flags */ /* copy device flags to netif flags */
netif->flags = ethif->flags; netif->flags = ethif->flags;
return ERR_OK; return ERR_OK;
} }
return ERR_IF; return ERR_IF;
} }
static void tcpip_init_done_callback(void *arg) static void tcpip_init_done_callback(void *arg)
{ {
rt_device_t device; rt_device_t device;
struct eth_device *ethif; struct eth_device *ethif;
struct ip_addr ipaddr, netmask, gw; struct ip_addr ipaddr, netmask, gw;
struct rt_list_node* node; struct rt_list_node* node;
struct rt_object* object; struct rt_object* object;
struct rt_object_information *information; struct rt_object_information *information;
extern struct rt_object_information rt_object_container[]; extern struct rt_object_information rt_object_container[];
LWIP_ASSERT("invalid arg.\n",arg); LWIP_ASSERT("invalid arg.\n",arg);
IP4_ADDR(&gw, 0,0,0,0); IP4_ADDR(&gw, 0,0,0,0);
IP4_ADDR(&ipaddr, 0,0,0,0); IP4_ADDR(&ipaddr, 0,0,0,0);
IP4_ADDR(&netmask, 0,0,0,0); IP4_ADDR(&netmask, 0,0,0,0);
/* enter critical */ /* enter critical */
rt_enter_critical(); rt_enter_critical();
/* for each network interfaces */ /* for each network interfaces */
information = &rt_object_container[RT_Object_Class_Device]; information = &rt_object_container[RT_Object_Class_Device];
for (node = information->object_list.next; node != &(information->object_list); node = node->next) for (node = information->object_list.next;
{ node != &(information->object_list);
object = rt_list_entry(node, struct rt_object, list); node = node->next)
device = (rt_device_t) object; {
if (device->type == RT_Device_Class_NetIf) object = rt_list_entry(node, struct rt_object, list);
{ device = (rt_device_t)object;
ethif = (struct eth_device*)device; if (device->type == RT_Device_Class_NetIf)
{
ethif = (struct eth_device *)device;
/* leave critical */ /* leave critical */
rt_exit_critical(); rt_exit_critical();
netif_add(ethif->netif, &ipaddr, &netmask, &gw, netif_add(ethif->netif, &ipaddr, &netmask, &gw,
ethif, netif_device_init, tcpip_input); ethif, netif_device_init, tcpip_input);
if (netif_default == RT_NULL) if (netif_default == RT_NULL)
netif_set_default(ethif->netif); netif_set_default(ethif->netif);
#if LWIP_DHCP #if LWIP_DHCP
if (ethif->flags & NETIF_FLAG_DHCP) if (ethif->flags & NETIF_FLAG_DHCP)
{ {
/* if this interface uses DHCP, start the DHCP client */ /* if this interface uses DHCP, start the DHCP client */
dhcp_start(ethif->netif); dhcp_start(ethif->netif);
} }
else else
#endif #endif
{ {
/* set interface up */ /* set interface up */
netif_set_up(ethif->netif); netif_set_up(ethif->netif);
} }
#ifdef LWIP_NETIF_LINK_CALLBACK #ifdef LWIP_NETIF_LINK_CALLBACK
netif_set_link_up(ethif->netif); netif_set_link_up(ethif->netif);
#endif #endif
/* enter critical */ /* enter critical */
rt_enter_critical(); rt_enter_critical();
} }
} }
/* leave critical */ /* leave critical */
rt_exit_critical(); rt_exit_critical();
rt_sem_release((rt_sem_t)arg); rt_sem_release((rt_sem_t)arg);
} }
/** /**
@ -108,212 +111,224 @@ static void tcpip_init_done_callback(void *arg)
*/ */
void lwip_system_init(void) void lwip_system_init(void)
{ {
rt_err_t rc; rt_err_t rc;
struct rt_semaphore done_sem; struct rt_semaphore done_sem;
/* set default netif to NULL */ /* set default netif to NULL */
netif_default = RT_NULL; netif_default = RT_NULL;
rc = rt_sem_init(&done_sem, "done", 0, RT_IPC_FLAG_FIFO); rc = rt_sem_init(&done_sem, "done", 0, RT_IPC_FLAG_FIFO);
if(rc != RT_EOK) if (rc != RT_EOK)
{ {
LWIP_ASSERT("Failed to create semaphore", 0); LWIP_ASSERT("Failed to create semaphore", 0);
return;
}
tcpip_init(tcpip_init_done_callback,(void *)&done_sem); return;
}
/* waiting for initialization done */ tcpip_init(tcpip_init_done_callback, (void *)&done_sem);
if (rt_sem_take(&done_sem, RT_WAITING_FOREVER) != RT_EOK)
{
rt_sem_detach(&done_sem);
return;
}
rt_sem_detach(&done_sem);
/* set default ip address */ /* waiting for initialization done */
if (rt_sem_take(&done_sem, RT_WAITING_FOREVER) != RT_EOK)
{
rt_sem_detach(&done_sem);
return;
}
rt_sem_detach(&done_sem);
/* set default ip address */
#if !LWIP_DHCP #if !LWIP_DHCP
if (netif_default != RT_NULL) if (netif_default != RT_NULL)
{ {
struct ip_addr ipaddr, netmask, gw; struct ip_addr ipaddr, netmask, gw;
IP4_ADDR(&ipaddr, RT_LWIP_IPADDR0, RT_LWIP_IPADDR1, RT_LWIP_IPADDR2, RT_LWIP_IPADDR3); IP4_ADDR(&ipaddr, RT_LWIP_IPADDR0, RT_LWIP_IPADDR1, RT_LWIP_IPADDR2, RT_LWIP_IPADDR3);
IP4_ADDR(&gw, RT_LWIP_GWADDR0, RT_LWIP_GWADDR1, RT_LWIP_GWADDR2, RT_LWIP_GWADDR3); IP4_ADDR(&gw, RT_LWIP_GWADDR0, RT_LWIP_GWADDR1, RT_LWIP_GWADDR2, RT_LWIP_GWADDR3);
IP4_ADDR(&netmask, RT_LWIP_MSKADDR0, RT_LWIP_MSKADDR1, RT_LWIP_MSKADDR2, RT_LWIP_MSKADDR3); IP4_ADDR(&netmask, RT_LWIP_MSKADDR0, RT_LWIP_MSKADDR1, RT_LWIP_MSKADDR2, RT_LWIP_MSKADDR3);
netifapi_netif_set_addr(netif_default, &ipaddr, &netmask, &gw); netifapi_netif_set_addr(netif_default, &ipaddr, &netmask, &gw);
} }
#endif #endif
} }
void sys_init(void) void sys_init(void)
{ {
/* nothing on RT-Thread porting */ /* nothing on RT-Thread porting */
} }
void lwip_sys_init(void) void lwip_sys_init(void)
{ {
lwip_system_init(); lwip_system_init();
} }
err_t sys_sem_new(sys_sem_t *sem, u8_t count) err_t sys_sem_new(sys_sem_t *sem, u8_t count)
{ {
static unsigned short counter = 0; static unsigned short counter = 0;
char tname[RT_NAME_MAX]; char tname[RT_NAME_MAX];
sys_sem_t tmpsem; sys_sem_t tmpsem;
RT_DEBUG_NOT_IN_INTERRUPT; RT_DEBUG_NOT_IN_INTERRUPT;
rt_snprintf(tname, RT_NAME_MAX, "%s%d", SYS_LWIP_SEM_NAME, counter); rt_snprintf(tname, RT_NAME_MAX, "%s%d", SYS_LWIP_SEM_NAME, counter);
counter++; counter ++;
tmpsem = rt_sem_create(tname, count, RT_IPC_FLAG_FIFO); tmpsem = rt_sem_create(tname, count, RT_IPC_FLAG_FIFO);
if( tmpsem == RT_NULL ) if (tmpsem == RT_NULL)
return ERR_MEM; return ERR_MEM;
else else
{ {
*sem = tmpsem; *sem = tmpsem;
return ERR_OK;
} return ERR_OK;
}
} }
void sys_sem_free(sys_sem_t *sem) void sys_sem_free(sys_sem_t *sem)
{ {
RT_DEBUG_NOT_IN_INTERRUPT; RT_DEBUG_NOT_IN_INTERRUPT;
rt_sem_delete(*sem); rt_sem_delete(*sem);
} }
void sys_sem_signal(sys_sem_t *sem) void sys_sem_signal(sys_sem_t *sem)
{ {
rt_sem_release(*sem); rt_sem_release(*sem);
} }
u32_t sys_arch_sem_wait(sys_sem_t *sem, u32_t timeout) u32_t sys_arch_sem_wait(sys_sem_t *sem, u32_t timeout)
{ {
rt_err_t ret; rt_err_t ret;
s32_t t; s32_t t;
u32_t tick; u32_t tick;
RT_DEBUG_NOT_IN_INTERRUPT; RT_DEBUG_NOT_IN_INTERRUPT;
/* get the begin tick */
tick = rt_tick_get();
if(timeout == 0) t = RT_WAITING_FOREVER;
else
{
/* convert msecond to os tick */
if (timeout < (1000/RT_TICK_PER_SECOND))
t = 1;
else
t = timeout / (1000/RT_TICK_PER_SECOND);
}
ret = rt_sem_take(*sem, t); /* get the begin tick */
tick = rt_tick_get();
if (timeout == 0)
t = RT_WAITING_FOREVER;
else
{
/* convert msecond to os tick */
if (timeout < (1000/RT_TICK_PER_SECOND))
t = 1;
else
t = timeout / (1000/RT_TICK_PER_SECOND);
}
if (ret == -RT_ETIMEOUT) ret = rt_sem_take(*sem, t);
return SYS_ARCH_TIMEOUT;
else
{
if (ret == RT_EOK)
ret = 1;
}
/* get elapse msecond */ if (ret == -RT_ETIMEOUT)
tick = rt_tick_get() - tick; return SYS_ARCH_TIMEOUT;
else
{
if (ret == RT_EOK)
ret = 1;
}
/* convert tick to msecond */ /* get elapse msecond */
tick = tick * (1000/RT_TICK_PER_SECOND); tick = rt_tick_get() - tick;
if (tick == 0)
tick = 1;
return tick; /* convert tick to msecond */
tick = tick * (1000 / RT_TICK_PER_SECOND);
if (tick == 0)
tick = 1;
return tick;
} }
#ifndef sys_sem_valid #ifndef sys_sem_valid
/** Check if a semaphore is valid/allocated: return 1 for valid, 0 for invalid */ /** Check if a semaphore is valid/allocated:
* return 1 for valid, 0 for invalid
*/
int sys_sem_valid(sys_sem_t *sem) int sys_sem_valid(sys_sem_t *sem)
{ {
return (int)(*sem); return (int)(*sem);
}
#endif
#ifndef sys_sem_set_invalid
/** Set a semaphore invalid so that sys_sem_valid returns 0 */
void sys_sem_set_invalid(sys_sem_t *sem)
{
*sem = RT_NULL;
} }
#endif #endif
#ifndef sys_sem_set_invalid
/** Set a semaphore invalid so that sys_sem_valid returns 0
*/
void sys_sem_set_invalid(sys_sem_t *sem)
{
*sem = RT_NULL;
}
#endif
/* ====================== Mutex ====================== */ /* ====================== Mutex ====================== */
/** Create a new mutex /** Create a new mutex
* @param mutex pointer to the mutex to create * @param mutex pointer to the mutex to create
* @return a new mutex */ * @return a new mutex
*/
err_t sys_mutex_new(sys_mutex_t *mutex) err_t sys_mutex_new(sys_mutex_t *mutex)
{ {
static unsigned short counter = 0; static unsigned short counter = 0;
char tname[RT_NAME_MAX]; char tname[RT_NAME_MAX];
sys_mutex_t tmpmutex; sys_mutex_t tmpmutex;
RT_DEBUG_NOT_IN_INTERRUPT; RT_DEBUG_NOT_IN_INTERRUPT;
rt_snprintf(tname, RT_NAME_MAX, "%s%d", SYS_LWIP_MUTEX_NAME, counter); rt_snprintf(tname, RT_NAME_MAX, "%s%d", SYS_LWIP_MUTEX_NAME, counter);
counter++; counter ++;
tmpmutex = rt_mutex_create(tname, RT_IPC_FLAG_FIFO); tmpmutex = rt_mutex_create(tname, RT_IPC_FLAG_FIFO);
if( tmpmutex == RT_NULL ) if (tmpmutex == RT_NULL)
return ERR_MEM; return ERR_MEM;
else else
{ {
*mutex = tmpmutex; *mutex = tmpmutex;
return ERR_OK;
} return ERR_OK;
}
} }
/** Lock a mutex /** Lock a mutex
* @param mutex the mutex to lock */ * @param mutex the mutex to lock
*/
void sys_mutex_lock(sys_mutex_t *mutex) void sys_mutex_lock(sys_mutex_t *mutex)
{ {
RT_DEBUG_NOT_IN_INTERRUPT; RT_DEBUG_NOT_IN_INTERRUPT;
rt_mutex_take(*mutex, RT_WAITING_FOREVER); rt_mutex_take(*mutex, RT_WAITING_FOREVER);
return; return;
} }
/** Unlock a mutex /** Unlock a mutex
* @param mutex the mutex to unlock */ * @param mutex the mutex to unlock
*/
void sys_mutex_unlock(sys_mutex_t *mutex) void sys_mutex_unlock(sys_mutex_t *mutex)
{ {
rt_mutex_release(*mutex); rt_mutex_release(*mutex);
} }
/** Delete a semaphore /** Delete a semaphore
* @param mutex the mutex to delete */ * @param mutex the mutex to delete
*/
void sys_mutex_free(sys_mutex_t *mutex) void sys_mutex_free(sys_mutex_t *mutex)
{ {
RT_DEBUG_NOT_IN_INTERRUPT; RT_DEBUG_NOT_IN_INTERRUPT;
rt_mutex_delete(*mutex); rt_mutex_delete(*mutex);
} }
#ifndef sys_mutex_valid #ifndef sys_mutex_valid
/** Check if a mutex is valid/allocated: return 1 for valid, 0 for invalid */ /** Check if a mutex is valid/allocated:
* return 1 for valid, 0 for invalid
*/
int sys_mutex_valid(sys_mutex_t *mutex) int sys_mutex_valid(sys_mutex_t *mutex)
{ {
return (int)(*mutex); return (int)(*mutex);
} }
#endif #endif
#ifndef sys_mutex_set_invalid #ifndef sys_mutex_set_invalid
/** Set a mutex invalid so that sys_mutex_valid returns 0 */ /** Set a mutex invalid so that sys_mutex_valid returns 0
*/
void sys_mutex_set_invalid(sys_mutex_t *mutex) void sys_mutex_set_invalid(sys_mutex_t *mutex)
{ {
*mutex = RT_NULL; *mutex = RT_NULL;
} }
#endif #endif
@ -321,53 +336,55 @@ void sys_mutex_set_invalid(sys_mutex_t *mutex)
err_t sys_mbox_new(sys_mbox_t *mbox, int size) err_t sys_mbox_new(sys_mbox_t *mbox, int size)
{ {
static unsigned short counter = 0; static unsigned short counter = 0;
char tname[RT_NAME_MAX]; char tname[RT_NAME_MAX];
sys_mbox_t tmpmbox; sys_mbox_t tmpmbox;
RT_DEBUG_NOT_IN_INTERRUPT; RT_DEBUG_NOT_IN_INTERRUPT;
rt_snprintf(tname, RT_NAME_MAX, "%s%d", SYS_LWIP_MBOX_NAME, counter); rt_snprintf(tname, RT_NAME_MAX, "%s%d", SYS_LWIP_MBOX_NAME, counter);
counter++; counter ++;
tmpmbox = rt_mb_create(tname, size, RT_IPC_FLAG_FIFO); tmpmbox = rt_mb_create(tname, size, RT_IPC_FLAG_FIFO);
if( tmpmbox != RT_NULL ) if (tmpmbox != RT_NULL)
{ {
*mbox = tmpmbox; *mbox = tmpmbox;
return ERR_OK;
}
return ERR_MEM; return ERR_OK;
}
return ERR_MEM;
} }
void sys_mbox_free(sys_mbox_t *mbox) void sys_mbox_free(sys_mbox_t *mbox)
{ {
RT_DEBUG_NOT_IN_INTERRUPT; RT_DEBUG_NOT_IN_INTERRUPT;
rt_mb_delete(*mbox); rt_mb_delete(*mbox);
return; return;
} }
/** Post a message to an mbox - may not fail /** Post a message to an mbox - may not fail
* -> blocks if full, only used from tasks not from ISR * -> blocks if full, only used from tasks not from ISR
* @param mbox mbox to posts the message * @param mbox mbox to posts the message
* @param msg message to post (ATTENTION: can be NULL) */ * @param msg message to post (ATTENTION: can be NULL)
*/
void sys_mbox_post(sys_mbox_t *mbox, void *msg) void sys_mbox_post(sys_mbox_t *mbox, void *msg)
{ {
RT_DEBUG_NOT_IN_INTERRUPT; RT_DEBUG_NOT_IN_INTERRUPT;
rt_mb_send_wait(*mbox, (rt_uint32_t)msg,RT_WAITING_FOREVER); rt_mb_send_wait(*mbox, (rt_uint32_t)msg, RT_WAITING_FOREVER);
return; return;
} }
err_t sys_mbox_trypost(sys_mbox_t *mbox, void *msg) err_t sys_mbox_trypost(sys_mbox_t *mbox, void *msg)
{ {
if (rt_mb_send(*mbox, (rt_uint32_t)msg) == RT_EOK) if (rt_mb_send(*mbox, (rt_uint32_t)msg) == RT_EOK)
return ERR_OK; return ERR_OK;
return ERR_MEM; return ERR_MEM;
} }
/** Wait for a new message to arrive in the mbox /** Wait for a new message to arrive in the mbox
@ -376,47 +393,48 @@ err_t sys_mbox_trypost(sys_mbox_t *mbox, void *msg)
* @param timeout maximum time (in milliseconds) to wait for a message * @param timeout maximum time (in milliseconds) to wait for a message
* @return time (in milliseconds) waited for a message, may be 0 if not waited * @return time (in milliseconds) waited for a message, may be 0 if not waited
or SYS_ARCH_TIMEOUT on timeout or SYS_ARCH_TIMEOUT on timeout
* The returned time has to be accurate to prevent timer jitter! */ * The returned time has to be accurate to prevent timer jitter!
*/
u32_t sys_arch_mbox_fetch(sys_mbox_t *mbox, void **msg, u32_t timeout) u32_t sys_arch_mbox_fetch(sys_mbox_t *mbox, void **msg, u32_t timeout)
{ {
rt_err_t ret; rt_err_t ret;
s32_t t; s32_t t;
u32_t tick; u32_t tick;
RT_DEBUG_NOT_IN_INTERRUPT; RT_DEBUG_NOT_IN_INTERRUPT;
/* get the begin tick */ /* get the begin tick */
tick = rt_tick_get(); tick = rt_tick_get();
if(timeout == 0) if(timeout == 0)
t = RT_WAITING_FOREVER; t = RT_WAITING_FOREVER;
else else
{ {
/* convirt msecond to os tick */ /* convirt msecond to os tick */
if (timeout < (1000/RT_TICK_PER_SECOND)) if (timeout < (1000/RT_TICK_PER_SECOND))
t = 1; t = 1;
else else
t = timeout / (1000/RT_TICK_PER_SECOND); t = timeout / (1000/RT_TICK_PER_SECOND);
} }
ret = rt_mb_recv(*mbox, (rt_uint32_t *)msg, t); ret = rt_mb_recv(*mbox, (rt_uint32_t *)msg, t);
if(ret == -RT_ETIMEOUT) if(ret == -RT_ETIMEOUT)
return SYS_ARCH_TIMEOUT; return SYS_ARCH_TIMEOUT;
else else
{ {
LWIP_ASSERT("rt_mb_recv returned with error!", ret == RT_EOK); LWIP_ASSERT("rt_mb_recv returned with error!", ret == RT_EOK);
} }
/* get elapse msecond */ /* get elapse msecond */
tick = rt_tick_get() - tick; tick = rt_tick_get() - tick;
/* convert tick to msecond */ /* convert tick to msecond */
tick = tick * (1000/RT_TICK_PER_SECOND); tick = tick * (1000 / RT_TICK_PER_SECOND);
if (tick == 0) if (tick == 0)
tick = 1; tick = 1;
return tick; return tick;
} }
/** Wait for a new message to arrive in the mbox /** Wait for a new message to arrive in the mbox
@ -424,80 +442,130 @@ u32_t sys_arch_mbox_fetch(sys_mbox_t *mbox, void **msg, u32_t timeout)
* @param msg pointer where the message is stored * @param msg pointer where the message is stored
* @param timeout maximum time (in milliseconds) to wait for a message * @param timeout maximum time (in milliseconds) to wait for a message
* @return 0 (milliseconds) if a message has been received * @return 0 (milliseconds) if a message has been received
* or SYS_MBOX_EMPTY if the mailbox is empty */ * or SYS_MBOX_EMPTY if the mailbox is empty
*/
u32_t sys_arch_mbox_tryfetch(sys_mbox_t *mbox, void **msg) u32_t sys_arch_mbox_tryfetch(sys_mbox_t *mbox, void **msg)
{ {
int ret; int ret;
ret = rt_mb_recv(*mbox, (rt_uint32_t *)msg, 0); ret = rt_mb_recv(*mbox, (rt_uint32_t *)msg, 0);
if(ret == -RT_ETIMEOUT) if(ret == -RT_ETIMEOUT)
return SYS_ARCH_TIMEOUT; return SYS_ARCH_TIMEOUT;
else else
{ {
if (ret == RT_EOK) if (ret == RT_EOK)
ret = 1; ret = 1;
} }
return ret; return ret;
} }
#ifndef sys_mbox_valid #ifndef sys_mbox_valid
/** Check if an mbox is valid/allocated: return 1 for valid, 0 for invalid */ /** Check if an mbox is valid/allocated:
* return 1 for valid, 0 for invalid
*/
int sys_mbox_valid(sys_mbox_t *mbox) int sys_mbox_valid(sys_mbox_t *mbox)
{ {
return (int)(*mbox); return (int)(*mbox);
} }
#endif #endif
#ifndef sys_mbox_set_invalid #ifndef sys_mbox_set_invalid
/** Set an mbox invalid so that sys_mbox_valid returns 0 */ /** Set an mbox invalid so that sys_mbox_valid returns 0
*/
void sys_mbox_set_invalid(sys_mbox_t *mbox) void sys_mbox_set_invalid(sys_mbox_t *mbox)
{ {
*mbox = RT_NULL; *mbox = RT_NULL;
} }
#endif #endif
/* ====================== System ====================== */ /* ====================== System ====================== */
sys_thread_t sys_thread_new(const char *name, lwip_thread_fn thread, void *arg, int stacksize, int prio) sys_thread_t sys_thread_new(const char *name,
lwip_thread_fn thread,
void *arg,
int stacksize,
int prio)
{ {
rt_thread_t t; rt_thread_t t;
RT_DEBUG_NOT_IN_INTERRUPT; RT_DEBUG_NOT_IN_INTERRUPT;
/* create thread */ /* create thread */
t = rt_thread_create(name, thread, arg, stacksize, prio, 20); t = rt_thread_create(name, thread, arg, stacksize, prio, 20);
RT_ASSERT(t != RT_NULL); RT_ASSERT(t != RT_NULL);
/* startup thread */ /* startup thread */
rt_thread_startup(t); rt_thread_startup(t);
return t; return t;
} }
sys_prot_t sys_arch_protect(void) sys_prot_t sys_arch_protect(void)
{ {
rt_base_t level; rt_base_t level;
/* disable interrupt */ /* disable interrupt */
level = rt_hw_interrupt_disable(); level = rt_hw_interrupt_disable();
return level;
return level;
} }
void sys_arch_unprotect(sys_prot_t pval) void sys_arch_unprotect(sys_prot_t pval)
{ {
/* enable interrupt */ /* enable interrupt */
rt_hw_interrupt_enable(pval); rt_hw_interrupt_enable(pval);
return; return;
} }
void sys_arch_assert(const char* file, int line) void sys_arch_assert(const char *file, int line)
{ {
rt_kprintf("\nAssertion: %d in %s, thread %s\n", line, file, rt_kprintf("\nAssertion: %d in %s, thread %s\n",
rt_thread_self()->name); line, file, rt_thread_self()->name);
RT_ASSERT(0); RT_ASSERT(0);
}
u32_t sys_jiffies(void)
{
return rt_tick_get();
}
u32_t sio_read(sio_fd_t fd, u8_t *buf, u32_t size)
{
u32_t len, i;
RT_ASSERT(fd != RT_NULL);
len = rt_device_read((rt_device_t)fd, 0, buf, size);
if (len <= 0)
return 0;
return len;
}
u32_t sio_write(sio_fd_t fd, u8_t *buf, u32_t size)
{
u32_t i;
RT_ASSERT(fd != RT_NULL);
return rt_device_write((rt_device_t)fd, 0, buf, size);
}
void sio_read_abort(sio_fd_t fd)
{
rt_kprintf("read_abort\n");
}
void ppp_trace(int level, const char *format, ...)
{
va_list args;
rt_size_t length;
static char rt_log_buf[RT_CONSOLEBUF_SIZE];
va_start(args, format);
length = rt_vsprintf(rt_log_buf, format, args);
rt_device_write((rt_device_t)rt_console_get_device(), 0, rt_log_buf, length);
va_end(args);
} }