add rtt event, and adapted to new schedule event pool

This commit is contained in:
Gatsby Van
2023-12-22 01:20:44 +08:00
parent f72e6fadb1
commit 57dfad7b82
+19 -265
View File
@@ -255,265 +255,6 @@ inline L2_RTT_FSM* L2_GetRttFsm(L2_INST* instPtr){
return instPtr->rttFSM;
}
/*****************************************************************************/
/**
* @brief Creat a new schedule envent, register event in schedule event pool.
*
* @param instPtr a pointer to linklayer instance
* @param event event type of the new schedule event.
*
* @return NULL error occurred
* Pointer to schedule event.
*
******************************************************************************/
L2_SCHD_EVENT* L2_CreatNewSchdEvent(L2_INST* instPtr, L2_EVENT_TYPE event){
L2_SCHD_EVENT* schdEventPtr = NULL;
if(instPtr->schdEventCnt >= L2_SCHD_EVENT_MAX){
DBG_ERROR("Schedule event number exceeds the max, no more schedule event can be created.\n");
return NULL;
}
schdEventPtr = (L2_SCHD_EVENT*)malloc(sizeof(L2_SCHD_EVENT));
if(schdEventPtr == NULL){
free(schdEventPtr);
return NULL;
}
if(event < L2_EV_SCAN_PROC_DONE || event > L2_ROUTINE_UPDATE){
DBG_ERROR("Unknown event type: %d.\n", event);
return NULL;
}
schdEventPtr->eventId = instPtr->schdEventCnt;
schdEventPtr->l2Event.msg = NULL;
schdEventPtr->isSchd = false;
schdEventPtr->schdSlot = L2_SLOTNO_NONE;
schdEventPtr->schdFrame = L2_FRAMENO_NONE;
instPtr->l2SchdEventPool[instPtr->schdEventCnt] = schdEventPtr;
instPtr->schdEventCnt++;
return schdEventPtr;
}
/*****************************************************************************/
/**
* @brief Delete a schedule event, remove the event from event pool,
* release memory, release event ID.
*
* @param instPtr a pointer to linklayer instance
* @param eventId ID of the event
*
* @return SUCCESS
* error code
*
******************************************************************************/
int32_t L2_DeletSchdEvent(L2_INST* instPtr, int32_t eventId){
ASSERT(instPtr != NULL);
if (eventId > instPtr->schdEventCnt) {
return EIGNORE;
}
L2_SCHD_EVENT* schdEvent = instPtr->l2SchdEventPool[eventId];
for(int32_t i = schdEvent->eventId; i < instPtr->schdEventCnt; i++){
if(i == instPtr->schdEventCnt - 1){
instPtr->l2SchdEventPool[i] = NULL;
}
else{
instPtr->l2SchdEventPool[i] = instPtr->l2SchdEventPool[i+1];
}
}
instPtr->schdEventCnt --;
if(schdEvent->l2Event.msg != NULL) {
free(schdEvent->l2Event.msg);
}
free(schdEvent);
return SUCCESS;
}
/*****************************************************************************/
/**
* @brief Clear all event in the event pool.
*
* @param instPtr a pointer to linklayer instance
*
* @return NONE
*
******************************************************************************/
void L2_ClearSchdEvent(L2_INST* instPtr){
ASSERT(instPtr != NULL);
for(int32_t i = 0; i < instPtr->schdEventCnt; i++){
if(instPtr->l2SchdEventPool[i]->l2Event.msg != NULL) {
free(instPtr->l2SchdEventPool[i]->l2Event.msg);
}
free(instPtr->l2SchdEventPool[i]);
}
instPtr->schdEventCnt = 0;
}
/*****************************************************************************/
/**
* @brief Append extra message content to specific schedule event.
*
* @param schdEvent pointer to the schedule event.
* msg pointer to the append content.
*
* @return SUCCESS.
* error code.
*
******************************************************************************/
inline int32_t L2_SchdEventAppendMsg(L2_SCHD_EVENT* schdEvent, void* msg){
ASSERT(schdEvent != NULL);
schdEvent->l2Event.msg = msg;
return SUCCESS;
}
/*****************************************************************************/
/**
* @brief Cancel a scheduled event.
*
* @param schdEvent pointer to the schedule event.
*
* @return SUCCESS.
*
******************************************************************************/
int32_t L2_CancelEvent(L2_SCHD_EVENT* schdEvent){
ASSERT(schdEvent != NULL);
if(schdEvent->isSchd == false){
DBG_WARNING("Event %d has not been scheduled yet.\n", schdEvent->eventId);
}
schdEvent->isSchd = false;
return SUCCESS;
}
/*****************************************************************************/
/**
* @brief Check if the event was scheduled.
*
* @param schdEvent pointer to the schedule event.
*
* @return true.
* false.
*
******************************************************************************/
inline bool L2_isEventScheduled(L2_SCHD_EVENT* schdEvent){
ASSERT(schdEvent != NULL);
return schdEvent->isSchd;
}
/*****************************************************************************/
/**
* @brief Schedule a event at a specific time(indexed by frame and slot number)
*
* @param instPtr a pointer to linklayer instance
* @param schdEvent pointer to the schedule event.
* @param frameNum schedule frame number
* @param slotNum schedule slot number
*
* @return FAILURE, event has already been scheduled/schedule time not allowed.
* SUCCESS
*
******************************************************************************/
int32_t L2_ScheduleEventAt(L2_INST* instPtr, L2_SCHD_EVENT* schdEvent, uint32_t frameNum, uint32_t slotNum){
ASSERT(schdEvent != NULL);
if(L2_isEventScheduled(schdEvent) == true){
DBG_ERROR("Event %d has already been scheduled.\n", schdEvent->eventId);
return FAILURE;
}
if(frameNum <= L2_GetCurrentFrameNum(instPtr) && slotNum < L2_GetCurrentSlotNum(instPtr)){
DBG_ERROR("Cannot schedule event %d to the past(current: [%u-%u], schedule: [%u-%u]).\n",
schdEvent->eventId, L2_GetCurrentFrameNum(instPtr), L2_GetCurrentSlotNum(instPtr), frameNum, slotNum);
return FAILURE;
}
schdEvent->isSchd = true;
schdEvent->schdFrame = frameNum;
schdEvent->schdSlot = slotNum;
return SUCCESS;
}
/*****************************************************************************/
/**
* @brief Schedule a event after a specific time period.
*
* @param instPtr a pointer to linklayer instance
* @param schdEvent pointer to the schedule event.
* @param numSlots how many slot later the event should be scheduled
*
* @return FAILURE, event has already been scheduled/schedule time not allowed.
* SUCCESS
*
******************************************************************************/
int32_t L2_ScheduleEventAfter(L2_INST* instPtr, L2_SCHD_EVENT* schdEvent, uint32_t numSlots){
ASSERT(schdEvent != NULL);
if(L2_isEventScheduled(schdEvent) == true){
DBG_ERROR("Event %d has already been scheduled.\n", schdEvent->eventId);
return FAILURE;
}
uint32_t frameNum = L2_GetCurrentFrameNum(instPtr) + (numSlots/L2_SLOTS_PER_FRAME);
uint32_t slotNum = L2_GetCurrentSlotNum(instPtr) + (numSlots%L2_SLOTS_PER_FRAME);
return L2_ScheduleEventAt(instPtr, schdEvent, frameNum, slotNum);
}
/*****************************************************************************/
/**
* @brief Reschedule a event at a specific time(indexed by frame and slot number)
*
* @param instPtr a pointer to linklayer instance
* @param schdEvent pointer to the schedule event.
* @param frameNum schedule frame number
* @param slotNum schedule slot number
*
* @return FAILURE, event has already been scheduled/schedule time not allowed.
* SUCCESS
*
******************************************************************************/
int32_t L2_RecheduleEventAt(L2_INST* instPtr, L2_SCHD_EVENT* schdEvent, uint32_t frameNum, uint32_t slotNum){
ASSERT(schdEvent != NULL);
if(schdEvent->isSchd == false){
DBG_WARNING("Event %d has not been scheduled yet.\n", schdEvent->eventId);
}
schdEvent->isSchd = false;
return L2_ScheduleEventAt(instPtr, schdEvent, frameNum, slotNum);
}
/*****************************************************************************/
/**
* @brief Rechedule a event after a specific time period.
*
* @param instPtr a pointer to linklayer instance
* @param schdEvent pointer to the schedule event.
* @param numSlots how many slot later the event should be scheduled
*
* @return FAILURE, event has already been scheduled/schedule time not allowed.
* SUCCESS
*
******************************************************************************/
int32_t L2_RecheduleEventAfter(L2_INST* instPtr, L2_SCHD_EVENT* schdEvent, uint32_t numSlots){
ASSERT(schdEvent != NULL);
if(schdEvent->isSchd == false){
DBG_WARNING("Event %d has not been scheduled yet.\n", schdEvent->eventId);
}
return L2_ScheduleEventAfter(instPtr, schdEvent, numSlots);
}
/*****************************************************************************/
/**
* @brief Check and excute schedule event in event pool illiterate.
*
* @param instPtr a pointer to linklayer instance
*
* @return NONE.
*
******************************************************************************/
static void L2_EventPoolHandler(L2_INST* instPtr){
ASSERT(instPtr != NULL);
for(int32_t i = 0; i < instPtr->schdEventCnt; i++){
if(instPtr->l2SchdEventPool[i]->isSchd == true){
if(instPtr->l2SchdEventPool[i]->schdFrame == instPtr->frameNum.curr
&& instPtr->l2SchdEventPool[i]->schdSlot == instPtr->slotNum.curr){
AssertL2Event(instPtr, &(instPtr->l2SchdEventPool[i]->l2Event));
}
}
}
}
/*****************************************************************************/
/**
* @brief Shift L2 status record.(newval->next->curr->last)
@@ -906,7 +647,6 @@ int32_t Linklayer_Init(L2_INST** instPtr, const L2_CONFIG *config) {
// Reset basic info
(*instPtr)->netStartTime = UINT32_MAX;
(*instPtr)->schdEventCnt = 0;
(*instPtr)->rtneConfig.last = NULL;
(*instPtr)->rtneConfig.curr = NULL;
(*instPtr)->rtneConfig.next = NULL;
@@ -947,7 +687,17 @@ int32_t Linklayer_Init(L2_INST** instPtr, const L2_CONFIG *config) {
(*instPtr)->svcMsgRecvCnt1 = 0;
(*instPtr)->buffSwitch = 0;
NodeList_Init(&((*instPtr)->nodeList));
Status = L2_CreateSchedEventPool(&((*instPtr)->schdEventPool));
if (Status != SUCCESS) {
DBG_ERROR("L2_CreateSchedEventPool runs failed, with error code: %d.\n", Status);
goto error;
}
Status = L2_NodeList_Init(&((*instPtr)->nodeList));
if (Status != SUCCESS) {
DBG_ERROR("NodeList_Init runs failed, with error code: %d.\n", Status);
goto error;
}
Status = ScanNet_Init(&((*instPtr)->scanNetFSM));
if (Status != SUCCESS) {
@@ -992,7 +742,6 @@ int32_t Linklayer_Reconfig(L2_INST* instPtr, const L2_CONFIG *config) {
// Reset basic info
instPtr->netStartTime = UINT32_MAX;
instPtr->schdEventCnt = 0;
instPtr->rtneConfig.last = NULL;
instPtr->rtneConfig.curr = NULL;
instPtr->rtneConfig.next = NULL;
@@ -1033,8 +782,8 @@ int32_t Linklayer_Reconfig(L2_INST* instPtr, const L2_CONFIG *config) {
instPtr->buffSwitch = 0;
// Reset according instance
L2_ClearSchdEvent(instPtr);
NodeList_Clear(instPtr->nodeList);
L2_ClearSchedEventPool(instPtr->schdEventPool);
L2_NodeList_Clear(instPtr->nodeList);
ScanNet_Reset(instPtr->scanNetFSM);
MgmtNet_Reset(instPtr->mgmtNetFSM);
ServiceNet_Reset(instPtr->serviceNetFSM);
@@ -1052,7 +801,8 @@ void Linklayer_Destroy(L2_INST* instPtr){
free(instPtr->mgmtMsgRecvBuff1);
free(instPtr->svcMsgRecvBuff1);
// Destroy FSMs and nodeList
NodeList_Destroy(instPtr->nodeList);
L2_DestroySchedEventPool(instPtr->schdEventPool);
L2_NodeList_Destroy(instPtr->nodeList);
ScanNet_Destroy(instPtr->scanNetFSM);
MgmtNet_Destroy(instPtr->mgmtNetFSM);
ServiceNet_Destroy(instPtr->serviceNetFSM);
@@ -1125,6 +875,10 @@ int32_t Linklayer_EventHandler(L2_INST* instPtr, const L2_EVENT* l2Event) {
DBG_INFO("Event L2_EV_TIME_SYNC asserted....\n");
break;
}
case L2_EV_RTT_RECV_UPDATE:
DBG_INFO("Event L2_EV_RTT_RECV_UPDATE asserted....\n");
RTT_FsmUpdate(instPtr, L2_TOR_RX);
break;
case L2_EV_LINK_SET_REQ: {
DBG_INFO("Event L2_EV_LINK_SET_REQ asserted....\n");
break;