V1.0
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
/**
|
||||
****************************************************************************************
|
||||
*
|
||||
* @file ke.h
|
||||
*
|
||||
* @brief This file contains the definition of the kernel environment.
|
||||
*
|
||||
* Copyright (C) RivieraWaves 2009-2015
|
||||
*
|
||||
*
|
||||
****************************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef _KE_H_
|
||||
#define _KE_H_
|
||||
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @addtogroup ENV Environment
|
||||
* @ingroup KERNEL
|
||||
* @brief Kernel Environment
|
||||
*
|
||||
* @{
|
||||
****************************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
* INCLUDE FILES
|
||||
****************************************************************************************
|
||||
*/
|
||||
|
||||
#include "rwip_config.h" // stack configuration
|
||||
|
||||
#include <stdbool.h> // standard boolean definitions
|
||||
#include <stdint.h> // standard integer definitions
|
||||
|
||||
/*
|
||||
* ENUMERATION
|
||||
****************************************************************************************
|
||||
*/
|
||||
|
||||
/// Kernel Error Status
|
||||
enum KE_STATUS
|
||||
{
|
||||
KE_SUCCESS = 0,
|
||||
KE_FAIL
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* FUNCTION DECLARATIONS
|
||||
****************************************************************************************
|
||||
*/
|
||||
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @brief This function performs all the initializations of the kernel.
|
||||
*
|
||||
* It initializes first the heap, then the message queues and the events. Then if required
|
||||
* it initializes the trace.
|
||||
*
|
||||
****************************************************************************************
|
||||
*/
|
||||
void ke_init(void);
|
||||
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @brief This function flushes all messages currently pending in the kernel.
|
||||
*
|
||||
****************************************************************************************
|
||||
*/
|
||||
void ke_flush(void);
|
||||
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @brief This function checks if sleep is possible or kernel is processing
|
||||
*
|
||||
* @return True if sleep is allowed, false otherwise
|
||||
****************************************************************************************
|
||||
*/
|
||||
bool ke_sleep_check(void);
|
||||
|
||||
#if (KE_PROFILING)
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @brief This function gets the statistics of the kernel usage.
|
||||
*
|
||||
* @param[out] max_msg_sent Max message sent
|
||||
* @param[out] max_msg_saved Max message saved
|
||||
* @param[out] max_timer_used Max timer used
|
||||
* @param[out] max_heap_used Max heap used
|
||||
****************************************************************************************
|
||||
*/
|
||||
enum KE_STATUS ke_stats_get(uint8_t* max_msg_sent,
|
||||
uint8_t* max_msg_saved,
|
||||
uint8_t* max_timer_used,
|
||||
uint16_t* max_heap_used);
|
||||
#endif //KE_PROFILING
|
||||
|
||||
/// @} KE
|
||||
|
||||
#endif // _KE_H_
|
||||
@@ -0,0 +1,152 @@
|
||||
/**
|
||||
****************************************************************************************
|
||||
*
|
||||
* @file ke_event.h
|
||||
*
|
||||
* @brief This file contains the definition related to kernel events.
|
||||
*
|
||||
* Copyright (C) RivieraWaves 2009-2015
|
||||
*
|
||||
*
|
||||
****************************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef _KE_EVENT_H_
|
||||
#define _KE_EVENT_H_
|
||||
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @addtogroup EVT Events and Schedule
|
||||
* @ingroup KERNEL
|
||||
* @brief Event scheduling module.
|
||||
*
|
||||
* The KE_EVT module implements event scheduling functions. It can be used to
|
||||
* implement deferred actions.
|
||||
*
|
||||
* @{
|
||||
****************************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
* INCLUDE FILES
|
||||
****************************************************************************************
|
||||
*/
|
||||
|
||||
#include "rwip_config.h" // stack configuration
|
||||
|
||||
#include <stdint.h> // standard integer definition
|
||||
|
||||
|
||||
/*
|
||||
* CONSTANTS
|
||||
****************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/// Status of ke_task API functions
|
||||
enum KE_EVENT_STATUS
|
||||
{
|
||||
KE_EVENT_OK = 0,
|
||||
KE_EVENT_FAIL,
|
||||
KE_EVENT_UNKNOWN,
|
||||
KE_EVENT_CAPA_EXCEEDED,
|
||||
KE_EVENT_ALREADY_EXISTS,
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* TYPE DEFINITION
|
||||
****************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* FUNCTION PROTOTYPES
|
||||
****************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @brief Initialize Kernel event module.
|
||||
****************************************************************************************
|
||||
*/
|
||||
void ke_event_init(void);
|
||||
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @brief Register an event callback.
|
||||
*
|
||||
* @param[in] event_type Event type.
|
||||
* @param[in] p_callback Pointer to callback function.
|
||||
*
|
||||
* @return Status
|
||||
****************************************************************************************
|
||||
*/
|
||||
uint8_t ke_event_callback_set(uint8_t event_type, void (*p_callback)(void));
|
||||
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @brief Set an event
|
||||
*
|
||||
* This primitive sets one event. It will trigger the call to the corresponding event
|
||||
* handler in the next scheduling call.
|
||||
*
|
||||
* @param[in] event_type Event to be set.
|
||||
****************************************************************************************
|
||||
*/
|
||||
void ke_event_set(uint8_t event_type);
|
||||
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @brief Clear an event
|
||||
*
|
||||
* @param[in] event_type Event to be cleared.
|
||||
****************************************************************************************
|
||||
*/
|
||||
void ke_event_clear(uint8_t event_type);
|
||||
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @brief Get the status of an event
|
||||
*
|
||||
* @param[in] event_type Event to get.
|
||||
*
|
||||
* @return Event status (0: not set / 1: set)
|
||||
****************************************************************************************
|
||||
*/
|
||||
uint8_t ke_event_get(uint8_t event_type);
|
||||
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @brief Get all event status
|
||||
*
|
||||
* @return Events bit field
|
||||
****************************************************************************************
|
||||
*/
|
||||
uint32_t ke_event_get_all(void);
|
||||
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @brief Flush all pending events.
|
||||
****************************************************************************************
|
||||
*/
|
||||
void ke_event_flush(void);
|
||||
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @brief Event scheduler entry point.
|
||||
*
|
||||
* This primitive is the entry point of Kernel event scheduling.
|
||||
****************************************************************************************
|
||||
*/
|
||||
void ke_event_schedule(void);
|
||||
|
||||
|
||||
|
||||
/// @} EVT
|
||||
|
||||
#endif //_KE_EVENT_H_
|
||||
@@ -0,0 +1,153 @@
|
||||
/**
|
||||
****************************************************************************************
|
||||
*
|
||||
* @file ke_mem.h
|
||||
*
|
||||
* @brief API for the heap management module.
|
||||
*
|
||||
* Copyright (C) RivieraWaves 2009-2015
|
||||
*
|
||||
*
|
||||
****************************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef _KE_MEM_H_
|
||||
#define _KE_MEM_H_
|
||||
|
||||
#include "rwip_config.h" // IP configuration
|
||||
#include <stdint.h> // standard integer
|
||||
#include <stdbool.h> // standard includes
|
||||
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @defgroup MEM Memory
|
||||
* @ingroup KERNEL
|
||||
* @brief Heap management module.
|
||||
*
|
||||
* This module implements heap management functions that allow initializing heap,
|
||||
* allocating and freeing memory.
|
||||
*
|
||||
* @{
|
||||
****************************************************************************************
|
||||
*/
|
||||
|
||||
// forward declarations
|
||||
struct mblock_free;
|
||||
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @brief Heap initialization.
|
||||
*
|
||||
* This function performs the following operations:
|
||||
* - sanity checks
|
||||
* - check memory allocated is at least large enough to hold two block descriptors to hold
|
||||
* start and end
|
||||
* - initialize the first and last descriptors
|
||||
* - save heap into kernel environment variable.
|
||||
*
|
||||
* @param[in] type Memory type.
|
||||
* @param[in|out] heap Heap pointer
|
||||
* @param[in] heap_size Size of the heap
|
||||
*
|
||||
*
|
||||
****************************************************************************************
|
||||
*/
|
||||
void ke_mem_init(uint8_t type, uint8_t* heap, uint16_t heap_size);
|
||||
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @brief Allocation of a block of memory.
|
||||
*
|
||||
* Allocates a memory block whose size is size; if no memory is available return NULL
|
||||
*
|
||||
* @param[in] size Size of the memory area that need to be allocated.
|
||||
* @param[in] type Type of memory block
|
||||
*
|
||||
* @return A pointer to the allocated memory area.
|
||||
*
|
||||
****************************************************************************************
|
||||
*/
|
||||
void *ke_malloc(uint32_t size, uint8_t type);
|
||||
|
||||
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @brief Check if it's possible to allocate a block of memory with a specific size.
|
||||
*
|
||||
* @param[in] size Size of the memory area that need to be allocated.
|
||||
* @param[in] type Type of memory block
|
||||
*
|
||||
* @return True if memory block can be allocated, False else.
|
||||
*
|
||||
****************************************************************************************
|
||||
*/
|
||||
bool ke_check_malloc(uint32_t size, uint8_t type);
|
||||
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @brief Freeing of a block of memory.
|
||||
*
|
||||
* Free the memory area pointed by mem_ptr : mark the block as free and insert it in
|
||||
* the pool of free block.
|
||||
*
|
||||
* @param[in] mem_ptr Pointer to the memory area that need to be freed.
|
||||
*
|
||||
****************************************************************************************
|
||||
*/
|
||||
void ke_free(void *mem_ptr);
|
||||
|
||||
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @brief Check if current heap is empty or not (not used)
|
||||
*
|
||||
* @param[in] type Type of memory heap block
|
||||
*
|
||||
* @return true if heap not used, false else.
|
||||
****************************************************************************************
|
||||
*/
|
||||
bool ke_mem_is_empty(uint8_t type);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @brief Check if current pointer is free or not
|
||||
*
|
||||
* @param[in] mem_ptr pointer to a memory block
|
||||
*
|
||||
* @return true if already free, false else.
|
||||
****************************************************************************************
|
||||
*/
|
||||
bool ke_is_free(void* mem_ptr);
|
||||
|
||||
#if (KE_PROFILING)
|
||||
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @brief Retrieve memory usage of selected heap.
|
||||
*
|
||||
* @param[in] type Type of memory heap block
|
||||
*
|
||||
* @return current memory usage of current heap.
|
||||
****************************************************************************************
|
||||
*/
|
||||
uint16_t ke_get_mem_usage(uint8_t type);
|
||||
|
||||
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @brief Retrieve max memory usage of all heap.
|
||||
* This command also resets max measured value.
|
||||
*
|
||||
* @return max memory usage of all heap.
|
||||
****************************************************************************************
|
||||
*/
|
||||
uint32_t ke_get_max_mem_usage(void);
|
||||
|
||||
#endif // (KE_PROFILING)
|
||||
|
||||
///@} MEM
|
||||
|
||||
#endif // _KE_MEM_H_
|
||||
|
||||
@@ -0,0 +1,320 @@
|
||||
/**
|
||||
****************************************************************************************
|
||||
*
|
||||
* @file ke_msg.h
|
||||
*
|
||||
* @brief This file contains the definition related to message scheduling.
|
||||
*
|
||||
* Copyright (C) RivieraWaves 2009-2015
|
||||
*
|
||||
*
|
||||
****************************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef _KE_MSG_H_
|
||||
#define _KE_MSG_H_
|
||||
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @defgroup MSG Message Exchange
|
||||
* @ingroup KERNEL
|
||||
* @brief Message scheduling module.
|
||||
*
|
||||
* The MSG module implements message scheduling functions.
|
||||
|
||||
* A kernel message has an ID, a receiver task ID and a source task ID.
|
||||
* In most cases, it also has parameters which are defined in
|
||||
* a structure dynamically embedded in the message structure,
|
||||
* so the whole message will be managed internally as one block.
|
||||
*
|
||||
* A message can also have one extra parameter which is referenced
|
||||
* in the normal parameter structure. This extra block is assumed
|
||||
* to be large by the kernel and will be moved by DMA if needed.
|
||||
* This feature allows moving MMPDU from LMAC to UMAC.
|
||||
*
|
||||
* In order to send a message, a function first have to allocate
|
||||
* the memory for this message. It can be done with the wrapper
|
||||
* macro KE_MSG_ALLOC() (which will call ke_msg_alloc()).
|
||||
|
||||
* The message can then be sent with ke_msg_send(). The kernel
|
||||
* will take care of freeing the allocated memory.
|
||||
|
||||
* If the message has no parameters, the ke_msg_send_basic() function
|
||||
* can be used.
|
||||
*
|
||||
* @{
|
||||
****************************************************************************************
|
||||
*/
|
||||
|
||||
#include <stddef.h> // standard definition
|
||||
#include <stdint.h> // standard integer
|
||||
#include <stdbool.h> // standard boolean
|
||||
#include "arch.h" // architectural definition
|
||||
#include "compiler.h" // compiler definition
|
||||
#include "co_list.h" // list definition
|
||||
|
||||
/// Task Identifier. Composed by the task type and the task index.
|
||||
typedef uint16_t ke_task_id_t;
|
||||
|
||||
/// Builds the task identifier from the type and the index of that task.
|
||||
#define KE_BUILD_ID(type, index) ( (ke_task_id_t)(((index) << 8)|(type)) )
|
||||
|
||||
/// Retrieves task type from task id.
|
||||
#define KE_TYPE_GET(ke_task_id) ((ke_task_id) & 0xFF)
|
||||
|
||||
/// Retrieves task index number from task id.
|
||||
#define KE_IDX_GET(ke_task_id) (((ke_task_id) >> 8) & 0xFF)
|
||||
|
||||
/// Task State
|
||||
typedef uint8_t ke_state_t;
|
||||
|
||||
/// Message Identifier. The number of messages is limited to 0xFFFF.
|
||||
/// The message ID is divided in two parts:
|
||||
/// bits[15~8]: task index (no more than 255 tasks support)
|
||||
/// bits[7~0]: message index(no more than 255 messages per task)
|
||||
/*@TRACE*/
|
||||
typedef uint16_t ke_msg_id_t;
|
||||
|
||||
/// Message structure.
|
||||
typedef struct ke_msg
|
||||
{
|
||||
struct co_list_hdr hdr; ///< List header for chaining
|
||||
|
||||
ke_msg_id_t id; ///< Message id.
|
||||
ke_task_id_t dest_id; ///< Destination kernel identifier.
|
||||
ke_task_id_t src_id; ///< Source kernel identifier.
|
||||
uint16_t param_len; ///< Parameter embedded struct length.
|
||||
uint32_t param[__ARRAY_EMPTY]; ///< Parameter embedded struct. Must be word-aligned.
|
||||
} ke_msg_t;
|
||||
|
||||
|
||||
/// Status returned by a task when handling a message
|
||||
/*@TRACE*/
|
||||
enum ke_msg_status_tag
|
||||
{
|
||||
KE_MSG_CONSUMED = 0, ///< consumed, msg and ext are freed by the kernel
|
||||
KE_MSG_NO_FREE, ///< consumed, nothing is freed by the kernel
|
||||
KE_MSG_SAVED, ///< not consumed, will be pushed in the saved queue
|
||||
};
|
||||
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @brief Convert a parameter pointer to a message pointer
|
||||
*
|
||||
* @param[in] param_ptr Pointer to the parameter member of a ke_msg
|
||||
* Usually retrieved by a ke_msg_alloc()
|
||||
*
|
||||
* @return The pointer to the ke_msg
|
||||
****************************************************************************************
|
||||
*/
|
||||
__INLINE struct ke_msg * ke_param2msg(void const *param_ptr)
|
||||
{
|
||||
return (struct ke_msg*) (((uint8_t*)param_ptr) - offsetof(struct ke_msg, param));
|
||||
}
|
||||
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @brief Convert a message pointer to a parameter pointer
|
||||
*
|
||||
* @param[in] msg Pointer to the ke_msg.
|
||||
*
|
||||
* @return The pointer to the param member
|
||||
****************************************************************************************
|
||||
*/
|
||||
__INLINE void * ke_msg2param(struct ke_msg const *msg)
|
||||
{
|
||||
return (void*) (((uint8_t*) msg) + offsetof(struct ke_msg, param));
|
||||
}
|
||||
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @brief Convenient wrapper to ke_msg_alloc()
|
||||
*
|
||||
* This macro calls ke_msg_alloc() and cast the returned pointer to the
|
||||
* appropriate structure. Can only be used if a parameter structure exists
|
||||
* for this message (otherwise, use ke_msg_send_basic()).
|
||||
*
|
||||
* @param[in] id Message identifier
|
||||
* @param[in] dest Destination Identifier
|
||||
* @param[in] src Source Identifier
|
||||
* @param[in] param_str parameter structure tag
|
||||
*
|
||||
* @return Pointer to the parameter member of the ke_msg.
|
||||
****************************************************************************************
|
||||
*/
|
||||
#define KE_MSG_ALLOC(id, dest, src, param_str) \
|
||||
(struct param_str*) ke_msg_alloc(id, dest, src, sizeof(struct param_str))
|
||||
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @brief Convenient wrapper to ke_msg_free()
|
||||
*
|
||||
* This macro calls ke_msg_free() with the appropriate msg pointer as parameter, according
|
||||
* to the message parameter pointer passed.
|
||||
*
|
||||
* @param[in] param_ptr parameter structure pointer
|
||||
****************************************************************************************
|
||||
*/
|
||||
#define KE_MSG_FREE(param_ptr) ke_msg_free(ke_param2msg((param_ptr)))
|
||||
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @brief Convenient wrapper to ke_msg_alloc()
|
||||
*
|
||||
* This macro calls ke_msg_alloc() and cast the returned pointer to the
|
||||
* appropriate structure with a variable length. Can only be used if a parameter structure exists
|
||||
* for this message (otherwise, use ke_msg_send_basic()).Can only be used if the data array is
|
||||
* located at the end of the structure.
|
||||
*
|
||||
* @param[in] id Message identifier
|
||||
* @param[in] dest Destination Identifier
|
||||
* @param[in] src Source Identifier
|
||||
* @param[in] param_str parameter structure tag
|
||||
* @param[in] length length for the data
|
||||
*
|
||||
* @return Pointer to the parameter member of the ke_msg.
|
||||
****************************************************************************************
|
||||
*/
|
||||
#define KE_MSG_ALLOC_DYN(id, dest, src, param_str,length) (struct param_str*)ke_msg_alloc(id, dest, src, \
|
||||
(sizeof(struct param_str) + (length)));
|
||||
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @brief Allocate memory for a message
|
||||
*
|
||||
* This primitive allocates memory for a message that has to be sent. The memory
|
||||
* is allocated dynamically on the heap and the length of the variable parameter
|
||||
* structure has to be provided in order to allocate the correct size.
|
||||
*
|
||||
* Several additional parameters are provided which will be preset in the message
|
||||
* and which may be used internally to choose the kind of memory to allocate.
|
||||
*
|
||||
* The memory allocated will be automatically freed by the kernel, after the
|
||||
* pointer has been sent to ke_msg_send(). If the message is not sent, it must
|
||||
* be freed explicitly with ke_msg_free().
|
||||
*
|
||||
* Allocation failure is considered critical and should not happen.
|
||||
*
|
||||
* @param[in] id Message identifier
|
||||
* @param[in] dest_id Destination Task Identifier
|
||||
* @param[in] src_id Source Task Identifier
|
||||
* @param[in] param_len Size of the message parameters to be allocated
|
||||
*
|
||||
* @return Pointer to the parameter member of the ke_msg. If the parameter
|
||||
* structure is empty, the pointer will point to the end of the message
|
||||
* and should not be used (except to retrieve the message pointer or to
|
||||
* send the message)
|
||||
****************************************************************************************
|
||||
*/
|
||||
void *ke_msg_alloc(ke_msg_id_t const id, ke_task_id_t const dest_id,
|
||||
ke_task_id_t const src_id, uint16_t const param_len);
|
||||
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @brief Message sending.
|
||||
*
|
||||
* Send a message previously allocated with any ke_msg_alloc()-like functions.
|
||||
*
|
||||
* The kernel will take care of freeing the message memory.
|
||||
*
|
||||
* Once the function have been called, it is not possible to access its data
|
||||
* anymore as the kernel may have copied the message and freed the original
|
||||
* memory.
|
||||
*
|
||||
* @param[in] param_ptr Pointer to the parameter member of the message that
|
||||
* should be sent.
|
||||
****************************************************************************************
|
||||
*/
|
||||
|
||||
void ke_msg_send(void const *param_ptr);
|
||||
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @brief Basic message sending.
|
||||
*
|
||||
* Send a message that has a zero length parameter member. No allocation is
|
||||
* required as it will be done internally.
|
||||
*
|
||||
* @param[in] id Message identifier
|
||||
* @param[in] dest_id Destination Identifier
|
||||
* @param[in] src_id Source Identifier
|
||||
****************************************************************************************
|
||||
*/
|
||||
void ke_msg_send_basic(ke_msg_id_t const id, ke_task_id_t const dest_id, ke_task_id_t const src_id);
|
||||
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @brief Message forwarding.
|
||||
*
|
||||
* Forward a message to another task by changing its destination and source tasks IDs.
|
||||
*
|
||||
* @param[in] param_ptr Pointer to the parameter member of the message that
|
||||
* should be sent.
|
||||
* @param[in] dest_id New destination task of the message.
|
||||
* @param[in] src_id New source task of the message.
|
||||
****************************************************************************************
|
||||
*/
|
||||
void ke_msg_forward(void const *param_ptr, ke_task_id_t const dest_id, ke_task_id_t const src_id);
|
||||
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @brief Message forwarding.
|
||||
*
|
||||
* Forward a message to another task by changing its message ID and its destination and source tasks IDs.
|
||||
*
|
||||
* @param[in] param_ptr Pointer to the parameter member of the message that
|
||||
* should be sent.
|
||||
* @param[in] msg_id New ID of the message.
|
||||
* @param[in] dest_id New destination task of the message.
|
||||
* @param[in] src_id New source task of the message.
|
||||
****************************************************************************************
|
||||
*/
|
||||
void ke_msg_forward_new_id(void const *param_ptr,
|
||||
ke_msg_id_t const msg_id, ke_task_id_t const dest_id, ke_task_id_t const src_id);
|
||||
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @brief Free allocated message
|
||||
*
|
||||
* @param[in] msg Pointer to the message to be freed (not the parameter member!)
|
||||
****************************************************************************************
|
||||
*/
|
||||
void ke_msg_free(struct ke_msg const *param);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @brief Retrieve destination task identifier of a kernel message
|
||||
*
|
||||
* @param[in] param_ptr Pointer to the parameter member of the message.
|
||||
*
|
||||
* @return message destination task
|
||||
****************************************************************************************
|
||||
*/
|
||||
ke_msg_id_t ke_msg_dest_id_get(void const *param_ptr);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @brief Retrieve source task identifier of a kernel message
|
||||
*
|
||||
* @param[in] param_ptr Pointer to the parameter member of the message.
|
||||
*
|
||||
* @return message source task
|
||||
****************************************************************************************
|
||||
*/
|
||||
ke_msg_id_t ke_msg_src_id_get(void const *param_ptr);
|
||||
|
||||
/**
|
||||
* Used to know if message is present in kernel queue or not.
|
||||
*
|
||||
* @param[in] param_ptr Pointer to the parameter member of the message.
|
||||
*
|
||||
* @return True if message is present in Kernel Queue, False else.
|
||||
*/
|
||||
bool ke_msg_in_queue(void const *param_ptr);
|
||||
/// @} MSG
|
||||
|
||||
#endif // _KE_MSG_H_
|
||||
@@ -0,0 +1,221 @@
|
||||
/**
|
||||
****************************************************************************************
|
||||
*
|
||||
* @file ke_task.h
|
||||
*
|
||||
* @brief This file contains the definition related to kernel task management.
|
||||
*
|
||||
* Copyright (C) RivieraWaves 2009-2015
|
||||
*
|
||||
*
|
||||
****************************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef _KE_TASK_H_
|
||||
#define _KE_TASK_H_
|
||||
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @defgroup TASK Task and Process
|
||||
* @ingroup KERNEL
|
||||
* @brief Task management module.
|
||||
*
|
||||
* This module implements the functions used for managing tasks.
|
||||
*
|
||||
* @{
|
||||
****************************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
* INCLUDE FILES
|
||||
****************************************************************************************
|
||||
*/
|
||||
#include <stdint.h> // standard integer
|
||||
#include <stdbool.h> // standard boolean
|
||||
|
||||
#include "rwip_config.h" // stack configuration
|
||||
#include "compiler.h" // compiler defines, INLINE
|
||||
#include "ke_msg.h" // kernel message defines
|
||||
|
||||
/* Default Message handler code to handle several message type in same handler. */
|
||||
#define KE_MSG_DEFAULT_HANDLER (0xFFFF)
|
||||
/* Invalid task */
|
||||
#define KE_TASK_INVALID (0xFFFF)
|
||||
/* Used to know if a message is not present in kernel queue */
|
||||
#define KE_MSG_NOT_IN_QUEUE ((struct co_list_hdr *) 0xFFFFFFFF)
|
||||
|
||||
/// Status of ke_task API functions
|
||||
enum KE_TASK_STATUS
|
||||
{
|
||||
KE_TASK_OK = 0,
|
||||
KE_TASK_FAIL,
|
||||
KE_TASK_UNKNOWN,
|
||||
KE_TASK_CAPA_EXCEEDED,
|
||||
KE_TASK_ALREADY_EXISTS,
|
||||
};
|
||||
|
||||
|
||||
#define MSG_T(msg) ((ke_task_id_t)((msg) >> 8))
|
||||
#define MSG_I(msg) ((msg) & ((1<<8)-1))
|
||||
|
||||
/// Format of a task message handler function
|
||||
typedef int (*ke_msg_func_t)(ke_msg_id_t const msgid, void const *param,
|
||||
ke_task_id_t const dest_id, ke_task_id_t const src_id);
|
||||
|
||||
/// Macro for message handler function declaration or definition
|
||||
#define KE_MSG_HANDLER(msg_name, param_struct) int msg_name##_handler(ke_msg_id_t const msgid, \
|
||||
param_struct const *param, \
|
||||
ke_task_id_t const dest_id, \
|
||||
ke_task_id_t const src_id)
|
||||
|
||||
#define KE_MSG_HANDLER_NO_STATIC(msg_name, param_struct) int msg_name##_handler(ke_msg_id_t const msgid, \
|
||||
param_struct const *param, \
|
||||
ke_task_id_t const dest_id, \
|
||||
ke_task_id_t const src_id)
|
||||
|
||||
/// Macro for message handlers table declaration or definition
|
||||
#define KE_MSG_HANDLER_TAB(task) const struct ke_msg_handler task##_msg_handler_tab[] =
|
||||
|
||||
/// Element of a message handler table.
|
||||
struct ke_msg_handler
|
||||
{
|
||||
/// Id of the handled message.
|
||||
ke_msg_id_t id;
|
||||
/// Pointer to the handler function for the msgid above.
|
||||
ke_msg_func_t func;
|
||||
};
|
||||
|
||||
/// Task descriptor grouping all information required by the kernel for the scheduling.
|
||||
typedef struct ke_task_desc
|
||||
{
|
||||
/// Pointer to the message handler table
|
||||
const struct ke_msg_handler* msg_handler_tab;
|
||||
/// Pointer to the state table (one element for each instance).
|
||||
ke_state_t* state;
|
||||
/// Maximum index of supported instances of the task.
|
||||
uint16_t idx_max;
|
||||
/// Number of messages handled
|
||||
uint16_t msg_cnt;
|
||||
} ke_task_desc_t;
|
||||
|
||||
/*
|
||||
* FUNCTION PROTOTYPES
|
||||
****************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @brief Initialize Kernel task module.
|
||||
****************************************************************************************
|
||||
*/
|
||||
void ke_task_init(void);
|
||||
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @brief Create a task.
|
||||
*
|
||||
* @param[in] task_type Task type.
|
||||
* @param[in] p_task_desc Pointer to task descriptor.
|
||||
*
|
||||
* @return Status
|
||||
****************************************************************************************
|
||||
*/
|
||||
uint8_t ke_task_create(uint8_t task_type, struct ke_task_desc const * p_task_desc);
|
||||
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @brief Delete a task.
|
||||
*
|
||||
* @param[in] task_type Task type.
|
||||
*
|
||||
* @return Status
|
||||
****************************************************************************************
|
||||
*/
|
||||
uint8_t ke_task_delete(uint8_t task_type);
|
||||
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @brief Retrieve the state of a task.
|
||||
*
|
||||
* @param[in] id Task id.
|
||||
*
|
||||
* @return Current state of the task
|
||||
****************************************************************************************
|
||||
*/
|
||||
ke_state_t ke_state_get(ke_task_id_t const id);
|
||||
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @brief Set the state of the task identified by its Task Id.
|
||||
*
|
||||
* In this function we also handle the SAVE service: when a task state changes we
|
||||
* try to activate all the messages currently saved in the save queue for the given
|
||||
* task identifier.
|
||||
*
|
||||
* @param[in] id Identifier of the task instance whose state is going to be modified
|
||||
* @param[in] state_id New State
|
||||
*
|
||||
****************************************************************************************
|
||||
*/
|
||||
void ke_state_set(ke_task_id_t const id, ke_state_t const state_id);
|
||||
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @brief Generic message handler to consume message without handling it in the task.
|
||||
*
|
||||
* @param[in] msgid Id of the message received (probably unused)
|
||||
* @param[in] param Pointer to the parameters of the message.
|
||||
* @param[in] dest_id TaskId of the receiving task.
|
||||
* @param[in] src_id TaskId of the sending task.
|
||||
*
|
||||
* @return KE_MSG_CONSUMED
|
||||
****************************************************************************************
|
||||
*/
|
||||
int ke_msg_discard(ke_msg_id_t const msgid, void const *param,
|
||||
ke_task_id_t const dest_id, ke_task_id_t const src_id);
|
||||
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @brief Generic message handler to consume message without handling it in the task.
|
||||
*
|
||||
* @param[in] msgid Id of the message received (probably unused)
|
||||
* @param[in] param Pointer to the parameters of the message.
|
||||
* @param[in] dest_id TaskId of the receiving task.
|
||||
* @param[in] src_id TaskId of the sending task.
|
||||
*
|
||||
* @return KE_MSG_CONSUMED
|
||||
****************************************************************************************
|
||||
*/
|
||||
int ke_msg_save(ke_msg_id_t const msgid, void const *param,
|
||||
ke_task_id_t const dest_id, ke_task_id_t const src_id);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @brief This function flushes all messages, currently pending in the kernel for a
|
||||
* specific task.
|
||||
*
|
||||
* @param[in] task The Task Identifier that shall be flushed.
|
||||
****************************************************************************************
|
||||
*/
|
||||
void ke_task_msg_flush(ke_task_id_t task);
|
||||
|
||||
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @brief Check validity of a task. If task type or task instance does not exist,
|
||||
* return invalid task
|
||||
*
|
||||
* @param[in] task Task Identifier to check.
|
||||
*
|
||||
* @return Task identifier if valid, invalid identifier else.
|
||||
****************************************************************************************
|
||||
*/
|
||||
ke_task_id_t ke_task_check(ke_task_id_t task);
|
||||
|
||||
/// @} TASK
|
||||
|
||||
#endif // _KE_TASK_H_
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
/**
|
||||
****************************************************************************************
|
||||
*
|
||||
* @file ke_timer.h
|
||||
*
|
||||
* @brief This file contains the definitions used for timer management
|
||||
*
|
||||
* Copyright (C) RivieraWaves 2009-2015
|
||||
*
|
||||
*
|
||||
****************************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef _KE_TIMER_H_
|
||||
#define _KE_TIMER_H_
|
||||
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @defgroup TIMER BT Time
|
||||
* @ingroup KERNEL
|
||||
* @brief Timer management module.
|
||||
*
|
||||
* This module implements the functions used for managing kernel timers.
|
||||
*
|
||||
****************************************************************************************
|
||||
*/
|
||||
|
||||
#include "rwip.h" // RW definitions
|
||||
#include "rwip_config.h" // stack configuration
|
||||
#include "ke_msg.h" // messaging definition
|
||||
|
||||
|
||||
/*
|
||||
* DEFINITIONS
|
||||
****************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* TYPE DEFINITIONS
|
||||
****************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* FUNCTION PROTOTYPES
|
||||
****************************************************************************************
|
||||
*/
|
||||
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @brief This function flushes all timers pending in the kernel.
|
||||
*
|
||||
****************************************************************************************
|
||||
*/
|
||||
void ke_timer_flush(void);
|
||||
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @brief Set a timer.
|
||||
*
|
||||
* The function first cancel the timer if it is already existing, then
|
||||
* it creates a new one. The timer can be one-shot or periodic, i.e. it
|
||||
* will be automatically set again after each trigger.
|
||||
*
|
||||
* When the timer expires, a message is sent to the task provided as
|
||||
* argument, with the timer id as message id.
|
||||
*
|
||||
*
|
||||
* @param[in] timer_id Timer identifier (message identifier type).
|
||||
* @param[in] task_id Task identifier which will be notified
|
||||
* @param[in] delay Delay in time milliseconds.
|
||||
****************************************************************************************
|
||||
*/
|
||||
void ke_timer_set(ke_msg_id_t const timer_id, ke_task_id_t const task, uint32_t delay_ms);
|
||||
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @brief Remove an registered timer.
|
||||
*
|
||||
* This function search for the timer identified by its id and its task id.
|
||||
* If found it is stopped and freed, otherwise an error message is returned.
|
||||
*
|
||||
* @param[in] timer_id Timer identifier.
|
||||
* @param[in] task Task identifier.
|
||||
****************************************************************************************
|
||||
*/
|
||||
void ke_timer_clear(ke_msg_id_t const timerid, ke_task_id_t const task);
|
||||
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @brief Checks if a requested timer is active.
|
||||
*
|
||||
* This function pops the first timer from the timer queue and notifies the appropriate
|
||||
* task by sending a kernel message. If the timer is periodic, it is set again;
|
||||
* if it is one-shot, the timer is freed. The function checks also the next timers
|
||||
* and process them if they have expired or are about to expire.
|
||||
****************************************************************************************
|
||||
*/
|
||||
bool ke_timer_active(ke_msg_id_t const timer_id, ke_task_id_t const task_id);
|
||||
|
||||
|
||||
/// @} TIMER
|
||||
|
||||
#endif // _KE_TIMER_H_
|
||||
@@ -0,0 +1,65 @@
|
||||
/**
|
||||
****************************************************************************************
|
||||
*
|
||||
* @file ke_env.h
|
||||
*
|
||||
* @brief This file contains the definition of the kernel.
|
||||
*
|
||||
* Copyright (C) RivieraWaves 2009-2015
|
||||
*
|
||||
*
|
||||
****************************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef _KE_ENV_H_
|
||||
#define _KE_ENV_H_
|
||||
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @addtogroup ENV Environment
|
||||
* @ingroup KERNEL
|
||||
* @brief Kernel Environment
|
||||
*
|
||||
* @{
|
||||
****************************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
* INCLUDE FILES
|
||||
****************************************************************************************
|
||||
*/
|
||||
#include "rwip_config.h" // stack configuration
|
||||
#include "ke_event.h" // kernel event
|
||||
#include "co_list.h" // kernel queue definition
|
||||
|
||||
// forward declaration
|
||||
struct mblock_free;
|
||||
|
||||
/// Kernel environment definition
|
||||
struct ke_env_tag
|
||||
{
|
||||
/// Queue of sent messages but not yet delivered to receiver
|
||||
struct co_list queue_sent;
|
||||
/// Queue of messages delivered but not consumed by receiver
|
||||
struct co_list queue_saved;
|
||||
/// Queue of timers
|
||||
struct co_list queue_timer;
|
||||
/// Root pointer = pointer to first element of heap linked lists
|
||||
struct mblock_free * heap[KE_MEM_BLOCK_MAX];
|
||||
/// Size of heaps
|
||||
uint16_t heap_size[KE_MEM_BLOCK_MAX];
|
||||
|
||||
#if (KE_PROFILING)
|
||||
/// Size of heap used
|
||||
uint16_t heap_used[KE_MEM_BLOCK_MAX];
|
||||
/// Maximum heap memory used
|
||||
uint32_t max_heap_used;
|
||||
#endif //KE_PROFILING
|
||||
};
|
||||
|
||||
/// Kernel environment
|
||||
extern struct ke_env_tag ke_env;
|
||||
|
||||
/// @} ENV
|
||||
|
||||
#endif // _KE_ENV_H_
|
||||
@@ -0,0 +1,107 @@
|
||||
/**
|
||||
****************************************************************************************
|
||||
*
|
||||
* @file ke_queue.h
|
||||
*
|
||||
* @brief This file contains the definition of the message object, queue element
|
||||
* object and queue object
|
||||
*
|
||||
* Copyright (C) RivieraWaves 2009-2015
|
||||
*
|
||||
*
|
||||
****************************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef _KE_QUEUE_H_
|
||||
#define _KE_QUEUE_H_
|
||||
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @addtogroup QUEUE Queues and Lists
|
||||
* @ingroup KERNEL
|
||||
* @brief Queue management module
|
||||
*
|
||||
* This module implements the functions used for managing message queues.
|
||||
* These functions must not be called under IRQ!
|
||||
* @{
|
||||
****************************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
* INCLUDE FILES
|
||||
****************************************************************************************
|
||||
*/
|
||||
#include <stdint.h> // standard integer
|
||||
#include <stdbool.h> // standard boolean
|
||||
#include "compiler.h" // compiler definitions
|
||||
#include "co_list.h" // list definition
|
||||
|
||||
/*
|
||||
* FUNCTION PROTOTYPES
|
||||
****************************************************************************************
|
||||
*/
|
||||
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @brief Pop entry to the queue
|
||||
*
|
||||
* @param[in] queue Pointer to the queue.
|
||||
* @param[in] element Pointer to the element.
|
||||
****************************************************************************************
|
||||
*/
|
||||
__INLINE void ke_queue_push(struct co_list *const queue, struct co_list_hdr *const element)
|
||||
{
|
||||
co_list_push_back(queue, element);
|
||||
}
|
||||
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @brief Pop entry from the queue
|
||||
*
|
||||
* @param[in] queue Pointer to the queue.
|
||||
*
|
||||
* @return Pointer to the element.
|
||||
****************************************************************************************
|
||||
*/
|
||||
__INLINE struct co_list_hdr *ke_queue_pop(struct co_list *const queue)
|
||||
{
|
||||
return co_list_pop_front(queue);
|
||||
}
|
||||
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @brief Extracts an element matching a given algorithm.
|
||||
*
|
||||
* @param[in] queue Pointer to the queue.
|
||||
* @param[in] func Matching function.
|
||||
* @param[in] arg Match argument.
|
||||
*
|
||||
* @return Pointer to the element found and removed (NULL otherwise).
|
||||
****************************************************************************************
|
||||
*/
|
||||
struct co_list_hdr *ke_queue_extract(struct co_list * const queue,
|
||||
bool (*func)(struct co_list_hdr const * elmt, uint32_t arg),
|
||||
uint32_t arg);
|
||||
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @brief Insert an element in a sorted queue.
|
||||
*
|
||||
* This primitive use a comparison function from the parameter list to select where the
|
||||
* element must be inserted.
|
||||
*
|
||||
* @param[in] queue Pointer to the queue.
|
||||
* @param[in] element Pointer to the element to insert.
|
||||
* @param[in] cmp Comparison function (return true if first element has to be inserted
|
||||
* before the second one).
|
||||
*
|
||||
* @return Pointer to the element found and removed (NULL otherwise).
|
||||
****************************************************************************************
|
||||
*/
|
||||
void ke_queue_insert(struct co_list * const queue, struct co_list_hdr * const element,
|
||||
bool (*cmp)(struct co_list_hdr const *elementA,
|
||||
struct co_list_hdr const *elementB));
|
||||
|
||||
/// @} QUEUE
|
||||
|
||||
#endif // _KE_QUEUE_H_
|
||||
Reference in New Issue
Block a user