⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sys_pico.h

📁 picoos源码。The RTOS and the TCP/IP stack will be built automatically.
💻 H
字号:
/*
 *  Copyright (c) 2004-2005, Dennis Kuschel.
 *  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 contains the
 *
 *  operating system adaption for  pico]OS with lwIP
 */

#ifndef MY_SYS_H
#define MY_SYS_H


/*---------------------------------------------------------------------------
 *  Include Operating System Header Files
 *-------------------------------------------------------------------------*/

#include "lwip/opt.h"
#include "lwip/inet.h"
#include "lwip/sockets.h"
#include <stdarg.h>
#include <picoos.h>

/* check pico]OS configuration */
#if POSCFG_FEATURE_JIFFIES == 0
#error POSCFG_FEATURE_JIFFIES not enabled
#endif
#if POSCFG_FEATURE_SEMAPHORES == 0
#error POSCFG_FEATURE_SEMAPHORES not enabled
#endif
#if POSCFG_FEATURE_SEMADESTROY == 0
#error POSCFG_FEATURE_SEMADESTROY not enabled
#endif
#if POSCFG_FEATURE_SLEEP == 0
#error POSCFG_FEATURE_SLEEP not enabled
#endif

/* check lwIP configuration */
#if !LWIP_COMPAT_SOCKETS
#error LWIP_COMPAT_SOCKETS not set to 1 in lwipopts.h !
#endif

/* correct a bug in lwip/sockets.h */
#if FD_SETSIZE < MEMP_NUM_NETCONN
#undef FD_SETSIZE
#define FD_SETSIZE  MEMP_NUM_NETCONN
#ifdef fd_set
#undef fd_set
#endif
#define fd_set  fd_set_2
typedef struct fd_set_2 {
  unsigned char fd_bits [(FD_SETSIZE+7)/8];
} fd_set_2;
#undef select
#define select(a,b,c,d,e) \
          lwip_select(a,(void*)(b),(void*)(c),(void*)(d),e)
#endif



/*---------------------------------------------------------------------------
 *  Common Declarations - needed by ftpd and filesys
 *-------------------------------------------------------------------------*/

/* definition of common types */

/* note: already defined in cc.h from lwip
typedef unsigned char   u8_t;
typedef signed   char   s8_t;
typedef unsigned short  u16_t;
typedef signed   short  s16_t;
typedef unsigned int    u32_t;
typedef signed   int    s32_t;
*/
typedef unsigned int    uint_t;
typedef signed   int    sint_t;

/* macros */
#if POSCFG_ENABLE_NANO != 0

#define sysPrintErr(x)          nosPrint(x)
#define sysSleep(ms)            nosTaskSleep(ms)
#define sysMemAlloc(s)          nosMemAlloc(s)
#define sysMemFree(x)           nosMemFree(x)
#define sysMemCopy(d,s,l)       nosMemCopy(d,s,l)
#define sysMemSet(d,v,s)        nosMemSet(d,v,s)

#else

#define sysPrintErr(x)          printf("%s",x)
#define sysSleep(ms)            posTaskSleep(ms)
#define sysMemAlloc(s)          malloc(s)
#define sysMemFree(x)           free(x)
#define sysMemCopy(d,s,l)       memcpy(d,s,l)
#define sysMemSet(d,v,s)        memset(d,v,s)

#endif

#define sysStrcpy(d,s)          strcpy(d,s)
#define sysStrncpy(d,s,n)       strncpy(d,s,n)
#define sysStrcat(d,s)          strcat(d,s)
#define sysStrlen(s)            strlen(s)
#define sysStrcmp(s1,s2)        strcmp(s1,s2)
#define sysStricmp(s1,s2)       stricmp(s1,s2)
#define sysStrncmp(s1,s2,n)     strncmp(s1,s2,n)
#define sysStrnicmp(s1,s2,n)    strnicmp(s1,s2,n)

#define closesocket(s)          lwip_close(s)



/*---------------------------------------------------------------------------
 *  Things needed by FTPD
 *-------------------------------------------------------------------------*/

/* Declaration of a counter variable.
   The variable is provided and exported by the operating system.
   It is incremented by the system timer. */
#define COUNTERVAR      jiffies  /* external variable that is incremented n times per second */
#define COUNTERTYPE     JIF_t    /* type of external counter variable */
#define COUNTERSTYPE    SJIF_t   /* signed type of external counter variable */
#define COUNTERTPS      HZ       /* number of ticks the counter is incremented per second */


/* socket error numbers */
#define sysGetErrno()       errno



/*---------------------------------------------------------------------------
 *  Things needed by filesys and HTTPD
 *-------------------------------------------------------------------------*/

/* Multitasking locking - done through semaphores.
 */
#define SYS_MTASK_DECLARELOCK(lock)     POSSEMA_t lock;
#define SYS_MTASK_CREATELOCK(lock)      lock = posSemaCreate(1)
#define SYS_MTASK_DESTROYLOCK(lock)     posSemaDestroy(lock)
#define SYS_MTASK_LOCK(lock)            posSemaGet(lock)
#define SYS_MTASK_UNLOCK(lock)          posSemaSignal(lock)


#endif /* MY_SYS_H */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -