1 /*************************************************************************** 2 * Copyright (c) 2024 Microsoft Corporation 3 * 4 * This program and the accompanying materials are made available under the 5 * terms of the MIT License which is available at 6 * https://opensource.org/licenses/MIT. 7 * 8 * SPDX-License-Identifier: MIT 9 **************************************************************************/ 10 11 12 /**************************************************************************/ 13 /**************************************************************************/ 14 /** */ 15 /** ThreadX Component */ 16 /** */ 17 /** OSEK IMPLEMENTATION */ 18 /** */ 19 /**************************************************************************/ 20 /**************************************************************************/ 21 22 /**************************************************************************/ 23 /* */ 24 /* EKV DEFINITIONS RELEASE */ 25 /* */ 26 /* os.h PORTABLE C */ 27 /* 6.1.7 */ 28 /* AUTHOR */ 29 /* */ 30 /* William E. Lamie, Microsoft Corporation */ 31 /* */ 32 /* DESCRIPTION */ 33 /* */ 34 /* This file defines the constants, structures, etc. needed for the */ 35 /* OSEK implementation. */ 36 /* */ 37 /* */ 38 /* RELEASE HISTORY */ 39 /* */ 40 /* DATE NAME DESCRIPTION */ 41 /* */ 42 /* 06-02-2021 William E. Lamie Initial Version 6.1.7 */ 43 /* */ 44 /**************************************************************************/ 45 46 #ifndef TX_OSEK_H 47 #define TX_OSEK_H 48 49 #include <tx_api.h> 50 51 #include "osek_user.h" 52 53 #ifdef TRUE 54 #undef TRUE 55 #endif 56 57 #ifdef FALSE 58 #undef FALSE 59 #endif 60 61 62 /**************************************************************************/ 63 /* System Macros. */ 64 /**************************************************************************/ 65 66 #define TASK(Taskname) void Func ## Taskname() 67 #define TaskEntry(Taskname) Func ## Taskname 68 #define ALARM(Alarmname) void Func ## Alarmname() 69 #define ISR(ISRname) void ISR_ ## ISRname() 70 #define ISREntry(ISRname) ISR_ ## ISRname 71 72 #define ALARMCALLBACK(Alarmcallbackfunction) void Func ## Alarmcallbackfunction() 73 #define ALARMCALLBACKEntry(Alarmcallbackfunction) Func ## Alarmcallbackfunction 74 #define DeclareALARMCALLBACK(Alarmcallbackfunction) ALARMCALLBACK(Alarmcallbackfunction) 75 76 #define DeclareISR(ISRname) ISR(ISRname) 77 #define DeclareResource(Resource_name) 78 #define DeclareEvent(Event_name) 79 #define DeclareAlarm(Alarmname) ALARM(Alarmname) 80 #define DeclareTask(Taskname) TASK(Taskname) 81 82 #define CALL_ISR(ISRname) ISR_ ## ISRname() 83 84 #define OSErrorGetServiceId() service_GetServiceId.id 85 #define OSError_ActivateTask_TaskID() service_ActivateTask.TaskID 86 #define OSError_ChainTask_TaskID() service_ChainTask.TaskID 87 #define OSError_GetAlarm_AlarmID() service_GetAlarm.AlarmID 88 #define OSError_CancelAlarm_AlarmID() service_CancelAlarm.AlarmID 89 #define OSError_SetAbsAlarm_AlarmID() service_SetAbsAlarm.AlarmID 90 #define OSError_SetRelAlarm_AlarmID() service_SetRelAlarm.AlarmID 91 #define OSError_GetResource_ResID() service_GetResource.ResID 92 #define OSError_ReleaseResource_ResID() service_ReleaseResource.ResID 93 #define OSError_SetEvent_TaskID() service_SetEvent.TaskID 94 #define OSError_GetEvent_TaskID() service_SetEvent.TaskID 95 #define OSError_WaitEvent_EventID() service_SetEvent.EventID 96 #define OSError_ClearEvent_EventID() service_ClearEvent.EventID 97 98 /**************************************************************************/ 99 /* OSEK data Types */ 100 /**************************************************************************/ 101 102 typedef ULONG STATUS; 103 typedef void *VP; 104 typedef void (* FP)(); 105 typedef ULONG PRI; 106 typedef ULONG CounterType; 107 typedef ULONG TaskType; 108 typedef TaskType ISRType; /* TaskType and ISRType must be same as both often used interchangeably. */ 109 typedef ULONG TaskStateType; 110 typedef ULONG *TaskStateRefType; 111 typedef ULONG *TaskRefType; 112 typedef ULONG TickType; 113 typedef ULONG *TickRefType; 114 typedef ULONG AppModeType; 115 typedef ULONG AlarmType; 116 typedef ULONG StatusType; 117 typedef ULONG OsServiceIdType; 118 typedef ULONG ResourceType; 119 typedef ULONG *ResourceRefType; 120 typedef ULONG EventMaskType; 121 typedef ULONG *EventMaskRefType; 122 typedef ULONG EventType; 123 typedef ULONG *EventRefType; 124 125 126 /**************************************************************************/ 127 /* OSEK Error Codes */ 128 /**************************************************************************/ 129 130 #define E_OK (0U) 131 #define E_OS_ACCESS (1U) 132 #define E_OS_CALLEVEL (2U) 133 #define E_OS_ID (3U) 134 #define E_OS_LIMIT (4U) 135 #define E_OS_NOFUNC (5U) 136 #define E_OS_RESOURCE (6U) 137 #define E_OS_STATE (7U) 138 #define E_OS_VALUE (8U) 139 140 141 /* Additional error codes defined for this Implementation. */ 142 143 #define E_OS_EVENT (9U) 144 #define E_OS_EXIST (10U) /* identical task name are found. */ 145 #define E_OS_SYSTEM (11U) /* Error for the OSEK system. */ 146 #define E_OS_SYS_STACK (12U) /* Error For OSEK Memory. */ 147 148 /* osek_internal_error() error codes. */ 149 150 #define THREADX_OBJECT_CREATION_ERROR (1U) 151 #define THREADX_THREAD_RESUME_IN_ACTIVATE_TASK (2U) 152 #define THREADX_PREEMPTION_CHANGE_GETRESOURCE (3U) 153 #define THREADX_PREEMPTION_CHANGE_RLSRESOURCE (4U) 154 #define THREADX_THREAD_TERMINATE_TERMINATETASK (5U) 155 #define THREADX_THREAD_DELETE_TERMINATETASK (6U) 156 #define THREADX_THREAD_TERMINATE_CHAINTASK (7U) 157 #define THREADX_THREAD_DELETE_CHAINTASK (8U) 158 #define THREADX_THREAD_DELETE_DELETETASK (9U) 159 #define THREADX_THREAD_TERMINATE_DELETETASK (10U) 160 #define THREADX_PREEMPTION_CHANGE_WRAPPER (11U) 161 #define THREADX_THREAD_RELINQUISH_SCHEDULE (12U) 162 #define THREADX_MUTEX_CREATERESOURCE (13U) 163 #define THREADX_EVENT_SETEVENT (14U) 164 #define THREADX_EVENT_CLEAREVENT (15U) 165 #define THREADX_EVENT_FLAG_GETEVENT (16U) 166 #define THREADX_EVENT_FLAG_WAITEVENT (17U) 167 #define QUEUE_DELETETASK (18U) 168 #define NO_FREE_EVENT (20U) 169 #define SYSMGR_FATAL_ERROR (21U) 170 #define EVENT_DELETETASK (22U) 171 #define ERROR_FREEING_MEMORY (23U) 172 #define SYS_MGR_SEND_CHAINTASK (24U) 173 #define SYS_MGR_SEND_TERMINATETASK (25U) 174 #define INVALID_ALARMID_TIMERWRAPPER (26U) 175 #define TASK_ENDING_WITHOUT_CHAIN_OR_TERMINATE (27U) 176 #define SYSMGR_QUEUE_SEND (28U) 177 #define INVALID_OBJECT_CREATION_CALL (29U) 178 #define SYS_MGR_START_OS (30U) 179 #define SYS_MGR_SEND_ACTIVATETASK (31U) 180 #define ERROR_OBJECT_CREATION (32U) 181 182 183 /**************************************************************************/ 184 /* OSEM SYSTEM SERVICES IDs */ 185 /**************************************************************************/ 186 187 #define OSServiceId_ActivateTask (1U) 188 #define OSServiceId_TerminateTask (2U) 189 #define OSServiceId_ChainTask (3U) 190 #define OSServiceId_Schedule (4U) 191 #define OSServiceId_GetTaskID (5U) 192 #define OSServiceId_GetTaskState (6U) 193 #define OSServiceId_DisableAllInterrupts (7U) 194 #define OSServiceId_EnableAllInterrupts (8U) 195 #define OSServiceId_SuspendAllInterrupts (9U) 196 #define OSServiceId_ResumeAllInterrupts (10U) 197 #define OSServiceId_SuspendOSInterrupts (11U) 198 #define OSServiceId_ResumeOSInterrupts (12U) 199 #define OSServiceId_GetResource (13U) 200 #define OSServiceId_ReleaseResource (14U) 201 #define OSServiceId_SetEvent (15U) 202 #define OSServiceId_ClearEvent (16U) 203 #define OSServiceId_GetEvent (17U) 204 #define OSServiceId_WaitEvent (18U) 205 #define OSServiceId_GetAlarmBase (19U) 206 #define OSServiceId_GetAlarm (20U) 207 #define OSServiceId_SetRelAlarm (21U) 208 #define OSServiceId_SetAbsAlarm (22U) 209 #define OSServiceId_CancelAlarm (23U) 210 #define OSServiceId_GetActiveApplicationMode (24U) 211 #define OSServiceId_StartOS (25U) 212 #define OSServiceId_ShutdownOS (26U) 213 214 215 /**************************************************************************/ 216 /* Implementation Specific OSEK operating modes */ 217 /* */ 218 /**************************************************************************/ 219 220 #define NORMAL_EXECUTION_MODE (0U) 221 #define STARTUPHOOK_MODE (1U) 222 #define SHUTDOWNHOOK_MODE (2U) 223 #define PRETASKHOOK_MODE (3U) 224 #define POSTTASKHOOK_MODE (4U) 225 #define ERRORHOOK_MODE (5U) 226 #define ISR1_MODE (6U) 227 #define ISR2_MODE (7U) 228 #define TIMER_MODE (8U) 229 #define INITSYSTEM_MODE (9U) 230 #define ALARM_CALLBACK_MODE (10U) 231 #define OSEK_INIT_NOT_DONE (99U) 232 233 234 /**************************************************************************/ 235 /* OSEK Constants and Definitions */ 236 /**************************************************************************/ 237 238 /* OS APPLICATION MODES */ 239 240 #define OSDEFAULTAPPMODE (1U) 241 242 243 /* OSEK Task Types */ 244 245 #define EXTENDED (1U) 246 #define BASIC (0U) 247 #define TRUE (1U) 248 #define FALSE (0U) 249 250 251 /* OSEK Task States */ 252 253 #define RUNNING (0U) 254 #define WAITING (1U) 255 #define READY (2U) 256 #define SUSPENDED (3U) 257 #define THREADX_STATE (4U) 258 259 /* Invalid task id */ 260 #define INVALID_TASK (0U) 261 262 263 /* ALARM OPERATION MODES */ 264 265 #define ABSOLUTE_ALARM (1U) 266 #define RELATIVE_ALARM (0U) 267 #define AUTO_START (1U) 268 #define NO_START (0U) 269 270 271 /* RESOURCE TYPE */ 272 273 #define STANDARD (0U) 274 #define INTERNAL (1U) 275 #define LINKED (2U) 276 277 typedef enum {NON, FULL} SCHEDULE; 278 typedef enum {ACTIVATETASK, SETEVENT, CALLBACK, NONE} ACTION; 279 typedef ULONG ACCR_TYPE; 280 typedef ULONG TASK_TYPE; 281 typedef ULONG COPY; 282 typedef ULONG AUTOSTART; 283 284 285 /* ISR types */ 286 287 #define CATEGORY1 (1U) 288 #define CATEGORY2 (2U) 289 290 291 /**************************************************************************/ 292 /* SYSTEM CONFIGURATION PARAMETERS */ 293 /**************************************************************************/ 294 295 /* OSEK Priority Definitions */ 296 297 #define THREADX_MAX_PRIORITY (31U) 298 #define THREADX_HIGHEST_PRIORITY (0U) 299 #define THREADX_LOWEST_PRIORITY (31U) 300 301 #define OSEK_MAX_PRIORITY (23U) 302 #define OSEK_HIGHEST_PRIORITY (OSEK_MAX_PRIORITY) 303 #define OSEK_LOWEST_PRIORITY (0U) 304 305 #define OSEK_NON_SCHEDULE_PRIORITY (OSEK_HIGHEST_PRIORITY + 1u) /* 24 */ 306 #define OSEK_ISR2_PRIORITY (OSEK_NON_SCHEDULE_PRIORITY + 1u) /* 25 */ 307 #define OSEK_ISR1_PRIORITY (OSEK_ISR2_PRIORITY + 1u) /* 26 */ 308 309 310 /* Define maximum queued activation per task */ 311 312 #define OSEK_MAX_ACTIVATION (8U) 313 314 /* Define maximum time count for Counters / Alarms */ 315 316 #define MAXALLOWEDVALUE (0x7FFFFFFFUL) 317 318 #define OSEK_STACK_PADDING (128U) 319 #define OSEK_SYSTEM_STACK_SIZE (1024U) 320 321 322 /* Requests/commands to SysMgr task. */ 323 324 #define SYSMGR_START_OS (0U) 325 #define SYSMGR_TERMINATE_TASK (1U) 326 #define SYSMGR_CHAIN_TASK (2U) 327 #define SYSMGR_ACTIVATE_TASK (3U) 328 #define SYSMGR_SCHEDULE (4U) 329 #define SYSMGR_WAITEVENT (5U) 330 #define SYSMGR_RELEASE_RESOURCE (6U) 331 #define SYSMGR_SETEVENT (7U) 332 #define SYSMGR_SHUTDOWN_OS (8U) 333 #define SYSMGR_ERRORHOOK (9U) 334 #define SYSMGR_GET_RESOURCE (10U) 335 336 /**************************************************************************/ 337 /* Define size of Region 0 memory segment. */ 338 /* NOTE: This region should be large enough to supply the memory */ 339 /* for all task stacks, TCBs, thread control blocks in the system. */ 340 /**************************************************************************/ 341 342 #define TX_REGION0_SIZE (OSEK_MEMORY_SIZE) 343 #define TX_REGION0_SIZE_IN_BYTES (TX_REGION0_SIZE) 344 345 346 /**********************************************************************************/ 347 /* OSEK System Object maximum numbers */ 348 /* NOTE: These are only suggested values, user may modify them as needed. */ 349 /* Memory is the only limiting factor. */ 350 /**********************************************************************************/ 351 352 /* Define the maximum number of simultaneous OSEK tasks supported. */ 353 /* Interrupt Service Routines are also treated as a task. */ 354 /* Total 8 Interrupt sources are supported. */ 355 /* That gives 24 max OSEK tasks. */ 356 357 #define OSEK_MAX_TASKS (32U) 358 359 /* Define the maximum number of simultaneous Internal OSEK Resources supported. */ 360 361 #define OSEK_MAX_INTERNAL_RES (8U) 362 363 364 /* Define the maximum number of simultaneous External OSEK Resources supported. */ 365 366 #define OSEK_MAX_EXTERNAL_RES (16U) 367 368 369 /* Define the maximum number of simultaneous OSEK Resources (Internal & External Combined) supported. */ 370 371 #define OSEK_MAX_RES (OSEK_MAX_INTERNAL_RES + OSEK_MAX_EXTERNAL_RES) 372 373 374 /* Define the maximum number of simultaneous OSEK alarms supported. */ 375 376 #define OSEK_MAX_ALARMS (16U) 377 378 379 /* Define the maximum number of simultaneous OSEK counters supported. */ 380 /* This includes a counter to be assigned as a SystemTimer. */ 381 /* A system can have 8 alarms so 8 counters (one counter for each alarm) would be enough. */ 382 383 #define OSEK_MAX_COUNTERS (16U) 384 385 386 /* Define the maximum number of simultaneous OSEK events supported. */ 387 /* An event is just a bit , so a ULONG (32 bit data type) is used. */ 388 389 #define OSEK_MAX_EVENTS (32U) 390 391 392 /* Define the maximum number of OSEK ISR sources supported. */ 393 394 #define OSEK_MAX_ISR (8U) 395 396 397 /* Define OSEK Internal Task Queue depth per priority. */ 398 /* There is one such queue for each priority level. */ 399 /* What is the maximum number of tasks that can go in a queue? */ 400 /* Assuming that all tasks are of same priority and each task is activated to maximum */ 401 /* allowable limits (OSEK_MAX_ACTIVATION) it should be OSEK_MAX_ACTIVATION * OSEK_MAX_TASKS */ 402 /* but sometimes (READY)tasks are moved from queue to queue based on its changed ceiling priority */ 403 /* and that number could be equal to to maximum number of tasks supported. */ 404 405 #define TASK_QUEUE_DEPTH1 (OSEK_MAX_ACTIVATION * OSEK_MAX_TASKS) 406 #define TASK_QUEUE_DEPTH (TASK_QUEUE_DEPTH1 + OSEK_MAX_TASKS) 407 408 #define SYSMGR_QUEUE_MSG_LENGTH (4U) 409 #define SYSMGR_QUEUE_MSG_COUNT (OSEK_MAX_ALARMS) 410 #define SYSMGR_QUEUE_DEPTH ((sizeof(ULONG)) * SYSMGR_QUEUE_MSG_COUNT) 411 412 #define SYSMGR_PRIORITY (0U) 413 #define SYSMGR_THRESHOLD (0U) 414 415 416 /**********************************************************************************/ 417 /* OSEK System Object identifier this is placed in the object's control structure */ 418 /**********************************************************************************/ 419 420 #define OSEK_TASK_ID (0x1234ABCDUL) 421 #define OSEK_ALARM_ID (0x4567ABCDUL) 422 #define OSEK_COUNTER_ID (0xABCD1234UL) 423 #define OSEK_EVENT_ID (0x1234FEDCUL) 424 #define OSEK_RES_ID (0x5678CDEFUL) 425 #define OSEK_APPLICATION_ID (0x789ABCDEUL) 426 #define OSEK_ISR_ID (0x3456CDEFUL) 427 428 429 /**************************************************************************/ 430 /* OSEK SYSTEM OBJECT CONTROL STRUCTURES */ 431 /**************************************************************************/ 432 433 434 /* OSEK SERVICES */ 435 436 struct Service_ActivateTask 437 { 438 StatusType TaskID; 439 }; 440 441 struct Service_TerminateTask 442 { 443 StatusType TaskID; 444 }; 445 446 struct Service_ChainTask 447 { 448 StatusType TaskID; 449 }; 450 451 struct Service_Schedule 452 { 453 StatusType TaskID; 454 }; 455 456 struct Service_GetTaskID 457 { 458 TaskRefType TaskID; 459 }; 460 461 struct Service_GetTaskState 462 { 463 StatusType TaskID; 464 }; 465 466 struct Service_DisableAllInterrupts 467 { 468 StatusType TaskID; 469 }; 470 471 struct Service_EnableAllInterrupts 472 { 473 StatusType TaskID; 474 }; 475 476 struct Service_SuspendAllInterrupts 477 { 478 StatusType TaskID; 479 }; 480 481 struct Service_ResumeAllInterrupts 482 { 483 StatusType TaskID; 484 }; 485 486 struct Service_SuspendOSInterrupts 487 { 488 StatusType TaskID; 489 }; 490 491 struct Service_ResumeOSInterrupts 492 { 493 StatusType TaskID; 494 }; 495 496 struct Service_GetResource 497 { 498 ResourceType ResID; 499 }; 500 501 struct Service_ReleaseResource 502 { 503 ResourceType ResID; 504 }; 505 506 struct Service_SetEvent 507 { 508 StatusType EventID; 509 TaskType TaskID; 510 }; 511 512 struct Service_ClearEvent 513 { 514 EventMaskType EventID; 515 }; 516 517 struct Service_GetEvent 518 { 519 StatusType EventID; 520 TaskType TaskID; 521 }; 522 523 struct Service_WaitEvent 524 { 525 EventMaskType EventID; 526 }; 527 528 struct Service_GetAlarmBase 529 { 530 AlarmType AlarmID; 531 }; 532 533 struct Service_GetAlarm 534 { 535 AlarmType AlarmID; 536 }; 537 538 struct Service_SetRelAlarm 539 { 540 AlarmType AlarmID; 541 TickType increment; 542 TickType cycle; 543 }; 544 545 struct Service_SetAbsAlarm 546 { 547 AlarmType AlarmID; 548 TickType start; 549 TickType cycle; 550 }; 551 552 struct Service_CancelAlarm 553 { 554 AlarmType AlarmID; 555 }; 556 557 struct Service_GetActiveApplicationMode 558 { 559 StatusType TaskID; 560 }; 561 562 struct Service_StartOS 563 { 564 StatusType TaskID; 565 }; 566 567 struct Service_ShutdownOS 568 { 569 StatusType TaskID; 570 }; 571 572 struct Service_GetServiceId 573 { 574 OsServiceIdType id; 575 }; 576 577 578 /**************************************************************************/ 579 /* OSEK Resource */ 580 /**************************************************************************/ 581 582 typedef struct osek_resource_struct 583 { 584 /* Name. */ 585 const CHAR *name; 586 587 /* This Resource is in use. */ 588 ULONG res_in_use; 589 590 /* Ceiling priority of the resource. */ 591 UINT c_priority; 592 593 /* Task occupying this resource. */ 594 TaskType taskid; 595 596 /* Type. */ 597 StatusType type; /* Internal, External, Linked. */ 598 599 /* Linked Resource. */ 600 601 ResourceType linked_res; /* id of the resource , Linked with this res. */ 602 603 ResourceType resolved_res; /* Id of the res linked to this , after all chained links. */ 604 605 /* Resource Object id. */ 606 ULONG osek_res_id; 607 608 } OSEK_RESOURCE; 609 610 611 /**************************************************************************/ 612 /* Task structure */ 613 /**************************************************************************/ 614 615 typedef struct osek_tcb_struct 616 { 617 /* This task's ThreadX TCB. */ 618 TX_THREAD task; 619 620 /* Name. */ 621 const CHAR *name; 622 623 /* This field indicates if this task is in use. */ 624 ULONG tcb_in_use; 625 626 /* Task type BASIC or EXTENDED. */ 627 UINT task_type; 628 629 /* Task AUTOSTART mode. */ 630 UINT task_autostart; 631 632 /* Design time Scheduling policy of this Task. */ 633 SCHEDULE policy; 634 635 /* Task start address (entry point). */ 636 FP task_entry; 637 638 /* Design time task priority. */ 639 UINT org_prio; 640 641 642 /* Current ThreadX thread preemption threshold. */ 643 UINT cur_threshold; 644 645 /* task stack size. */ 646 ULONG stack_size; 647 648 /* start address of the task stack. */ 649 CHAR *pStackBase; 650 651 652 /* Task status Suspended/ Ready(Running). */ 653 ULONG suspended; 654 655 /* Wait status */ 656 ULONG waiting; 657 658 /* Task to be activated when this task calls ChainTask(). */ 659 TaskType task_to_chain; 660 661 /* Counter to indicate how many Resources are occupied. */ 662 ULONG res_ocp; 663 664 /* Maximum multiple activation allowed for this task. */ 665 UINT max_active; 666 667 /* Current (recorded) multiple activation requests. */ 668 UINT current_active; 669 670 /* List of Event assigned to this task. */ 671 EventMaskType events; 672 673 EventMaskType waiting_events; 674 675 EventMaskType set_events; 676 677 /* List of External resources assigned (Design time) to this task. */ 678 ResourceType external_resource_list[OSEK_MAX_EXTERNAL_RES]; 679 680 /* List of External Resources currently occupied (Run time) by this task. */ 681 ResourceType external_resource_occuplied_list[OSEK_MAX_EXTERNAL_RES]; 682 683 /* List of Internal resources assigned (Design Time) to this task. */ 684 ResourceType internal_resource_list[OSEK_MAX_INTERNAL_RES]; 685 686 /* List of Internal Resources currently occupied (Run Time) by this task. */ 687 ResourceType internal_resource_occuplied_list[OSEK_MAX_INTERNAL_RES]; 688 689 /* Internal Resource assigned or not. */ 690 UINT internal_res; 691 692 /* RES_SCHEDULER taken or not. */ 693 UINT resource_scheduler; 694 695 AppModeType task_Appl_Mode; 696 697 /* Task Object id. */ 698 ULONG osek_task_id; 699 700 } OSEK_TCB; 701 702 703 /**************************************************************************/ 704 /* Counter */ 705 /**************************************************************************/ 706 707 typedef struct OSEK_COUNTER_STRUCT 708 { 709 710 /* Max. allowable value. */ 711 TickType maxallowedvalue; 712 713 /* Tick base multiplier. */ 714 TickType ticksperbase; 715 716 /* Minimum cyclic numbers of counter ticks allowed for a cyclic alarm. */ 717 TickType mincycle; 718 719 /* Name. */ 720 const CHAR* name; 721 722 /* This field indicates if this counter is in use. */ 723 UINT cntr_in_use; 724 725 /* Pre-count needed to increment main count by 1. */ 726 TickType sub_count; 727 728 /* Current counter value in ticks. */ 729 TickType counter_value; 730 731 /* Whether attached to system timer. */ 732 UINT system_timer; 733 734 /* List of all alarms attached to this counter. */ 735 AlarmType alarm_list[OSEK_MAX_ALARMS]; 736 737 /* Counter object id. */ 738 ULONG osek_counter_id; 739 740 741 }OSEK_COUNTER; 742 743 744 /**************************************************************************/ 745 /* ALARM */ 746 /**************************************************************************/ 747 748 typedef struct OSEK_ALARM_STRUCT 749 { 750 751 /* Name. */ 752 const CHAR* name; 753 754 /* This field indicates if this entry is in use. */ 755 UINT alarm_in_use; 756 757 UINT occupied; 758 759 /* Max allowed value of count for this alarm depends on the counter to which this alarm is attached. */ 760 TickType max_allowed_value; 761 762 /* Cycles programmed depends on the counter to which this alarm is attached. */ 763 TickType min_cyc; 764 765 /* Tick base multiplier. */ 766 TickType ticks_per_base; 767 768 /* Cycles programmed for this alarm. */ 769 TickType cycle; 770 771 /* alarm expiration count. */ 772 773 TickType expiration_count; 774 775 /* Alarm Callback function. */ 776 void (*alarm_callback)(); 777 778 /* Alarm Activation. */ 779 UINT armed; 780 781 /* Alarm Action. */ 782 UINT action; 783 784 /* Attach task here. */ 785 OSEK_TCB* task; 786 787 /* Attach the counter. */ 788 OSEK_COUNTER *cntr; 789 790 /* Event to set in case of SET_EVENT action. The event bits should be 1 791 to SET that EVENT of the task. */ 792 EventMaskType events; 793 794 /* Start up action. */ 795 UINT auto_start; 796 797 /* ALARM armed in relative mode or abs mode. */ 798 UINT rel_abs_mode; 799 800 /* Counter roll back flag for absolute alarm mode. */ 801 UINT counter_rollback; 802 803 /* Alarm object id. */ 804 ULONG osek_alarm_id; 805 806 } OSEK_ALARM; 807 808 809 typedef struct USER_ALARM_STRUCT 810 { 811 812 /* Max allowed value of count. */ 813 TickType maxallowedvalue; 814 815 /* Cycles. */ 816 TickType mincycle; 817 818 /* Tick base multiplier. */ 819 TickType ticksperbase; 820 821 }AlarmBaseType; 822 823 typedef AlarmBaseType *AlarmBaseRefType; 824 825 826 typedef struct REGISTER_APPLICATION_STRUCT 827 { 828 829 AppModeType application_mode; 830 831 /* ErrorHook. */ 832 void (*error_hook_handler)(StatusType); 833 /* Startup hook. */ 834 void (*startup_hook_handler)(); 835 /* Shutdown Hook. */ 836 void (*shutdown_hook_handler)(StatusType); 837 838 void (*pretask_hook_handler)(void); 839 840 void (*posttask_hook_handler)(void); 841 842 /* Any errors generated while creating the application. */ 843 StatusType osek_object_creation_error; 844 845 846 /* Application object ID. */ 847 ULONG osek_application_id; 848 849 850 }APPLICATION_INFO; 851 852 typedef APPLICATION_INFO *APPLICATION_INFO_PTR; 853 854 855 /**************************************************************************/ 856 /* OSEK API CALLS */ 857 /**************************************************************************/ 858 859 860 /* TASK MANAGEMENT */ 861 862 StatusType ActivateTask(TaskType TaskId); 863 StatusType GetTaskID(TaskType *TaskID); 864 StatusType TerminateTask(void); 865 StatusType ChainTask(TaskType TaskID); 866 StatusType GetTaskState(TaskType TaskID, TaskStateRefType State); 867 TaskType CreateTask(const CHAR *name, void(*entry_function)(), UINT priority, UINT max_activation, 868 ULONG stack_size, SCHEDULE policy, AUTOSTART start, UINT, AppModeType mode); 869 StatusType Schedule (void); 870 871 872 /* RESOURCE MANAGEMENT */ 873 874 ResourceType CreateResource(const CHAR *name, StatusType type, ResourceType linked_res); 875 StatusType GetResource(ResourceType id); 876 StatusType ReleaseResource(ResourceType id); 877 StatusType RegisterTasktoResource(ResourceType Resource, TaskType TaskID); 878 879 /* EVENT MANAGEMENT */ 880 881 StatusType SetEvent(TaskType task_id, EventMaskType mask); 882 StatusType ClearEvent(EventMaskType mask); 883 StatusType GetEvent(TaskType task_id, EventMaskRefType event); 884 StatusType WaitEvent(EventMaskType mask); 885 EventMaskType CreateEvent(void); 886 StatusType RegisterEventtoTask(EventType eventid, TaskType TaskID); 887 888 /* INTERUUPT MANAGEMENT */ 889 890 StatusType EnableInterrupt(void); 891 StatusType DisableInterrupt(void); 892 893 StatusType GetInterruptDescriptor(UINT *mask); 894 895 void SuspendAllInterrupts(void); 896 void ResumeAllInterrupts(void); 897 898 void SuspendOSInterrupts(void); 899 void ResumeOSInterrupts(void); 900 901 void DisableAllInterrupts(void); 902 void EnableAllInterrupts(void); 903 904 ISRType CreateISR(const CHAR *name, void(*entry_function)(), UINT category, ULONG stack_size); 905 StatusType RegisterISRtoResource(ResourceType Resource, ISRType ISRID); 906 907 908 /* COUNTER MANAGEMENT */ 909 910 StatusType GetCounterValue(OSEK_COUNTER *counter_ptr, TickRefType ticks); 911 CounterType CreateCounter(const CHAR *name, TickType max_allowed_value, TickType ticks_per_base, 912 TickType min_cycle, TickType start_value); 913 StatusType IncrCounter(CounterType cntr); 914 StatusType DefineSystemCounter(CounterType cntr); 915 916 /* ALARM MANAGEMENT */ 917 918 StatusType GetAlarmBase(AlarmType AlarmID, AlarmBaseRefType info); 919 StatusType SetAbsAlarm(AlarmType AlarmID, TickType start, TickType cycle); 920 StatusType SetRelAlarm(AlarmType AlarmID, TickType increment, TickType cycle); 921 StatusType CancelAlarm(AlarmType AlarmID); 922 StatusType GetAlarm(AlarmType AlarmID, TickRefType tick_ptr); 923 AlarmType CreateAlarm(const CHAR *name, CounterType cntr, UINT action, ULONG events, 924 TaskType task, void (*callback)(), UINT Startup, TickType Alarmtime, TickType Cycle); 925 926 /* OS MANAGEMENT */ 927 928 UCHAR *osek_initialize(void *osek_memory, APPLICATION_INFO_PTR application1); 929 UINT osek_cleanup(APPLICATION_INFO_PTR application1); 930 void ShutdownOS(StatusType error); 931 void StartOS(StatusType os_mode); 932 AppModeType GetActiveApplicationMode(void); 933 934 935 void process_ISR2(ISRType isrname); 936 937 #endif 938 939 940 /******************************* End of file ************************/ 941