├── Common ├── Compiler.h ├── Compiler_Cfg.h ├── Dem.h ├── Det.h ├── Os_MemMap.h ├── Platform_Types.h └── Std_Types.h ├── Os_Cfg ├── Os_Alarm_Cfg.h ├── Os_Cfg.h ├── Os_Counter_Cfg.h ├── Os_Event_Cfg.h ├── Os_General_Cfg.h ├── Os_Isr_Cfg.h ├── Os_Resource_Cfg.h ├── Os_ScheduleTable_Cfg.h └── Os_Task_Cfg.h ├── Os_Headers ├── OsInterface_Headers │ ├── Os.h │ ├── Os_Alarm.h │ ├── Os_Counter.h │ ├── Os_Event.h │ ├── Os_General.h │ ├── Os_Isr.h │ ├── Os_Resource.h │ ├── Os_ScheduleTable.h │ └── Os_Task.h └── OsInternal_Headers │ ├── Os_Alarm_Internal.h │ ├── Os_Counter_Internal.h │ ├── Os_Event_Internal.h │ ├── Os_ExternalVariables.h │ ├── Os_General_Internal.h │ ├── Os_Gpt_Internal.h │ ├── Os_Internal.h │ ├── Os_Isr_Internal.h │ ├── Os_Resource_Internal.h │ ├── Os_ScheduleTable_Internal.h │ └── Os_Task_Internal.h └── Os_Sources ├── OsInterface_Sources ├── Os_Alarm.c ├── Os_Counter.c ├── Os_Event.c ├── Os_General.c ├── Os_Isr.c ├── Os_Resource.c ├── Os_ScheduleTable.c └── Os_Task.c └── OsInternal_Sources ├── Os_Alarm_Internal.c ├── Os_Gpt_internal.c ├── Os_Resource_Internal.c ├── Os_ScheduleTable_Internal.c ├── Os_Task_Internal.c └── Os_Variables.c /Common/Compiler.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Written by : Bebo 4 | DATE : 7/2/2019 5 | AUTOSAR Version : 4.3.1 6 | DOC Name : AUTOSAR_SWS_CompilerAbstraction.pdf 7 | Target : ARM TIVA_C TM4C123GH6PM 8 | 9 | */ 10 | 11 | 12 | #ifndef COMPILER_H 13 | 14 | #define COMPILER_H 15 | 16 | 17 | #include "Compiler_Cfg.h" 18 | 19 | 20 | /*********************************************************************/ 21 | 22 | 23 | /* Published information */ 24 | #define MCU_MODULE_ID 30u 25 | #define MCU_VENDOR_ID 0x002Bu /* vendor id of NXP */ 26 | 27 | #define MCU_AR_RELEASE_MAJOR_VERSION 0x01u 28 | #define MCU_AR_RELEASE_MINOR_VERSION 0x00u 29 | #define MCU_AR_RELEASE_REVISION_VERSION 0x00u 30 | 31 | #define MCU_SW_MAJOR_VERSION 0x04u 32 | #define MCU_SW_MINOR_VERSION 0x03u 33 | #define MCU_SW_PATCH_VERSION 0x01u 34 | 35 | 36 | /*********************************************************************/ 37 | 38 | /* 8.2.1 */ 39 | 40 | #define NULL_PTR ((void*) 0x0) 41 | 42 | #define AUTOMATIC /* used as input for memory class (memclass) and pointer class (ptrclass) when no input from Compiler_Cfg.h is needed */ 43 | #define TYPEDEF /* used with typedef keyword in as input for memory class (of compiler)because with typedef we cannot use them */ 44 | 45 | #define INLINE inline 46 | #define LOCAL_INLINE static inline 47 | 48 | 49 | /* 8.2.2 function definition use it to define functions */ 50 | 51 | #define FUNC( rettype, memclass ) rettype /* for the declaration and definition of functions */ 52 | 53 | #define FUNC_P2CONST(rettype, ptrclass, memclass) const rettype * /* declaration and definition of functions returning a pointer to a constant */ 54 | 55 | #define FUNC_P2VAR(rettype, ptrclass, memclass) rettype * /* for the declaration and definition of functions returning a pointer to a variable */ 56 | 57 | 58 | /* 8.2.3 Pointer definitions use it to define pointers */ 59 | 60 | #define P2VAR(ptrtype, memclass, ptrclass) ptrtype * /* for the declaration and definition of pointers in RAM, pointing to variables */ 61 | 62 | #define P2CONST(ptrtype, memclass, ptrclass) const ptrtype* /* for the declaration and definition of pointers in RAM pointing to constants */ 63 | 64 | #define CONSTP2VAR(ptrtype, memclass, ptrclass) ptrtype * const /* for the declaration and definition of constant pointers accessing variables */ 65 | 66 | #define CONSTP2CONST(ptrtype, memclass, ptrclass) const ptrtype * const /* for the declaration and definition of constant pointers accessing constants */ 67 | 68 | #define P2FUNC(rettype, ptrclass, fctname) rettype (* fctname) /* for the type definition of pointers to functions */ /* fctname is pointer to function name*/ 69 | 70 | #define CONSTP2FUNC(rettype, ptrclass, fctname) rettype (* const fctname) /* the type definition of constant pointers to functions */ /* fctname is pointer to function name*/ 71 | 72 | 73 | /* 8.2.4 Constant definitions use it to define Constants */ 74 | 75 | #define CONST(type, memclass) const type /* for the declaration and definition of constants */ 76 | 77 | 78 | /* 8.2.4 Variable definitions use it to define Variables */ 79 | 80 | #define VAR( type, memclass ) type /* for the declaration and definition of constants */ 81 | 82 | 83 | #endif /* COMPILER_H */ 84 | 85 | -------------------------------------------------------------------------------- /Common/Compiler_Cfg.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Written by : Bebo 4 | DATE : 7/2/2019 5 | AUTOSAR Version : 4.3.1 6 | DOC Name : AUTOSAR_SWS_CompilerAbstraction.pdf 7 | Target : ARM TIVA_C TM4C123GH6PM 8 | 9 | */ 10 | 11 | 12 | #ifndef COMPILER_CFG_H 13 | 14 | #define COMPILER_CFG_H 15 | 16 | 17 | /*********************************************************************/ 18 | 19 | 20 | /* Published information */ 21 | #define OS_MODULE_ID 30u 22 | #define OS_VENDOR_ID 0x002Bu /* vendor id of NXP */ 23 | 24 | #define OS_AR_RELEASE_MAJOR_VERSION 0x01u 25 | #define OS_AR_RELEASE_MINOR_VERSION 0x00u 26 | #define OS_AR_RELEASE_REVISION_VERSION 0x00u 27 | 28 | #define OS_SW_MAJOR_VERSION 0x04u 29 | #define OS_SW_MINOR_VERSION 0x03u 30 | #define OS_SW_PATCH_VERSION 0x01u 31 | 32 | 33 | /*********************************************************************/ 34 | 35 | /* 7.1.2 */ 36 | /* this is compiler keywords (not C keywords) must by used with function, variables and, pointers to work in prober way */ 37 | /* for ARM C (GCC, ADS) compilers no need for those*/ 38 | 39 | #define OS_CODE /* used for ordinary code */ 40 | #define OS_CONFIG_DATA /* used for cused for module configuration constants */ 41 | #define REGSPACE /* used for staitc Pointer to Reg (ptr to volatile) carry adress of value that changed in any time by interrupts */ 42 | #define OS_VAR_INIT /* for variables that are initialized with values after every reset */ 43 | #define OS_CONST /* used for global or static constants */ 44 | #define OS_APPL_CONST /* used for global or static pointer to constants */ 45 | #define OS_VAR_CLEARED /* for variables that are cleared to zero after every reset */ 46 | 47 | 48 | 49 | 50 | 51 | #endif /* COMPILER_CFG_H */ 52 | -------------------------------------------------------------------------------- /Common/Dem.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Dem.h 3 | * 4 | * Created on: Nov 19, 2019 5 | * Author: MohamedBakr 6 | */ 7 | 8 | #ifndef DEM_H_ 9 | #define DEM_H_ 10 | 11 | 12 | 13 | 14 | 15 | #endif /* DEM_H_ */ 16 | -------------------------------------------------------------------------------- /Common/Det.h: -------------------------------------------------------------------------------- 1 | #ifndef DET_H 2 | 3 | #define DET_H 4 | 5 | /*********************************************************************/ 6 | 7 | 8 | /* Published information */ 9 | #define MCU_MODULE_ID 30u 10 | #define MCU_VENDOR_ID 0x002Bu /* vendor id of NXP */ 11 | 12 | #define MCU_AR_RELEASE_MAJOR_VERSION 0x01u 13 | #define MCU_AR_RELEASE_MINOR_VERSION 0x00u 14 | #define MCU_AR_RELEASE_REVISION_VERSION 0x00u 15 | 16 | #define MCU_SW_MAJOR_VERSION 0x04u 17 | #define MCU_SW_MINOR_VERSION 0x03u 18 | #define MCU_SW_PATCH_VERSION 0x01u 19 | 20 | 21 | /*********************************************************************/ 22 | 23 | #include "Std_Types.h" 24 | 25 | 26 | FUNC(Std_ReturnType, MCU_CODE ) Det_ReportError( uint16 ModuleId, uint8 InstanceId, uint8 ApiId, uint8 ErrorId ) ; 27 | 28 | 29 | #endif // DET_H 30 | -------------------------------------------------------------------------------- /Common/Os_MemMap.h: -------------------------------------------------------------------------------- 1 | 2 | /*Arm Compiler # Pragmas */ 3 | /* 4 | #pragma arm section code ="Name0",rodata="Name1",rwdata="Name2",zidata="Name3" 5 | 6 | to place functions and variables in separate named sections. 7 | The scatter-loading description file can then be used to locate these at a 8 | particular address in memory. 9 | • code //Code section 10 | • rodata //Read only section 11 | • rwdata //Read write section 12 | • zidata //zero initialized 13 | 14 | #pragma pack(n) //n aligenment as bytes 1,2,4,8 15 | 16 | Packed objects are read and written using unaligned accesses. 17 | 18 | #pragma arm section zidata 19 | int i, j; // uninitialized data in non_initialized section (without the pragma, 20 | would be in .bss section by default) 21 | 22 | */ 23 | #define MEMMAP_ERROR 24 | /**********************Data Section**********************/ 25 | 26 | /*Init-Aligenment*/ 27 | /*Start*/ 28 | #ifdef OS_START_SEC_VAR_INIT_8 29 | //define memory aligenment function to 8 bits 30 | #undef OS_START_SEC_VAR_INIT_8 31 | #define START_SECTION_DATA_INIT_8 32 | 33 | #elif OS_START_SEC_VAR_INIT_16 34 | //define memory aligenment function to 16 bits 35 | #undef OS_START_SEC_VAR_INIT_16 36 | #define START_SECTION_DATA_INIT_16 37 | 38 | #elif OS_START_SEC_VAR_INIT_32 39 | //define memory aligenment function to 32 bits 40 | #undef OS_START_SEC_VAR_INIT_32 41 | #define START_SECTION_DATA_INIT_32 42 | 43 | #elif OS_START_SEC_VAR_INIT_64 44 | //define memory aligenment function to 64 bits 45 | #undef OS_START_SEC_VAR_INIT_64 46 | #define START_SECTION_DATA_INIT_64 47 | #endif 48 | /*Stop*/ 49 | #ifdef OS_STOP_SEC_VAR_INIT_8 50 | //define memory aligenment function to 8 bits 51 | #undef OS_STOP_SEC_VAR_INIT_8 52 | #define STOP_SECTION_DATA_INIT_8 53 | 54 | #elif OS_STOP_SEC_VAR_INIT_16 55 | //define memory aligenment function to 16 bits 56 | #undef OS_STOP_SEC_VAR_INIT_16 57 | #define STOP_SECTION_DATA_INIT_16 58 | 59 | #elif OS_STOP_SEC_VAR_INIT_32 60 | //define memory aligenment function to 32 bits 61 | #undef OS_STOP_SEC_VAR_INIT_32 62 | #define STOP_SECTION_DATA_INIT_32 63 | 64 | #elif OS_STOP_SEC_VAR_INIT_64 65 | //define memory aligenment function to 64 bits 66 | #undef OS_STOP_SEC_VAR_INIT_64 67 | #define STOP_SECTION_DATA_INIT_64 68 | #endif 69 | /*****************************************/ 70 | /*Non_Init-Aligenment*/ 71 | /*Start*/ 72 | #ifdef OS_START_SEC_VAR_NO_INIT_8 73 | //define memory aligenment function to 8 bits 74 | #undef OS_START_SEC_VAR_NO_INIT_8 75 | #define START_SECTION_DATA_NO_INIT_8 76 | 77 | #elif OS_START_SEC_VAR_NO_INIT_16 78 | //define memory aligenment function to 16 bits 79 | #undef OS_START_SEC_VAR_NO_INIT_16 80 | #define START_SECTION_DATA_NO_INIT_16 81 | 82 | #elif OS_START_SEC_VAR_NO_INIT_32 83 | //define memory aligenment function to 32 bits 84 | #undef OS_START_SEC_VAR_NO_INIT_32 85 | #define START_SECTION_DATA_NO_INIT_32 86 | 87 | #elif OS_START_SEC_VAR_NO_INIT_64 88 | //define memory aligenment function to 64 bits 89 | #undef OS_START_SEC_VAR_NO_INIT_64 90 | #define START_SECTION_DATA_NO_INIT_64 91 | #endif 92 | /*Stop*/ 93 | #ifdef OS_STOP_SEC_VAR_NO_INIT_8 94 | //define memory aligenment function to 8 bits 95 | #undef OS_STOP_SEC_VAR_NO_INIT_8 96 | #define STOP_SECTION_DATA_NO_INIT_8 97 | 98 | #elif OS_STOP_SEC_VAR_NO_INIT_16 99 | //define memory aligenment function to 16 bits 100 | #undef OS_STOP_SEC_VAR_NO_INIT_16 101 | #define STOP_SECTION_DATA_NO_INIT_16 102 | 103 | #elif OS_STOP_SEC_VAR_NO_INIT_32 104 | //define memory aligenment function to 32 bits 105 | #undef OS_STOP_SEC_VAR_NO_INIT_32 106 | #define STOP_SECTION_DATA_NO_INIT_32 107 | 108 | #elif OS_STOP_SEC_VAR_NO_INIT_64 109 | //define memory aligenment function to 64 bits 110 | #undef OS_STOP_SEC_VAR_NO_INIT_64 111 | #define STOP_SECTION_DATA_NO_INIT_64 112 | #endif 113 | /*****************************************/ 114 | /*Cleared-Aligenment*/ 115 | /*Start*/ 116 | #ifdef OS_START_SEC_VAR_CLEARED_8 117 | //define memory aligenment function to 8 bits 118 | #undef OS_START_SEC_VAR_CLEARED_8 119 | #define START_SECTION_DATA_CLEARED_8 120 | 121 | #elif OS_START_SEC_VAR_CLEARED_16 122 | //define memory aligenment function to 16 bits 123 | #undef OS_START_SEC_VAR_CLEARED_16 124 | #define START_SECTION_DATA_CLEARED_16 125 | 126 | #elif OS_START_SEC_VAR_CLEARED_32 127 | //define memory aligenment function to 32 bits 128 | #undef OS_START_SEC_VAR_CLEARED_32 129 | #define START_SECTION_DATA_CLEARED_32 130 | 131 | #elif OS_START_SEC_VAR_CLEARED_64 132 | //define memory aligenment function to 64 bits 133 | #undef OS_START_SEC_VAR_CLEARED_64 134 | #define START_SECTION_DATA_CLEARED_64 135 | #endif 136 | /*Stop*/ 137 | #ifdef OS_STOP_SEC_VAR_CLEARED_8 138 | //define memory aligenment function to 8 bits 139 | #undef OS_STOP_SEC_VAR_CLEARED_8 140 | #define STOP_SECTION_DATA_CLEARED_8 141 | 142 | #elif OS_STOP_SEC_VAR_CLEARED_16 143 | //define memory aligenment function to 16 bits 144 | #undef OS_STOP_SEC_VAR_CLEARED_16 145 | #define STOP_SECTION_DATA_CLEARED_16 146 | 147 | #elif OS_STOP_SEC_VAR_CLEARED_32 148 | //define memory aligenment function to 32 bits 149 | #undef OS_STOP_SEC_VAR_CLEARED_32 150 | #define STOP_SECTION_DATA_CLEARED_32 151 | 152 | #elif OS_STOP_SEC_VAR_CLEARED_64 153 | //define memory aligenment function to 64 bits 154 | #undef OS_STOP_SEC_VAR_CLEARED_64 155 | #define STOP_SECTION_DATA_CLEARED_64 156 | #endif 157 | /*****************************************/ 158 | /*Constant-Aligenment*/ 159 | /*Start*/ 160 | #ifdef OS_START_SEC_CONST_8 161 | //define memory aligenment function to 8 bits 162 | #undef OS_START_SEC_CONST_8 163 | #define START_SECTION_DATA_CONST_8 164 | 165 | #elif OS_START_SEC_CONST_16 166 | //define memory aligenment function to 16 bits 167 | #undef OS_START_SEC_CONST_16 168 | #define START_SECTION_DATA_CONST_16 169 | 170 | #elif OS_START_SEC_CONST_32 171 | //define memory aligenment function to 32 bits 172 | #undef OS_START_SEC_CONST_32 173 | #define START_SECTION_DATA_CONST_32 174 | 175 | #elif OS_START_SEC_CONST_64 176 | //define memory aligenment function to 64 bits 177 | #undef OS_START_SEC_CONST_64 178 | #define START_SECTION_DATA_CONST_64 179 | #endif 180 | /*Stop*/ 181 | #ifdef OS_STOP_SEC_CONST_8 182 | //define memory aligenment function to 8 bits 183 | #undef OS_STOP_SEC_CONST_8 184 | #define STOP_SECTION_DATA_CONST_8 185 | 186 | #elif OS_STOP_SEC_CONST_16 187 | //define memory aligenment function to 16 bits 188 | #undef OS_STOP_SEC_CONST_16 189 | #define STOP_SECTION_DATA_CONST_16 190 | 191 | #elif OS_STOP_SEC_CONST_32 192 | //define memory aligenment function to 32 bits 193 | #undef OS_STOP_SEC_CONST_32 194 | #define STOP_SECTION_DATA_CONST_32 195 | 196 | #elif OS_STOP_SEC_CONST_64 197 | //define memory aligenment function to 64 bits 198 | #undef OS_STOP_SEC_CONST_64 199 | #define STOP_SECTION_DATA_CONST_64 200 | #endif 201 | /*****************************************/ 202 | /**********************Code Section**********************/ 203 | 204 | /*CODE SECTION DECLARATION*/ 205 | /*Start*/ 206 | #ifdef OS_START_SEC_CODE_LOCAL 207 | //DEFINE MEMORY SECTION AS CODE 208 | #undef OS_START_SEC_CODE_LOCAL 209 | #define START_SEC_CODE_LOCAL 210 | #endif 211 | /*Stop*/ 212 | #ifdef OS_STOP_SEC_CODE_LOCAL 213 | //END THE CODE MEMORY SECTION 214 | #undef OS_STOP_SEC_CODE_LOCAL 215 | #define STOP_START_SEC_CODE_LOCAL 216 | 217 | #endif 218 | /*****************************************/ 219 | /**************************************************************************************/ 220 | /**********************Data Section**********************/ 221 | 222 | /*Assigen pragmas as defined function*/ 223 | /*Init-Aligenment*/ 224 | /*Start*/ 225 | #ifdef START_SECTION_DATA_INIT_8 226 | 227 | #pragma arm section rwdata="RW_Section_8bit" //Initialized section named RW_Section_8bit 228 | #pragma pack(1) //Assigen the aligenment as 1 byte => 8bit 229 | #undef START_SECTION_DATA_INIT_8 230 | #undef MEMMAP_ERROR 231 | 232 | #elif START_SECTION_DATA_INIT_16 233 | 234 | #pragma arm section rwdata="RW_Section_16bit" //Initialized section named RW_Section_16bit 235 | #pragma pack(2) //Assigen the aligenment as 2 byte => 16bit 236 | #undef START_SECTION_DATA_INIT_16 237 | #undef MEMMAP_ERROR 238 | 239 | #elif START_SECTION_DATA_INIT_32 240 | 241 | #pragma arm section rwdata="RW_Section_32bit" //Initialized section named RW_Section_32bit 242 | #pragma pack(4) //Assigen the aligenment as 4 byte => 32bit 243 | #undef START_SECTION_DATA_INIT_32 244 | #undef MEMMAP_ERROR 245 | 246 | #elif START_SECTION_DATA_INIT_64 247 | 248 | #pragma arm section rwdata="RW_Section_64bit" //Initialized section named RW_Section_64bit 249 | #pragma pack(8) //Assigen the aligenment as 8 byte => 64bit 250 | #undef START_SECTION_DATA_INIT_64 251 | #undef MEMMAP_ERROR 252 | 253 | #endif 254 | /*Stop*/ 255 | #ifdef STOP_SECTION_DATA_INIT_8 256 | 257 | #pragma arm section //Default 258 | #pragma pack(8) //Default 259 | #undef STOP_SECTION_DATA_INIT_8 260 | #undef MEMMAP_ERROR 261 | 262 | #elif STOP_SECTION_DATA_INIT_16 263 | 264 | #pragma arm section //Default section 265 | #pragma pack(8) //Default aligenment 266 | #undef STOP_SECTION_DATA_INIT_16 267 | #undef MEMMAP_ERROR 268 | 269 | #elif STOP_SECTION_DATA_INIT_32 270 | 271 | #pragma arm section //Default section 272 | #pragma pack(8) //Default aligenment 273 | #undef STOP_SECTION_DATA_INIT_32 274 | #undef MEMMAP_ERROR 275 | 276 | #elif STOP_SECTION_DATA_INIT_64 277 | 278 | #pragma arm section //Default section 279 | #pragma pack(8) //Default aligenment 280 | #undef STOP_SECTION_DATA_INIT_64 281 | #undef MEMMAP_ERROR 282 | 283 | #endif 284 | /********************************/ 285 | /*Non_Init-Aligenment*/ 286 | /*Start*/ 287 | #ifdef START_SECTION_DATA_NO_INIT_8 288 | 289 | #pragma arm section zidata="NI_Section_8bit" //non Initialized section named NI_Section_8bit 290 | #pragma pack(1) //Assigen the aligenment as 1 byte => 8bit 291 | #undef START_SECTION_DATA_NO_INIT_8 292 | #undef MEMMAP_ERROR 293 | 294 | #elif START_SECTION_DATA_NO_INIT_16 295 | 296 | #pragma arm section zidata="NI_Section_16bit" //non Initialized section named NI_Section_16bit 297 | #pragma pack(2) //Assigen the aligenment as 2 byte => 16bit 298 | #undef START_SECTION_DATA_NO_INIT_16 299 | #undef MEMMAP_ERROR 300 | 301 | #elif START_SECTION_DATA_NO_INIT_32 302 | 303 | #pragma arm section zidata="NI_Section_32bit" //non Initialized section named NI_Section_32bit 304 | #pragma pack(4) //Assigen the aligenment as 4 byte => 32bit 305 | #undef START_SECTION_DATA_NO_INIT_32 306 | #undef MEMMAP_ERROR 307 | 308 | #elif START_SECTION_DATA_NO_INIT_64 309 | 310 | #pragma arm section zidata="NI_Section_64bit" //non Initialized section named NI_Section_64bit 311 | #pragma pack(8) //Assigen the aligenment as 8 byte => 64bit 312 | #undef START_SECTION_DATA_NO_INIT_64 313 | #undef MEMMAP_ERROR 314 | 315 | #endif 316 | /*Stop*/ 317 | #ifdef STOP_SECTION_DATA_NO_INIT_8 318 | 319 | #pragma arm section //Default section 320 | #pragma pack(8) //Default aligenment 321 | #undef STOP_SECTION_DATA_NO_INIT_8 322 | #undef MEMMAP_ERROR 323 | 324 | #elif STOP_SECTION_DATA_NO_INIT_16 325 | 326 | #pragma arm section //Default section 327 | #pragma pack(8) //Default aligenment 328 | #undef STOP_SECTION_DATA_NO_INIT_16 329 | #undef MEMMAP_ERROR 330 | 331 | #elif STOP_SECTION_DATA_NO_INIT_32 332 | 333 | #pragma arm section //Default section 334 | #pragma pack(8) //Default aligenment 335 | #undef START_SECTION_DATA_NO_INIT_32 336 | #undef MEMMAP_ERROR 337 | 338 | #elif STOP_SECTION_DATA_NO_INIT_64 339 | 340 | #pragma arm section //Default section 341 | #pragma pack(8) //Default aligenment 342 | #undef STOP_SECTION_DATA_NO_INIT_64 343 | #undef MEMMAP_ERROR 344 | 345 | #endif 346 | /********************************/ 347 | /*Cleared-Aligenment*/ 348 | /*Start*/ 349 | #ifdef START_SECTION_DATA_CLEARED_8 350 | 351 | #pragma arm section zidata="ZI_Section_8bit" //Zero Initialized section named ZI_Section_8bit 352 | #pragma pack(1) //Assigen the aligenment as 1 byte => 8bit 353 | #undef START_SECTION_DATA_CLEARED_8 354 | #undef MEMMAP_ERROR 355 | 356 | #elif START_SECTION_DATA_CLEARED_16 357 | 358 | #pragma arm section zidata="ZI_Section_16bit" //Zero Initialized section named ZI_Section_16bit 359 | #pragma pack(2) //Assigen the aligenment as 2 byte => 16bit 360 | #undef START_SECTION_DATA_CLEARED_16 361 | #undef MEMMAP_ERROR 362 | 363 | #elif START_SECTION_DATA_CLEARED_32 364 | 365 | #pragma arm section zidata="ZI_Section_32bit" //Zero Initialized section named ZI_Section_32bit 366 | #pragma pack(4) //Assigen the aligenment as 4 byte => 32bit 367 | #undef START_SECTION_DATA_CLEARED_32 368 | #undef MEMMAP_ERROR 369 | 370 | #elif START_SECTION_DATA_CLEARED_64 371 | 372 | #pragma arm section zidata="ZI_Section_64bit" //Zero Initialized section named ZI_Section_64bit 373 | #pragma pack(8) //Assigen the aligenment as 8 byte => 64bit 374 | #undef START_SECTION_DATA_CLEARED_64 375 | #undef MEMMAP_ERROR 376 | 377 | #endif 378 | /*Stop*/ 379 | #ifdef STOP_SECTION_DATA_CLEARED_8 380 | 381 | #pragma arm section //Default section 382 | #pragma pack(8) //Default aligenment 383 | #undef STOP_SECTION_DATA_CLEARED_8 384 | #undef MEMMAP_ERROR 385 | 386 | #elif STOP_SECTION_DATA_CLEARED_16 387 | 388 | #pragma arm section //Default section 389 | #pragma pack(8) //Default aligenment 390 | #undef STOP_SECTION_DATA_CLEARED_16 391 | #undef MEMMAP_ERROR 392 | 393 | #elif STOP_SECTION_DATA_CLEARED_32 394 | 395 | #pragma arm section //Default section 396 | #pragma pack(8) //Default aligenment 397 | #undef STOP_SECTION_DATA_CLEARED_32 398 | #undef MEMMAP_ERROR 399 | 400 | #elif STOP_SECTION_DATA_CLEARED_64 401 | 402 | #pragma arm section //Default section 403 | #pragma pack(8) //Default aligenment 404 | #undef STOP_SECTION_DATA_CLEARED_64 405 | #undef MEMMAP_ERROR 406 | 407 | #endif 408 | /********************************/ 409 | /*Constant-Aligenment*/ 410 | /*Start*/ 411 | #ifdef START_SECTION_DATA_CONST_8 412 | 413 | #pragma arm section rodata="RO_Section_8bit" //Read only section named RO_Section_8bit 414 | #pragma pack(1) //Assigen the aligenment as 1 byte => 8bit 415 | #undef START_SECTION_DATA_CONST_8 416 | #undef MEMMAP_ERROR 417 | 418 | #elif START_SECTION_DATA_CONST_16 419 | 420 | #pragma arm section rodata="RO_Section_16bit" //Read only section named RO_Section_16bit 421 | #pragma pack(2) //Assigen the aligenment as 2 byte => 16bit 422 | #undef START_SECTION_DATA_CONST_16 423 | #undef MEMMAP_ERROR 424 | 425 | #elif START_SECTION_DATA_CONST_32 426 | 427 | #pragma arm section rodata="RO_Section_32bit" //Read only section named RO_Section_32bit 428 | #pragma pack(4) //Assigen the aligenment as 4 byte => 32bit 429 | #undef START_SECTION_DATA_CONST_32 430 | #undef MEMMAP_ERROR 431 | 432 | #elif START_SECTION_DATA_CONST_64 433 | 434 | #pragma arm section rodata="RO_Section_64bit" //Read only section named RO_Section_64bit 435 | #pragma pack(8) //Assigen the aligenment as 8 byte => 64bit 436 | #undef START_SECTION_DATA_CONST_64 437 | #undef MEMMAP_ERROR 438 | 439 | #endif 440 | /*Stop*/ 441 | #ifdef STOP_SECTION_DATA_CONST_8 442 | 443 | #pragma arm section //Default section 444 | #pragma pack(8) //Default aligenment 445 | #undef STOP_SECTION_DATA_CONST_8 446 | #undef MEMMAP_ERROR 447 | 448 | #elif STOP_SECTION_DATA_CONST_16 449 | 450 | #pragma arm section //Default section 451 | #pragma pack(8) //Default aligenment 452 | #undef STOP_SECTION_DATA_CONST_16 453 | #undef MEMMAP_ERROR 454 | 455 | #elif STOP_SECTION_DATA_CONST_32 456 | 457 | #pragma arm section //Default section 458 | #pragma pack(8) //Default aligenment 459 | #undef STOP_SECTION_DATA_CONST_32 460 | #undef MEMMAP_ERROR 461 | 462 | #elif STOP_SECTION_DATA_CONST_64 463 | 464 | #pragma arm section //Default section 465 | #pragma pack(8) //Default aligenment 466 | #undef STOP_SECTION_DATA_CONST_64 467 | #undef MEMMAP_ERROR 468 | 469 | #endif 470 | /********************************/ 471 | /**********************Code Section**********************/ 472 | /*Start*/ 473 | #ifdef START_SEC_CODE_LOCAL 474 | 475 | #pragma arm section code="Code_Section" //define a code section 476 | #undef START_SEC_CODE_LOCAL 477 | #undef MEMMAP_ERROR 478 | 479 | #endif 480 | /*Stop*/ 481 | #ifdef STOP_START_SEC_CODE_LOCAL 482 | 483 | #pragma arm section //Default section 484 | #undef STOP_START_SEC_CODE_LOCAL 485 | #undef MEMMAP_ERROR 486 | 487 | #endif 488 | /********************************/ 489 | -------------------------------------------------------------------------------- /Common/Platform_Types.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Written by : Bebo 4 | DATE : 1/9/2019 5 | AUTOSAR Version : 4.3.1 6 | DOC Name : AUTOSAR_SWS_PlatformTypes.pdf 7 | Target : ARM TIVA_C TM4C123GH6PM 8 | 9 | */ 10 | 11 | 12 | #ifndef PLATFORM_TYPES_H 13 | 14 | #define PLATFORM_TYPES_H 15 | 16 | 17 | /* 8.3 */ 18 | #ifndef TRUE 19 | #define TRUE 0x01u 20 | #endif 21 | 22 | #ifndef FALSE 23 | #define FALSE 0x0u 24 | #endif 25 | 26 | #define CPU_TYPE_8 8 27 | #define CPU_TYPE_16 16 28 | #define CPU_TYPE_32 32 29 | #define CPU_TYPE_64 64 30 | 31 | #define MSB_FIRST 0 32 | #define LSB_FIRST 1 33 | 34 | #define HIGH_BYTE_FIRST 0 35 | #define LOW_BYTE_FIRST 1 36 | 37 | 38 | /* 8.2 */ 39 | typedef unsigned char boolean; 40 | 41 | typedef signed char sint8; 42 | typedef unsigned char uint8; 43 | 44 | typedef signed short sint16; 45 | typedef unsigned short uint16; 46 | 47 | typedef signed long sint32; 48 | typedef unsigned long uint32; 49 | 50 | typedef signed long long sint64; 51 | typedef unsigned long long uint64; 52 | 53 | /* its 32 bit due to tiva is faster with dealing with 32 bit 54 | * but least mean it won't overflow at uint8 range but it logically used for 55 | * range < 256 */ 56 | typedef unsigned long uint8_least; 57 | typedef unsigned long uint16_least; 58 | typedef unsigned long uint32_least; 59 | 60 | typedef signed long sint8_least; 61 | typedef signed long sint16_least; 62 | typedef signed long sint32_least; 63 | 64 | typedef float float32; 65 | typedef double float64; 66 | 67 | 68 | /* 7.2 & 7.3*/ 69 | #define CPU_TYPE CPU_TYPE_32 /* 2 ARM */ 70 | #define CPU_BIT_ORDER LSB_FIRST /* 2.3.6 ARM */ 71 | #define CPU_BYTE_ORDER LOW_BYTE_FIRST /* 2.4.6 ARM */ 72 | 73 | #endif /* PLATFORM_TYPES_H */ 74 | 75 | -------------------------------------------------------------------------------- /Common/Std_Types.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Written by : Bebo 4 | DATE : 7/2/2019 5 | AUTOSAR Version : 4.3.1 6 | DOC Name : AUTOSAR_SWS_StandardTypes.pdf 7 | Target : ARM TIVA_C TM4C123GH6PM 8 | 9 | */ 10 | 11 | #ifndef STD_TYPES_H 12 | 13 | #define STD_TYPES_H 14 | 15 | #include "Platform_Types.h" 16 | #include "Compiler.h" 17 | 18 | /* 8.2 */ 19 | #ifndef STATUSTYPEDEFINED 20 | #define STATUSTYPEDEFINED 21 | #define E_OK 0x00u 22 | typedef VAR( uint8, TYPEDEF) StatusType ; /* OSEK compliance */ 23 | #endif 24 | #define E_NOT_OK 0x01u 25 | 26 | #define STD_HIGH 0x01u /* Physical state 5V or 3.3V */ 27 | #define STD_LOW 0x00u /* Physical state 0V */ 28 | 29 | #define STD_ACTIVE 0x01u /* Logical state active */ 30 | #define STD_IDLE 0x00u /* Logical state idle */ 31 | 32 | #define STD_ON 0x01u 33 | #define STD_OFF 0x00u 34 | 35 | /* 8.1 */ 36 | typedef VAR( uint8, TYPEDEF) Std_ReturnType ; 37 | 38 | typedef struct 39 | { 40 | VAR( uint16, AUTOMATIC ) vendorID ; 41 | VAR( uint16, AUTOMATIC ) moduleID ; 42 | VAR( uint8, AUTOMATIC ) sw_major_version ; 43 | VAR( uint8, AUTOMATIC ) sw_minor_version ; 44 | VAR( uint8, AUTOMATIC ) sw_patch_version ; 45 | } Std_VersionInfoType ; 46 | 47 | 48 | #endif /* STD_TYPES_H */ 49 | 50 | -------------------------------------------------------------------------------- /Os_Cfg/Os_Alarm_Cfg.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Written by : Bakr 4 | DATE : 18/2/2020 5 | AUTOSAR Version : 4.3.1 6 | DOC Name : AUTOSAR_SWS_OS.pdf 7 | Target : ARM TIVA_C TM4C123GH6PM 8 | 9 | */ 10 | 11 | 12 | 13 | #ifndef OS_CFG_OS_ALARM_CFG_H_ 14 | #define OS_CFG_OS_ALARM_CFG_H_ 15 | 16 | 17 | #define ALARM_ABSOLUTE 0x55u 18 | #define ALARM_RELATIVE 0xAAu 19 | 20 | 21 | #define ALARMS_NUMBER 2u 22 | 23 | #define ALARM_1 0u 24 | 25 | #define ALARM_ACTIVATE_TASK 0x01u 26 | #define ALARM_CALL_BACK 0x02u 27 | #define ALARM_INCREMENT_COUNTER 0x04u 28 | #define ALARM_SET_EVENT 0x08u 29 | #define ALARM_NOFUNC 0x09u 30 | 31 | #define AUTOSTART 0x55u 32 | 33 | #define ALARM_FINISHED 0x0u 34 | #define ALARM_ONESHOT 0x1u 35 | #define ALARM_CYCLIC 0x2u 36 | 37 | #define ALARM_ACTION_INC_COUNTER 0x13u 38 | #define ALARM_ACTION_ACT_TASK 0x10u 39 | #define ALARM_ACTION_CALLBACK 0x11u 40 | #define ALARM_ACTION_SET_EVENT 0x12u 41 | 42 | #define OS_ALARMS_OBJECT_CONGIFURATION \ 43 | {\ 44 | {\ 45 | .OsAlarmCounterRef = COUNTER_1\ 46 | ,\ 47 | .AlarmAction = \ 48 | {\ 49 | .ActionType = ALARM_ACTION_CALLBACK \ 50 | }\ 51 | }\ 52 | } 53 | 54 | #define OS_ALARMS_INTERNAL_OBJECT_CONFIGURATION \ 55 | {\ 56 | {\ 57 | .AlarmExpiryTickValue = 0u \ 58 | ,\ 59 | .Cycle = 0 \ 60 | ,\ 61 | .InUse = FALSE\ 62 | }\ 63 | } 64 | 65 | #endif /* OS_CFG_OS_ALARM_CFG_H_ */ 66 | -------------------------------------------------------------------------------- /Os_Cfg/Os_Cfg.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Written by : Bebo 4 | DATE : 7/2/2019 5 | AUTOSAR Version : 4.3.1 6 | DOC Name : AUTOSAR_SWS_OS.pdf 7 | Target : ARM TIVA_C TM4C123GH6PM 8 | 9 | */ 10 | 11 | 12 | 13 | #ifndef OS_CFG_OS_CFG_H_ 14 | #define OS_CFG_OS_CFG_H_ 15 | 16 | #include "Os_General_Cfg.h" 17 | #include "Os_Task_Cfg.h" 18 | #include "Os_Isr_Cfg.h" 19 | #include "Os_Resource_Cfg.h" 20 | #include "Os_Event_Cfg.h" 21 | #include "Os_Counter_Cfg.h" 22 | #include "Os_Alarm_Cfg.h" 23 | #include "Os_ScheduleTable_Cfg.h" 24 | 25 | 26 | #endif /* OS_CFG_OS_CFG_H_ */ 27 | -------------------------------------------------------------------------------- /Os_Cfg/Os_Counter_Cfg.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Written by : Bakr 4 | DATE : 18/2/2020 5 | AUTOSAR Version : 4.3.1 6 | DOC Name : AUTOSAR_SWS_OS.pdf 7 | Target : ARM TIVA_C TM4C123GH6PM 8 | 9 | */ 10 | 11 | 12 | #ifndef OS_CFG_OS_COUNTER_CFG_H_ 13 | #define OS_CFG_OS_COUNTER_CFG_H_ 14 | 15 | 16 | #define COUNTERS_NUMBER 1 17 | 18 | 19 | #define COUNTER_1 0 20 | #define COUNTER_2 1 21 | 22 | 23 | #define COUNTER_HARDWARE 0x55u 24 | #define COUNTER_SOFTWARE 0xAAu 25 | 26 | 27 | #define OS_COUNTERS_OBJECT_CONGIFURATION \ 28 | {\ 29 | {\ 30 | .OsCounterType = COUNTER_SOFTWARE \ 31 | ,\ 32 | .OsCounterTicksPerBase = 1u \ 33 | ,\ 34 | .OsCounterMaxAllowedValue = 10000u \ 35 | ,\ 36 | .OsCounterMinCycle = 0u \ 37 | }\ 38 | } 39 | 40 | #endif /* OS_CFG_OS_COUNTER_CFG_H_ */ 41 | -------------------------------------------------------------------------------- /Os_Cfg/Os_Event_Cfg.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Written by : Bebo 4 | DATE : 7/2/2019 5 | AUTOSAR Version : 4.3.1 6 | DOC Name : AUTOSAR_SWS_OS.pdf 7 | Target : ARM TIVA_C TM4C123GH6PM 8 | 9 | */ 10 | 11 | #ifndef OS_CFG_OS_EVENT_CFG_H_ 12 | #define OS_CFG_OS_EVENT_CFG_H_ 13 | 14 | 15 | #define OS_EVENTS_NUMBER 4u 16 | 17 | #define OS_EVENT_BASIC_TASK 0x00000000u 18 | 19 | #define OS_EVENT_MASK_1 0x00000001u 20 | 21 | #define OS_EVENT_MASK_2 0x00000002u 22 | 23 | #define OS_EVENT_MASK_3 0x00000004u 24 | 25 | #define OS_EVENT_MASK_4 0x00000008u 26 | 27 | 28 | 29 | #define OS_EVENTS_OBJECT_CONGIFURATION \ 30 | {\ 31 | OS_EVENT_MASK_1\ 32 | ,\ 33 | OS_EVENT_MASK_2\ 34 | ,\ 35 | OS_EVENT_MASK_3\ 36 | ,\ 37 | OS_EVENT_MASK_4\ 38 | } 39 | 40 | #endif /* OS_CFG_OS_EVENT_CFG_H_ */ 41 | -------------------------------------------------------------------------------- /Os_Cfg/Os_General_Cfg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Os_General_Cfg.h 3 | * 4 | * Created on: Feb 13, 2020 5 | * Author: ME 6 | */ 7 | 8 | #ifndef OS_CFG_OS_GENERAL_CFG_H_ 9 | #define OS_CFG_OS_GENERAL_CFG_H_ 10 | 11 | 12 | /************************************************************************************************/ 13 | 14 | 15 | /* Os */ 16 | /* 10.2.20 */ 17 | 18 | /* OsHooks */ 19 | /* 10.2.16 */ 20 | 21 | #define OS_SC1 0x00u 22 | #define OS_SC2 0x01u 23 | #define OS_SC3 0x02u 24 | #define OS_SC4 0x03u 25 | 26 | 27 | #define OS_STANDARD 0x55u 28 | #define OS_EXTENDED 0xAAu 29 | 30 | #define OS_MODE OS_EXTENDED 31 | 32 | #define APPMODE_INVALID 0xFFFFu 33 | 34 | /* list appmodes defined by user in configuration tool */ 35 | #define OSAPPMPDE_1 0X02u 36 | 37 | #define OS_APPMODES_NUMBER 2 38 | 39 | #define AUTOSTART_TASKS_NUMBER 2 40 | 41 | #define AUTOSTART_ALARMS_NUMBER 2 42 | 43 | #define AUTOSTART_TABLES_NUMBER 2 44 | 45 | 46 | 47 | /* used to define OS object */ 48 | #define OS_OS_OBJECT_CONGIFURATION \ 49 | { \ 50 | \ 51 | .OsStackMonitoring = TRUE\ 52 | ,\ 53 | .OsUseGetServiceId = FALSE\ 54 | ,\ 55 | .OsUseParameterAccess = FALSE\ 56 | ,\ 57 | .OsUseResScheduler = TRUE\ 58 | ,\ 59 | .OsErrorHook = FALSE\ 60 | ,\ 61 | .OsPostTaskHook = FALSE\ 62 | ,\ 63 | .OsPreTaskHook = FALSE\ 64 | ,\ 65 | .OsProtectionHook = FALSE\ 66 | ,\ 67 | .OsShutdownHook = FALSE\ 68 | ,\ 69 | .OsStartupHook = FALSE\ 70 | ,\ 71 | .OsNumberOfCores = 0x01u\ 72 | ,\ 73 | .OsScalabilityClass = OS_SC1\ 74 | ,\ 75 | .OsStatus = OS_EXTENDED\ 76 | \ 77 | } 78 | 79 | 80 | #define OS_APPMODES_OBJECT_CONGIFURATION \ 81 | {\ 82 | } 83 | 84 | #define OS_AUTOSTART_TASKS_OBJECT_CONGIFURATION \ 85 | {\ 86 | } 87 | 88 | 89 | #define OS_AUTOSTART_ALARMS_OBJECT_CONGIFURATION \ 90 | {\ 91 | } 92 | 93 | 94 | #define OS_AUTOSTART_TABLES_OBJECT_CONGIFURATION \ 95 | {\ 96 | } 97 | 98 | #define OS_AUTOSTART_SETTING_ALARMS_OBJECT_CONGIFURATION \ 99 | {\ 100 | } 101 | 102 | #define OS_AUTOSTART_SETTING_TABLES_OBJECT_CONGIFURATION \ 103 | {\ 104 | } 105 | 106 | /************************************************************************************************/ 107 | 108 | 109 | #endif /* OS_CFG_OS_GENERAL_CFG_H_ */ 110 | -------------------------------------------------------------------------------- /Os_Cfg/Os_Isr_Cfg.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Written by : Bebo 4 | DATE : 7/2/2019 5 | AUTOSAR Version : 4.3.1 6 | DOC Name : AUTOSAR_SWS_OS.pdf 7 | Target : ARM TIVA_C TM4C123GH6PM 8 | 9 | */ 10 | 11 | #ifndef OS_CFG_OS_ISR_CFG_H_ 12 | #define OS_CFG_OS_ISR_CFG_H_ 13 | 14 | 15 | #define ISR_CATEGORY_1 0x55u 16 | #define ISR_CATEGORY_2 0xAAu 17 | 18 | 19 | #define ISRS_NUMBER 10u 20 | 21 | #define TOTAL_ISRS_RESOURCES_NUMBER 5 22 | 23 | 24 | #define OS_ISRS_RESOURCES_OBJECT_CONGIFURATION \ 25 | {\ 26 | } 27 | 28 | 29 | #define OS_ISRS_OBJECT_CONGIFURATION \ 30 | {\ 31 | } 32 | 33 | #endif /* OS_CFG_OS_ISR_CFG_H_ */ 34 | -------------------------------------------------------------------------------- /Os_Cfg/Os_Resource_Cfg.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Written by : Bebo 4 | DATE : 7/2/2019 5 | AUTOSAR Version : 4.3.1 6 | DOC Name : AUTOSAR_SWS_OS.pdf 7 | Target : ARM TIVA_C TM4C123GH6PM 8 | 9 | */ 10 | 11 | #ifndef OS_CFG_OS_RESOURCE_CFG_H_ 12 | #define OS_CFG_OS_RESOURCE_CFG_H_ 13 | 14 | #define RESOURCE_INTERNAL 0x11u 15 | 16 | #define RESOURCE_LINKED 0x22u 17 | 18 | #define RESOURCE_STANDARD 0x44u 19 | 20 | 21 | 22 | 23 | #define OS_RESOURCES_NUMBER 5u 24 | 25 | #define OS_NO_RESOURCE_MASK 0x00000000u 26 | #define OS_RESORCE_0_MASK 0x00000001u 27 | #define OS_RESORCE_1_MASK 0x00000002u 28 | #define OS_RESORCE_2_MASK 0x00000004u 29 | #define OS_RESORCE_3_MASK 0x00000008u 30 | #define OS_RESORCE_4_MASK 0x00000010u 31 | 32 | 33 | 34 | #define OS_RESOURCE_0 0u 35 | #define OS_RESOURCE_1 1u 36 | #define OS_RESOURCE_2 2u 37 | #define OS_RESOURCE_3 3u 38 | #define OS_RESOURCE_4 4u 39 | #define OS_NO_RESOURCE 0xFFu 40 | 41 | 42 | 43 | 44 | #define OS_RESOURCES_OBJECT_CONGIFURATION \ 45 | { \ 46 | {\ 47 | .OsResourceProperty = RESOURCE_INTERNAL \ 48 | ,\ 49 | .OsResourceLinkedResourceRef = OS_NO_RESOURCE\ 50 | ,\ 51 | .OsResourcePriority = 0x04u \ 52 | }\ 53 | ,\ 54 | {\ 55 | .OsResourceProperty = RESOURCE_STANDARD \ 56 | ,\ 57 | .OsResourceLinkedResourceRef = OS_NO_RESOURCE \ 58 | ,\ 59 | .OsResourcePriority = 0x08u \ 60 | }\ 61 | ,\ 62 | {\ 63 | .OsResourceProperty = RESOURCE_STANDARD \ 64 | ,\ 65 | .OsResourceLinkedResourceRef = OS_NO_RESOURCE \ 66 | ,\ 67 | .OsResourcePriority = 0x07u \ 68 | }\ 69 | ,\ 70 | {\ 71 | .OsResourceProperty = RESOURCE_STANDARD \ 72 | ,\ 73 | .OsResourceLinkedResourceRef = OS_NO_RESOURCE \ 74 | ,\ 75 | .OsResourcePriority = 0x06u \ 76 | }\ 77 | ,\ 78 | {\ 79 | .OsResourceProperty = RESOURCE_STANDARD \ 80 | ,\ 81 | .OsResourceLinkedResourceRef = OS_NO_RESOURCE \ 82 | ,\ 83 | .OsResourcePriority = 0x05u \ 84 | }\ 85 | } 86 | 87 | 88 | #define OS_RESOURCES_PCB_OBJECT_CONGIFURATION \ 89 | {\ 90 | } 91 | 92 | #endif /* OS_CFG_OS_RESOURCE_CFG_H_ */ 93 | -------------------------------------------------------------------------------- /Os_Cfg/Os_ScheduleTable_Cfg.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Written by : Bakr 4 | DATE : 18/2/2020 5 | AUTOSAR Version : 4.3.1 6 | DOC Name : AUTOSAR_SWS_OS.pdf 7 | Target : ARM TIVA_C TM4C123GH6PM 8 | 9 | */ 10 | #ifndef OS_CFG_OS_SCHEDULETABLE_CFG_H_ 11 | #define OS_CFG_OS_SCHEDULETABLE_CFG_H_ 12 | 13 | 14 | #define TABLE_ABSOLUTE 0x55u 15 | #define TABLE_SYNCHRON 0xAAu 16 | 17 | #define IMPLICIT 0u 18 | #define EXPLICIT 1u 19 | 20 | #define SCHEDULE_TABLE_1 0 21 | #define SCHEDULE_TABLE_2 1 22 | 23 | #define TABLES_NUMBER 2 24 | #define TABLES_POINTS_NUMBER 4 25 | #define TABLES_TASKS_NUMBER 4 26 | #define TABLES_EVENTS_SET_NUMBER 0 27 | 28 | 29 | #define EMPTY_NEXT_TABLE -1 30 | 31 | #define OS_TABLESS_OBJECT_CONGIFURATION \ 32 | {\ 33 | {\ 34 | .OsScheduleTableRepeating = FALSE,\ 35 | .OsScheduleTableCounterRef = COUNTER_1,\ 36 | .ExpiryPointsNumber = 2,\ 37 | .FirstExpiryPoint = 0,\ 38 | .OsScheduleTableDuration = 2000u,\ 39 | .OsScheduleTblSyncStrategy = EXPLICIT,\ 40 | }\ 41 | ,\ 42 | {\ 43 | .OsScheduleTableRepeating = TRUE,\ 44 | .OsScheduleTableCounterRef = COUNTER_1,\ 45 | .ExpiryPointsNumber = 2,\ 46 | .FirstExpiryPoint = 2,\ 47 | .OsScheduleTableDuration = 2000u,\ 48 | .OsScheduleTblSyncStrategy = EXPLICIT,\ 49 | }\ 50 | } 51 | 52 | #define OS_TABLESS_POINTS_OBJECT_CONGIFURATION \ 53 | {\ 54 | {\ 55 | .OsScheduleTblExpPointOffset = 0,\ 56 | .PointTasks = {1,0},\ 57 | .OsScheduleTblAdjustableExpPoint = 0,\ 58 | },\ 59 | {\ 60 | .OsScheduleTblExpPointOffset = 1500,\ 61 | .PointTasks = {1,1},\ 62 | .OsScheduleTblAdjustableExpPoint = 0,\ 63 | },\ 64 | {\ 65 | .OsScheduleTblExpPointOffset = 1,\ 66 | .PointTasks = {1,2},\ 67 | .OsScheduleTblAdjustableExpPoint = 0,\ 68 | },\ 69 | {\ 70 | .OsScheduleTblExpPointOffset = 2,\ 71 | .PointTasks = {1,3},\ 72 | .OsScheduleTblAdjustableExpPoint = 0,\ 73 | },\ 74 | } 75 | /* contains id for tasks to be activated by the schedule table's points */ 76 | #define OS_TABLESS_TASKS_OBJECT_CONGIFURATION \ 77 | {\ 78 | 0,7,2,9\ 79 | } 80 | 81 | 82 | #define OS_TABLESS_TASKS_SET_OBJECT_CONGIFURATION \ 83 | {\ 84 | } 85 | 86 | #define OS_TABLESS_EVENTS_SET_OBJECT_CONGIFURATION \ 87 | {\ 88 | } 89 | 90 | 91 | #endif /* OS_CFG_OS_SCHEDULETABLE_CFG_H_ */ 92 | -------------------------------------------------------------------------------- /Os_Cfg/Os_Task_Cfg.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Written by : Bebo 4 | DATE : 7/2/2019 5 | AUTOSAR Version : 4.3.1 6 | DOC Name : AUTOSAR_SWS_OS.pdf 7 | Target : ARM TIVA_C TM4C123GH6PM 8 | 9 | */ 10 | 11 | 12 | #ifndef OS_CFG_OS_TASK_CFG_H_ 13 | #define OS_CFG_OS_TASK_CFG_H_ 14 | 15 | /**************************************************************************/ 16 | 17 | #define TASK_NON 0x55u 18 | #define TASK_FULL 0xAAu 19 | 20 | /**************************************************************************/ 21 | 22 | #define TASKS_NUMBER 14 23 | 24 | #define TASK_RED_ON 0 25 | #define TASK_GREEN_ON 1 26 | #define TASK_BLUE_ON 2 27 | #define TASK_YELLOW_ON 3 28 | #define TASK_BURBULE_ON 4 29 | #define TASK_AQUA_ON 5 30 | #define TASK_WHITE_ON 6 31 | #define TASK_RED_OFF 7 32 | #define TASK_GREEN_OFF 8 33 | #define TASK_BLUE_OFF 9 34 | #define TASK_YELLOW_OFF 10 35 | #define TASK_BURBULE_OFF 11 36 | #define TASK_AQUA_OFF 12 37 | #define TASK_WHITE_OFF 13 38 | 39 | 40 | #define TOTAL_TASKS_RESOURCES_NUMBER 2 41 | 42 | /**************************************************************************/ 43 | 44 | 45 | 46 | /* number of priorities allowed for tasks 0~7 */ 47 | #define TASK_PRIORITIES_NUMBER 8 48 | 49 | /* number of tasks allowed to have same priority + 1*/ 50 | #define TASKS_PER_PRIORITY 33 51 | 52 | /* stack size of every task in number of double words */ 53 | #define TASK_STACK_SIZE 32 54 | 55 | /* number of tasks not in suspended state max is 75*/ 56 | #define TASK_PCBS_NUMBER TASKS_NUMBER 57 | 58 | /* maximum number of tasks suspended or not allowed in the system */ 59 | #define MAX_TASKS_NUMBER 255 60 | 61 | /**************************************************************************/ 62 | 63 | /* where 0x2000.8000 is the adress of MSP which loaded form top of vector table */ 64 | #define OS_MSP_STACK_FRAME_ADDRESS (( ( volatile P2VAR( OsStackFrame_MSP, AUTOMATIC, REGSPACE ) ) 0x20008000 ) - 1 ) 65 | 66 | 67 | /**************************************************************************/ 68 | 69 | 70 | 71 | /**************************************************************************/ 72 | 73 | #define OS_TASKS_OBJECT_CONGIFURATION \ 74 | {\ 75 | {\ 76 | .OsTaskSchedule = TASK_FULL \ 77 | ,\ 78 | .OsTaskActivation = 1 \ 79 | ,\ 80 | .OsTaskPriority = 0 \ 81 | ,\ 82 | .OsTaskCeilingPriority_Internal = 0x04u \ 83 | ,\ 84 | .OsResourceRef = \ 85 | (\ 86 | OS_RESORCE_0_MASK | \ 87 | OS_RESORCE_1_MASK | \ 88 | OS_RESORCE_2_MASK | \ 89 | OS_RESORCE_3_MASK | \ 90 | OS_RESORCE_4_MASK \ 91 | )\ 92 | ,\ 93 | .OsTaskEventRef = \ 94 | (\ 95 | OS_EVENT_BASIC_TASK \ 96 | )\ 97 | }\ 98 | ,\ 99 | {\ 100 | .OsTaskSchedule = TASK_FULL \ 101 | ,\ 102 | .OsTaskActivation = 2 \ 103 | ,\ 104 | .OsTaskPriority = 1 \ 105 | ,\ 106 | .OsTaskCeilingPriority_Internal = 0x01u \ 107 | ,\ 108 | .OsResourceRef = OS_NO_RESOURCE_MASK \ 109 | ,\ 110 | .OsTaskEventRef = OS_EVENT_BASIC_TASK \ 111 | }\ 112 | ,\ 113 | {\ 114 | .OsTaskSchedule = TASK_FULL \ 115 | ,\ 116 | .OsTaskActivation = 1 \ 117 | ,\ 118 | .OsTaskPriority = 2 \ 119 | ,\ 120 | .OsTaskCeilingPriority_Internal = 0x02u \ 121 | ,\ 122 | .OsResourceRef = OS_NO_RESOURCE_MASK \ 123 | ,\ 124 | .OsTaskEventRef = OS_EVENT_BASIC_TASK \ 125 | }\ 126 | ,\ 127 | {\ 128 | .OsTaskSchedule = TASK_FULL \ 129 | ,\ 130 | .OsTaskActivation = 1 \ 131 | ,\ 132 | .OsTaskPriority = 3 \ 133 | ,\ 134 | .OsTaskCeilingPriority_Internal = 0x03u \ 135 | ,\ 136 | .OsResourceRef = OS_NO_RESOURCE_MASK \ 137 | ,\ 138 | .OsTaskEventRef = OS_EVENT_BASIC_TASK \ 139 | }\ 140 | ,\ 141 | {\ 142 | .OsTaskSchedule = TASK_FULL \ 143 | ,\ 144 | .OsTaskActivation = 1 \ 145 | ,\ 146 | .OsTaskPriority = 4 \ 147 | ,\ 148 | .OsTaskCeilingPriority_Internal = 0x04u \ 149 | ,\ 150 | .OsResourceRef = OS_NO_RESOURCE_MASK \ 151 | ,\ 152 | .OsTaskEventRef = OS_EVENT_BASIC_TASK \ 153 | }\ 154 | ,\ 155 | {\ 156 | .OsTaskSchedule = TASK_FULL \ 157 | ,\ 158 | .OsTaskActivation = 1 \ 159 | ,\ 160 | .OsTaskPriority = 5 \ 161 | ,\ 162 | .OsTaskCeilingPriority_Internal = 0x05u \ 163 | ,\ 164 | .OsResourceRef = OS_NO_RESOURCE_MASK \ 165 | ,\ 166 | .OsTaskEventRef = OS_EVENT_BASIC_TASK \ 167 | }\ 168 | ,\ 169 | {\ 170 | .OsTaskSchedule = TASK_FULL \ 171 | ,\ 172 | .OsTaskActivation = 1 \ 173 | ,\ 174 | .OsTaskPriority = 6 \ 175 | ,\ 176 | .OsTaskCeilingPriority_Internal = 0x06u \ 177 | ,\ 178 | .OsResourceRef = OS_NO_RESOURCE_MASK \ 179 | ,\ 180 | .OsTaskEventRef = OS_EVENT_BASIC_TASK \ 181 | }\ 182 | ,\ 183 | {\ 184 | .OsTaskSchedule = TASK_FULL \ 185 | ,\ 186 | .OsTaskActivation = 1 \ 187 | ,\ 188 | .OsTaskPriority = 7 \ 189 | ,\ 190 | .OsTaskCeilingPriority_Internal = 0x07u \ 191 | ,\ 192 | .OsResourceRef = OS_NO_RESOURCE_MASK \ 193 | ,\ 194 | .OsTaskEventRef = \ 195 | (\ 196 | OS_EVENT_MASK_1 | \ 197 | OS_EVENT_MASK_2 | \ 198 | OS_EVENT_MASK_3 | \ 199 | OS_EVENT_MASK_4 \ 200 | )\ 201 | }\ 202 | ,\ 203 | {\ 204 | .OsTaskSchedule = TASK_FULL \ 205 | ,\ 206 | .OsTaskActivation = 1 \ 207 | ,\ 208 | .OsTaskPriority = 7 \ 209 | ,\ 210 | .OsTaskCeilingPriority_Internal = 0x07u \ 211 | ,\ 212 | .OsResourceRef = OS_NO_RESOURCE_MASK \ 213 | ,\ 214 | .OsTaskEventRef = OS_EVENT_BASIC_TASK \ 215 | }\ 216 | ,\ 217 | {\ 218 | .OsTaskSchedule = TASK_FULL \ 219 | ,\ 220 | .OsTaskActivation = 1 \ 221 | ,\ 222 | .OsTaskPriority = 6 \ 223 | ,\ 224 | .OsTaskCeilingPriority_Internal = 0x06u \ 225 | ,\ 226 | .OsResourceRef = OS_NO_RESOURCE_MASK \ 227 | ,\ 228 | .OsTaskEventRef = OS_EVENT_BASIC_TASK \ 229 | }\ 230 | ,\ 231 | {\ 232 | .OsTaskSchedule = TASK_FULL \ 233 | ,\ 234 | .OsTaskActivation = 1 \ 235 | ,\ 236 | .OsTaskPriority = 5 \ 237 | ,\ 238 | .OsTaskCeilingPriority_Internal = 0x05u \ 239 | ,\ 240 | .OsResourceRef = OS_NO_RESOURCE_MASK \ 241 | ,\ 242 | .OsTaskEventRef = OS_EVENT_BASIC_TASK \ 243 | }\ 244 | ,\ 245 | {\ 246 | .OsTaskSchedule = TASK_FULL \ 247 | ,\ 248 | .OsTaskActivation = 1 \ 249 | ,\ 250 | .OsTaskPriority = 4 \ 251 | ,\ 252 | .OsTaskCeilingPriority_Internal = 0x04u \ 253 | ,\ 254 | .OsResourceRef = OS_NO_RESOURCE_MASK \ 255 | ,\ 256 | .OsTaskEventRef = OS_EVENT_BASIC_TASK \ 257 | }\ 258 | ,\ 259 | {\ 260 | .OsTaskSchedule = TASK_FULL \ 261 | ,\ 262 | .OsTaskActivation = 1 \ 263 | ,\ 264 | .OsTaskPriority = 3 \ 265 | ,\ 266 | .OsTaskCeilingPriority_Internal = 0x03u \ 267 | ,\ 268 | .OsResourceRef = OS_NO_RESOURCE_MASK \ 269 | ,\ 270 | .OsTaskEventRef = OS_EVENT_BASIC_TASK \ 271 | }\ 272 | ,\ 273 | {\ 274 | .OsTaskSchedule = TASK_FULL \ 275 | ,\ 276 | .OsTaskActivation = 1 \ 277 | ,\ 278 | .OsTaskPriority = 2 \ 279 | ,\ 280 | .OsTaskCeilingPriority_Internal = 0x02u \ 281 | ,\ 282 | .OsResourceRef = OS_NO_RESOURCE_MASK \ 283 | ,\ 284 | .OsTaskEventRef = OS_EVENT_BASIC_TASK \ 285 | }\ 286 | } 287 | 288 | 289 | #define TASKS_PCB_INDEX_ARRAY_CONFIGURATION \ 290 | {\ 291 | VAL_8(0xFFu),VAL_4(0xFFu),VAL_2(0xFFu)\ 292 | } 293 | 294 | #endif /* OS_CFG_OS_TASK_CFG_H_ */ 295 | -------------------------------------------------------------------------------- /Os_Headers/OsInterface_Headers/Os.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Written by : Bebo 4 | DATE : 7/2/2019 5 | AUTOSAR Version : 4.3.1 6 | DOC Name : AUTOSAR_SWS_OS.pdf 7 | Target : ARM TIVA_C TM4C123GH6PM 8 | 9 | */ 10 | 11 | #ifndef OS_HEADERS_OSINTERFACE_HEADERS_OS_H_ 12 | #define OS_HEADERS_OSINTERFACE_HEADERS_OS_H_ 13 | 14 | #include "..\..\Common\Std_Types.h" 15 | #include "..\..\Common\Os_MemMap.h" 16 | 17 | #include "..\..\Os_Cfg\Os_Cfg.h" 18 | 19 | #include "Os_General.h" 20 | #include "Os_Task.h" 21 | #include "Os_Isr.h" 22 | #include "Os_Resource.h" 23 | #include "Os_Event.h" 24 | #include "Os_Counter.h" 25 | #include "Os_Alarm.h" 26 | #include "Os_ScheduleTable.h" 27 | #include "../OsInternal_Headers/Os_Gpt_Internal.h" /* used in testing the OS in main function */ 28 | 29 | 30 | 31 | 32 | #endif /* OS_HEADERS_OSINTERFACE_HEADERS_OS_H_ */ 33 | -------------------------------------------------------------------------------- /Os_Headers/OsInterface_Headers/Os_Alarm.h: -------------------------------------------------------------------------------- 1 | /* 2 | Os_Alarm.h 3 | Written by : Bakr 4 | DATE : 18/2/2020 5 | Created on: Feb 11, 2020 6 | Author: ME 7 | */ 8 | 9 | #ifndef OS_HEADERS_OSINTERFACE_HEADERS_OS_ALARM_H_ 10 | #define OS_HEADERS_OSINTERFACE_HEADERS_OS_ALARM_H_ 11 | 12 | 13 | /* structure for storage of counter characteristics */ 14 | typedef VAR (struct, TYPEDEF) 15 | { 16 | 17 | VAR( TickType, AUTOMATIC ) ticksperbase ; 18 | 19 | VAR( TickType, AUTOMATIC ) maxallowedvalue ; 20 | 21 | VAR( TickType, AUTOMATIC ) mincycle ; 22 | 23 | 24 | } AlarmBaseType ; 25 | 26 | /* data type points to the data type AlarmBaseType */ 27 | typedef P2VAR ( AlarmBaseType ,TYPEDEF, TYPEDEF ) AlarmBaseRefType ; 28 | 29 | 30 | /* data type represents an alarm object */ 31 | typedef VAR( uint8, TYPEDEF ) AlarmType ; 32 | 33 | /************************************************************************************************/ 34 | 35 | /* - Reference to structure with constants of the alarm base 36 | 37 | - Description: The system service GetAlarmBase reads the alarm base characteristics. 38 | The return value is a structure in which the information of data type AlarmBaseType is stored. 39 | 40 | - Particularities: Allowed on task level, ISR, and in several hook routines. 41 | */ 42 | 43 | FUNC(StatusType, OS_CODE) GetAlarmBase ( AlarmType AlarmID, AlarmBaseRefType Info ) ; 44 | 45 | /**************************************************************************************************/ 46 | 47 | /* 48 | - Description: The system service GetAlarm returns the relative value in ticks before the alarm expires. 49 | - Particularities: It is up to the application to decide whether for example a CancelAlarm may still be useful. 50 | If is not in use, is not defined. 51 | Allowed on task level, ISR, and in several hook routines 52 | */ 53 | 54 | 55 | FUNC(StatusType, OS_CODE) GetAlarm ( AlarmType AlarmID, TickRefType Tick) ; 56 | 57 | /****************************************************************************************************/ 58 | 59 | /* 60 | - Description: The system service occupies the alarm element. After ticks have elapsed, 61 | the task assigned to the alarm is activated or the assigned event (only for extended tasks) 62 | is set or the alarm-callback routine is called. 63 | - NOTES: To change values of alarms already in use the alarm shall be cancelled first. 64 | If the alarm is already in use, this call will be ignored and the error E_OS_STATE is returned. 65 | Allowed on task level and in ISR, but not in hook routines. 66 | 67 | */ 68 | FUNC(StatusType, OS_CODE) SetRelAlarm ( AlarmType AlarmID, TickType increment, TickType cycle ) ; 69 | 70 | /*****************************************************************************************************/ 71 | /* 72 | - Description: The system service occupies the alarm element. When ticks are reached, 73 | the task assigned to the alarm is activated or 74 | the assigned event (only for extended tasks) is set or the alarm-callback routine is called. 75 | - NOTE: - If the absolute value is very close to the current counter value, the alarm may expire, 76 | and the task may become ready or the alarm-callback may be called before the system service returns to the user. 77 | - If the absolute value already was reached before the system call, the alarm shall only expire when the absolute value is reached again, 78 | i.e. after the next overrun of the counter. 79 | 80 | */ 81 | 82 | FUNC(StatusType, OS_CODE) SetAbsAlarm ( AlarmType AlarmID, TickType start, TickType cycle ) ; 83 | 84 | /****************************************************************************************************/ 85 | /* 86 | - Description: The system service cancels the alarm . 87 | - 88 | */ 89 | FUNC(StatusType, OS_CODE) CancelAlarm ( AlarmType AlarmID ) ; 90 | 91 | #endif /* OS_HEADERS_OSINTERFACE_HEADERS_OS_ALARM_H_ */ 92 | -------------------------------------------------------------------------------- /Os_Headers/OsInterface_Headers/Os_Counter.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Written by : Bakr 4 | DATE : 18/2/2020 5 | AUTOSAR Version : 4.3.1 6 | DOC Name : AUTOSAR_SWS_OS.pdf 7 | Target : ARM TIVA_C TM4C123GH6PM 8 | 9 | */ 10 | 11 | #ifndef OS_HEADERS_OSINTERFACE_HEADERS_OS_COUNTER_H_ 12 | #define OS_HEADERS_OSINTERFACE_HEADERS_OS_COUNTER_H_ 13 | 14 | typedef VAR( uint8, TYPEDEF ) CounterType ; 15 | 16 | 17 | typedef VAR( uint32, TYPEDEF ) TickType ; 18 | 19 | typedef P2VAR(TickType, TYPEDEF, VAR) TickRefType; 20 | 21 | 22 | 23 | FUNC( StatusType, OS_CODE) IncrementCounter( CounterType CounterID ); 24 | 25 | FUNC( StatusType, OS_CODE) GetCounterValue( CounterType CounterID, TickRefType Value ); 26 | 27 | FUNC( StatusType, OS_CODE) GetElapsedValue( CounterType CounterID, TickRefType Value, TickRefType ElapsedValue ); 28 | 29 | 30 | #endif /* OS_HEADERS_OSINTERFACE_HEADERS_OS_COUNTER_H_ */ 31 | -------------------------------------------------------------------------------- /Os_Headers/OsInterface_Headers/Os_Event.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Written by : Bebo 4 | DATE : 7/2/2019 5 | AUTOSAR Version : 4.3.1 6 | DOC Name : AUTOSAR_SWS_OS.pdf 7 | Target : ARM TIVA_C TM4C123GH6PM 8 | 9 | */ 10 | 11 | #ifndef OS_HEADERS_OSINTERFACE_HEADERS_OS_EVENT_H_ 12 | #define OS_HEADERS_OSINTERFACE_HEADERS_OS_EVENT_H_ 13 | 14 | /* Data type of the event mask */ 15 | typedef VAR( uint64, TYPEDEF ) EventMaskType ; 16 | 17 | /* Reference to an event mask */ 18 | typedef P2VAR ( EventMaskType, TYPEDEF, TYPEDEF ) EventMaskRefType ; 19 | 20 | 21 | /*****************************************************************************/ 22 | 23 | /* called from an interrupt service routine and from the task level, but not from hook routines */ 24 | /* events of task are set according to the event mask */ 25 | /* Calling SetEvent causes to be transferred to the ready state, 26 | * if it was waiting for at least one of the events specified in is invalid, E_OS_ID */ 29 | /* Referenced task is no extended task, E_OS_ACCESS */ 30 | /* Events can not be set as the referenced task is in the suspended state, E_OS_STATE */ 31 | 32 | FUNC (StatusType, OS_CODE) SetEvent ( TaskType TaskID, EventMaskType Mask ) ; 33 | 34 | /*****************************************************************************/ 35 | 36 | /* The events of the extended task calling ClearEvent are cleared according to the event mask . */ 37 | /* The system service ClearEvent is restricted to extended tasks which own the event */ 38 | /* The system service ClearEvent is restricted to extended tasks which own the event */ 39 | /* Call at interrupt level, E_OS_CALLEVEL */ 40 | 41 | FUNC (StatusType, OS_CODE) ClearEvent ( EventMaskType Mask ) ; 42 | 43 | /*****************************************************************************/ 44 | 45 | /* service returns the current state of all event bits of the task , not the events that the task is waiting for */ 46 | /* service may be called from interrupt service routines, task level and some hook routines */ 47 | /* current status of the event mask of task is copied to . */ 48 | /* Task is invalid, E_OS_ID */ 49 | /* Referenced task is not an extended task, E_OS_ACCESS */ 50 | /* Referenced task is in the suspended state, E_OS_STATE */ 51 | 52 | FUNC (StatusType, OS_CODE) GetEvent ( TaskType TaskID, EventMaskRefType Event ) ; 53 | 54 | /*****************************************************************************/ 55 | 56 | /* The state of the calling task is set to waiting, unless at least one of the events specified in has already been set. */ 57 | /* call enforces rescheduling, if the wait condition occurs. 58 | * If rescheduling takes place, the internal resource of the task is released while the task is in the waiting state. */ 59 | /* service shall only be called from the extended task owning the event */ 60 | /* Calling task is not an extended task, E_OS_ACCESS */ 61 | /* Calling task occupies resources, E_OS_RESOURCE */ 62 | /* Call at interrupt level, E_OS_CALLEVEL */ 63 | 64 | FUNC (StatusType, OS_CODE) WaitEvent ( EventMaskType Mask ) ; 65 | 66 | /*****************************************************************************/ 67 | 68 | 69 | 70 | #endif /* OS_HEADERS_OSINTERFACE_HEADERS_OS_EVENT_H_ */ 71 | -------------------------------------------------------------------------------- /Os_Headers/OsInterface_Headers/Os_General.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Written by : Bebo 4 | DATE : 7/2/2019 5 | AUTOSAR Version : 4.3.1 6 | DOC Name : AUTOSAR_SWS_OS.pdf 7 | Target : ARM TIVA_C TM4C123GH6PM 8 | 9 | */ 10 | 11 | #ifndef OS_HEADERS_OSINTERFACE_HEADERS_OS_GENERAL_H_ 12 | #define OS_HEADERS_OSINTERFACE_HEADERS_OS_GENERAL_H_ 13 | 14 | 15 | /*********************************************************************************************************/ 16 | 17 | 18 | /* enum type used for all status information the API services offer. Naming convention: 19 | * all errors for API services start with E_. 20 | * Those reserved for the operating system will begin with E_OS_ */ 21 | 22 | #define E_OS_ACCESS 1u 23 | #define E_OS_CALLEVEL 2u 24 | #define E_OS_ID 3u 25 | #define E_OS_LIMIT 4u 26 | #define E_OS_NOFUNC 5u 27 | #define E_OS_RESOURCE 6u 28 | #define E_OS_STATE 7u 29 | #define E_OS_VALUE 8u 30 | 31 | 32 | /* enum data type represents the application mode, max allowed modes is 8 , elements name defined by user and exist in Os_General_Cfg.h */ 33 | 34 | #define NOT_AUTOSTART 0x00u 35 | #define OSDEFAULTAPPMODE 0x01u /* Default application mode, always a valid parameter to StartOS */ 36 | typedef VAR( uint8, TYPEDEF ) AppModeType ; 37 | 38 | /*********************************************************************************************************/ 39 | 40 | 41 | /* service returns the current application mode. It may be used to write mode dependent code. */ 42 | AppModeType GetActiveApplicationMode ( void ) ; 43 | 44 | 45 | /*********************************************************************************************************/ 46 | 47 | /* The user can call this system service to start the operating system in a specific mode */ 48 | FUNC (void, OS_CODE) StartOS ( AppModeType Mode ) ; 49 | 50 | 51 | /*********************************************************************************************************/ 52 | 53 | /* user can call this system service to abort the overall system (e.g. emergency off). 54 | * The operating system also calls this function internally, 55 | * if it has reached an undefined internal state and is no longer ready to run. */ 56 | FUNC (void, OS_CODE) ShutdownOS ( StatusType Error ) ; 57 | 58 | /*********************************************************************************************************/ 59 | 60 | 61 | #endif /* OS_HEADERS_OSINTERFACE_HEADERS_OS_GENERAL_H_ */ 62 | -------------------------------------------------------------------------------- /Os_Headers/OsInterface_Headers/Os_Isr.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Created by : Ahmad HEGAZY 4 | DATE : 15/2/2019 5 | AUTOSAR Version : 4.3.1 6 | DOC Name : AUTOSAR_SWS_OS.pdf 7 | OSEK/VDX.pdf 8 | Target : ARM TIVA_C TM4C123GH6PM 9 | 10 | */ 11 | 12 | #ifndef OS_HEADERS_OSINTERFACE_HEADERS_OS_ISR_H_ 13 | #define OS_HEADERS_OSINTERFACE_HEADERS_OS_ISR_H_ 14 | 15 | 16 | /*********************************************************************************************************/ 17 | 18 | /* All possible interrupt service routines IDs */ 19 | 20 | #define INVALID_ISR 0xFFu 21 | #define GPIOPortA_ISRID 0x01u 22 | #define GPIOPortB_ISRID 0x02u 23 | #define GPIOPortC_ISRID 0x03u 24 | #define GPIOPortD_ISRID 0x04u 25 | #define GPIOPortE_ISRID 0x05u 26 | #define UART0_ISRID 0x06u 27 | #define UART1_ISRID 0x07u 28 | #define SSI0_ISRID 0x08u 29 | #define I2C0_ISRID 0x09u 30 | #define PWMFault_ISRID 0x0au 31 | #define PWMGen0_ISRID 0x0bu 32 | #define PWMGen1_ISRID 0x0cu 33 | #define PWMGen2_ISRID 0x0du 34 | #define QEI0_ISRID 0x0eu 35 | #define ADCSeq0_ISRID 0x0fu 36 | #define ADCSeq1_ISRID 0x10u 37 | #define ADCSeq2_ISRID 0x12u 38 | #define ADCSeq3_ISRID 0x13u 39 | #define Watchdog_ISRID 0x14u 40 | #define Timer0A_ISRID 0x15u 41 | #define Timer0B_ISRID 0x16u 42 | #define Timer1A_ISRID 0x17u 43 | #define Timer1B_ISRID 0x18u 44 | #define Timer2A_ISRID 0x19u 45 | #define Timer2B_ISRID 0x1au 46 | #define Comp0_ISRID 0x1bu 47 | #define Comp1_ISRID 0x1cu 48 | #define Comp2_ISRID 0x1du 49 | #define SysCtrl_ISRID 0x1eu 50 | #define FlashCtrl_ISRID 0x1fu 51 | #define GPIOPortF_ISRID 0x20u 52 | #define GPIOPortG_ISRID 0x21u 53 | #define GPIOPortH_ISRID 0x22u 54 | #define UART2_ISRID 0x23u 55 | #define SSI1_ISRID 0x24u 56 | #define Timer3A_ISRID 0x25u 57 | #define Timer3B_ISRID 0x26u 58 | #define I2C1_ISRID 0x27u 59 | #define QEI1_ISRID 0x28u 60 | #define CAN0_ISRID 0x29u 61 | #define CAN1_ISRID 0x2au 62 | #define CAN2_ISRID 0x2bu 63 | #define Hibernate_ISRID 0x2cu 64 | #define USB0_ISRID 0x2du 65 | #define PWMGen3_ISRID 0x2eu 66 | #define uDMAST_ISRID 0x2fu 67 | #define uDMAError_ISRID 0x30u 68 | #define ADC1Seq0_ISRID 0x31u 69 | #define ADC1Seq1_ISRID 0x32u 70 | #define ADC1Seq2_ISRID 0x33u 71 | #define ADC1Seq3_ISRID 0x34u 72 | #define GPIOPortJ_ISRID 0x35u 73 | #define GPIOPortK_ISRID 0x36u 74 | #define GPIOPortL_ISRID 0x37u 75 | #define SSI2_ISRID 0x38u 76 | #define SSI3_ISRID 0x39u 77 | #define UART3_ISRID 0x3au 78 | #define UART4_ISRID 0x3bu 79 | #define UART5_ISRID 0x3cu 80 | #define UART6_ISRID 0x3du 81 | #define UART7_ISRID 0x3eu 82 | #define I2C2_ISRID 0x3fu 83 | #define I2C3_ISRID 0x40u 84 | #define Timer4A_ISRID 0x41u 85 | #define Timer4B_ISRID 0x42u 86 | #define Timer5A_ISRID 0x43u 87 | #define Timer5B_ISRID 0x44u 88 | #define WideTimer0A_ISRID 0x45u 89 | #define WideTimer0B_ISRID 0x46u 90 | #define WideTimer1A_ISRID 0x47u 91 | #define WideTimer1B_ISRID 0x48u 92 | #define WideTimer2A_ISRID 0x49u 93 | #define WideTimer2B_ISRID 0x4au 94 | #define WideTimer3A_ISRID 0x4bu 95 | #define WideTimer3B_ISRID 0x4cu 96 | #define WideTimer4A_ISRID 0x4du 97 | #define WideTimer4B_ISRID 0x4eu 98 | #define WideTimer5A_ISRID 0x4fu 99 | #define WideTimer5B_ISRID 0x50u 100 | #define FPU_ISRID 0x51u 101 | #define I2C4_ISRID 0x52u 102 | #define I2C5_ISRID 0x53u 103 | #define GPIOPortM_ISRID 0x54u 104 | #define GPIOPortN_ISRID 0x55u 105 | #define QEI2_ISRID 0x56u 106 | #define GPIOPortP0_ISRID 0x57u 107 | #define GPIOPortP1_ISRID 0x58u 108 | #define GPIOPortP2_ISRID 0x59u 109 | #define GPIOPortP3_ISRID 0x5au 110 | #define GPIOPortP4_ISRID 0x5bu 111 | #define GPIOPortP5_ISRID 0x5cu 112 | #define GPIOPortP6_ISRID 0x5du 113 | #define GPIOPortP7_ISRID 0x5eu 114 | #define GPIOPortQ0_ISRID 0x5fu 115 | #define GPIOPortQ1_ISRID 0x60u 116 | #define GPIOPortQ2_ISRID 0x61u 117 | #define GPIOPortQ3_ISRID 0x62u 118 | #define GPIOPortQ4_ISRID 0x63u 119 | #define GPIOPortQ5_ISRID 0x64u 120 | #define GPIOPortQ6_ISRID 0x65u 121 | #define GPIOPortQ7_ISRID 0x66u 122 | #define GPIOPortR_ISRID 0x67u 123 | #define GPIOPortS_ISRID 0x68u 124 | #define PWM1Gen0_ISRID 0x69u 125 | #define PWM1Gen1_ISRID 0x6au 126 | #define PWM1Gen2_ISRID 0x6bu 127 | #define PWM1Gen3_ISRID 0x6cu 128 | #define PWM1Fault_ISRID 0x6du 129 | 130 | /* enum data type identifies an interrupt service routine (ISR). */ 131 | typedef VAR( uint8, TYPEDEF ) ISRType ; 132 | 133 | /* 134 | Within the application, an interrupt service routine of category 2 is defined according to the following pattern: 135 | ISR (FuncName) 136 | { 137 | } 138 | The keyword ISR is evaluated by the system generation to clearly distinguish between func-tions and interrupt service routines in the source code. 139 | */ 140 | #define ISR( FuncName ) FUNC(void, OS_CODE) FuncName (void) 141 | 142 | /* This service returns the identifier of the currently executing ISR.*/ 143 | FUNC(ISRType, AUTOMATIC) GetISRID( void ); 144 | /*This service restores the state saved by DisableAllInterrupts.*/ 145 | FUNC(StatusType, AUTOMATIC) EnableAllInterrupts(void); 146 | /*This service disables all interrupts for which the hardware supports disabling. The state before is saved for the EnableAllInterrupts call.*/ 147 | FUNC(StatusType, AUTOMATIC) DisableAllInterrupts(void); 148 | /* This service restores the recognition status of all interrupts saved by the SuspendAllInterrupts service. */ 149 | FUNC(StatusType, AUTOMATIC) ResumeAllInterrupts(void); 150 | /*This service saves the recognition status of all interrupts and disables all interrupts for which the hardware supports disabling.*/ 151 | FUNC(StatusType, AUTOMATIC) SuspendAllInterrupts(void); 152 | /*This service restores the recognition status of interrupts saved by the SuspendOSInterrupts service.*/ 153 | FUNC(StatusType, AUTOMATIC) ResumeOSInterrupts(void); 154 | /* This service saves the recognition status of interrupts of category 2 and disables the recognition of these interrupts.*/ 155 | FUNC(StatusType, AUTOMATIC) SuspendOSInterrupts(void); 156 | 157 | 158 | 159 | /*********************************************************************************************************/ 160 | 161 | #endif /* OS_HEADERS_OSINTERFACE_HEADERS_OS_ISR_H_ */ 162 | -------------------------------------------------------------------------------- /Os_Headers/OsInterface_Headers/Os_Resource.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Written by : Bebo 4 | DATE : 7/2/2019 5 | AUTOSAR Version : 4.3.1 6 | DOC Name : AUTOSAR_SWS_OS.pdf 7 | Target : ARM TIVA_C TM4C123GH6PM 8 | 9 | */ 10 | 11 | #ifndef OS_HEADERS_OSINTERFACE_HEADERS_OS_RESOURCE_H_ 12 | #define OS_HEADERS_OSINTERFACE_HEADERS_OS_RESOURCE_H_ 13 | 14 | 15 | /* Data type for a resource */ 16 | typedef VAR( uint8, TYPEDEF ) ResourceType ; 17 | 18 | 19 | /* call serves to enter critical sections in the code that are assigned to the resource referenced by . 20 | * A critical section shall always be left using ReleaseResource */ 21 | /* Nested resource occupation is only allowed 22 | * if the inner critical sections are completely executed within the surrounding critical section 23 | * by order LIFO last resource to get is the first to out */ 24 | /* Nested occupation of one and the same resource is also forbidden!*/ 25 | /* recommended that corresponding calls to GetResource and ReleaseResource appear within the same function */ 26 | /* not allowed to use services which are points of rescheduling for non preemptable tasks in resources critical section 27 | * this points is TerminateTask, WaitTask, ChainTask, Schedule */ 28 | /* critical sections are to be left before completion of an interrupt service routine */ 29 | /* critical sections should be short */ 30 | /* service may be called from an ISR and from task leve */ 31 | /* Resource is invalid, E_OS_ID */ 32 | /* get a resource which is already occupied by any task or ISR, or the statically assigned priority of the calling task or 33 | interrupt routine is higher than the calculated ceiling priority, E_OS_ACCESS*/ 34 | 35 | FUNC (StatusType, OS_CODE) GetResource ( ResourceType ResID ) ; 36 | 37 | 38 | /* ReleaseResource is the counterpart of GetResource and serves to 39 | * leave critical sections in the code that are assigned to the resource referenced by . */ 40 | /* The service may be called from an ISR and from task level */ 41 | /* Resource is invalid, E_OS_ID */ 42 | /* Attempt to release a resource which is not occupied by any task or ISR, or another resource shall be released before, E_OS_NOFUNC*/ 43 | /* Attempt to release a resource which has a lower ceiling priority than 44 | * the statically assigned priority of the calling task or interrupt routine, E_OS_ACCESS */ 45 | 46 | FUNC (StatusType, OS_CODE) ReleaseResource ( ResourceType ResID ) ; 47 | 48 | 49 | 50 | #endif /* OS_HEADERS_OSINTERFACE_HEADERS_OS_RESOURCE_H_ */ 51 | -------------------------------------------------------------------------------- /Os_Headers/OsInterface_Headers/Os_ScheduleTable.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Written by : Bakr 4 | DATE : 18/2/2020 5 | AUTOSAR Version : 4.3.1 6 | DOC Name : AUTOSAR_SWS_OS.pdf 7 | Target : ARM TIVA_C TM4C123GH6PM 8 | 9 | */ 10 | 11 | #ifndef OS_HEADERS_OSINTERFACE_HEADERS_OS_SCHEDULETABLE_H_ 12 | #define OS_HEADERS_OSINTERFACE_HEADERS_OS_SCHEDULETABLE_H_ 13 | 14 | /*********************************************************************************************************/ 15 | 16 | 17 | typedef VAR( uint8, TYPEDEF ) ScheduleTableType ; 18 | 19 | 20 | /* describes the status of a schedule. The status can be one of the following */ 21 | #define SCHEDULETABLE_STOPPED 0x00u /* SCHEDULETABLE_RUNNING_AND_SYNCHRONOUS */ 22 | #define SCHEDULETABLE_NEXT 0x44u /* will be started after the end of currently running schedule table */ 23 | #define SCHEDULETABLE_RUNNING 0xCCu /* table is running, but is currently not synchronous to a global time source*/ 24 | 25 | typedef VAR( uint8, TYPEDEF ) ScheduleTableStatusType ; 26 | 27 | /* data type points to a variable of the data type ScheduleTableStatusType */ 28 | typedef P2VAR( ScheduleTableStatusType, TYPEDEF, TYPEDEF ) ScheduleTableStatusRefType ; 29 | 30 | 31 | /*********************************************************************************************************/ 32 | 33 | FUNC(StatusType, OS_CODE) StartScheduleTableRel( ScheduleTableType ScheduleTableID, TickType Offset ); 34 | 35 | FUNC( StatusType, OS_CODE ) StartScheduleTableAbs( ScheduleTableType ScheduleTableID, TickType Start ); 36 | 37 | FUNC( StatusType, OS_CODE ) StopScheduleTable( ScheduleTableType ScheduleTableID ); 38 | 39 | FUNC( StatusType, OS_CODE ) NextScheduleTable( ScheduleTableType ScheduleTableID_From, ScheduleTableType ScheduleTableID_To ); 40 | 41 | FUNC( StatusType, OS_CODE ) GetScheduleTableStatus( ScheduleTableType ScheduleTableID, ScheduleTableStatusRefType ScheduleStatus ); 42 | #endif /* OS_HEADERS_OSINTERFACE_HEADERS_OS_SCHEDULETABLE_H_ */ 43 | -------------------------------------------------------------------------------- /Os_Headers/OsInterface_Headers/Os_Task.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AU20GradProject/OS/8c693b006dd1c926e856cfe32eb944fff8964a7d/Os_Headers/OsInterface_Headers/Os_Task.h -------------------------------------------------------------------------------- /Os_Headers/OsInternal_Headers/Os_Alarm_Internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Written by : Bakr 4 | DATE : 18/2/2020 5 | AUTOSAR Version : 4.3.1 6 | DOC Name : AUTOSAR_SWS_OS.pdf 7 | Target : ARM TIVA_C TM4C123GH6PM 8 | 9 | */ 10 | 11 | #ifndef OS_HEADERS_OSINTERNAL_HEADERS_OS_ALARM_INTERNAL_H_ 12 | #define OS_HEADERS_OSINTERNAL_HEADERS_OS_ALARM_INTERNAL_H_ 13 | 14 | /***************************************************************/ 15 | 16 | 17 | typedef struct 18 | { 19 | /* Reference to the task that event will be set to by the alarm */ 20 | VAR( TaskType, AUTOMATIC ) OsAlarmSetEventTaskRef ; 21 | 22 | 23 | /* Reference to the event in case of expiration action is setting event */ 24 | VAR( EventMaskType, AUTOMATIC ) OsAlarmSetEventRef ; 25 | 26 | } OsAlarmSetEvent ; 27 | 28 | /* 29 | Internal Function to check alarms waiting on Counter ID value for expiring by searching for alarms with CounterID 30 | and checking the tick value for expiry with OsCounterInternal OsCounterVal 31 | */ 32 | 33 | /***************************************************************/ 34 | 35 | typedef union 36 | { 37 | 38 | /* Reference to the counter that will be incremented by that alarm action */ 39 | VAR( CounterType, AUTOMATIC ) OsAlarmIncrementCounterRef ; 40 | 41 | /* Reference to the task that will be activated by that alarm action */ 42 | VAR( TaskType, AUTOMATIC ) OsAlarmActivateTaskRef ; 43 | 44 | /* Name of the function that is called when this alarm callback is triggered. */ 45 | P2FUNC( void, AUTOMATIC, OsAlarmCallbackName ) (void) ; 46 | 47 | VAR( OsAlarmSetEvent, AUTOMATIC ) AlarmEvent ; 48 | 49 | } OsAlarmActions ; 50 | 51 | typedef struct{ 52 | 53 | /* Enum holds ID for action taken on alarm expiry */ 54 | VAR (uint8, AUTOMATIC) ActionType; /* Actions*/ 55 | 56 | /* Action to be executed on alarm expiry */ 57 | VAR (OsAlarmActions, AUTOMATIC) Action; 58 | 59 | } OsAlarmAction; 60 | 61 | /***************************************************************/ 62 | 63 | typedef struct 64 | { 65 | 66 | /* Reference to application modes in which that alarm is activated on startup of the OS , as a mask for modes of this task 67 | * if = NOT_AUTOSTART then it won't be in autostart */ 68 | VAR( uint8, AUTOMATIC ) OsAlarmAppModeRef ; 69 | 70 | /* specifies the type of autostart for the alarm absolute or relative */ 71 | VAR( uint8, AUTOMATIC ) OsAlarmAutostartType ; 72 | 73 | /* relative or absolute tick value when the alarm expires for the first time. 74 | * for an alarm which is RELATIVE the value must be at bigger than 0 */ 75 | VAR( TickType, AUTOMATIC ) OsAlarmAlarmTime ; 76 | 77 | /* Cycle time of a cyclic alarm in ticks. If the value is 0 than the alarm is not cyclic */ 78 | VAR( TickType, AUTOMATIC ) OsAlarmCycleTime ; 79 | 80 | } OsAlarmAutostart ; 81 | 82 | /***************************************************************/ 83 | 84 | typedef struct 85 | { 86 | 87 | /* Reference to the assigned counter for that alarm */ 88 | VAR( CounterType, AUTOMATIC ) OsAlarmCounterRef ; 89 | 90 | VAR (OsAlarmAction, AUTOMATIC ) AlarmAction ; 91 | 92 | } OsAlarm ; 93 | 94 | /**************************************************************/ 95 | 96 | typedef struct 97 | { 98 | /* Holds the value the Software/Hardware Counter will expire at 99 | either is ABSOLUTE or RELATIVE which is added to the current counter value 100 | then stored here 101 | */ 102 | VAR ( TickType, AUTOMATIC ) AlarmExpiryTickValue; 103 | 104 | /* Holds Cycle value (FINISHED,ONE_SHOT,CYCLIC) */ 105 | VAR ( TickType, AUTOMATIC ) Cycle; /* 0 if not cyclic */ 106 | 107 | VAR ( uint8 , AUTOMATIC ) InUse; 108 | 109 | } OsAlarmInternal ; 110 | 111 | /***************************************************************/ 112 | 113 | FUNC(void, OS_INTERNAL_CODE) CheckAlarmExpiry(CounterType CounterID); 114 | 115 | 116 | #endif /* OS_HEADERS_OSINTERNAL_HEADERS_OS_ALARM_INTERNAL_H_ */ 117 | -------------------------------------------------------------------------------- /Os_Headers/OsInternal_Headers/Os_Counter_Internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Written by : Bakr 4 | DATE : 18/2/2020 5 | AUTOSAR Version : 4.3.1 6 | DOC Name : AUTOSAR_SWS_OS.pdf 7 | Target : ARM TIVA_C TM4C123GH6PM 8 | 9 | */ 10 | 11 | #ifndef OS_HEADERS_OSINTERNAL_HEADERS_OS_COUNTER_INTERNAL_H_ 12 | #define OS_HEADERS_OSINTERNAL_HEADERS_OS_COUNTER_INTERNAL_H_ 13 | 14 | 15 | 16 | /*******************************************************************/ 17 | 18 | typedef struct 19 | { 20 | /* enum contains the natural type or unit of the counter. */ 21 | VAR( CounterType, AUTOMATIC ) OsCounterType ; 22 | 23 | /* specifies the number of ticks required to reach a counterspecific unit. 24 | * The interpretation is implementation-specific */ 25 | VAR( TickType, AUTOMATIC ) OsCounterTicksPerBase ; 26 | 27 | /* Maximum possible allowed value of the system counter in ticks */ 28 | VAR( TickType, AUTOMATIC ) OsCounterMaxAllowedValue ; 29 | 30 | /* specifies the minimum allowed number of counter ticks for a cyclic alarm linked to the counter */ 31 | VAR( TickType, AUTOMATIC ) OsCounterMinCycle ; 32 | 33 | } OsCounter ; 34 | 35 | /*******************************************************************/ 36 | typedef struct 37 | { 38 | /* Contains the current value of the counter */ 39 | VAR( TickType , AUTOMATIC ) OsCounterVal; 40 | 41 | /* Incremented at each system tick until it reaches OsCounterTicksPerBase value this OsCounter Value is Incremented */ 42 | VAR( TickType , AUTOMATIC ) OsCounterTicksValue; 43 | 44 | } OsCounterInternal; 45 | 46 | typedef P2VAR(OsCounterInternal, TYPDEF,TYPDEF) OsCounterRefInternal; 47 | 48 | typedef P2CONST(OsCounter, TYPEDEF,TYPEDEF) OsCounterRef; 49 | 50 | 51 | #endif /* OS_COUNTER_INTERNAL_H_ */ 52 | -------------------------------------------------------------------------------- /Os_Headers/OsInternal_Headers/Os_Event_Internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Written by : Bebo 4 | DATE : 7/2/2019 5 | AUTOSAR Version : 4.3.1 6 | DOC Name : AUTOSAR_SWS_OS.pdf 7 | Target : ARM TIVA_C TM4C123GH6PM 8 | 9 | */ 10 | 11 | #ifndef OS_HEADERS_OSINTERNAL_HEADERS_OS_EVENT_INTERNAL_H_ 12 | #define OS_HEADERS_OSINTERNAL_HEADERS_OS_EVENT_INTERNAL_H_ 13 | 14 | 15 | 16 | #endif /* OS_HEADERS_OSINTERNAL_HEADERS_OS_EVENT_INTERNAL_H_ */ 17 | -------------------------------------------------------------------------------- /Os_Headers/OsInternal_Headers/Os_ExternalVariables.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Written by : Bebo 4 | DATE : 7/2/2019 5 | AUTOSAR Version : 4.3.1 6 | DOC Name : AUTOSAR_SWS_OS.pdf 7 | Target : ARM TIVA_C TM4C123GH6PM 8 | 9 | */ 10 | 11 | 12 | #ifndef OS_HEADERS_OSINTERNAL_HEADERS_OS_EXTERNAL_VARIABLES_H_ 13 | #define OS_HEADERS_OSINTERNAL_HEADERS_OS_EXTERNAL_VARIABLES_H_ 14 | 15 | /**************************************************************************/ 16 | 17 | 18 | extern CONSTP2FUNC( void, OS_CONFIG_DATA, OsTasksNames_Array [TASKS_NUMBER] ) (void) ; 19 | 20 | 21 | /**************************************************************************/ 22 | /* used for define OS object in the system */ 23 | extern CONST( OsOS, OS_CONFIG_DATA ) OS ; 24 | 25 | /* represent configuration data of every app mode Auto start hold informations of Auto start tasks,alarms,schedule tables */ 26 | extern CONST( OsAppMode, OS_CONFIG_DATA ) OsAppModes_Array[ OS_APPMODES_NUMBER ] ; 27 | 28 | 29 | /* hold all tasks' IDs that will be activated in Auto start in all APP modes ordered by order of APP modes */ 30 | extern CONST( TaskType, OS_CONFIG_DATA ) OsAutoStartTasks_Array [ AUTOSTART_TASKS_NUMBER ] ; 31 | 32 | 33 | /* hold all alarms' IDs that will be activated in Auto start in all APP modes ordered by order of APP modes */ 34 | extern CONST( AlarmType, OS_CONFIG_DATA ) OsAutoStartAlarms_Array [ AUTOSTART_ALARMS_NUMBER ] ; 35 | 36 | /* hold all alarms' auto start settings that will be activated in Auto start in all APP modes ordered by order of APP modes */ 37 | extern CONST( OsAlarmAutostart, OS_CONFIG_DATA ) OsAutoStartAlarms_SettingArray [ AUTOSTART_ALARMS_NUMBER ] ; 38 | 39 | 40 | /* hold all ScheduleTables' IDs that will be activated in Auto start in all APP modes ordered by order of APP modes */ 41 | extern CONST( ScheduleTableStatusType, OS_CONFIG_DATA ) OsAutoStartTabless_Array [ AUTOSTART_TABLES_NUMBER ] ; 42 | 43 | /* hold all tables' auto start settings that will be activated in Auto start in all APP modes ordered by order of APP modes */ 44 | extern CONST( OsScheduleTableAutostart, OS_CONFIG_DATA ) OsAutoStartTables_SettingArray [ AUTOSTART_TABLES_NUMBER ] ; 45 | 46 | 47 | /* used to save app mode used inside system and passed to StartOS service */ 48 | extern VAR( AppModeType, OS_CONFIG_DATA ) AppMode ; 49 | 50 | /**************************************************************************/ 51 | 52 | /* used to take a copy of ReadyTaskPCB_Index inside dispatcher */ 53 | extern VAR ( uint8, OS_VAR_CLEARED ) DispatcherLocal_Variable ; 54 | 55 | /**************************************************************************/ 56 | 57 | /* represent configuration data of every task */ 58 | extern CONST( OsTask, OS_CONFIG_DATA ) OsTasks_Array [ TASKS_NUMBER ] ; 59 | 60 | /* array of PCBs of not suspended tasks*/ 61 | extern VAR( OsTask_PCB, OS_VAR_CLEARED ) OsTasksPCB_Array [ TASK_PCBS_NUMBER ] ; 62 | 63 | /* used to scheduling and determine next running task, every element carry the index of task PCB in OsTasksPCB_Array 64 | * OsTasksPriority_Array [ 0 ] is array of tasks' PCB index */ 65 | extern VAR( uint8, OS_VAR_INIT ) OsTasksPriority_Array [ TASK_PRIORITIES_NUMBER ] [ TASKS_PER_PRIORITY] ; 66 | 67 | /* used to carry index of first element in OsTasksPriority_Array, 68 | * this element will be chosen for running if its array priority is currently largest priority */ 69 | extern VAR( uint8, OS_VAR_CLEARED) OsTasksPriorityIndex_Array [TASK_PRIORITIES_NUMBER] ; 70 | 71 | /* used to carry index of available element to the newly coming task to OsTasksPriority_Array 72 | * OsTasksPriorityNext_Array [0] = x, determine index of OsTasksPriority_Array [ 0 ][x] to carry the PCB index to new task of priority 0 */ 73 | extern VAR( uint8, OS_VAR_CLEARED) OsTasksPriorityNext_Array [TASK_PRIORITIES_NUMBER] ; 74 | 75 | /* used to carry PCB index of all tasks 76 | * OsTasksPCB_Index_Array[ TaskId ] will return index of PCB of this task OsTasksPCB_Array in if not suspended */ 77 | extern VAR( uint8, OS_VAR_INIT) OsTasksPCB_Index_Array [ TASKS_NUMBER ] ; 78 | 79 | /* carry the highest priority of all current ready/running tasks 80 | * depending on it ReadyTaskPCB_Index will determined */ 81 | extern VAR ( uint8, OS_VAR_INIT ) ReadyHighestPriority ; 82 | 83 | 84 | /* carry PCB index of ready task that will preempt currently running task */ 85 | extern VAR ( uint8, OS_VAR_INIT ) ReadyTaskPCB_Index ; 86 | 87 | /* carry the PCB index of currently running task */ 88 | extern VAR ( uint8, OS_VAR_INIT ) RunningTaskPCB_Index ; 89 | 90 | /* used in context swithcing and preemption to easily modify value of stack frame */ 91 | extern volatile CONSTP2VAR ( OsStackFrame_MSP, OS_VAR_INIT, OS_APPL_CONST ) OsMSP_StackFrame_ptr ; 92 | 93 | /* used in context swithcing and preemption to easily modify value of stack frame */ 94 | extern volatile P2VAR ( OsStackFrame_PSP, OS_VAR_CLEARED, OS_APPL_CONST ) OsPSP_StackFrame_ptr ; 95 | 96 | extern VAR ( uint8, OS_VAR_CLEARED ) NotSuspendedTasks_Number ; 97 | 98 | /* used to indicate current policy used in scheduling for running task preemptive or not */ 99 | extern VAR ( uint8, OS_VAR_INIT ) SchedulingPolicy ; 100 | 101 | /* used inside dispatcher to take a copy of task ceiling priority */ 102 | extern VAR ( uint8, OS_VAR_CLEARED ) CeilingPriority ; 103 | 104 | 105 | /**************************************************************************/ 106 | 107 | 108 | /* used to carry ISR_ID of current runnign ISR, set at the beginning of the ISR 109 | if no ISR is active, INVALID_ISR is the default value. */ 110 | extern VAR( ISRType, OS_VAR_CLEARED ) IsrID ; 111 | 112 | 113 | /* represent configuration data of every task */ 114 | extern VAR( OsIsr, OS_CONFIG_DATA ) OsIsr_Array [ ISRS_NUMBER ] ; 115 | 116 | 117 | /**************************************************************************/ 118 | /* used to carry HOOK_ID of current runnign Hook routine */ 119 | extern VAR( HOOKType, OS_VAR_CLEARED ) HookID ; 120 | 121 | /**************************************************************************/ 122 | 123 | /* used to define events configurations */ 124 | extern CONST( EventMaskType, OS_CONFIG_DATA ) OsEvents_Array [ OS_EVENTS_NUMBER ] ; 125 | 126 | /**************************************************************************/ 127 | 128 | /* define configurations of resources in system */ 129 | extern CONST( OsResource, OS_CONFIG_DATA ) OsResource_Array [ OS_RESOURCES_NUMBER ] ; 130 | 131 | /* define array contain all resources PCBs with index of thier id */ 132 | extern VAR( OsResource_PCB, OS_VAR_INIT) OsResourcePCB_Array [ OS_RESOURCES_NUMBER ] ; 133 | 134 | extern VAR( boolean, OS_VAR_INIT) OsResource_CS_Flag ; 135 | 136 | 137 | 138 | /**************************************************************************/ 139 | 140 | 141 | /* used to counter Alarms configurations */ 142 | extern CONST( OsCounter, OS_CONFIG_DATA ) OsCounter_Array [ COUNTERS_NUMBER ] ; 143 | 144 | extern VAR( OsCounterInternal, OS_DATA) OsCounterInternal_Array [COUNTERS_NUMBER ]; 145 | 146 | /**************************************************************************/ 147 | 148 | /* used to define Alarms configurations */ 149 | extern CONST( OsAlarm, OS_CONFIG_DATA ) OsAlarm_Array [ ALARMS_NUMBER ]; 150 | 151 | extern VAR( OsAlarmInternal, OS_CONFIG_DATA ) OsAlarmInternal_Array [ALARMS_NUMBER]; 152 | 153 | /**************************************************************************/ 154 | 155 | 156 | /* define configuration of schedule tables in system */ 157 | extern CONST( OsScheduleTable, OS_CONFIG_DATA ) ScheduleTable_Array [ TABLES_NUMBER ] ; 158 | 159 | /* define configuration of expiry points in system */ 160 | extern CONST( OsScheduleTableExpiryPoint, OS_CONFIG_DATA ) ScheduleTablePoints_Array [ TABLES_POINTS_NUMBER ] ; 161 | 162 | /* define configuration of tasks to be activated by tables in system */ 163 | extern CONST( TaskType, OS_CONFIG_DATA ) ScheduleTableTaskActivation_Array [ TABLES_TASKS_NUMBER ] ; 164 | 165 | /* define configuration of tasks to be set its events by tables in system */ 166 | extern CONST( TaskType, OS_CONFIG_DATA ) ScheduleTableTaskSet_Array [ TABLES_EVENTS_SET_NUMBER ] ; 167 | 168 | /* define configuration of events to be set by tables in system */ 169 | extern CONST( EventMaskType, OS_CONFIG_DATA ) ScheduleTableEventSet_Array [ TABLES_EVENTS_SET_NUMBER ]; 170 | 171 | extern VAR( OsScheduleTableInternal, OS_DATA ) ScheduleTableInternal_Array [ TABLES_NUMBER ] ; 172 | 173 | extern VAR( ExpiryPointOffset, OS_DATA ) ScheduleTablePointsOffsets_Array[TABLES_POINTS_NUMBER ]; 174 | 175 | /**************************************************************************/ 176 | 177 | /* PEND status store variables used in Os_Isr */ 178 | extern VAR(uint32, AUTOMATIC) PEND0; 179 | extern VAR(uint32, AUTOMATIC) PEND1; 180 | extern VAR(uint32, AUTOMATIC) PEND2; 181 | extern VAR(uint32, AUTOMATIC) PEND3; 182 | extern VAR(uint32, AUTOMATIC) PEND4; 183 | 184 | 185 | /* Variable contains the called interrupt disable function, if no function is called default value is NoDisableActive*/ 186 | extern VAR(ActiveIsrDisableType, AUTOMATIC) ActiveIsrDisable; 187 | 188 | extern VAR(uint8, AUTOMATIC) suspendCount; 189 | 190 | 191 | /**************************************************************************/ 192 | 193 | 194 | #endif /* OS_HEADERS_OSINTERNAL_HEADERS_OS_EXTERNAL_VARIABLES_H_ */ 195 | -------------------------------------------------------------------------------- /Os_Headers/OsInternal_Headers/Os_General_Internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Written by : Bebo 4 | DATE : 7/2/2019 5 | AUTOSAR Version : 4.3.1 6 | DOC Name : AUTOSAR_SWS_OS.pdf 7 | Target : ARM TIVA_C TM4C123GH6PM 8 | 9 | */ 10 | 11 | #ifndef OS_HEADERS_OSINTERNAL_HEADERS_OS_GENERAL_INTERNAL_H_ 12 | #define OS_HEADERS_OSINTERNAL_HEADERS_OS_GENERAL_INTERNAL_H_ 13 | 14 | /*******************************************************************/ 15 | 16 | typedef struct 17 | { 18 | VAR( boolean, AUTOMATIC ) OsStackMonitoring ; /* Select stack monitoring of Tasks/Category 2 ISRs (true: Stacks are monitored) */ 19 | VAR( boolean, AUTOMATIC ) OsUseGetServiceId ; /* determine whether access macros to get service id which caused last error is defined or not */ 20 | VAR( boolean, AUTOMATIC ) OsUseParameterAccess ; /* determine whether access macros to get values of parameter of service which caused last error is defined or not */ 21 | VAR( boolean, AUTOMATIC ) OsUseResScheduler ; /* defines whether the resource RES_SCHEDULER is used within the application. */ 22 | VAR( boolean, AUTOMATIC ) OsErrorHook ; /* whether Error hook as defined by OSEK called in case of error ( true: Hook is called ) */ 23 | VAR( boolean, AUTOMATIC ) OsPostTaskHook ; /* as post hook but here before old task is leave running state */ 24 | VAR( boolean, AUTOMATIC ) OsPreTaskHook ; /* as pre hook but here after new task is enter running state */ 25 | VAR( boolean, AUTOMATIC ) OsProtectionHook ; /* enable/disable the call to the (user supplied) protection hook ( true: hook is called )*/ 26 | VAR( boolean, AUTOMATIC ) OsShutdownHook ; /* as previous hooks but for hook called when shutdown is requested */ 27 | VAR( boolean, AUTOMATIC ) OsStartupHook ; /* as previous hooks but for hook called after os startup and before scheduler */ 28 | VAR( uint8, AUTOMATIC ) OsNumberOfCores ; /* Maximum number of cores that are controlled by the OS */ 29 | VAR( uint8, AUTOMATIC ) OsScalabilityClass ; /* determine supported scalability class by OS */ 30 | VAR( uint8, AUTOMATIC ) OsStatus ; /* The Status attribute specifies whether a system with standard or extended status has to be used */ 31 | 32 | } OsOS ; 33 | 34 | /*******************************************************************/ 35 | 36 | /* used to determine setting of applications modes and task & alarm which activated in AutoStart */ 37 | typedef struct 38 | { 39 | VAR( uint16, AUTOMATIC ) AutoStartTasks_Number ; /* determine number of tasks to be activated */ 40 | VAR( uint16, AUTOMATIC ) AutoStartTasks_Index ; /* determine index of first task to be activated in ,APPMODE_INVALID for no auto start tasks */ 41 | VAR( uint16, AUTOMATIC ) AutoStartAlarms_Number ; /* determine number of alarms to be activated */ 42 | VAR( uint16, AUTOMATIC ) AutoStartAlarms_Index ; /* determine index of first alarm to be activated in */ 43 | VAR( uint16, AUTOMATIC ) AutoStartScheduleTables_Number ; /* determine number of ScheduleTables to be activated */ 44 | VAR( uint16, AUTOMATIC ) AutoStartScheduleTables_Index ; /* determine index of first ScheduleTable to be activated in */ 45 | 46 | }OsAppMode ; 47 | 48 | 49 | /*******************************************************************/ 50 | 51 | 52 | #define INVALID_HOOK 0xFFU 53 | 54 | /* enum data type identifies an Hook routine. */ 55 | typedef VAR( uint8, TYPEDEF ) HOOKType ; 56 | 57 | #endif /* OS_HEADERS_OSINTERNAL_HEADERS_OS_GENERAL_INTERNAL_H_ */ 58 | -------------------------------------------------------------------------------- /Os_Headers/OsInternal_Headers/Os_Gpt_Internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | Os_Gpt.h 3 | Written by : Bakr 4 | DATE : 18/2/2020 5 | */ 6 | 7 | #ifndef OS_HEADERS_OSINTERNAL_HEADERS_OS_GPT_INTERNAL_H_ 8 | #define OS_HEADERS_OSINTERNAL_HEADERS_OS_GPT_INTERNAL_H_ 9 | 10 | /* Configurations */ 11 | #define SYSTICK_TICK_DURATION_MS 1u 12 | #define SYSTICK_ENABLE STD_ON 13 | #define SYSTICK_INT_ENABLE STD_ON 14 | #define SYSTICK_CLK_SRC CLK_SRC_PIOSC_DIV4 15 | #define SYS_TICK_PRIORITY *( ( volatile P2VAR( uint32, AUTOMATIC, REGSPACE ) ) 0xE000ED20 ) |= ( 0x01u << 29 ) 16 | 17 | 18 | /* Register addresses */ 19 | #define Systick_STCTRL (*(( volatile P2VAR( uint32, AUTOMATIC, REGSPACE ) ) 0xE000E010 )) 20 | #define Systick_STRELOAD (*(( volatile P2VAR( uint32, AUTOMATIC, REGSPACE ) ) 0xE000E014 )) 21 | #define Systick_STCURRENT (*(( volatile P2VAR( uint32, AUTOMATIC, REGSPACE ) ) 0xE000E018 )) 22 | 23 | /* Registers pin numbers */ 24 | #define ENABLE 0u 25 | #define INTEN 1u 26 | #define CLK_SRC 2u 27 | #define COUNT 16u 28 | 29 | /* Configuration Constants */ 30 | #define CLK_SRC_PIOSC_DIV4 0 /* sets the clock source to be PIOSC*/ 31 | #define CLK_SRC_SYSTEM 1 32 | 33 | /* Function Declarations */ 34 | FUNC(StatusType, OSCODE_Internal) Init_Systick(void); 35 | 36 | 37 | 38 | #endif /* OS_HEADERS_OSINTERNAL_HEADERS_OS_GPT_INTERNAL_H_ */ 39 | -------------------------------------------------------------------------------- /Os_Headers/OsInternal_Headers/Os_Internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Written by : Bebo 4 | DATE : 7/2/2019 5 | AUTOSAR Version : 4.3.1 6 | DOC Name : AUTOSAR_SWS_OS.pdf 7 | Target : ARM TIVA_C TM4C123GH6PM 8 | 9 | */ 10 | 11 | #ifndef OS_HEADERS_OSINTERNAL_HEADERS_OS_INTERNAL_H_ 12 | #define OS_HEADERS_OSINTERNAL_HEADERS_OS_INTERNAL_H_ 13 | 14 | #include "Os_General_Internal.h" 15 | #include "Os_Resource_Internal.h" 16 | #include "Os_Task_Internal.h" 17 | #include "Os_Isr_Internal.h" 18 | #include "Os_Counter_Internal.h" 19 | #include "Os_Alarm_Internal.h" 20 | #include "Os_ScheduleTable_Internal.h" 21 | #include "Os_Gpt_Internal.h" 22 | #include "Os_ExternalVariables.h" 23 | 24 | 25 | 26 | #endif /* OS_HEADERS_OSINTERNAL_HEADERS_OS_INTERNAL_H_ */ 27 | -------------------------------------------------------------------------------- /Os_Headers/OsInternal_Headers/Os_Isr_Internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Created by : Ahmad HEGAZY 4 | DATE : 15/2/2019 5 | AUTOSAR Version : 4.3.1 6 | DOC Name : AUTOSAR_SWS_OS.pdf 7 | Target : ARM TIVA_C TM4C123GH6PM 8 | 9 | */ 10 | 11 | #ifndef OS_HEADERS_OSINTERNAL_HEADERS_OS_ISR_INTERNAL_H_ 12 | #define OS_HEADERS_OSINTERNAL_HEADERS_OS_ISR_INTERNAL_H_ 13 | 14 | 15 | /*******************************************************************/ 16 | 17 | typedef struct 18 | { 19 | 20 | /* specifies the category of this ISR. */ 21 | VAR( uint8, AUTOMATIC ) OsIsrCategory ; 22 | 23 | /* specifies the category of this ISR. */ 24 | VAR( uint8, AUTOMATIC ) Isr_Priority ; 25 | 26 | /* defines the list of resource that task may occupy */ 27 | VAR( ResourceMaskType, AUTOMATIC ) OsResourceRef ; 28 | 29 | /* hold resource id of last occupied resource by the task */ 30 | VAR( ResourceType, AUTOMATIC ) Isr_LastResourceOccupied ; 31 | 32 | 33 | } OsIsr; 34 | 35 | 36 | #define NoDisableActive 0x00u 37 | #define DisAllIntActive 0x01u 38 | #define SuspendAllIntActive 0x02u 39 | #define SuspendOSIntActive 0x03u 40 | 41 | /* enum contains the called interrupt disable function */ 42 | typedef VAR( uint8, TYPEDEF ) ActiveIsrDisableType; 43 | 44 | 45 | /* PEND registers addresses */ 46 | #define PEND0_REG_ADDR (*(( volatile P2VAR( uint32, AUTOMATIC, REGSPACE ) ) 0xE000E200 )) 47 | #define PEND1_REG_ADDR (*(( volatile P2VAR( uint32, AUTOMATIC, REGSPACE ) ) 0xE000E204 )) 48 | #define PEND2_REG_ADDR (*(( volatile P2VAR( uint32, AUTOMATIC, REGSPACE ) ) 0xE000E208 )) 49 | #define PEND3_REG_ADDR (*(( volatile P2VAR( uint32, AUTOMATIC, REGSPACE ) ) 0xE000E20C )) 50 | #define PEND4_REG_ADDR (*(( volatile P2VAR( uint32, AUTOMATIC, REGSPACE ) ) 0xE000E210 )) 51 | 52 | /* Clear PEND registers addresses */ 53 | #define UNPEND0_REG_ADDR (*(( volatile P2VAR( uint32, AUTOMATIC, REGSPACE ) ) 0xE000E280 )) 54 | #define UNPEND1_REG_ADDR (*(( volatile P2VAR( uint32, AUTOMATIC, REGSPACE ) ) 0xE000E284 )) 55 | #define UNPEND2_REG_ADDR (*(( volatile P2VAR( uint32, AUTOMATIC, REGSPACE ) ) 0xE000E288 )) 56 | #define UNPEND3_REG_ADDR (*(( volatile P2VAR( uint32, AUTOMATIC, REGSPACE ) ) 0xE000E28C )) 57 | #define UNPEND4_REG_ADDR (*(( volatile P2VAR( uint32, AUTOMATIC, REGSPACE ) ) 0xE000E290 )) 58 | 59 | 60 | /*******************************************************************/ 61 | 62 | #define END_PRIVILEGE __asm ( " MRS R10, CONTROL " ) ;\ 63 | __asm ( " ORR R10, R10, #0x01 " ) ;\ 64 | __asm ( " MSR CONTROL, R10 " ) 65 | 66 | #endif /* OS_HEADERS_OSINTERNAL_HEADERS_OS_ISR_INTERNAL_H_ */ 67 | -------------------------------------------------------------------------------- /Os_Headers/OsInternal_Headers/Os_Resource_Internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Written by : Bebo 4 | DATE : 7/2/2019 5 | AUTOSAR Version : 4.3.1 6 | DOC Name : AUTOSAR_SWS_OS.pdf 7 | Target : ARM TIVA_C TM4C123GH6PM 8 | 9 | */ 10 | 11 | #ifndef OS_HEADERS_OSINTERNAL_HEADERS_OS_RESOURCE_INTERNAL_H_ 12 | #define OS_HEADERS_OSINTERNAL_HEADERS_OS_RESOURCE_INTERNAL_H_ 13 | 14 | /*******************************************************************/ 15 | 16 | typedef VAR( uint64, TYPEDEF ) ResourceMaskType ; 17 | 18 | 19 | /*******************************************************************/ 20 | 21 | 22 | typedef struct 23 | { 24 | /*This specifies the type of the resource*/ 25 | VAR( uint8, AUTOMATIC ) OsResourceProperty ; 26 | 27 | /*This specifies the ceiling priority of the resource*/ 28 | VAR( uint8, AUTOMATIC ) OsResourcePriority ; 29 | 30 | /* link to the resource. Must be valid if OsResourceProperty is LINKED. 31 | * If OsResourceProperty is not LINKED the value is ignored 32 | * this hold resource id linked to this resource */ 33 | VAR( ResourceType, AUTOMATIC ) OsResourceLinkedResourceRef ; 34 | 35 | 36 | } OsResource ; 37 | 38 | /*******************************************************************/ 39 | 40 | typedef struct 41 | { 42 | 43 | /*This specifies the id of task own this resource */ 44 | VAR( TaskType, AUTOMATIC ) OsResourceOwner ; 45 | 46 | /*This specifies the id of resource occupied by OsResourceOwner before this resource*/ 47 | VAR( ResourceType, AUTOMATIC ) OsPreviousResource ; 48 | 49 | 50 | } OsResource_PCB ; 51 | 52 | /*******************************************************************/ 53 | 54 | void Resource_IsrMask ( uint8 ResourcePriority ) ; 55 | 56 | 57 | #endif /* OS_HEADERS_OSINTERNAL_HEADERS_OS_RESOURCE_INTERNAL_H_ */ 58 | -------------------------------------------------------------------------------- /Os_Headers/OsInternal_Headers/Os_ScheduleTable_Internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Written by : Bakr 4 | DATE : 18/2/2020 5 | AUTOSAR Version : 4.3.1 6 | DOC Name : AUTOSAR_SWS_OS.pdf 7 | Target : ARM TIVA_C TM4C123GH6PM 8 | 9 | */ 10 | 11 | #ifndef OS_HEADERS_OSINTERNAL_HEADERS_OS_SCHEDULETABLE_INTERNAL_H_ 12 | #define OS_HEADERS_OSINTERNAL_HEADERS_OS_SCHEDULETABLE_INTERNAL_H_ 13 | 14 | 15 | 16 | 17 | 18 | 19 | typedef struct 20 | { 21 | /* specifies the type of the autostart for the schedule table */ 22 | VAR( uint8, AUTOMATIC ) OsScheduleTableAutostartType ; 23 | 24 | /* which application modes the schedule table should be started during startup 25 | * if = NOT_AUTOSTART then it won't be in autostart */ 26 | VAR( AppModeType, AUTOMATIC ) OsScheduleTableAppModeRef ; 27 | 28 | /* Absolute autostart tick value when the schedule table starts. 29 | * Only used if the OsScheduleTableAutostartType is ABSOLUTE. 30 | * Relative offset in ticks when the schedule table starts. 31 | * Only used if the OsScheduleTableAutostartType is RELATIVE*/ 32 | VAR( TickType, AUTOMATIC ) OsScheduleTableStartValue ; 33 | 34 | } OsScheduleTableAutostart ; 35 | 36 | 37 | typedef struct 38 | { 39 | 40 | /* number of events to be set contained in the point */ 41 | VAR( uint16, AUTOMATIC ) EventSetNumber ; 42 | 43 | /* pointer to first event to set in the point */ 44 | VAR( uint16, AUTOMATIC ) FirstEventSet ; 45 | 46 | /*index of first first task to set its event in the point */ 47 | VAR( uint16, AUTOMATIC ) FirstEventSetTask_Ptr ; 48 | 49 | } OsScheduleTableEventSetting ; 50 | 51 | typedef struct 52 | { 53 | 54 | /* number of tasks activation contained in the point */ 55 | VAR( uint16, AUTOMATIC ) TaskActivationNumber ; 56 | 57 | /* index of first first task activation in the point */ 58 | VAR( uint16, AUTOMATIC ) FirstTaskActivation ; 59 | 60 | 61 | } OsScheduleTableTaskActivation ; 62 | 63 | 64 | typedef struct 65 | { 66 | /* maximum negative adjustment that can be made to the expiry point offset (in ticks */ 67 | VAR( TickType, AUTOMATIC ) OsScheduleTableMaxShorten ; 68 | 69 | /* maximum positive adjustment that can be made to the expiry point offset (in ticks */ 70 | VAR( TickType, AUTOMATIC ) OsScheduleTableMaxLengthen ; 71 | 72 | } OsScheduleTblAdjustableExpPoint ; 73 | 74 | 75 | typedef struct 76 | { 77 | 78 | /* offset from zero (in ticks) at which the expiry point is to be processed */ 79 | VAR( TickType, AUTOMATIC ) OsScheduleTblExpPointOffset ; 80 | 81 | /* define tasks will be activated in this point expiration */ 82 | VAR( OsScheduleTableTaskActivation, AUTOMATIC ) PointTasks; 83 | 84 | /* define events will be set in this point expiration */ 85 | VAR( OsScheduleTableEventSetting, AUTOMATIC ) PointEvents ; 86 | 87 | /* if 0 value for its parameter then point not adjustable */ 88 | VAR( OsScheduleTblAdjustableExpPoint, AUTOMATIC ) OsScheduleTblAdjustableExpPoint ; 89 | 90 | 91 | } OsScheduleTableExpiryPoint ; 92 | 93 | typedef struct{ 94 | 95 | VAR( TickType , AUTOMATIC ) EPCurrentOffset; 96 | 97 | VAR( TickType , AUTOMATIC ) EPFullOffset; 98 | 99 | }ExpiryPointOffset; 100 | 101 | typedef struct 102 | { 103 | 104 | /* true: first expiry point on the schedule table shall be processed at 105 | * final expiry point delay ticks after the final expiry point is processed. 106 | * false: the schedule table processing stops when the final expiry point is processed */ 107 | VAR( boolean, AUTOMATIC ) OsScheduleTableRepeating ; 108 | 109 | /* Reference to the assigned counter for that alarm */ 110 | VAR( CounterType, AUTOMATIC ) OsScheduleTableCounterRef ; 111 | 112 | /* number of expiry points contained in the table */ 113 | VAR( uint16, AUTOMATIC ) ExpiryPointsNumber ; 114 | 115 | /* index of first expiry point in the table in expiry points list */ 116 | VAR( uint16, AUTOMATIC ) FirstExpiryPoint ; 117 | 118 | /* defines the modulus of the schedule table (in ticks). */ 119 | VAR( TickType, AUTOMATIC ) OsScheduleTableDuration ; 120 | 121 | /* 122 | IMPLICIT: synchronization, EXPLICIT: no synchronization 123 | */ 124 | VAR(boolean, AUTOMATIC ) OsScheduleTblSyncStrategy ; 125 | 126 | } OsScheduleTable ; 127 | 128 | typedef struct{ 129 | 130 | /* Last accessed expiry point */ 131 | VAR( uint16, AUTOMATIC ) CurrentExpiryPointIndex; 132 | 133 | /* Schedule table current state */ 134 | VAR( uint8, AUTOMATIC ) CurrentState; 135 | 136 | /* Offset to start from current counter */ 137 | VAR( TickType, AUTOMATIC ) ScheduleTableDuration; 138 | 139 | /* Next schedule ID if there is */ 140 | VAR ( sint16 , AUTOMATIC ) NextScheduleTable; 141 | 142 | } OsScheduleTableInternal ; 143 | /***********************************************************************************************************************/ 144 | 145 | 146 | FUNC(void, OS_INTERNAL_CODE) CheckScheduleTablesExpiry( CounterType CounterID ) ; 147 | 148 | //FUNC(StatusType, OS_INTERNAL_CODE) CheckCounter 149 | #endif /* OS_HEADERS_OSINTERNAL_HEADERS_OS_SCHEDULETABLE_INTERNAL_H_ */ 150 | -------------------------------------------------------------------------------- /Os_Headers/OsInternal_Headers/Os_Task_Internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Written by : Bebo 4 | DATE : 7/2/2019 5 | AUTOSAR Version : 4.3.1 6 | DOC Name : AUTOSAR_SWS_OS.pdf 7 | Target : ARM TIVA_C TM4C123GH6PM 8 | 9 | */ 10 | 11 | #ifndef OS_HEADERS_OSINTERNAL_HEADERS_OS_TASK_INTERNAL_H_ 12 | #define OS_HEADERS_OSINTERNAL_HEADERS_OS_TASK_INTERNAL_H_ 13 | 14 | 15 | /*****************************************************************************/ 16 | 17 | 18 | /* used for initialize all elements of array with value x */ 19 | #define VAL_1(x) x 20 | #define VAL_2(x) VAL_1(x), VAL_1(x) 21 | #define VAL_4(x) VAL_2(x), VAL_2(x) 22 | #define VAL_8(x) VAL_4(x), VAL_4(x) 23 | #define VAL_16(x) VAL_8(x), VAL_8(x) 24 | #define VAL_32(x) VAL_16(x), VAL_16(x) 25 | #define VAL_64(x) VAL_32(x), VAL_32(x) 26 | #define VAL_128(x) VAL_64(x), VAL_64(x) 27 | #define VAL_256(x) VAL_128(x), VAL_128(x) 28 | 29 | 30 | /*****************************************************************************/ 31 | /* set pending bit of PendSv exception and set stack pointer to MSP */ 32 | 33 | #define DISPATCHER_CALL *( ( volatile P2VAR( uint32, AUTOMATIC, REGSPACE ) ) 0xE000ED04 ) |= ( 0x01u << 28 ) 34 | 35 | 36 | 37 | /* set BASEPRI priority to be 7 to disable dispatcher*/ 38 | #define DISPATCHER_OFF __asm ( " SVC #0x00 " ) ; \ 39 | __asm ( " MOV R11, #0x0E0u " ) ;\ 40 | __asm ( " MSR BASEPRI, R11 " ) 41 | 42 | 43 | /* befor convert to dipatcher make stack pointer for MSP*/ 44 | #define DISPATCHER_ON __asm ( " SVC #0x00 " ) ; \ 45 | __asm ( " MOV R11, #0x00 " );\ 46 | __asm ( " MSR BASEPRI, R11 " ) ;\ 47 | __asm ( " MRS R10, CONTROL " ) ;\ 48 | __asm ( " ORR R10, R10, #0x01 " ) ;\ 49 | __asm ( " MSR CONTROL, R10 " ) 50 | 51 | 52 | /* set and clear PRIMASK register*/ 53 | #define CS_ON __asm ( " SVC #0x00 " ) ; \ 54 | __asm ( " CPSID i " ) ; 55 | 56 | 57 | #define CS_OFF __asm ( " CPSIE i " ) ; \ 58 | __asm ( " MRS R10, CONTROL " ) ;\ 59 | __asm ( " ORR R10, R10, #0x01 " ) ;\ 60 | __asm ( " MSR CONTROL, R10 " ) 61 | 62 | /*****************************************************************************/ 63 | 64 | 65 | typedef struct 66 | { 67 | /* OsTaskSchedule attribute defines the preemptability of the task. 68 | * If this attribute is set to NON, no internal resources may be assigned to this task */ 69 | VAR( uint8, AUTOMATIC ) OsTaskSchedule ; 70 | 71 | /* defines the maximum number of queued activation requests for the task 72 | * 1" means that at any time only a single activation is permitted for this task 73 | * for basic tasks in BCC2,ECC2 */ 74 | VAR( uint8, AUTOMATIC ) OsTaskActivation ; 75 | 76 | /* priority of a task is defined by the value of this, 77 | * larger values correspond to higher priorities 0 is lowest */ 78 | VAR( uint8, AUTOMATIC ) OsTaskPriority ; 79 | 80 | /* internal resource ceiling priority if no resources accessed by the task value will be = OsTaskPriority */ 81 | VAR( uint8, AUTOMATIC ) OsTaskCeilingPriority_Internal ; 82 | 83 | /* defines the list of resource that task may occupy */ 84 | VAR( ResourceMaskType, AUTOMATIC ) OsResourceRef ; 85 | 86 | /* defines the list of events the extended task may react on, as a mask for events of this task */ 87 | VAR( EventMaskType, AUTOMATIC ) OsTaskEventRef ; 88 | 89 | 90 | } OsTask ; 91 | 92 | 93 | 94 | /*****************************************************************************/ 95 | 96 | 97 | typedef struct 98 | { 99 | 100 | 101 | /* variable to carry number of multiple activation requested for basic tasks 102 | * at every activate will be decremented if not equeal to zero 103 | * initialized from configuration task array */ 104 | VAR( uint8, AUTOMATIC ) OsTaskMultipleActivation ; 105 | 106 | /* priority of the task */ 107 | VAR( uint8, AUTOMATIC ) Task_Priority ; 108 | 109 | /* number of resource number occupied by task */ 110 | VAR( uint8, AUTOMATIC ) Task_ResourcesOccupied ; 111 | 112 | /* hold resource id of last occupied resource by the task */ 113 | VAR( ResourceType, AUTOMATIC ) Task_LastResourceOccupied ; 114 | 115 | /* id of task own this PCB */ 116 | VAR( TaskType, AUTOMATIC ) Task_ID ; 117 | 118 | /* state of task own this PCB */ 119 | VAR( TaskStateType, AUTOMATIC ) Task_State ; 120 | 121 | /* general purpose register */ 122 | VAR( uint32, AUTOMATIC ) Task_R0 ; 123 | VAR( uint32, AUTOMATIC ) Task_R1 ; 124 | VAR( uint32, AUTOMATIC ) Task_R2 ; 125 | VAR( uint32, AUTOMATIC ) Task_R3 ; 126 | VAR( uint32, AUTOMATIC ) Task_R4 ; 127 | VAR( uint32, AUTOMATIC ) Task_R5 ; 128 | VAR( uint32, AUTOMATIC ) Task_R6 ; 129 | VAR( uint32, AUTOMATIC ) Task_R7 ; 130 | VAR( uint32, AUTOMATIC ) Task_R8 ; 131 | VAR( uint32, AUTOMATIC ) Task_R9 ; 132 | VAR( uint32, AUTOMATIC ) Task_R10 ; 133 | VAR( uint32, AUTOMATIC ) Task_R11 ; 134 | VAR( uint32, AUTOMATIC ) Task_R12 ; 135 | 136 | /* PSP for task */ 137 | VAR( uint32, AUTOMATIC ) Task_SP ; 138 | 139 | /* linker register of task used for return from function calls */ 140 | VAR( uint32, AUTOMATIC ) Task_LR ; 141 | 142 | /* program counter for task */ 143 | P2FUNC( void, AUTOMATIC, Task_PC ) (void) ; 144 | 145 | /* status register for task */ 146 | VAR( uint32, AUTOMATIC ) Task_PSR ; 147 | 148 | /* control register for task to save privilege level */ 149 | VAR( uint32, AUTOMATIC ) Task_CONTROL ; 150 | 151 | /* flags determine states of the task set or cleared */ 152 | VAR( EventMaskType, AUTOMATIC ) Task_EvnetsFlag ; 153 | 154 | /* flags determine which events task is waiting */ 155 | VAR( EventMaskType, AUTOMATIC ) Task_EvnetsWaiting ; 156 | 157 | VAR( uint32, AUTOMATIC ) Task_Stack [TASK_STACK_SIZE] ; 158 | 159 | } OsTask_PCB ; 160 | 161 | 162 | /*****************************************************************************/ 163 | 164 | 165 | /* used to reference stack frame in case of interrupt 166 | * to easily access the element that pushed to main stack for context switching */ 167 | typedef struct 168 | { 169 | 170 | /* this registers are pushed manually */ 171 | VAR (uint32, AUTOMATIC) CONTROL ; 172 | VAR (uint32, AUTOMATIC) R11 ; 173 | VAR (uint32, AUTOMATIC) R10 ; 174 | VAR (uint32, AUTOMATIC) R9 ; 175 | VAR (uint32, AUTOMATIC) R8 ; 176 | VAR (uint32, AUTOMATIC) R7 ; 177 | VAR (uint32, AUTOMATIC) R6 ; 178 | VAR (uint32, AUTOMATIC) R5 ; 179 | VAR (uint32, AUTOMATIC) R4 ; 180 | VAR (uint32, AUTOMATIC) PSP ; 181 | 182 | VAR (uint32, AUTOMATIC) emp_1 ; 183 | VAR (uint32, AUTOMATIC) emp_2 ; 184 | 185 | 186 | } OsStackFrame_MSP; 187 | 188 | 189 | /*****************************************************************************/ 190 | 191 | 192 | typedef struct 193 | { 194 | 195 | /* this register are pushed by exception entry automatically */ 196 | VAR (uint32, AUTOMATIC) R0 ; 197 | VAR (uint32, AUTOMATIC) R1 ; 198 | VAR (uint32, AUTOMATIC) R2 ; 199 | VAR (uint32, AUTOMATIC) R3 ; 200 | VAR (uint32, AUTOMATIC) R12 ; 201 | VAR (uint32, AUTOMATIC) LR ; 202 | P2FUNC( void, AUTOMATIC, PC ) (void) ; 203 | VAR (uint32, AUTOMATIC) PSR ; 204 | 205 | } OsStackFrame_PSP ; 206 | 207 | 208 | /*****************************************************************************/ 209 | 210 | 211 | /* make context switching */ 212 | FUNC (void, OS_CODE) OsDispatcher (void) ; 213 | 214 | /* used to add Task to last of proper priority queue and modify the queue */ 215 | FUNC (void, OS_CODE) OsTailTask ( uint8 PCB_Index ) ; 216 | 217 | /* used to add to head of proper priority queue and modify the queue */ 218 | FUNC (void, OS_CODE) OsHeadTask ( uint8 PCB_Index ) ; 219 | 220 | /* used to remove task from in the head of priority queue and modify the queue */ 221 | FUNC (void, OS_CODE) RemoveTask ( uint8 TaskPriority ) ; 222 | 223 | FUNC (void, OS_CODE) Init_PCB ( uint8 PCB_Index, uint8 TaskID ) ; 224 | 225 | 226 | /*****************************************************************************/ 227 | 228 | #endif /* OS_HEADERS_OSINTERNAL_HEADERS_OS_TASK_INTERNAL_H_ */ 229 | 230 | 231 | 232 | 233 | 234 | -------------------------------------------------------------------------------- /Os_Sources/OsInterface_Sources/Os_Alarm.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Written by : Bakr 4 | DATE : 18/2/2020 5 | AUTOSAR Version : 4.3.1 6 | DOC Name : AUTOSAR_SWS_OS.pdf 7 | Target : ARM TIVA_C TM4C123GH6PM 8 | 9 | */ 10 | 11 | 12 | 13 | 14 | 15 | #include "..\..\Os_Headers\OsInterface_Headers\Os.h" 16 | #include "..\..\Os_Headers\OsInternal_Headers\Os_Internal.h" 17 | 18 | /************************************************************************************************/ 19 | 20 | extern CONST( OsCounter, OS_CONFIG_DATA ) OsCounter_Array [ COUNTERS_NUMBER ]; 21 | 22 | extern CONST( OsAlarm, OS_CONFIG_DATA ) OsAlarm_Array [ ALARMS_NUMBER ]; 23 | 24 | extern VAR( OsAlarmInternal, OS_CONFIG_DATA ) OsAlarmInternal_Array [ALARMS_NUMBER]; 25 | 26 | extern VAR( OsCounterInternal, OS_DATA) OsCounterInternal_Array [COUNTERS_NUMBER ]; 27 | 28 | /************************************************************************************************/ 29 | 30 | /* - Reference to structure with constants of the alarm base 31 | 32 | - Description: The system service GetAlarmBase reads the alarm base characteristics. 33 | The return value is a structure in which the information of data type AlarmBaseType is stored. 34 | 35 | - Particularities: Allowed on task level, ISR, and in several hook routines. 36 | */ 37 | 38 | 39 | FUNC(StatusType, OS_CODE) GetAlarmBase ( AlarmType AlarmID, AlarmBaseRefType Info ) { 40 | 41 | StatusType RetVal = E_OK; 42 | CS_ON; 43 | if(AlarmID > ALARMS_NUMBER){ 44 | 45 | RetVal = E_OS_ID; 46 | 47 | }else{ 48 | 49 | Info->mincycle = OsCounter_Array[OsAlarm_Array[AlarmID].OsAlarmCounterRef].OsCounterMinCycle; 50 | 51 | Info->maxallowedvalue = OsCounter_Array[OsAlarm_Array[AlarmID].OsAlarmCounterRef].OsCounterMaxAllowedValue; 52 | 53 | Info->ticksperbase = OsCounter_Array[OsAlarm_Array[AlarmID].OsAlarmCounterRef].OsCounterTicksPerBase; 54 | 55 | } 56 | CS_OFF; 57 | return RetVal; 58 | } 59 | 60 | /**************************************************************************************************/ 61 | 62 | /* 63 | - Description: The system service GetAlarm returns the relative value in ticks before the alarm expires. 64 | - Particularities: It is up to the application to decide whether for example a CancelAlarm may still be useful. 65 | If is not in use, is not defined. 66 | Allowed on task level, ISR, and in several hook routines 67 | */ 68 | 69 | 70 | FUNC(StatusType, OS_CODE) GetAlarm ( AlarmType AlarmID, TickRefType Tick) { 71 | 72 | StatusType RetVal = E_OK; 73 | CS_ON; 74 | /* return the difference between the current counter value and the alarm expiry value */ 75 | 76 | #if OS_MODE == OS_STANDARD 77 | 78 | if(OsAlarm_Array[AlarmID].AlarmAction.ActionType == ALARM_NOFUNC){ 79 | 80 | RetVal = E_OS_NOFUNC; 81 | 82 | }else{ 83 | if( OsAlarmInternal_Array[AlarmID].AlarmExpiryTickValue >= 84 | 85 | OsCounterInternal_Array[OsAlarm_Array[AlarmID].OsAlarmCounterRef].OsCounterVal ){ 86 | 87 | *Tick = OsAlarmInternal_Array[AlarmID].AlarmExpiryTickValue - 88 | 89 | OsCounterInternal_Array[OsAlarm_Array[AlarmID].OsAlarmCounterRef].OsCounterVal; 90 | 91 | }else{ /* Counter has passed the alarm value */ 92 | 93 | *Tick = OsCounter_Array[OsAlarm_Array[AlarmID].OsAlarmCounterRef].OsCounterMaxAllowedValue - 94 | 95 | OsCounterInternal_Array[OsAlarm_Array[AlarmID].OsAlarmCounterRef].OsCounterVal + 96 | 97 | OsAlarmInternal_Array[AlarmID].AlarmExpiryTickValue; 98 | 99 | } 100 | } 101 | 102 | #elif OS_MODE == OS_EXTENDED 103 | 104 | if(AlarmID > ALARMS_NUMBER){ 105 | 106 | RetVal = E_OS_ID; 107 | }else if(OsAlarm_Array[AlarmID].AlarmAction.ActionType == ALARM_NOFUNC){ 108 | 109 | RetVal = E_OS_NOFUNC; 110 | 111 | }else{ 112 | 113 | if( OsAlarmInternal_Array[AlarmID].AlarmExpiryTickValue >= 114 | 115 | OsCounterInternal_Array[OsAlarm_Array[AlarmID].OsAlarmCounterRef].OsCounterVal ){ 116 | 117 | *Tick = OsAlarmInternal_Array[AlarmID].AlarmExpiryTickValue - 118 | 119 | OsCounterInternal_Array[OsAlarm_Array[AlarmID].OsAlarmCounterRef].OsCounterVal; 120 | 121 | }else{ /* Counter has passed the alarm value */ 122 | 123 | *Tick = OsCounter_Array[OsAlarm_Array[AlarmID].OsAlarmCounterRef].OsCounterMaxAllowedValue - 124 | 125 | OsCounterInternal_Array[OsAlarm_Array[AlarmID].OsAlarmCounterRef].OsCounterVal + 126 | 127 | OsAlarmInternal_Array[AlarmID].AlarmExpiryTickValue; 128 | 129 | } 130 | 131 | } 132 | 133 | #endif 134 | CS_OFF; 135 | return RetVal; 136 | 137 | } 138 | 139 | /****************************************************************************************************/ 140 | 141 | /* 142 | - Description: The system service occupies the alarm element. After ticks have elapsed, 143 | the task assigned to the alarm is activated or the assigned event (only for extended tasks) 144 | is set or the alarm-callback routine is called. 145 | - NOTES: - To change values of alarms already in use the alarm shall be cancelled first. 146 | If the alarm is already in use, this call will be ignored and the error E_OS_STATE is returned. 147 | Allowed on task level and in ISR, but not in hook routines. 148 | 149 | 150 | */ 151 | FUNC(StatusType, OS_CODE) SetRelAlarm ( AlarmType AlarmID, TickType increment, TickType cycle ) { 152 | 153 | VAR( StatusType, AUTOMATIC ) RetVal = E_OK; 154 | CS_ON; 155 | #if OS_MODE == OS_STANDARD 156 | 157 | if( OsAlarmInternal_Array[AlarmID].InUse == FALSE ){ 158 | 159 | OsAlarmInternal_Array[AlarmID].AlarmExpiryTickValue = (OsCounterInternal_Array[OsAlarm_Array[AlarmID].OsAlarmCounterRef].OsCounterVal + increment) % 160 | 161 | OsCounter_Array[OsAlarm_Array[AlarmID].OsAlarmCounterRef].OsCounterMaxAllowedValue; 162 | 163 | OsAlarmInternal_Array[AlarmID].Cycle = cycle; 164 | 165 | OsAlarmInternal_Array[AlarmID].InUse = TRUE; 166 | 167 | }else{ 168 | 169 | RetVal = E_OS_STATE; 170 | 171 | } 172 | 173 | #elif OS_MODE == OS_EXTENDED 174 | 175 | if(AlarmID > ALARMS_NUMBER){ 176 | 177 | RetVal = E_OS_ID; 178 | }else if( OsAlarmInternal_Array[AlarmID].InUse != FALSE ){ 179 | 180 | RetVal = E_OS_STATE; 181 | 182 | }else if(increment > OsCounter_Array[OsAlarm_Array[AlarmID].OsAlarmCounterRef].OsCounterMaxAllowedValue ){ 183 | 184 | RetVal = E_OS_VALUE; 185 | 186 | }else if(((cycle < OsCounter_Array[OsAlarm_Array[AlarmID].OsAlarmCounterRef].OsCounterMinCycle) && cycle != 0) 187 | 188 | || cycle > OsCounter_Array[OsAlarm_Array[AlarmID].OsAlarmCounterRef].OsCounterMaxAllowedValue ){ 189 | 190 | RetVal = E_OS_VALUE; 191 | 192 | }else{ 193 | 194 | OsAlarmInternal_Array[AlarmID].AlarmExpiryTickValue = (OsCounterInternal_Array[OsAlarm_Array[AlarmID].OsAlarmCounterRef].OsCounterVal + increment) % 195 | 196 | OsCounter_Array[OsAlarm_Array[AlarmID].OsAlarmCounterRef].OsCounterMaxAllowedValue; 197 | 198 | OsAlarmInternal_Array[AlarmID].Cycle = cycle; 199 | 200 | OsAlarmInternal_Array[AlarmID].InUse = TRUE; 201 | 202 | 203 | 204 | RetVal = E_OS_STATE; 205 | 206 | 207 | 208 | } 209 | 210 | #endif 211 | 212 | CS_OFF; 213 | return RetVal; 214 | 215 | } 216 | 217 | /*****************************************************************************************************/ 218 | /* 219 | - Description: The system service occupies the alarm element. When ticks are reached, 220 | the task assigned to the alarm is activated or 221 | the assigned event (only for extended tasks) is set or the alarm-callback routine is called. 222 | - NOTE: - If the absolute value is very close to the current counter value, the alarm may expire, 223 | and the task may become ready or the alarm-callback may be called before the system service returns to the user. 224 | - If the absolute value already was reached before the system call, the alarm shall only expire when the absolute value is reached again, 225 | i.e. after the next overrun of the counter. 226 | 227 | */ 228 | 229 | FUNC(StatusType, OS_CODE) SetAbsAlarm ( AlarmType AlarmID, TickType start, TickType cycle ) { 230 | 231 | StatusType RetVal = E_OK; 232 | 233 | CS_ON; 234 | 235 | #if OS_MODE == OS_STANDARD 236 | 237 | /* Make sure alarm is not already in use */ 238 | if(OsAlarmInternal_Array[AlarmID].InUse != FALSE ){ 239 | 240 | RetVal = E_OS_STATE; 241 | 242 | }else{ 243 | 244 | OsAlarmInternal_Array[AlarmID].AlarmExpiryTickValue = start; 245 | 246 | OsAlarmInternal_Array[AlarmID].Cycle = cycle; 247 | 248 | OsAlarmInternal_Array[AlarmID].InUse = TRUE; 249 | 250 | 251 | } 252 | 253 | #elif OS_MODE == OS_EXTENDED 254 | 255 | if(AlarmID > ALARMS_NUMBER){ 256 | 257 | RetVal = E_OS_ID; 258 | 259 | }if(OsAlarmInternal_Array[AlarmID].InUse != FALSE ){ 260 | 261 | RetVal = E_OS_STATE; 262 | 263 | }else if(start > OsCounter_Array[OsAlarm_Array[AlarmID].OsAlarmCounterRef].OsCounterMaxAllowedValue ){ 264 | 265 | RetVal = E_OS_VALUE; 266 | 267 | }else if(((cycle < OsCounter_Array[OsAlarm_Array[AlarmID].OsAlarmCounterRef].OsCounterMinCycle) && cycle != 0) 268 | 269 | || cycle > OsCounter_Array[OsAlarm_Array[AlarmID].OsAlarmCounterRef].OsCounterMaxAllowedValue ){ 270 | 271 | RetVal = E_OS_VALUE; 272 | 273 | }else{ 274 | 275 | if( OsAlarmInternal_Array[AlarmID].InUse == FALSE ){ 276 | 277 | OsAlarmInternal_Array[AlarmID].AlarmExpiryTickValue = start; 278 | 279 | OsAlarmInternal_Array[AlarmID].Cycle = cycle; 280 | 281 | OsAlarmInternal_Array[AlarmID].InUse = TRUE; 282 | 283 | }else{ 284 | 285 | RetVal = E_OS_STATE; 286 | 287 | } 288 | } 289 | 290 | #endif 291 | CS_OFF; 292 | return RetVal; 293 | 294 | } 295 | 296 | /****************************************************************************************************/ 297 | /* 298 | - Description: The system service cancels the alarm . 299 | - 300 | */ 301 | FUNC(StatusType, OS_CODE) CancelAlarm ( AlarmType AlarmID ) { 302 | 303 | StatusType RetVal = E_OK; 304 | 305 | CS_ON; 306 | 307 | #if OS_MODE == OS_STANDARD 308 | 309 | if(OsAlarmInternal_Array[AlarmID].InUse == FALSE){ 310 | 311 | RetVal = E_OS_NOFUNC; 312 | 313 | }else{ 314 | 315 | OsAlarmInternal_Array[AlarmID].InUse = FALSE; 316 | 317 | } 318 | 319 | 320 | #elif OS_MODE == OS_EXTENDED 321 | 322 | if(OsAlarmInternal_Array[AlarmID].InUse == FALSE){ 323 | 324 | RetVal = E_OS_NOFUNC; 325 | 326 | }else if(AlarmID > ALARMS_NUMBER){ 327 | 328 | RetVal = E_OS_ID; 329 | 330 | }else{ 331 | 332 | OsAlarmInternal_Array[AlarmID].InUse = FALSE; 333 | 334 | } 335 | 336 | #endif 337 | 338 | CS_OFF; 339 | 340 | return RetVal; 341 | 342 | } 343 | -------------------------------------------------------------------------------- /Os_Sources/OsInterface_Sources/Os_Counter.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AU20GradProject/OS/8c693b006dd1c926e856cfe32eb944fff8964a7d/Os_Sources/OsInterface_Sources/Os_Counter.c -------------------------------------------------------------------------------- /Os_Sources/OsInterface_Sources/Os_Event.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Written by : Bebo 4 | DATE : 7/2/2019 5 | AUTOSAR Version : 4.3.1 6 | DOC Name : AUTOSAR_SWS_OS.pdf 7 | Target : ARM TIVA_C TM4C123GH6PM 8 | 9 | */ 10 | 11 | 12 | 13 | #include "..\..\Os_Headers\OsInterface_Headers\Os.h" 14 | #include "..\..\Os_Headers\OsInternal_Headers\Os_Internal.h" 15 | #include "..\..\Os_Headers\OsInternal_Headers\Os_ExternalVariables.h" 16 | 17 | 18 | 19 | /*****************************************************************************/ 20 | 21 | /* called from an interrupt service routine and from the task level, but not from hook routines */ 22 | /* events of task are set according to the event mask */ 23 | /* Calling SetEvent causes to be transferred to the ready state, 24 | * if it was waiting for at least one of the events specified in is invalid, E_OS_ID */ 27 | /* Referenced task is no extended task, E_OS_ACCESS */ 28 | /* Events can not be set as the referenced task is in the suspended state, E_OS_STATE */ 29 | 30 | FUNC (StatusType, OS_CODE) SetEvent ( TaskType TaskID, EventMaskType Mask ) 31 | { 32 | CS_ON ; 33 | 34 | VAR ( StatusType, AUTOMATIC ) ReturnResult = E_OK ; 35 | VAR ( uint8, AUTOMATIC ) PCB_Index ; 36 | 37 | 38 | if (TaskID < TASKS_NUMBER ) /* valid task id */ 39 | { 40 | 41 | /* making sure that event is related to task */ 42 | Mask &= OsTasks_Array[ TaskID ].OsTaskEventRef ; 43 | 44 | if( OS_EVENT_BASIC_TASK != Mask ) /* task is extended task */ 45 | { 46 | 47 | /* critical section to protect read modify write sequence, read from PCB_Index write to events flags */ 48 | 49 | PCB_Index = OsTasksPCB_Index_Array[ TaskID ] ; 50 | 51 | if( INVALID_TASK != PCB_Index ) /* task is not suspended */ 52 | { 53 | /* set events for task even if task don't wait for them */ 54 | OsTasksPCB_Array[ PCB_Index ].Task_EvnetsFlag |= Mask ; 55 | 56 | if ( OS_EVENT_BASIC_TASK != ( ( OsTasksPCB_Array[ PCB_Index ].Task_EvnetsWaiting ) & Mask ) ) /* set event task is waiting for */ 57 | { 58 | OsTasksPCB_Array[ PCB_Index ].Task_EvnetsWaiting = OS_EVENT_BASIC_TASK ; 59 | 60 | /* add new task's pcb index to proper priority queue */ 61 | OsTailTask ( PCB_Index ) ; 62 | 63 | } 64 | else /* set event task isn't waiting for it */ 65 | { 66 | } 67 | } 68 | else 69 | { 70 | /* task is suspended */ 71 | ReturnResult = E_OS_STATE ; 72 | 73 | } /* else */ 74 | 75 | } /* if */ 76 | else 77 | { 78 | /* task is basic task */ 79 | ReturnResult = E_OS_ACCESS ; 80 | 81 | } /* else */ 82 | 83 | } /* if */ 84 | else 85 | { 86 | /* invalid task ID*/ 87 | ReturnResult = E_OS_ID ; 88 | } 89 | 90 | CS_OFF ; 91 | 92 | return ReturnResult ; 93 | } 94 | 95 | 96 | /*****************************************************************************/ 97 | 98 | /* The events of the extended task calling ClearEvent are cleared according to the event mask . */ 99 | /* The system service ClearEvent is restricted to extended tasks which own the event */ 100 | /* The system service ClearEvent is restricted to extended tasks which own the event */ 101 | /* Call at interrupt level, E_OS_CALLEVEL */ 102 | 103 | FUNC (StatusType, OS_CODE) ClearEvent ( EventMaskType Mask ) 104 | { 105 | CS_ON ; 106 | 107 | StatusType ReturnResult = E_OK ; 108 | 109 | 110 | if ( INVALID_ISR== IsrID) /* check if called form ISR level */ 111 | { 112 | 113 | 114 | /* making sure that event is related to task */ 115 | Mask &= OsTasks_Array[ ( OsTasksPCB_Array[RunningTaskPCB_Index].Task_ID ) ].OsTaskEventRef ; 116 | 117 | /* check if task is extended task */ 118 | if( OS_EVENT_BASIC_TASK != Mask ) /* task is extended task */ 119 | { 120 | /* critical section to read modify write of Task_EvnetsFlag */ 121 | 122 | /* clear events according to input mask*/ 123 | OsTasksPCB_Array[RunningTaskPCB_Index].Task_EvnetsFlag &= ~Mask ; 124 | 125 | } 126 | else 127 | { 128 | /* task is basic task or has no reference to this event */ 129 | ReturnResult = E_OS_ACCESS ; 130 | 131 | } /* else */ 132 | 133 | } /* if */ 134 | else 135 | { 136 | /* called form interrupt */ 137 | ReturnResult = E_OS_CALLEVEL ; 138 | } 139 | 140 | CS_OFF ; 141 | 142 | return ReturnResult ; 143 | 144 | } 145 | 146 | /*****************************************************************************/ 147 | 148 | /* service returns the current state of all event bits of the task , not the events that the task is waiting for */ 149 | /* service may be called from interrupt service routines, task level and some hook routines */ 150 | /* current status of the event mask of task is copied to . */ 151 | /* Task is invalid, E_OS_ID */ 152 | /* Referenced task is not an extended task, E_OS_ACCESS */ 153 | /* Referenced task is in the suspended state, E_OS_STATE */ 154 | 155 | FUNC (StatusType, OS_CODE) GetEvent ( TaskType TaskID, EventMaskRefType Event ) 156 | { 157 | CS_ON ; 158 | 159 | StatusType ReturnResult = E_OK ; 160 | VAR ( uint8, AUTOMATIC ) PCB_Index ; 161 | 162 | 163 | if ( TaskID < TASKS_NUMBER ) /* valid task id */ 164 | { 165 | 166 | /* check if task is extended task */ 167 | if( OS_EVENT_BASIC_TASK != OsTasks_Array[ TaskID ].OsTaskEventRef ) /* task is extended task */ 168 | { 169 | 170 | /* critical section to protect read modify write sequence, read from PCB_Index write to index of OsTasksPCB_Array */ 171 | 172 | PCB_Index = OsTasksPCB_Index_Array[ TaskID ] ; 173 | 174 | if( INVALID_TASK != PCB_Index ) /* task is not suspended */ 175 | { 176 | *Event = OsTasksPCB_Array[ PCB_Index ].Task_EvnetsFlag ; 177 | } 178 | else 179 | { 180 | /* task is suspended */ 181 | ReturnResult = E_OS_STATE ; 182 | 183 | } /* else */ 184 | 185 | } 186 | else 187 | { 188 | /* task is basic task or has no reference to this event */ 189 | ReturnResult = E_OS_ACCESS ; 190 | 191 | } /* else */ 192 | 193 | } /* if */ 194 | else 195 | { 196 | /* invalid task ID*/ 197 | ReturnResult = E_OS_ID ; 198 | } 199 | 200 | CS_OFF ; 201 | 202 | return ReturnResult ; 203 | } 204 | 205 | /*****************************************************************************/ 206 | 207 | /* The state of the calling task is set to waiting, unless at least one of the events specified in has already been set. */ 208 | /* call enforces rescheduling, if the wait condition occurs. 209 | * If rescheduling takes place, the internal resource of the task is released while the task is in the waiting state. */ 210 | /* service shall only be called from the extended task owning the event */ 211 | /* Calling task is not an extended task, E_OS_ACCESS */ 212 | /* Calling task occupies resources, E_OS_RESOURCE */ 213 | /* Call at interrupt level, E_OS_CALLEVEL */ 214 | 215 | FUNC (StatusType, OS_CODE) WaitEvent ( EventMaskType Mask ) 216 | { 217 | 218 | CS_ON ; 219 | 220 | StatusType ReturnResult = E_OK ; 221 | 222 | if ( INVALID_ISR== IsrID) /* check if called form ISR level */ 223 | { 224 | 225 | /* making sure that event is related to task */ 226 | Mask &= OsTasks_Array [ ( OsTasksPCB_Array[RunningTaskPCB_Index].Task_ID ) ].OsTaskEventRef ; 227 | 228 | if ( OS_EVENT_BASIC_TASK != Mask ) 229 | { 230 | /* no need to critical section because RunningTaskPCB_Index won't be corrupted by other task */ 231 | if ( 0 == OsTasksPCB_Array[ RunningTaskPCB_Index ].Task_ResourcesOccupied ) 232 | { 233 | /* critical section to read modify write sequence, read for Task_EvnetsFlag, write for Task_EvnetsWaiting, Task_State, and Dispatcher */ 234 | 235 | /* check if at least on event task is waiting is set or not*/ 236 | if ( OS_EVENT_BASIC_TASK == ( Mask & OsTasksPCB_Array[ RunningTaskPCB_Index ].Task_EvnetsFlag ) ) 237 | { 238 | /* no waiting events are set write waiting mask, change task state, call scheduler, and release its internal resource */ 239 | OsTasksPCB_Array[ RunningTaskPCB_Index ].Task_EvnetsWaiting = Mask ; 240 | OsTasksPCB_Array[ RunningTaskPCB_Index ].Task_State = WAITING ; 241 | RemoveTask ( OsTasksPCB_Array[RunningTaskPCB_Index].Task_Priority ) ; 242 | /* to release internal resource if exist */ 243 | OsTasksPCB_Array[ RunningTaskPCB_Index ].Task_Priority = OsTasks_Array[ (OsTasksPCB_Array[ RunningTaskPCB_Index ].Task_Priority) ].OsTaskPriority ; 244 | 245 | 246 | } 247 | else 248 | { 249 | /* at least on event which task is waiting for is set */ 250 | } 251 | } 252 | else 253 | { 254 | 255 | /* task still occupy resources */ 256 | ReturnResult = E_OS_RESOURCE ; 257 | 258 | } /* else */ 259 | 260 | } /* event */ 261 | else 262 | { 263 | /* task is basic task or has no reference to this event */ 264 | ReturnResult = E_OS_ACCESS ; 265 | 266 | } /* else */ 267 | 268 | } /* if */ 269 | else 270 | { 271 | /* called form interrupt */ 272 | ReturnResult = E_OS_CALLEVEL ; 273 | } 274 | 275 | CS_OFF ; 276 | 277 | return ReturnResult ; 278 | } 279 | 280 | /*****************************************************************************/ 281 | -------------------------------------------------------------------------------- /Os_Sources/OsInterface_Sources/Os_General.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Written by : Bebo 4 | DATE : 7/2/2019 5 | AUTOSAR Version : 4.3.1 6 | DOC Name : AUTOSAR_SWS_OS.pdf 7 | Target : ARM TIVA_C TM4C123GH6PM 8 | 9 | */ 10 | 11 | 12 | #include "..\..\Os_Headers\OsInterface_Headers\Os.h" 13 | #include "..\..\Os_Headers\OsInternal_Headers\Os_Internal.h" 14 | #include "..\..\Os_Headers\OsInternal_Headers\Os_ExternalVariables.h" 15 | 16 | /********************************************************************************************/ 17 | 18 | /* service returns the current application mode. It may be used to write mode dependent code. */ 19 | AppModeType GetActiveApplicationMode ( void ) 20 | { 21 | return AppMode ; 22 | } 23 | 24 | 25 | /********************************************************************************************/ 26 | 27 | 28 | /* The user can call this system service to start the operating system in a specific mode */ 29 | FUNC (void, OS_CODE) StartOS ( AppModeType Mode ) 30 | { 31 | VAR ( uint16, AUTOMATIC ) LocalTemp = 0 ; 32 | VAR ( uint16, AUTOMATIC ) LocalCounter = 0 ; 33 | 34 | /* all interrupt must be disabled before calling StartOS */ 35 | CS_ON ; 36 | 37 | /* check if application mode has auto start tasks, alarms or scheduling tables*/ 38 | if( NOT_AUTOSTART == Mode ) 39 | { 40 | /* tasks auto starting */ 41 | LocalCounter = OsAppModes_Array [Mode].AutoStartTasks_Index ; 42 | if ( APPMODE_INVALID != LocalCounter ) 43 | { 44 | 45 | /* determine stop index of tasks which will be activated by for loop */ 46 | LocalTemp = OsAppModes_Array [Mode].AutoStartTasks_Index + OsAppModes_Array [Mode].AutoStartTasks_Number ; 47 | 48 | for( ; LocalCounter < LocalTemp ; LocalCounter++ ) 49 | { 50 | ActivateTask( OsAutoStartTasks_Array[LocalCounter] ) ; 51 | 52 | } /* for */ 53 | } 54 | else 55 | { 56 | /* this app mode hasn't auto start tasks */ 57 | } 58 | 59 | 60 | /************************************************************************/ 61 | 62 | 63 | /* alarms auto starting */ 64 | LocalCounter = OsAppModes_Array [Mode].AutoStartAlarms_Index ; 65 | 66 | if ( APPMODE_INVALID != LocalCounter ) 67 | { 68 | /* determine stop index of alarms which will be activated by for loop */ 69 | LocalTemp = OsAppModes_Array [Mode].AutoStartAlarms_Index + OsAppModes_Array [Mode].AutoStartAlarms_Number ; 70 | 71 | for( ; LocalCounter < LocalTemp ; LocalCounter++ ) 72 | { 73 | if( ALARM_ABSOLUTE == OsAutoStartAlarms_SettingArray[LocalCounter].OsAlarmAutostartType ) 74 | { 75 | /* 76 | SetAbsAlarm( OsAutoStartAlarms_Array[LocalCounter], OsAutoStartAlarms_SettingArray[LocalCounter].OsAlarmAlarmTime , OsAutoStartAlarms_SettingArray[LocalCounter].OsAlarmCycleTime ); 77 | */ 78 | 79 | } 80 | else 81 | { 82 | /* 83 | SetRelAlarm( OsAutoStartAlarms_Array[LocalCounter], OsAutoStartAlarms_SettingArray[LocalCounter].OsAlarmAlarmTime , OsAutoStartAlarms_SettingArray[LocalCounter].OsAlarmCycleTime ); 84 | */ 85 | 86 | } /* else */ 87 | 88 | } /* for*/ 89 | 90 | } /* if */ 91 | else 92 | { 93 | /* this app mode hasn't auto start tasks */ 94 | } 95 | 96 | 97 | /************************************************************************/ 98 | 99 | 100 | /* schedule tables auto starting */ 101 | LocalCounter = OsAppModes_Array [Mode].AutoStartScheduleTables_Index ; 102 | 103 | if ( APPMODE_INVALID != LocalCounter ) 104 | { 105 | /* determine stop index of schedule tables which will be activated by for loop */ 106 | LocalTemp = OsAppModes_Array [Mode].AutoStartScheduleTables_Index + OsAppModes_Array [Mode].AutoStartScheduleTables_Number ; 107 | 108 | for( ; LocalCounter < LocalTemp ; LocalCounter++ ) 109 | { 110 | 111 | if( TABLE_ABSOLUTE == OsAutoStartTables_SettingArray[LocalCounter].OsScheduleTableAutostartType ) 112 | { 113 | /* 114 | StartScheduleTableAbs( OsAutoStartTabless_Array[LocalCounter] , OsAutoStartTables_SettingArray[LocalCounter].OsScheduleTableStartValue ) ; 115 | */ 116 | 117 | } 118 | else 119 | { 120 | /* 121 | StartScheduleTableRel( OsAutoStartTabless_Array[LocalCounter] , OsAutoStartTables_SettingArray[LocalCounter].OsScheduleTableStartValue ) ; 122 | */ 123 | 124 | } /* else */ 125 | 126 | } /* for */ 127 | 128 | } /* if */ 129 | else 130 | { 131 | /* this app mode hasn't auto start tasks */ 132 | } 133 | 134 | 135 | } 136 | else 137 | { 138 | /* application don't has any auto start to do */ 139 | } 140 | 141 | CS_OFF ; 142 | 143 | 144 | /* StartOS function mustn't return so if no auto start task it will enter idle loop till task activation happen */ 145 | while(1); 146 | } 147 | 148 | /********************************************************************************************/ 149 | 150 | /* user can call this system service to abort the overall system (e.g. emergency off). 151 | * The operating system also calls this function internally, 152 | * if it has reached an undefined internal state and is no longer ready to run. */ 153 | FUNC (void, OS_CODE) ShutdownOS ( StatusType Error ) 154 | { 155 | 156 | CS_ON ; 157 | while (1) ; 158 | 159 | } 160 | -------------------------------------------------------------------------------- /Os_Sources/OsInterface_Sources/Os_Isr.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Created by : Ahmad HEGAZY 4 | DATE : 15/2/2019 5 | AUTOSAR Version : 4.3.1 6 | DOC Name : AUTOSAR_SWS_OS.pdf 7 | OSEK/VDX.pdf 8 | Target : ARM TIVA_C TM4C123GH6PM 9 | 10 | */ 11 | 12 | 13 | 14 | 15 | #include "..\..\Os_Headers\OsInterface_Headers\Os.h" 16 | #include "..\..\Os_Headers\OsInternal_Headers\Os_Internal.h" 17 | #include "..\..\Os_Headers\OsInternal_Headers\Os_ExternalVariables.h" 18 | 19 | /* This service returns the identifier of the currently executing ISR.*/ 20 | FUNC(ISRType, OS_CODE) GetISRID( void ) 21 | { 22 | /* 23 | [SWS_Os_00263] If called from category 2 ISR (or Hook routines called inside a category 2 ISR), GetISRID() shall return the identifier of the currently executing ISR. 24 | [SWS_Os_00264] If its caller is not a category 2 ISR (or Hook routines called inside a category 2 ISR), GetISRID() shall return INVALID_ISR. 25 | */ 26 | return IsrID; 27 | } 28 | 29 | /*This service restores the state saved by DisableAllInterrupts.*/ 30 | FUNC(StatusType, OS_CODE) EnableAllInterrupts(void) 31 | { 32 | CS_ON; 33 | StatusType status = E_OK; 34 | 35 | /* The service may be called from an ISR category 1 and category 2 and from the task level, but not from hook routines. */ 36 | 37 | 38 | if( HookID != INVALID_HOOK) 39 | { 40 | status = E_NOT_OK; 41 | }else 42 | { 43 | 44 | /* This service is a counterpart of DisableAllInterrupts service, which has to be called before, and its aim is the completion of the critical section of code. */ 45 | if (ActiveIsrDisable != DisAllIntActive) 46 | { 47 | /* Error interrupts wasnot disabled using DisableAllInterrupts before enabling it*/ 48 | status = E_NOT_OK; 49 | } 50 | else 51 | { 52 | /* 53 | * The implementation should adapt this service to the target hardware providing a minimum overhead. Usually, this service enables recognition of interrupts by the central processing unit. 54 | */ 55 | ActiveIsrDisable = NoDisableActive; /* cannot be interrupted after because interrupt is disabled.*/ 56 | __asm volatile (" CPSIE i"); 57 | } 58 | } 59 | 60 | CS_OFF; /* disable critical section */ 61 | 62 | return status; 63 | } 64 | 65 | /*This service disables all interrupts for which the hardware supports disabling. The state before is saved for the EnableAllInterrupts call.*/ 66 | FUNC(StatusType, OS_CODE) DisableAllInterrupts(void) 67 | { 68 | CS_ON; 69 | StatusType status = E_OK; 70 | 71 | /* 72 | The service may be called from an ISR category 1 and category 2 and from the task level, but not from hook routines. 73 | */ 74 | if( HookID != INVALID_HOOK) 75 | { 76 | status = E_NOT_OK; 77 | CS_OFF; 78 | /* 79 | This service is intended to start a critical section of the code. This section shall be finished by calling the EnableAllInterrupts service. No API service calls are allowed within this critical section. 80 | */ 81 | } 82 | else 83 | { 84 | if (ActiveIsrDisable != NoDisableActive) 85 | { 86 | /* Error nesting is not supported*/ 87 | status = E_NOT_OK; 88 | CS_OFF; 89 | } 90 | else 91 | { 92 | /* 93 | The implementation should adapt this service to the target hardware providing a minimum overhead. Usually, this service disables recognition of interrupts by the central processing unit. 94 | Note that this service does not support nesting. If nesting is needed for critical sections e.g. for libraries SuspendOSInterrupts/ResumeOSInterrupts or SuspendAllInterrupt/ResumeAllInterrupts should be used. 95 | */ 96 | __asm volatile (" CPSID i"); 97 | ActiveIsrDisable = DisAllIntActive; /* cannot be interrupted before because interrupt is disabled. */ 98 | } 99 | } 100 | 101 | END_PRIVILEGE; 102 | return status; 103 | } 104 | /* The rest of the functions werenot implemented because we donot need them */ 105 | 106 | /* This service restores the recognition status of all interrupts saved by the SuspendAllInterrupts service. */ 107 | FUNC(StatusType, OS_CODE) ResumeAllInterrupts(void) 108 | { 109 | CS_ON; 110 | StatusType status = E_OK; 111 | 112 | /* 113 | The service may be called from an ISR category 1 and category 2, from alarm-callbacks and from the task level, but not from all hook routines. 114 | */ 115 | if( HookID != INVALID_HOOK) 116 | { 117 | status = E_NOT_OK; 118 | CS_OFF; 119 | } 120 | else 121 | { 122 | /* 123 | This service is the counterpart of SuspendAllInterrupts service, which has to have been called before, and its aim is the completion of the critical section of code. No API service calls beside SuspendAllInterrupts/ResumeAllInterrupts pairs and SuspendOSInterrupts/ResumeOSInterrupts pairs are allowed within this critical section. 124 | */ 125 | /* 126 | The implementation should adapt this service to the target hardware providing a minimum overhead. 127 | SuspendAllInterrupts/ResumeAllInterrupts can be nested. In case of nesting pairs of the calls SuspendAllInterrupts and ResumeAllInterrupts the interrupt recognition status saved by the first call of SuspendAllInterrupts is restored by the last call of the ResumeAllInterrupts service. 128 | */ 129 | if (ActiveIsrDisable != SuspendAllIntActive && ActiveIsrDisable != SuspendOSIntActive) 130 | { 131 | /* Error interrupts wasnot suspended before resuming them*/ 132 | status = E_NOT_OK; 133 | } 134 | else 135 | { 136 | PEND0_REG_ADDR = PEND0; 137 | PEND1_REG_ADDR = PEND1; 138 | PEND2_REG_ADDR = PEND2; 139 | PEND3_REG_ADDR = PEND3; 140 | PEND4_REG_ADDR = PEND4; 141 | UNPEND0_REG_ADDR = ~PEND0; 142 | UNPEND1_REG_ADDR = ~PEND1; 143 | UNPEND2_REG_ADDR = ~PEND2; 144 | UNPEND3_REG_ADDR = ~PEND3; 145 | UNPEND4_REG_ADDR = ~PEND4; 146 | if ( 0 == --suspendCount) 147 | { 148 | ActiveIsrDisable = NoDisableActive; 149 | CS_OFF; 150 | }else 151 | { 152 | ActiveIsrDisable = SuspendAllIntActive; 153 | } 154 | } 155 | } 156 | END_PRIVILEGE; 157 | return status; 158 | } 159 | 160 | /*This service saves the recognition status of all interrupts and disables all interrupts for which the hardware supports disabling.*/ 161 | FUNC(StatusType, OS_CODE) SuspendAllInterrupts(void) 162 | { 163 | CS_ON; 164 | StatusType status = E_OK; 165 | /* 166 | The service may be called from an ISR category 1 and category 2, from alarm-callbacks and from the task level, but not from all hook routines. 167 | */ 168 | if( HookID != INVALID_HOOK){ 169 | status = E_NOT_OK; 170 | CS_OFF; 171 | }else{ 172 | /* 173 | This service is intended to protect a critical section of code from interruptions of any kind. This section shall be finished by calling the ResumeAllInterrupts service. No API service calls beside SuspendAllInterrupts/ResumeAllInterrupts pairs and SuspendOSInterrupts/ResumeOSInterrupts pairs are allowed within this critical section. 174 | */ 175 | /* 176 | The implementation should adapt this service to the target hardware providing a minimum overhead. 177 | */ 178 | if (ActiveIsrDisable == NoDisableActive){ 179 | PEND0 = PEND0_REG_ADDR; 180 | PEND1 = PEND1_REG_ADDR; 181 | PEND2 = PEND2_REG_ADDR; 182 | PEND3 = PEND3_REG_ADDR; 183 | PEND4 = PEND4_REG_ADDR; 184 | ActiveIsrDisable = SuspendAllIntActive; 185 | suspendCount = 1; 186 | }else if (ActiveIsrDisable == DisAllIntActive){ 187 | /* nesting is not supported in DisableAllInterrupts*/ 188 | status = E_NOT_OK; 189 | CS_OFF; 190 | }else { 191 | /* Nesting, data is stored in the 1st time */ 192 | suspendCount++; 193 | } 194 | } 195 | END_PRIVILEGE; 196 | return status; 197 | } 198 | 199 | 200 | /*This service restores the recognition status of interrupts saved by the SuspendOSInterrupts service.*/ 201 | FUNC(StatusType, OS_CODE) ResumeOSInterrupts(void) 202 | { 203 | CS_ON; 204 | StatusType status = E_OK; 205 | /* 206 | The service may be called from an ISR category 1 and category 2, from alarm-callbacks and from the task level, but not from all hook routines. 207 | */ 208 | if( HookID != INVALID_HOOK) 209 | { 210 | status = E_NOT_OK; 211 | CS_OFF; 212 | }else 213 | { 214 | /* 215 | This service is the counterpart of SuspendAllInterrupts service, which has to have been called before, and its aim is the completion of the critical section of code. No API service calls beside SuspendAllInterrupts/ResumeAllInterrupts pairs and SuspendOSInterrupts/ResumeOSInterrupts pairs are allowed within this critical section. 216 | */ 217 | /* 218 | The implementation should adapt this service to the target hardware providing a minimum overhead. 219 | SuspendAllInterrupts/ResumeAllInterrupts can be nested. In case of nesting pairs of the calls SuspendAllInterrupts and ResumeAllInterrupts the interrupt recognition status saved by the first call of SuspendAllInterrupts is restored by the last call of the ResumeAllInterrupts service. 220 | */ 221 | if (ActiveIsrDisable != SuspendOSIntActive && ActiveIsrDisable != SuspendAllIntActive){ 222 | /* Error interrupts wasnot suspended before resuming them*/ 223 | status = E_NOT_OK; 224 | }else { 225 | PEND0_REG_ADDR = PEND0; 226 | PEND1_REG_ADDR = PEND1; 227 | PEND2_REG_ADDR = PEND2; 228 | PEND3_REG_ADDR = PEND3; 229 | PEND4_REG_ADDR = PEND4; 230 | UNPEND0_REG_ADDR = ~PEND0; 231 | UNPEND1_REG_ADDR = ~PEND1; 232 | UNPEND2_REG_ADDR = ~PEND2; 233 | UNPEND3_REG_ADDR = ~PEND3; 234 | UNPEND4_REG_ADDR = ~PEND4; 235 | 236 | if ( 0 == --suspendCount) 237 | { 238 | ActiveIsrDisable = NoDisableActive; 239 | CS_OFF; 240 | } 241 | else 242 | { 243 | ActiveIsrDisable = SuspendOSIntActive; 244 | } 245 | } 246 | } 247 | END_PRIVILEGE; 248 | return status; 249 | } 250 | 251 | /* This service saves the recognition status of interrupts of category 2 and disables the recognition of these interrupts.*/ 252 | FUNC(StatusType, OS_CODE) SuspendOSInterrupts(void){ 253 | CS_ON; 254 | StatusType status = E_OK; 255 | ActiveIsrDisable = SuspendOSIntActive; 256 | /* 257 | The service may be called from an ISR and from the task level, but not from hook routines. 258 | */ 259 | if( HookID != INVALID_HOOK){ 260 | status = E_NOT_OK; 261 | CS_OFF; 262 | }else{ 263 | /* 264 | This service is intended to protect a critical section of code. This section shall be finished by calling the ResumeOSInterrupts service. No API service calls beside SuspendAllInterrupts/ResumeAllInterrupts pairs and SuspendOSInterrupts/ResumeOSInterrupts pairs are allowed within this critical section. 265 | */ 266 | /* 267 | The implementation should adapt this service to the target hardware providing a minimum overhead. 268 | It is intended only to disable interrupts of category 2. However, if this is not possible in an efficient way more interrupts may be disabled. 269 | */ 270 | if (ActiveIsrDisable == NoDisableActive){ 271 | PEND0 = PEND0_REG_ADDR; 272 | PEND1 = PEND1_REG_ADDR; 273 | PEND2 = PEND2_REG_ADDR; 274 | PEND3 = PEND3_REG_ADDR; 275 | PEND4 = PEND4_REG_ADDR; 276 | ActiveIsrDisable = SuspendOSIntActive; 277 | suspendCount = 1; 278 | }else if (ActiveIsrDisable == DisAllIntActive){ 279 | /* nesting is not supported in DisableAllInterrupts*/ 280 | status = E_NOT_OK; 281 | CS_OFF; 282 | }else { 283 | /* Nesting, data is stored in the 1st time */ 284 | suspendCount++; 285 | } 286 | } 287 | END_PRIVILEGE; 288 | return status; 289 | } 290 | -------------------------------------------------------------------------------- /Os_Sources/OsInterface_Sources/Os_Resource.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Written by : Bebo 4 | DATE : 7/2/2019 5 | AUTOSAR Version : 4.3.1 6 | DOC Name : AUTOSAR_SWS_OS.pdf 7 | Target : ARM TIVA_C TM4C123GH6PM 8 | 9 | */ 10 | 11 | 12 | 13 | 14 | #include "..\..\Os_Headers\OsInterface_Headers\Os.h" 15 | #include "..\..\Os_Headers\OsInternal_Headers\Os_Internal.h" 16 | #include "..\..\Os_Headers\OsInternal_Headers\Os_ExternalVariables.h" 17 | 18 | 19 | 20 | 21 | /* call serves to enter critical sections in the code that are assigned to the resource referenced by . 22 | * A critical section shall always be left using ReleaseResource */ 23 | /* Nested resource occupation is only allowed 24 | * if the inner critical sections are completely executed within the surrounding critical section 25 | * by order LIFO last resource to get is the first to out */ 26 | /* Nested occupation of one and the same resource is also forbidden!*/ 27 | /* recommended that corresponding calls to GetResource and ReleaseResource appear within the same function */ 28 | /* not allowed to use services which are points of rescheduling for non preemptable tasks in resources critical section 29 | * this points is TerminateTask, WaitTask, ChainTask, Schedule */ 30 | /* critical sections are to be left before completion of an interrupt service routine */ 31 | /* critical sections should be short */ 32 | /* service may be called from an ISR and from task level */ 33 | /* Resource is invalid, E_OS_ID */ 34 | /* get a resource which is already occupied by any task or ISR, or the statically assigned priority of the calling task or 35 | interrupt routine is higher than the calculated ceiling priority, E_OS_ACCESS*/ 36 | FUNC (StatusType, OS_CODE) GetResource ( ResourceType ResID ) 37 | { 38 | CS_ON ; 39 | 40 | VAR( StatusType, AUTOMATIC ) ReturnResult = E_OK; 41 | VAR( uint8, AUTOMATIC ) CeilingPriority ; 42 | VAR( ResourceMaskType, AUTOMATIC ) ResourceMask ; 43 | if ( INVALID_ISR== IsrID) /* check if called form ISR level */ 44 | { 45 | /* called from task */ 46 | ResourceMask = ( OsTasks_Array [(OsTasksPCB_Array [ RunningTaskPCB_Index ].Task_ID)].OsTaskCeilingPriority_Internal ) & (1 << ResID) ; 47 | 48 | if ( ResID < OS_RESOURCES_NUMBER ) /* check for valid resource */ 49 | { 50 | /* check if task try to get resource which could occupy */ 51 | if ( OS_NO_RESOURCE_MASK != ResourceMask ) 52 | { 53 | /* resource is free and running task has right to get it 54 | * if running task has another resource other than ResID but has same or higher priority then the behavior won't change 55 | * case it try to get ResID instead of its resource */ 56 | 57 | /* first thing to do is allocate resource */ 58 | 59 | /* modify resource setting */ 60 | OsResourcePCB_Array[ ResID ].OsResourceOwner = OsTasksPCB_Array [ RunningTaskPCB_Index ].Task_ID ; 61 | OsResourcePCB_Array[ ResID ].OsPreviousResource = OsTasksPCB_Array [ RunningTaskPCB_Index ].Task_LastResourceOccupied ; 62 | OsTasksPCB_Array [ RunningTaskPCB_Index ].Task_LastResourceOccupied = ResID ; 63 | 64 | if ( (OsResource_Array[ResID].OsResourcePriority) > (OsTasksPCB_Array [ RunningTaskPCB_Index ].Task_Priority) ) 65 | { 66 | CeilingPriority = OsTasksPCB_Array [ RunningTaskPCB_Index ].Task_Priority ; 67 | OsTasksPCB_Array [ RunningTaskPCB_Index ].Task_Priority = OsResource_Array[ResID].OsResourcePriority ; 68 | 69 | if ( (OsResource_Array[ResID].OsResourcePriority) >= TASK_PRIORITIES_NUMBER ) 70 | { 71 | Resource_IsrMask( OsResource_Array[ResID].OsResourcePriority ) ; 72 | 73 | } 74 | else 75 | { 76 | /* remove task from old priority queue */ 77 | OsTasksPriority_Array [CeilingPriority] [ (OsTasksPriorityIndex_Array[CeilingPriority]) ] = INVALID_TASK ; 78 | OsTasksPriorityIndex_Array[CeilingPriority] = ( OsTasksPriorityIndex_Array[CeilingPriority] + 1 ) % TASKS_PER_PRIORITY ; 79 | 80 | /* put task in new queue */ 81 | OsHeadTask( RunningTaskPCB_Index ); 82 | } 83 | 84 | } 85 | else 86 | { 87 | } 88 | 89 | } 90 | else 91 | { 92 | /* ceiling priority of task is higher or lower than ceiling priority of resource, 93 | * if resource occupied by another task if this task access same resource it won't get in running state 94 | * if not then its priority is higher than ceiling priority 95 | * if not then this resource is not occupied and lower priority task trying to get it */ 96 | ReturnResult = E_OS_ACCESS ; 97 | } /* else */ 98 | 99 | } /* if */ 100 | else 101 | { 102 | /* invalid resource id */ 103 | ReturnResult = E_OS_ID ; 104 | 105 | } /* else */ 106 | 107 | } /* if */ 108 | else 109 | { 110 | /* called form isr */ 111 | 112 | if ( ResID < OS_RESOURCES_NUMBER ) /* check for valid resource */ 113 | { 114 | ResourceMask = ( OsIsr_Array [IsrID].OsResourceRef ) & (1 << ResID) ; 115 | 116 | 117 | if ( OS_NO_RESOURCE_MASK != ResourceMask ) 118 | { 119 | 120 | /* modify resource setting */ 121 | OsResourcePCB_Array[ ResID ].OsResourceOwner = IsrID ; 122 | OsResourcePCB_Array[ ResID ].OsPreviousResource = OsIsr_Array [IsrID].Isr_LastResourceOccupied ; 123 | OsIsr_Array [IsrID].Isr_LastResourceOccupied = ResID ; 124 | 125 | 126 | if ( (OsResource_Array[ResID].OsResourcePriority) > (OsIsr_Array [ IsrID ].Isr_Priority) ) 127 | { 128 | Resource_IsrMask( OsResource_Array[ResID].OsResourcePriority ); 129 | } 130 | else 131 | { 132 | } 133 | 134 | } 135 | else 136 | { 137 | } 138 | 139 | } /* if */ 140 | else 141 | { 142 | 143 | /* invalid resource id */ 144 | ReturnResult = E_OS_ID ; 145 | 146 | } /* else */ 147 | 148 | } /* else */ 149 | 150 | 151 | if ( TRUE == OsResource_CS_Flag ) 152 | { 153 | OsResource_CS_Flag = FALSE ; 154 | } 155 | else 156 | { 157 | CS_OFF ; 158 | 159 | } 160 | return ReturnResult ; 161 | } 162 | 163 | 164 | /*****************************************************************************/ 165 | 166 | 167 | /* ReleaseResource is the counterpart of GetResource and serves to 168 | * leave critical sections in the code that are assigned to the resource referenced by . */ 169 | /* The service may be called from an ISR and from task level */ 170 | /* Resource is invalid, E_OS_ID */ 171 | /* Attempt to release a resource which is not occupied by any task or ISR, or another resource shall be released before, E_OS_NOFUNC */ 172 | /* Attempt to release a resource which has a lower ceiling priority than 173 | * the statically assigned priority of the calling task or interrupt routine, E_OS_ACCESS */ 174 | FUNC (StatusType, OS_CODE) ReleaseResource ( ResourceType ResID ) 175 | { 176 | CS_ON ; 177 | 178 | VAR( StatusType, AUTOMATIC ) ReturnResult = E_OK; 179 | VAR( uint8, AUTOMATIC ) CeilingPriority ; 180 | VAR( ResourceType, AUTOMATIC ) ResID_Temp ; 181 | VAR( ResourceMaskType, AUTOMATIC ) ResourceMask = ( OsTasks_Array [(OsTasksPCB_Array [ RunningTaskPCB_Index ].Task_ID)].OsTaskCeilingPriority_Internal ) & (1 << ResID) ; 182 | 183 | 184 | 185 | if ( INVALID_ISR== IsrID) /* check if called form ISR level */ 186 | { 187 | /* called from task */ 188 | CeilingPriority = OsTasks_Array [ ( OsTasksPCB_Array [ RunningTaskPCB_Index ].Task_ID ) ].OsTaskCeilingPriority_Internal ; 189 | 190 | if ( ResID < OS_RESOURCES_NUMBER ) /* check for valid resource */ 191 | { 192 | if ( OS_NO_RESOURCE_MASK != ResourceMask ) 193 | { 194 | /* check for releasing sequence of nested resources */ 195 | if ( ResID == OsTasksPCB_Array [ RunningTaskPCB_Index ].Task_LastResourceOccupied) 196 | { 197 | /* free ResID from task's resources list */ 198 | 199 | OsTasksPCB_Array [ RunningTaskPCB_Index ].Task_LastResourceOccupied = OsResourcePCB_Array[ ResID ].OsPreviousResource ; 200 | OsResourcePCB_Array[ ResID ].OsPreviousResource = OS_NO_RESOURCE ; 201 | OsResourcePCB_Array[ ResID ].OsResourceOwner = INVALID_TASK ; 202 | 203 | 204 | /* check if running task still occupy resources */ 205 | if( OS_NO_RESOURCE == ( OsTasksPCB_Array [ RunningTaskPCB_Index ].Task_LastResourceOccupied ) ) 206 | { 207 | 208 | } 209 | else 210 | { 211 | /* running task still occupy resource */ 212 | 213 | if( (OsTasksPCB_Array [ RunningTaskPCB_Index ].Task_Priority) > (OsResource_Array[ ResID ].OsResourcePriority) ) 214 | { 215 | 216 | } 217 | else 218 | { 219 | 220 | /* check for task ceiling priority */ 221 | CeilingPriority = OsTasks_Array [ ( OsTasksPCB_Array [ RunningTaskPCB_Index ].Task_ID ) ].OsTaskCeilingPriority_Internal ; 222 | ResID_Temp = OsTasksPCB_Array [ RunningTaskPCB_Index ].Task_LastResourceOccupied ; 223 | 224 | if( (OsResource_Array[ResID_Temp].OsResourcePriority) > CeilingPriority ) 225 | { 226 | OsTasksPCB_Array [ RunningTaskPCB_Index ].Task_Priority = OsResource_Array[ResID_Temp].OsResourcePriority ; 227 | } 228 | else 229 | { 230 | OsTasksPCB_Array [ RunningTaskPCB_Index ].Task_Priority = CeilingPriority ; 231 | } 232 | 233 | OsHeadTask( RunningTaskPCB_Index ) ; 234 | RemoveTask( OsResource_Array[ResID].OsResourcePriority ) ; 235 | 236 | } 237 | 238 | } /* else */ 239 | 240 | Resource_IsrMask( OsTasksPCB_Array [ RunningTaskPCB_Index ].Task_Priority ); 241 | 242 | } 243 | else 244 | { 245 | /* another resource must released first or task don't occupy this resource */ 246 | ReturnResult = E_OS_NOFUNC ; 247 | 248 | } /* else */ 249 | 250 | } /* if */ 251 | else 252 | { 253 | /* ceiling priority of task is higher or lower than ceiling priority of resource, 254 | * if resource occupied by another task if this task access same resource it won't get in running state 255 | * if not then its priority is higher than ceiling priority 256 | * if not then this resource is not occupied and lower priority task trying to get it */ 257 | ReturnResult = E_OS_ACCESS ; 258 | } /* else */ 259 | 260 | } /* if */ 261 | else 262 | { 263 | /* invalid resource id */ 264 | ReturnResult = E_OS_ID ; 265 | 266 | } /* else */ 267 | 268 | } /* if*/ 269 | else 270 | { 271 | /* called from isr */ 272 | 273 | CeilingPriority = OsIsr_Array [ IsrID ].OsResourceRef ; 274 | 275 | if ( ResID < OS_RESOURCES_NUMBER ) /* check for valid resource */ 276 | { 277 | if ( OS_NO_RESOURCE_MASK != ResourceMask ) 278 | { 279 | 280 | /* check for releasing sequence of nested resources */ 281 | if ( ResID == OsIsr_Array [ IsrID ].Isr_LastResourceOccupied) 282 | { 283 | /* free ResID from task's resources list */ 284 | OsIsr_Array [ IsrID ].Isr_LastResourceOccupied = OsResourcePCB_Array[ ResID ].OsPreviousResource ; 285 | OsResourcePCB_Array[ ResID ].OsPreviousResource = OS_NO_RESOURCE ; 286 | OsResourcePCB_Array[ ResID ].OsResourceOwner = INVALID_TASK ; 287 | 288 | /* check if running task still occupy resources */ 289 | if( OS_NO_RESOURCE == ( OsTasksPCB_Array [ RunningTaskPCB_Index ].Task_LastResourceOccupied ) ) 290 | { 291 | 292 | } 293 | else 294 | { 295 | /* running task still occupy resource */ 296 | 297 | if( (OsIsr_Array [ IsrID ].Isr_Priority) > (OsResource_Array[ ResID ].OsResourcePriority) ) 298 | { 299 | 300 | } 301 | else 302 | { 303 | 304 | ResID_Temp = OsIsr_Array [ IsrID ].Isr_LastResourceOccupied ; 305 | Resource_IsrMask( OsResource_Array[ResID_Temp].OsResourcePriority ); 306 | 307 | } 308 | 309 | } /* else */ 310 | 311 | } 312 | else 313 | { 314 | /* another resource must released first or task don't occupy this resource */ 315 | ReturnResult = E_OS_NOFUNC ; 316 | 317 | } /* else */ 318 | 319 | } 320 | else 321 | { 322 | /* ceiling priority of task is higher or lower than ceiling priority of resource, 323 | * if resource occupied by another task if this task access same resource it won't get in running state 324 | * if not then its priority is higher than ceiling priority 325 | * if not then this resource is not occupied and lower priority task trying to get it */ 326 | ReturnResult = E_OS_ACCESS ; 327 | } 328 | } 329 | else 330 | { 331 | /* invalid resource id */ 332 | ReturnResult = E_OS_ID ; 333 | } 334 | } 335 | 336 | if ( TRUE == OsResource_CS_Flag ) 337 | { 338 | OsResource_CS_Flag = FALSE ; 339 | } 340 | else 341 | { 342 | CS_OFF ; 343 | 344 | } 345 | 346 | return ReturnResult ; 347 | 348 | 349 | } 350 | 351 | 352 | 353 | /*****************************************************************************/ 354 | -------------------------------------------------------------------------------- /Os_Sources/OsInterface_Sources/Os_ScheduleTable.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Written by : Bakr 4 | DATE : 18/2/2020 5 | AUTOSAR Version : 4.3.1 6 | DOC Name : AUTOSAR_SWS_OS.pdf 7 | Target : ARM TIVA_C TM4C123GH6PM 8 | 9 | */ 10 | 11 | 12 | 13 | #include "..\..\Os_Headers\OsInterface_Headers\Os.h" 14 | #include "..\..\Os_Headers\OsInternal_Headers\Os_Internal.h" 15 | 16 | 17 | extern CONST( OsScheduleTable, OS_CONFIG_DATA ) ScheduleTable_Array [ TABLES_NUMBER ] ; 18 | 19 | extern VAR( OsScheduleTableInternal, OS_CONFIG_DATA ) ScheduleTableInternal_Array [ TABLES_NUMBER ] ; 20 | 21 | extern CONST( OsScheduleTableExpiryPoint, OS_CONFIG_DATA ) ScheduleTablePoints_Array [ TABLES_POINTS_NUMBER ] ; 22 | 23 | 24 | extern CONST( EventMaskType, OS_CONFIG_DATA ) ScheduleTableEventSet_Array [ TABLES_EVENTS_SET_NUMBER ] ; 25 | 26 | extern CONST( OsCounter, OS_CONFIG_DATA ) OsCounter_Array [ COUNTERS_NUMBER ] ; 27 | 28 | extern VAR( OsCounterInternal, OS_DATA) OsCounterInternal_Array [COUNTERS_NUMBER ]; 29 | 30 | extern VAR( ExpiryPointOffset, OS_DATA ) ScheduleTablePointsOffsets_Array[TABLES_POINTS_NUMBER ]; 31 | 32 | /* 33 | - Service: 0x07, Synchronous, Reentrant 34 | - This service starts the processing of a schedule table at "Offset" relative to the "Now" value on the underlying counter. 35 | */ 36 | FUNC(StatusType, OS_CODE) StartScheduleTableRel( ScheduleTableType ScheduleTableID, TickType Offset ){ 37 | 38 | VAR(StatusType, AUTOMATIC) RetVal = E_OK; 39 | 40 | VAR( uint16, AUTOMATIC ) i, j; 41 | 42 | 43 | 44 | #if OS_MODE == OS_STANDARD 45 | 46 | /* [SWS_Os_00452] If the schedule table in a call of StartScheduleTableRel() is implicitely 47 | synchronized (OsScheduleTblSyncStrategy = IMPLICIT), StartScheduleTableRel() shall return E_OS_ID. ( ) */ 48 | if(ScheduleTable_Array[ScheduleTableID].OsScheduleTblSyncStrategy == IMPLICIT){ 49 | 50 | RetVal = E_OS_ID; 51 | 52 | }if(ScheduleTableID >= TABLES_NUMBER){ 53 | 54 | RetVal = E_OS_ID; 55 | 56 | }else if(Offset == 0 || 57 | Offset > OsCounter_Array[ScheduleTable_Array[ScheduleTableID].OsScheduleTableCounterRef].OsCounterMaxAllowedValue || 58 | Offset < OsCounter_Array[ScheduleTable_Array[ScheduleTableID].OsScheduleTableCounterRef].OsCounterMinCycle || 59 | (Offset + ScheduleTable_Array[ScheduleTableID].OsScheduleTableDuration) > OsCounter_Array[ScheduleTable_Array[ScheduleTableID].OsScheduleTableCounterRef].OsCounterMaxAllowedValue) 60 | { 61 | 62 | 63 | }else if(ScheduleTableInternal_Array[ScheduleTableID].CurrentState != SCHEDULETABLE_STOPPED){ 64 | 65 | /* [SWS_Os_00277] If the schedule table in a call of StartScheduleTableRel() is not in the state SCHEDULETABLE_STOPPED, 66 | StartScheduleTableRel() shall return E_OS_STATE. ( ) */ 67 | 68 | RetVal = E_OS_STATE; 69 | }else{ 70 | /* [SWS_Os_00278] If the input parameters of StartScheduleTableRel() are valid and 71 | the state of schedule table is SCHEDULETABLE_STOPPED, 72 | then StartScheduleTableRel() shall start the processing of a schedule table . 73 | The Initial Expiry Point shall be processed after + Initial Offset ticks have elapsed on the underlying counter. 74 | The state of is set to SCHEDULETABLE_RUNNING before the service returns to the caller. ( ) */ 75 | 76 | 77 | for(i = ScheduleTable_Array[ScheduleTableID].FirstExpiryPoint, j = 0; i < ScheduleTable_Array[ScheduleTableID].ExpiryPointsNumber + ScheduleTable_Array[ScheduleTableID].FirstExpiryPoint ; i++, j++){ 78 | 79 | ScheduleTablePointsOffsets_Array[i].EPCurrentOffset = Offset + ScheduleTablePoints_Array[j].OsScheduleTblExpPointOffset ; 80 | ScheduleTablePointsOffsets_Array[i].EPFullOffset = ScheduleTablePointsOffsets_Array[i].EPCurrentOffset; 81 | 82 | } 83 | 84 | /* set index of schedule table expiry point to start */ 85 | ScheduleTableInternal_Array[ScheduleTableID].CurrentExpiryPointIndex = ScheduleTable_Array[ScheduleTableID].FirstExpiryPoint; 86 | 87 | ScheduleTableInternal_Array[ScheduleTableID].ScheduleTableDuration = ScheduleTable_Array[ScheduleTableID].OsScheduleTableDuration + Offset; 88 | 89 | ScheduleTableInternal_Array[ScheduleTableID].NextScheduleTable = EMPTY_NEXT_TABLE; 90 | 91 | /* set schedule table state to running */ 92 | ScheduleTableInternal_Array[ScheduleTableID].CurrentState = SCHEDULETABLE_RUNNING; 93 | 94 | } 95 | 96 | 97 | #elif OS_MODE == OS_EXTENDED 98 | 99 | /* [SWS_Os_00275] If the schedule table in a call of StartScheduleTableRel() 100 | is not valid, StartScheduleTableRel() shall return E_OS_ID. in EXTENDED MODE ( )*/ 101 | if(ScheduleTableID >= TABLES_NUMBER){ 102 | 103 | RetVal = E_OS_ID; 104 | 105 | }else if(ScheduleTable_Array[ScheduleTableID].OsScheduleTblSyncStrategy == IMPLICIT){ 106 | /* [SWS_Os_00452] If the schedule table in a call of StartScheduleTableRel() is implicitely 107 | synchronized (OsScheduleTblSyncStrategy = IMPLICIT), StartScheduleTableRel() shall return E_OS_ID. ( ) */ 108 | RetVal = E_OS_ID; 109 | 110 | }else if(Offset == 0 || 111 | Offset > OsCounter_Array[ScheduleTable_Array[ScheduleTableID].OsScheduleTableCounterRef].OsCounterMaxAllowedValue || 112 | Offset < OsCounter_Array[ScheduleTable_Array[ScheduleTableID].OsScheduleTableCounterRef].OsCounterMinCycle 113 | ) 114 | { 115 | /* [SWS_Os_00332] If in a call of StartScheduleTableRel() is zero StartScheduleTableRel() shall 116 | return E_OS_VALUE. in EXTENDED ( ) */ 117 | 118 | /* [SWS_Os_00276] If the offset ) is greater than OsCounterMaxAllowedValue of the underlying counter minus the Initial Offset, 119 | StartScheduleTableRel() shall return E_OS_VALUE. in EXTENDED ( ) */ 120 | 121 | RetVal = E_OS_VALUE; 122 | 123 | }else if(ScheduleTableInternal_Array[ScheduleTableID].CurrentState != SCHEDULETABLE_STOPPED){ 124 | 125 | /* [SWS_Os_00277] If the schedule table in a call of StartScheduleTableRel() is not in the state SCHEDULETABLE_STOPPED, 126 | StartScheduleTableRel() shall return E_OS_STATE. ( ) */ 127 | 128 | RetVal = E_OS_STATE; 129 | 130 | }else{ 131 | /* [SWS_Os_00278] If the input parameters of StartScheduleTableRel() are valid and 132 | the state of schedule table is SCHEDULETABLE_STOPPED, 133 | then StartScheduleTableRel() shall start the processing of a schedule table . 134 | The Initial Expiry Point shall be processed after + Initial Offset ticks have elapsed on the underlying counter. 135 | The state of is set to SCHEDULETABLE_RUNNING before the service returns to the caller. ( ) */ 136 | 137 | /* store the current value of the counter */ 138 | 139 | for(i = ScheduleTable_Array[ScheduleTableID].FirstExpiryPoint, j = 0; i < ScheduleTable_Array[ScheduleTableID].ExpiryPointsNumber + ScheduleTable_Array[ScheduleTableID].FirstExpiryPoint ; i++, j++){ 140 | 141 | ScheduleTablePointsOffsets_Array[i].EPCurrentOffset = Offset + ScheduleTablePoints_Array[j].OsScheduleTblExpPointOffset ; 142 | ScheduleTablePointsOffsets_Array[i].EPFullOffset = ScheduleTablePointsOffsets_Array[i].EPCurrentOffset; 143 | 144 | } 145 | 146 | /* set index of schedule table expiry point to start */ 147 | ScheduleTableInternal_Array[ScheduleTableID].CurrentExpiryPointIndex = ScheduleTable_Array[ScheduleTableID].FirstExpiryPoint; 148 | 149 | ScheduleTableInternal_Array[ScheduleTableID].ScheduleTableDuration = ScheduleTable_Array[ScheduleTableID].OsScheduleTableDuration + Offset; 150 | 151 | ScheduleTableInternal_Array[ScheduleTableID].NextScheduleTable = EMPTY_NEXT_TABLE; 152 | 153 | /* set schedule table state to running */ 154 | ScheduleTableInternal_Array[ScheduleTableID].CurrentState = SCHEDULETABLE_RUNNING; 155 | 156 | } 157 | 158 | #endif 159 | 160 | return RetVal; 161 | } 162 | 163 | FUNC( StatusType, OS_CODE ) StartScheduleTableAbs( ScheduleTableType ScheduleTableID, TickType Start ) { 164 | 165 | VAR(StatusType, AUTOMATIC) RetVal = E_OK; 166 | 167 | VAR( uint16, AUTOMATIC ) i, j; 168 | 169 | VAR( TickType, AUTOMATIC ) Offset; 170 | 171 | 172 | #if OS_MODE == OS_STANDARD 173 | 174 | /* [SWS_Os_00452] If the schedule table in a call of StartScheduleTableRel() is implicitely 175 | synchronized (OsScheduleTblSyncStrategy = IMPLICIT), StartScheduleTableRel() shall return E_OS_ID. ( ) */ 176 | if(ScheduleTable_Array[ScheduleTableID].OsScheduleTblSyncStrategy == IMPLICIT){ 177 | 178 | RetVal = E_OS_ID; 179 | 180 | }else if(ScheduleTableID >= TABLES_NUMBER){ 181 | 182 | 183 | }else if(Start > OsCounter_Array[ScheduleTable_Array[ScheduleTableID].OsScheduleTableCounterRef].OsCounterMaxAllowedValue || 184 | Start < OsCounter_Array[ScheduleTable_Array[ScheduleTableID].OsScheduleTableCounterRef].OsCounterMinCycle || 185 | (Start + ScheduleTable_Array[ScheduleTableID].OsScheduleTableDuration) > OsCounter_Array[ScheduleTable_Array[ScheduleTableID].OsScheduleTableCounterRef].OsCounterMaxAllowedValue) 186 | { 187 | 188 | }else if(ScheduleTableInternal_Array[ScheduleTableID].CurrentState != SCHEDULETABLE_STOPPED){ 189 | 190 | /* [SWS_Os_00350] If the schedule table in a call of StartScheduleTableAbs() is not in the state SCHEDULETABLE_STOPPED, 191 | StartScheduleTableAbs() shall return E_OS_STATE. ( ) */ 192 | 193 | RetVal = E_OS_STATE; 194 | }else{ 195 | /* [SWS_Os_00351] If the input parameters of StartScheduleTableAbs() are valid and is in the state SCHEDULETABLE_STOPPED, StartScheduleTableAbs() shall start the processing of schedule table when the underlying counter next equals and shall set the state of to 196 | - SCHEDULETABLE_RUNNING (for a non-synchronized / Explicitly synchronized schedule table) OR 197 | - SCHEDULETABLE_RUNNING_AND_SYNCHRONOUS (for implicitly synchronized schedule table) before returning to the user. 198 | (The Initial Expiry Point will be processed when the underlying counter next equals +Initial Offset). ( ) */ 199 | 200 | /* store the current value of the counter */ 201 | //ScheduleTableInternal_Array[ScheduleTableID].StartCounterVal = Start; 202 | 203 | if(OsCounterInternal_Array[ScheduleTable_Array[ScheduleTableID].OsScheduleTableCounterRef].OsCounterVal > Start){ 204 | Offset = OsCounter_Array[ScheduleTable_Array[ScheduleTableID].OsScheduleTableCounterRef].OsCounterMaxAllowedValue - OsCounterInternal_Array[ScheduleTable_Array[ScheduleTableID].OsScheduleTableCounterRef].OsCounterVal 205 | + Start; 206 | }else if(OsCounterInternal_Array[ScheduleTable_Array[ScheduleTableID].OsScheduleTableCounterRef].OsCounterVal <= Start){ 207 | 208 | Offset = Start - OsCounterInternal_Array[ScheduleTable_Array[ScheduleTableID].OsScheduleTableCounterRef].OsCounterVal; 209 | 210 | } 211 | 212 | for(i = ScheduleTable_Array[ScheduleTableID].FirstExpiryPoint, j = 0; i < ScheduleTable_Array[ScheduleTableID].ExpiryPointsNumber + ScheduleTable_Array[ScheduleTableID].FirstExpiryPoint ; i++, j++){ 213 | 214 | ScheduleTablePointsOffsets_Array[i].EPCurrentOffset = Offset + ScheduleTablePoints_Array[j].OsScheduleTblExpPointOffset ; 215 | ScheduleTablePointsOffsets_Array[i].EPFullOffset = ScheduleTablePointsOffsets_Array[i].EPCurrentOffset; 216 | 217 | } 218 | /* set index of schedule table expiry point to start */ 219 | ScheduleTableInternal_Array[ScheduleTableID].CurrentExpiryPointIndex = ScheduleTable_Array[ScheduleTableID].FirstExpiryPoint; 220 | 221 | ScheduleTableInternal_Array[ScheduleTableID].ScheduleTableDuration = ScheduleTable_Array[ScheduleTableID].OsScheduleTableDuration+ Offset; 222 | 223 | 224 | ScheduleTableInternal_Array[ScheduleTableID].NextScheduleTable = EMPTY_NEXT_TABLE; 225 | 226 | /* set schedule table state to running */ 227 | ScheduleTableInternal_Array[ScheduleTableID].CurrentState = SCHEDULETABLE_RUNNING; 228 | 229 | } 230 | 231 | 232 | #elif OS_MODE == OS_EXTENDED 233 | 234 | /* [SWS_Os_00452] If the schedule table in a call of StartScheduleTableRel() is implicitely 235 | synchronized (OsScheduleTblSyncStrategy = IMPLICIT), StartScheduleTableRel() shall return E_OS_ID. ( ) */ 236 | if(ScheduleTable_Array[ScheduleTableID].OsScheduleTblSyncStrategy == IMPLICIT){ 237 | 238 | RetVal = E_OS_ID; 239 | 240 | }else if(ScheduleTableID >= TABLES_NUMBER){ 241 | 242 | /*[SWS_Os_00348] If the schedule table in a call of StartScheduleTableAbs() is not valid, 243 | StartScheduleTableAbs() shall return E_OS_ID. ( )*/ 244 | 245 | RetVal = E_OS_ID; 246 | 247 | }else if(Start > OsCounter_Array[ScheduleTable_Array[ScheduleTableID].OsScheduleTableCounterRef].OsCounterMaxAllowedValue || 248 | Start < OsCounter_Array[ScheduleTable_Array[ScheduleTableID].OsScheduleTableCounterRef].OsCounterMinCycle || 249 | (Start + ScheduleTable_Array[ScheduleTableID].OsScheduleTableDuration) >= OsCounter_Array[ScheduleTable_Array[ScheduleTableID].OsScheduleTableCounterRef].OsCounterMaxAllowedValue) 250 | { 251 | 252 | /*[SWS_Os_00349] If the in a call of StartScheduleTableAbs() is greater than the OsCounterMaxAllowedValue of the underlying counter, 253 | StartScheduleTableAbs() shall return E_OS_VALUE. ( )*/ 254 | RetVal = E_OS_VALUE; 255 | 256 | }else if(ScheduleTableInternal_Array[ScheduleTableID].CurrentState != SCHEDULETABLE_STOPPED){ 257 | 258 | /* [SWS_Os_00350] If the schedule table in a call of StartScheduleTableAbs() is not in the state SCHEDULETABLE_STOPPED, 259 | StartScheduleTableAbs() shall return E_OS_STATE. ( ) */ 260 | 261 | RetVal = E_OS_STATE; 262 | }else{ 263 | /* [SWS_Os_00351] If the input parameters of StartScheduleTableAbs() are valid and is in the state SCHEDULETABLE_STOPPED, StartScheduleTableAbs() shall start the processing of schedule table when the underlying counter next equals and shall set the state of to 264 | - SCHEDULETABLE_RUNNING (for a non-synchronized / Explicitly synchronized schedule table) OR 265 | - SCHEDULETABLE_RUNNING_AND_SYNCHRONOUS (for implicitly synchronized schedule table) before returning to the user. 266 | (The Initial Expiry Point will be processed when the underlying counter next equals +Initial Offset). ( ) */ 267 | 268 | 269 | if(OsCounterInternal_Array[ScheduleTable_Array[ScheduleTableID].OsScheduleTableCounterRef].OsCounterVal > Start){ 270 | Offset = OsCounter_Array[ScheduleTable_Array[ScheduleTableID].OsScheduleTableCounterRef].OsCounterMaxAllowedValue - OsCounterInternal_Array[ScheduleTable_Array[ScheduleTableID].OsScheduleTableCounterRef].OsCounterVal 271 | + Start; 272 | }else if(OsCounterInternal_Array[ScheduleTable_Array[ScheduleTableID].OsScheduleTableCounterRef].OsCounterVal <= Start){ 273 | 274 | Offset = Start - OsCounterInternal_Array[ScheduleTable_Array[ScheduleTableID].OsScheduleTableCounterRef].OsCounterVal; 275 | 276 | } 277 | 278 | 279 | for(i = ScheduleTable_Array[ScheduleTableID].FirstExpiryPoint, j = 0; i < ScheduleTable_Array[ScheduleTableID].ExpiryPointsNumber + ScheduleTable_Array[ScheduleTableID].FirstExpiryPoint ; i++, j++){ 280 | 281 | ScheduleTablePointsOffsets_Array[i].EPCurrentOffset = Offset + ScheduleTablePoints_Array[j].OsScheduleTblExpPointOffset ; 282 | ScheduleTablePointsOffsets_Array[i].EPFullOffset = ScheduleTablePointsOffsets_Array[i].EPCurrentOffset; 283 | 284 | } 285 | /* set index of schedule table expiry point to start */ 286 | ScheduleTableInternal_Array[ScheduleTableID].CurrentExpiryPointIndex = ScheduleTable_Array[ScheduleTableID].FirstExpiryPoint; 287 | 288 | ScheduleTableInternal_Array[ScheduleTableID].ScheduleTableDuration = ScheduleTable_Array[ScheduleTableID].OsScheduleTableDuration+ Offset; 289 | 290 | ScheduleTableInternal_Array[ScheduleTableID].NextScheduleTable = EMPTY_NEXT_TABLE; 291 | 292 | /* set schedule table state to running */ 293 | ScheduleTableInternal_Array[ScheduleTableID].CurrentState = SCHEDULETABLE_RUNNING; 294 | 295 | } 296 | 297 | #endif 298 | 299 | 300 | return RetVal; 301 | } 302 | 303 | FUNC( StatusType, OS_CODE ) StopScheduleTable( ScheduleTableType ScheduleTableID ){ 304 | 305 | StatusType RetVal = E_OK; 306 | 307 | 308 | #if OS_MODE == OS_STANDARD 309 | 310 | if(ScheduleTableID >= TABLES_NUMBER){ 311 | 312 | 313 | }else if(ScheduleTableInternal_Array[ScheduleTableID].CurrentState != SCHEDULETABLE_STOPPED){ 314 | 315 | /* [SWS_Os_00280] If the schedule table with identifier is in state SCHEDULETABLE_STOPPED when calling StopScheduleTable(), 316 | StopScheduleTable() shall return E_OS_NOFUNC. ( ) */ 317 | 318 | RetVal = E_OS_NOFUNC; 319 | 320 | }else{ 321 | 322 | ScheduleTableInternal_Array[ScheduleTableID].CurrentState = SCHEDULETABLE_STOPPED; 323 | 324 | if(ScheduleTableInternal_Array[ScheduleTableID].NextScheduleTable != EMPTY_NEXT_TABLE){ 325 | 326 | ScheduleTableInternal_Array[ScheduleTableInternal_Array[ScheduleTableID].NextScheduleTable].CurrentState = SCHEDULETABLE_STOPPED; 327 | 328 | } 329 | } 330 | 331 | 332 | #elif OS_MODE == OS_EXTENDED 333 | 334 | if(ScheduleTableID >= TABLES_NUMBER){ 335 | 336 | /*[SWS_Os_00279] If the schedule table identifier in a call of StopScheduleTable() is not valid, 337 | StopScheduleTable() shall return E_OS_ID. ( )*/ 338 | 339 | RetVal = E_OS_ID; 340 | 341 | }else if(ScheduleTableInternal_Array[ScheduleTableID].CurrentState != SCHEDULETABLE_STOPPED){ 342 | 343 | /* [SWS_Os_00280] If the schedule table with identifier is in state SCHEDULETABLE_STOPPED when calling StopScheduleTable(), 344 | StopScheduleTable() shall return E_OS_NOFUNC. ( ) */ 345 | 346 | RetVal = E_OS_NOFUNC; 347 | }else{ 348 | 349 | ScheduleTableInternal_Array[ScheduleTableID].CurrentState = SCHEDULETABLE_STOPPED; 350 | 351 | if(ScheduleTableInternal_Array[ScheduleTableID].NextScheduleTable != EMPTY_NEXT_TABLE){ 352 | 353 | ScheduleTableInternal_Array[ScheduleTableInternal_Array[ScheduleTableID].NextScheduleTable].CurrentState = SCHEDULETABLE_STOPPED; 354 | 355 | } 356 | } 357 | 358 | #endif 359 | 360 | 361 | return RetVal; 362 | 363 | } 364 | 365 | FUNC( StatusType, OS_CODE ) NextScheduleTable( ScheduleTableType ScheduleTableID_From, ScheduleTableType ScheduleTableID_To ) { 366 | 367 | StatusType RetVal = E_OK; 368 | 369 | #if OS_MODE == OS_STANDARD 370 | 371 | if(ScheduleTableID_From >= TABLES_NUMBER || ScheduleTableID_To >= TABLES_NUMBER ){ 372 | 373 | 374 | }else if(ScheduleTable_Array[ScheduleTableID_From].OsScheduleTableCounterRef != ScheduleTable_Array[ScheduleTableID_To].OsScheduleTableCounterRef){ 375 | 376 | 377 | }else if(ScheduleTableInternal_Array[ScheduleTableID_From].CurrentState != SCHEDULETABLE_RUNNING){ 378 | 379 | /* [SWS_Os_00330] If in a call of NextScheduleTable() schedule table is driven by different counter 380 | than schedule table then NextScheduleTable() shall return an error E_OS_ID. ( )*/ 381 | 382 | RetVal = E_OS_NOFUNC; 383 | 384 | }else if(ScheduleTableInternal_Array[ScheduleTableID_To].CurrentState != SCHEDULETABLE_STOPPED){ 385 | 386 | /* [SWS_Os_00309] If the schedule table in a call of NextScheduleTable() is not in state SCHEDULETABLE_STOPPED, 387 | NextScheduleTable() shall leave the state of and unchanged and return E_OS_STATE. ( ) */ 388 | 389 | RetVal = E_OS_STATE; 390 | 391 | }else if(ScheduleTable_Array[ScheduleTableID_To].OsScheduleTblSyncStrategy != ScheduleTable_Array[ScheduleTableID_From].OsScheduleTblSyncStrategy){ 392 | 393 | 394 | }else{ 395 | 396 | if(ScheduleTableInternal_Array[ScheduleTableID_From].NextScheduleTable != EMPTY_NEXT_TABLE){ 397 | 398 | /* change the state of the previous next table */ 399 | ScheduleTableInternal_Array[ScheduleTableInternal_Array[ScheduleTableID_From].NextScheduleTable].CurrentState = SCHEDULETABLE_STOPPED; 400 | 401 | } 402 | 403 | /* set the next schedule table */ 404 | ScheduleTableInternal_Array[ScheduleTableID_From].NextScheduleTable = ScheduleTableID_To; 405 | 406 | /* change the state of ScheduleTableID_To*/ 407 | ScheduleTableInternal_Array[ScheduleTableID_To].CurrentState = SCHEDULETABLE_NEXT; 408 | 409 | } 410 | 411 | 412 | #elif OS_MODE == OS_EXTENDED 413 | 414 | if(ScheduleTableID_From >= TABLES_NUMBER || ScheduleTableID_To >= TABLES_NUMBER ){ 415 | 416 | /* [SWS_Os_00282] If the input parameter or in a call of NextScheduleTable() is not valid, 417 | NextScheduleTable() shall return E_OS_ID. ( ) */ 418 | 419 | RetVal = E_OS_ID; 420 | 421 | }else if(ScheduleTable_Array[ScheduleTableID_From].OsScheduleTableCounterRef != ScheduleTable_Array[ScheduleTableID_To].OsScheduleTableCounterRef){ 422 | 423 | /* [SWS_Os_00330] If in a call of NextScheduleTable() schedule table is driven by different counter 424 | than schedule table then NextScheduleTable() shall return an error E_OS_ID. ( ) */ 425 | 426 | RetVal = E_OS_ID; 427 | }else if(ScheduleTableInternal_Array[ScheduleTableID_From].CurrentState != SCHEDULETABLE_RUNNING){ 428 | 429 | /* [SWS_Os_00330] If in a call of NextScheduleTable() schedule table is driven by different counter 430 | than schedule table then NextScheduleTable() shall return an error E_OS_ID. ( )*/ 431 | 432 | RetVal = E_OS_NOFUNC; 433 | 434 | }else if(ScheduleTableInternal_Array[ScheduleTableID_To].CurrentState != SCHEDULETABLE_STOPPED){ 435 | 436 | /* [SWS_Os_00309] If the schedule table in a call of NextScheduleTable() is not in state SCHEDULETABLE_STOPPED, 437 | NextScheduleTable() shall leave the state of and unchanged and return E_OS_STATE. ( ) */ 438 | 439 | RetVal = E_OS_STATE; 440 | 441 | }else if(ScheduleTable_Array[ScheduleTableID_To].OsScheduleTblSyncStrategy != ScheduleTable_Array[ScheduleTableID_From].OsScheduleTblSyncStrategy){ 442 | 443 | /* [SWS_Os_00484] If OsScheduleTblSyncStrategy of in a call of NextScheduleTable() is not equal 444 | to the OsScheduleTblSyncStrategy of then NextScheduleTable() shall return E_OS_ID. ( ) */ 445 | 446 | RetVal = E_OS_ID; 447 | 448 | }else{ 449 | 450 | if(ScheduleTableInternal_Array[ScheduleTableID_From].NextScheduleTable != EMPTY_NEXT_TABLE){ 451 | 452 | /* change the state of the previous next table */ 453 | ScheduleTableInternal_Array[ScheduleTableInternal_Array[ScheduleTableID_From].NextScheduleTable].CurrentState = SCHEDULETABLE_STOPPED; 454 | 455 | } 456 | 457 | /* set the next schedule table */ 458 | ScheduleTableInternal_Array[ScheduleTableID_From].NextScheduleTable = ScheduleTableID_To; 459 | 460 | /* change the state of ScheduleTableID_To*/ 461 | ScheduleTableInternal_Array[ScheduleTableID_To].CurrentState = SCHEDULETABLE_NEXT; 462 | 463 | } 464 | 465 | #endif 466 | 467 | return RetVal; 468 | 469 | } 470 | 471 | FUNC( StatusType, OS_CODE ) GetScheduleTableStatus( ScheduleTableType ScheduleTableID, ScheduleTableStatusRefType ScheduleStatus ) { 472 | 473 | StatusType RetVal = E_OK; 474 | 475 | CS_ON; 476 | #if OS_MODE == OS_STANDARD 477 | 478 | * ScheduleStatus = ScheduleTableInternal_Array[ScheduleTableID].CurrentState; 479 | 480 | #elif OS_MODE == OS_EXTENDED 481 | 482 | if(ScheduleTableID > TABLES_NUMBER){ 483 | 484 | RetVal = E_OS_ID; 485 | 486 | }else{ 487 | 488 | * ScheduleStatus = ScheduleTableInternal_Array[ScheduleTableID].CurrentState; 489 | 490 | } 491 | 492 | #endif 493 | CS_OFF; 494 | return RetVal; 495 | 496 | } 497 | -------------------------------------------------------------------------------- /Os_Sources/OsInterface_Sources/Os_Task.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AU20GradProject/OS/8c693b006dd1c926e856cfe32eb944fff8964a7d/Os_Sources/OsInterface_Sources/Os_Task.c -------------------------------------------------------------------------------- /Os_Sources/OsInternal_Sources/Os_Alarm_Internal.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Written by : Bebo 4 | DATE : 7/2/2019 5 | AUTOSAR Version : 4.3.1 6 | DOC Name : AUTOSAR_SWS_OS.pdf 7 | Target : ARM TIVA_C TM4C123GH6PM 8 | 9 | */ 10 | 11 | 12 | 13 | #include "..\..\Os_Headers\OsInterface_Headers\Os.h" 14 | #include "..\..\Os_Headers\OsInternal_Headers\Os_Internal.h" 15 | #include "..\..\Os_Headers\OsInternal_Headers\Os_ExternalVariables.h" 16 | 17 | 18 | FUNC(void, OS_INTERNAL_CODE) CheckAlarmExpiry(CounterType CounterID){ 19 | 20 | VAR(uint8, AUTOMATIC) i; 21 | /* know which of the alarms depend on CounterID */ 22 | for(i = 0; i < ALARMS_NUMBER ; i++){ 23 | 24 | /* if CounterID value equal to AlarmExpiry */ 25 | if(OsAlarm_Array[i].OsAlarmCounterRef == CounterID && OsAlarmInternal_Array[i].InUse == TRUE 26 | && OsAlarmInternal_Array[i].AlarmExpiryTickValue == OsCounterInternal_Array[i].OsCounterVal){ 27 | 28 | switch(OsAlarm_Array[i].AlarmAction.ActionType){ 29 | 30 | case ALARM_ACTION_ACT_TASK: 31 | 32 | ActivateTask(OsAlarm_Array[i].AlarmAction.Action.OsAlarmActivateTaskRef); 33 | 34 | break; 35 | case ALARM_ACTION_CALLBACK: 36 | OsAlarm_Array[i].AlarmAction.Action.OsAlarmCallbackName(); 37 | break; 38 | 39 | case ALARM_ACTION_INC_COUNTER: 40 | IncrementCounter(OsAlarm_Array[i].AlarmAction.Action.OsAlarmIncrementCounterRef); 41 | break; 42 | 43 | case ALARM_ACTION_SET_EVENT: 44 | SetEvent(OsAlarm_Array[i].AlarmAction.Action.AlarmEvent.OsAlarmSetEventTaskRef,OsAlarm_Array[i].AlarmAction.Action.AlarmEvent.OsAlarmSetEventRef); 45 | break; 46 | 47 | case ALARM_NOFUNC: 48 | break; 49 | } 50 | OsAlarmInternal_Array[i].InUse = FALSE; 51 | 52 | /* check if cyclic */ 53 | if(OsAlarmInternal_Array[i].Cycle != 0){ 54 | 55 | SetRelAlarm ( i , OsAlarmInternal_Array[i].Cycle , OsAlarmInternal_Array[i].Cycle ); 56 | 57 | } 58 | } 59 | } 60 | } 61 | 62 | 63 | -------------------------------------------------------------------------------- /Os_Sources/OsInternal_Sources/Os_Gpt_internal.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Os_Gpt_internal.c 4 | Written by : Bakr 5 | DATE : 18/2/2020 6 | 7 | */ 8 | 9 | #ifndef OS_SOURCES_OSINTERNAL_SOURCES_OS_GPT_INTERNAL_C_ 10 | #define OS_SOURCES_OSINTERNAL_SOURCES_OS_GPT_INTERNAL_C_ 11 | 12 | 13 | #include "..\..\Os_Headers\OsInterface_Headers\Os.h" 14 | #include "..\..\Os_Headers\OsInternal_Headers\Os_Internal.h" 15 | 16 | 17 | 18 | FUNC(StatusType, OSCODE_Internal) Init_Systick(void){ 19 | 20 | CS_ON; 21 | SYS_TICK_PRIORITY; 22 | StatusType retVal = E_OK; 23 | /* Set clock source */ 24 | if(SYSTICK_CLK_SRC == CLK_SRC_PIOSC_DIV4){ 25 | 26 | Systick_STCTRL &= ~(1<PSP) ) ) ; 43 | 44 | /* save context of preempted task */ 45 | 46 | /* change old task state */ 47 | OsTasksPCB_Array[ RunningTaskPCB_Index ].Task_State = READY ; 48 | 49 | /* save processor states of preempted task in its pcb, this states are pushed in main stack when exception of task context switching (PendSV) is triggered */ 50 | OsTasksPCB_Array[ RunningTaskPCB_Index ].Task_PSR = OsPSP_StackFrame_ptr->PSR ; 51 | OsTasksPCB_Array[ RunningTaskPCB_Index ].Task_PC = OsPSP_StackFrame_ptr->PC ; 52 | OsTasksPCB_Array[ RunningTaskPCB_Index ].Task_LR = OsPSP_StackFrame_ptr->LR ; 53 | OsTasksPCB_Array[ RunningTaskPCB_Index ].Task_R12 = OsPSP_StackFrame_ptr->R12 ; 54 | OsTasksPCB_Array[ RunningTaskPCB_Index ].Task_R3 = OsPSP_StackFrame_ptr->R3 ; 55 | OsTasksPCB_Array[ RunningTaskPCB_Index ].Task_R2 = OsPSP_StackFrame_ptr->R2 ; 56 | OsTasksPCB_Array[ RunningTaskPCB_Index ].Task_R1 = OsPSP_StackFrame_ptr->R1 ; 57 | OsTasksPCB_Array[ RunningTaskPCB_Index ].Task_R0 = OsPSP_StackFrame_ptr->R0 ; 58 | 59 | /* this registers are pushed manually */ 60 | OsTasksPCB_Array[ RunningTaskPCB_Index ].Task_SP = OsMSP_StackFrame_ptr->PSP + 0x020u ; /* the added value for the automatically pushed registers */ 61 | OsTasksPCB_Array[ RunningTaskPCB_Index ].Task_R4 = OsMSP_StackFrame_ptr->R4 ; 62 | OsTasksPCB_Array[ RunningTaskPCB_Index ].Task_R5 = OsMSP_StackFrame_ptr->R5 ; 63 | OsTasksPCB_Array[ RunningTaskPCB_Index ].Task_R6 = OsMSP_StackFrame_ptr->R6 ; 64 | OsTasksPCB_Array[ RunningTaskPCB_Index ].Task_R7 = OsMSP_StackFrame_ptr->R7 ; 65 | OsTasksPCB_Array[ RunningTaskPCB_Index ].Task_R8 = OsMSP_StackFrame_ptr->R8 ; 66 | OsTasksPCB_Array[ RunningTaskPCB_Index ].Task_R9 = OsMSP_StackFrame_ptr->R9 ; 67 | OsTasksPCB_Array[ RunningTaskPCB_Index ].Task_R10 = OsMSP_StackFrame_ptr->R10 ; 68 | OsTasksPCB_Array[ RunningTaskPCB_Index ].Task_R11 = OsMSP_StackFrame_ptr->R11 ; 69 | OsTasksPCB_Array[ RunningTaskPCB_Index ].Task_CONTROL = OsMSP_StackFrame_ptr->CONTROL ; 70 | 71 | } 72 | else /* case running task is terminated */ 73 | { 74 | } 75 | 76 | if ( INVALID_TASK != ReadyHighestPriority ) /* case there's tasks could enter running state */ 77 | { 78 | /* initialize stack pointer to allocate space for 12 word to wirte in registers that will be pooped manually */ 79 | __asm ( " MOV R12, #0x7FD0 " ) ; 80 | __asm( " MOVT R12, #0x2000 " ) ; 81 | __asm ( " MSR MSP, R12 " ) ; 82 | 83 | /* take copy for ReadyTaskPCB_Index, CS for read modify write sequence from ReadyTaskPCB_Index to ReadyHighestPriority*/ 84 | __asm ( " CPSID i " ) ; 85 | 86 | /* critical section to modify priority queue */ 87 | CeilingPriority = OsTasks_Array[ ( OsTasksPCB_Array[ ReadyTaskPCB_Index ].Task_ID ) ].OsTaskCeilingPriority_Internal ; 88 | DispatcherLocal_Variable = OsTasksPCB_Array[ ReadyTaskPCB_Index ].Task_Priority ; 89 | 90 | /* assign new priority for task if has an internal resource */ 91 | if ( CeilingPriority > OsTasksPCB_Array[ ReadyTaskPCB_Index ].Task_Priority ) 92 | { 93 | 94 | /* remove task from old queue */ 95 | OsTasksPriority_Array [DispatcherLocal_Variable] [ (OsTasksPriorityIndex_Array[DispatcherLocal_Variable]) ] = INVALID_TASK ; 96 | OsTasksPriorityIndex_Array[DispatcherLocal_Variable] = ( OsTasksPriorityIndex_Array[DispatcherLocal_Variable] + 1 ) % TASKS_PER_PRIORITY ; 97 | 98 | /* modify task priority */ 99 | OsTasksPCB_Array[ DispatcherLocal_Variable ].Task_Priority = CeilingPriority ; 100 | ReadyHighestPriority = CeilingPriority ; 101 | 102 | /* add task to the new queue */ 103 | OsTasksPriority_Array[ CeilingPriority ][ OsTasksPriorityNext_Array[CeilingPriority] ] = ReadyTaskPCB_Index ; 104 | OsTasksPriorityNext_Array[CeilingPriority] = ( OsTasksPriorityNext_Array[CeilingPriority] + 1 ) % TASKS_PER_PRIORITY ; 105 | 106 | } 107 | else 108 | { 109 | } 110 | 111 | DispatcherLocal_Variable = ReadyTaskPCB_Index ; 112 | 113 | __asm ( " CPSIE i " ) ; 114 | 115 | SchedulingPolicy = OsTasks_Array[ (OsTasksPCB_Array[ DispatcherLocal_Variable ].Task_ID) ].OsTaskSchedule ; 116 | 117 | /* write values of next running task into stack to be popped into registers */ 118 | 119 | /* popped manually by code */ 120 | OsMSP_StackFrame_ptr->CONTROL = OsTasksPCB_Array[ DispatcherLocal_Variable ].Task_CONTROL ; 121 | OsMSP_StackFrame_ptr->R11 = OsTasksPCB_Array[ DispatcherLocal_Variable ].Task_R11 ; 122 | OsMSP_StackFrame_ptr->R10 = OsTasksPCB_Array[ DispatcherLocal_Variable ].Task_R10 ; 123 | OsMSP_StackFrame_ptr->R9 = OsTasksPCB_Array[ DispatcherLocal_Variable ].Task_R9 ; 124 | OsMSP_StackFrame_ptr->R8 = OsTasksPCB_Array[ DispatcherLocal_Variable ].Task_R8 ; 125 | OsMSP_StackFrame_ptr->R7 = OsTasksPCB_Array[ DispatcherLocal_Variable ].Task_R7 ; 126 | OsMSP_StackFrame_ptr->R6 = OsTasksPCB_Array[ DispatcherLocal_Variable ].Task_R6 ; 127 | OsMSP_StackFrame_ptr->R5 = OsTasksPCB_Array[ DispatcherLocal_Variable ].Task_R5 ; 128 | OsMSP_StackFrame_ptr->R4 = OsTasksPCB_Array[ DispatcherLocal_Variable ].Task_R4 ; 129 | OsMSP_StackFrame_ptr->PSP = OsTasksPCB_Array[ DispatcherLocal_Variable ].Task_SP - 0x020u ; 130 | 131 | OsPSP_StackFrame_ptr = (( ( volatile P2VAR( OsStackFrame_PSP, AUTOMATIC, REGSPACE ) ) (OsMSP_StackFrame_ptr->PSP) ) ) ; 132 | 133 | /* manual pop for special register ready task */ 134 | __asm ( " POP {R12} " ) ; 135 | __asm ( " MSR CONTROL, R12 " ) ; 136 | 137 | __asm ( " POP {R11} " ) ; 138 | __asm ( " POP {R10} " ) ; 139 | __asm ( " POP {R9} " ) ; 140 | __asm ( " POP {R8} " ) ; 141 | __asm ( " POP {R7} " ) ; 142 | __asm ( " POP {R6} " ) ; 143 | __asm ( " POP {R5} " ) ; 144 | __asm ( " POP {R4} " ) ; 145 | 146 | __asm ( " POP {R12} " ) ; 147 | __asm ( " MSR PSP, R12 " ) ; 148 | 149 | /* will be popped automatically in exception return */ 150 | OsPSP_StackFrame_ptr->R0 = OsTasksPCB_Array[ DispatcherLocal_Variable ].Task_R0 ; 151 | OsPSP_StackFrame_ptr->R1 = OsTasksPCB_Array[ DispatcherLocal_Variable ].Task_R1 ; 152 | OsPSP_StackFrame_ptr->R2 = OsTasksPCB_Array[ DispatcherLocal_Variable ].Task_R2 ; 153 | OsPSP_StackFrame_ptr->R3 = OsTasksPCB_Array[ DispatcherLocal_Variable ].Task_R3 ; 154 | OsPSP_StackFrame_ptr->R12 = OsTasksPCB_Array[ DispatcherLocal_Variable ].Task_R12 ; 155 | OsPSP_StackFrame_ptr->LR = OsTasksPCB_Array[ DispatcherLocal_Variable ].Task_LR ; 156 | OsPSP_StackFrame_ptr->PC = OsTasksPCB_Array[ DispatcherLocal_Variable ].Task_PC ; 157 | OsPSP_StackFrame_ptr->PSR = OsTasksPCB_Array[ DispatcherLocal_Variable ].Task_PSR ; 158 | 159 | /* change index of running task pcb and change state for running task */ 160 | RunningTaskPCB_Index = DispatcherLocal_Variable ; 161 | OsTasksPCB_Array[ RunningTaskPCB_Index ].Task_State = RUNNING ; 162 | } 163 | else /* no ready tasks, go to idle mechanism */ 164 | { 165 | while ( INVALID_TASK == ReadyHighestPriority) ; 166 | } 167 | 168 | return ; 169 | 170 | } 171 | 172 | 173 | 174 | /*****************************************************************************/ 175 | 176 | /* used to add Task to last of proper priority queue and modify the queue */ 177 | FUNC (void, OS_CODE) OsTailTask ( uint8 PCB_Index ) 178 | { 179 | VAR( uint8, AUTOMATIC ) TaskPriority = OsTasksPCB_Array[PCB_Index].Task_Priority ; 180 | 181 | 182 | OsTasksPriority_Array[ TaskPriority ][ OsTasksPriorityNext_Array[TaskPriority] ] = PCB_Index ; 183 | OsTasksPriorityNext_Array[TaskPriority] = ( OsTasksPriorityNext_Array[TaskPriority] + 1 ) % TASKS_PER_PRIORITY ; 184 | 185 | /* check for preemption and calling dispatcher */ 186 | 187 | /* critical section to read modify write to ReadyHighestPriority & DISPATCHER_CALL & ReadyTaskPCB_Index */ 188 | 189 | if( TaskPriority > ReadyHighestPriority ) /* if task priority is the highest in current system */ 190 | { 191 | /* modify highest priority in system and pcb index of task which will preempt running task */ 192 | ReadyHighestPriority = TaskPriority ; 193 | ReadyTaskPCB_Index = PCB_Index ; 194 | 195 | if( TASK_FULL == SchedulingPolicy ) /* task is follow fully preemptive scheduling policy */ 196 | { 197 | DISPATCHER_CALL ; 198 | } 199 | else /* task is follow non preemptive scheduling policy */ 200 | { 201 | } 202 | 203 | } /* if */ 204 | else if ( INVALID_TASK == ReadyHighestPriority ) /* if no ready tasks in system */ 205 | { 206 | /* modify highest priority in system and pcb index of task which will preempt running task */ 207 | ReadyHighestPriority = TaskPriority ; 208 | ReadyTaskPCB_Index = PCB_Index ; 209 | 210 | DISPATCHER_CALL ; 211 | } 212 | else 213 | { 214 | } 215 | 216 | return ; 217 | } 218 | 219 | /*****************************************************************************/ 220 | 221 | /* used to add to head of proper priority queue and modify the queue */ 222 | FUNC (void, OS_CODE) OsHeadTask ( uint8 PCB_Index ) 223 | { 224 | VAR( uint8, AUTOMATIC ) TaskPriority = OsTasksPCB_Array[PCB_Index].Task_Priority ; 225 | VAR( uint8, AUTOMATIC ) TempVariable = OsTasksPriorityIndex_Array[TaskPriority] - 1 ; 226 | 227 | if ( 0xFF == TempVariable) 228 | { 229 | TempVariable = TASKS_PER_PRIORITY - 1 ; 230 | } 231 | else 232 | { 233 | } 234 | 235 | OsTasksPriorityIndex_Array[TaskPriority] = TempVariable ; 236 | OsTasksPriority_Array[ TaskPriority ][ TempVariable ] = PCB_Index ; 237 | 238 | 239 | if( TaskPriority > ReadyHighestPriority ) /* if task priority is the highest in current system */ 240 | { 241 | /* modify highest priority in system and pcb index of task which will preempt running task */ 242 | ReadyHighestPriority = TaskPriority ; 243 | 244 | } /* if */ 245 | else 246 | { 247 | 248 | } 249 | 250 | return ; 251 | } 252 | 253 | /*****************************************************************************/ 254 | 255 | /* used to remove task from in the head of priority queue and modify the queue */ 256 | FUNC (void, OS_CODE) RemoveTask ( uint8 TaskPriority ) 257 | { 258 | 259 | OsTasksPriority_Array [TaskPriority] [ (OsTasksPriorityIndex_Array[TaskPriority]) ] = INVALID_TASK ; 260 | OsTasksPriorityIndex_Array[TaskPriority] = ( OsTasksPriorityIndex_Array[TaskPriority] + 1 ) % TASKS_PER_PRIORITY ; 261 | 262 | 263 | if ( ReadyHighestPriority > TaskPriority ) /* no need for CS, just read ReadyHighestPriority */ /* this case just happen in non preemptive tasks */ 264 | { 265 | 266 | } 267 | else 268 | { 269 | 270 | /* check for highest priority and if no there ready tasks then TaskPriority = INVALID_TASK */ 271 | while ( ( INVALID_TASK == OsTasksPriority_Array [TaskPriority] [ (OsTasksPriorityIndex_Array[TaskPriority]) ] ) && ( INVALID_TASK != TaskPriority ) ) 272 | { 273 | /* get highest priority in system */ 274 | TaskPriority-- ; 275 | } /* while */ 276 | 277 | ReadyHighestPriority = TaskPriority ; 278 | 279 | if ( INVALID_TASK != TaskPriority ) /* another task could enter running state */ 280 | { 281 | ReadyTaskPCB_Index = OsTasksPriority_Array [TaskPriority] [ (OsTasksPriorityIndex_Array[TaskPriority]) ] ; 282 | } 283 | else /* no ready tasks */ 284 | { 285 | 286 | } /* else */ 287 | 288 | } 289 | 290 | DISPATCHER_CALL ; 291 | 292 | 293 | return ; 294 | } 295 | 296 | 297 | /*****************************************************************************/ 298 | 299 | /* this function used to initialize content of PCB related to hardware to achieve abstraction */ 300 | FUNC (void, OS_CODE) Init_PCB ( uint8 PCB_Index, uint8 TaskID ) 301 | { 302 | 303 | /* initialize task PCB */ 304 | OsTasksPCB_Array[PCB_Index].Task_SP = ( VAR( uint32, AUTOMATIC ) ) ( &( ( (OsTasksPCB_Array[PCB_Index]).Task_Stack ) [TASK_STACK_SIZE] ) ) ; 305 | OsTasksPCB_Array[PCB_Index].Task_LR = 0xFFFFFFFD ; 306 | OsTasksPCB_Array[PCB_Index].Task_PSR = 0x01000000 ; 307 | OsTasksPCB_Array[PCB_Index].Task_PC = OsTasksNames_Array[ TaskID ] ; 308 | OsTasksPCB_Array[PCB_Index].Task_CONTROL = 0x01u ; 309 | /* initialized because register 9 is used to hold temp of Linker register */ 310 | OsTasksPCB_Array[PCB_Index].Task_R9 = 0x00u ; 311 | 312 | return ; 313 | } 314 | 315 | 316 | /*****************************************************************************/ 317 | 318 | 319 | 320 | -------------------------------------------------------------------------------- /Os_Sources/OsInternal_Sources/Os_Variables.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Written by : Bebo 4 | DATE : 7/2/2019 5 | AUTOSAR Version : 4.3.1 6 | DOC Name : AUTOSAR_SWS_OS.pdf 7 | Target : ARM TIVA_C TM4C123GH6PM 8 | 9 | */ 10 | 11 | 12 | 13 | 14 | #include "..\..\Os_Headers\OsInterface_Headers\Os.h" 15 | #include "..\..\Os_Headers\OsInternal_Headers\Os_Internal.h" 16 | 17 | /**************************************************************************/ 18 | 19 | /* used for define OS object in the system */ 20 | CONST( OsOS, OS_CONFIG_DATA ) OS = OS_OS_OBJECT_CONGIFURATION ; 21 | 22 | /* represent configuration data of every app mode Auto start hold informations of Auto start tasks,alarms,schedule tables */ 23 | CONST( OsAppMode, OS_CONFIG_DATA ) OsAppModes_Array[ OS_APPMODES_NUMBER ] = OS_APPMODES_OBJECT_CONGIFURATION ; 24 | 25 | 26 | /* hold all tasks' IDs that will be activated in Auto start in all APP modes ordered by order of APP modes */ 27 | CONST( TaskType, OS_CONFIG_DATA ) OsAutoStartTasks_Array [ AUTOSTART_TASKS_NUMBER ] = OS_AUTOSTART_TASKS_OBJECT_CONGIFURATION ; 28 | 29 | 30 | /* hold all alarms' IDs that will be activated in Auto start in all APP modes ordered by order of APP modes */ 31 | CONST( AlarmType, OS_CONFIG_DATA ) OsAutoStartAlarms_Array [ AUTOSTART_ALARMS_NUMBER ] = OS_AUTOSTART_ALARMS_OBJECT_CONGIFURATION ; 32 | 33 | /* hold all alarms' auto start settings that will be activated in Auto start in all APP modes ordered by order of APP modes */ 34 | CONST( OsAlarmAutostart, OS_CONFIG_DATA ) OsAutoStartAlarms_SettingArray [ AUTOSTART_ALARMS_NUMBER ] = OS_AUTOSTART_SETTING_ALARMS_OBJECT_CONGIFURATION ; 35 | 36 | 37 | /* hold all ScheduleTables' IDs that will be activated in Auto start in all APP modes ordered by order of APP modes */ 38 | CONST( ScheduleTableStatusType, OS_CONFIG_DATA ) OsAutoStartTabless_Array [ AUTOSTART_TABLES_NUMBER ] = OS_AUTOSTART_TABLES_OBJECT_CONGIFURATION ; 39 | 40 | /* hold all tables' auto start settings that will be activated in Auto start in all APP modes ordered by order of APP modes */ 41 | CONST( OsScheduleTableAutostart, OS_CONFIG_DATA ) OsAutoStartTables_SettingArray [ AUTOSTART_TABLES_NUMBER ] = OS_AUTOSTART_SETTING_TABLES_OBJECT_CONGIFURATION ; 42 | 43 | 44 | /* used to save app mode used inside system and passed to StartOS service */ 45 | VAR( AppModeType, OS_CONFIG_DATA ) AppMode ; 46 | 47 | 48 | /**************************************************************************/ 49 | 50 | 51 | /* used to take a copy of ReadyTaskPCB_Index inside dispatcher */ 52 | VAR ( uint8, OS_VAR_CLEARED ) DispatcherLocal_Variable ; 53 | 54 | 55 | 56 | /**************************************************************************/ 57 | 58 | /* represent configuration data of every task */ 59 | CONST( OsTask, OS_CONFIG_DATA ) OsTasks_Array [ TASKS_NUMBER ] = OS_TASKS_OBJECT_CONGIFURATION ; 60 | 61 | /* array of PCBs of not suspended tasks*/ 62 | VAR( OsTask_PCB, OS_VAR_CLEARED ) OsTasksPCB_Array [ TASK_PCBS_NUMBER ] ; 63 | 64 | /* used to scheduling and determine next running task, every element carry the index of task PCB in OsTasksPCB_Array 65 | * OsTasksPriority_Array [ 0 ] is array of tasks' PCB index */ 66 | VAR( uint8, OS_VAR_INIT ) OsTasksPriority_Array [ TASK_PRIORITIES_NUMBER ] [ TASKS_PER_PRIORITY] = { VAL_256(0xFF), VAL_8(0xFF) } ; 67 | 68 | /* used to carry index of first element in OsTasksPriority_Array, 69 | * this element will be chosen for running if its array priority is currently largest priority */ 70 | VAR( uint8, OS_VAR_CLEARED) OsTasksPriorityIndex_Array [TASK_PRIORITIES_NUMBER] ; 71 | 72 | /* used to carry index of available element to the newly coming task to OsTasksPriority_Array 73 | * OsTasksPriorityNext_Array [0] = x, determine index of OsTasksPriority_Array [ 0 ][x] to carry the PCB index to new task of priority 0 */ 74 | VAR( uint8, OS_VAR_CLEARED) OsTasksPriorityNext_Array [TASK_PRIORITIES_NUMBER] ; 75 | 76 | /* used to carry PCB index of all tasks 77 | * OsTasksPCB_Index_Array[ TaskId ] will return index of PCB of this task OsTasksPCB_Array in if not suspended */ 78 | VAR( uint8, OS_VAR_INIT) OsTasksPCB_Index_Array [ TASKS_NUMBER ] = TASKS_PCB_INDEX_ARRAY_CONFIGURATION ; 79 | 80 | /* carry the highest priority of all current ready/running tasks 81 | * depending on it ReadyTaskPCB_Index will determined */ 82 | VAR ( uint8, OS_VAR_INIT ) ReadyHighestPriority = INVALID_TASK ; 83 | 84 | 85 | /* carry PCB index of ready task that will preempt currently running task */ 86 | VAR ( uint8, OS_VAR_INIT ) ReadyTaskPCB_Index = INVALID_TASK ; 87 | 88 | /* carry the PCB index of currently running task */ 89 | VAR ( uint8, OS_VAR_INIT ) RunningTaskPCB_Index = INVALID_TASK ; 90 | 91 | /* used in context switching and preemption to easily modify value of stack frame */ 92 | volatile CONSTP2VAR ( OsStackFrame_MSP, OS_VAR_INIT, OS_APPL_CONST ) OsMSP_StackFrame_ptr = OS_MSP_STACK_FRAME_ADDRESS ; 93 | 94 | /* used in context switching and preemption to easily modify value of stack frame */ 95 | volatile P2VAR ( OsStackFrame_PSP, OS_VAR_CLEARED, OS_APPL_CONST ) OsPSP_StackFrame_ptr ; 96 | 97 | /* used to check if there a place to activate new task*/ 98 | VAR ( uint8, OS_VAR_CLEARED ) NotSuspendedTasks_Number ; 99 | 100 | /* used to indicate current policy used in scheduling for running task preemptive or not */ 101 | VAR ( uint8, OS_VAR_INIT ) SchedulingPolicy = TASK_NON ; 102 | 103 | /* used inside dispatcher to take a copy of task ceiling priority */ 104 | VAR ( uint8, OS_VAR_CLEARED ) CeilingPriority ; 105 | 106 | 107 | /**************************************************************************/ 108 | 109 | 110 | /* used to carry ISR_ID of current runnign ISR */ 111 | VAR( ISRType, OS_VAR_CLEARED ) IsrID = INVALID_ISR ; 112 | 113 | /* represent configuration data of every task */ 114 | VAR( OsIsr, OS_CONFIG_DATA ) OsIsr_Array [ ISRS_NUMBER ] = OS_ISRS_OBJECT_CONGIFURATION ; 115 | 116 | 117 | /**************************************************************************/ 118 | 119 | /* used to carry HOOK_ID of current runnign Hook routine */ 120 | VAR( HOOKType, OS_VAR_CLEARED ) HookID = INVALID_HOOK ; 121 | 122 | /**************************************************************************/ 123 | 124 | /* used to define events configurations */ 125 | CONST( EventMaskType, OS_CONFIG_DATA ) OsEvents_Array [ OS_EVENTS_NUMBER ] = OS_EVENTS_OBJECT_CONGIFURATION ; 126 | 127 | /**************************************************************************/ 128 | 129 | /* define configurations of resources in system */ 130 | CONST( OsResource, OS_CONFIG_DATA ) OsResource_Array [ OS_RESOURCES_NUMBER ] = OS_RESOURCES_OBJECT_CONGIFURATION ; 131 | 132 | /* define array contain all resources PCBs with index of thier id */ 133 | VAR( OsResource_PCB, OS_VAR_INIT) OsResourcePCB_Array [ OS_RESOURCES_NUMBER ] = OS_RESOURCES_PCB_OBJECT_CONGIFURATION ; 134 | 135 | /* define array contain all resources PCBs with index of thier id */ 136 | VAR( boolean, OS_VAR_INIT) OsResource_CS_Flag = FALSE ; 137 | 138 | /**************************************************************************/ 139 | 140 | 141 | /* used to counter Alarms configurations */ 142 | CONST( OsCounter, OS_CONFIG_DATA ) OsCounter_Array [ COUNTERS_NUMBER ] = OS_COUNTERS_OBJECT_CONGIFURATION ; 143 | 144 | VAR( OsCounterInternal, OS_DATA) OsCounterInternal_Array [COUNTERS_NUMBER ]; 145 | 146 | /**************************************************************************/ 147 | 148 | /* used to define Alarms configurations */ 149 | CONST( OsAlarm, OS_CONFIG_DATA ) OsAlarm_Array [ ALARMS_NUMBER ] = OS_ALARMS_OBJECT_CONGIFURATION ; 150 | 151 | VAR( OsAlarmInternal, OS_CONFIG_DATA ) OsAlarmInternal_Array [ALARMS_NUMBER] ; 152 | 153 | /**************************************************************************/ 154 | 155 | 156 | 157 | 158 | 159 | /* define configuration of schedule tables in system */ 160 | CONST( OsScheduleTable, OS_CONFIG_DATA ) ScheduleTable_Array [ TABLES_NUMBER ] = OS_TABLESS_OBJECT_CONGIFURATION ; 161 | 162 | VAR( OsScheduleTableInternal, OS_DATA ) ScheduleTableInternal_Array [ TABLES_NUMBER ] ; 163 | 164 | /* define configuration of expiry points in system */ 165 | CONST( OsScheduleTableExpiryPoint, OS_CONFIG_DATA ) ScheduleTablePoints_Array [ TABLES_POINTS_NUMBER ] = OS_TABLESS_POINTS_OBJECT_CONGIFURATION ; 166 | 167 | VAR( ExpiryPointOffset, OS_DATA ) ScheduleTablePointsOffsets_Array[TABLES_POINTS_NUMBER ]; 168 | 169 | /* define configuration of tasks to be activated by tables in system */ 170 | CONST( TaskType, OS_CONFIG_DATA ) ScheduleTableTaskActivation_Array [ TABLES_TASKS_NUMBER ] = OS_TABLESS_TASKS_OBJECT_CONGIFURATION ; 171 | 172 | /* define configuration of tasks to be set its events by tables in system */ 173 | CONST( TaskType, OS_CONFIG_DATA ) ScheduleTableTaskSet_Array [ TABLES_EVENTS_SET_NUMBER ] = OS_TABLESS_TASKS_SET_OBJECT_CONGIFURATION ; 174 | 175 | /* define configuration of events to be set by tables in system */ 176 | CONST( EventMaskType, OS_CONFIG_DATA ) ScheduleTableEventSet_Array [ TABLES_EVENTS_SET_NUMBER ] = OS_TABLESS_EVENTS_SET_OBJECT_CONGIFURATION ; 177 | 178 | /**************************************************************************/ 179 | 180 | 181 | /* PEND status store variables used in Os_Isr */ 182 | VAR(uint32, AUTOMATIC) PEND0; 183 | VAR(uint32, AUTOMATIC) PEND1; 184 | VAR(uint32, AUTOMATIC) PEND2; 185 | VAR(uint32, AUTOMATIC) PEND3; 186 | VAR(uint32, AUTOMATIC) PEND4; 187 | 188 | 189 | /* Variable contains the called interrupt disable function, if no function is called default value is NoDisableActive*/ 190 | VAR(ActiveIsrDisableType, AUTOMATIC) ActiveIsrDisable; 191 | 192 | VAR(uint8, AUTOMATIC) suspendCount; 193 | 194 | /**************************************************************************/ 195 | 196 | --------------------------------------------------------------------------------