195 lines
		
	
	
		
			6.6 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
		
		
			
		
	
	
			195 lines
		
	
	
		
			6.6 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
|  | /****************************************************************************
 | ||
|  | 
 | ||
|  | Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED. | ||
|  | 
 | ||
|  | This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT | ||
|  | be copied by any method or incorporated into another program without | ||
|  | the express written consent of Aerospace C.Power. This Information or any portion | ||
|  | thereof remains the property of Aerospace C.Power. The Information contained herein | ||
|  | is believed to be accurate and Aerospace C.Power assumes no responsibility or | ||
|  | liability for its use in any way and conveys no license or title under | ||
|  | any patent or copyright and makes no representation or warranty that this | ||
|  | Information is free from patent or copyright infringement. | ||
|  | 
 | ||
|  | ****************************************************************************/ | ||
|  | 
 | ||
|  | #ifndef IOT_SHARE_TASK_H
 | ||
|  | #define IOT_SHARE_TASK_H
 | ||
|  | 
 | ||
|  | /* os shim includes */ | ||
|  | #include "os_types.h"
 | ||
|  | #include "os_task.h"
 | ||
|  | 
 | ||
|  | /* common includes */ | ||
|  | #include "iot_queue.h"
 | ||
|  | #include "iot_task.h"
 | ||
|  | 
 | ||
|  | #ifdef __cplusplus
 | ||
|  | extern "C" { | ||
|  | #endif
 | ||
|  | 
 | ||
|  | /** \defgroup SHARE_TASK_APIs Share Task APIs
 | ||
|  |   * @brief Share Task APIs | ||
|  |   * | ||
|  |   * | ||
|  |   * | ||
|  |   */ | ||
|  | 
 | ||
|  | /** @addtogroup SHARE_TASK_APIs
 | ||
|  |   * @{ | ||
|  |   */ | ||
|  | 
 | ||
|  | /* define priorities for message to be handle */ | ||
|  | #define IOT_SHARE_TASK_QUEUE_HP         0
 | ||
|  | #define IOT_SHARE_TASK_QUEUE_LP         1
 | ||
|  | #define IOT_SHARE_TASK_QUEUE_MAX_PRIO   2
 | ||
|  | 
 | ||
|  | /* define message type for posting msg to share task */ | ||
|  | #define IOT_SHARE_TASK_MT_INVALID       0
 | ||
|  | #define IOT_SHARE_TASK_MT_PIB           1
 | ||
|  | #define IOT_SHARE_TASK_MT_PLC_LED       2
 | ||
|  | #define IOT_SHARE_TASK_MT_CLI           3
 | ||
|  | #define IOT_SHARE_TASK_MT_UPGRADE       4
 | ||
|  | #define IOT_SHARE_TASK_MT_BH_INIT       5
 | ||
|  | #define IOT_SHARE_TASK_MT_CCO_PK_HDL    6
 | ||
|  | #define IOT_SHARE_TASK_MT_PLC_PM        7
 | ||
|  | #define IOT_SHARE_TASK_MT_DRIVER_I2S    8
 | ||
|  | #define IOT_SHARE_TASK_MT_HW_TSFM       9
 | ||
|  | #define IOT_SHARE_TASK_MT_EM_EXT        10
 | ||
|  | #define IOT_SHARE_TASK_MT_CRYPTO        11
 | ||
|  | #define IOT_SHARE_TASK_MT_SPI           12
 | ||
|  | /* maximum supported message types, should always keep this number accurate */ | ||
|  | #define IOT_SHARE_TASK_MT_MAX           12
 | ||
|  | 
 | ||
|  | /* Event ID NOT the Message ID */ | ||
|  | typedef enum | ||
|  | { | ||
|  |     IOT_SHARE_EVENT_START = 1, | ||
|  |     IOT_SHARE_EVENT_GPIO_INT = 1, | ||
|  |     IOT_SHARE_EVENT_LED_PLC_TX_PHASE_A = 2, | ||
|  |     IOT_SHARE_EVENT_LED_PLC_TX_PHASE_B = 3, | ||
|  |     IOT_SHARE_EVENT_LED_PLC_TX_PHASE_C = 4, | ||
|  |     IOT_SHARE_EVENT_LED_PLC_RX = 5, | ||
|  |     IOT_SHARE_EVENT_LED_PLC_485_TX = 6, | ||
|  |     IOT_SHARE_EVENT_LED_PLC_485_RX = 7, | ||
|  |     IOT_SHARE_EVENT_ETH0_INT = 8, | ||
|  |     IOT_SHARE_EVENT_GP_TIMER_INT = 9, | ||
|  |     IOT_SHARE_EVENT_PM_TIMER = 10, | ||
|  |     IOT_SHARE_EVENT_I2S_DMA_INT = 11, | ||
|  |     IOT_SHARE_EVENT_I2S_DMA_OUT_T_EOF = 12, | ||
|  |     IOT_SHARE_EVENT_I2S_TX_POOL = 13, | ||
|  |     IOT_SHARE_EVENT_LED_PLC_APP_TX = 14, | ||
|  |     IOT_SHARE_EVENT_LED_PLC_APP_RX = 15, | ||
|  |     IOT_SHARE_EVENT_SADC0_DMA_INT = 16, | ||
|  |     IOT_SHARE_EVENT_SADC1_DMA_INT = 17, | ||
|  |     IOT_SHARE_EVENT_UART_DMA_INT = 18, | ||
|  |     IOT_SHARE_EVENT_EM_EXT = 19, | ||
|  |     IOT_SHARE_EVENT_LED_PLC_SM_FOUND = 20, | ||
|  |     IOT_SHARE_EVENT_HW_TSFM = 21, | ||
|  |     IOT_SHARE_EVENT_DBG_MSG_TIMER = 22, | ||
|  |     IOT_SHARE_EVENT_CRYPTO = 23, | ||
|  |     IOT_SHARE_EVENT_SPI0_DMA_SEND_OVER = 24, | ||
|  |     IOT_SHARE_EVENT_SPI2_DMA_SEND_OVER = 25, | ||
|  |     IOT_SHARE_EVENT_LED_RF_APP_TX = 26, | ||
|  |     IOT_SHARE_EVENT_END = 32 | ||
|  | }iot_share_event_type; | ||
|  | 
 | ||
|  | #define IOT_SHARE_TASK_MSG_ID_ALL       IOT_TASK_MSG_ID_ALL
 | ||
|  | 
 | ||
|  | typedef void (*iot_share_msg_func_t)(iot_msg_entry_t *entry); | ||
|  | typedef void (*iot_share_msg_cancel_func_t)(iot_msg_entry_t *entry); | ||
|  | typedef void (*iot_share_event_func)(int); | ||
|  | 
 | ||
|  | typedef struct _iot_share_task_msg { | ||
|  |     iot_task_msg_t              msg; | ||
|  |     /* data1 */ | ||
|  |     uint32_t                    data1; | ||
|  |     /* data2*/ | ||
|  |     void*                       data2; | ||
|  | }iot_share_task_msg_t; | ||
|  | 
 | ||
|  | /* @brief iot_share_task_init - create the background
 | ||
|  |  * iot_task shared by all tasks | ||
|  |  * @return return 0 for success case. other for failed case. | ||
|  |  */ | ||
|  | uint32_t iot_share_task_init(); | ||
|  | 
 | ||
|  | /* @brief iot_share_task_deinit - delete the background share task.
 | ||
|  |  */ | ||
|  | void iot_share_task_deinit(); | ||
|  | 
 | ||
|  | /* @brief iot_share_task_post_msg - post msg to share task with high priority
 | ||
|  |  * @param prio:       priority to handle this message | ||
|  |  * @param msg_type:   message type | ||
|  |  * @param msg_id:     id of the message | ||
|  |  * @param data1:      data1 field of the message | ||
|  |  * @param data2:      a pointer field of the message | ||
|  |  * | ||
|  |  * @return ERR_FAIL -- Operation failed. | ||
|  |  * @return ERR_OK -- Operation Successful. | ||
|  |  */ | ||
|  | uint32_t iot_share_task_post_msg | ||
|  |     (uint32_t prio, uint16_t msg_type, uint16_t msg_id, uint32_t data1, | ||
|  |     void *data2); | ||
|  | 
 | ||
|  | /* @brief iot_share_task_clean_msg - clean msg with specified type and id
 | ||
|  |  * @param msg_type:   type of the message to be removed from share task queue | ||
|  |  * @param msg_id:     if of the message to be removed. | ||
|  |  */ | ||
|  | void iot_share_task_clean_msg | ||
|  |     (uint16_t msg_type, uint16_t msg_id); | ||
|  | 
 | ||
|  | /* @brief iot_share_task_event_register - bind a event with a callback function.
 | ||
|  |  * @param type:       The event type. | ||
|  |  * @param func:       The callback function. | ||
|  |  * @param arg:        Argument for the callback function. | ||
|  |  * @return ERR_FAIL -- Operation failed. | ||
|  |  * @return ERR_OK -- Operation Successful. | ||
|  |  */ | ||
|  | uint32_t iot_share_task_event_register | ||
|  |     (iot_share_event_type type, iot_share_event_func func, int arg); | ||
|  | 
 | ||
|  | /* @brief iot_share_task_msg_register - bind a message type with handling
 | ||
|  |  *        callback function. note that this function can only be invoked in | ||
|  |  *        initialization stage as there is no lock protection for this function. | ||
|  |  * @param msg_type:     the message type. see IOT_SHARE_TASK_MT_XXX. | ||
|  |  * @param exe_func:     the callback function for message excuting | ||
|  |  * @param cancel_func:  the callback function for message canceling | ||
|  |  * | ||
|  |  * @return  ERR_FAIL    --  Operation failed. | ||
|  |  * @return  ERR_OK      --    Operation Successful. | ||
|  |  */ | ||
|  | uint32_t iot_share_task_msg_register(uint16_t msg_type, | ||
|  |     iot_share_msg_func_t exe_func, iot_share_msg_cancel_func_t cancel_func); | ||
|  | 
 | ||
|  | /* @brief iot_share_task_post_event_from_isr - post event to share task,
 | ||
|  |  * caller is an ISR | ||
|  |  * @param prio:       priority to handle this message | ||
|  |  * @param type:       event type | ||
|  |  * @return ERR_FAIL -- Operation failed. | ||
|  |  * @return ERR_OK -- Operation Successful. | ||
|  |  */ | ||
|  | uint32_t iot_share_task_post_event_from_isr | ||
|  |     (uint32_t prio, iot_share_event_type type); | ||
|  | 
 | ||
|  | /* @brief iot_share_task_post_event_from_isr - post event to share task,
 | ||
|  |  * caller is a TASK | ||
|  |  * @param prio:       priority to handle this message | ||
|  |  * @param type:       event type | ||
|  |  * @return ERR_FAIL -- Operation failed. | ||
|  |  * @return ERR_OK -- Operation Successful. | ||
|  |  */ | ||
|  | uint32_t iot_share_task_post_event_from_task | ||
|  |     (uint32_t prio, iot_share_event_type type); | ||
|  | 
 | ||
|  | /**
 | ||
|  |   * @} | ||
|  |   */ | ||
|  | 
 | ||
|  | 
 | ||
|  | #ifdef __cplusplus
 | ||
|  | } | ||
|  | #endif
 | ||
|  | 
 | ||
|  | #endif /* IOT_SHARE_TASK_H */
 |