www.pudn.com > TCPmodbushy.rar > sys.h


/* 
 * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 
 * All rights reserved.  
 *  
 * Redistribution and use in source and binary forms, with or without modification,  
 * are permitted provided that the following conditions are met: 
 * 
 * 1. Redistributions of source code must retain the above copyright notice, 
 *    this list of conditions and the following disclaimer. 
 * 2. Redistributions in binary form must reproduce the above copyright notice, 
 *    this list of conditions and the following disclaimer in the documentation 
 *    and/or other materials provided with the distribution. 
 * 3. The name of the author may not be used to endorse or promote products 
 *    derived from this software without specific prior written permission.  
 * 
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED  
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF  
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT  
 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,  
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT  
 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS  
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN  
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING  
 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY  
 * OF SUCH DAMAGE. 
 * 
 * This file is part of the lwIP TCP/IP stack. 
 *  
 * Author: Adam Dunkels  
 * 
 */ 
#ifndef __LWIP_SYS_H__ 
#define __LWIP_SYS_H__ 
 
#include "o:/arch/cc.h" 
 
#include "o:/lwip/opt.h" 
 
 
#if NO_SYS 
 
/* For a totally minimal and standalone system, we provide null 
   definitions of the sys_ functions. */ 
typedef u8_t sys_sem_t; 
typedef u8_t sys_mbox_t; 
 
#define sys_init() 
#define sys_untimeout(m,a) 
#define sys_sem_new(c) c 
#define sys_sem_signal(s) 
#define sys_sem_wait(s) 
#define sys_sem_free(s) 
#define sys_mbox_new() 0 
#define sys_mbox_fetch(m,d) 
#define sys_mbox_post(m,d) 
#define sys_mbox_free(m) 
 
#define sys_thread_new(t,a,p) 
 
#endif /* NO_SYS */ 
 
 
/* Critical Region Protection */ 
/* These functions must be implemented in the sys_arch.c file. 
   In some implementations they can provide a more light-weight protection 
   mechanism than using semaphores. Otherwise semaphores can be used for 
   implementation */ 
#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. 
 */ 
#if SYS_LIGHTWEIGHT_PROT 
 
/** 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 
/** 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() 
/** 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) 
sys_prot_t sys_arch_protect(void); 
void sys_arch_unprotect(sys_prot_t pval); 
 
#else 
 
#define SYS_ARCH_DECL_PROTECT(lev) 
#define SYS_ARCH_PROTECT(lev) 
#define SYS_ARCH_UNPROTECT(lev) 
 
#endif /* SYS_LIGHTWEIGHT_PROT */ 
 
#endif /* SYS_ARCH_PROTECT */ 
 
#endif /* __LWIP_SYS_H__ */