141 lines
		
	
	
		
			4.0 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
		
		
			
		
	
	
			141 lines
		
	
	
		
			4.0 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_CUS_PORTS_H__
							 | 
						||
| 
								 | 
							
								#define __IOT_CUS_PORTS_H__
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief enum _iot_cus_task_port_id_e - List of PIDs.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								enum _iot_cus_task_port_id_e {
							 | 
						||
| 
								 | 
							
								    PID_UART        = 0,
							 | 
						||
| 
								 | 
							
								    PID_RF          = 1,
							 | 
						||
| 
								 | 
							
								    PID_BLE         = 2,
							 | 
						||
| 
								 | 
							
								    PID_LORA        = 3,
							 | 
						||
| 
								 | 
							
								    PID_ZIGBEE      = 4,
							 | 
						||
| 
								 | 
							
								    PID_ETH         = 5,
							 | 
						||
| 
								 | 
							
								    PID_MAX
							 | 
						||
| 
								 | 
							
								};
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define port_valid(p)   ((p) >= PID_UART && (p) < PID_MAX)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#ifndef bit
							 | 
						||
| 
								 | 
							
								#define bit(b)  (1 << (b))
							 | 
						||
| 
								 | 
							
								#endif
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief enum _iot_cus_task_port_event_e - List of events.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								enum _iot_cus_task_port_event_e {
							 | 
						||
| 
								 | 
							
								    EVT_INVALID     = 0,
							 | 
						||
| 
								 | 
							
								    EVT_DOUT_DONE   = bit(0),
							 | 
						||
| 
								 | 
							
								    EVT_DIN_DONE    = bit(1),
							 | 
						||
| 
								 | 
							
								    EVT_MAX         = bit(2)
							 | 
						||
| 
								 | 
							
								};
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief init_fn() - Initialize the port.
							 | 
						||
| 
								 | 
							
								 * @param pid: port id.
							 | 
						||
| 
								 | 
							
								 * @param cfg: configuration for this port.
							 | 
						||
| 
								 | 
							
								 * @return ERR_FAIL -- Operation failed.
							 | 
						||
| 
								 | 
							
								 * @return ERR_OK -- Operation Successful.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								typedef uint32_t (*init_fn)(uint32_t pid, void *cfg);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief ready_fn() - Get status of port.
							 | 
						||
| 
								 | 
							
								 * @return 1 -- port is ready.
							 | 
						||
| 
								 | 
							
								 * @return 0 -- port is not ready.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								typedef uint32_t (*ready_fn)(void);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief timer_fn() - every XXX ms, this handler will be called.
							 | 
						||
| 
								 | 
							
								 * @param t_time: delta time in ms.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								typedef void (*timer_fn)(uint32_t delta);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief write_fn() - write data to the port.
							 | 
						||
| 
								 | 
							
								 * @param buf: pointer of buffer.
							 | 
						||
| 
								 | 
							
								 * @param length: count of bytes to write.
							 | 
						||
| 
								 | 
							
								 * @return -- count of bytes was written.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								typedef int (*write_fn)(char *buf, uint32_t length);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief read_fn() - read data from the port.
							 | 
						||
| 
								 | 
							
								 * @param buf: pointer of buffer.
							 | 
						||
| 
								 | 
							
								 * @param length: count of bytes to read.
							 | 
						||
| 
								 | 
							
								 * @return -- count of bytes was read.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								typedef int (*read_fn)(char *buf, uint32_t length);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief struct _iot_cus_ports_api_t - APIs defination for port driver.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								typedef struct _iot_cus_ports_api_t {
							 | 
						||
| 
								 | 
							
								    int         pid;
							 | 
						||
| 
								 | 
							
								    init_fn     p_init;
							 | 
						||
| 
								 | 
							
								    ready_fn    p_ready;
							 | 
						||
| 
								 | 
							
								    timer_fn    p_timer;
							 | 
						||
| 
								 | 
							
								    write_fn    p_write;
							 | 
						||
| 
								 | 
							
								    read_fn     p_read;
							 | 
						||
| 
								 | 
							
								} iot_cus_ports_api_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_cus_ports_event_post() - post events to cus-task.
							 | 
						||
| 
								 | 
							
								 * @param pid: pid of this port.
							 | 
						||
| 
								 | 
							
								 * @param events: event to post.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								void iot_cus_ports_event_post(uint32_t pid, uint32_t events);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_cus_ports_init() - Initialize all of the ports.
							 | 
						||
| 
								 | 
							
								 * @return ERR_FAIL -- Operation failed.
							 | 
						||
| 
								 | 
							
								 * @return ERR_OK -- Operation Successful.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								uint32_t iot_cus_ports_init(void);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_cus_ports_timer_handle() - every XXX ms, this handler will be called.
							 | 
						||
| 
								 | 
							
								 * @param delta_time: delta time in ms.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								void iot_cus_ports_timer_handle(uint32_t delta_time);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_cus_ports_send() - write data to the port.
							 | 
						||
| 
								 | 
							
								 * @param port: port number.
							 | 
						||
| 
								 | 
							
								 * @param buf: pointer of buffer.
							 | 
						||
| 
								 | 
							
								 * @param length: count of bytes to write.
							 | 
						||
| 
								 | 
							
								 * @return -- count of bytes was written.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								uint32_t iot_cus_ports_send(uint32_t port, uint8_t *buf, uint32_t len);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_cus_all_ports_write() - try to write data to all port.
							 | 
						||
| 
								 | 
							
								 * @param buf: pointer of buffer.
							 | 
						||
| 
								 | 
							
								 * @param length: count of bytes to write.
							 | 
						||
| 
								 | 
							
								 * @return -- count of bytes was written.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								void iot_cus_all_ports_write(uint8_t *buf, uint32_t len);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_cus_ports_event_handle() - Ports events handle.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								void iot_cus_ports_event_handle(void);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#endif /* __IOT_CUS_PORTS_H__ */
							 |