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

📄 pos_nano.h

📁 picoos源码。The RTOS and the TCP/IP stack will be built automatically.
💻 H
📖 第 1 页 / 共 5 页
字号:
#define NOS_MEM_FREE(x)    free(x)
#elif   NOSCFG_MEM_MANAGER_TYPE == 1
void*   nos_malloc(UINT_t size);
void    nos_free(void *mp);
#define NOS_MEM_ALLOC(x)   nos_malloc(x)
#define NOS_MEM_FREE(x)    nos_free(x)
#elif   NOSCFG_MEM_MANAGER_TYPE == 2
#define NOS_MEM_ALLOC(x)   NOSCFG_MEM_USER_MALLOC(x)
#define NOS_MEM_FREE(x)    NOSCFG_MEM_USER_FREE(x)
#endif
#endif /* NANOINTERNAL */

#endif /* NOSCFG_FEATURE_MEMALLOC */

#if DOX!=0 || NOSCFG_FEATURE_MEMSET != 0

/**
 * Fill a block of memory with a special character.
 * This function works like the memset function from the
 * C runtime library.
 * @param   buf  pointer to the destination memory block
 * @param   val  character to fill into the memory block
 * @param   count  number of bytes to fill into the block
 * @note    ::NOSCFG_FEATURE_MEMSET must be defined to 1 
 *          to have this function compiled in.
 * @sa      nosMemAlloc, nosMemCopy
 */
NANOEXT void nosMemSet(void *buf, char val, UINT_t count);

#if NOSCFG_MEM_OVWR_STANDARD != 0
#ifdef memset
#undef memset
#endif
#define memset  nosMemSet
#endif

#endif /* NOSCFG_FEATURE_MEMSET */

#if DOX!=0 || NOSCFG_FEATURE_MEMCOPY != 0

/**
 * Copy a block of memory.
 * This function works like the memcpy function from the
 * C runtime library.
 * @param   dst  pointer to the destination memory block
 * @param   src  pointer to the source memory block
 * @param   count  number of bytes to copy
 * @note    ::NOSCFG_FEATURE_MEMCOPY must be defined to 1 
 *          to have this function compiled in.
 * @sa      nosMemAlloc, nosMemSet
 */
NANOEXT void nosMemCopy(void *dst, void *src, UINT_t count);

#if NOSCFG_MEM_OVWR_STANDARD != 0
#ifdef memcpy
#undef memcpy
#endif
#define memcpy  nosMemCopy
#endif

#endif /* NOSCFG_FEATURE_MEMCOPY */
#undef NANOEXT
/** @} */



/*---------------------------------------------------------------------------
 *  CONSOLE INPUT / OUTPUT
 *-------------------------------------------------------------------------*/

/** @defgroup conio Console Input / Output
 * @ingroup userapin
 * 
 * <b> Note: This API is part of the nano layer </b>
 *
 * The nano layer supplies a set of multitasking able console I/O functions.
 * Note that the platform port must support some basic I/O mechanisms.
 * For console output, pico]OS calls the function ::p_putchar to output
 * a single character. This function may fail when a transmitter FIFO
 * ran out of space, and the function ::c_nos_putcharReady should be called
 * when the transmitter is ready again. Input from a terminal or keyboard is
 * fet into pico]OS by calling the function ::c_nos_keyinput or by rising the
 * software interrupt number zero with the keycode as parameter. Not all
 * platform ports may support console I/O, please read the port documentation
 * for further information.@n
 * Since the nano layer supplies also a set of printf and sprintf functions,
 * you may no more need a large runtime library in some special cases.
 * @{
 */

#ifdef _N_CONIO_C
#define NANOEXT
#else
#define NANOEXT extern
#endif

#if DOX!=0 || NOSCFG_FEATURE_CONIN != 0

/**
 * Keyboard input.
 * This function is called by the architecture port to feed keyboard
 * input into the nano layer.
 * @param   key  keycode of the pressed key
 * @note    ::NOSCFG_FEATURE_CONIN must be defined to 1 
 *          to have this function compiled in.@n
 *          The alternative to the use of this function is to use
 *          software interrupt 0 to feed keyboard data into the nano layer.
 * @sa      nosKeyGet, nosKeyPressed, NOSCFG_CONIO_KEYBUFSIZE
 */
NANOEXT void  c_nos_keyinput(UVAR_t key);

/**
 * Wait and get the code of the next pressed key.
 * This function blocks until the user presses a key on the keyboard
 * and returns the code of the pressed key as result.
 * @return  ASCII-code of the pressed key
 * @note    ::NOSCFG_FEATURE_CONIN must be defined to 1 
 *          to have this function compiled in.
 * @sa      nosKeyPressed, c_nos_keyinput, NOSCFG_CONIO_KEYBUFSIZE
 */
NANOEXT char  nosKeyGet(void);

/**
 * Test if a key was pressed.
 * This function tests if a key code is available in the keyboard buffer.
 * Even if no key is pressed yet, the function will immediately return.
 * @return  TRUE (nonzero) when a key code is available.
 * @note    ::NOSCFG_FEATURE_CONIN must be defined to 1 
 *          to have this function compiled in.
 * @sa      nosKeyGet, c_nos_keyinput, NOSCFG_CONIO_KEYBUFSIZE
 */
NANOEXT UVAR_t  nosKeyPressed(void);

#endif  /* NOSCFG_FEATURE_CONIN */


#if DOX!=0 || NOSCFG_FEATURE_CONOUT != 0
/**
 * Print a character to the console or terminal. This function
 * must be supplied by the architecture port; it is not callable
 * by the user.
 * @param   c  character to print out.
 * @return  This function should return nonzero (=TRUE) when the
 *          character could be printed. If the function could not
 *          print the character (e.g. the FIFO of a serial line
 *          is full), this function should return zero (=FALSE).
 *          The nano layer will try to send the character later again.
 * @note    This function must not do a CR/LF conversion, a CR
 *          must result in a simple carriage return, and a LF
 *          must result in a simple line feed without returning
 *          the carriage.
 * @note    If this function returns FALSE, the platform port
 *          must do a call to ::c_nos_putcharReady when it is
 *          ready again for accepting new characters. When
 *          ::NOSCFG_CONOUT_HANDSHAKE is disabled, the return
 *          value of this function is ignored.
 * @sa      c_nos_putcharReady, c_nos_keyinput
 */
NANOEXT UVAR_t  p_putchar(char c); 
#endif


#if DOX!=0 || NOSCFG_CONOUT_HANDSHAKE != 0
/**
 * This is the optional handshake function for ::p_putchar.
 * The handshake function is usefull for console output over
 * a serial line. The function ::p_putchar will fail when the
 * transmitter FIFO is full, and the nano layer will save the
 * last character for later transmission. The platform port
 * should than call ::c_nos_putcharReady when the transmitter
 * FIFO has space again (when the last character has left the
 * output shift register); most commonly this is signalled by
 * a hardware interrupt, that would be used to call this
 * handshake function. @n
 * The purpose of this handshaking is to reduce CPU usage
 * by avoiding polling on the standard output until the stdout
 * is ready again. In the current implementation this function
 * triggers a semaphore that wakes the task waiting for
 * service on standard out. @n
 * Note that this function must be supplied by the
 * architecture port; it is not callable by the user.
 * @note To enable this handshake function, the define
 *       ::NOSCFG_CONOUT_HANDSHAKE must be set to 1.
 */
NANOEXT void  c_nos_putcharReady(void);
#endif


#if DOX!=0 || NOSCFG_FEATURE_CONOUT != 0

/**
 * Print a character to the console or terminal.
 * This function prints a single character to the console.
 * No CR/LF conversion is performed.
 * @note    ::NOSCFG_FEATURE_CONOUT must be defined to 1 
 *          to have this function compiled in.
 * @sa      nosPrint, p_putchar
 */
NANOEXT void  nosPrintChar(char c);

/**
 * Print a character string to the console or terminal.
 * This function prints a string of characters (text) to the console.
 * A CR/LF conversion is performed, CR is preceding each LF.
 * @param   s  pointer to zero terminated ASCII string
 * @note    ::NOSCFG_FEATURE_CONOUT must be defined to 1 
 *          to have this function compiled in.
 * @sa      nosPrintChar, p_putchar
 */
NANOEXT void  nosPrint(const char *s);

#endif

#if NOSCFG_FEATURE_CONOUT == 0
#if NOSCFG_FEATURE_PRINTF != 0
#undef  NOSCFG_FEATURE_PRINTF
#define NOSCFG_FEATURE_PRINTF  0
#endif
#endif

#if NOSCFG_FEATURE_PRINTF != 0 || NOSCFG_FEATURE_SPRINTF != 0
typedef void* NOSARG_t;
#endif


#if DOX!=0 || ((NOSCFG_FEATURE_CONOUT != 0)&&(NOSCFG_FEATURE_PRINTF != 0))

NANOEXT void n_printFormattedN(const char *fmt, NOSARG_t args);

#if DOX
/**
 * Print a formated character string to the console or terminal.
 * This function acts like the usual printf function, except that
 * it is limmited to the basic formats. The largest integer that
 * can be displayed is of type INT_t.
 * @param   fmt  format string
 * @param   a1   first argument
 * @note    ::NOSCFG_FEATURE_CONOUT and ::NOSCFG_FEATURE_PRINTF 
 *          must be defined to 1
 *          to have this function compiled in.@n
 *          This function is not variadic. To print strings with
 *          more than one argument, you may use the functions
 *          nosPrintf2 (2 arguments) to nosPrintf6 (6 arguments).
 * @sa      nosPrintChar, nosPrint
 */
NANOEXT void nosPrintf1(const char *fmt, arg a1);

#else /* DOX!=0 */
#define nosPrintf1(fmt, a1)  \
  do { \
    NOSARG_t args[1]; args[0] = (NOSARG_t)(a1); \
    n_printFormattedN(fmt, args); \
  } while(0);

#define nosPrintf2(fmt, a1, a2)  \
  do { \
    NOSARG_t args[2]; args[0] = (NOSARG_t)(a1); \
    args[1] = (NOSARG_t)(a2); \
    n_printFormattedN(fmt, args); \
  } while(0);

#define nosPrintf3(fmt, a1, a2, a3)  \
  do { \
    NOSARG_t args[3]; args[0] = (NOSARG_t)(a1); \
    args[1] = (NOSARG_t)(a2); args[2] = (NOSARG_t)(a3); \
    n_printFormattedN(fmt, args); \
  } while(0);

#define nosPrintf4(fmt, a1, a2, a3, a4)  \
  do { \
    NOSARG_t args[4]; \
    args[0] = (NOSARG_t)(a1); args[1] = (NOSARG_t)(a2); \
    args[2] = (NOSARG_t)(a3); args[3] = (NOSARG_t)(a4); \
    n_printFormattedN(fmt, args); \
  } while(0);

#define nosPrintf5(fmt, a1, a2, a3, a4, a5)  \
  do { \
    NOSARG_t args[5]; args[0] = (NOSARG_t)(a1); \
    args[1] = (NOSARG_t)(a2); args[2] = (NOSARG_t)(a3); \
    args[3] = (NOSARG_t)(a4); args[4] = (NOSARG_t)(a5); \
    n_printFormattedN(fmt, args); \
  } while(0);

#define nosPrintf6(fmt, a1, a2, a3, a4, a5, a6)  \
  do { \
    NOSARG_t args[6]; \
    args[0] = (NOSARG_t)(a1); args[1] = (NOSARG_t)(a2); \
    args[2] = (NOSARG_t)(a3); args[3] = (NOSARG_t)(a4); \
    args[4] = (NOSARG_t)(a5); args[5] = (NOSARG_t)(a6); \
    n_printFormattedN(fmt, args); \
  } while(0);

#endif /* DOX!=0 */
#endif /* NOSCFG_FEATURE_PRINTF */


#if DOX!=0 || NOSCFG_FEATURE_SPRINTF != 0
#if DOX
/**
 * Print a formated character string to a string buffer.
 * This function acts like the usual sprintf function, except that
 * it is limmited to the basic formats. The largest integer that
 * can be displayed is of type INT_t.
 * @param   buf  destination string buffer
 * @param   fmt  format string
 * @param   a1   first argument
 * @note    ::NOSCFG_FEATURE_SPRINTF must be defined to 1 
 *          to have this function compiled in.@n
 *          This function is not variadic. To print strings with
 *          more than one argument, you may use the functions
 *          nosSPrintf2 (2 arguments) to nosSPrintf6 (6 arguments).
 * @sa      nosPrintf1, nosPrint
 */
NANOEXT void nosSPrintf1(char *buf, const char *fmt, arg a1);

#else /* DOX!=0 */

NANOEXT void n_sprintFormattedN(char *buf, const char *fmt, NOSARG_t args);

#define nosSPrintf1(buf, fmt, a1)  \
  do { \
    NOSARG_t args[1]; args[0] = (NOSARG_t)(a1); \
    n_sprintFormattedN(buf, fmt, args); \
  } while(0);

#define nosSPrintf2(buf, fmt, a1, a2)  \
  do { \
    NOSARG_t args[2]; args[0] = (NOSARG_t)(a1); \
    args[1] = (NOSARG_t)(a2); \
    n_sprintFormattedN(buf, fmt, args); \
  } while(0);

#define nosSPrintf3(buf, fmt, a1, a2, a3)  \
  do { \
    NOSARG_t args[3]; args[0] = (NOSARG_t)(a1); \
    args[1] = (NOSARG_t)(a2); args[2] = (NOSARG_t)(a3); \
    n_sprintFormattedN(buf, fmt, args); \
  } while(0);

#define nosSPrintf4(buf, fmt, a1, a2, a3, a4)  \
  do { \
    NOSARG_t args[4]; \
    args[0] = (NOSARG_t)(a1); args[1] = (NOSARG_t)(a2); \

⌨️ 快捷键说明

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