161 lines
		
	
	
		
			4.5 KiB
		
	
	
	
		
			C
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			161 lines
		
	
	
		
			4.5 KiB
		
	
	
	
		
			C
		
	
	
		
			Executable File
		
	
	
	
	
/****************************************************************************
 | 
						|
 | 
						|
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 MAC_STREAM_H
 | 
						|
#define MAC_STREAM_H
 | 
						|
#include "plc_utils.h"
 | 
						|
#include "mac_peer.h"
 | 
						|
#include "mac_msdu.h"
 | 
						|
#include "rx_pb_reorder.h"
 | 
						|
#include "iot_config.h"
 | 
						|
 | 
						|
#ifdef __cplusplus
 | 
						|
extern "C" {
 | 
						|
#endif
 | 
						|
 | 
						|
#if PLC_SUPPORT_CCO_ROLE
 | 
						|
 | 
						|
#if RUN_IN_PSRAM
 | 
						|
#define stream_tbl_sz   (1 << 10)
 | 
						|
#else /* RUN_IN_PSRAM */
 | 
						|
#define stream_tbl_sz   (1 << 6)
 | 
						|
#endif /* RUN_IN_PSRAM */
 | 
						|
 | 
						|
#else /* PLC_SUPPORT_CCO_ROLE */
 | 
						|
 | 
						|
#define stream_tbl_sz   (1 << 6)
 | 
						|
 | 
						|
#endif
 | 
						|
 | 
						|
/* define rx stream */
 | 
						|
#define IS_RX_STREAM        0
 | 
						|
/* define tx stream */
 | 
						|
#define IS_TX_STREAM        1
 | 
						|
/* define dbg tx stream */
 | 
						|
#define IS_DBG_TX_STREAM    2
 | 
						|
 | 
						|
/* is plc device stream */
 | 
						|
#define IS_PLC_STREAM    0
 | 
						|
/* is rf device stream */
 | 
						|
#define IS_RF_STREAM     1
 | 
						|
 | 
						|
//rx stream timeout
 | 
						|
#define MAC_RX_STREAM_TIMEOUT_MS    20*1000    //20s
 | 
						|
 | 
						|
/* pack for the structures in the whole file */
 | 
						|
#pragma pack(push)      // save the pack status
 | 
						|
#pragma pack(1)         // 1 byte align
 | 
						|
 | 
						|
typedef struct _mac_tx_stream_ctxt {
 | 
						|
    mac_msdu_t *cur_tx_msdu;
 | 
						|
    mac_msdu_frame_t *mac_frame_list; // the mac_frame queue
 | 
						|
    mac_msdu_frame_t *last_mac_frame; // the last frame
 | 
						|
    /* node in swq */
 | 
						|
    iot_list_head_t swq_node;
 | 
						|
    /* put the not 4-byte align part at the end */
 | 
						|
    /* the number of mac frame in this stream
 | 
						|
     * not include the frame already in HWQ
 | 
						|
     */
 | 
						|
    uint16_t mac_frame_num;
 | 
						|
} mac_tx_stream_ctxt_t;
 | 
						|
 | 
						|
typedef struct _mac_rx_stream_ctxt {
 | 
						|
    reorder_msdu_buf_t reorder_buf;
 | 
						|
} mac_rx_stream_ctxt_t;
 | 
						|
 | 
						|
typedef struct _mac_stream {
 | 
						|
    mac_peer_t *peer;
 | 
						|
    iot_single_list_head_t peer_node;  /* node in peer */
 | 
						|
    struct _mac_stream *next; /* next in stream hash table */
 | 
						|
    union {
 | 
						|
        mac_tx_stream_ctxt_t tx;
 | 
						|
        mac_rx_stream_ctxt_t rx;
 | 
						|
    } msdu;
 | 
						|
    /* put the not 4-byte align part at the end */
 | 
						|
    lid_t   lid;
 | 
						|
    uint8_t is_tx       : 2,
 | 
						|
        in_swq          : 1, /* is in swq already */
 | 
						|
        phase_in_swq    : 2, /* stream phase */
 | 
						|
        is_rf           : 1, /* is plc or rf streaam 0:plc, 1:rf */
 | 
						|
        resv            : 2; /* resv */
 | 
						|
} mac_stream_t;
 | 
						|
 | 
						|
#if DEBUG_FREE_STREAM_FAIL
 | 
						|
typedef struct _mac_debug_stream_ctxt {
 | 
						|
    uint32_t nid;
 | 
						|
    uint32_t lid;
 | 
						|
    uint32_t tei;
 | 
						|
    uint32_t is_tx : 2,
 | 
						|
             is_rf : 1,
 | 
						|
             resv  : 29;
 | 
						|
} mac_debug_stream_t;
 | 
						|
 | 
						|
#endif
 | 
						|
 | 
						|
/* stream hash table related */
 | 
						|
extern mac_stream_t *g_stream_hash_tbl[stream_tbl_sz];
 | 
						|
 | 
						|
uint32_t stream_hash_tbl_get_hsahv(nid_t nid, \
 | 
						|
    tei_t tei, lid_t lid, uint8_t is_tx, uint8_t is_rf);
 | 
						|
 | 
						|
 | 
						|
/*
 | 
						|
*   @peer_in - the peer to look into, could be NULL if nid is valid
 | 
						|
*                else should be not NULL
 | 
						|
*    @nid    -   if 0, the peer_in is needed
 | 
						|
*    @tei    -   tei
 | 
						|
*    @lid    -   lid
 | 
						|
*   @return stream address if found
 | 
						|
*            NULL if not found
 | 
						|
*/
 | 
						|
mac_stream_t * find_stream(mac_peer_t *peer_in, \
 | 
						|
    nid_t nid, tei_t tei, lid_t lid, uint8_t is_tx, uint8_t is_rf);
 | 
						|
 | 
						|
/* @return - 0 for successful
 | 
						|
*           other for failed
 | 
						|
*/
 | 
						|
uint32_t stream_hash_tbl_add(mac_stream_t *stream);
 | 
						|
 | 
						|
 | 
						|
/* @return  - 0 for successful
 | 
						|
 *          - other for error
 | 
						|
 * @peer (INPUT)    - ptr for peer based on
 | 
						|
 * @is_tx(INPUT)    - this stream is for tx or rx
 | 
						|
 * @lid     (INPUT) - link id for this stream
 | 
						|
 * @is_rf   (INPUT) - this stream is for plc or rf
 | 
						|
 * @stream_ptr  (OUTPUT) - the stream created
 | 
						|
 */
 | 
						|
uint32_t mac_stream_alloc(mac_peer_t *peer, uint32_t is_tx, \
 | 
						|
    lid_t lid, uint8_t is_rf, mac_stream_t **stream_ptr);
 | 
						|
 | 
						|
uint32_t mac_stream_free(mac_peer_t *peer, mac_stream_t *stream);
 | 
						|
 | 
						|
uint32_t is_stream_empty(mac_stream_t *stream);
 | 
						|
 | 
						|
/* @brief           dump info when mac stream exhausted
 | 
						|
 * @param peer:     ptr for peer based on
 | 
						|
 * @retval:         void
 | 
						|
 */
 | 
						|
void mac_stream_exhausted_dump(mac_peer_t *peer);
 | 
						|
 | 
						|
#pragma pack(pop)       // restore the pack status
 | 
						|
 | 
						|
 | 
						|
#ifdef __cplusplus
 | 
						|
}
 | 
						|
#endif
 | 
						|
 | 
						|
#endif // !MAC_STREAM_H
 |