180 lines
5.3 KiB
C
180 lines
5.3 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_H
|
|
#define HTBUS_H
|
|
|
|
/* os shim includes */
|
|
#include "os_types.h"
|
|
#include "os_timer_api.h"
|
|
|
|
/* common includes */
|
|
#include "iot_task.h"
|
|
#include "iot_utils_api.h"
|
|
#include "iot_pkt_api.h"
|
|
#include "iot_mem_pool_api.h"
|
|
|
|
/* mac layer includes */
|
|
#include "mac_bcm_api.h"
|
|
|
|
/* htbus internal includes */
|
|
#include "htbus_msg.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/* define htbus task prio */
|
|
#define HTBUS_TASK_PRIO (8)
|
|
|
|
/* define htbus network id */
|
|
#define HTBUS_NID (0x1553)
|
|
|
|
/* define htbus frame cache queue depth */
|
|
#define HTBUS_FRAME_QUEUE_DEPTH (10)
|
|
|
|
|
|
typedef struct _htbus_frame {
|
|
/* link for frame list */
|
|
iot_list_head_t link;
|
|
/* frame data pkt */
|
|
iot_pkt_t *pkt;
|
|
} htbus_frame_t;
|
|
|
|
/* tx queue context structure */
|
|
typedef struct _htbus_tx_queue {
|
|
/* frame buffer head */
|
|
iot_list_head_t head;
|
|
/* frame buffer pool */
|
|
iot_mem_pool_t *frame_pool;
|
|
/* The frame pointer currently being sent */
|
|
htbus_frame_t *cur_frame;
|
|
/* free number of tx queue */
|
|
uint8_t free_num;
|
|
} htbus_tx_queue_t;
|
|
|
|
/* rx beacon descriptor */
|
|
typedef struct _mac_bc_rx_desc_htbus {
|
|
/* beacon entries of the received beacon */
|
|
uint16_t field_flag;
|
|
/* frame control descriptor */
|
|
mac_bc_fc_t fc;
|
|
/* fixed paload descriptor */
|
|
mac_bc_htbus_fp_t fp;
|
|
/* time slot alloc descriptor */
|
|
mac_bc_htbus_time_slot_t ts;
|
|
/* user data descriptor */
|
|
mac_bc_htbus_user_data_t ud;
|
|
} mac_bc_rx_desc_htbus_t;
|
|
|
|
/* htbus global descriptor */
|
|
typedef struct _htbus_global {
|
|
/* task handle */
|
|
iot_task_h task_h;
|
|
/* dev addr */
|
|
uint8_t addr[IOT_MAC_ADDR_LEN];
|
|
/* mac vdev id */
|
|
uint8_t mac_vdev_id;
|
|
/* device role */
|
|
uint8_t role;
|
|
/* device lacal tei */
|
|
uint8_t local_tei;
|
|
/* tx sdu seq number */
|
|
uint8_t tx_sdu_sn;
|
|
/* beacon information buffer */
|
|
mac_bc_rx_desc_htbus_t bc_temp;
|
|
/* pointer to tx queue */
|
|
void *tx_queue;
|
|
/* function pointer to handle task events */
|
|
htbus_event_func_t event_func;
|
|
/* htbus message executing callback */
|
|
htbus_msg_execute_func_t msg_exe_func;
|
|
/* htbus message canceling callback */
|
|
htbus_msg_cancel_func_t msg_cannel_func;
|
|
} htbus_global_t;
|
|
|
|
/**
|
|
* @brief htbus_data_print() - format print buffer data
|
|
* @param str: data label.
|
|
* @param buf: buffer pointer to be printed
|
|
* @param len: buffer len to be printed
|
|
*/
|
|
void htbus_data_print(const char* str, uint8_t* buf, uint32_t len);
|
|
|
|
/**
|
|
* @brief htbus_bc_parse() - parse a iot_pkt to get beacon info
|
|
* in a mac_bc_rx_desc_htbus_t
|
|
* @param buf: pointer to a iot_pkt with beacon raw data
|
|
* @param bc_desc: beacon descriptor with all beacon info
|
|
* @retval ERR_OK - for success case, othersie - error code
|
|
*/
|
|
uint32_t htbus_bc_parse(iot_pkt_t *buf, mac_bc_rx_desc_htbus_t *bc_desc);
|
|
|
|
/*
|
|
* @brief htbus_get_bc_entry() - get pointer to beacon entry field specified
|
|
* by entry_id
|
|
* @param bc: the beacon descriptor
|
|
* @param entry_id: entry id of beacon field
|
|
* @retval: NULL -- if the field is invalid
|
|
* @retval: otherwise -- pointer to specific field
|
|
*/
|
|
void* htbus_get_bc_entry(mac_bc_rx_desc_htbus_t* bc, uint8_t entry_id);
|
|
|
|
/**
|
|
* @brief htbus_bc_rx() - beacon rx handling function. Same as mac_bc_rx_func_t.
|
|
* @param arg: arg parameter registered alone with the callback
|
|
* @param bc: iot_pkt containing beacon raw data
|
|
* @param new_bp: indicate if this beacon is the first beacon received for new bp
|
|
*/
|
|
void htbus_bc_rx(void *arg, iot_pkt_t *bc, uint8_t new_bp);
|
|
|
|
/**
|
|
* @brief htbus_set_band() - set plc band info.
|
|
* @param band_id: band id, see BEACON_FREQ_BAND_ID_XXX.
|
|
*/
|
|
void htbus_set_band(uint8_t band_id);
|
|
|
|
/**
|
|
* @brief htbus_tx_sdu() - tx sdu to htbus.
|
|
* @param pkt: The iot packet to be tx
|
|
* @retval ERR_OK - for success case, othersie - error code
|
|
*/
|
|
uint32_t htbus_tx_sdu(iot_pkt_t *pkt);
|
|
|
|
/**
|
|
* @brief htbus_tx_queue_load() - load frame from tx queue
|
|
* @retval: pointer to frame
|
|
*/
|
|
htbus_frame_t *htbus_tx_queue_load(void);
|
|
|
|
/**
|
|
* @brief htbus_get_local_tei() - get local devices tei.
|
|
* @retval: - local devices tei
|
|
*/
|
|
uint8_t htbus_get_local_tei();
|
|
|
|
/**
|
|
* @brief htbus_get_sdu_sn() - get current SDU seq number to be sent.
|
|
* @retval: seq number
|
|
*/
|
|
uint8_t htbus_get_sdu_sn();
|
|
|
|
/* htbus global data structure declaration */
|
|
extern htbus_global_t *p_htbus_glb;
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* HTBUS_H */ |