Files
kunlun/app/iot_dlt645_app/common/app_cus_task.h
2024-09-28 14:24:04 +08:00

146 lines
4.2 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 _APP_CUS_TASK_H_
#define _APP_CUS_TASK_H_
#include "app_common.h"
#include "app_types.h"
#ifdef __cplusplus
extern "C" {
#endif
#define APP_CUS_HANDLE_TASK_PRIO (8)
#define APP_CUS_PENDING_LIMIT (32)
#define APP_CUS_TASK_PRIO_QUE (1)
#define APP_CUS_TASK_TIMER_PERIOD_MS (1000)
typedef void (*iot_cus_task_mismatch_dlt645_proc_fn)(iot_pkt_t *pkt645);
typedef struct _iot_cus_task_t {
/* task handle. */
iot_task_h task;
/* uart handle. */
iot_uart_h uart_h;
/* timer handle. */
timer_id_t peroid_timer;
} iot_cus_task_t;
/* message type for customer task. */
typedef enum {
E_CUS_MSG_START = 0,
/* customer task message from uart. */
E_CUS_MSG_FROM_UART,
/* customer task message from customer task. */
E_CUS_MSG_FROM_CUSTASK,
/* customer task message from main task. */
E_CUS_MSG_FROM_MAINTASK,
/* customer task message from timer. */
E_CUS_MSG_FROM_TIMER,
E_CUS_MSG_END
} iot_cus_task_msg_e;
/* message id for customer task. */
typedef enum {
E_CUS_MSG_ID_START = 0,
/* customer task receive bytes from uart. */
E_CUS_MSG_ID_BYTES_RECV,
/* customer task send bytes to uart or other task. */
E_CUS_MSG_ID_BYTES_SEND,
/* customer task receive dlt645 frame from main task or uart. */
E_CUS_MSG_ID_645PKT_RECV,
/* period timer of customer task triggered. */
E_CUS_MSG_ID_TMR_TRIGGER,
/* on line or off line event to customer task. */
E_CUS_MSG_ID_ONOFF_LINE,
E_CUS_MSG_ID_END
} iot_cus_task_msg_id_e;
#define APP_CUS_MSG_VALID(msg) ((msg)>E_CUS_MSG_START && (msg)<E_CUS_MSG_END)
typedef struct {
/* The main entity of message. */
iot_task_msg_t msg;
/* The user data inside this message. */
void *data;
} iot_cus_task_msg_t;
/**
* @brief iot_cus_task_init() - Initialize customer task.
*
* @param None.
*
* @return ERR_OK : Initialize done;
* @return ERR_FAIL : Initialize failed;
*/
uint32_t iot_cus_task_init(void);
/**
* @brief iot_cus_task_msg_post() - Post message to customer task.
*
* @param [in] msg_type : message type, see iot_cus_task_msg_e.
* @param [in] msg_id : message id, see iot_cus_task_msg_id_e.
* @param [in] data : message data.
*
* @return ERR_OK : message post done;
* @return ERR_FAIL : message post failed;
*/
uint32_t iot_cus_task_msg_post(uint16_t msg_type, uint16_t msg_id,
iot_pkt_t *data);
/**
* @brief iot_cus_task_onoffline_report() - report on/off line event to
* customer task.
*
* @param [in] dev_mac : device mac address.
* @param [in] status : STA_ONLINE_EVENT or STA_OFFLINE_EVENT.
*
* @return ERR_OK : event report done;
* @return ERR_FAIL : event report failed;
*/
uint32_t iot_cus_task_onoffline_report(uint8_t *dev_mac, uint8_t status);
/**
* @brief iot_cus_task_mismatch_dlt645_handle_set() - set a handle for mismatch
* dlt645 frame.
*
* @param [in] handle.
*
* @return None.
*/
void iot_cus_task_mismatch_dlt645_handle_set(
iot_cus_task_mismatch_dlt645_proc_fn handle);
/**
* @brief iot_cus_task_get_uart_handle() - get uart handle.
*
* @param None.
*
* @return uart handle.
*/
iot_uart_h iot_cus_task_get_uart_handle(void);
/**
* @brief iot_cus_task_set_uart_handle() - set uart handle.
*
* @param [in] uart_h : uart handle.
*
* @return None.
*/
void iot_cus_task_set_uart_handle(iot_uart_h uart_h);
#endif /* _APP_CUS_TASK_H_ */