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

📄 pos_nano.h

📁 picoos源码。The RTOS and the TCP/IP stack will be built automatically.
💻 H
📖 第 1 页 / 共 5 页
字号:
/*
 *  Copyright (c) 2004-2006, 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.
 *
 */


/**
 * @file    pos_nano.h
 * @brief   pico]OS nano layer main include file
 * @author  Dennis Kuschel
 *
 * This file is originally from the pico]OS realtime operating system
 * (http://picoos.sourceforge.net).
 *
 * CVS-ID $Id: pos_nano.h,v 1.7 2006/04/14 09:33:52 dkuschel Exp $
 */

#ifndef _POS_NANO_H
#define _POS_NANO_H

#ifndef DOX
#define DOX  0
#endif



/*---------------------------------------------------------------------------
 *  NANO LAYER INSTALLATION
 *-------------------------------------------------------------------------*/

/* include configuration files */
#ifndef _PICOOS_H
#include <port.h>
#include <poscfg.h>
#endif
#include <noscfg.h>


#ifndef NOSCFG_FEATURE_REGISTRY
#define NOSCFG_FEATURE_REGISTRY  0
#endif

#if POSCFG_TASKSTACKTYPE==0
#define NOS_NEEDTASKEXITHOOK
#else
#if NOSCFG_FEATURE_REGISTRY!=0
#define NOS_NEEDTASKEXITHOOK
#endif
#endif

#ifdef NOS_NEEDTASKEXITHOOK

/* define hook */
#ifdef POSCFG_TASKEXIT_HOOK
#undef POSCFG_TASKEXIT_HOOK
#endif
#define POSCFG_TASKEXIT_HOOK  1

/* set additional task data for the nano layer */
#define NOS_TASKDATA  void *nosstkroot;

#endif /* NOS_NEEDTASKEXITHOOK */

/* include pico]OS header if not yet done */
#ifndef _PICOOS_H
#include <picoos.h>
#endif



/*---------------------------------------------------------------------------
 *  CONFIGURATION
 *-------------------------------------------------------------------------*/

#ifndef NOSCFG_FEATURE_MEMALLOC
#error  NOSCFG_FEATURE_MEMALLOC not defined
#endif
#ifndef NOSCFG_FEATURE_CONIN
#error  NOSCFG_FEATURE_CONIN not defined
#endif
#ifndef NOSCFG_FEATURE_CONOUT
#error  NOSCFG_FEATURE_CONOUT not defined
#endif
#ifndef NOSCFG_CONOUT_HANDSHAKE
#error  NOSCFG_CONOUT_HANDSHAKE not defined
#endif
#ifndef NOSCFG_CONOUT_FIFOSIZE
#error  NOSCFG_CONOUT_FIFOSIZE not defined
#endif
#ifndef NOSCFG_FEATURE_PRINTF
#error  NOSCFG_FEATURE_PRINTF not defined
#endif
#ifndef NOSCFG_FEATURE_SPRINTF
#error  NOSCFG_FEATURE_SPRINTF not defined
#endif
#ifndef NOSCFG_FEATURE_TASKCREATE
#error  NOSCFG_FEATURE_TASKCREATE not defined
#endif
#ifndef NOSCFG_DEFAULT_STACKSIZE
#error  NOSCFG_DEFAULT_STACKSIZE not defined in the port configuration file
#endif
#ifndef NOSCFG_STACK_GROWS_UP
#error  NOSCFG_STACK_GROWS_UP not defined in the port configuration file
#endif
#ifndef NOSCFG_MEM_MANAGE_MODE
#error  NOSCFG_MEM_MANAGE_MODE not defined
#endif
#ifndef NOSCFG_FEATURE_MEMSET
#error  NOSCFG_FEATURE_MEMSET not defined
#endif
#ifndef NOSCFG_FEATURE_MEMCOPY
#error  NOSCFG_FEATURE_MEMCOPY not defined
#endif
#ifndef NOSCFG_STKMEM_RESERVE
#error  NOSCFG_STKMEM_RESERVE not defined
#endif
#if NOSCFG_MEM_MANAGER_TYPE == 2
#ifndef NOSCFG_MEM_USER_MALLOC
#error  NOSCFG_MEM_USER_MALLOC not defined
#endif
#ifndef NOSCFG_MEM_USER_FREE
#error  NOSCFG_MEM_USER_FREE not defined
#endif
#endif
#ifndef NOSCFG_FEATURE_BOTTOMHALF
#error  NOSCFG_FEATURE_BOTTOMHALF not defined
#endif
#if NOSCFG_FEATURE_BOTTOMHALF != 0
#ifndef NOS_MAX_BOTTOMHALFS
#error  NOS_MAX_BOTTOMHALFS not defined
#endif
#if (NOS_MAX_BOTTOMHALFS == 0) || (NOS_MAX_BOTTOMHALFS > MVAR_BITS)
#error NOS_MAX_BOTTOMHALFS must be in the range 1 .. MVAR_BITS
#endif
#endif
#ifndef NOSCFG_FEATURE_CPUUSAGE
#error  NOSCFG_FEATURE_CPUUSAGE not defined
#endif

#if NOSCFG_FEATURE_REGISTRY
#ifndef NOSCFG_FEATURE_REGQUERY
#error  NOSCFG_FEATURE_REGQUERY
#endif
#ifndef NOSCFG_FEATURE_USERREG
#error  NOSCFG_FEATURE_USERREG
#endif
#ifndef NOS_MAX_REGKEYLEN
#error  NOS_MAX_REGKEYLEN
#endif
#if NOS_MAX_REGKEYLEN < 4
#error NOS_MAX_REGKEYLEN must be at least 4
#endif
#ifndef NOS_REGKEY_PREALLOC
#error  NOS_REGKEY_PREALLOC
#endif
#else /* NOSCFG_FEATURE_REGISTRY */
#ifdef NOSCFG_FEATURE_USERREG
#undef NOSCFG_FEATURE_USERREG
#endif
#define NOSCFG_FEATURE_USERREG 0
#ifdef NOSCFG_FEATURE_REGQUERY
#undef NOSCFG_FEATURE_REGQUERY
#endif
#define NOSCFG_FEATURE_REGQUERY 0
#endif  /* NOSCFG_FEATURE_REGISTRY */

#ifndef NOSCFG_FEATURE_SEMAPHORES
#define NOSCFG_FEATURE_SEMAPHORES  0
#endif

#if NOSCFG_FEATURE_SEMAPHORES != 0  &&  POSCFG_FEATURE_SEMAPHORES == 0
#error NOSCFG_FEATURE_SEMAPHORES enabled, but pico]OS semaphores disabled
#endif

#ifndef NOSCFG_FEATURE_MUTEXES
#define NOSCFG_FEATURE_MUTEXES  0
#endif
#if NOSCFG_FEATURE_MUTEXES != 0  &&  POSCFG_FEATURE_MUTEXES == 0
#error NOSCFG_FEATURE_MUTEXES enabled, but pico]OS mutexes disabled
#endif

#ifndef NOSCFG_FEATURE_MSGBOXES
#define NOSCFG_FEATURE_MSGBOXES  0
#endif
#if NOSCFG_FEATURE_MSGBOXES != 0  &&  POSCFG_FEATURE_MSGBOXES == 0
#error NOSCFG_FEATURE_MSGBOXES enabled, but pico]OS message boxes disabled
#endif

#ifndef NOSCFG_FEATURE_FLAGS
#define NOSCFG_FEATURE_FLAGS  0
#endif
#if NOSCFG_FEATURE_FLAGS != 0  &&  POSCFG_FEATURE_FLAGS == 0
#error NOSCFG_FEATURE_FLAGS enabled, but pico]OS flag functions disabled
#endif

#ifndef NOSCFG_FEATURE_TIMER
#define NOSCFG_FEATURE_TIMER  0
#endif
#if NOSCFG_FEATURE_TIMER != 0  &&  POSCFG_FEATURE_TIMER == 0
#error NOSCFG_FEATURE_TIMER enabled, but pico]OS timer functions disabled
#endif

#ifndef NOSCFG_MEM_OVWR_STANDARD
#define NOSCFG_MEM_OVWR_STANDARD  1
#endif
#ifndef NOSCFG_FEATURE_REALLOC
#define NOSCFG_FEATURE_REALLOC    0
#endif



/*---------------------------------------------------------------------------
 *  DATA TYPES
 *-------------------------------------------------------------------------*/

#if DOX!=0 || NOSCFG_FEATURE_BOTTOMHALF != 0
/** Bottom half function pointer.
 * @param   arg         Optional argument that was set when the
 *                      bottom half was registered with
 *                      ::nosBottomHalfRegister.
 * @param   bh          Number of the bottom half
 *                      (0 .. ::NOS_MAX_BOTTOMHALFS - 1)
 */
typedef void (*NOSBHFUNC_t)(void* arg, UVAR_t bh);
#endif



/*---------------------------------------------------------------------------
 *  MEMORY MANAGEMENT
 *-------------------------------------------------------------------------*/

/** @defgroup mem Memory Management
 * @ingroup userapin
 * 
 * <b> Note: This API is part of the nano layer </b>
 *
 * The nano layer supplies a set of memory management functions.
 * pico]OS functions are thread save, thus pico]OS can replace the
 * memory allocation functions of a runtime library that was not
 * designed for a multitasking environment.
 * @{
 */

#ifdef _N_MEM_C
#define NANOEXT
#else
#define NANOEXT extern
#endif

#if DOX!=0 || NOSCFG_FEATURE_MEMALLOC != 0

/**
 * Allocate memory from the heap.
 * This function allocates a block of memory from the heap.
 * The function is thread save, thus multiple threads can access the
 * heap without corrupting it.
 * @param   size in bytes of the memory block to allocate.
 * @return  The function returns the pointer to the new memory block
 *          on success. NULL is returned when the function failed
 *          to allocate a block with the wished size.
 * @note    ::NOSCFG_FEATURE_MEMALLOC must be defined to 1 
 *          to have this function compiled in.
 * @sa      nosMemRealloc, nosMemFree, NOSCFG_MEM_MANAGER_TYPE
 */
NANOEXT void* nosMemAlloc(UINT_t size);

/**
 * Free a block of memory to the heap.
 * This function is the counterpart to ::nosMemAlloc.
 * @param   p pointer to the memory block to free.
 * @note    ::NOSCFG_FEATURE_MEMALLOC must be defined to 1 
 *          to have this function compiled in.
 * @sa      nosMemAlloc, nosMemRealloc, NOSCFG_MEM_MANAGER_TYPE
 */
NANOEXT void  nosMemFree(void *p);


#if DOX!=0 || NOSCFG_FEATURE_REALLOC != 0
/**
 * Reallocate a block of memory.
 * Sometimes it is necessary to increase or decrease the size of a
 * memory block on the heap. This function works like the usual
 * realloc(), it is optimized to keep the heap clean and unfragmented.
 * @param   memblock  pointer to the memory block on the heap.
 * @param   size  new size of the memory block (larger or smaller)
 * @return  The function returns the pointer to the new memory block
 *          on success. NULL is returned when the function failed
 *          to change the size of the block.
 * @note    ::NOSCFG_FEATURE_MEMALLOC and ::NOSCFG_FEATURE_REALLOC
 *          must be defined to 1 to have this function compiled in.
 * @note    ::nosMemRealloc reaches the best performance only when
 *          ::NOSCFG_MEM_MANAGE_MODE is set to 1
 * @sa      nosMemAlloc, nosMemFree, NOSCFG_MEM_MANAGER_TYPE
 */
NANOEXT void *nosMemRealloc(void *memblock, UINT_t size);
#endif

/* overwrite standard memory allocation functions */
#ifndef NANOINTERNAL
#if NOSCFG_MEM_OVWR_STANDARD != 0
#ifdef malloc
#undef malloc
#endif
#ifdef calloc
#undef calloc
#endif
#ifdef free
#undef free
#endif
#define malloc  nosMemAlloc
#define calloc  (not_supported)
#define free    nosMemFree
#endif /* NOSCFG_MEM_OVWR_STANDARD */
#else /* NANOINTERNAL */
/* internal malloc/free, used by OS core and platform ports */
#if NOSCFG_MEM_MANAGER_TYPE == 0
#define NOS_MEM_ALLOC(x)   malloc((size_t)(x))

⌨️ 快捷键说明

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