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

📄 pos_nano.h

📁 picoos源码。The RTOS and the TCP/IP stack will be built automatically.
💻 H
📖 第 1 页 / 共 5 页
字号:
    args[2] = (NOSARG_t)(a3); args[3] = (NOSARG_t)(a4); \
    n_sprintFormattedN(buf, fmt, args); \
  } while(0);

#define nosSPrintf5(buf, 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_sprintFormattedN(buf, fmt, args); \
  } while(0);

#define nosSPrintf6(buf, 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_sprintFormattedN(buf, fmt, args); \
  } while(0);

#endif /* DOX!=0 */
#endif /* NOSCFG_FEATURE_SPRINTF */
#undef NANOEXT
/** @} */



/*---------------------------------------------------------------------------
 *  BOTTOM HALFS
 *-------------------------------------------------------------------------*/

/** @defgroup bhalf Bottom Halfs
 * @ingroup userapin
 * 
 * <b> Note: This API is part of the nano layer </b>
 *
 * Interrupt service routines can be divided into to halfs: the top and
 * the bottom half. The top half is that piece of code, that is directly
 * executed when the processor gets an hardware interrupt signalled.
 * This code is usually executed with globally disabled interrupts. Thus,
 * a second interrupt that happens while the first interrupt is still
 * serviced, will be delayed until the processor has left the currently
 * running ISR again. To minimize interrupt delay, only the critical part
 * of the ISR (the top half) is executed at interrupt level, all non
 * critical code is executed at task level (bottom half). Because the bottom
 * half is interruptable, critical interrupts won't be delayed too much.
 * @{
 */

#ifdef _N_BHALF_C
#define NANOEXT
#else
#define NANOEXT extern
#endif

#if DOX!=0 || NOSCFG_FEATURE_BOTTOMHALF != 0
/**
 * Bottom half function. Registers a new bottom half.
 * @param   number      Number of the bottom half. Must be between
 *                      0 and ::NOS_MAX_BOTTOMHALFS - 1.
 * @param   func        pointer to the bottom half function that shall be
 *                      executed when the bottom half is triggered.
 * @param   arg         optional argument passed to function func.
 * @return  Zero on success. Nonzero values denote an error.
 * @note    To unregister a bottom half function again, you may call
 *          this function with funcptr = NULL, or alternatively,
 *          you can use the macro ::nosBottomHalfUnregister. @n
 *          ::NOSCFG_FEATURE_BOTTOMHALF must be defined to 1
 *          to enable bottom half support.
 * @note    Important! A bottom half function is not allowed to block,
 *          that means such a function must not call functions that
 *          may block (for example, this functions are nosTaskSleep,
 *          nosSemaGet, nosSemaWait, nosMutexLock).
 * @sa      nosBottomHalfUnregister, nosBottomHalfStart
 */
NANOEXT VAR_t  nosBottomHalfRegister(UVAR_t number, NOSBHFUNC_t func,
                                     void *arg);

/**
 * Bottom half function. Unregisters a bottom half.
 * @param   number      Number of the bottom half to unregister.
 *                      Must be between 0 and ::NOS_MAX_BOTTOMHALFS - 1.
 * @return  Zero on success. Nonzero values denote an error.
 * @note    ::NOSCFG_FEATURE_BOTTOMHALF must be defined to 1
 *          to enable bottom half support.
 * @sa      nosBottomHalfRegister
 */
#define nosBottomHalfUnregister(number) \
          nosBottomHalfRegister(number, NULL, NULL)

/**
 * Bottom half function. Triggers a bottom half function.
 * The bottom half is executed when the interrupt level is left.
 * @param   number      Number of the bottom half. Must be between
 *                      0 and ::NOS_MAX_BOTTOMHALFS - 1.
 * @note    This function is called by the top half of an
 *          interrupt service routine. The ISR that calls this function
 *          does not need to call ::c_pos_intEnter before. @n
 *          ::NOSCFG_FEATURE_BOTTOMHALF must be defined to 1
 *          to enable bottom half support.
 * @sa      nosBottomHalfRegister, nosBottomHalfUnregister
 */
NANOEXT void nosBottomHalfStart(UVAR_t number);

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



/*---------------------------------------------------------------------------
 *  REGISTRY
 *-------------------------------------------------------------------------*/

/** @defgroup registry Registry
 * @ingroup userapin
 * 
 * <b> Note: This API is part of the nano layer </b>
 *
 * Registry keys are short ASCII texts that are assigned to binary numbers
 * like integers or pointers. pico]OS uses registry keys in two ways: @n@n
 * First, this keys are used to identify resources, such as tasks,
 * semaphores and timers. So it is possible to create named semaphores,
 * that are accessible by every program module that knows the name of
 * the semaphore (the program module does not need to know the exact
 * semaphore handle, the ASCII name is sufficiennt). Also with named
 * resources it is possible to maintain a list of allocated resources,
 * e.g. this resource list can be printed out to a shell window. @n@n
 * Second, registry keys can be used by an application to maintain a
 * central storage with setup and configuration data. This is known
 * as "the registry" in MS Windows operating systems.
 * @{
 */

#ifdef _N_REG_C
#define NANOEXT
#else
#define NANOEXT extern
#endif

#if DOX!=0 || NOSCFG_FEATURE_REGISTRY != 0

/** Generic Handle */
typedef void*  NOSGENERICHANDLE_t;

/** Registry Query Handle. Every registry query uses an own handle
    to the registry system.*/
typedef void*  NOSREGQHANDLE_t;

/* Generic registry key value type.
   It is on the developer how he uses the type. */
typedef union {
  void*       voidptr; /*!< pointer type, may be used for handles */
  int         integer; /*!< integer type, may be used to store numbers */
} KEYVALUE_t;

/** Registry type */
typedef enum {
  REGTYPE_TASK = 0,    /*!< task registry */
#if DOX!=0 || NOSCFG_FEATURE_SEMAPHORES != 0
  REGTYPE_SEMAPHORE,   /*!< semaphore registry */
#endif
#if DOX!=0 || NOSCFG_FEATURE_MUTEXES != 0
  REGTYPE_MUTEX,       /*!< mutex registry */
#endif
#if DOX!=0 || NOSCFG_FEATURE_FLAGS != 0
  REGTYPE_FLAG,        /*!< flag event registry */
#endif
#if DOX!=0 || NOSCFG_FEATURE_TIMER != 0
  REGTYPE_TIMER,       /*!< timer registry */
#endif
#if DOX!=0 || NOSCFG_FEATURE_USERREG != 0
  REGTYPE_USER,        /*!< user defined registry */
#endif
  REGTYPE_SEARCHALL    /*!< this is a special flag for the
                            function nosGetNameByHandle */
} NOSREGTYPE_t;
#define MIN_REGTYPE  REGTYPE_TASK
#define MAX_REGTYPE  (REGTYPE_SEARCHALL-1)


/**
 * Registry function. Searches the registry for an object name and returns
 * the handle that is assigned to the object.
 * For example, somebody can get a semaphore handle by just knowing the
 * semaphores name.
 * @param objtype   Type of the object that is searched for. Valid types are:
 *                  REGTYPE_TASK, REGTYPE_SEMAPHORE, REGTYPE_MUTEX,
 *                  REGTYPE_FLAG, REGTYPE_TIMER, REGTYPE_USER
 * @param objname   Name of the object to search for.
 * @return  The handle to the object on success,
 *          NULL if the object was not found.
 * @note    ::NOSCFG_FEATURE_REGISTRY must be defined to 1 to enable
 *          the registry and this function.@n
 * @sa nosGetNameByHandle
 */
NANOEXT NOSGENERICHANDLE_t  nosGetHandleByName(
                                 NOSREGTYPE_t objtype, const char *objname);


/**
 * Registry function. Searches the registry for a handle and returns the
 * name of the objetct.
 * @param handle    Object-handle to search the registry for.
 * @param buffer    If the object could be found in the registry,
 *                  the name of the object will be stored in this buffer.
 * @param bufsize   Size of the buffer in bytes. The size should be at
 *                  least ::NOS_MAX_REGKEYLEN + 1.
 * @param what      What to search for. If the type of the handle is known,
 *                  this parameter should be set to
 *                  REGTYPE_TASK, REGTYPE_SEMAPHORE, REGTYPE_MUTEX,
 *                  REGTYPE_FLAG, REGTYPE_TIMER or REGTYPE_USER.
 *                  If the object type is unknown, you may specify
 *                  REGTYPE_SEARCHALL. But note that the user branch of
 *                  the registry will not be included into the search.
 * @note    ::NOSCFG_FEATURE_REGISTRY must be defined to 1 to enable
 *          the registry and this function.@n
 * @sa nosGetHandleByName
 */
NANOEXT VAR_t nosGetNameByHandle(NOSGENERICHANDLE_t handle,
                                 char *buffer, VAR_t bufsize,
                                 NOSREGTYPE_t what);

#if DOX!=0  ||  NOSCFG_FEATURE_USERREG != 0
/**
 * Registry function. Sets a key value or creates a new registry key string.
 * This function is used to assign a binary value to a text string.
 * If the user knows the text string, he can call ::nosRegGet to
 * get the binary value that is associated with the text string.
 * @param   keyname   text string, name of the registry key to create or set
 * @param   keyvalue  binary value that shall be assigned to the registry key
 * @return  Zero on success. Nonzero values denote an error.
 * @note    When creating a new registry key string, you can use the asteriks
 *          joker sign as last character in the registry key string. This
 *          function will replace the asteriks character by a decimal number,
 *          so that the generated registry key will be unique. @n
 *          ::NOSCFG_FEATURE_REGISTRY and ::NOSCFG_FEATURE_USERREG
 *          must be defined to 1 to enable the registry and this function.@n
 *          The maximum length of a registry key string is ::NOS_MAX_REGKEYLEN.
 * @sa nosRegGet, nosRegDel
 */
NANOEXT VAR_t nosRegSet(const char *keyname, KEYVALUE_t keyvalue);

/**
 * Registry function. Returns the binary value that is assigned to a
 * registry key. This function is the counterpart to function ::nosRegSet.
 * @param   keyname     text string that binary value shall be returned
 * @param   keyvalue    Pointer to a variable of type KEYVALUE_t.
 *                      When the function succeeds (the text string
 *                      could be found), the value that is associated
 *                      with the registry key is stored in this variable.
 * @return  Zero on success. Nonzero values denote an error.
 * @note    ::NOSCFG_FEATURE_REGISTRY and ::NOSCFG_FEATURE_USERREG
 *          must be defined to 1 to enable the registry and this function.
 * @sa nosRegSet, nosRegDel
 */
NANOEXT VAR_t nosRegGet(const char *keyname, KEYVALUE_t *keyvalue);

/**
 * Registry function. Deletes a registry key string.
 * @param   keyname     Name of the registry key string to delete.
 * @return  Zero on success. Nonzero values denote an error.
 * @note    ::NOSCFG_FEATURE_REGISTRY and ::NOSCFG_FEATURE_USERREG
 *          must be defined to 1 to enable the registry and this function.
 * @sa nosRegSet, nosRegGet
 */
NANOEXT VAR_t nosRegDel(const char *keyname);
#endif

#if DOX!=0 || NOSCFG_FEATURE_REGQUERY != 0
/**
 * Registry function. Queries a list of registry keys.
 * This function starts a new registry query.
 * @param   type        Type of the registry to query:
 *                      - REGTYPE_TASK:      query list of task handles
 *                      - REGTYPE_SEMAPHORE: query list of semaphore handles
 *                      - REGTYPE_MUTEX:     query list of mutex handles
 *                      - REGTYPE_FLAG:      query list of flag event handles
 *                      - REGTYPE_TIMER:     query list of timer handles
 *                      - REGTYPE_USER:  query list of user values (registry)
 * @return  Handle to the new query. NULL is returned on error.
 * @note    In the current implementation, only one registry query can run
 *          at a time. The next query can start when the first query
 *          is finnished (function ::nosRegQueryEnd called). @n
 *          As long as the user queries the registry, all other operating system
 *          functions that try to access the registry will be blocked. @n
 *          ::NOSCFG_FEATURE_REGISTRY and ::NOSCFG_FEATURE_REGQUERY
 *          must be defined to 1 to enable the registry and this function.
 * @sa nosRegQueryElem, nosRegQueryEnd
 */
NANOEXT NOSREGQHANDLE_t  nosRegQueryBegin(NOSREGTYPE_t type);

/**
 * Registry function. Returns the next found element in a query.
 * @param   qh          Handle to the current query 
 *                      (returnvalue of ::nosRegQueryBegin).
 * @param   genh        Pointer to a (user provided) generic handle variable.
 *                      In this variable the handle of the next found
 *                      registry key will be stored. For user registry keys
 *                      (REGTYPE_USER), this is the KEYVALUE_t.voidptr
 * @param   namebuf     Pointer to a (user provided) character buffer.
 *                      The buffer is filled with the name of the next
 *                      registry key that is found. The buffer must have
 *                      at least a size of NOS_MAX_REGKEYLEN+1 characters.
 * @param   bufsize     Size of namebuf in bytes.
 * @return  Zero on success (E_OK). A negative value denotes an error.
 *          -E_NOMORE is returned when the end of the query is reached.
 * @note    ::NOSCFG_FEATURE_REGISTRY and ::NOSCFG_FEATURE_REGQUERY
 *          must be defined to 1 to enable the registry and this function.
 * @sa nosRegQueryBegin, nosRegQueryEnd
 */
NANOEXT VAR_t nosRegQueryElem(NOSREGQHANDLE_t qh, NOSGENERICHANDLE_t *genh,
                              char* namebuf, VAR_t bufsize);

/**
 * Registry function. Finnishes a query.
 * This function is the counterpart to ::nosRegQueryBegin.
 * @param   qh          Handle to the current query 
 *                      (returnvalue of ::nosRegQueryBegin).
 * @return  Zero on success. A negative value denotes an error.
 * @note    ::NOSCFG_FEATURE_REGISTRY and ::NOSCFG_FEATURE_REGQUERY
 *          must be defined to 1 to enable the registry and this function.
 * @sa nosRegQueryBegin, nosRegQueryElem
 */
NANOEXT void nosRegQueryEnd(NOSREGQHANDLE_t qh);
#endif

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



/*---------------------------------------------------------------------------
 *  CPU USAGE
 *-------------------------------------------------------------------------*/

#if (DOX!=0) || (NOSCFG_FEATURE_CPUUSAGE != 0)
/** @defgroup cpuusage CPU Usage Calculation
 * @ingroup userapin
 * The nano layer features CPU usage measurement. If this feature is
 * enabled, the system start is delayed for approximately one second that
 * is needed to calibrate the idle loop counter.

⌨️ 快捷键说明

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