122 lines
		
	
	
		
			3.7 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
		
		
			
		
	
	
			122 lines
		
	
	
		
			3.7 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 HTBUS_MSG_H
							 | 
						||
| 
								 | 
							
								#define HTBUS_MSG_H
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* os shim includes */
							 | 
						||
| 
								 | 
							
								#include "os_types.h"
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* common includes */
							 | 
						||
| 
								 | 
							
								#include "iot_task.h"
							 | 
						||
| 
								 | 
							
								#include "iot_config.h"
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#ifdef __cplusplus
							 | 
						||
| 
								 | 
							
								extern "C" {
							 | 
						||
| 
								 | 
							
								#endif
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* define the htbus message queue count and priorities, the higer the priority
							 | 
						||
| 
								 | 
							
								 * the lower the queue number.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								#define HTBUS_MSG_QUEUE_HP                  0
							 | 
						||
| 
								 | 
							
								#define HTBUS_MSG_QUEUE_LP                  1
							 | 
						||
| 
								 | 
							
								#define HTBUS_MSG_QUEUE_MAX_PRIO            2
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* define htbus layer message pool size */
							 | 
						||
| 
								 | 
							
								#define HTBUS_MSG_POOL_SIZE                 128
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* message type definition */
							 | 
						||
| 
								 | 
							
								#define HTBUS_MSG_TYPE_INTERNAL             0   /* messages from interanal */
							 | 
						||
| 
								 | 
							
								#define HTBUS_MSG_TYPE_MAC                  1   /* messages from mac layer */
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* messages id definitions for internal type */
							 | 
						||
| 
								 | 
							
								/* start reqeust */
							 | 
						||
| 
								 | 
							
								#define HTBUS_MSG_ID_INTERNAL_START         0
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* messages id definitions for MAC type */
							 | 
						||
| 
								 | 
							
								#define HTBUS_MSG_ID_MAC_BEACON_RX          0   /* beacon rx */
							 | 
						||
| 
								 | 
							
								#define HTBUS_MSG_ID_MAC_BP_END_ALERT       1   /* beacon period end alert */
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* define event type */
							 | 
						||
| 
								 | 
							
								/* test trigger event */
							 | 
						||
| 
								 | 
							
								#define HTBUS_EVENT_TEST_TRIG               1
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* htbus message */
							 | 
						||
| 
								 | 
							
								typedef struct _htbus_msg {
							 | 
						||
| 
								 | 
							
								    /* htbus task message */
							 | 
						||
| 
								 | 
							
								    iot_task_msg_t  task_msg;
							 | 
						||
| 
								 | 
							
								    /* message data1 */
							 | 
						||
| 
								 | 
							
								    uint32_t        data1;
							 | 
						||
| 
								 | 
							
								    /* message data2 pointer */
							 | 
						||
| 
								 | 
							
								    void            *data2;
							 | 
						||
| 
								 | 
							
								} htbus_msg_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/*
							 | 
						||
| 
								 | 
							
								 * htbus_alloc_msg() - allocate one message from global msg pool
							 | 
						||
| 
								 | 
							
								 *
							 | 
						||
| 
								 | 
							
								 * return:
							 | 
						||
| 
								 | 
							
								 *      NULL      -- for failure case
							 | 
						||
| 
								 | 
							
								 *      othersie  -- pointer of allocated message
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								#define htbus_alloc_msg() ((htbus_msg_t *)iot_task_alloc_msg(p_htbus_glb->task_h))
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/*
							 | 
						||
| 
								 | 
							
								 * htbus_free_msg() - free one message back to global msg pool
							 | 
						||
| 
								 | 
							
								 * @msg:    pointer of msg to be freed
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								#define htbus_free_msg(msg) \
							 | 
						||
| 
								 | 
							
								    (iot_task_free_msg(p_htbus_glb->task_h, (iot_task_msg_t *)msg))
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/*
							 | 
						||
| 
								 | 
							
								 * htbus_queue_msg() - queue one message into msg queues based on the priority
							 | 
						||
| 
								 | 
							
								 * @msg:    pointer of msg to be queued
							 | 
						||
| 
								 | 
							
								 * @prio:   the priority of the message
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								#define htbus_queue_msg(msg, prio) \
							 | 
						||
| 
								 | 
							
								    (iot_task_queue_msg(p_htbus_glb->task_h, (iot_task_msg_t *)msg, prio))
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/*
							 | 
						||
| 
								 | 
							
								 * htbus_clean_msg() - clean up specified messages
							 | 
						||
| 
								 | 
							
								 * @type:   type of the messages to be canceled
							 | 
						||
| 
								 | 
							
								 * @id:     id of messages to be canceled
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								#define htbus_clean_msg(type, id) \
							 | 
						||
| 
								 | 
							
								    (iot_task_clean_msg(p_htbus_glb->task_h, type, id))
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/*
							 | 
						||
| 
								 | 
							
								 * function callback to handle event
							 | 
						||
| 
								 | 
							
								 * @events:     collection of events, see HTBUS_EVENT_XXX
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								typedef void (*htbus_event_func_t)(uint32_t events);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/*
							 | 
						||
| 
								 | 
							
								 * function callback to handle msg executing case
							 | 
						||
| 
								 | 
							
								 * @msg:        pointer to message to be executed
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								typedef void (*htbus_msg_execute_func_t)(htbus_msg_t *msg);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/*
							 | 
						||
| 
								 | 
							
								 * function callback to handle msg canceling case
							 | 
						||
| 
								 | 
							
								 * @msg:        pointer to message to be canceled
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								typedef void (*htbus_msg_cancel_func_t)(htbus_msg_t *msg);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#ifdef __cplusplus
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								#endif
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#endif /* HTBUS_MSG_H */
							 | 
						||
| 
								 | 
							
								
							 |