Question:
I am working on extending an OSEK-based OS to implement the SyncScheduleTable
API as specified in AUTOSAR 4.4.0. Our current OS only supports a single schedule table, but synchronization requires managing multiple schedule tables. Below is the list of APIs supported in our existing OS for schedule table management:
Existing APIs:
Os_StatusType Os_Fn_StartScheduleTableRel(Os_ScheduleTBLType ScheduleTableID, Os_Base_Type Offset);
Os_StatusType Os_Fn_StartScheduleTableAbs(Os_ScheduleTBLType ScheduleTableID, Os_Base_Type Start);
Os_StatusType Os_Fn_StopScheduleTable(Os_ScheduleTBLType ScheduleTableID);
void Os_Fn_ScheduleTblMainFunction(void);
void Os_Fn_ScheduleTblInit(void);
void Os_Fn_ScheduleTblDeInit(void);
Newly Implemented APIs:
Os_StatusType Os_Fn_SyncScheduleTable(ScheduleTableType ScheduleTableID, uint32_t Sync_Counter);
Os_StatusType Os_Fn_GetScheduleTableStatus(ScheduleTableType ScheduleTableID, ScheduleTableStatusRefType ScheduleStatus);
Os_StatusType Os_Fn_NextScheduleTable(ScheduleTableType ScheduleTableID_From, ScheduleTableType ScheduleTableID_To);
Here is my implementation of the Os_Fn_SyncScheduleTable
API:
Os_StatusType Os_Fn_SyncScheduleTable(ScheduleTableType ScheduleTableID, uint32_t Sync_Counter){ /* Local Variables */ Os_Schedule_Tbl_Type_St* fl_SchdTbL_St; uint32_t fl_deviation_size_u32 = 0u; uint32_t fl_duration_size_u32 = 0u; Os_StatusType status = E_OS_OK; /* Check if the Schedule Table ID is valid */ if (ScheduleTableID >= MAX_SCHEDULE_TBL_ID) { return E_OS_ID; // Invalid Schedule Table ID } /* Get the schedule table object */ fl_SchdTbL_St = &OS_Core_Dynamic_st[g_Os_Current_App_Mode_u32].Schedule_Tbl_St[ScheduleTableID]; /* Ensure the schedule table is configured for synchronization */ if (fl_SchdTbL_St->Schd_Tbl_SyncType == OS_SCHT_SYNC_IMPLICIT || fl_SchdTbL_St->Schd_Tbl_SyncType == OS_SCHT_SYNC_NON) { return E_OS_ID; // Synchronization not supported or misconfigured } /* Ensure the schedule table is running */ if (fl_SchdTbL_St->Schd_Tbl_State == SCHEDULETABLE_STOPPED || fl_SchdTbL_St->Schd_Tbl_State == SCHEDULETABLE_NEXT) { return E_OS_STATE; // Schedule table is not running } /* Retrieve the duration of the schedule table */ fl_duration_size_u32 = fl_SchdTbL_St->Schd_Final_Delay; /* Calculate the fl_deviation_size_u32 */ fl_deviation_size_u32 = (Sync_Counter - fl_SchdTbL_St->Schd_SysTick_Counter_Stamp) % fl_duration_size_u32; /* Adjust fl_deviation_size_u32 to be positive */ if (fl_deviation_size_u32 < 0) { fl_deviation_size_u32 += fl_duration_size_u32; } /* Check if fl_deviation_size_u32 exceeds allowed bounds */ if (fl_deviation_size_u32 > OS_COUNTER_MAX_ALLOWED_VALUE) { status = E_OS_VALUE; // fl_deviation_size_u32 too large } else { /* Update the system tick stamp for synchronization */ fl_SchdTbL_St->Schd_SysTick_Counter_Stamp = Sync_Counter % fl_duration_size_u32; fl_SchdTbL_St->Schd_Current_Expiry_Point = fl_deviation_size_u32; // Adjust expiry point fl_SchdTbL_St->Schd_Expiry_Point_State = SERVE_EXP_POINT_OFFSET; // Sync state } return status;}
This implementation assumes that the OS can manage multiple schedule tables, but our current OS supports only one. I am trying to determine how to extend our OS to manage multiple schedule tables effectively.
My Questions:
How can I modify or extend the current OS to support multiple schedule tables for synchronization?
Does my implementation of
Os_Fn_SyncScheduleTable
meet the AUTOSAR 4.4.0 specification requirements? If not, what improvements are needed?How do the existing APIs like
Os_Fn_StartScheduleTableRel
andOs_Fn_NextScheduleTable
interact with the newly implemented synchronization API?