formatted.
This commit is contained in:
@@ -1,18 +1,18 @@
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* Description: Functions for framing operations.
|
||||
*
|
||||
*
|
||||
* Date: 2022-07-16 14:17
|
||||
* LastEditors: Fan Hao
|
||||
* LastEditTime: 2022-07-16 17:11
|
||||
* Revisions: Rev 0.0
|
||||
* History:
|
||||
* History:
|
||||
* [2022-07-16]: Description of modification.
|
||||
*
|
||||
*
|
||||
* Copyright(c) 2022 Beijing Institute of Technology.
|
||||
* Lab of Communication and Networking
|
||||
*
|
||||
******************************************************************************/
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/***************************** Include Files *********************************/
|
||||
#include <stdint.h>
|
||||
@@ -24,7 +24,6 @@
|
||||
|
||||
/************************** Constant Definitions *****************************/
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* @brief Generate crc of specified data.
|
||||
@@ -38,18 +37,20 @@
|
||||
* SUCCESS
|
||||
*
|
||||
******************************************************************************/
|
||||
static int32_t L2_CrcGen(uint8_t* dataBuff, uint32_t dataLen, L2_CRC_TYPE crcType, uint32_t* crc){
|
||||
static int32_t L2_CrcGen(uint8_t *dataBuff, uint32_t dataLen, L2_CRC_TYPE crcType, uint32_t *crc)
|
||||
{
|
||||
ASSERT(dataBuff != NULL);
|
||||
int32_t Status;
|
||||
switch (crcType){
|
||||
switch (crcType)
|
||||
{
|
||||
case L2_CRC16_1021:
|
||||
Status = crc16_gen(dataBuff, dataLen, 0x1021, (uint16_t*)crc);
|
||||
Status = crc16_gen(dataBuff, dataLen, 0x1021, (uint16_t *)crc);
|
||||
break;
|
||||
case L2_CRC16_8005:
|
||||
Status = crc16_gen(dataBuff, dataLen, 0x8005, (uint16_t*)crc);
|
||||
Status = crc16_gen(dataBuff, dataLen, 0x8005, (uint16_t *)crc);
|
||||
break;
|
||||
case L2_CRC8_31:
|
||||
Status = crc8_gen(dataBuff, dataLen, 0x31, (uint8_t*)crc);
|
||||
Status = crc8_gen(dataBuff, dataLen, 0x31, (uint8_t *)crc);
|
||||
break;
|
||||
default:
|
||||
Status = EPARAM;
|
||||
@@ -71,23 +72,26 @@ static int32_t L2_CrcGen(uint8_t* dataBuff, uint32_t dataLen, L2_CRC_TYPE crcTyp
|
||||
* SUCCESS
|
||||
*
|
||||
******************************************************************************/
|
||||
int32_t L2_CrcAppend(uint8_t* dataBuff, uint32_t dataLen, uint32_t crcPos, L2_CRC_TYPE crcType){
|
||||
int32_t L2_CrcAppend(uint8_t *dataBuff, uint32_t dataLen, uint32_t crcPos, L2_CRC_TYPE crcType)
|
||||
{
|
||||
ASSERT(dataBuff != NULL);
|
||||
int32_t Status;
|
||||
uint32_t crcVal;
|
||||
uint8_t* crcPtr;
|
||||
uint8_t *crcPtr;
|
||||
crcPtr = dataBuff + crcPos;
|
||||
Status = L2_CrcGen(dataBuff,dataLen, crcType, &crcVal);
|
||||
if(Status != SUCCESS){
|
||||
Status = L2_CrcGen(dataBuff, dataLen, crcType, &crcVal);
|
||||
if (Status != SUCCESS)
|
||||
{
|
||||
return Status;
|
||||
}
|
||||
switch (crcType){
|
||||
switch (crcType)
|
||||
{
|
||||
case L2_CRC16_1021:
|
||||
*(crcPtr+1) = (uint8_t)(crcVal>>8);
|
||||
*(crcPtr + 1) = (uint8_t)(crcVal >> 8);
|
||||
*crcPtr = (uint8_t)(crcVal);
|
||||
break;
|
||||
case L2_CRC16_8005:
|
||||
*(crcPtr+1) = (uint8_t)(crcVal>>8);
|
||||
*(crcPtr + 1) = (uint8_t)(crcVal >> 8);
|
||||
*crcPtr = (uint8_t)(crcVal);
|
||||
break;
|
||||
case L2_CRC8_31:
|
||||
@@ -112,21 +116,26 @@ int32_t L2_CrcAppend(uint8_t* dataBuff, uint32_t dataLen, uint32_t crcPos, L2_CR
|
||||
* SUCCESS
|
||||
*
|
||||
******************************************************************************/
|
||||
bool L2_CrcCheck(uint8_t* dataBuff, uint32_t dataLen, L2_CRC_TYPE crcType){
|
||||
bool L2_CrcCheck(uint8_t *dataBuff, uint32_t dataLen, L2_CRC_TYPE crcType)
|
||||
{
|
||||
ASSERT(dataBuff != NULL);
|
||||
int32_t Status;
|
||||
uint32_t crcVal;
|
||||
crcVal = 0;
|
||||
Status = L2_CrcGen(dataBuff, dataLen, crcType, &crcVal);
|
||||
if(Status == SUCCESS){
|
||||
if(crcVal == 0){
|
||||
if (Status == SUCCESS)
|
||||
{
|
||||
if (crcVal == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,17 +1,17 @@
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* Description: Header file for df linklayer functions
|
||||
*
|
||||
*
|
||||
* Date: 2021-11-13 13:33
|
||||
* LastEditTime: 2022-07-16 10:12
|
||||
* Revisions: Rev 0.1
|
||||
* History:
|
||||
* 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 __LINK_LAYER_H_
|
||||
@@ -26,50 +26,53 @@
|
||||
#include "../config/app_config.h"
|
||||
#include "node_list.h"
|
||||
/************************** Constant Definitions *****************************/
|
||||
#define L2_HEAD_NODE_ID 1
|
||||
#define L2_MEMBER_NODE_ID 2
|
||||
#define L2_HEAD_NODE_ID 1
|
||||
#define L2_MEMBER_NODE_ID 2
|
||||
/***************** Macros (Inline Functions) Definitions *********************/
|
||||
//#define AssertL2Event(inst, envent) Linklayer_EventHandler(inst, envent)
|
||||
// #define AssertL2Event(inst, event) Linklayer_EventHandler(inst, event)
|
||||
/**************************** Type Definitions *******************************/
|
||||
|
||||
typedef struct{
|
||||
L2_RTNE_TABLE_ENTRY** rtneTable;
|
||||
typedef struct
|
||||
{
|
||||
L2_RTNE_TABLE_ENTRY **rtneTable;
|
||||
uint32_t rtnePrd;
|
||||
uint32_t rtneStep;
|
||||
L2_RTNE_TABLE_ENTRY* last;
|
||||
L2_RTNE_TABLE_ENTRY* curr;
|
||||
L2_RTNE_TABLE_ENTRY* next;
|
||||
}L2_RTNE_CONFIG;
|
||||
L2_RTNE_TABLE_ENTRY *last;
|
||||
L2_RTNE_TABLE_ENTRY *curr;
|
||||
L2_RTNE_TABLE_ENTRY *next;
|
||||
} L2_RTNE_CONFIG;
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
L2_NODE_TYPE myType;
|
||||
// bool isInterHead;
|
||||
// uint8_t clustId;
|
||||
// bool isInterHead;
|
||||
// uint8_t clustId;
|
||||
uint8_t myId;
|
||||
uint8_t headId;
|
||||
// uint8_t bkpHeadId;
|
||||
// uint8_t bkpHeadId;
|
||||
uint8_t netScale;
|
||||
PHY_INST* phyInstRef; // pyhsical layer reference
|
||||
PHY_INST *phyInstRef; // pyhsical layer reference
|
||||
} L2_CONFIG;
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
L2_CONFIG config;
|
||||
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 frameNo; // stores the last current and next frame number.
|
||||
L2_RCD slotNo; // stores the last current and next slot number.
|
||||
L2_RCD frame; // stores the last current and next link layer frame type.
|
||||
L2_RCD torState; // stores the last current and next link layer send/receive state.
|
||||
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.
|
||||
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 frameNo; // stores the last current and next frame number.
|
||||
L2_RCD slotNo; // stores the last current and next slot number.
|
||||
L2_RCD frame; // stores the last current and next link layer frame type.
|
||||
L2_RCD torState; // stores the last current and next link layer send/receive state.
|
||||
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_SCHD_EVENT* schdEventPool[L2_SCHD_EVENT_MAX];
|
||||
L2_SCHD_EVENT *schdEventPool[L2_SCHD_EVENT_MAX];
|
||||
uint32_t schdEventCnt;
|
||||
SCAN_FSM scanFsm;
|
||||
SVC_FSM serviceFsm;
|
||||
NODE_LIST *nodeInfoList;
|
||||
uint8_t* sendPktData;
|
||||
uint8_t* recvPktData;
|
||||
uint8_t *sendPktData;
|
||||
uint8_t *recvPktData;
|
||||
// for system log
|
||||
SYSINFO sysInfo;
|
||||
SLOTLOG txSlotLog;
|
||||
@@ -83,32 +86,32 @@ typedef struct {
|
||||
} L2_INST;
|
||||
|
||||
/************************** Variable Definitions *****************************/
|
||||
extern L2_RTNE_TABLE_ENTRY* normalTable[L2_RTNE_PERIOD];
|
||||
extern L2_RTNE_TABLE_ENTRY *normalTable[L2_RTNE_PERIOD];
|
||||
/************************** Function Prototypes ******************************/
|
||||
// Main
|
||||
int32_t Linklayer_Init(L2_INST **instPtr, L2_CONFIG *config);
|
||||
int32_t Linklayer_Proc(L2_INST *instPtr);
|
||||
int32_t Linklayer_EventHandler(L2_INST *instPtr, L2_EVENT* l2Event);
|
||||
int32_t Linklayer_EventHandler(L2_INST *instPtr, L2_EVENT *l2Event);
|
||||
int32_t Linklayer_PktHandler(L2_INST *instPtr);
|
||||
int32_t L2_SteerBeam2Node(L2_INST *instPtr, uint8_t nodeId);
|
||||
int32_t L2_SetupNextSlot(L2_INST *instPtr, L2_TOR_TYPE txrxMode, L2_FRAME_TYPE frameType);
|
||||
|
||||
// Event
|
||||
L2_SCHD_EVENT* L2_CreatNewSchdEvent(L2_INST *instPtr, L2_EVENT_TYPE 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);
|
||||
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);
|
||||
L2_SCHD_EVENT *L2_CreatNewSchdEvent(L2_INST *instPtr, L2_EVENT_TYPE 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);
|
||||
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);
|
||||
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, L2_CRC_TYPE crcType);
|
||||
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, L2_CRC_TYPE crcType);
|
||||
|
||||
// Miscellaneous
|
||||
L2_NODE_STATE L2_GetMainState(L2_INST *instPtr);
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* Description: A brief description of this file
|
||||
*
|
||||
*
|
||||
* Date: 2022-08-28 22:53
|
||||
* LastEditTime: 2022-08-29 00:45
|
||||
* Revisions: Rev 0.0
|
||||
* History:
|
||||
* History:
|
||||
* [2022-08-29]: Initial version.
|
||||
*
|
||||
*
|
||||
* Copyright(c) 2022 Beijing Institute of Technology.
|
||||
* Lab of Communication and Networking
|
||||
*
|
||||
******************************************************************************/
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __LINK_LAYER_DEF_H_
|
||||
#define __LINK_LAYER_DEF_H_
|
||||
@@ -36,16 +36,16 @@
|
||||
#define L2_FRAMENO_NONE 0
|
||||
|
||||
// Common number of slots definition
|
||||
#define L2_FRAME_NO_MAX 256
|
||||
#define L2_SLOTS_PER_FRAME 200
|
||||
#define L2_SLOTS_PER_SUBFRAME 20
|
||||
#define L2_FRAME_NO_MAX 256
|
||||
#define L2_SLOTS_PER_FRAME 200
|
||||
#define L2_SLOTS_PER_SUBFRAME 20
|
||||
|
||||
#define NUM_SLOTS_NONE UINT32_MAX
|
||||
#define NUM_SLOTS_100MS 20
|
||||
#define NUM_SLOTS_20MS 4
|
||||
#define NUM_SLOTS_10MS 2
|
||||
#define NUM_SLOTS_5MS 1
|
||||
#define NUM_SLOTS_SKIP 0
|
||||
#define NUM_SLOTS_100MS 20
|
||||
#define NUM_SLOTS_20MS 4
|
||||
#define NUM_SLOTS_10MS 2
|
||||
#define NUM_SLOTS_5MS 1
|
||||
#define NUM_SLOTS_SKIP 0
|
||||
|
||||
// Common schedule event definition
|
||||
#define L2_SCHD_EVENT_MAX 16
|
||||
@@ -54,13 +54,15 @@
|
||||
#define AssertL2Event(inst, envent) Linklayer_EventHandler(inst, envent)
|
||||
/**************************** Type Definitions *******************************/
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
int32_t last;
|
||||
int32_t curr;
|
||||
int32_t next;
|
||||
} L2_RCD;
|
||||
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
L2_TOR_SUSPEND = 0,
|
||||
L2_TOR_TX = 1,
|
||||
L2_TOR_RX = 2
|
||||
@@ -68,7 +70,8 @@ typedef enum {
|
||||
|
||||
/** @name Prior information type definition
|
||||
*/
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
L2_NONE_TYPE = 0,
|
||||
L2_HEAD_NODE = 1,
|
||||
L2_MEMBER_NODE = 2,
|
||||
@@ -77,17 +80,18 @@ typedef enum {
|
||||
/** @name Node state type definition
|
||||
*/
|
||||
|
||||
typedef enum {
|
||||
NONE_STATE = 0,
|
||||
INIT_STATE = 1,
|
||||
typedef enum
|
||||
{
|
||||
NONE_STATE = 0,
|
||||
INIT_STATE = 1,
|
||||
NORMAL_STATE = 2
|
||||
} L2_NODE_STATE;
|
||||
|
||||
|
||||
/** @name Node information type definition
|
||||
* The following types define the detail node info which needed by the link layer.
|
||||
*/
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
uint8_t nodeId;
|
||||
uint8_t nodeType;
|
||||
uint8_t beamNo;
|
||||
@@ -99,7 +103,8 @@ typedef struct {
|
||||
/** @name L2 event enum
|
||||
* A enum of L2 event types.
|
||||
*/
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
L2_EV_NONE = 0,
|
||||
L2_EV_SCAN_PROC_DONE = 1,
|
||||
L2_EV_NET_SETUP_DONE = 2,
|
||||
@@ -116,15 +121,17 @@ typedef enum {
|
||||
/** @name L2 event
|
||||
* A definition of L2 event instance.
|
||||
*/
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
L2_EVENT_TYPE event;
|
||||
void* msg;
|
||||
void *msg;
|
||||
} L2_EVENT;
|
||||
|
||||
/** @name L2 event
|
||||
* A definition of L2 event instance.
|
||||
*/
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
uint8_t eventId;
|
||||
bool isSchd;
|
||||
L2_EVENT l2Event;
|
||||
@@ -135,7 +142,8 @@ typedef struct {
|
||||
/** @name Slot types
|
||||
* A definition of different slots.
|
||||
*/
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
L2_SLOT_NONE = 0,
|
||||
L2_SLOT_IDLE = 1,
|
||||
L2_SLOT_SCAN = 2,
|
||||
@@ -146,7 +154,8 @@ typedef enum {
|
||||
/** @name Frame types
|
||||
* A definition of different frame types.
|
||||
*/
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
L2_NONE_FRAME = 0,
|
||||
L2_SCAN_FRAME = 1,
|
||||
L2_SVC_FRAME = 2,
|
||||
@@ -156,7 +165,8 @@ typedef enum {
|
||||
/** @name Frame types
|
||||
* A definition of different frame types.
|
||||
*/
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
L2_CRC_NONE = 0,
|
||||
L2_CRC16_1021 = 1,
|
||||
L2_CRC16_8005 = 2,
|
||||
@@ -166,7 +176,8 @@ typedef enum {
|
||||
/** @name Schedule subtable entry
|
||||
* A definition of Schedule subtable entry.
|
||||
*/
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
L2_SLOT_TYPE slotType : 8;
|
||||
uint8_t slotSeq;
|
||||
uint8_t src;
|
||||
@@ -175,14 +186,16 @@ typedef struct {
|
||||
|
||||
/** @name Scan procedure FSM
|
||||
*/
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
uint8_t sacanCnt;
|
||||
uint8_t beamNo;
|
||||
} SCAN_FSM;
|
||||
|
||||
/** @name Service procedure FSM
|
||||
*/
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
uint32_t txSeqNum;
|
||||
uint32_t rxSeqNum;
|
||||
uint8_t rxLog[256];
|
||||
|
||||
@@ -26,10 +26,10 @@
|
||||
// 1 slot number
|
||||
// 26 payload
|
||||
// 2 crc
|
||||
#define L2_MSG_FRAME_NO 0
|
||||
#define L2_MSG_SLOT_NO 1
|
||||
#define L2_MSG_PAYLOAD 2
|
||||
#define L2_MSG_CRC 28
|
||||
#define L2_MSG_FRAME_NO 0
|
||||
#define L2_MSG_SLOT_NO 1
|
||||
#define L2_MSG_PAYLOAD 2
|
||||
#define L2_MSG_CRC 28
|
||||
|
||||
// service frame structure:
|
||||
// [bytes] [name]
|
||||
@@ -38,13 +38,13 @@
|
||||
// 3 time sync
|
||||
// 23 payload
|
||||
// 2 crc
|
||||
#define L2_MSG_SVC_TMSYNC 2
|
||||
#define L2_MSG_SVC_TMSYNC_LEN 3
|
||||
#define L2_MSG_SVC_TMSYNC_MAX (8388607) //0x007FFFFF
|
||||
#define L2_MSG_SVC_TMSYNC_MIN (-8388608) //0x00800000
|
||||
#define L2_MSG_SVC_SEQ_ID 5
|
||||
#define L2_MSG_SVC_PAYLOAD 6
|
||||
#define L2_MSG_SVC_PAYLOAD_LEN 22
|
||||
#define L2_MSG_SVC_TMSYNC 2
|
||||
#define L2_MSG_SVC_TMSYNC_LEN 3
|
||||
#define L2_MSG_SVC_TMSYNC_MAX (8388607) // 0x007FFFFF
|
||||
#define L2_MSG_SVC_TMSYNC_MIN (-8388608) // 0x00800000
|
||||
#define L2_MSG_SVC_SEQ_ID 5
|
||||
#define L2_MSG_SVC_PAYLOAD 6
|
||||
#define L2_MSG_SVC_PAYLOAD_LEN 22
|
||||
|
||||
// response frame structure:
|
||||
// [bytes] [name]
|
||||
@@ -58,11 +58,11 @@
|
||||
// 4 speed z
|
||||
// 2 dummy
|
||||
// 2 crc
|
||||
#define L2_MSG_INFO_POSX 2
|
||||
#define L2_MSG_INFO_POSY 6
|
||||
#define L2_MSG_INFO_POSZ 10
|
||||
#define L2_MSG_INFO_SPEEDX 14
|
||||
#define L2_MSG_INFO_SPEEDY 18
|
||||
#define L2_MSG_INFO_SPEEDZ 22
|
||||
#define L2_MSG_INFO_DUMMY 26
|
||||
#define L2_MSG_INFO_POSX 2
|
||||
#define L2_MSG_INFO_POSY 6
|
||||
#define L2_MSG_INFO_POSZ 10
|
||||
#define L2_MSG_INFO_SPEEDX 14
|
||||
#define L2_MSG_INFO_SPEEDY 18
|
||||
#define L2_MSG_INFO_SPEEDZ 22
|
||||
#define L2_MSG_INFO_DUMMY 26
|
||||
#endif //__L2_MSG_DEF_H_
|
||||
|
||||
@@ -23,7 +23,8 @@
|
||||
/************************** Constant Definitions *****************************/
|
||||
|
||||
/***************** Macros (Inline Functions) Definitions *********************/
|
||||
inline int32_t GetNodeNum(NODE_LIST *list) {
|
||||
inline int32_t GetNodeNum(NODE_LIST *list)
|
||||
{
|
||||
ASSERT(list != NULL);
|
||||
return list->nodeNum;
|
||||
}
|
||||
@@ -43,14 +44,17 @@ inline int32_t GetNodeNum(NODE_LIST *list) {
|
||||
* ENOMEM - not enough memory.
|
||||
*
|
||||
******************************************************************************/
|
||||
int32_t NodeList_Init(NODE_LIST **list) {
|
||||
int32_t NodeList_Init(NODE_LIST **list)
|
||||
{
|
||||
NODE_ENTRY *entry;
|
||||
(*list) = malloc(sizeof(NODE_LIST));
|
||||
if (*list == NULL) {
|
||||
if (*list == NULL)
|
||||
{
|
||||
return ENOMEM;
|
||||
}
|
||||
entry = malloc(sizeof(NODE_ENTRY));
|
||||
if(entry == NULL) {
|
||||
if (entry == NULL)
|
||||
{
|
||||
free(*list);
|
||||
return ENOMEM;
|
||||
}
|
||||
@@ -62,11 +66,13 @@ int32_t NodeList_Init(NODE_LIST **list) {
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
void NodeList_Clear(NODE_LIST *list){
|
||||
void NodeList_Clear(NODE_LIST *list)
|
||||
{
|
||||
ASSERT(list != NULL);
|
||||
NODE_ENTRY *nodeEntry, *deletEntry;
|
||||
nodeEntry = list->head->nextNode;
|
||||
while (nodeEntry != list->head) {
|
||||
while (nodeEntry != list->head)
|
||||
{
|
||||
deletEntry = nodeEntry;
|
||||
nodeEntry = nodeEntry->nextNode;
|
||||
deletEntry->preNode->nextNode = deletEntry->nextNode;
|
||||
@@ -77,8 +83,10 @@ void NodeList_Clear(NODE_LIST *list){
|
||||
}
|
||||
}
|
||||
|
||||
void NodeList_Destroy(NODE_LIST *list){
|
||||
if(list == NULL){
|
||||
void NodeList_Destroy(NODE_LIST *list)
|
||||
{
|
||||
if (list == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
NodeList_Clear(list);
|
||||
@@ -97,21 +105,27 @@ void NodeList_Destroy(NODE_LIST *list){
|
||||
* NULL if node dose not exist.
|
||||
*
|
||||
******************************************************************************/
|
||||
NODE_ENTRY* GetNode(NODE_LIST *list, uint32_t nodeId) {
|
||||
NODE_ENTRY *GetNode(NODE_LIST *list, uint32_t nodeId)
|
||||
{
|
||||
ASSERT(list != NULL);
|
||||
NODE_ENTRY* nodeEntry = list->head->nextNode;
|
||||
while (nodeEntry != list->head) {
|
||||
if (nodeEntry->nodeInfo.nodeId == nodeId) {
|
||||
NODE_ENTRY *nodeEntry = list->head->nextNode;
|
||||
while (nodeEntry != list->head)
|
||||
{
|
||||
if (nodeEntry->nodeInfo.nodeId == nodeId)
|
||||
{
|
||||
break;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
nodeEntry = nodeEntry->nextNode;
|
||||
}
|
||||
}
|
||||
if (nodeEntry == list->head) {
|
||||
if (nodeEntry == list->head)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
return nodeEntry;
|
||||
}
|
||||
}
|
||||
@@ -127,7 +141,8 @@ NODE_ENTRY* GetNode(NODE_LIST *list, uint32_t nodeId) {
|
||||
* false node not in the list
|
||||
*
|
||||
******************************************************************************/
|
||||
inline bool IsNodeInList(NODE_LIST *list, uint8_t nodeId) {
|
||||
inline bool IsNodeInList(NODE_LIST *list, uint8_t nodeId)
|
||||
{
|
||||
ASSERT(list != NULL);
|
||||
return (GetNode(list, nodeId) != NULL);
|
||||
}
|
||||
@@ -147,17 +162,19 @@ inline bool IsNodeInList(NODE_LIST *list, uint8_t nodeId) {
|
||||
int32_t AppendNode(NODE_LIST *list, uint8_t nodeId, L2_NODE_TYPE nodeType)
|
||||
{
|
||||
ASSERT(list != NULL);
|
||||
if(IsNodeInList(list, nodeId)){
|
||||
if (IsNodeInList(list, nodeId))
|
||||
{
|
||||
DBG_WARNING("Node [%d] already exist.\n", nodeId);
|
||||
return FAILURE;
|
||||
}
|
||||
DBG_INFO("Link layer appending node [%d] to node list.\n", nodeId);
|
||||
NODE_ENTRY* nodeEntry = (NODE_ENTRY*) malloc(sizeof(NODE_ENTRY));
|
||||
if (nodeEntry == NULL) {
|
||||
NODE_ENTRY *nodeEntry = (NODE_ENTRY *)malloc(sizeof(NODE_ENTRY));
|
||||
if (nodeEntry == NULL)
|
||||
{
|
||||
return ENOMEM;
|
||||
}
|
||||
nodeEntry->nodeInfo.nodeId = nodeId;
|
||||
nodeEntry->nodeInfo.nodeType = (uint8_t) nodeType;
|
||||
nodeEntry->nodeInfo.nodeType = (uint8_t)nodeType;
|
||||
nodeEntry->nodeInfo.pos.x = 0;
|
||||
nodeEntry->nodeInfo.pos.y = 0;
|
||||
nodeEntry->nodeInfo.pos.z = 0;
|
||||
@@ -186,10 +203,12 @@ int32_t AppendNode(NODE_LIST *list, uint8_t nodeId, L2_NODE_TYPE nodeType)
|
||||
* Other Node not exist.
|
||||
*
|
||||
******************************************************************************/
|
||||
int32_t DeletNode(NODE_LIST *list, uint8_t nodeId) {
|
||||
int32_t DeletNode(NODE_LIST *list, uint8_t nodeId)
|
||||
{
|
||||
ASSERT(list != NULL);
|
||||
NODE_ENTRY* nodeEntry = GetNode(list, nodeId);
|
||||
if(nodeEntry == NULL){
|
||||
NODE_ENTRY *nodeEntry = GetNode(list, nodeId);
|
||||
if (nodeEntry == NULL)
|
||||
{
|
||||
DBG_WARNING("Node [%d] in not in node list, skip deleting process.\n", nodeId);
|
||||
return SUCCESS;
|
||||
}
|
||||
@@ -201,7 +220,6 @@ int32_t DeletNode(NODE_LIST *list, uint8_t nodeId) {
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* @brief Get the distance between me and the node.
|
||||
@@ -215,13 +233,16 @@ int32_t DeletNode(NODE_LIST *list, uint8_t nodeId) {
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
int32_t GetDistance(NODE_LIST *list, COORD myCoord, uint8_t nodeId, double* dst) {
|
||||
int32_t GetDistance(NODE_LIST *list, COORD myCoord, uint8_t nodeId, double *dst)
|
||||
{
|
||||
ASSERT(list != NULL);
|
||||
NODE_ENTRY* nodeEntry = GetNode(list, nodeId);
|
||||
if (nodeEntry == NULL) {
|
||||
NODE_ENTRY *nodeEntry = GetNode(list, nodeId);
|
||||
if (nodeEntry == NULL)
|
||||
{
|
||||
return FAILURE;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
*dst = Coord_Distance(myCoord, nodeEntry->nodeInfo.pos);
|
||||
return SUCCESS;
|
||||
}
|
||||
@@ -239,19 +260,21 @@ int32_t GetDistance(NODE_LIST *list, COORD myCoord, uint8_t nodeId, double* dst)
|
||||
* FAILURE node not exist.
|
||||
*
|
||||
******************************************************************************/
|
||||
int32_t UpdateNodePos(NODE_LIST *list, uint8_t nodeId, const COORD *newPos) {
|
||||
int32_t UpdateNodePos(NODE_LIST *list, uint8_t nodeId, const COORD *newPos)
|
||||
{
|
||||
ASSERT(list != NULL);
|
||||
NODE_ENTRY* nodeEntry = GetNode(list, nodeId);
|
||||
if (nodeEntry == NULL) {
|
||||
NODE_ENTRY *nodeEntry = GetNode(list, nodeId);
|
||||
if (nodeEntry == NULL)
|
||||
{
|
||||
return FAILURE;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
memcpy(&(nodeEntry->nodeInfo.pos), newPos, sizeof(COORD));
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* @brief Get node positions information.
|
||||
@@ -264,13 +287,16 @@ int32_t UpdateNodePos(NODE_LIST *list, uint8_t nodeId, const COORD *newPos) {
|
||||
* FAILURE node not exist.
|
||||
*
|
||||
******************************************************************************/
|
||||
int32_t GetNodePos(NODE_LIST *list, uint8_t nodeId, COORD *pos) {
|
||||
int32_t GetNodePos(NODE_LIST *list, uint8_t nodeId, COORD *pos)
|
||||
{
|
||||
ASSERT(list != NULL);
|
||||
NODE_ENTRY* nodeEntry = GetNode(list, nodeId);
|
||||
if (nodeEntry == NULL) {
|
||||
NODE_ENTRY *nodeEntry = GetNode(list, nodeId);
|
||||
if (nodeEntry == NULL)
|
||||
{
|
||||
return FAILURE;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
memcpy(pos, &(nodeEntry->nodeInfo.pos), sizeof(COORD));
|
||||
}
|
||||
return SUCCESS;
|
||||
@@ -288,19 +314,21 @@ int32_t GetNodePos(NODE_LIST *list, uint8_t nodeId, COORD *pos) {
|
||||
* FAILURE node not exist.
|
||||
*
|
||||
******************************************************************************/
|
||||
int32_t UpdateNodeSpeed(NODE_LIST *list, uint8_t nodeId, const COORD *newSpeed) {
|
||||
int32_t UpdateNodeSpeed(NODE_LIST *list, uint8_t nodeId, const COORD *newSpeed)
|
||||
{
|
||||
ASSERT(list != NULL);
|
||||
NODE_ENTRY* nodeEntry = GetNode(list, nodeId);
|
||||
if (nodeEntry == NULL) {
|
||||
NODE_ENTRY *nodeEntry = GetNode(list, nodeId);
|
||||
if (nodeEntry == NULL)
|
||||
{
|
||||
return FAILURE;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
memcpy(&(nodeEntry->nodeInfo.speed), newSpeed, sizeof(COORD));
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* @brief Get node speed information.
|
||||
@@ -313,13 +341,16 @@ int32_t UpdateNodeSpeed(NODE_LIST *list, uint8_t nodeId, const COORD *newSpeed)
|
||||
* FAILURE node not exist.
|
||||
*
|
||||
******************************************************************************/
|
||||
int32_t GetNodeSpeed(NODE_LIST *list, uint8_t nodeId, COORD *speed) {
|
||||
int32_t GetNodeSpeed(NODE_LIST *list, uint8_t nodeId, COORD *speed)
|
||||
{
|
||||
ASSERT(list != NULL);
|
||||
NODE_ENTRY* nodeEntry = GetNode(list, nodeId);
|
||||
if (nodeEntry == NULL) {
|
||||
NODE_ENTRY *nodeEntry = GetNode(list, nodeId);
|
||||
if (nodeEntry == NULL)
|
||||
{
|
||||
return FAILURE;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
memcpy(speed, &(nodeEntry->nodeInfo.speed), sizeof(COORD));
|
||||
}
|
||||
return SUCCESS;
|
||||
@@ -336,13 +367,16 @@ int32_t GetNodeSpeed(NODE_LIST *list, uint8_t nodeId, COORD *speed) {
|
||||
* FAILURE Node not exist.
|
||||
*
|
||||
******************************************************************************/
|
||||
int32_t UpdateNodeTimeDeviation(NODE_LIST *list, uint8_t nodeId, int32_t devi) {
|
||||
int32_t UpdateNodeTimeDeviation(NODE_LIST *list, uint8_t nodeId, int32_t devi)
|
||||
{
|
||||
ASSERT(list != NULL);
|
||||
NODE_ENTRY* nodeEntry = GetNode(list, nodeId);
|
||||
if (nodeEntry == NULL) {
|
||||
NODE_ENTRY *nodeEntry = GetNode(list, nodeId);
|
||||
if (nodeEntry == NULL)
|
||||
{
|
||||
return FAILURE;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
nodeEntry->timeDevi = devi;
|
||||
}
|
||||
return SUCCESS;
|
||||
@@ -359,13 +393,16 @@ int32_t UpdateNodeTimeDeviation(NODE_LIST *list, uint8_t nodeId, int32_t devi) {
|
||||
* @return NONE
|
||||
*
|
||||
******************************************************************************/
|
||||
int32_t IncNodeTTL(NODE_LIST *list, uint8_t nodeId, uint32_t inc) {
|
||||
int32_t IncNodeTTL(NODE_LIST *list, uint8_t nodeId, uint32_t inc)
|
||||
{
|
||||
ASSERT(list != NULL);
|
||||
NODE_ENTRY* nodeEntry = GetNode(list, nodeId);
|
||||
if (nodeEntry == NULL) {
|
||||
NODE_ENTRY *nodeEntry = GetNode(list, nodeId);
|
||||
if (nodeEntry == NULL)
|
||||
{
|
||||
return FAILURE;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
nodeEntry->ttlCnt += inc;
|
||||
}
|
||||
return SUCCESS;
|
||||
@@ -382,13 +419,16 @@ int32_t IncNodeTTL(NODE_LIST *list, uint8_t nodeId, uint32_t inc) {
|
||||
* FAILURE Node not exist.
|
||||
*
|
||||
******************************************************************************/
|
||||
int32_t RstNodeTTL(NODE_LIST *list, uint8_t nodeId) {
|
||||
int32_t RstNodeTTL(NODE_LIST *list, uint8_t nodeId)
|
||||
{
|
||||
ASSERT(list != NULL);
|
||||
NODE_ENTRY* nodeEntry = GetNode(list, nodeId);
|
||||
if (nodeEntry == NULL) {
|
||||
NODE_ENTRY *nodeEntry = GetNode(list, nodeId);
|
||||
if (nodeEntry == NULL)
|
||||
{
|
||||
return FAILURE;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
nodeEntry->ttlCnt = 0;
|
||||
}
|
||||
return SUCCESS;
|
||||
@@ -405,13 +445,16 @@ int32_t RstNodeTTL(NODE_LIST *list, uint8_t nodeId) {
|
||||
* @return NONE
|
||||
*
|
||||
******************************************************************************/
|
||||
int32_t GetNodeTTL(NODE_LIST *list, uint8_t nodeId, uint32_t *ttl) {
|
||||
int32_t GetNodeTTL(NODE_LIST *list, uint8_t nodeId, uint32_t *ttl)
|
||||
{
|
||||
ASSERT(list != NULL);
|
||||
NODE_ENTRY* nodeEntry = GetNode(list, nodeId);
|
||||
if (nodeEntry == NULL) {
|
||||
NODE_ENTRY *nodeEntry = GetNode(list, nodeId);
|
||||
if (nodeEntry == NULL)
|
||||
{
|
||||
return FAILURE;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
*ttl = nodeEntry->ttlCnt;
|
||||
}
|
||||
return SUCCESS;
|
||||
@@ -430,13 +473,16 @@ int32_t GetNodeTTL(NODE_LIST *list, uint8_t nodeId, uint32_t *ttl) {
|
||||
* Other Error occurred.
|
||||
*
|
||||
******************************************************************************/
|
||||
int32_t IterEditNode(NODE_LIST *list, const void *param, int32_t (*operation)(NODE_ENTRY *, const void *)) {
|
||||
int32_t IterEditNode(NODE_LIST *list, const void *param, int32_t (*operation)(NODE_ENTRY *, const void *))
|
||||
{
|
||||
ASSERT(list != NULL);
|
||||
int32_t Status = SUCCESS;
|
||||
NODE_ENTRY *nodeEntry = list->head->nextNode;
|
||||
while (nodeEntry != list->head) {
|
||||
while (nodeEntry != list->head)
|
||||
{
|
||||
Status = operation(nodeEntry, param);
|
||||
if(Status != SUCCESS){
|
||||
if (Status != SUCCESS)
|
||||
{
|
||||
break;
|
||||
}
|
||||
nodeEntry = nodeEntry->nextNode;
|
||||
@@ -455,12 +501,15 @@ int32_t IterEditNode(NODE_LIST *list, const void *param, int32_t (*operation)(NO
|
||||
* @return SUCCESS
|
||||
*
|
||||
******************************************************************************/
|
||||
int32_t IterDeleteNode(NODE_LIST *list, bool (*condition)(NODE_ENTRY *)) {
|
||||
int32_t IterDeleteNode(NODE_LIST *list, bool (*condition)(NODE_ENTRY *))
|
||||
{
|
||||
ASSERT(list != NULL);
|
||||
NODE_ENTRY *nodeEntry, *deletEntry;
|
||||
nodeEntry = list->head->nextNode;
|
||||
while (nodeEntry != list->head) {
|
||||
if (condition(nodeEntry) == false) {
|
||||
while (nodeEntry != list->head)
|
||||
{
|
||||
if (condition(nodeEntry) == false)
|
||||
{
|
||||
deletEntry = nodeEntry;
|
||||
nodeEntry = nodeEntry->nextNode;
|
||||
deletEntry->preNode->nextNode = deletEntry->nextNode;
|
||||
@@ -469,7 +518,8 @@ int32_t IterDeleteNode(NODE_LIST *list, bool (*condition)(NODE_ENTRY *)) {
|
||||
free(deletEntry);
|
||||
list->nodeNum--;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
nodeEntry = nodeEntry->nextNode;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,8 @@
|
||||
/************************** Constant Definitions *****************************/
|
||||
/***************** Macros (Inline Functions) Definitions *********************/
|
||||
/**************************** Type Definitions *******************************/
|
||||
typedef struct NODE_LIST_ENTRY {
|
||||
typedef struct NODE_LIST_ENTRY
|
||||
{
|
||||
L2_NODE_INFO nodeInfo;
|
||||
uint32_t ttlCnt;
|
||||
int32_t timeDevi;
|
||||
@@ -34,7 +35,8 @@ typedef struct NODE_LIST_ENTRY {
|
||||
struct NODE_LIST_ENTRY *preNode;
|
||||
} NODE_ENTRY;
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
uint32_t nodeNum;
|
||||
NODE_ENTRY *head;
|
||||
} NODE_LIST;
|
||||
@@ -53,12 +55,12 @@ int32_t GetNodePos(NODE_LIST *list, uint8_t nodeId, COORD *newPos);
|
||||
int32_t UpdateNodeSpeed(NODE_LIST *list, uint8_t nodeId, const COORD *newSpeed);
|
||||
int32_t GetNodeSpeed(NODE_LIST *list, uint8_t nodeId, COORD *speed);
|
||||
int32_t UpdateNodeTimeDeviation(NODE_LIST *list, uint8_t nodeId, int32_t devi);
|
||||
int32_t GetDistance(NODE_LIST *list, COORD myCoord, uint8_t nodeId, double* dst);
|
||||
int32_t GetDistance(NODE_LIST *list, COORD myCoord, uint8_t nodeId, double *dst);
|
||||
int32_t GetNodeNum(NODE_LIST *list);
|
||||
int32_t RstNodeTTL(NODE_LIST *list, uint8_t nodeId);
|
||||
int32_t IncNodeTTL(NODE_LIST *list, uint8_t nodeId, uint32_t inc);
|
||||
int32_t GetNodeTTL(NODE_LIST *list, uint8_t nodeId, uint32_t *ttl);
|
||||
bool IsNodeInList(NODE_LIST *list, uint8_t nodeId);
|
||||
int32_t IterEditNode(NODE_LIST *list, const void *param, int32_t (*operation)(NODE_ENTRY*, const void*));
|
||||
int32_t IterEditNode(NODE_LIST *list, const void *param, int32_t (*operation)(NODE_ENTRY *, const void *));
|
||||
int32_t IterDeleteNode(NODE_LIST *list, bool (*condition)(NODE_ENTRY *));
|
||||
#endif /* __L2_LOCAL_RECORD_H_ */
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -45,45 +45,52 @@ static int32_t ScanMsg_Packing(L2_INST *instPtr, L2_FRAME_TYPE type);
|
||||
* SUCCESS
|
||||
*
|
||||
******************************************************************************/
|
||||
static int32_t ScanMsg_Packing(L2_INST *instPtr, L2_FRAME_TYPE type) {
|
||||
static int32_t ScanMsg_Packing(L2_INST *instPtr, L2_FRAME_TYPE type)
|
||||
{
|
||||
ASSERT(instPtr != NULL);
|
||||
int32_t Status;
|
||||
uint8_t *buff;
|
||||
uint32_t packLen;
|
||||
switch (type) {
|
||||
case L2_INFO_FRAME:{
|
||||
packLen = RSP_PACK_LEN;
|
||||
SysMonitor_GetSysinfo(&(instPtr->sysInfo));
|
||||
buff = malloc(packLen);
|
||||
if (buff == NULL) {
|
||||
DBG_ERROR("Not enough space, failed to pack frame...\n");
|
||||
return ENOMEM;
|
||||
}
|
||||
buff[L2_MSG_FRAME_NO] = L2_GetNextFrameNo(instPtr);
|
||||
buff[L2_MSG_SLOT_NO] = L2_GetNextSlotNo(instPtr);
|
||||
memcpy(buff+L2_MSG_INFO_POSX, &(instPtr->sysInfo.posX), sizeof(float));
|
||||
memcpy(buff+L2_MSG_INFO_POSY, &(instPtr->sysInfo.posY), sizeof(float));
|
||||
memcpy(buff+L2_MSG_INFO_POSZ, &(instPtr->sysInfo.posZ), sizeof(float));
|
||||
memcpy(buff+L2_MSG_INFO_SPEEDX, &(instPtr->sysInfo.vX), sizeof(float));
|
||||
memcpy(buff+L2_MSG_INFO_SPEEDY, &(instPtr->sysInfo.vY), sizeof(float));
|
||||
memcpy(buff+L2_MSG_INFO_SPEEDZ, &(instPtr->sysInfo.vZ), sizeof(float));
|
||||
switch (type)
|
||||
{
|
||||
case L2_INFO_FRAME:
|
||||
{
|
||||
packLen = RSP_PACK_LEN;
|
||||
SysMonitor_GetSysinfo(&(instPtr->sysInfo));
|
||||
buff = malloc(packLen);
|
||||
if (buff == NULL)
|
||||
{
|
||||
DBG_ERROR("Not enough space, failed to pack frame...\n");
|
||||
return ENOMEM;
|
||||
}
|
||||
buff[L2_MSG_FRAME_NO] = L2_GetNextFrameNo(instPtr);
|
||||
buff[L2_MSG_SLOT_NO] = L2_GetNextSlotNo(instPtr);
|
||||
memcpy(buff + L2_MSG_INFO_POSX, &(instPtr->sysInfo.posX), sizeof(float));
|
||||
memcpy(buff + L2_MSG_INFO_POSY, &(instPtr->sysInfo.posY), sizeof(float));
|
||||
memcpy(buff + L2_MSG_INFO_POSZ, &(instPtr->sysInfo.posZ), sizeof(float));
|
||||
memcpy(buff + L2_MSG_INFO_SPEEDX, &(instPtr->sysInfo.vX), sizeof(float));
|
||||
memcpy(buff + L2_MSG_INFO_SPEEDY, &(instPtr->sysInfo.vY), sizeof(float));
|
||||
memcpy(buff + L2_MSG_INFO_SPEEDZ, &(instPtr->sysInfo.vZ), sizeof(float));
|
||||
|
||||
Status = L2_CrcAppend(buff, packLen - 2, L2_MSG_CRC, L2_CRC16_1021);
|
||||
if (Status != SUCCESS) {
|
||||
DBG_ERROR("Fail to append CRC, error code: %ld.\n", Status);
|
||||
return Status;
|
||||
}
|
||||
if(CircQueuePush(instPtr->txQueue, buff) == false){
|
||||
DBG_ERROR("Cannot push packet to queue..\n");
|
||||
return EQUEUE;
|
||||
}
|
||||
break;
|
||||
Status = L2_CrcAppend(buff, packLen - 2, L2_MSG_CRC, L2_CRC16_1021);
|
||||
if (Status != SUCCESS)
|
||||
{
|
||||
DBG_ERROR("Fail to append CRC, error code: %ld.\n", Status);
|
||||
return Status;
|
||||
}
|
||||
default :{
|
||||
DBG_ERROR("Unexpected frame type: %d.\n", type);
|
||||
return EPARAM;
|
||||
break;
|
||||
if (CircQueuePush(instPtr->txQueue, buff) == false)
|
||||
{
|
||||
DBG_ERROR("Cannot push packet to queue..\n");
|
||||
return EQUEUE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
DBG_ERROR("Unexpected frame type: %d.\n", type);
|
||||
return EPARAM;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
@@ -97,7 +104,8 @@ static int32_t ScanMsg_Packing(L2_INST *instPtr, L2_FRAME_TYPE type) {
|
||||
* @return
|
||||
*
|
||||
******************************************************************************/
|
||||
int32_t L2_Scan_Init(L2_INST *instPtr) {
|
||||
int32_t L2_Scan_Init(L2_INST *instPtr)
|
||||
{
|
||||
ASSERT(instPtr != NULL);
|
||||
instPtr->scanFsm.sacanCnt = 0;
|
||||
instPtr->scanFsm.beamNo = 0;
|
||||
@@ -113,25 +121,32 @@ int32_t L2_Scan_Init(L2_INST *instPtr) {
|
||||
* @return
|
||||
*
|
||||
******************************************************************************/
|
||||
int32_t L2_Scan_PktHandler(L2_INST *instPtr, uint8_t *msg) {
|
||||
int32_t L2_Scan_PktHandler(L2_INST *instPtr, uint8_t *msg)
|
||||
{
|
||||
ASSERT(instPtr != NULL);
|
||||
ASSERT(msg != NULL);
|
||||
int32_t Status;
|
||||
switch (instPtr->frame.last) {
|
||||
case L2_SCAN_FRAME: {
|
||||
if (instPtr->config.myType == L2_HEAD_NODE) {
|
||||
switch (instPtr->frame.last)
|
||||
{
|
||||
case L2_SCAN_FRAME:
|
||||
{
|
||||
if (instPtr->config.myType == L2_HEAD_NODE)
|
||||
{
|
||||
DBG_ERROR("Unexpected call from head node, Only None-Head Node can handle L2_SVC_FRAME.\n");
|
||||
Status = EUNEXP;
|
||||
break;
|
||||
}
|
||||
Status = AppendNode(instPtr->nodeInfoList, L2_HEAD_NODE_ID, L2_HEAD_NODE);
|
||||
if (Status != SUCCESS) {
|
||||
if (Status != SUCCESS)
|
||||
{
|
||||
DBG_ERROR("Failed to append node %d, errorCode: %ld.\n", L2_MEMBER_NODE_ID, Status);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case L2_INFO_FRAME: {
|
||||
if (instPtr->config.myType != L2_HEAD_NODE) {
|
||||
case L2_INFO_FRAME:
|
||||
{
|
||||
if (instPtr->config.myType != L2_HEAD_NODE)
|
||||
{
|
||||
DBG_ERROR("Unexpected call from member node, Only Head Node can handle L2_SVC_FRAME.\n");
|
||||
Status = EUNEXP;
|
||||
break;
|
||||
@@ -139,47 +154,55 @@ int32_t L2_Scan_PktHandler(L2_INST *instPtr, uint8_t *msg) {
|
||||
COORD coordTemp;
|
||||
float tmpVal;
|
||||
Status = AppendNode(instPtr->nodeInfoList, L2_MEMBER_NODE_ID, L2_MEMBER_NODE);
|
||||
if (Status != SUCCESS) {
|
||||
if (Status != SUCCESS)
|
||||
{
|
||||
DBG_ERROR("Failed to append node %d, errorCode: %ld.\n", L2_MEMBER_NODE_ID, Status);
|
||||
break;
|
||||
}
|
||||
memcpy(&tmpVal, msg+L2_MSG_INFO_POSX, sizeof(float));
|
||||
memcpy(&tmpVal, msg + L2_MSG_INFO_POSX, sizeof(float));
|
||||
coordTemp.x = tmpVal;
|
||||
memcpy(&tmpVal, msg+L2_MSG_INFO_POSY, sizeof(float));
|
||||
memcpy(&tmpVal, msg + L2_MSG_INFO_POSY, sizeof(float));
|
||||
coordTemp.y = tmpVal;
|
||||
memcpy(&tmpVal, msg+L2_MSG_INFO_POSZ, sizeof(float));
|
||||
memcpy(&tmpVal, msg + L2_MSG_INFO_POSZ, sizeof(float));
|
||||
coordTemp.z = tmpVal;
|
||||
Status = UpdateNodePos(instPtr->nodeInfoList, L2_MEMBER_NODE_ID, &coordTemp);
|
||||
if (Status != SUCCESS) {
|
||||
if (Status != SUCCESS)
|
||||
{
|
||||
DBG_ERROR("Failed to update node %d position, errorCode: %ld.\n", L2_MEMBER_NODE_ID, Status);
|
||||
}
|
||||
memcpy(&tmpVal, msg+L2_MSG_INFO_SPEEDX, sizeof(float));
|
||||
memcpy(&tmpVal, msg + L2_MSG_INFO_SPEEDX, sizeof(float));
|
||||
coordTemp.x = tmpVal;
|
||||
memcpy(&tmpVal, msg+L2_MSG_INFO_SPEEDY, sizeof(float));
|
||||
memcpy(&tmpVal, msg + L2_MSG_INFO_SPEEDY, sizeof(float));
|
||||
coordTemp.y = tmpVal;
|
||||
memcpy(&tmpVal, msg+L2_MSG_INFO_SPEEDZ, sizeof(float));
|
||||
memcpy(&tmpVal, msg + L2_MSG_INFO_SPEEDZ, sizeof(float));
|
||||
coordTemp.z = tmpVal;
|
||||
Status = UpdateNodeSpeed(instPtr->nodeInfoList, L2_MEMBER_NODE_ID, &coordTemp);
|
||||
if (Status != SUCCESS) {
|
||||
if (Status != SUCCESS)
|
||||
{
|
||||
DBG_ERROR("Failed to update node %d speed, errorCode: %ld.\n", L2_MEMBER_NODE_ID, Status);
|
||||
}
|
||||
// Update Time deviation
|
||||
int64_t devi, deviTrunc;
|
||||
Status = L2_TimeSync_GetDeviatoion(instPtr, &devi);
|
||||
if (Status != SUCCESS) {
|
||||
if (Status != SUCCESS)
|
||||
{
|
||||
DBG_ERROR("Failed to compute slot deviation.\n");
|
||||
UpdateNodeTimeDeviation(instPtr->nodeInfoList, L2_MEMBER_NODE_ID, 0);
|
||||
}
|
||||
else {
|
||||
if(devi > INT32_MAX || devi < INT32_MIN) {
|
||||
else
|
||||
{
|
||||
if (devi > INT32_MAX || devi < INT32_MIN)
|
||||
{
|
||||
DBG_ERROR("Illegal deviation value: %lld.\n", devi);
|
||||
deviTrunc = 0;
|
||||
}
|
||||
else if(devi > L2_MSG_SVC_TMSYNC_MAX || devi < L2_MSG_SVC_TMSYNC_MIN) {
|
||||
else if (devi > L2_MSG_SVC_TMSYNC_MAX || devi < L2_MSG_SVC_TMSYNC_MIN)
|
||||
{
|
||||
DBG_WARNING("Deviation value: %lld is out of adjustable range.\n", devi);
|
||||
deviTrunc = (int32_t)devi;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
deviTrunc = (int32_t)devi;
|
||||
}
|
||||
UpdateNodeTimeDeviation(instPtr->nodeInfoList, L2_MEMBER_NODE_ID, (uint32_t)deviTrunc);
|
||||
@@ -193,7 +216,8 @@ int32_t L2_Scan_PktHandler(L2_INST *instPtr, uint8_t *msg) {
|
||||
}
|
||||
|
||||
// Net setup finished.
|
||||
if(L2_GetMainState(instPtr) == INIT_STATE && Status == SUCCESS){
|
||||
if (L2_GetMainState(instPtr) == INIT_STATE && Status == SUCCESS)
|
||||
{
|
||||
L2_EVENT l2Event;
|
||||
L2_RTNE_CONFIG newRtneConfig;
|
||||
|
||||
@@ -204,7 +228,7 @@ int32_t L2_Scan_PktHandler(L2_INST *instPtr, uint8_t *msg) {
|
||||
|
||||
// Assert Routine Table Update...
|
||||
newRtneConfig.rtneTable = normalTable;
|
||||
newRtneConfig.rtnePrd = ARRAY_SIZE(normalTable)*L2_SLOTS_PER_FRAME;
|
||||
newRtneConfig.rtnePrd = ARRAY_SIZE(normalTable) * L2_SLOTS_PER_FRAME;
|
||||
newRtneConfig.rtneStep = 0;
|
||||
l2Event.event = L2_ROUTINE_UPDATE;
|
||||
l2Event.msg = &newRtneConfig;
|
||||
@@ -222,43 +246,50 @@ int32_t L2_Scan_PktHandler(L2_INST *instPtr, uint8_t *msg) {
|
||||
* @return used slot (5ms slot).
|
||||
*
|
||||
******************************************************************************/
|
||||
int32_t L2_Scan_Proc(L2_INST *instPtr) {
|
||||
int32_t L2_Scan_Proc(L2_INST *instPtr)
|
||||
{
|
||||
int32_t Status;
|
||||
/* instPtr->nextState == NORMAL_STATE indicates network set up procedure was finished.
|
||||
* Skip 5ms for nodes for node configuration update.
|
||||
*/
|
||||
DBG_INFO("-------- Scan Process --------\n");
|
||||
if (instPtr->nextState == NORMAL_STATE) {
|
||||
if (instPtr->nextState == NORMAL_STATE)
|
||||
{
|
||||
DBG_INFO("NETSET DONE, halt 20ms before normal routine.\n");
|
||||
if(instPtr->config.myType != L2_HEAD_NODE) {
|
||||
if (instPtr->config.myType != L2_HEAD_NODE)
|
||||
{
|
||||
Phy_SetBeamAngle(instPtr->config.phyInstRef, 0.0, 0.0);
|
||||
Phy_SetBeamWidth(instPtr->config.phyInstRef, PHY_ANT_BEAM_120);
|
||||
Phy_SetMode(instPtr->config.phyInstRef, PHY_MODE_SCHEDULE);
|
||||
L2_SetupNextSlot(instPtr, L2_TOR_SUSPEND, L2_SCAN_FRAME);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
DBG_ERROR("Illegal call from Head Node.\n");
|
||||
}
|
||||
return NUM_SLOTS_SKIP;
|
||||
}
|
||||
|
||||
/* Head node implement a periodical scan pattern
|
||||
/* Head node implement a periodical scan pattern
|
||||
* | Tx 20ms | Rx 100ms | Tx 20ms | Rx 100ms ... ...
|
||||
* Send pilot signal in Tx slots with narrow beam width.
|
||||
* Wait for response in Rx slots with the same beam width and beam number.
|
||||
* Increase beam number after a Tx-Rx procedure pair, reset beam number when
|
||||
* Increase beam number after a Tx-Rx procedure pair, reset beam number when
|
||||
* it reaches the boundary.
|
||||
*/
|
||||
if (instPtr->config.myType == L2_HEAD_NODE) {
|
||||
if (instPtr->config.myType == L2_HEAD_NODE)
|
||||
{
|
||||
// Apply a scan procedure
|
||||
if (instPtr->scanFsm.sacanCnt % 2 == 0){
|
||||
if (instPtr->scanFsm.sacanCnt % 2 == 0)
|
||||
{
|
||||
// Antenna configure
|
||||
Phy_SetBeamWidth(instPtr->config.phyInstRef, PHY_ANT_BEAM_8);
|
||||
Phy_SetBeamNo(instPtr->config.phyInstRef, instPtr->scanFsm.beamNo);
|
||||
Phy_SetMode(instPtr->config.phyInstRef, PHY_MODE_SCHEDULE);
|
||||
L2_SetupNextSlot(instPtr, L2_TOR_TX, L2_SCAN_FRAME);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
// Antenna configure
|
||||
Phy_SetBeamWidth(instPtr->config.phyInstRef, PHY_ANT_BEAM_8);
|
||||
Phy_SetBeamNo(instPtr->config.phyInstRef, instPtr->scanFsm.beamNo);
|
||||
@@ -270,23 +301,27 @@ int32_t L2_Scan_Proc(L2_INST *instPtr) {
|
||||
}
|
||||
/* Member node listening the head node pilot signal with wide beam width.
|
||||
* Once is received a pilot signal, physical layer will perform a response
|
||||
* procedure automatically, witch should contains the basic node information
|
||||
* procedure automatically, witch should contains the basic node information
|
||||
* (position, speed, etc.).
|
||||
* So that, a extra datagram with the up-to-date node information is attached
|
||||
* to the listening configuration.
|
||||
*/
|
||||
else {
|
||||
else
|
||||
{
|
||||
uint8_t *sendData;
|
||||
// Pack node information.
|
||||
Status = ScanMsg_Packing(instPtr, L2_INFO_FRAME);
|
||||
if (Status != SUCCESS) {
|
||||
if (Status != SUCCESS)
|
||||
{
|
||||
DBG_INFO("Failed to pack response.\n");
|
||||
}
|
||||
if (CircQueuePop(instPtr->txQueue, (void **)(&sendData)) == true) {
|
||||
if (CircQueuePop(instPtr->txQueue, (void **)(&sendData)) == true)
|
||||
{
|
||||
memcpy(instPtr->sendPktData, sendData, RSP_PACK_LEN);
|
||||
free(sendData);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
DBG_INFO("Failed to pop tx Queue.\n");
|
||||
}
|
||||
// Antenna configure
|
||||
@@ -297,7 +332,7 @@ int32_t L2_Scan_Proc(L2_INST *instPtr) {
|
||||
}
|
||||
|
||||
// Increase scan counter (for debug purpose).
|
||||
instPtr->scanFsm.sacanCnt ++;
|
||||
instPtr->scanFsm.sacanCnt++;
|
||||
return NUM_SLOTS_SKIP;
|
||||
}
|
||||
|
||||
@@ -311,7 +346,8 @@ int32_t L2_Scan_Proc(L2_INST *instPtr) {
|
||||
* @return used slot (5ms slot).
|
||||
*
|
||||
******************************************************************************/
|
||||
int32_t L2_Scan_Routine(L2_INST *instPtr, L2_RTNE_TABLE_ENTRY *schedEntry) {
|
||||
int32_t L2_Scan_Routine(L2_INST *instPtr, L2_RTNE_TABLE_ENTRY *schedEntry)
|
||||
{
|
||||
DBG_INFO("-------- Scan Routine --------\n");
|
||||
ASSERT(false); // Not support.
|
||||
return 0;
|
||||
|
||||
@@ -25,10 +25,10 @@
|
||||
#include "../config/app_config.h"
|
||||
|
||||
/************************** Constant Definitions *****************************/
|
||||
#define NUM_SERVICE_SLOTS 20
|
||||
#define NUM_RESPONSE_SLOTS 20
|
||||
#define NUM_NONE_SERVICE_SLOTS 0
|
||||
#define NUM_SERVICE_PRD_SLOTS 60
|
||||
#define NUM_SERVICE_SLOTS 20
|
||||
#define NUM_RESPONSE_SLOTS 20
|
||||
#define NUM_NONE_SERVICE_SLOTS 0
|
||||
#define NUM_SERVICE_PRD_SLOTS 60
|
||||
/***************** Macros (Inline Functions) Definitions *********************/
|
||||
|
||||
/**************************** Type Definitions *******************************/
|
||||
@@ -42,8 +42,7 @@ static uint8_t berTestData[SVC_PACK_LEN] = {
|
||||
0x27, 0x4E, 0xFB, 0x39, 0x11, 0xE7, 0x12, 0xDA,
|
||||
0xDF, 0xD2, 0x27, 0x8F, 0xC9, 0x42, 0xCD, 0x0C,
|
||||
0x76, 0x1C, 0x81, 0x87, 0x69, 0xC9, 0x60, 0xFD,
|
||||
0xC4, 0x27, 0xA5, 0x09, 0xE5, 0x71
|
||||
};
|
||||
0xC4, 0x27, 0xA5, 0x09, 0xE5, 0x71};
|
||||
#endif
|
||||
|
||||
/*****************************************************************************/
|
||||
@@ -58,116 +57,134 @@ static uint8_t berTestData[SVC_PACK_LEN] = {
|
||||
* SUCCESS
|
||||
*
|
||||
******************************************************************************/
|
||||
static int32_t Service_Packing(L2_INST *instPtr, L2_FRAME_TYPE type) {
|
||||
static int32_t Service_Packing(L2_INST *instPtr, L2_FRAME_TYPE type)
|
||||
{
|
||||
#ifndef DATALINK_ENABLE_BERTEST
|
||||
ASSERT(instPtr != NULL);
|
||||
int32_t Status;
|
||||
uint8_t *buff;
|
||||
uint32_t packLen;
|
||||
switch (type) {
|
||||
case L2_SVC_FRAME:{
|
||||
const NODE_ENTRY *nodeEntry;
|
||||
int32_t timeDevi;
|
||||
packLen = SVC_PACK_LEN;
|
||||
switch (type)
|
||||
{
|
||||
case L2_SVC_FRAME:
|
||||
{
|
||||
const NODE_ENTRY *nodeEntry;
|
||||
int32_t timeDevi;
|
||||
packLen = SVC_PACK_LEN;
|
||||
|
||||
buff = malloc(packLen);
|
||||
if (buff == NULL) {
|
||||
DBG_ERROR("Not enough space, failed to pack frame...\n");
|
||||
return ENOMEM;
|
||||
}
|
||||
buff[L2_MSG_FRAME_NO] = L2_GetNextFrameNo(instPtr);
|
||||
buff[L2_MSG_SLOT_NO] = L2_GetNextSlotNo(instPtr);
|
||||
|
||||
// TODO: Check Pack TimeSync info, and better approch?.
|
||||
nodeEntry = GetNode(instPtr->nodeInfoList, L2_MEMBER_NODE_ID);
|
||||
if(nodeEntry != NULL) {
|
||||
// check if deviation info outdated.
|
||||
if(nodeEntry->ttlCnt <= NUM_SERVICE_PRD_SLOTS) {
|
||||
// Member node should adjust in the opposite way.
|
||||
timeDevi = -nodeEntry->timeDevi;
|
||||
}
|
||||
else {
|
||||
DBG_WARNING("Time deviation is outdated, omitted it.\n");
|
||||
}
|
||||
}
|
||||
else {
|
||||
DBG_ERROR("Fail to get time deviation...\n");
|
||||
timeDevi = 0;
|
||||
}
|
||||
if(timeDevi > L2_MSG_SVC_TMSYNC_MAX || timeDevi < L2_MSG_SVC_TMSYNC_MIN) {
|
||||
do {
|
||||
timeDevi /= 2;
|
||||
} while(timeDevi > L2_MSG_SVC_TMSYNC_MAX || timeDevi < L2_MSG_SVC_TMSYNC_MIN);
|
||||
DBG_WARNING("Deviation is out of adjustable range, truncate it to %d.\n", timeDevi);
|
||||
}
|
||||
memcpy(buff+L2_MSG_SVC_TMSYNC, &timeDevi, L2_MSG_SVC_TMSYNC_LEN);
|
||||
|
||||
// Pack Seq ID
|
||||
buff[L2_MSG_SVC_SEQ_ID] = instPtr->serviceFsm.txSeqNum;
|
||||
|
||||
// Pack payload
|
||||
memcpy(buff+L2_MSG_SVC_PAYLOAD,
|
||||
instPtr->serviceFsm.txLog + L2_MSG_SVC_PAYLOAD_LEN*instPtr->serviceFsm.txSeqNum,
|
||||
L2_MSG_SVC_PAYLOAD_LEN);
|
||||
if (instPtr->config.myType == L2_HEAD_NODE) {
|
||||
// if last packet reset counting
|
||||
instPtr->serviceFsm.txSeqNum = (instPtr->serviceFsm.txSeqNum
|
||||
>= (PAYLOAD_FLJ-1)/L2_MSG_SVC_PAYLOAD+1)
|
||||
? 0 : instPtr->serviceFsm.txSeqNum + 1;
|
||||
}
|
||||
else{
|
||||
// if last packet reset counting
|
||||
instPtr->serviceFsm.txSeqNum = (instPtr->serviceFsm.txSeqNum
|
||||
>= (PAYLOAD_LJ-1)/L2_MSG_SVC_PAYLOAD+1)
|
||||
? 0 : instPtr->serviceFsm.txSeqNum + 1;
|
||||
}
|
||||
|
||||
|
||||
Status = L2_CrcAppend(buff, packLen - 2, L2_MSG_CRC, L2_CRC16_1021);
|
||||
if (Status != SUCCESS) {
|
||||
DBG_ERROR("Fail to append CRC...\n");
|
||||
return Status;
|
||||
}
|
||||
|
||||
if(CircQueuePush(instPtr->txQueue, buff) == false){
|
||||
DBG_ERROR("Cannot push packet to queue..\n");
|
||||
return EQUEUE;
|
||||
}
|
||||
break;
|
||||
buff = malloc(packLen);
|
||||
if (buff == NULL)
|
||||
{
|
||||
DBG_ERROR("Not enough space, failed to pack frame...\n");
|
||||
return ENOMEM;
|
||||
}
|
||||
case L2_INFO_FRAME:{
|
||||
packLen = RSP_PACK_LEN;
|
||||
SysMonitor_GetSysinfo(&(instPtr->sysInfo));
|
||||
buff = malloc(packLen);
|
||||
if (buff == NULL) {
|
||||
DBG_ERROR("Not enough space, failed to pack frame...\n");
|
||||
return ENOMEM;
|
||||
}
|
||||
buff[L2_MSG_FRAME_NO] = L2_GetNextFrameNo(instPtr);
|
||||
buff[L2_MSG_SLOT_NO] = L2_GetNextSlotNo(instPtr);
|
||||
memcpy(buff+L2_MSG_INFO_POSX, &(instPtr->sysInfo.posX), sizeof(float));
|
||||
memcpy(buff+L2_MSG_INFO_POSY, &(instPtr->sysInfo.posY), sizeof(float));
|
||||
memcpy(buff+L2_MSG_INFO_POSZ, &(instPtr->sysInfo.posZ), sizeof(float));
|
||||
memcpy(buff+L2_MSG_INFO_SPEEDX, &(instPtr->sysInfo.vX), sizeof(float));
|
||||
memcpy(buff+L2_MSG_INFO_SPEEDY, &(instPtr->sysInfo.vY), sizeof(float));
|
||||
memcpy(buff+L2_MSG_INFO_SPEEDZ, &(instPtr->sysInfo.vZ), sizeof(float));
|
||||
buff[L2_MSG_FRAME_NO] = L2_GetNextFrameNo(instPtr);
|
||||
buff[L2_MSG_SLOT_NO] = L2_GetNextSlotNo(instPtr);
|
||||
|
||||
Status = L2_CrcAppend(buff, packLen - 2, L2_MSG_CRC, L2_CRC16_1021);
|
||||
if (Status != SUCCESS) {
|
||||
DBG_ERROR("Fail to append CRC...\n");
|
||||
return Status;
|
||||
// TODO: Check Pack TimeSync info, and better approch?.
|
||||
nodeEntry = GetNode(instPtr->nodeInfoList, L2_MEMBER_NODE_ID);
|
||||
if (nodeEntry != NULL)
|
||||
{
|
||||
// check if deviation info outdated.
|
||||
if (nodeEntry->ttlCnt <= NUM_SERVICE_PRD_SLOTS)
|
||||
{
|
||||
// Member node should adjust in the opposite way.
|
||||
timeDevi = -nodeEntry->timeDevi;
|
||||
}
|
||||
if(CircQueuePush(instPtr->txQueue, buff) == false){
|
||||
DBG_ERROR("Cannot push packet to queue..\n");
|
||||
return EQUEUE;
|
||||
else
|
||||
{
|
||||
DBG_WARNING("Time deviation is outdated, omitted it.\n");
|
||||
}
|
||||
break;
|
||||
}
|
||||
default :{
|
||||
DBG_ERROR("Unexpected frame type: %d.\n", type);
|
||||
return EPARAM;
|
||||
break;
|
||||
else
|
||||
{
|
||||
DBG_ERROR("Fail to get time deviation...\n");
|
||||
timeDevi = 0;
|
||||
}
|
||||
if (timeDevi > L2_MSG_SVC_TMSYNC_MAX || timeDevi < L2_MSG_SVC_TMSYNC_MIN)
|
||||
{
|
||||
do
|
||||
{
|
||||
timeDevi /= 2;
|
||||
} while (timeDevi > L2_MSG_SVC_TMSYNC_MAX || timeDevi < L2_MSG_SVC_TMSYNC_MIN);
|
||||
DBG_WARNING("Deviation is out of adjustable range, truncate it to %d.\n", timeDevi);
|
||||
}
|
||||
memcpy(buff + L2_MSG_SVC_TMSYNC, &timeDevi, L2_MSG_SVC_TMSYNC_LEN);
|
||||
|
||||
// Pack Seq ID
|
||||
buff[L2_MSG_SVC_SEQ_ID] = instPtr->serviceFsm.txSeqNum;
|
||||
|
||||
// Pack payload
|
||||
memcpy(buff + L2_MSG_SVC_PAYLOAD,
|
||||
instPtr->serviceFsm.txLog + L2_MSG_SVC_PAYLOAD_LEN * instPtr->serviceFsm.txSeqNum,
|
||||
L2_MSG_SVC_PAYLOAD_LEN);
|
||||
if (instPtr->config.myType == L2_HEAD_NODE)
|
||||
{
|
||||
// if last packet reset counting
|
||||
instPtr->serviceFsm.txSeqNum = (instPtr->serviceFsm.txSeqNum >= (PAYLOAD_FLJ - 1) / L2_MSG_SVC_PAYLOAD + 1)
|
||||
? 0
|
||||
: instPtr->serviceFsm.txSeqNum + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// if last packet reset counting
|
||||
instPtr->serviceFsm.txSeqNum = (instPtr->serviceFsm.txSeqNum >= (PAYLOAD_LJ - 1) / L2_MSG_SVC_PAYLOAD + 1)
|
||||
? 0
|
||||
: instPtr->serviceFsm.txSeqNum + 1;
|
||||
}
|
||||
|
||||
Status = L2_CrcAppend(buff, packLen - 2, L2_MSG_CRC, L2_CRC16_1021);
|
||||
if (Status != SUCCESS)
|
||||
{
|
||||
DBG_ERROR("Fail to append CRC...\n");
|
||||
return Status;
|
||||
}
|
||||
|
||||
if (CircQueuePush(instPtr->txQueue, buff) == false)
|
||||
{
|
||||
DBG_ERROR("Cannot push packet to queue..\n");
|
||||
return EQUEUE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case L2_INFO_FRAME:
|
||||
{
|
||||
packLen = RSP_PACK_LEN;
|
||||
SysMonitor_GetSysinfo(&(instPtr->sysInfo));
|
||||
buff = malloc(packLen);
|
||||
if (buff == NULL)
|
||||
{
|
||||
DBG_ERROR("Not enough space, failed to pack frame...\n");
|
||||
return ENOMEM;
|
||||
}
|
||||
buff[L2_MSG_FRAME_NO] = L2_GetNextFrameNo(instPtr);
|
||||
buff[L2_MSG_SLOT_NO] = L2_GetNextSlotNo(instPtr);
|
||||
memcpy(buff + L2_MSG_INFO_POSX, &(instPtr->sysInfo.posX), sizeof(float));
|
||||
memcpy(buff + L2_MSG_INFO_POSY, &(instPtr->sysInfo.posY), sizeof(float));
|
||||
memcpy(buff + L2_MSG_INFO_POSZ, &(instPtr->sysInfo.posZ), sizeof(float));
|
||||
memcpy(buff + L2_MSG_INFO_SPEEDX, &(instPtr->sysInfo.vX), sizeof(float));
|
||||
memcpy(buff + L2_MSG_INFO_SPEEDY, &(instPtr->sysInfo.vY), sizeof(float));
|
||||
memcpy(buff + L2_MSG_INFO_SPEEDZ, &(instPtr->sysInfo.vZ), sizeof(float));
|
||||
|
||||
Status = L2_CrcAppend(buff, packLen - 2, L2_MSG_CRC, L2_CRC16_1021);
|
||||
if (Status != SUCCESS)
|
||||
{
|
||||
DBG_ERROR("Fail to append CRC...\n");
|
||||
return Status;
|
||||
}
|
||||
if (CircQueuePush(instPtr->txQueue, buff) == false)
|
||||
{
|
||||
DBG_ERROR("Cannot push packet to queue..\n");
|
||||
return EQUEUE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
DBG_ERROR("Unexpected frame type: %d.\n", type);
|
||||
return EPARAM;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return SUCCESS;
|
||||
#else
|
||||
@@ -176,7 +193,6 @@ static int32_t Service_Packing(L2_INST *instPtr, L2_FRAME_TYPE type) {
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* @brief Initialize scan FSM.
|
||||
@@ -186,7 +202,8 @@ static int32_t Service_Packing(L2_INST *instPtr, L2_FRAME_TYPE type) {
|
||||
* @return
|
||||
*
|
||||
******************************************************************************/
|
||||
int32_t L2_Service_Init(L2_INST *instPtr) {
|
||||
int32_t L2_Service_Init(L2_INST *instPtr)
|
||||
{
|
||||
ASSERT(instPtr != NULL);
|
||||
instPtr->serviceFsm.txSeqNum = 0;
|
||||
instPtr->serviceFsm.rxSeqNum = 0;
|
||||
@@ -211,13 +228,17 @@ int32_t L2_Service_Init(L2_INST *instPtr) {
|
||||
* other error occurred.
|
||||
*
|
||||
******************************************************************************/
|
||||
int32_t L2_Service_PktHandler(L2_INST *instPtr, uint8_t *msg) {
|
||||
int32_t L2_Service_PktHandler(L2_INST *instPtr, uint8_t *msg)
|
||||
{
|
||||
ASSERT(instPtr != NULL);
|
||||
ASSERT(msg != NULL);
|
||||
int32_t Status;
|
||||
switch (instPtr->frame.last) {
|
||||
case L2_SVC_FRAME: {
|
||||
if (instPtr->config.myType == L2_HEAD_NODE) {
|
||||
switch (instPtr->frame.last)
|
||||
{
|
||||
case L2_SVC_FRAME:
|
||||
{
|
||||
if (instPtr->config.myType == L2_HEAD_NODE)
|
||||
{
|
||||
DBG_ERROR("Unexpected call, Only None-Head Node can handle L2_SVC_FRAME.\n");
|
||||
Status = EUNEXP;
|
||||
break;
|
||||
@@ -241,57 +262,72 @@ int32_t L2_Service_PktHandler(L2_INST *instPtr, uint8_t *msg) {
|
||||
timeAdj |= (timeAdj & 0x0000000000800000) ? 0xFFFFFFFFFF000000 : 0x0000000000000000;
|
||||
// FIXME: better approach?
|
||||
// Implement a time sync procedure, first time received a time deviation in a service period.
|
||||
if (seqNum % NUM_SERVICE_PRD_SLOTS == 0 || instPtr->serviceFsm.seqNum != seqNum) {
|
||||
if (seqNum % NUM_SERVICE_PRD_SLOTS == 0 || instPtr->serviceFsm.seqNum != seqNum)
|
||||
{
|
||||
AssertL2Event(instPtr, &l2Event);
|
||||
}
|
||||
#endif
|
||||
#ifndef DATALINK_ENABLE_BERTEST
|
||||
memcpy(instPtr->serviceFsm.rxLog + L2_MSG_SVC_PAYLOAD_LEN*seqNum, msg + L2_MSG_SVC_PAYLOAD, L2_MSG_SVC_PAYLOAD_LEN);
|
||||
if (instPtr->config.myType == L2_HEAD_NODE) {
|
||||
memcpy(instPtr->serviceFsm.rxLog + L2_MSG_SVC_PAYLOAD_LEN * seqNum, msg + L2_MSG_SVC_PAYLOAD, L2_MSG_SVC_PAYLOAD_LEN);
|
||||
if (instPtr->config.myType == L2_HEAD_NODE)
|
||||
{
|
||||
// if last packet reset counting
|
||||
if(seqNum >= (PAYLOAD_FLJ-1)/L2_MSG_SVC_PAYLOAD+1) {
|
||||
if(seqNum == instPtr->serviceFsm.rxSeqNum) {
|
||||
if (seqNum >= (PAYLOAD_FLJ - 1) / L2_MSG_SVC_PAYLOAD + 1)
|
||||
{
|
||||
if (seqNum == instPtr->serviceFsm.rxSeqNum)
|
||||
{
|
||||
SysMonitor_UpdateRecvPayloadLJRaw(instPtr->serviceFsm.rxLog);
|
||||
}
|
||||
instPtr->serviceFsm.rxSeqNum = 0;
|
||||
}
|
||||
else {
|
||||
if(instPtr->serviceFsm.rxSeqNum == seqNum){
|
||||
else
|
||||
{
|
||||
if (instPtr->serviceFsm.rxSeqNum == seqNum)
|
||||
{
|
||||
instPtr->serviceFsm.rxSeqNum++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
else
|
||||
{
|
||||
// if last packet reset counting
|
||||
if(seqNum >= (PAYLOAD_LJ-1)/L2_MSG_SVC_PAYLOAD+1) {
|
||||
if(seqNum == instPtr->serviceFsm.rxSeqNum) {
|
||||
if (seqNum >= (PAYLOAD_LJ - 1) / L2_MSG_SVC_PAYLOAD + 1)
|
||||
{
|
||||
if (seqNum == instPtr->serviceFsm.rxSeqNum)
|
||||
{
|
||||
SysMonitor_UpdateRecvPayloadFLJRaw(instPtr->serviceFsm.rxLog);
|
||||
}
|
||||
instPtr->serviceFsm.rxSeqNum = 0;
|
||||
}
|
||||
else {
|
||||
if(instPtr->serviceFsm.rxSeqNum == seqNum){
|
||||
else
|
||||
{
|
||||
if (instPtr->serviceFsm.rxSeqNum == seqNum)
|
||||
{
|
||||
instPtr->serviceFsm.rxSeqNum++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
for(int i = 0; i < SVC_PACK_LEN; i++) {
|
||||
instPtr->serviceFsm.bitError += count_ones(msg[i]^berTestData[i]);
|
||||
for (int i = 0; i < SVC_PACK_LEN; i++)
|
||||
{
|
||||
instPtr->serviceFsm.bitError += count_ones(msg[i] ^ berTestData[i]);
|
||||
}
|
||||
instPtr->serviceFsm.bitTotal += SVC_PACK_LEN*8;
|
||||
instPtr->serviceFsm.bitTotal += SVC_PACK_LEN * 8;
|
||||
#endif
|
||||
instPtr->serviceFsm.pktRecved++;
|
||||
// Reset Node TTL
|
||||
Status = RstNodeTTL(instPtr->nodeInfoList, L2_HEAD_NODE_ID);
|
||||
if (Status != SUCCESS) {
|
||||
if (Status != SUCCESS)
|
||||
{
|
||||
DBG_ERROR("Failed to reset node %d TTL, errorCode: %ld.\n", L2_MEMBER_NODE_ID, Status);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case L2_INFO_FRAME: {
|
||||
if (instPtr->config.myType != L2_HEAD_NODE) {
|
||||
case L2_INFO_FRAME:
|
||||
{
|
||||
if (instPtr->config.myType != L2_HEAD_NODE)
|
||||
{
|
||||
DBG_ERROR("Unexpected call, Only Head Node can handle L2_SVC_FRAME.\n");
|
||||
Status = EUNEXP;
|
||||
break;
|
||||
@@ -299,24 +335,26 @@ int32_t L2_Service_PktHandler(L2_INST *instPtr, uint8_t *msg) {
|
||||
#ifndef DATALINK_ENABLE_BERTEST
|
||||
COORD coordTemp;
|
||||
float tmpVal;
|
||||
memcpy(&tmpVal, msg+L2_MSG_INFO_POSX, sizeof(float));
|
||||
memcpy(&tmpVal, msg + L2_MSG_INFO_POSX, sizeof(float));
|
||||
coordTemp.x = tmpVal;
|
||||
memcpy(&tmpVal, msg+L2_MSG_INFO_POSY, sizeof(float));
|
||||
memcpy(&tmpVal, msg + L2_MSG_INFO_POSY, sizeof(float));
|
||||
coordTemp.y = tmpVal;
|
||||
memcpy(&tmpVal, msg+L2_MSG_INFO_POSZ, sizeof(float));
|
||||
memcpy(&tmpVal, msg + L2_MSG_INFO_POSZ, sizeof(float));
|
||||
coordTemp.z = tmpVal;
|
||||
Status = UpdateNodePos(instPtr->nodeInfoList, L2_MEMBER_NODE_ID, &coordTemp);
|
||||
if (Status != SUCCESS) {
|
||||
if (Status != SUCCESS)
|
||||
{
|
||||
DBG_ERROR("Failed to update node %d position, errorCode: %ld.\n", L2_MEMBER_NODE_ID, Status);
|
||||
}
|
||||
memcpy(&tmpVal, msg+L2_MSG_INFO_SPEEDX, sizeof(float));
|
||||
memcpy(&tmpVal, msg + L2_MSG_INFO_SPEEDX, sizeof(float));
|
||||
coordTemp.x = tmpVal;
|
||||
memcpy(&tmpVal, msg+L2_MSG_INFO_SPEEDY, sizeof(float));
|
||||
memcpy(&tmpVal, msg + L2_MSG_INFO_SPEEDY, sizeof(float));
|
||||
coordTemp.y = tmpVal;
|
||||
memcpy(&tmpVal, msg+L2_MSG_INFO_SPEEDZ, sizeof(float));
|
||||
memcpy(&tmpVal, msg + L2_MSG_INFO_SPEEDZ, sizeof(float));
|
||||
coordTemp.z = tmpVal;
|
||||
Status = UpdateNodeSpeed(instPtr->nodeInfoList, L2_MEMBER_NODE_ID, &coordTemp);
|
||||
if (Status != SUCCESS) {
|
||||
if (Status != SUCCESS)
|
||||
{
|
||||
DBG_ERROR("Failed to update node %d speed, errorCode: %ld.\n", L2_MEMBER_NODE_ID, Status);
|
||||
}
|
||||
|
||||
@@ -324,38 +362,46 @@ int32_t L2_Service_PktHandler(L2_INST *instPtr, uint8_t *msg) {
|
||||
// Update Time deviation
|
||||
int64_t devi, deviTrunc;
|
||||
Status = L2_TimeSync_GetDeviatoion(instPtr, &devi);
|
||||
if (Status != SUCCESS) {
|
||||
if (Status != SUCCESS)
|
||||
{
|
||||
DBG_ERROR("Failed to compute slot deviation.\n");
|
||||
deviTrunc = 0;
|
||||
}
|
||||
else {
|
||||
if(devi > INT32_MAX || devi < INT32_MIN) {
|
||||
else
|
||||
{
|
||||
if (devi > INT32_MAX || devi < INT32_MIN)
|
||||
{
|
||||
DBG_WARNING("Illegal deviation value: %lld, omit it.\n", devi);
|
||||
deviTrunc = 0;
|
||||
}
|
||||
else if(devi > L2_MSG_SVC_TMSYNC_MAX || devi < L2_MSG_SVC_TMSYNC_MIN) {
|
||||
else if (devi > L2_MSG_SVC_TMSYNC_MAX || devi < L2_MSG_SVC_TMSYNC_MIN)
|
||||
{
|
||||
DBG_WARNING("Deviation value: %lld is out of adjustable range.\n", devi);
|
||||
deviTrunc = (int32_t)devi;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
deviTrunc = (int32_t)devi;
|
||||
}
|
||||
UpdateNodeTimeDeviation(instPtr->nodeInfoList, L2_MEMBER_NODE_ID, (uint32_t)deviTrunc);
|
||||
}
|
||||
Status = UpdateNodeTimeDeviation(instPtr->nodeInfoList, L2_MEMBER_NODE_ID, (uint32_t)deviTrunc);
|
||||
if (Status != SUCCESS) {
|
||||
if (Status != SUCCESS)
|
||||
{
|
||||
DBG_ERROR("Failed to update node %d time deviation, errorCode: %ld.\n", L2_MEMBER_NODE_ID, Status);
|
||||
}
|
||||
#else
|
||||
for(int i = 0; i < SVC_PACK_LEN; i++) {
|
||||
instPtr->serviceFsm.bitError += count_ones(msg[i]^berTestData[i]);
|
||||
for (int i = 0; i < SVC_PACK_LEN; i++)
|
||||
{
|
||||
instPtr->serviceFsm.bitError += count_ones(msg[i] ^ berTestData[i]);
|
||||
}
|
||||
instPtr->serviceFsm.bitTotal += SVC_PACK_LEN*8;
|
||||
instPtr->serviceFsm.bitTotal += SVC_PACK_LEN * 8;
|
||||
#endif
|
||||
instPtr->serviceFsm.pktRecved++;
|
||||
// Reset Node TTL
|
||||
Status = RstNodeTTL(instPtr->nodeInfoList, L2_MEMBER_NODE_ID);
|
||||
if (Status != SUCCESS) {
|
||||
if (Status != SUCCESS)
|
||||
{
|
||||
DBG_ERROR("Failed to reset node %d ttl, errorCode: %ld.\n", L2_MEMBER_NODE_ID, Status);
|
||||
}
|
||||
break;
|
||||
@@ -377,42 +423,53 @@ int32_t L2_Service_PktHandler(L2_INST *instPtr, uint8_t *msg) {
|
||||
* @return Slot has been used.
|
||||
*
|
||||
******************************************************************************/
|
||||
int32_t L2_Service_Routine(L2_INST *instPtr, L2_RTNE_TABLE_ENTRY *schedEntry) {
|
||||
int32_t L2_Service_Routine(L2_INST *instPtr, L2_RTNE_TABLE_ENTRY *schedEntry)
|
||||
{
|
||||
ASSERT(instPtr != NULL);
|
||||
DBG_INFO("-------- ServiceNet Routine --------\n");
|
||||
uint8_t *sendData;
|
||||
int32_t usedSlots;
|
||||
L2_TOR_TYPE torState;
|
||||
if(schedEntry->src == instPtr->config.myId){
|
||||
if (schedEntry->src == instPtr->config.myId)
|
||||
{
|
||||
torState = L2_TOR_TX;
|
||||
}
|
||||
else if(schedEntry->dst == instPtr->config.myId){
|
||||
else if (schedEntry->dst == instPtr->config.myId)
|
||||
{
|
||||
torState = L2_TOR_RX;
|
||||
instPtr->serviceFsm.pktRecv++;
|
||||
}
|
||||
else{
|
||||
else
|
||||
{
|
||||
torState = L2_TOR_SUSPEND;
|
||||
}
|
||||
|
||||
switch(schedEntry->slotType){
|
||||
switch (schedEntry->slotType)
|
||||
{
|
||||
case L2_SLOT_SERVICE:
|
||||
if(torState == L2_TOR_TX){
|
||||
if (torState == L2_TOR_TX)
|
||||
{
|
||||
#ifndef DATALINK_ENABLE_BERTEST
|
||||
if (instPtr->serviceFsm.txSeqNum == 0) {
|
||||
if(instPtr->config.myType == L2_HEAD_NODE){
|
||||
if (instPtr->serviceFsm.txSeqNum == 0)
|
||||
{
|
||||
if (instPtr->config.myType == L2_HEAD_NODE)
|
||||
{
|
||||
SysMonitor_GetSendPayloadFLJRaw(instPtr->serviceFsm.txLog);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
SysMonitor_GetSendPayloadLJRaw(instPtr->serviceFsm.txLog);
|
||||
}
|
||||
}
|
||||
// Packing service data
|
||||
Service_Packing(instPtr, L2_SVC_FRAME);
|
||||
if (CircQueuePop(instPtr->txQueue, (void **)(&sendData)) == true) {
|
||||
if (CircQueuePop(instPtr->txQueue, (void **)(&sendData)) == true)
|
||||
{
|
||||
memcpy(instPtr->sendPktData, sendData, SVC_PACK_LEN);
|
||||
free(sendData);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
DBG_ERROR("Failed to pop tx queue.\n");
|
||||
}
|
||||
#else
|
||||
@@ -428,14 +485,17 @@ int32_t L2_Service_Routine(L2_INST *instPtr, L2_RTNE_TABLE_ENTRY *schedEntry) {
|
||||
break;
|
||||
#ifndef DATALINK_ENABLE_BERTEST
|
||||
case L2_SLOT_ADVERTISE:
|
||||
if(torState == L2_TOR_TX){
|
||||
if (torState == L2_TOR_TX)
|
||||
{
|
||||
// Packing response data.
|
||||
Service_Packing(instPtr, L2_INFO_FRAME);
|
||||
if (CircQueuePop(instPtr->txQueue, (void **)(&sendData)) == true) {
|
||||
if (CircQueuePop(instPtr->txQueue, (void **)(&sendData)) == true)
|
||||
{
|
||||
memcpy(instPtr->sendPktData, sendData, RSP_PACK_LEN);
|
||||
free(sendData);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
DBG_ERROR("Failed to pop tx queue.\n");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* Description: Time sync implementation file.
|
||||
*
|
||||
*
|
||||
* Date: 2021-12-04 16:32
|
||||
* LastEditors: FanHao
|
||||
* LastEditTime: 2022-07-10 20:43
|
||||
* Revisions: Rev 0.0
|
||||
* History:
|
||||
* History:
|
||||
* [2022-07-10]: New branch for Dijian.
|
||||
* [2021-12-04]: Initial version.
|
||||
*
|
||||
*
|
||||
* Copyright(c) 2021 Beijing Institute of Technology.
|
||||
* Lab of Communication and Networking
|
||||
*
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/***************************** Include Files *********************************/
|
||||
@@ -23,25 +23,25 @@
|
||||
#include "link_layer.h"
|
||||
#include "../phy_layer/phy_reg.h"
|
||||
/************************** Constant Definitions *****************************/
|
||||
#define MAX_FREQ_EST_NUM 128 // 32bit word
|
||||
#define SVC_FREQ_EST_NUM 512 // byte
|
||||
#define MGMT_FREQ_EST_NUM 512 // byte
|
||||
#define MAX_FREQ_EST_NUM 128 // 32bit word
|
||||
#define SVC_FREQ_EST_NUM 512 // byte
|
||||
#define MGMT_FREQ_EST_NUM 512 // byte
|
||||
#define BISAR_FREQ_EST_NUM 480 // byte
|
||||
|
||||
#define SYS_CLK_FREQ 192000000.0 // Hz
|
||||
#define SIG_CLK_FREQ 245760000.0 // Hz
|
||||
#define CXR_FREQ 3800000000.0 // Hz
|
||||
#define SYS_CLK_FREQ 192000000.0 // Hz
|
||||
#define SIG_CLK_FREQ 245760000.0 // Hz
|
||||
#define CXR_FREQ 3800000000.0 // Hz
|
||||
|
||||
#define NORMAL_SLOT_CLK_NUM 960000.0 // 9600000= 5e-3*192e6
|
||||
#define COUNTER_10NS_MAX 500000 // how many 10ns in a 5ms
|
||||
#define COUNTER_10NS_MAX 500000 // how many 10ns in a 5ms
|
||||
|
||||
#define LIGHT_SPPED_AIR 299702547.0 // m/s
|
||||
#define LIGHT_SPPED_VAC 299792458.0 // m/s
|
||||
|
||||
//#define PHY_SYNCT2FEND_200K 904052UL
|
||||
//#define PHY_SYNCT2FEND_200K 924232UL
|
||||
// #define PHY_SYNCT2FEND_200K 904052UL
|
||||
// #define PHY_SYNCT2FEND_200K 924232UL
|
||||
|
||||
#define PHY_SYNCT2FEND_2K_20MS 276336UL // 1.919ms
|
||||
#define PHY_SYNCT2FEND_2K_20MS 276336UL // 1.919ms
|
||||
#define PHY_SYNCT2FEND_2K_100MS 11796336UL // 81.919ms
|
||||
|
||||
#define PHY_LOCAL_CNT_MAX 0x0000FFFFFFFFFFFFULL
|
||||
@@ -60,7 +60,8 @@
|
||||
* @return
|
||||
*
|
||||
******************************************************************************/
|
||||
inline int32_t L2_TimeSync_LocalTimerAdd(L2_INST *instPtr, int64_t adjustment) {
|
||||
inline int32_t L2_TimeSync_LocalTimerAdd(L2_INST *instPtr, int64_t adjustment)
|
||||
{
|
||||
// read nextSendTime from physical layer
|
||||
Phy_SetTimeWord(instPtr->config.phyInstRef, adjustment, PHY_TIME_WORD_LOCAL_ADJ);
|
||||
PhyWrite(instPtr->config.phyInstRef, TM_ADJ_MODE, TM_ADJ_MODE_ADD);
|
||||
@@ -76,11 +77,13 @@ inline int32_t L2_TimeSync_LocalTimerAdd(L2_INST *instPtr, int64_t adjustment) {
|
||||
* @return
|
||||
*
|
||||
******************************************************************************/
|
||||
int32_t L2_TimeSync_SlotAlign(L2_INST *instPtr) {
|
||||
int32_t L2_TimeSync_SlotAlign(L2_INST *instPtr)
|
||||
{
|
||||
int32_t Status;
|
||||
int64_t slotAdj;
|
||||
int64_t slotAdj;
|
||||
Status = L2_TimeSync_GetDeviatoion(instPtr, &slotAdj);
|
||||
if (Status != SUCCESS) {
|
||||
if (Status != SUCCESS)
|
||||
{
|
||||
DBG_ERROR("Failed to compute slot deviation.\n");
|
||||
return Status;
|
||||
}
|
||||
@@ -97,17 +100,19 @@ int32_t L2_TimeSync_SlotAlign(L2_INST *instPtr) {
|
||||
* @return
|
||||
*
|
||||
******************************************************************************/
|
||||
int32_t L2_TimeSync_GetDeviatoion(L2_INST *instPtr, int64_t *devi) {
|
||||
int32_t L2_TimeSync_GetDeviatoion(L2_INST *instPtr, int64_t *devi)
|
||||
{
|
||||
// read nextSendTime from physical layer
|
||||
int64_t currentTarget, lastFrameSync, slotMeasure;
|
||||
int64_t currentTarget, lastFrameSync, slotMeasure;
|
||||
currentTarget = PhyRead(instPtr->config.phyInstRef, TM_TARGET_L);
|
||||
currentTarget |= ((int64_t)PhyRead(instPtr->config.phyInstRef, TM_TARGET_H)) << 32;
|
||||
lastFrameSync = PhyRead(instPtr->config.phyInstRef, FSTIME_L);
|
||||
lastFrameSync |= ((int64_t)PhyRead(instPtr->config.phyInstRef, FSTIME_H)) << 32;
|
||||
slotMeasure = (currentTarget > lastFrameSync) ? (currentTarget - lastFrameSync)
|
||||
: (currentTarget - lastFrameSync + PHY_LOCAL_CNT_MAX);
|
||||
switch (Phy_GetLastDetectedFrameType(instPtr->config.phyInstRef)) {
|
||||
case L1_2KBPS_20MS_FRAME :
|
||||
switch (Phy_GetLastDetectedFrameType(instPtr->config.phyInstRef))
|
||||
{
|
||||
case L1_2KBPS_20MS_FRAME:
|
||||
*devi = ((int64_t)PHY_SYNCT2FEND_2K_20MS) - slotMeasure;
|
||||
break;
|
||||
case L1_2KBPS_100MS_FRAME:
|
||||
@@ -119,5 +124,3 @@ int32_t L2_TimeSync_GetDeviatoion(L2_INST *instPtr, int64_t *devi) {
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -230,11 +230,14 @@ int32_t Phy_AntConfigInit(PHY_ANT_COINFO *antConfigPtr)
|
||||
|
||||
int32_t Phy_SetBeamNo(PHY_INST *instPtr, int32_t beamNo)
|
||||
{
|
||||
if(instPtr->beamWd.next == PHY_ANT_BEAM_8){
|
||||
if (beamNo >= L1_NUM_ANT_NRRW_PATTERN) {
|
||||
if (instPtr->beamWd.next == PHY_ANT_BEAM_8)
|
||||
{
|
||||
if (beamNo >= L1_NUM_ANT_NRRW_PATTERN)
|
||||
{
|
||||
return FAILURE;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
instPtr->beamNo.next = beamNo;
|
||||
instPtr->antConfigPtr.oaxis[1] = (uint8_t)(antNrrwPattern[beamNo].oaxis);
|
||||
instPtr->antConfigPtr.oaxis[0] = (uint8_t)((antNrrwPattern[beamNo].oaxis) >> 8);
|
||||
@@ -243,11 +246,14 @@ int32_t Phy_SetBeamNo(PHY_INST *instPtr, int32_t beamNo)
|
||||
return SUCCESS;
|
||||
}
|
||||
}
|
||||
else if(instPtr->beamWd.next == PHY_ANT_BEAM_25){
|
||||
if (beamNo >= L1_NUM_ANT_SUBNRRW_PATTERN) {
|
||||
else if (instPtr->beamWd.next == PHY_ANT_BEAM_25)
|
||||
{
|
||||
if (beamNo >= L1_NUM_ANT_SUBNRRW_PATTERN)
|
||||
{
|
||||
return FAILURE;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
instPtr->beamNo.next = beamNo;
|
||||
instPtr->antConfigPtr.oaxis[1] = (uint8_t)(antSubnrrwPattern[beamNo].oaxis);
|
||||
instPtr->antConfigPtr.oaxis[0] = (uint8_t)((antSubnrrwPattern[beamNo].oaxis) >> 8);
|
||||
@@ -256,7 +262,8 @@ int32_t Phy_SetBeamNo(PHY_INST *instPtr, int32_t beamNo)
|
||||
return SUCCESS;
|
||||
}
|
||||
}
|
||||
else{
|
||||
else
|
||||
{
|
||||
// Beam number assign not support.
|
||||
// Assign default angle (0,0)
|
||||
instPtr->beamNo.next = 0;
|
||||
@@ -306,7 +313,7 @@ int32_t Phy_SetBeamAngle(PHY_INST *phyInstPtr, double offAx, double rndAx)
|
||||
if (offAxDeg > 60)
|
||||
{
|
||||
DBG_ERROR("Angle out of range, off axis angle: %u (should be 0~60), round axis angle: %u (should be 0~360).\n",
|
||||
offAxDeg, rndAxDeg);
|
||||
offAxDeg, rndAxDeg);
|
||||
return EPARAM;
|
||||
}
|
||||
offAxDeg = offAxDeg * 10;
|
||||
|
||||
@@ -30,39 +30,39 @@
|
||||
#include "../config/app_config.h"
|
||||
|
||||
/************************** Constant Definitions *****************************/
|
||||
#define TOR_BUFF_MAX_SIZE 1024 //8192bits
|
||||
#define TMWORD_FRAC_MAX 500000
|
||||
#define ANTCONFIG_MAX_LEN (8192/2)
|
||||
#define PAYLOAD_MAX_LEN (4096/2)
|
||||
#define TOR_BUFF_MAX_SIZE 1024 // 8192bits
|
||||
#define TMWORD_FRAC_MAX 500000
|
||||
#define ANTCONFIG_MAX_LEN (8192 / 2)
|
||||
#define PAYLOAD_MAX_LEN (4096 / 2)
|
||||
|
||||
#define INIT_BEAM_NO 0
|
||||
#define INIT_ANT_WD PHY_ANT_BEAM_120
|
||||
#define INIT_ANT_NO 0
|
||||
|
||||
#define L1_FRAME_NONE_LEN UINT32_MAX// byte
|
||||
#define L1_FRAME_2KBPS_20MS_LEN 0 // byte
|
||||
#define L1_FRAME_2KBPS_100MS_LEN (240/8 )// byte
|
||||
#define L1_FRAME_10KBPS_10MS_LEN 0 // byte
|
||||
#define L1_FRAME_10KBPS_20MS_LEN (240/8) // byte
|
||||
#define L1_FRAME_40KBPS_20MS_LEN (2160/8)// byte
|
||||
#define L1_FRAME_40KBPS_10MS_LEN (720/8) // byte
|
||||
#define L1_FRAME_200KBPS_5MS_LEN (2048/8)// byte
|
||||
#define L1_FRAME_1M2BPS_5MS_LEN (8184/8)// byte
|
||||
#define L1_FRAME_NONE_LEN UINT32_MAX // byte
|
||||
#define L1_FRAME_2KBPS_20MS_LEN 0 // byte
|
||||
#define L1_FRAME_2KBPS_100MS_LEN (240 / 8) // byte
|
||||
#define L1_FRAME_10KBPS_10MS_LEN 0 // byte
|
||||
#define L1_FRAME_10KBPS_20MS_LEN (240 / 8) // byte
|
||||
#define L1_FRAME_40KBPS_20MS_LEN (2160 / 8) // byte
|
||||
#define L1_FRAME_40KBPS_10MS_LEN (720 / 8) // byte
|
||||
#define L1_FRAME_200KBPS_5MS_LEN (2048 / 8) // byte
|
||||
#define L1_FRAME_1M2BPS_5MS_LEN (8184 / 8) // byte
|
||||
|
||||
#define L1_FRAME_NONE_COMP UINT32_MAX // *10ns
|
||||
#define L1_FRAME_2KBPS_20MS_COMP 1622400 // *10ns
|
||||
#define L1_FRAME_2KBPS_100MS_COMP 1622400 // *10ns
|
||||
#define L1_FRAME_10KBPS_10MS_COMP 747366 // *10ns
|
||||
#define L1_FRAME_10KBPS_20MS_COMP 747366 // *10ns
|
||||
#define L1_FRAME_40KBPS_20MS_COMP 97066 // *10ns
|
||||
#define L1_FRAME_40KBPS_10MS_COMP 97066 // *10ns
|
||||
#define L1_FRAME_200KBPS_5MS_COMP 17067 // *10ns
|
||||
#define L1_FRAME_1M2BPS_5MS_COMP 17067 // *10ns
|
||||
#define L1_FRAME_NONE_COMP UINT32_MAX // *10ns
|
||||
#define L1_FRAME_2KBPS_20MS_COMP 1622400 // *10ns
|
||||
#define L1_FRAME_2KBPS_100MS_COMP 1622400 // *10ns
|
||||
#define L1_FRAME_10KBPS_10MS_COMP 747366 // *10ns
|
||||
#define L1_FRAME_10KBPS_20MS_COMP 747366 // *10ns
|
||||
#define L1_FRAME_40KBPS_20MS_COMP 97066 // *10ns
|
||||
#define L1_FRAME_40KBPS_10MS_COMP 97066 // *10ns
|
||||
#define L1_FRAME_200KBPS_5MS_COMP 17067 // *10ns
|
||||
#define L1_FRAME_1M2BPS_5MS_COMP 17067 // *10ns
|
||||
|
||||
/***************** Macros (Inline Functions) Definitions *********************/
|
||||
/************************** Function Prototypes ******************************/
|
||||
static void Phy_RcdShift(PHY_RCD* rcd, int32_t netxVal);
|
||||
static int32_t SetSendData(PHY_INST* instPtr, L1_FRAME_TYPE frameType, uint8_t* buff);
|
||||
static void Phy_RcdShift(PHY_RCD *rcd, int32_t netxVal);
|
||||
static int32_t SetSendData(PHY_INST *instPtr, L1_FRAME_TYPE frameType, uint8_t *buff);
|
||||
|
||||
/**************************** Type Definitions *******************************/
|
||||
|
||||
@@ -79,22 +79,24 @@ static int32_t SetSendData(PHY_INST* instPtr, L1_FRAME_TYPE frameType, uint8_t*
|
||||
* FAILURE last frame type cannot be recognized.
|
||||
*
|
||||
******************************************************************************/
|
||||
int32_t Phy_RetrieveRecvData(PHY_INST* instPtr, uint8_t* buff) {
|
||||
int32_t Phy_RetrieveRecvData(PHY_INST *instPtr, uint8_t *buff)
|
||||
{
|
||||
ASSERT(instPtr != NULL);
|
||||
uint32_t frameLen, recvBramAddr;
|
||||
frameLen = Phy_GetFrameLen(instPtr->frameType.last);
|
||||
if (frameLen == L1_FRAME_NONE_LEN) {
|
||||
if (frameLen == L1_FRAME_NONE_LEN)
|
||||
{
|
||||
return FAILURE;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
// Ping-pong flow.
|
||||
recvBramAddr = instPtr->rxDataPtr + ((PhyRead(instPtr, RECV_DATA_SATE) & RECV_DATA_OFFSET_MASK) >> RECV_DATA_OFFSET_SHIFT);
|
||||
memcpy(buff, (uint8_t*) recvBramAddr, frameLen);
|
||||
memcpy(buff, (uint8_t *)recvBramAddr, frameLen);
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* @brief Setup data will be sent in next slot.
|
||||
@@ -105,18 +107,21 @@ int32_t Phy_RetrieveRecvData(PHY_INST* instPtr, uint8_t* buff) {
|
||||
* SUCCESS Setting data successful.
|
||||
*
|
||||
******************************************************************************/
|
||||
static int32_t SetSendData(PHY_INST* instPtr, L1_FRAME_TYPE frameType, uint8_t* buff) {
|
||||
static int32_t SetSendData(PHY_INST *instPtr, L1_FRAME_TYPE frameType, uint8_t *buff)
|
||||
{
|
||||
ASSERT(instPtr != NULL);
|
||||
uint32_t frameLen, sendCmd;
|
||||
frameLen = Phy_GetFrameLen(frameType);
|
||||
|
||||
if (frameLen == L1_FRAME_NONE_LEN) {
|
||||
if (frameLen == L1_FRAME_NONE_LEN)
|
||||
{
|
||||
return FAILURE;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
// Implement a ping-pong flow, offset always is 0 or half of buffer depth.
|
||||
instPtr->sendOffset = (instPtr->sendOffset == PAYLOAD_MAX_LEN) ? 0 : PAYLOAD_MAX_LEN;
|
||||
memcpy((uint8_t*) (instPtr->txDataPtr + instPtr->sendOffset), buff, frameLen);
|
||||
memcpy((uint8_t *)(instPtr->txDataPtr + instPtr->sendOffset), buff, frameLen);
|
||||
// Trigger Physical layer to start fetching data.
|
||||
sendCmd = frameLen & SEND_DATA_CMD_LEN_MASK;
|
||||
sendCmd |= (instPtr->sendOffset << SEND_DATA_CMD_OFFSET_SHIFT) & SEND_DATA_CMD_OFFSET_MASK;
|
||||
@@ -125,7 +130,6 @@ static int32_t SetSendData(PHY_INST* instPtr, L1_FRAME_TYPE frameType, uint8_t*
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* @brief Check whether a frame was detected. (Do not check if the frame was
|
||||
@@ -137,12 +141,15 @@ static int32_t SetSendData(PHY_INST* instPtr, L1_FRAME_TYPE frameType, uint8_t*
|
||||
* false
|
||||
*
|
||||
******************************************************************************/
|
||||
inline bool Phy_IsFrameDetected(PHY_INST* instPtr) {
|
||||
inline bool Phy_IsFrameDetected(PHY_INST *instPtr)
|
||||
{
|
||||
ASSERT(instPtr != NULL);
|
||||
if(instPtr->TOR.last == PHY_TOR_RX && instPtr->isAcq && instPtr->isFrameSync) {
|
||||
if (instPtr->TOR.last == PHY_TOR_RX && instPtr->isAcq && instPtr->isFrameSync)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -151,20 +158,22 @@ inline bool Phy_IsFrameDetected(PHY_INST* instPtr) {
|
||||
/**
|
||||
* @brief Check whether a frame was received. (Do not check if the frame was
|
||||
* crashed.)
|
||||
*
|
||||
*
|
||||
* @param instPtr
|
||||
*
|
||||
*
|
||||
* @return true
|
||||
* false
|
||||
*
|
||||
*
|
||||
******************************************************************************/
|
||||
inline bool Phy_IsFrameReceived(PHY_INST* instPtr) {
|
||||
inline bool Phy_IsFrameReceived(PHY_INST *instPtr)
|
||||
{
|
||||
ASSERT(instPtr != NULL);
|
||||
if(instPtr->TOR.last == PHY_TOR_RX && instPtr->isAcq
|
||||
&& instPtr->isFrameSync && instPtr->isDecode) {
|
||||
if (instPtr->TOR.last == PHY_TOR_RX && instPtr->isAcq && instPtr->isFrameSync && instPtr->isDecode)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -180,13 +189,15 @@ inline bool Phy_IsFrameReceived(PHY_INST* instPtr) {
|
||||
* false
|
||||
*
|
||||
******************************************************************************/
|
||||
inline bool Phy_IsFrameValid(PHY_INST* instPtr) {
|
||||
inline bool Phy_IsFrameValid(PHY_INST *instPtr)
|
||||
{
|
||||
ASSERT(instPtr != NULL);
|
||||
if (instPtr->TOR.last == PHY_TOR_RX && instPtr->isAcq && instPtr->isFrameSync
|
||||
&& instPtr->isDecode && instPtr->isValid) {
|
||||
if (instPtr->TOR.last == PHY_TOR_RX && instPtr->isAcq && instPtr->isFrameSync && instPtr->isDecode && instPtr->isValid)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -200,12 +211,15 @@ inline bool Phy_IsFrameValid(PHY_INST* instPtr) {
|
||||
* @return Layer2 frame type. Refer "frame_def.h"
|
||||
*
|
||||
******************************************************************************/
|
||||
inline L1_FRAME_TYPE Phy_GetLastDetectedFrameType(PHY_INST* instPtr) {
|
||||
inline L1_FRAME_TYPE Phy_GetLastDetectedFrameType(PHY_INST *instPtr)
|
||||
{
|
||||
ASSERT(instPtr != NULL);
|
||||
if (Phy_IsFrameDetected(instPtr) == false) {
|
||||
if (Phy_IsFrameDetected(instPtr) == false)
|
||||
{
|
||||
return L1_NONE_FRAME;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
return instPtr->frameType.last;
|
||||
}
|
||||
}
|
||||
@@ -219,17 +233,19 @@ inline L1_FRAME_TYPE Phy_GetLastDetectedFrameType(PHY_INST* instPtr) {
|
||||
* @return Layer2 frame type. Refer "frame_def.h"
|
||||
*
|
||||
******************************************************************************/
|
||||
inline L1_FRAME_TYPE Phy_GetLastReceivedFrameType(PHY_INST* instPtr) {
|
||||
inline L1_FRAME_TYPE Phy_GetLastReceivedFrameType(PHY_INST *instPtr)
|
||||
{
|
||||
ASSERT(instPtr != NULL);
|
||||
if (Phy_IsFrameReceived(instPtr) == false) {
|
||||
if (Phy_IsFrameReceived(instPtr) == false)
|
||||
{
|
||||
return L1_NONE_FRAME;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
return instPtr->frameType.last;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* @brief Get frame type of the frame was sent in last slot.
|
||||
@@ -239,12 +255,15 @@ inline L1_FRAME_TYPE Phy_GetLastReceivedFrameType(PHY_INST* instPtr) {
|
||||
* @return Layer2 frame type. Refer "frame_def.h"
|
||||
*
|
||||
******************************************************************************/
|
||||
inline L1_FRAME_TYPE Phy_GetLastSentFrameType(PHY_INST* instPtr) {
|
||||
inline L1_FRAME_TYPE Phy_GetLastSentFrameType(PHY_INST *instPtr)
|
||||
{
|
||||
ASSERT(instPtr != NULL);
|
||||
if (instPtr->TOR.last != PHY_TOR_TX) {
|
||||
if (instPtr->TOR.last != PHY_TOR_TX)
|
||||
{
|
||||
return L1_NONE_FRAME;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
return instPtr->frameType.last;
|
||||
}
|
||||
}
|
||||
@@ -258,7 +277,8 @@ inline L1_FRAME_TYPE Phy_GetLastSentFrameType(PHY_INST* instPtr) {
|
||||
* @return NONE.
|
||||
*
|
||||
******************************************************************************/
|
||||
static void Phy_RcdShift(PHY_RCD* rcd, int32_t netxVal){
|
||||
static void Phy_RcdShift(PHY_RCD *rcd, int32_t netxVal)
|
||||
{
|
||||
ASSERT(rcd != NULL);
|
||||
rcd->last = rcd->curr;
|
||||
rcd->curr = rcd->next;
|
||||
@@ -275,12 +295,14 @@ static void Phy_RcdShift(PHY_RCD* rcd, int32_t netxVal){
|
||||
* L1_FRAME_NONE_LEN if the frame type code cannot be recognized.
|
||||
*
|
||||
******************************************************************************/
|
||||
uint32_t Phy_GetFrameLen(L1_FRAME_TYPE frameType) {
|
||||
switch (frameType) {
|
||||
uint32_t Phy_GetFrameLen(L1_FRAME_TYPE frameType)
|
||||
{
|
||||
switch (frameType)
|
||||
{
|
||||
case L1_2KBPS_20MS_FRAME:
|
||||
// FIXME: for DUIFEI net setup
|
||||
return L1_FRAME_2KBPS_100MS_LEN;
|
||||
// return L1_FRAME_2KBPS_20MS_LEN;
|
||||
// return L1_FRAME_2KBPS_20MS_LEN;
|
||||
case L1_2KBPS_100MS_FRAME:
|
||||
return L1_FRAME_2KBPS_100MS_LEN;
|
||||
case L1_10KBPS_10MS_FRAME:
|
||||
@@ -300,8 +322,6 @@ uint32_t Phy_GetFrameLen(L1_FRAME_TYPE frameType) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* @brief Update Physical Layer reception status.
|
||||
@@ -311,48 +331,52 @@ uint32_t Phy_GetFrameLen(L1_FRAME_TYPE frameType) {
|
||||
* @return
|
||||
*
|
||||
******************************************************************************/
|
||||
void Phy_UpdateState(PHY_INST* instPtr) {
|
||||
void Phy_UpdateState(PHY_INST *instPtr)
|
||||
{
|
||||
ASSERT(instPtr != NULL);
|
||||
|
||||
Phy_RcdShift(&(instPtr->TOR), PHY_TOR_SUSPEND);
|
||||
Phy_RcdShift(&(instPtr->frameType),L1_NONE_FRAME);
|
||||
Phy_RcdShift(&(instPtr->antNo),INIT_ANT_NO);
|
||||
Phy_RcdShift(&(instPtr->beamNo),INIT_BEAM_NO);
|
||||
Phy_RcdShift(&(instPtr->beamWd),INIT_ANT_WD);
|
||||
Phy_RcdShift(&(instPtr->frameType), L1_NONE_FRAME);
|
||||
Phy_RcdShift(&(instPtr->antNo), INIT_ANT_NO);
|
||||
Phy_RcdShift(&(instPtr->beamNo), INIT_BEAM_NO);
|
||||
Phy_RcdShift(&(instPtr->beamWd), INIT_ANT_WD);
|
||||
/* Update Frame Sate. */
|
||||
uint32_t txrxSate = PhyRead(instPtr, TXRX_STATE);
|
||||
instPtr->isAcq = ((txrxSate & TXRX_STATE_ACQ_MASK) == TXRX_STATE_ACQ_SUCCESS) ? true : false;
|
||||
instPtr->isFrameSync = ((txrxSate & TXRX_STATE_FSYNC_MASK) == TXRX_STATE_FSYNC_SUCCESS) ? true : false;
|
||||
instPtr->isDecode = ((txrxSate & TXRX_STATE_DECODE_MASK) == TXRX_STATE_DECODE_SUCCESS) ? true : false;
|
||||
|
||||
if (Phy_IsFrameReceived(instPtr)) {
|
||||
if (Phy_IsFrameReceived(instPtr))
|
||||
{
|
||||
DBG_INFO("Physical layer finished reception procedure, retrieving received data...\n");
|
||||
instPtr->isValid = true;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
instPtr->isValid = false;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* @brief Initialize Physical Layer instance, allocate memory for buffers,
|
||||
* apply a self test.
|
||||
*
|
||||
*
|
||||
* @param instPtr
|
||||
* phyConfig
|
||||
*
|
||||
* @return
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*
|
||||
******************************************************************************/
|
||||
int32_t Phy_InstInit(PHY_INST** instPtr, PHY_CONFIG *phyConfig) {
|
||||
int32_t Phy_InstInit(PHY_INST **instPtr, PHY_CONFIG *phyConfig)
|
||||
{
|
||||
ASSERT(instPtr != NULL);
|
||||
ASSERT(phyConfig != NULL);
|
||||
int32_t Status = SUCCESS;
|
||||
*instPtr = (PHY_INST*) malloc(sizeof(PHY_INST));
|
||||
if ((*instPtr) == NULL) {
|
||||
*instPtr = (PHY_INST *)malloc(sizeof(PHY_INST));
|
||||
if ((*instPtr) == NULL)
|
||||
{
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
@@ -374,7 +398,8 @@ int32_t Phy_InstInit(PHY_INST** instPtr, PHY_CONFIG *phyConfig) {
|
||||
memset(&((*instPtr)->hwSate), 0x00, sizeof(HWSTATE));
|
||||
|
||||
Status = Phy_AntConfigInit(&((*instPtr)->antConfigPtr));
|
||||
if (Status != SUCCESS) {
|
||||
if (Status != SUCCESS)
|
||||
{
|
||||
goto init_error;
|
||||
}
|
||||
|
||||
@@ -383,57 +408,65 @@ int32_t Phy_InstInit(PHY_INST** instPtr, PHY_CONFIG *phyConfig) {
|
||||
XBram txDataBram;
|
||||
XBram rxDataBram;
|
||||
bramConfigPtr = XBram_LookupConfig(phyConfig->antBramId);
|
||||
if (bramConfigPtr == NULL) {
|
||||
if (bramConfigPtr == NULL)
|
||||
{
|
||||
Status = EDCONF;
|
||||
goto init_error;
|
||||
|
||||
}
|
||||
Status = XBram_CfgInitialize(&antConfigBram, bramConfigPtr,
|
||||
bramConfigPtr->CtrlBaseAddress);
|
||||
if (Status != SUCCESS) {
|
||||
bramConfigPtr->CtrlBaseAddress);
|
||||
if (Status != SUCCESS)
|
||||
{
|
||||
goto init_error;
|
||||
}
|
||||
/*
|
||||
* Execute the BRAM driver selftest.
|
||||
*/
|
||||
Status = XBram_SelfTest(&antConfigBram, 0);
|
||||
if (Status != SUCCESS) {
|
||||
if (Status != SUCCESS)
|
||||
{
|
||||
goto init_error;
|
||||
}
|
||||
|
||||
bramConfigPtr = XBram_LookupConfig(phyConfig->txBramId);
|
||||
if (bramConfigPtr == NULL) {
|
||||
if (bramConfigPtr == NULL)
|
||||
{
|
||||
Status = EDCONF;
|
||||
goto init_error;
|
||||
}
|
||||
Status = XBram_CfgInitialize(&txDataBram, bramConfigPtr,
|
||||
bramConfigPtr->CtrlBaseAddress);
|
||||
if (Status != SUCCESS) {
|
||||
bramConfigPtr->CtrlBaseAddress);
|
||||
if (Status != SUCCESS)
|
||||
{
|
||||
goto init_error;
|
||||
}
|
||||
/*
|
||||
* Execute the BRAM driver selftest.
|
||||
*/
|
||||
Status = XBram_SelfTest(&txDataBram, 0);
|
||||
if (Status != SUCCESS) {
|
||||
if (Status != SUCCESS)
|
||||
{
|
||||
goto init_error;
|
||||
}
|
||||
|
||||
bramConfigPtr = XBram_LookupConfig(phyConfig->rxBramId);
|
||||
if (bramConfigPtr == NULL) {
|
||||
if (bramConfigPtr == NULL)
|
||||
{
|
||||
Status = EDCONF;
|
||||
goto init_error;
|
||||
}
|
||||
Status = XBram_CfgInitialize(&rxDataBram, bramConfigPtr,
|
||||
bramConfigPtr->CtrlBaseAddress);
|
||||
if (Status != SUCCESS) {
|
||||
bramConfigPtr->CtrlBaseAddress);
|
||||
if (Status != SUCCESS)
|
||||
{
|
||||
goto init_error;
|
||||
}
|
||||
/*
|
||||
* Execute the BRAM driver selftest.
|
||||
*/
|
||||
Status = XBram_SelfTest(&rxDataBram, 0);
|
||||
if (Status != SUCCESS) {
|
||||
if (Status != SUCCESS)
|
||||
{
|
||||
goto init_error;
|
||||
}
|
||||
|
||||
@@ -445,7 +478,8 @@ int32_t Phy_InstInit(PHY_INST** instPtr, PHY_CONFIG *phyConfig) {
|
||||
XAdcPs_Config *xadcConfigPtr;
|
||||
|
||||
xadcConfigPtr = XAdcPs_LookupConfig(phyConfig->hwXadcId);
|
||||
if (xadcConfigPtr == NULL) {
|
||||
if (xadcConfigPtr == NULL)
|
||||
{
|
||||
Status = EDCONF;
|
||||
goto init_error;
|
||||
}
|
||||
@@ -453,7 +487,8 @@ int32_t Phy_InstInit(PHY_INST** instPtr, PHY_CONFIG *phyConfig) {
|
||||
|
||||
/* Self Test the XADC/ADC device */
|
||||
Status = XAdcPs_SelfTest(&((*instPtr)->hwXadc));
|
||||
if (Status != SUCCESS) {
|
||||
if (Status != SUCCESS)
|
||||
{
|
||||
goto init_error;
|
||||
}
|
||||
|
||||
@@ -469,16 +504,18 @@ init_error:
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* @brief Start physical layer
|
||||
*
|
||||
*
|
||||
* @param instPtr a pointer to physical instance
|
||||
*
|
||||
*
|
||||
* @return NONE
|
||||
*
|
||||
*
|
||||
******************************************************************************/
|
||||
void Phy_Start(PHY_INST* instPtr) {
|
||||
void Phy_Start(PHY_INST *instPtr)
|
||||
{
|
||||
ASSERT(instPtr != NULL);
|
||||
uint32_t phyMainCtrl = PhyRead(instPtr, PHY_MAIN_CTRL);
|
||||
if((phyMainCtrl & PHY_MAIN_CTRL_EN_MASK) == PHY_MAIN_CTRL_EN_EN) {
|
||||
if ((phyMainCtrl & PHY_MAIN_CTRL_EN_MASK) == PHY_MAIN_CTRL_EN_EN)
|
||||
{
|
||||
DBG_WARNING("Physical layer was already enabled.\n");
|
||||
}
|
||||
instPtr->isPhyEn = true;
|
||||
@@ -489,37 +526,40 @@ void Phy_Start(PHY_INST* instPtr) {
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* @brief Halt physical layer operation
|
||||
*
|
||||
*
|
||||
* @param instPtr a pointer to physical instance
|
||||
*
|
||||
*
|
||||
* @return NONE
|
||||
*
|
||||
*
|
||||
******************************************************************************/
|
||||
void Phy_Halt(PHY_INST* instPtr) {
|
||||
void Phy_Halt(PHY_INST *instPtr)
|
||||
{
|
||||
ASSERT(instPtr != NULL);
|
||||
uint32_t phyMainCtrl = PhyRead(instPtr, PHY_MAIN_CTRL);
|
||||
if((phyMainCtrl & PHY_MAIN_CTRL_EN_MASK) == PHY_MAIN_CTRL_EN_DSBL) {
|
||||
if ((phyMainCtrl & PHY_MAIN_CTRL_EN_MASK) == PHY_MAIN_CTRL_EN_DSBL)
|
||||
{
|
||||
DBG_WARNING("Physical layer was allready halted.\n");
|
||||
}
|
||||
instPtr->isPhyEn = false;
|
||||
PhyWrite(instPtr, PHY_MAIN_CTRL, (phyMainCtrl & (~PHY_MAIN_CTRL_EN_MASK)));
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* @brief Update Physical Layer mode.
|
||||
*
|
||||
*
|
||||
* @param instPtr
|
||||
* modeCod
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* modeCod
|
||||
*
|
||||
* @return
|
||||
*
|
||||
******************************************************************************/
|
||||
int32_t Phy_SetMode(PHY_INST* instPtr, PHY_MODE modeCod) {
|
||||
int32_t Phy_SetMode(PHY_INST *instPtr, PHY_MODE modeCod)
|
||||
{
|
||||
ASSERT(instPtr != NULL);
|
||||
uint32_t phyMainCtrl = PhyRead(instPtr, PHY_MAIN_CTRL) & ~PHY_MAIN_CTRL_MODE_MASK;
|
||||
switch (modeCod) {
|
||||
switch (modeCod)
|
||||
{
|
||||
case PHY_MODE_NONE:
|
||||
phyMainCtrl |= PHY_MAIN_CTRL_MODE_NONE;
|
||||
break;
|
||||
@@ -543,20 +583,21 @@ int32_t Phy_SetMode(PHY_INST* instPtr, PHY_MODE modeCod) {
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* @brief Setup next slot operation.
|
||||
*
|
||||
*
|
||||
* @param instPtr
|
||||
* txrxMode
|
||||
* l2FrameType
|
||||
*
|
||||
* @return
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*
|
||||
******************************************************************************/
|
||||
int32_t Phy_SetupNextSlot(PHY_INST* instPtr, PHY_TOR_TYPE txrxMode,
|
||||
L1_FRAME_TYPE frameType, uint8_t* buff) {
|
||||
int32_t Phy_SetupNextSlot(PHY_INST *instPtr, PHY_TOR_TYPE txrxMode,
|
||||
L1_FRAME_TYPE frameType, uint8_t *buff)
|
||||
{
|
||||
ASSERT(instPtr != NULL);
|
||||
int32_t Status = SUCCESS;
|
||||
uint32_t phyModeCtrl, antConfigBramAddr, hopNum;
|
||||
uint16_t* hopPattern;
|
||||
uint16_t *hopPattern;
|
||||
// Implement a ping-pong flow, offset always is 0 or half of buffer depth.
|
||||
instPtr->antConfigOffset = (instPtr->antConfigOffset == ANTCONFIG_MAX_LEN) ? 0 : ANTCONFIG_MAX_LEN;
|
||||
antConfigBramAddr = instPtr->antConfigDataPtr + instPtr->antConfigOffset;
|
||||
@@ -564,7 +605,8 @@ int32_t Phy_SetupNextSlot(PHY_INST* instPtr, PHY_TOR_TYPE txrxMode,
|
||||
instPtr->TOR.next = txrxMode;
|
||||
instPtr->frameType.next = frameType;
|
||||
|
||||
switch (txrxMode) {
|
||||
switch (txrxMode)
|
||||
{
|
||||
case PHY_TOR_SUSPEND:
|
||||
phyModeCtrl = PHY_MODE_CTRL_TOR_SUSPEND;
|
||||
break;
|
||||
@@ -577,16 +619,19 @@ int32_t Phy_SetupNextSlot(PHY_INST* instPtr, PHY_TOR_TYPE txrxMode,
|
||||
default:
|
||||
return EPARAM;
|
||||
}
|
||||
if (instPtr->isPresetHop == false) {
|
||||
if (instPtr->isPresetHop == false)
|
||||
{
|
||||
hopPattern = hopPattern_Config;
|
||||
}
|
||||
else {
|
||||
switch (frameType) {
|
||||
else
|
||||
{
|
||||
switch (frameType)
|
||||
{
|
||||
case L1_2KBPS_20MS_FRAME:
|
||||
phyModeCtrl |= PHY_MODE_CTRL_FRAME_2KBPS_20MS;
|
||||
hopNum = L1_FRAME_2KBPS_20MS_HOPS;
|
||||
// FIXME: For DUIFEI net setup.
|
||||
// hopPattern = (txrxMode == TOR_TX) ? hopPattern_2KBPS_20MS;
|
||||
// hopPattern = (txrxMode == TOR_TX) ? hopPattern_2KBPS_20MS;
|
||||
hopPattern = hopPattern_2KBPS_100MS;
|
||||
break;
|
||||
case L1_2KBPS_100MS_FRAME:
|
||||
@@ -629,28 +674,29 @@ int32_t Phy_SetupNextSlot(PHY_INST* instPtr, PHY_TOR_TYPE txrxMode,
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
PhyWrite(instPtr, PHY_MODE_CTRL, phyModeCtrl);
|
||||
|
||||
//TODO: Set antenna stand by, when suspend.
|
||||
const uint8_t* dataSrcPtr = (uint8_t*)(&(instPtr->antConfigPtr));
|
||||
for (int32_t i = 0; i < hopNum; i++) {
|
||||
// TODO: Set antenna stand by, when suspend.
|
||||
const uint8_t *dataSrcPtr = (uint8_t *)(&(instPtr->antConfigPtr));
|
||||
for (int32_t i = 0; i < hopNum; i++)
|
||||
{
|
||||
instPtr->antConfigPtr.antFreq[1] = (uint8_t)(hopPattern[i] & 0x00FF);
|
||||
instPtr->antConfigPtr.antFreq[0] = (uint8_t)((hopPattern[i] >> 8) & 0x00FF);
|
||||
instPtr->antConfigPtr.rfFreq[1] = (uint8_t)(hopPattern[i] & 0x00FF);
|
||||
instPtr->antConfigPtr.rfFreq[0] = (uint8_t)((hopPattern[i] >> 8) & 0x00FF);
|
||||
memcpy((uint8_t*) (antConfigBramAddr + i * ANT_COINFO_LENGTH),
|
||||
dataSrcPtr, sizeof(PHY_ANT_COINFO));
|
||||
memcpy((uint8_t *)(antConfigBramAddr + i * ANT_COINFO_LENGTH),
|
||||
dataSrcPtr, sizeof(PHY_ANT_COINFO));
|
||||
}
|
||||
uint32_t antCtrl = (instPtr->antConfigOffset & ANT_CONFIG_CMD_OFFSET_MASK)
|
||||
| ((hopNum << ANT_CONFIG_CMD_NUM_SHIFT) & ANT_CONFIG_CMD_NUM_MASK)
|
||||
| ((ANT_COINFO_LENGTH << ANT_CONFIG_CMD_LEN_SHIFT) & ANT_CONFIG_CMD_LEN_MASK);
|
||||
uint32_t antCtrl = (instPtr->antConfigOffset & ANT_CONFIG_CMD_OFFSET_MASK) | ((hopNum << ANT_CONFIG_CMD_NUM_SHIFT) & ANT_CONFIG_CMD_NUM_MASK) | ((ANT_COINFO_LENGTH << ANT_CONFIG_CMD_LEN_SHIFT) & ANT_CONFIG_CMD_LEN_MASK);
|
||||
PhyWrite(instPtr, ANT_CONFIG_CMD, antCtrl);
|
||||
|
||||
// FIXME: For DUIFEI network setup. Should only set send data in send slots.
|
||||
if(txrxMode == PHY_TOR_TX) {
|
||||
if (txrxMode == PHY_TOR_TX)
|
||||
{
|
||||
Status = SetSendData(instPtr, frameType, buff);
|
||||
if(Status != SUCCESS) {
|
||||
if (Status != SUCCESS)
|
||||
{
|
||||
return Status;
|
||||
}
|
||||
}
|
||||
@@ -671,8 +717,10 @@ int32_t Phy_SetupNextSlot(PHY_INST* instPtr, PHY_TOR_TYPE txrxMode,
|
||||
* FAILURE frame type cannot be recognized
|
||||
*
|
||||
******************************************************************************/
|
||||
uint32_t Phy_GetHopLength(L1_FRAME_TYPE frameType){
|
||||
switch (frameType) {
|
||||
uint32_t Phy_GetHopLength(L1_FRAME_TYPE frameType)
|
||||
{
|
||||
switch (frameType)
|
||||
{
|
||||
case L1_2KBPS_20MS_FRAME:
|
||||
return L1_FRAME_2KBPS_20MS_HOPS;
|
||||
case L1_2KBPS_100MS_FRAME:
|
||||
@@ -703,8 +751,10 @@ uint32_t Phy_GetHopLength(L1_FRAME_TYPE frameType){
|
||||
* @return 32bit unsigned integer (clock periods)
|
||||
*
|
||||
******************************************************************************/
|
||||
uint32_t Phy_GetTimeComp(L1_FRAME_TYPE frameType){
|
||||
switch (frameType) {
|
||||
uint32_t Phy_GetTimeComp(L1_FRAME_TYPE frameType)
|
||||
{
|
||||
switch (frameType)
|
||||
{
|
||||
case L1_2KBPS_20MS_FRAME:
|
||||
return L1_FRAME_2KBPS_20MS_COMP;
|
||||
case L1_2KBPS_100MS_FRAME:
|
||||
@@ -735,17 +785,18 @@ uint32_t Phy_GetTimeComp(L1_FRAME_TYPE frameType){
|
||||
* @return 32bit signed integer (Hz)
|
||||
*
|
||||
******************************************************************************/
|
||||
int32_t Phy_GetFreqEst(PHY_INST *instPtr){
|
||||
int32_t Phy_GetFreqEst(PHY_INST *instPtr)
|
||||
{
|
||||
uint32_t temp;
|
||||
int32_t acqCh, fsCh;
|
||||
double freqEst;
|
||||
temp = PhyRead(instPtr, COASE_FREQEST);
|
||||
acqCh = temp & 0x000000FF;
|
||||
acqCh = 80 - acqCh;
|
||||
fsCh = (temp>>8) & 0x000000FF;
|
||||
fsCh = fsCh -128;
|
||||
freqEst = acqCh*(31.25e3/4) + fsCh*(31.25e3/256);
|
||||
return ((int32_t) freqEst);
|
||||
fsCh = (temp >> 8) & 0x000000FF;
|
||||
fsCh = fsCh - 128;
|
||||
freqEst = acqCh * (31.25e3 / 4) + fsCh * (31.25e3 / 256);
|
||||
return ((int32_t)freqEst);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
@@ -759,12 +810,14 @@ int32_t Phy_GetFreqEst(PHY_INST *instPtr){
|
||||
* FAILURE pattern length exceeds maximum length.
|
||||
*
|
||||
******************************************************************************/
|
||||
int32_t Phy_SetHopPattern(void* patternBuff, uint32_t patternLen){
|
||||
int32_t Phy_SetHopPattern(void *patternBuff, uint32_t patternLen)
|
||||
{
|
||||
ASSERT(patternBuff != NULL);
|
||||
if(patternLen > L1_FRAME_MAX_HOPS){
|
||||
if (patternLen > L1_FRAME_MAX_HOPS)
|
||||
{
|
||||
return FAILURE;
|
||||
}
|
||||
memcpy(hopPattern_Config, patternBuff, patternLen*sizeof(uint16_t));
|
||||
memcpy(hopPattern_Config, patternBuff, patternLen * sizeof(uint16_t));
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
@@ -780,16 +833,18 @@ int32_t Phy_SetHopPattern(void* patternBuff, uint32_t patternLen){
|
||||
* FAILURE pattern length exceeds maximum length.
|
||||
*
|
||||
******************************************************************************/
|
||||
int32_t Phy_SetTimeWord(PHY_INST* instPtr, uint64_t tmWord, PHY_TIME_WORD_TYPE tmType){
|
||||
int32_t Phy_SetTimeWord(PHY_INST *instPtr, uint64_t tmWord, PHY_TIME_WORD_TYPE tmType)
|
||||
{
|
||||
ASSERT(instPtr != NULL);
|
||||
switch(tmType){
|
||||
switch (tmType)
|
||||
{
|
||||
case PHY_TIME_WORD_POLL:
|
||||
PhyWrite(instPtr, POLLTIME_L, (uint32_t)tmWord);
|
||||
PhyWrite(instPtr, POLLTIME_H, (uint32_t)(tmWord>>32));
|
||||
PhyWrite(instPtr, POLLTIME_H, (uint32_t)(tmWord >> 32));
|
||||
break;
|
||||
case PHY_TIME_WORD_LOCAL_ADJ:
|
||||
PhyWrite(instPtr, LOCALTM_ADJ_L, (uint32_t)tmWord);
|
||||
PhyWrite(instPtr, LOCALTM_ADJ_H, (uint32_t)(tmWord>>32));
|
||||
PhyWrite(instPtr, LOCALTM_ADJ_H, (uint32_t)(tmWord >> 32));
|
||||
break;
|
||||
case PHY_TIME_WORD_STEP:
|
||||
PhyWrite(instPtr, CNT_STEP_OPT, (uint32_t)tmWord);
|
||||
@@ -800,7 +855,6 @@ int32_t Phy_SetTimeWord(PHY_INST* instPtr, uint64_t tmWord, PHY_TIME_WORD_TYPE t
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* @brief Setup a specific timer word register in physical controller.
|
||||
@@ -812,7 +866,8 @@ int32_t Phy_SetTimeWord(PHY_INST* instPtr, uint64_t tmWord, PHY_TIME_WORD_TYPE t
|
||||
* FAILURE pattern length exceeds maximum length.
|
||||
*
|
||||
******************************************************************************/
|
||||
void Phy_UpdateHwSate(PHY_INST *instPtr){
|
||||
void Phy_UpdateHwSate(PHY_INST *instPtr)
|
||||
{
|
||||
ASSERT(instPtr != NULL);
|
||||
uint32_t rawData;
|
||||
|
||||
@@ -824,7 +879,7 @@ void Phy_UpdateHwSate(PHY_INST *instPtr){
|
||||
rawData = XAdcPs_GetAdcData(&(instPtr->hwXadc), XADCPS_CH_TEMP);
|
||||
instPtr->hwSate.spTemp = (uint16_t)(XAdcPs_RawToTemperature(rawData) * 100);
|
||||
|
||||
//FIXME: Chip status determine.
|
||||
// FIXME: Chip status determine.
|
||||
instPtr->hwSate.chipSt = 0;
|
||||
|
||||
/*** Voltage and Status ***/
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* Description: Physical layer control definitions and function prototypes.
|
||||
*
|
||||
*
|
||||
* Date: 2021-12-04 16:32
|
||||
* LastEditTime: 2023-04-24 17:41
|
||||
* Revisions: Rev 0.1
|
||||
* History:
|
||||
* History:
|
||||
* [2021-12-08]: Initial version.
|
||||
* [2022-06-18]: New branch for glink control purpose:
|
||||
* -Add poll mode, physical layer will start Tx/Rx procedure
|
||||
@@ -13,10 +13,10 @@
|
||||
* -Add 61/37 beam switch
|
||||
* -Code simplification.
|
||||
* [2023-04-24]: Porting for DUIFEI.
|
||||
*
|
||||
*
|
||||
* Copyright(c) 2021 Beijing Institute of Technology.
|
||||
* Lab of Communication and Networking
|
||||
*
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef PHY_CTRL_H_
|
||||
@@ -30,24 +30,25 @@
|
||||
#include "phy_reg.h"
|
||||
#include "../../system_monitor.h"
|
||||
/************************** Constant Definitions *****************************/
|
||||
#define L1_FRAME_NONE_HOPS UINT32_MAX
|
||||
#define L1_FRAME_MAX_HOPS 81
|
||||
#define L1_FRAME_2KBPS_20MS_HOPS 1
|
||||
#define L1_FRAME_2KBPS_100MS_HOPS 81
|
||||
#define L1_FRAME_10KBPS_10MS_HOPS 1
|
||||
#define L1_FRAME_10KBPS_20MS_HOPS 11
|
||||
#define L1_FRAME_40KBPS_20MS_HOPS 19
|
||||
#define L1_FRAME_40KBPS_10MS_HOPS 9
|
||||
#define L1_FRAME_200KBPS_5MS_HOPS 20
|
||||
#define L1_FRAME_1M2BPS_5MS_HOPS 20
|
||||
#define L1_FRAME_NONE_HOPS UINT32_MAX
|
||||
#define L1_FRAME_MAX_HOPS 81
|
||||
#define L1_FRAME_2KBPS_20MS_HOPS 1
|
||||
#define L1_FRAME_2KBPS_100MS_HOPS 81
|
||||
#define L1_FRAME_10KBPS_10MS_HOPS 1
|
||||
#define L1_FRAME_10KBPS_20MS_HOPS 11
|
||||
#define L1_FRAME_40KBPS_20MS_HOPS 19
|
||||
#define L1_FRAME_40KBPS_10MS_HOPS 9
|
||||
#define L1_FRAME_200KBPS_5MS_HOPS 20
|
||||
#define L1_FRAME_1M2BPS_5MS_HOPS 20
|
||||
|
||||
#define L1_NUM_ANT_SUBNRRW_PATTERN 37
|
||||
#define L1_NUM_ANT_NRRW_PATTERN 61
|
||||
#define L1_NUM_ANT_SUBNRRW_PATTERN 37
|
||||
#define L1_NUM_ANT_NRRW_PATTERN 61
|
||||
|
||||
#define ANT_COINFO_LENGTH 32 //bytes
|
||||
#define ANT_COINFO_LENGTH 32 // bytes
|
||||
/***************** Macros (Inline Functions) Definitions *********************/
|
||||
/**************************** Type Definitions *******************************/
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
L1_NONE_FRAME = 0,
|
||||
L1_2KBPS_20MS_FRAME = 1,
|
||||
L1_2KBPS_100MS_FRAME = 2,
|
||||
@@ -59,7 +60,8 @@ typedef enum {
|
||||
L1_1M2BPS_5MS_FRAME = 8
|
||||
} L1_FRAME_TYPE;
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
/*** Ant Control ***/
|
||||
/* Antenna control frame head 0xAA */
|
||||
/* default 0, reserved for further use */
|
||||
@@ -113,8 +115,8 @@ typedef struct {
|
||||
uint8_t rfReserved1;
|
||||
} PHY_ANT_COINFO;
|
||||
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
/* off-axis angle range is 0~60,
|
||||
* 0.1 degree each LSB */
|
||||
uint16_t oaxis;
|
||||
@@ -123,15 +125,16 @@ typedef struct {
|
||||
uint16_t raxis;
|
||||
} PHY_ANT_ANGLE;
|
||||
|
||||
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
PHY_TIME_WORD_NONE = 0,
|
||||
PHY_TIME_WORD_POLL = 1,
|
||||
PHY_TIME_WORD_LOCAL_ADJ = 2,
|
||||
PHY_TIME_WORD_STEP = 3,
|
||||
} PHY_TIME_WORD_TYPE;
|
||||
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
PHY_ANT_BEAM_NONE = 0,
|
||||
PHY_ANT_BEAM_120 = 1,
|
||||
PHY_ANT_BEAM_60 = 2,
|
||||
@@ -139,20 +142,23 @@ typedef enum {
|
||||
PHY_ANT_BEAM_8 = 4
|
||||
} PHY_ANT_BEAM_WIDTH;
|
||||
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
PHY_TOR_SUSPEND = 0,
|
||||
PHY_TOR_TX = 1,
|
||||
PHY_TOR_RX = 2
|
||||
} PHY_TOR_TYPE;
|
||||
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
PHY_MODE_NONE = 0,
|
||||
PHY_MODE_LISTEN = 1,
|
||||
PHY_MODE_SCHEDULE = 2,
|
||||
PHY_MODE_PULL = 3
|
||||
} PHY_MODE;
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
uint32_t devId;
|
||||
uint32_t txBramId;
|
||||
uint32_t rxBramId;
|
||||
@@ -161,27 +167,29 @@ typedef struct {
|
||||
uint32_t baseAddr;
|
||||
} PHY_CONFIG;
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
int32_t last;
|
||||
int32_t curr;
|
||||
int32_t next;
|
||||
} PHY_RCD;
|
||||
|
||||
typedef struct {
|
||||
PHY_CONFIG phyCofig; // Device address configs
|
||||
bool isPhyEn; // is physical instance enable
|
||||
bool isAcq; // is last reception acquisition success
|
||||
bool isFrameSync; // is last reception frame sync success
|
||||
bool isDecode; // is last reception decode success
|
||||
bool isValid; // is last reception frame data valid (crc check pass)
|
||||
bool isPresetHop; // is using preset frequency hop
|
||||
PHY_RCD antNo; // antenna number record
|
||||
PHY_RCD beamNo; // beam number record
|
||||
PHY_RCD beamWd; // beam width record
|
||||
PHY_RCD TOR; // tx rx state record
|
||||
PHY_RCD frameType; // frame type record
|
||||
uint32_t antConfigOffset; // antenna configuration bram offset (to implement ping-pong data flow)
|
||||
uint32_t sendOffset; // antenna configuration bram offset (to implement ping-pong data flow)
|
||||
typedef struct
|
||||
{
|
||||
PHY_CONFIG phyCofig; // Device address configs
|
||||
bool isPhyEn; // is physical instance enable
|
||||
bool isAcq; // is last reception acquisition success
|
||||
bool isFrameSync; // is last reception frame sync success
|
||||
bool isDecode; // is last reception decode success
|
||||
bool isValid; // is last reception frame data valid (crc check pass)
|
||||
bool isPresetHop; // is using preset frequency hop
|
||||
PHY_RCD antNo; // antenna number record
|
||||
PHY_RCD beamNo; // beam number record
|
||||
PHY_RCD beamWd; // beam width record
|
||||
PHY_RCD TOR; // tx rx state record
|
||||
PHY_RCD frameType; // frame type record
|
||||
uint32_t antConfigOffset; // antenna configuration bram offset (to implement ping-pong data flow)
|
||||
uint32_t sendOffset; // antenna configuration bram offset (to implement ping-pong data flow)
|
||||
PHY_ANT_COINFO antConfigPtr; // antenna configuration pointer
|
||||
uintptr_t txDataPtr;
|
||||
uintptr_t rxDataPtr;
|
||||
@@ -213,15 +221,15 @@ void Phy_Start(PHY_INST *instPtr);
|
||||
void Phy_Halt(PHY_INST *instPtr);
|
||||
int32_t Phy_SetMode(PHY_INST *instPtr, PHY_MODE modeCod);
|
||||
|
||||
int32_t Phy_SetupNextSlot(PHY_INST *instPtr, PHY_TOR_TYPE txrxMode, L1_FRAME_TYPE frameType, uint8_t* buff);
|
||||
int32_t Phy_RetrieveRecvData(PHY_INST* instPtr, uint8_t* buff);
|
||||
int32_t Phy_SetupNextSlot(PHY_INST *instPtr, PHY_TOR_TYPE txrxMode, L1_FRAME_TYPE frameType, uint8_t *buff);
|
||||
int32_t Phy_RetrieveRecvData(PHY_INST *instPtr, uint8_t *buff);
|
||||
|
||||
bool Phy_IsFrameDetected(PHY_INST *instPtr);
|
||||
bool Phy_IsFrameReceived(PHY_INST *instPtr);
|
||||
bool Phy_IsFrameValid(PHY_INST *instPtr);
|
||||
uint32_t Phy_GetFrameLen(L1_FRAME_TYPE frameType);
|
||||
|
||||
L1_FRAME_TYPE Phy_GetLastDetectedFrameType(PHY_INST* instPtr);
|
||||
L1_FRAME_TYPE Phy_GetLastDetectedFrameType(PHY_INST *instPtr);
|
||||
L1_FRAME_TYPE Phy_GetLastReceivedFrameType(PHY_INST *instPtr);
|
||||
L1_FRAME_TYPE Phy_GetLastSentFrameType(PHY_INST *instPtr);
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
* -Add poll modephysical layer will start Tx/Rx procedure
|
||||
* at specific time stamp.
|
||||
* [2023-04-24]: Porting for DUIFEI.
|
||||
*
|
||||
*
|
||||
* Copyright(c) 2021 Beijing Institute of Technology.
|
||||
* Lab of Communication and Networking
|
||||
*
|
||||
@@ -28,311 +28,307 @@
|
||||
/***************** Macros (Inline Functions) Definitions *********************/
|
||||
|
||||
// Read Physical Layer register (0x00000000~0x000000FF)
|
||||
#define PhyRead(instPtr, addr) IO_In32(instPtr->phyCofig.baseAddr + addr)
|
||||
#define PhyRead(instPtr, addr) IO_In32(instPtr->phyCofig.baseAddr + addr)
|
||||
// Write Physical Layer register (0x000000100~0x00000200)
|
||||
#define PhyWrite(instPtr, addr, value) IO_Out32(instPtr->phyCofig.baseAddr + addr, value)
|
||||
#define PhyWrite(instPtr, addr, value) IO_Out32(instPtr->phyCofig.baseAddr + addr, value)
|
||||
|
||||
/************************** Constant Definitions *****************************/
|
||||
/************************* Ps2Pl Regs PS Write Only ***************************/
|
||||
/**
|
||||
* Register: PHY_MAIN_CTRL
|
||||
*/
|
||||
#define PHY_MAIN_CTRL 0X00000000U
|
||||
#define PHY_MAIN_CTRL_EN_SHIFT 0
|
||||
#define PHY_MAIN_CTRL_EN_WIDTH 1
|
||||
#define PHY_MAIN_CTRL_EN_MASK 0x00000001U
|
||||
#define PHY_MAIN_CTRL_MODE_SHIFT 8
|
||||
#define PHY_MAIN_CTRL_MODE_WIDTH 8
|
||||
#define PHY_MAIN_CTRL_MODE_MASK 0x0000FF00U
|
||||
#define PHY_MAIN_CTRL 0X00000000U
|
||||
#define PHY_MAIN_CTRL_EN_SHIFT 0
|
||||
#define PHY_MAIN_CTRL_EN_WIDTH 1
|
||||
#define PHY_MAIN_CTRL_EN_MASK 0x00000001U
|
||||
#define PHY_MAIN_CTRL_MODE_SHIFT 8
|
||||
#define PHY_MAIN_CTRL_MODE_WIDTH 8
|
||||
#define PHY_MAIN_CTRL_MODE_MASK 0x0000FF00U
|
||||
|
||||
#define PHY_MAIN_CTRL_EN_EN 0x00000001U
|
||||
#define PHY_MAIN_CTRL_EN_DSBL 0x00000000U
|
||||
#define PHY_MAIN_CTRL_MODE_NONE 0x00000000U
|
||||
#define PHY_MAIN_CTRL_MODE_LISTEN 0x00000100U
|
||||
#define PHY_MAIN_CTRL_MODE_SCHEDULE 0x00000200U
|
||||
#define PHY_MAIN_CTRL_MODE_PULL 0x00000300U
|
||||
#define PHY_MAIN_CTRL_EN_EN 0x00000001U
|
||||
#define PHY_MAIN_CTRL_EN_DSBL 0x00000000U
|
||||
#define PHY_MAIN_CTRL_MODE_NONE 0x00000000U
|
||||
#define PHY_MAIN_CTRL_MODE_LISTEN 0x00000100U
|
||||
#define PHY_MAIN_CTRL_MODE_SCHEDULE 0x00000200U
|
||||
#define PHY_MAIN_CTRL_MODE_PULL 0x00000300U
|
||||
|
||||
/**
|
||||
* Register: TXRX_CTRL
|
||||
*/
|
||||
#define PHY_MODE_CTRL 0x00000004U
|
||||
#define PHY_MODE_CTRL_TOR_SHIFT 0
|
||||
#define PHY_MODE_CTRL_TOR_WIDTH 2
|
||||
#define PHY_MODE_CTRL_TOR_MASK 0x00000003U
|
||||
#define PHY_MODE_CTRL_FRAME_SHIFT 16
|
||||
#define PHY_MODE_CTRL_FRAME_WIDTH 8
|
||||
#define PHY_MODE_CTRL_FRAME_MASK 0x00FF0000U
|
||||
#define PHY_MODE_CTRL 0x00000004U
|
||||
#define PHY_MODE_CTRL_TOR_SHIFT 0
|
||||
#define PHY_MODE_CTRL_TOR_WIDTH 2
|
||||
#define PHY_MODE_CTRL_TOR_MASK 0x00000003U
|
||||
#define PHY_MODE_CTRL_FRAME_SHIFT 16
|
||||
#define PHY_MODE_CTRL_FRAME_WIDTH 8
|
||||
#define PHY_MODE_CTRL_FRAME_MASK 0x00FF0000U
|
||||
|
||||
#define PHY_MODE_CTRL_TOR_SUSPEND 0x00000000U
|
||||
#define PHY_MODE_CTRL_TOR_TX 0x00000001U
|
||||
#define PHY_MODE_CTRL_TOR_RX 0x00000002U
|
||||
#define PHY_MODE_CTRL_TOR_SUSPEND 0x00000000U
|
||||
#define PHY_MODE_CTRL_TOR_TX 0x00000001U
|
||||
#define PHY_MODE_CTRL_TOR_RX 0x00000002U
|
||||
|
||||
#define PHY_MODE_CTRL_FRAME_NONE 0x00000000U
|
||||
#define PHY_MODE_CTRL_FRAME_2KBPS_20MS 0x00000100U
|
||||
#define PHY_MODE_CTRL_FRAME_2KBPS_100MS 0x00000200U
|
||||
#define PHY_MODE_CTRL_FRAME_10KBPS_10MS 0x00000300U // Initial Scan Frame
|
||||
#define PHY_MODE_CTRL_FRAME_10KBPS_20MS 0x00000400U // Benchmark Frame
|
||||
#define PHY_MODE_CTRL_FRAME_40KBPS_20MS 0x00000500U
|
||||
#define PHY_MODE_CTRL_FRAME_40KBPS_10MS 0x00000600U
|
||||
#define PHY_MODE_CTRL_FRAME_200KBPS_5MS 0x00000700U // 2-Way ACQ Frame, Management Frame, Service Frame
|
||||
#define PHY_MODE_CTRL_FRAME_1M2BPS_5MS 0x00000800U // Bistatic Synthetic Aperture Radar Frame
|
||||
#define PHY_MODE_CTRL_FRAME_NONE 0x00000000U
|
||||
#define PHY_MODE_CTRL_FRAME_2KBPS_20MS 0x00000100U
|
||||
#define PHY_MODE_CTRL_FRAME_2KBPS_100MS 0x00000200U
|
||||
#define PHY_MODE_CTRL_FRAME_10KBPS_10MS 0x00000300U // Initial Scan Frame
|
||||
#define PHY_MODE_CTRL_FRAME_10KBPS_20MS 0x00000400U // Benchmark Frame
|
||||
#define PHY_MODE_CTRL_FRAME_40KBPS_20MS 0x00000500U
|
||||
#define PHY_MODE_CTRL_FRAME_40KBPS_10MS 0x00000600U
|
||||
#define PHY_MODE_CTRL_FRAME_200KBPS_5MS 0x00000700U // 2-Way ACQ Frame, Management Frame, Service Frame
|
||||
#define PHY_MODE_CTRL_FRAME_1M2BPS_5MS 0x00000800U // Bistatic Synthetic Aperture Radar Frame
|
||||
|
||||
/**
|
||||
* Register: POLLTIME_L
|
||||
*/
|
||||
#define POLLTIME_L 0x00000008U
|
||||
#define POLLTIME_L_SHIFT 0
|
||||
#define POLLTIME_L_WIDTH 32
|
||||
#define POLLTIME_L_MASK 0xFFFFFFFFU
|
||||
#define POLLTIME_L 0x00000008U
|
||||
#define POLLTIME_L_SHIFT 0
|
||||
#define POLLTIME_L_WIDTH 32
|
||||
#define POLLTIME_L_MASK 0xFFFFFFFFU
|
||||
|
||||
/**
|
||||
* Register: POLLTIME_H
|
||||
*/
|
||||
#define POLLTIME_H 0x0000000CU
|
||||
#define POLLTIME_H_SHIFT 0
|
||||
#define POLLTIME_H_WIDTH 32
|
||||
#define POLLTIME_H_MASK 0xFFFFFFFFU
|
||||
#define POLLTIME_H 0x0000000CU
|
||||
#define POLLTIME_H_SHIFT 0
|
||||
#define POLLTIME_H_WIDTH 32
|
||||
#define POLLTIME_H_MASK 0xFFFFFFFFU
|
||||
|
||||
/**
|
||||
* Register: TM_ADJ_MODE
|
||||
*/
|
||||
#define TM_ADJ_MODE 0x00000010U
|
||||
#define TM_ADJ_MODE_SHIFT 0
|
||||
#define TM_ADJ_MODE_WIDTH 8
|
||||
#define TM_ADJ_MODE_MASK 0x000000FFU
|
||||
#define TM_ADJ_MODE_NONE 0x00000000U
|
||||
#define TM_ADJ_MODE_ADD 0x00000001U
|
||||
#define TM_ADJ_MODE_SET 0x00000002U
|
||||
#define TM_ADJ_MODE 0x00000010U
|
||||
#define TM_ADJ_MODE_SHIFT 0
|
||||
#define TM_ADJ_MODE_WIDTH 8
|
||||
#define TM_ADJ_MODE_MASK 0x000000FFU
|
||||
#define TM_ADJ_MODE_NONE 0x00000000U
|
||||
#define TM_ADJ_MODE_ADD 0x00000001U
|
||||
#define TM_ADJ_MODE_SET 0x00000002U
|
||||
|
||||
#define TM_ADJ_MODE_LOCAL_SHIFT 8
|
||||
#define TM_ADJ_MODE_LOCAL_WIDTH 8
|
||||
#define TM_ADJ_MODE_LOCAL_MASK 0x0000FF00U
|
||||
#define TM_ADJ_MODE_LOCAL_NONE 0x00000000U
|
||||
#define TM_ADJ_MODE_LOCAL_ADD 0x00000100U
|
||||
#define TM_ADJ_MODE_LOCAL_SET 0x00000200U
|
||||
#define TM_ADJ_MODE_LOCAL_SHIFT 8
|
||||
#define TM_ADJ_MODE_LOCAL_WIDTH 8
|
||||
#define TM_ADJ_MODE_LOCAL_MASK 0x0000FF00U
|
||||
#define TM_ADJ_MODE_LOCAL_NONE 0x00000000U
|
||||
#define TM_ADJ_MODE_LOCAL_ADD 0x00000100U
|
||||
#define TM_ADJ_MODE_LOCAL_SET 0x00000200U
|
||||
|
||||
/**
|
||||
* Register: LOCALTM_ADJ_L
|
||||
*/
|
||||
#define LOCALTM_ADJ_L 0x00000014U
|
||||
#define LOCALTM_ADJ_L_SHIFT 0
|
||||
#define LOCALTM_ADJ_L_WIDTH 32
|
||||
#define LOCALTM_ADJ_L_MASK 0xFFFFFFFFU
|
||||
#define LOCALTM_ADJ_L 0x00000014U
|
||||
#define LOCALTM_ADJ_L_SHIFT 0
|
||||
#define LOCALTM_ADJ_L_WIDTH 32
|
||||
#define LOCALTM_ADJ_L_MASK 0xFFFFFFFFU
|
||||
|
||||
/**
|
||||
* Register: LOCALTM_ADJ_H
|
||||
*/
|
||||
#define LOCALTM_ADJ_H 0x00000018U
|
||||
#define LOCALTM_ADJ_H_SHIFT 0
|
||||
#define LOCALTM_ADJ_H_WIDTH 32
|
||||
#define LOCALTM_ADJ_H_MASK 0xFFFFFFFFU
|
||||
#define LOCALTM_ADJ_H 0x00000018U
|
||||
#define LOCALTM_ADJ_H_SHIFT 0
|
||||
#define LOCALTM_ADJ_H_WIDTH 32
|
||||
#define LOCALTM_ADJ_H_MASK 0xFFFFFFFFU
|
||||
|
||||
/**
|
||||
* Register: CNT_STEP_TOPT
|
||||
*/
|
||||
#define CNT_STEP_OPT 0x0000001CU
|
||||
#define CNT_STEP_OPT_SHIFT 0
|
||||
#define CNT_STEP_OPT_WIDTH 32
|
||||
#define CNT_STEP_OPT_MASK 0xFFFFFFFFU
|
||||
#define CNT_STEP_OPT 0x0000001CU
|
||||
#define CNT_STEP_OPT_SHIFT 0
|
||||
#define CNT_STEP_OPT_WIDTH 32
|
||||
#define CNT_STEP_OPT_MASK 0xFFFFFFFFU
|
||||
|
||||
/**
|
||||
* Register: SEND_DATA_CMD
|
||||
*/
|
||||
#define SEND_DATA_CMD 0x00000020U
|
||||
#define SEND_DATA_CMD_LEN_SHIFT 0
|
||||
#define SEND_DATA_CMD_LEN_WIDTH 16
|
||||
#define SEND_DATA_CMD_LEN_MASK 0x0000FFFFU
|
||||
#define SEND_DATA_CMD_OFFSET_SHIFT 16
|
||||
#define SEND_DATA_CMD_OFFSET_WIDTH 16
|
||||
#define SEND_DATA_CMD_OFFSET_MASK 0xFFFF0000U
|
||||
#define SEND_DATA_CMD 0x00000020U
|
||||
#define SEND_DATA_CMD_LEN_SHIFT 0
|
||||
#define SEND_DATA_CMD_LEN_WIDTH 16
|
||||
#define SEND_DATA_CMD_LEN_MASK 0x0000FFFFU
|
||||
#define SEND_DATA_CMD_OFFSET_SHIFT 16
|
||||
#define SEND_DATA_CMD_OFFSET_WIDTH 16
|
||||
#define SEND_DATA_CMD_OFFSET_MASK 0xFFFF0000U
|
||||
|
||||
/**
|
||||
* Register: ANT_CONFIG_CMD
|
||||
*/
|
||||
#define ANT_CONFIG_CMD 0x00000024U
|
||||
#define ANT_CONFIG_CMD_OFFSET_SHIFT 0
|
||||
#define ANT_CONFIG_CMD_OFFSET_WIDTH 16
|
||||
#define ANT_CONFIG_CMD_OFFSET_MASK 0x0000FFFFU
|
||||
#define ANT_CONFIG_CMD_LEN_SHIFT 16
|
||||
#define ANT_CONFIG_CMD_LEN_WIDTH 8
|
||||
#define ANT_CONFIG_CMD_LEN_MASK 0x00FF0000U
|
||||
#define ANT_CONFIG_CMD_NUM_SHIFT 24
|
||||
#define ANT_CONFIG_CMD_NUM_WIDTH 8
|
||||
#define ANT_CONFIG_CMD_NUM_MASK 0xFF000000U
|
||||
#define ANT_CONFIG_CMD 0x00000024U
|
||||
#define ANT_CONFIG_CMD_OFFSET_SHIFT 0
|
||||
#define ANT_CONFIG_CMD_OFFSET_WIDTH 16
|
||||
#define ANT_CONFIG_CMD_OFFSET_MASK 0x0000FFFFU
|
||||
#define ANT_CONFIG_CMD_LEN_SHIFT 16
|
||||
#define ANT_CONFIG_CMD_LEN_WIDTH 8
|
||||
#define ANT_CONFIG_CMD_LEN_MASK 0x00FF0000U
|
||||
#define ANT_CONFIG_CMD_NUM_SHIFT 24
|
||||
#define ANT_CONFIG_CMD_NUM_WIDTH 8
|
||||
#define ANT_CONFIG_CMD_NUM_MASK 0xFF000000U
|
||||
|
||||
/**
|
||||
* Register: SLOT_CONFIG_CMD
|
||||
*/
|
||||
#define SLOT_CONFIG_CMD 0x00000028U
|
||||
#define SLOT_CONFIG_CMD_SHIFT 0
|
||||
#define SLOT_CONFIG_CMD_WIDTH 32
|
||||
#define SLOT_CONFIG_CMD_MASK 0xFFFFFFFFU
|
||||
#define SLOT_CONFIG_CMD_VAULE 0x4846414E
|
||||
#define SLOT_CONFIG_CMD 0x00000028U
|
||||
#define SLOT_CONFIG_CMD_SHIFT 0
|
||||
#define SLOT_CONFIG_CMD_WIDTH 32
|
||||
#define SLOT_CONFIG_CMD_MASK 0xFFFFFFFFU
|
||||
#define SLOT_CONFIG_CMD_VAULE 0x4846414E
|
||||
|
||||
/************************* Ps2Pl Regs PS Read Only ***************************/
|
||||
/**
|
||||
* Register: TXRX_STATE
|
||||
*/
|
||||
#define TXRX_STATE 0x00000100U
|
||||
#define TXRX_STATE_ACQ_SHIFT 0
|
||||
#define TXRX_STATE_ACQ_WIDTH 8
|
||||
#define TXRX_STATE_ACQ_MASK 0x000000FFU
|
||||
#define TXRX_STATE_ACQ_SUCCESS 0x00000001U
|
||||
#define TXRX_STATE_ACQ_FAIL 0x00000002U
|
||||
#define TXRX_STATE 0x00000100U
|
||||
#define TXRX_STATE_ACQ_SHIFT 0
|
||||
#define TXRX_STATE_ACQ_WIDTH 8
|
||||
#define TXRX_STATE_ACQ_MASK 0x000000FFU
|
||||
#define TXRX_STATE_ACQ_SUCCESS 0x00000001U
|
||||
#define TXRX_STATE_ACQ_FAIL 0x00000002U
|
||||
|
||||
#define TXRX_STATE_FSYNC_SHIFT 8
|
||||
#define TXRX_STATE_FSYNC_WIDTH 8
|
||||
#define TXRX_STATE_FSYNC_MASK 0x0000FF00U
|
||||
#define TXRX_STATE_FSYNC_SUCCESS 0x00000100U
|
||||
#define TXRX_STATE_FSYNC_FAIL 0x00000200U
|
||||
#define TXRX_STATE_FSYNC_SHIFT 8
|
||||
#define TXRX_STATE_FSYNC_WIDTH 8
|
||||
#define TXRX_STATE_FSYNC_MASK 0x0000FF00U
|
||||
#define TXRX_STATE_FSYNC_SUCCESS 0x00000100U
|
||||
#define TXRX_STATE_FSYNC_FAIL 0x00000200U
|
||||
|
||||
#define TXRX_STATE_DECODE_SHIFT 16
|
||||
#define TXRX_STATE_DECODE_WIDTH 8
|
||||
#define TXRX_STATE_DECODE_MASK 0x00FF0000U
|
||||
#define TXRX_STATE_DECODE_SUCCESS 0x00010000U
|
||||
#define TXRX_STATE_DECODE_FAIL 0x00020000U
|
||||
#define TXRX_STATE_DECODE_SHIFT 16
|
||||
#define TXRX_STATE_DECODE_WIDTH 8
|
||||
#define TXRX_STATE_DECODE_MASK 0x00FF0000U
|
||||
#define TXRX_STATE_DECODE_SUCCESS 0x00010000U
|
||||
#define TXRX_STATE_DECODE_FAIL 0x00020000U
|
||||
|
||||
/**
|
||||
* Register: RECV_SATE
|
||||
*/
|
||||
#define RECV_DATA_SATE 0x00000104U
|
||||
#define RECV_DATA_LEN_SHIFT 0
|
||||
#define RECV_DATA_LEN_WIDTH 16
|
||||
#define RECV_DATA_LEN_MASK 0x0000FFFFU
|
||||
#define RECV_DATA_OFFSET_SHIFT 16
|
||||
#define RECV_DATA_OFFSET_WIDTH 16
|
||||
#define RECV_DATA_OFFSET_MASK 0xFFFFF0000U
|
||||
|
||||
#define RECV_DATA_SATE 0x00000104U
|
||||
#define RECV_DATA_LEN_SHIFT 0
|
||||
#define RECV_DATA_LEN_WIDTH 16
|
||||
#define RECV_DATA_LEN_MASK 0x0000FFFFU
|
||||
#define RECV_DATA_OFFSET_SHIFT 16
|
||||
#define RECV_DATA_OFFSET_WIDTH 16
|
||||
#define RECV_DATA_OFFSET_MASK 0xFFFFF0000U
|
||||
|
||||
/**
|
||||
* Register: FSTIME_L
|
||||
*/
|
||||
#define FSTIME_L 0x00000108U
|
||||
#define FSTIME_L_SHIFT 0
|
||||
#define FSTIME_L_WIDTH 32
|
||||
#define FSTIME_L_MASK 0xFFFFFFFFU
|
||||
#define FSTIME_L 0x00000108U
|
||||
#define FSTIME_L_SHIFT 0
|
||||
#define FSTIME_L_WIDTH 32
|
||||
#define FSTIME_L_MASK 0xFFFFFFFFU
|
||||
|
||||
/**
|
||||
* Register: FSTIME_INT1
|
||||
*/
|
||||
#define FSTIME_H 0x0000010CU
|
||||
#define FSTIME_H_SHIFT 0
|
||||
#define FSTIME_H_WIDTH 32
|
||||
#define FSTIME_H_MASK 0xFFFFFFFFU
|
||||
#define FSTIME_H 0x0000010CU
|
||||
#define FSTIME_H_SHIFT 0
|
||||
#define FSTIME_H_WIDTH 32
|
||||
#define FSTIME_H_MASK 0xFFFFFFFFU
|
||||
|
||||
/**
|
||||
* Register: TM_TARGET_L
|
||||
*/
|
||||
#define TM_TARGET_L 0x00000110U
|
||||
#define TM_TARGET_L_SHIFT 0
|
||||
#define TM_TARGET_L_WIDTH 32
|
||||
#define TM_TARGET_L_MASK 0xFFFFFFFFU
|
||||
#define TM_TARGET_L 0x00000110U
|
||||
#define TM_TARGET_L_SHIFT 0
|
||||
#define TM_TARGET_L_WIDTH 32
|
||||
#define TM_TARGET_L_MASK 0xFFFFFFFFU
|
||||
|
||||
/**
|
||||
* Register: TM_TARGET_H
|
||||
*/
|
||||
#define TM_TARGET_H 0x00000114U
|
||||
#define TM_TARGET_H_SHIFT 0
|
||||
#define TM_TARGET_H_WIDTH 32
|
||||
#define TM_TARGET_H_MASK 0xFFFFFFFFU
|
||||
#define TM_TARGET_H 0x00000114U
|
||||
#define TM_TARGET_H_SHIFT 0
|
||||
#define TM_TARGET_H_WIDTH 32
|
||||
#define TM_TARGET_H_MASK 0xFFFFFFFFU
|
||||
|
||||
/**
|
||||
* Register: LOCALTM_L
|
||||
*/
|
||||
#define TM_LOCAL_L 0x00000118U
|
||||
#define TM_LOCAL_L_SHIFT 0
|
||||
#define TM_LOCAL_L_WIDTH 32
|
||||
#define TM_LOCAL_L_MASK 0xFFFFFFFFU
|
||||
#define TM_LOCAL_L 0x00000118U
|
||||
#define TM_LOCAL_L_SHIFT 0
|
||||
#define TM_LOCAL_L_WIDTH 32
|
||||
#define TM_LOCAL_L_MASK 0xFFFFFFFFU
|
||||
|
||||
/**
|
||||
* Register: LOCALTM_H
|
||||
*/
|
||||
#define TM_LOCAL_H 0x0000011CU
|
||||
#define TM_LOCAL_H_SHIFT 0
|
||||
#define TM_LOCAL_H_WIDTH 32
|
||||
#define TM_LOCAL_H_MASK 0xFFFFFFFFU
|
||||
#define TM_LOCAL_H 0x0000011CU
|
||||
#define TM_LOCAL_H_SHIFT 0
|
||||
#define TM_LOCAL_H_WIDTH 32
|
||||
#define TM_LOCAL_H_MASK 0xFFFFFFFFU
|
||||
|
||||
/**
|
||||
* Register: COASEFREQEST
|
||||
*/
|
||||
#define COASE_FREQEST 0x00000120U
|
||||
#define COASE_FREQEST_SHIFT 0
|
||||
#define COASE_FREQEST_WIDTH 32
|
||||
#define COASE_FREQEST_MASK 0xFFFFFFFFU
|
||||
#define COASE_FREQEST 0x00000120U
|
||||
#define COASE_FREQEST_SHIFT 0
|
||||
#define COASE_FREQEST_WIDTH 32
|
||||
#define COASE_FREQEST_MASK 0xFFFFFFFFU
|
||||
|
||||
/**
|
||||
* Register: INTR_TYPE
|
||||
*/
|
||||
#define INTR_TYPE 0x00000124U
|
||||
|
||||
#define INTR_TYPE 0x00000124U
|
||||
|
||||
/**
|
||||
* Register: ANT_STATUS_0
|
||||
*/
|
||||
#define ANT_STATUS 0x00000128U
|
||||
#define ANT_STATUS_CODE_SHIFT 0
|
||||
#define ANT_STATUS_CODE_WIDTH 8
|
||||
#define ANT_STATUS_CODE_MASK 0x000000FFU
|
||||
#define ANT_STATUS_NIL_VOLT_SHIFT 8
|
||||
#define ANT_STATUS_NIL_VOLT_WIDTH 8
|
||||
#define ANT_STATUS_NIL_VOLT_MASK 0x0000FF00U
|
||||
#define ANT_STATUS_RF_VOLT_SHIFT 16
|
||||
#define ANT_STATUS_RF_VOLT_WIDTH 8
|
||||
#define ANT_STATUS_RF_VOLT_MASK 0x00FF0000U
|
||||
#define ANT_STATUS_ANT_VOLT_SHIFT 24
|
||||
#define ANT_STATUS_ANT_VOLT_WIDTH 8
|
||||
#define ANT_STATUS_ANT_VOLT_MASK 0xFF000000U
|
||||
|
||||
#define ANT_STATUS 0x00000128U
|
||||
#define ANT_STATUS_CODE_SHIFT 0
|
||||
#define ANT_STATUS_CODE_WIDTH 8
|
||||
#define ANT_STATUS_CODE_MASK 0x000000FFU
|
||||
#define ANT_STATUS_NIL_VOLT_SHIFT 8
|
||||
#define ANT_STATUS_NIL_VOLT_WIDTH 8
|
||||
#define ANT_STATUS_NIL_VOLT_MASK 0x0000FF00U
|
||||
#define ANT_STATUS_RF_VOLT_SHIFT 16
|
||||
#define ANT_STATUS_RF_VOLT_WIDTH 8
|
||||
#define ANT_STATUS_RF_VOLT_MASK 0x00FF0000U
|
||||
#define ANT_STATUS_ANT_VOLT_SHIFT 24
|
||||
#define ANT_STATUS_ANT_VOLT_WIDTH 8
|
||||
#define ANT_STATUS_ANT_VOLT_MASK 0xFF000000U
|
||||
|
||||
/**
|
||||
* Register: ANT_FRAME_CNT
|
||||
*/
|
||||
#define ANT_FRAME_CNT 0x0000012CU
|
||||
#define ANT_FRAME_CNT_SHIFT 0
|
||||
#define ANT_FRAME_CNT_WIDTH 32
|
||||
#define ANT_FRAME_CNT_MASK 0xFFFFFFFFU
|
||||
#define ANT_FRAME_CNT 0x0000012CU
|
||||
#define ANT_FRAME_CNT_SHIFT 0
|
||||
#define ANT_FRAME_CNT_WIDTH 32
|
||||
#define ANT_FRAME_CNT_MASK 0xFFFFFFFFU
|
||||
|
||||
/**
|
||||
* Register: RF_STATUS
|
||||
*/
|
||||
#define RF_STATUS 0x00000130U
|
||||
#define RF_STATUS_TEMP_SHIFT 0
|
||||
#define RF_STATUS_TEMP_WIDTH 8
|
||||
#define RF_STATUS_TEMP_MASK 0x000000FFU
|
||||
#define RF_STATUS_BDLOCK_SHIFT 8
|
||||
#define RF_STATUS_BDLOCK_WIDTH 8
|
||||
#define RF_STATUS_BDLOCK_MASK 0x0000FF00U
|
||||
#define RF_STATUS_PLLA_SHIFT 16
|
||||
#define RF_STATUS_PLLA_WIDTH 8
|
||||
#define RF_STATUS_PLLA_MASK 0x00FF0000U
|
||||
#define RF_STATUS_PLLB_SHIFT 24
|
||||
#define RF_STATUS_PLLB_WIDTH 8
|
||||
#define RF_STATUS_PLLB_MASK 0xFF000000U
|
||||
#define RF_STATUS 0x00000130U
|
||||
#define RF_STATUS_TEMP_SHIFT 0
|
||||
#define RF_STATUS_TEMP_WIDTH 8
|
||||
#define RF_STATUS_TEMP_MASK 0x000000FFU
|
||||
#define RF_STATUS_BDLOCK_SHIFT 8
|
||||
#define RF_STATUS_BDLOCK_WIDTH 8
|
||||
#define RF_STATUS_BDLOCK_MASK 0x0000FF00U
|
||||
#define RF_STATUS_PLLA_SHIFT 16
|
||||
#define RF_STATUS_PLLA_WIDTH 8
|
||||
#define RF_STATUS_PLLA_MASK 0x00FF0000U
|
||||
#define RF_STATUS_PLLB_SHIFT 24
|
||||
#define RF_STATUS_PLLB_WIDTH 8
|
||||
#define RF_STATUS_PLLB_MASK 0xFF000000U
|
||||
|
||||
/**
|
||||
* Register: RF_MGC
|
||||
*/
|
||||
#define RF_MGC 0x00000134U
|
||||
#define RF_MGC_CH1_SHIFT 0
|
||||
#define RF_MGC_CH1_WIDTH 4
|
||||
#define RF_MGC_CH1_MASK 0x0000000FU
|
||||
#define RF_MGC_CH2_SHIFT 8
|
||||
#define RF_MGC_CH2_WIDTH 4
|
||||
#define RF_MGC_CH2_MASK 0x00000F00U
|
||||
#define RF_MGC_CH3_SHIFT 16
|
||||
#define RF_MGC_CH3_WIDTH 4
|
||||
#define RF_MGC_CH3_MASK 0x000F0000U
|
||||
#define RF_MGC_CH4_SHIFT 24
|
||||
#define RF_MGC_CH4_WIDTH 4
|
||||
#define RF_MGC_CH4_MASK 0x0F000000U
|
||||
|
||||
#define RF_MGC 0x00000134U
|
||||
#define RF_MGC_CH1_SHIFT 0
|
||||
#define RF_MGC_CH1_WIDTH 4
|
||||
#define RF_MGC_CH1_MASK 0x0000000FU
|
||||
#define RF_MGC_CH2_SHIFT 8
|
||||
#define RF_MGC_CH2_WIDTH 4
|
||||
#define RF_MGC_CH2_MASK 0x00000F00U
|
||||
#define RF_MGC_CH3_SHIFT 16
|
||||
#define RF_MGC_CH3_WIDTH 4
|
||||
#define RF_MGC_CH3_MASK 0x000F0000U
|
||||
#define RF_MGC_CH4_SHIFT 24
|
||||
#define RF_MGC_CH4_WIDTH 4
|
||||
#define RF_MGC_CH4_MASK 0x0F000000U
|
||||
|
||||
/**
|
||||
* Register: RF_FRAME_CNT
|
||||
*/
|
||||
#define RF_FRAME_CNT 0x00000138U
|
||||
#define RF_FRAME_CNT_SHIFT 0
|
||||
#define RF_FRAME_CNT_WIDTH 32
|
||||
#define RF_FRAME_CNT_MASK 0xFFFFFFFFU
|
||||
#define RF_FRAME_CNT 0x00000138U
|
||||
#define RF_FRAME_CNT_SHIFT 0
|
||||
#define RF_FRAME_CNT_WIDTH 32
|
||||
#define RF_FRAME_CNT_MASK 0xFFFFFFFFU
|
||||
|
||||
#endif /* PHY_CTRLREG_H_ */
|
||||
|
||||
Reference in New Issue
Block a user