add event-driven framework
see examples/event_driven_at_module and examples/event_driven_hello_world, demo project: TencentOS-tiny\board\TencentOS_tiny_EVB_MX\KEIL\event_driven_hello_world
This commit is contained in:
69
kernel/evtdrv/include/tos_evtdrv_msg.h
Normal file
69
kernel/evtdrv/include/tos_evtdrv_msg.h
Normal file
@@ -0,0 +1,69 @@
|
||||
#ifndef _TOS_EVTDRV_MSG_H_
|
||||
#define _TOS_EVTDRV_MSG_H_
|
||||
|
||||
#if TOS_CFG_EVENT_DRIVEN_EN > 0u
|
||||
|
||||
typedef uint16_t evtdrv_msg_len_t;
|
||||
typedef uint8_t *evtdrv_msg_body_t;
|
||||
|
||||
typedef struct evtdrv_message_header_st {
|
||||
k_list_t list;
|
||||
evtdrv_task_id_t dst_task_id; // destination task id
|
||||
evtdrv_msg_len_t len;
|
||||
} evtdrv_msg_hdr_t;
|
||||
|
||||
#define EVTDRV_MSG_BODY2HDR(msg_body) ((evtdrv_msg_hdr_t *)((uint8_t *)msg_body - sizeof(evtdrv_msg_hdr_t)))
|
||||
#define EVTDRV_MSG_LEN(msg_len) (sizeof(evtdrv_msg_hdr_t) + msg_len)
|
||||
#define EVTDRV_MSG_HDR2BODY(msg_hdr) ((evtdrv_msg_body_t)((evtdrv_msg_hdr_t *)msg_hdr + 1))
|
||||
|
||||
/**
|
||||
* @brief Allocate a message body.
|
||||
* Allocate a message body as a payload to hold the message content.
|
||||
*
|
||||
* @attention None
|
||||
*
|
||||
* @param[in] msg_len the length of the message payload.
|
||||
*
|
||||
* @return the message body allocated.
|
||||
* @retval #NULL allocate failed.
|
||||
* @retval #NO-NULL allocate successfully.
|
||||
*/
|
||||
__API__ evtdrv_msg_body_t tos_evtdrv_msg_alloc(evtdrv_msg_len_t msg_len);
|
||||
|
||||
/**
|
||||
* @brief Free a message body.
|
||||
*
|
||||
* @attention if you wanna free a message body, the message must be "dequeued"(already received by the target task)
|
||||
*
|
||||
* @param[in] msg_body message body to free.
|
||||
*
|
||||
* @return errcode
|
||||
* @retval #EVTDRV_ERR_PTR_NULL message body is NULL.
|
||||
* @retval #EVTDRV_ERR_MSG_BUSY message is still in the message queue(not received).
|
||||
* @retval #EVTDRV_ERR_NONE free successfully.
|
||||
*/
|
||||
__API__ evtdrv_err_t tos_evtdrv_msg_free(evtdrv_msg_body_t msg_body);
|
||||
|
||||
/**
|
||||
* @brief Send a message to the target task.
|
||||
*
|
||||
* @attention next time the target task should be "wakeup" by the event of TOS_EVTDRV_SYS_EVENT_MSG.
|
||||
*
|
||||
* @param[in] task_id id of the target task.
|
||||
* @param[in] msg_body message body to send.
|
||||
*
|
||||
* @return errcode
|
||||
* @retval #EVTDRV_ERR_PTR_NULL message body is NULL.
|
||||
* @retval #EVTDRV_ERR_TASK_INVALID target task id is invalid.
|
||||
* @retval #EVTDRV_ERR_NONE send successfully.
|
||||
*/
|
||||
__API__ evtdrv_err_t tos_evtdrv_msg_send(evtdrv_task_id_t dst_task_id, evtdrv_msg_body_t msg_body);
|
||||
|
||||
__API__ evtdrv_msg_body_t tos_evtdrv_msg_recv(void);
|
||||
|
||||
__KERNEL__ void evtdrv_msg_init(void);
|
||||
|
||||
#endif /* TOS_CFG_EVENT_DRIVEN_EN */
|
||||
|
||||
#endif /* _TOS_EVTDRV_MSG_H_ */
|
||||
|
Reference in New Issue
Block a user