Initial version.
This commit is contained in:
@@ -0,0 +1,179 @@
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* Description: Header file for 814 linklayer functions
|
||||
*
|
||||
* Date: 2021-11-13 13:33
|
||||
* LastEditors: Fan Hao
|
||||
* LastEditTime: 2022-07-16 10:12
|
||||
* Revisions: Rev 0.1
|
||||
* History:
|
||||
* [2022-07-16]: New branch for DiJian.
|
||||
* [2021-11-23]: Initial version.
|
||||
*
|
||||
* Copyright(c) 2021 Beijing Institute of Technology.
|
||||
* Lab of Communication and Networking
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef LINKLAYER814_H_
|
||||
#define LINKLAYER814_H_
|
||||
|
||||
/***************************** Include Files *********************************/
|
||||
#include <stdint.h>
|
||||
#include "linklayer814_types.h"
|
||||
#include "node_list.h"
|
||||
#include "rtt.h"
|
||||
#include "../bit_array/bit_array.h"
|
||||
#include "../phy_ctrl/phy_ctrl.h"
|
||||
#include "../time_ctrl/time_ctrl.h"
|
||||
|
||||
|
||||
|
||||
/************************** Constant Definitions *****************************/
|
||||
#define DATA_STORE_INTERVAL 100 // 250ms
|
||||
|
||||
#define NET_INI_STAGE 0
|
||||
#define NET_NORMAL_STAGE 1
|
||||
#define NET_INTER_SEEK_STAGE 2
|
||||
#define NET_INTRA_SEEK_STAGE 3
|
||||
#define NET_SEEK_STAGE 4
|
||||
#define NET_ERROR_STAGE -1
|
||||
|
||||
#define L2_PACKET_LEN_MAX 1024 //bit
|
||||
/***************** Macros (Inline Functions) Definitions *********************/
|
||||
#define AssertL2Event(instPtr, event) Linklayer_EventHandler(instPtr, event)
|
||||
/**************************** Type Definitions *******************************/
|
||||
|
||||
typedef struct {
|
||||
L2_NODE_TYPE myType;
|
||||
bool isInterHead;
|
||||
uint8_t clustId;
|
||||
uint8_t myId;
|
||||
uint8_t headId;
|
||||
uint8_t bkpHeadId;
|
||||
uint8_t netScale;
|
||||
PHY_INST* phyInstPtr;
|
||||
TIMECTRL_INST* tmcInstPtr;
|
||||
} L2_CONFIG;
|
||||
|
||||
typedef struct {
|
||||
L2_CONFIG config;
|
||||
L2_NODE_INFO myInfo;
|
||||
NODE_LIST* nodeList;
|
||||
L2_SCHD_EVENT* l2SchdEventPool[L2_SCHD_EVENT_MAX];
|
||||
uint32_t schdEventCnt;
|
||||
uint32_t netStartTime;
|
||||
bool isEnable; // if the node is connected to the network
|
||||
bool dataAvail; // if there is a valid received frame data in rx buffer
|
||||
bool cxn2Net; // if the node is connected to the network
|
||||
L2_RCD frameNum; // stores the last current and next frame number.
|
||||
L2_RCD slotNum; // stores the last current and next slot number.
|
||||
L2_RCD frame; // stores the last current and next link layer frame type.
|
||||
L2_NODE_STATE mainState; // the main state of link layer state
|
||||
L2_NODE_STATE nextState; // next state of link layer state, which will be applied to mainState every second.
|
||||
L2_RTNE_CONFIG rtneConfig; // current routine table configuration and status.
|
||||
L2_SCAN_FSM* scanNetFSM; // FSM of scan net (link set up)
|
||||
L2_MGMT_FSM* mgmtNetFSM; // FSM of management net (link management and time sync)
|
||||
L2_SVC_FSM* serviceNetFSM; // FSM of service net (data service)
|
||||
L2_RTT_FSM* rttFSM; // FSM for RTT (time sync algorithm)
|
||||
uint8_t* sendPktData;
|
||||
uint8_t* recvPktData;
|
||||
// for MPC
|
||||
uint8_t buffSwitch;
|
||||
uint8_t mgmtMsgRecvCnt0;
|
||||
uint8_t svcMsgRecvCnt0;
|
||||
uint8_t* mgmtMsgRecvBuff0; // mgmtMsg receive data buffer
|
||||
uint8_t* svcMsgRecvBuff0; // svc receive data buffer
|
||||
uint8_t mgmtMsgRecvCnt1;
|
||||
uint8_t svcMsgRecvCnt1;
|
||||
uint8_t* mgmtMsgRecvBuff1; // mgmtMsg receive data buffer
|
||||
uint8_t* svcMsgRecvBuff1; // svc receive data buffer
|
||||
} L2_INST;
|
||||
|
||||
/************************** Variable Definitions *****************************/
|
||||
extern L2_RTNE_TABLE_ENTRY* initTable[L2_INIT_RTNE_PERIOD];
|
||||
extern L2_RTNE_TABLE_ENTRY* seekTable[L2_SEEK_RTNE_PERIOD];
|
||||
extern L2_RTNE_TABLE_ENTRY* interSeekTable[L2_NORMAL_RTNE_PERIOD];
|
||||
extern L2_RTNE_TABLE_ENTRY* intraSeekTable[L2_NORMAL_RTNE_PERIOD];
|
||||
extern L2_RTNE_TABLE_ENTRY* normalTable[L2_NORMAL_RTNE_PERIOD];
|
||||
/************************** Function Prototypes ******************************/
|
||||
// Main
|
||||
int32_t Linklayer_Init(L2_INST** instPtr, const L2_CONFIG *config);
|
||||
int32_t Linklayer_Reconfig(L2_INST* instPtr, const L2_CONFIG *config);
|
||||
void Linklayer_Destroy(L2_INST* instPtr);
|
||||
int32_t Linklayer_Start(L2_INST* instPtr);
|
||||
int32_t Linklayer_Halt(L2_INST* instPtr);
|
||||
int32_t Linklayer_Proc(L2_INST* instPtr);
|
||||
int32_t Linklayer_EventHandler(L2_INST* instPtr, const L2_EVENT* l2Event);
|
||||
int32_t Linklayer_PktHandler(L2_INST* instPtr, L2_FRAME_TYPE frameType);
|
||||
int32_t L2_SetupNextSlot(L2_INST* instPtr, L2_TOR_TYPE txrxMode, L2_FRAME_TYPE frameType);
|
||||
|
||||
// Event
|
||||
bool L2_isEventScheduled(L2_SCHD_EVENT* schdEvent);
|
||||
int32_t L2_CancelEvent(L2_SCHD_EVENT* schdEvent);
|
||||
int32_t L2_SchdEventAppendMsg(L2_SCHD_EVENT* schdEvent, void* msg);
|
||||
L2_SCHD_EVENT* L2_CreatNewSchdEvent(L2_INST* instPtr, L2_EVENT_TYPE event);
|
||||
int32_t L2_DeletSchdEvent(L2_INST* instPtr, int32_t eventId);
|
||||
void L2_ClearSchdEvent(L2_INST* instPtr);
|
||||
int32_t L2_ScheduleEventAt(L2_INST* instPtr, L2_SCHD_EVENT* schdEvent, uint32_t frameNo, uint32_t slotNo);
|
||||
int32_t L2_ScheduleEventAfter(L2_INST* instPtr, L2_SCHD_EVENT* schdEvent, uint32_t numSlots);
|
||||
int32_t L2_RecheduleEventAt(L2_INST* instPtr, L2_SCHD_EVENT* schdEvent, uint32_t frameNo, uint32_t slotNo);
|
||||
int32_t L2_RecheduleEventAfter(L2_INST* instPtr, L2_SCHD_EVENT* schdEvent, uint32_t numSlots);
|
||||
|
||||
// Framing
|
||||
void L2_FrameStateUpdate(L2_INST* instPtr);
|
||||
L2_FRAME_TYPE L2_GetLastRcvFrameType(L2_INST* instPtr);
|
||||
L1_FRAME_TYPE L2_L2frame2L1frame(L2_FRAME_TYPE l2Frame);
|
||||
void FrameGetChunk(BIT_ARRAY* bitarr, uint32_t offset, uint32_t numBit, uint64_t* chunk);
|
||||
void FrameInsertChunk(BIT_ARRAY* bitarr, uint32_t offset, uint32_t numBit, uint64_t chunck);
|
||||
int32_t L2_CrcAppend(uint8_t* dataBuff, uint32_t dataLen, uint32_t crcPos, L2_CRC_TYPE crcType);
|
||||
bool L2_CrcCheck(uint8_t* dataBuff, uint32_t dataLen, uint32_t crcPos, L2_CRC_TYPE crcType);
|
||||
|
||||
// Scan Net
|
||||
int32_t ScanNet_Init(L2_SCAN_FSM** scanFSMPtr);
|
||||
void ScanNet_Reset(L2_SCAN_FSM* scanFSMPtr);
|
||||
void ScanNet_Destroy(L2_SCAN_FSM* scanFSMPtr);
|
||||
int32_t ScanNet_Proc(L2_INST* instPtr);
|
||||
int32_t ScanNet_PktHandler(L2_INST* instPtr);
|
||||
int32_t ScanNet_Routine(L2_INST* instPtr, const L2_RTNE_TABLE_ENTRY* rtneEntry);
|
||||
|
||||
// Management Net
|
||||
int32_t MgmtNet_Init(L2_MGMT_FSM** mgmtFSM);
|
||||
void MgmtNet_Reset(L2_MGMT_FSM* mgmtFSM);
|
||||
void MgmtNet_Destroy(L2_MGMT_FSM* mgmtFSM);
|
||||
int32_t MgmtNet_PktHandler(L2_INST* instPtr);
|
||||
int32_t MgmtNet_Routine(L2_INST* instPtr, const L2_RTNE_TABLE_ENTRY* rtneEntry);
|
||||
|
||||
|
||||
// Service net
|
||||
int32_t ServiceNet_Init(L2_SVC_FSM** serviceFSM);
|
||||
void ServiceNet_Reset(L2_SVC_FSM* serviceFSM);
|
||||
void ServiceNet_Destroy(L2_SVC_FSM* serviceFSM);
|
||||
int32_t ServiceNet_PktHandler(L2_INST* instPtr);
|
||||
int32_t ServiceNet_Routine(L2_INST* instPtr, const L2_RTNE_TABLE_ENTRY* schedEntry);
|
||||
|
||||
// Miscellaneous
|
||||
L2_NODE_STATE L2_GetMainState(L2_INST* instPtr);
|
||||
L2_RTT_FSM* L2_GetRttDesc(L2_INST* instPtr);
|
||||
bool L2_isDataAvail(L2_INST* instPtr);
|
||||
bool L2_isCxn2Net(L2_INST* instPtr);
|
||||
void L2_RcdShift(L2_RCD* rcd, int32_t netxVal);
|
||||
uint32_t L2_GetFrameLen(L2_FRAME_TYPE l2FrameType);
|
||||
uint32_t L2_GetLastFrameNum(L2_INST* instPtr);
|
||||
uint32_t L2_GetLastSlotNum(L2_INST* instPtr);
|
||||
uint32_t L2_GetCurrentFrameNum(L2_INST* instPtr);
|
||||
uint32_t L2_GetCurrentSlotNum(L2_INST* instPtr);
|
||||
uint32_t L2_GetNextFrameNum(L2_INST* instPtr);
|
||||
uint32_t L2_GetNextSlotNum(L2_INST* instPtr);
|
||||
|
||||
// Time syncronization
|
||||
int32_t L2_TimeAlign(L2_INST* instPtr, uint32_t frameNum, uint32_t slotNum);
|
||||
|
||||
// RTT
|
||||
int32_t RTT_Init(L2_RTT_FSM** rttFsmPtr);
|
||||
void RTT_Reset(L2_RTT_FSM* rttFsmPtr);
|
||||
void RTT_Destroy(L2_RTT_FSM* rttFsmPtr);
|
||||
int32_t RTT_Proc(L2_INST* instPtr);
|
||||
|
||||
|
||||
#endif /* LINKLAYER814_H_ */
|
||||
Reference in New Issue
Block a user