208 lines
		
	
	
		
			8.2 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			208 lines
		
	
	
		
			8.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 _INCLUDE_IOT_PLC_DEMO_H_
 | |
| #define _INCLUDE_IOT_PLC_DEMO_H_
 | |
| 
 | |
| #ifdef __cplusplus
 | |
| extern "C" {
 | |
| #endif
 | |
| 
 | |
| /********************** FOR USER CONFIGURATION ** START ***********************/
 | |
| 
 | |
| #define DEMO_APP_DEBUG_EN               1   /* enable data print debug or not.
 | |
|                                                 demo_app_data_print() */
 | |
| 
 | |
| #define DEMO_PRINT_DEBUG                1   /* enable data print debug or not */
 | |
| 
 | |
| #define DEMO_APP_CTRL_LED               1   /* enable led function or not */
 | |
| 
 | |
| /********************** FOR USER CONFIGURATION ** END *************************/
 | |
| 
 | |
| /********************** FOR DEMO CONFIGURATION ** START ***********************/
 | |
| 
 | |
| #if DEMO_APP_DEBUG_EN
 | |
| 
 | |
| #define DEMO_APP_LOG_BUF_LEN            (256)   /* define the buffer length for
 | |
|                                                     debug infon printing */
 | |
| #endif /* DEMO_APP_DEBUG_EN */
 | |
| 
 | |
| #define DEMO_UART_RCV_BUF_LEN           256     /*demo uart recv buffer */
 | |
| 
 | |
| /* for demo debug print function */
 | |
| #if DEMO_PRINT_DEBUG
 | |
| 
 | |
| #define DEMO_DEBUG_LOG(X0, X1, X2, X3, X4, X5, X6) \
 | |
|             iot_cus_printf((char *)X0, (int)X1, (int)X2, (int)X3, (int)X4, \
 | |
|             (int)X5, (int)X6);
 | |
| 
 | |
| #else /*DEMO_PRINT_DEBUG*/
 | |
| 
 | |
| #define DEMO_DEBUG_LOG(X0, X1, X2, X3, X4, X5, X6)
 | |
| 
 | |
| #endif /*DEMO_PRINT_DEBUG*/
 | |
| 
 | |
| #define DEMO_INFO(x0, x1, x2, x3, x4, x5, x6) \
 | |
|             DEMO_DEBUG_LOG("\r\n>>DEMO INFOR : " x0 "<<\r\n", x1, x2, x3, x4, \
 | |
|             x5, x6)
 | |
| 
 | |
| #define DEMO_ERROR(x0, x1, x2, x3, x4, x5, x6) \
 | |
|             DEMO_DEBUG_LOG("\r\n##DEMO ERROR : " x0 "##\r\n", x1, x2, x3, x4, \
 | |
|             x5, x6)
 | |
| 
 | |
| /* led configuration */
 | |
| #define DEMO_LED_LIGHT_UP_FLAG          0   /* Low led pin level  */
 | |
| #define DEMO_LED_LIGHT_DOWN_FLAG        1   /* High led pin level */
 | |
| #define DEMO_LED_TMR_PERIO              225 /* Time in micro-seconds. */
 | |
| #define DEMO_LED_BLINK_RX_TM            (DEMO_LED_TMR_PERIO)
 | |
| #define DEMO_LED_BLINK_TX_TM            (DEMO_LED_TMR_PERIO*4)  /* 1S */
 | |
| #define DEMO_LED_TM_FOREVER             (-1)
 | |
| #define DEMO_LED_RX_CONTINUE_TM         2000    /* 2s */
 | |
| #define DEMO_LED_TX_CONTINUE_TM         DEMO_LED_TM_FOREVER /* always blinking */
 | |
| 
 | |
| /* led attribute descriptor */
 | |
| typedef struct _demo_led_struct {
 | |
|     uint32_t    blink_time;
 | |
|     uint16_t    load_perio;
 | |
|     uint16_t    cur_perio;
 | |
|     uint16_t    status;
 | |
|     uint8_t     pin;
 | |
| } dm_led_t;
 | |
| 
 | |
| /* led device descriptor */
 | |
| typedef struct _demo_led_entity {
 | |
|     timer_id_t  tmr_id; /* To triger repeatedly works. */
 | |
|     os_mutex_h  sem_h;
 | |
|     dm_led_t    tx;     /* Designed to blinking all the time. */
 | |
|     dm_led_t    rx;     /* Designed to blinking when there are packets from
 | |
|                            PLC-layer. */
 | |
| }  dm_led_dev_t;
 | |
| 
 | |
| /* msg task descriptor */
 | |
| typedef struct _demo_msg_task {
 | |
|     iot_task_h          handle; /* Task handle. */
 | |
|     iot_task_config_t   cfg;    /* Keep the task configuration. */
 | |
| } dm_msg_task_t;
 | |
| 
 | |
| /* msg descriptor */
 | |
| typedef struct _demo_msg {
 | |
|     iot_task_msg_t  msg;        /* The main entity of message. */
 | |
|     void            *data;      /* The user data inside this message. */
 | |
| } dm_msg_t;
 | |
| 
 | |
| #define DEMO_APP_LINK_ID    2   /* maximum number of app connections */
 | |
| 
 | |
| typedef struct demo_device {
 | |
|     uint8_t        rmt_valid; /* Indicates if the remote device is ready. */
 | |
|     uint8_t        link_id;   /* dev connections number. */
 | |
|     uint8_t        dev_ready; /* Indicates if this local device is ready. */
 | |
|     uint8_t        dev_role;  /* This local device role, CCO or STA ... */
 | |
|     uint32_t       dev_type;  /* device type */
 | |
|     uint8_t        mac_addr[IOT_MAC_ADDR_LEN];/* MAC of this local device. */
 | |
|     uint8_t        cco_addr[IOT_MAC_ADDR_LEN];/* MAC of CCO in this topo. */
 | |
|     uint8_t        rmt_addr[IOT_MAC_ADDR_LEN];/* MAC of remote device we
 | |
|                                                    communicate with. */
 | |
|     uint32_t       nid;                       /* The network ID of this topo. */
 | |
| } dm_dev_t;
 | |
| 
 | |
| /* timer period to print core temperature. unit is ms */
 | |
| #define DEMO_APP_TEMP_PRINT_TMR_PERIOD  (5000)
 | |
| /* timer period to check associated sta. unit is ms */
 | |
| #define DEMO_APP_ASSOC_CHECK_TMR_PERIOD (1000)
 | |
| /* minimum count of tmr period wait for sta to associate */
 | |
| #define DEMO_APP_MIN_ASSOC_PERIODS      (20)
 | |
| /* medium count of tmr period wait for sta to associate */
 | |
| #define DEMO_APP_MED_ASSOC_PERIODS      (60)
 | |
| /* maximum count of tmr period wait for sta to associate */
 | |
| #define DEMO_APP_MAX_ASSOC_PERIODS      (120)
 | |
| /* count of whitelist entries to retrieve */
 | |
| #define DEMO_APP_WL_QR_CNT              (200)
 | |
| /* size of bitmap. unit is byte */
 | |
| #define DEMO_APP_BIT_MAP_SIZE           (IOT_APP_WL_PIB_ADDR_CNT / 8 + 1)
 | |
| 
 | |
| /* demo app entity descriptor */
 | |
| typedef struct _app_demo_entity {
 | |
|     iot_uart_h    cmd_uart;
 | |
|     dm_msg_task_t msg_task;   /* This task will process all messages and events
 | |
|                                     that from this very module. */
 | |
|     dm_led_dev_t  led;
 | |
|     iot_plc_app_h app_hdl;    /* The handle of this DEMO APP. */
 | |
|     uint32_t      app_reg;    /* Indicates if this APP has registered
 | |
|                                     to PLC-layer. */
 | |
|     dm_dev_t      dev;        /* Device information. */
 | |
|     timer_id_t    tmr_assoc_check;      /* timer id for associated sta check*/
 | |
|     uint8_t       addr_bitmap[DEMO_APP_BIT_MAP_SIZE];
 | |
|                                         /* array used to mark associated sta */
 | |
|     uint32_t      assoc_timeout_period; /* period of associated timeout */
 | |
|     uint32_t      periods_count;        /* count for tmr periods */
 | |
|     uint8_t       assoc_done;           /* label for all stas associated to network */
 | |
| } app_dm_entity_t;
 | |
| 
 | |
| /* demo msg type */
 | |
| typedef enum {
 | |
|     E_DEMO_MSG_START    = 0,
 | |
|     E_DEMO_MSG_FROM_MAC,        /* message type from plc */
 | |
|     E_DEMO_MSG_TIMER,           /* message type from timer */
 | |
|     E_DEMO_MSG_PROCESS,         /* message type from process */
 | |
|     E_DEMO_MSG_END
 | |
| } e_msg_t;
 | |
| 
 | |
| /* demo message id */
 | |
| typedef enum {
 | |
|     E_CMD_ID_START,
 | |
|     E_CMD_ID_RCV_FROM_PLC,      /* message id of plc */
 | |
|     E_CMD_ID_RCV_FROM_UART,     /* message id of uart */
 | |
|     E_CMD_ID_RCV_FROM_CLI,      /* message id of cli */
 | |
|     E_CMD_ID_TMR_ASSOC_CHECK,   /* message id of check connect */
 | |
|     E_CMD_ID_END
 | |
| } e_cmd_id_t;;
 | |
| 
 | |
| /* demo event type */
 | |
| typedef enum {
 | |
|     E_EVENT_START     = 0,
 | |
|     E_EVENT_TIMR,               /* timer event */
 | |
|     E_EVENT_END       = 31
 | |
| } e_ev_t;
 | |
| 
 | |
| #define DEMO_EVENT_VALID(ev) ((ev) <= E_EVENT_END && (ev) >= E_EVENT_START)
 | |
| 
 | |
| #ifndef EVENT_BIT
 | |
| #define EVENT_BIT(n)                    (1 << (n))
 | |
| #endif
 | |
| 
 | |
| /* demo task configuration */
 | |
| #define DEMO_PLC_CMD_PRIO               3   /* plc application priority */
 | |
| #define DEMO_TASK_MSG_PRIO              0   /* message priority */
 | |
| #define DEMO_MSG_HANDLE_TASK_PRIO       8   /* task priority */
 | |
| #define DEMO_MSG_TASK_PRIO_QUE          1   /* task message queue count */
 | |
| #define DEMO_MSG_PENDING_LIMIT          64  /* task message count */
 | |
| 
 | |
| #define DEMO_MSG_VALID(msg) ((msg) > E_DEMO_MSG_START && (msg) < E_DEMO_MSG_END)
 | |
| 
 | |
| #define DEMO_TMR_PERIO                  225 /* Time in micro-seconds. */
 | |
| #define DEMO_RUN_STAMP_TM               (DEMO_TMR_PERIO * 120)  /* 30S */
 | |
| #define DEMO_APP_QUERY_TM               (DEMO_TMR_PERIO * 8)    /* 2S */
 | |
| #define DEMO_APP_SAMPL_TM               (DEMO_TMR_PERIO * 20)   /* 5S */
 | |
| 
 | |
| #define DEMO_APP_CONNLESS_RETRY_CNT     (1) /* Retry cnt for conn less pkt */
 | |
| 
 | |
| /********************** FOR DEMO CONFIGURATION ** END *************************/
 | |
| 
 | |
| #ifdef __cplusplus
 | |
| }
 | |
| #endif
 | |
| 
 | |
| #endif /* _INCLUDE_IOT_PLC_DEMO_H_ */
 | |
| 
 |