Fixed SYS_ARCH_PROTECT macros when NO_SYS is not defined.

Added documentation for lightweight protection.

Fixed debug statement in ip.c.

Removed tabs in files I changed.
This commit is contained in:
davidhaas 2003-02-18 21:14:16 +00:00
parent 7f1becc682
commit e13c78820f
3 changed files with 89 additions and 40 deletions

View File

@ -121,3 +121,26 @@ to be implemented as well:
"thread()". The "arg" argument will be passed as an argument to the "thread()". The "arg" argument will be passed as an argument to the
thread() function. The id of the new thread is returned. thread() function. The id of the new thread is returned.
- sys_prot_t sys_arch_protect(void)
This optional function does a "fast" critical region protection and returns
the previous protection level. This function is only called during very short
critical regions. An embedded system which supports ISR-based drivers might
want to implement this function by disabling interrupts. Task-based systems
might want to implement this by using a mutex or disabling tasking. This
function should support recursive calls from the same task or interrupt. In
other words, sys_arch_protect() could be called while already protected. In
that case the return value indicates that it is already protected.
sys_arch_protect() is only required if your port is supporting an operating
system.
- void sys_arch_unprotect(sys_prot_t pval)
This optional function does a "fast" set of critical region protection to the
value specified by pval. See the documentation for sys_arch_protect() for
more information. This function is only required if your port is supporting
an operating system.

View File

@ -164,7 +164,7 @@ ip_forward(struct pbuf *p, struct ip_hdr *iphdr, struct netif *inp)
netif = ip_route((struct ip_addr *)&(iphdr->dest)); netif = ip_route((struct ip_addr *)&(iphdr->dest));
if(netif == NULL) { if(netif == NULL) {
DEBUGF(IP_DEBUG, ("ip_forward: no forwarding route for 0x%lx found\n", DEBUGF(IP_DEBUG, ("ip_forward: no forwarding route for 0x%lx found\n",
iphdr->dest.addr)); iphdr->dest.addr));
snmp_inc_ipnoroutes(); snmp_inc_ipnoroutes();
return; return;
} }
@ -196,7 +196,7 @@ ip_forward(struct pbuf *p, struct ip_hdr *iphdr, struct netif *inp)
} }
DEBUGF(IP_DEBUG, ("ip_forward: forwarding packet to 0x%lx\n", DEBUGF(IP_DEBUG, ("ip_forward: forwarding packet to 0x%lx\n",
iphdr->dest.addr)); iphdr->dest.addr));
#ifdef IP_STATS #ifdef IP_STATS
++lwip_stats.ip.fw; ++lwip_stats.ip.fw;
@ -290,10 +290,10 @@ ip_input(struct pbuf *p, struct netif *inp) {
for(netif = netif_list; netif != NULL; netif = netif->next) { for(netif = netif_list; netif != NULL; netif = netif->next) {
DEBUGF(IP_DEBUG, ("ip_input: iphdr->dest 0x%lx netif->ip_addr 0x%lx (0x%lx, 0x%lx, 0x%lx)\n", DEBUGF(IP_DEBUG, ("ip_input: iphdr->dest 0x%lx netif->ip_addr 0x%lx (0x%lx, 0x%lx, 0x%lx)\n",
iphdr->dest.addr, netif->ip_addr.addr, iphdr->dest.addr, netif->ip_addr.addr,
iphdr->dest.addr & netif->netmask.addr, iphdr->dest.addr & netif->netmask.addr,
netif->ip_addr.addr & netif->netmask.addr, netif->ip_addr.addr & netif->netmask.addr,
iphdr->dest.addr & ~(netif->netmask.addr))); iphdr->dest.addr & ~(netif->netmask.addr)));
/* interface configured? */ /* interface configured? */
if(!ip_addr_isany(&(netif->ip_addr))) if(!ip_addr_isany(&(netif->ip_addr)))
@ -306,7 +306,7 @@ ip_input(struct pbuf *p, struct netif *inp) {
/* or restricted broadcast? */ /* or restricted broadcast? */
ip_addr_cmp(&(iphdr->dest), IP_ADDR_BROADCAST)) { ip_addr_cmp(&(iphdr->dest), IP_ADDR_BROADCAST)) {
DEBUGF(IP_DEBUG, ("ip_input: packet accepted on interface %c%c\n", DEBUGF(IP_DEBUG, ("ip_input: packet accepted on interface %c%c\n",
netif->name[0], netif->name[1])); netif->name[0], netif->name[1]));
/* break out of for loop */ /* break out of for loop */
break; break;
} }
@ -328,7 +328,7 @@ ip_input(struct pbuf *p, struct netif *inp) {
} }
} }
#endif /* LWIP_DHCP */ #endif /* LWIP_DHCP */
/* packet not for us? */ /* packet not for us? */
if(netif == NULL) { if(netif == NULL) {
/* packet not for us, route or discard */ /* packet not for us, route or discard */
DEBUGF(IP_DEBUG, ("ip_input: packet not for us.\n")); DEBUGF(IP_DEBUG, ("ip_input: packet not for us.\n"));
@ -349,7 +349,7 @@ ip_input(struct pbuf *p, struct netif *inp) {
#if IP_REASSEMBLY #if IP_REASSEMBLY
if((IPH_OFFSET(iphdr) & htons(IP_OFFMASK | IP_MF)) != 0) { if((IPH_OFFSET(iphdr) & htons(IP_OFFMASK | IP_MF)) != 0) {
DEBUGF(IP_DEBUG, ("IP packet is a fragment (id=0x%04x tot_len=%u len=%u MF=%u offset=%u), calling ip_reass()\n", ntohs(IPH_ID(iphdr)), p->tot_len, ntohs(IPH_LEN(iphdr)), !!(IPH_OFFSET(iphdr) & htons(IP_MF)), (ntohs(IPH_OFFSET(iphdr)) & IP_OFFMASK))*8); DEBUGF(IP_DEBUG, ("IP packet is a fragment (id=0x%04x tot_len=%u len=%u MF=%u offset=%u), calling ip_reass()\n", ntohs(IPH_ID(iphdr)), p->tot_len, ntohs(IPH_LEN(iphdr)), !!(IPH_OFFSET(iphdr) & htons(IP_MF)), (ntohs(IPH_OFFSET(iphdr)) & IP_OFFMASK)*8));
p = ip_reass(p); p = ip_reass(p);
if(p == NULL) { if(p == NULL) {
return ERR_OK; return ERR_OK;
@ -360,7 +360,7 @@ ip_input(struct pbuf *p, struct netif *inp) {
if((IPH_OFFSET(iphdr) & htons(IP_OFFMASK | IP_MF)) != 0) { if((IPH_OFFSET(iphdr) & htons(IP_OFFMASK | IP_MF)) != 0) {
pbuf_free(p); pbuf_free(p);
DEBUGF(IP_DEBUG, ("IP packet dropped since it was fragmented (0x%x) (while IP_REASSEMBLY == 0).\n", DEBUGF(IP_DEBUG, ("IP packet dropped since it was fragmented (0x%x) (while IP_REASSEMBLY == 0).\n",
ntohs(IPH_OFFSET(iphdr)))); ntohs(IPH_OFFSET(iphdr))));
#ifdef IP_STATS #ifdef IP_STATS
++lwip_stats.ip.opterr; ++lwip_stats.ip.opterr;
++lwip_stats.ip.drop; ++lwip_stats.ip.drop;
@ -439,8 +439,8 @@ ip_input(struct pbuf *p, struct netif *inp) {
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
err_t err_t
ip_output_if(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest, ip_output_if(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
u8_t ttl, u8_t ttl,
u8_t proto, struct netif *netif) u8_t proto, struct netif *netif)
{ {
static struct ip_hdr *iphdr; static struct ip_hdr *iphdr;
static u16_t ip_id = 0; static u16_t ip_id = 0;
@ -484,7 +484,7 @@ ip_output_if(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
dest = &(iphdr->dest); dest = &(iphdr->dest);
} }
#if IP_FRAG #if IP_FRAG
/* don't fragment if interface has mtu set to 0 [loopif] */ /* don't fragment if interface has mtu set to 0 [loopif] */
if (netif->mtu && (p->tot_len > netif->mtu)) if (netif->mtu && (p->tot_len > netif->mtu))
return ip_frag(p,netif,dest); return ip_frag(p,netif,dest);
@ -511,7 +511,7 @@ ip_output_if(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
err_t err_t
ip_output(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest, ip_output(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
u8_t ttl, u8_t proto) u8_t ttl, u8_t proto)
{ {
struct netif *netif; struct netif *netif;
@ -540,34 +540,34 @@ ip_debug_print(struct pbuf *p)
DEBUGF(IP_DEBUG, ("IP header:\n")); DEBUGF(IP_DEBUG, ("IP header:\n"));
DEBUGF(IP_DEBUG, ("+-------------------------------+\n")); DEBUGF(IP_DEBUG, ("+-------------------------------+\n"));
DEBUGF(IP_DEBUG, ("|%2d |%2d | %2u | %4u | (v, hl, tos, len)\n", DEBUGF(IP_DEBUG, ("|%2d |%2d | %2u | %4u | (v, hl, tos, len)\n",
IPH_V(iphdr), IPH_V(iphdr),
IPH_HL(iphdr), IPH_HL(iphdr),
IPH_TOS(iphdr), IPH_TOS(iphdr),
ntohs(IPH_LEN(iphdr)))); ntohs(IPH_LEN(iphdr))));
DEBUGF(IP_DEBUG, ("+-------------------------------+\n")); DEBUGF(IP_DEBUG, ("+-------------------------------+\n"));
DEBUGF(IP_DEBUG, ("| %5u |%u%u%u| %4u | (id, flags, offset)\n", DEBUGF(IP_DEBUG, ("| %5u |%u%u%u| %4u | (id, flags, offset)\n",
ntohs(IPH_ID(iphdr)), ntohs(IPH_ID(iphdr)),
ntohs(IPH_OFFSET(iphdr)) >> 15 & 1, ntohs(IPH_OFFSET(iphdr)) >> 15 & 1,
ntohs(IPH_OFFSET(iphdr)) >> 14 & 1, ntohs(IPH_OFFSET(iphdr)) >> 14 & 1,
ntohs(IPH_OFFSET(iphdr)) >> 13 & 1, ntohs(IPH_OFFSET(iphdr)) >> 13 & 1,
ntohs(IPH_OFFSET(iphdr)) & IP_OFFMASK)); ntohs(IPH_OFFSET(iphdr)) & IP_OFFMASK));
DEBUGF(IP_DEBUG, ("+-------------------------------+\n")); DEBUGF(IP_DEBUG, ("+-------------------------------+\n"));
DEBUGF(IP_DEBUG, ("| %2u | %2u | 0x%04x | (ttl, proto, chksum)\n", DEBUGF(IP_DEBUG, ("| %2u | %2u | 0x%04x | (ttl, proto, chksum)\n",
IPH_TTL(iphdr), IPH_TTL(iphdr),
IPH_PROTO(iphdr), IPH_PROTO(iphdr),
ntohs(IPH_CHKSUM(iphdr)))); ntohs(IPH_CHKSUM(iphdr))));
DEBUGF(IP_DEBUG, ("+-------------------------------+\n")); DEBUGF(IP_DEBUG, ("+-------------------------------+\n"));
DEBUGF(IP_DEBUG, ("| %3ld | %3ld | %3ld | %3ld | (src)\n", DEBUGF(IP_DEBUG, ("| %3ld | %3ld | %3ld | %3ld | (src)\n",
ntohl(iphdr->src.addr) >> 24 & 0xff, ntohl(iphdr->src.addr) >> 24 & 0xff,
ntohl(iphdr->src.addr) >> 16 & 0xff, ntohl(iphdr->src.addr) >> 16 & 0xff,
ntohl(iphdr->src.addr) >> 8 & 0xff, ntohl(iphdr->src.addr) >> 8 & 0xff,
ntohl(iphdr->src.addr) & 0xff)); ntohl(iphdr->src.addr) & 0xff));
DEBUGF(IP_DEBUG, ("+-------------------------------+\n")); DEBUGF(IP_DEBUG, ("+-------------------------------+\n"));
DEBUGF(IP_DEBUG, ("| %3ld | %3ld | %3ld | %3ld | (dest)\n", DEBUGF(IP_DEBUG, ("| %3ld | %3ld | %3ld | %3ld | (dest)\n",
ntohl(iphdr->dest.addr) >> 24 & 0xff, ntohl(iphdr->dest.addr) >> 24 & 0xff,
ntohl(iphdr->dest.addr) >> 16 & 0xff, ntohl(iphdr->dest.addr) >> 16 & 0xff,
ntohl(iphdr->dest.addr) >> 8 & 0xff, ntohl(iphdr->dest.addr) >> 8 & 0xff,
ntohl(iphdr->dest.addr) & 0xff)); ntohl(iphdr->dest.addr) & 0xff));
DEBUGF(IP_DEBUG, ("+-------------------------------+\n")); DEBUGF(IP_DEBUG, ("+-------------------------------+\n"));
} }
#endif /* IP_DEBUG */ #endif /* IP_DEBUG */

View File

@ -36,9 +36,6 @@
#include "lwip/opt.h" #include "lwip/opt.h"
#define SYS_ARCH_DECL_PROTECT(lev)
#define SYS_ARCH_PROTECT(lev)
#define SYS_ARCH_UNPROTECT(lev)
#if NO_SYS #if NO_SYS
@ -61,6 +58,11 @@ struct sys_timeout {u8_t dummy;};
#define sys_thread_new(t,a) #define sys_thread_new(t,a)
/* We don't need protection if there is no OS */
#define SYS_ARCH_DECL_PROTECT(lev)
#define SYS_ARCH_PROTECT(lev)
#define SYS_ARCH_UNPROTECT(lev)
#else /* NO_SYS */ #else /* NO_SYS */
#include "arch/sys_arch.h" #include "arch/sys_arch.h"
@ -115,13 +117,37 @@ void sys_mbox_fetch(sys_mbox_t mbox, void **msg);
mechanism than using semaphores. Otherwise semaphores can be used for mechanism than using semaphores. Otherwise semaphores can be used for
implementation */ implementation */
#ifndef SYS_ARCH_PROTECT #ifndef SYS_ARCH_PROTECT
/** SYS_LIGHTWEIGHT_PROT
* define SYS_LIGHTWEIGHT_PROT in lwipopts.h if you want inter-task protection
* for certain critical regions during buffer allocation, deallocation and memory
* allocation and deallocation.
*/
#ifdef SYS_LIGHTWEIGHT_PROT #ifdef SYS_LIGHTWEIGHT_PROT
#undef SYS_ARCH_DECL_PROTECT /** SYS_ARCH_DECL_PROTECT
* declare a protection variable. This macro will default to defining a variable of
* type sys_prot_t. If a particular port needs a different implementation, then
* this macro may be defined in sys_arch.h.
*/
#define SYS_ARCH_DECL_PROTECT(lev) sys_prot_t lev #define SYS_ARCH_DECL_PROTECT(lev) sys_prot_t lev
#undef SYS_ARCH_PROTECT /** SYS_ARCH_PROTECT
* Perform a "fast" protect. This could be implemented by
* disabling interrupts for an embedded system or by using a semaphore or
* mutex. The implementation should allow calling SYS_ARCH_PROTECT when
* already protected. The old protection level is returned in the variable
* "lev". This macro will default to calling the sys_arch_protect() function
* which should be implemented in sys_arch.c. If a particular port needs a
* different implementation, then this macro may be defined in sys_arch.h
*/
#define SYS_ARCH_PROTECT(lev) lev = sys_arch_protect() #define SYS_ARCH_PROTECT(lev) lev = sys_arch_protect()
#undef SYS_ARCH_UNPROTECT /** SYS_ARCH_UNPROTECT
* Perform a "fast" set of the protection level to "lev". This could be
* implemented by setting the interrupt level to "lev" within the MACRO or by
* using a semaphore or mutex. This macro will default to calling the
* sys_arch_unprotect() function which should be implemented in
* sys_arch.c. If a particular port needs a different implementation, then
* this macro may be defined in sys_arch.h
*/
#define SYS_ARCH_UNPROTECT(lev) sys_arch_unprotect(lev) #define SYS_ARCH_UNPROTECT(lev) sys_arch_unprotect(lev)
sys_prot_t sys_arch_protect(void); sys_prot_t sys_arch_protect(void);
void sys_arch_unprotect(sys_prot_t pval); void sys_arch_unprotect(sys_prot_t pval);