Mahmoud Bazzal | 69a0a24 | 2019-08-22 17:36:17 +0200 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | * Copyright (c) 2019 Dortmund University of Applied Sciences and Arts and others. |
| 3 | * |
| 4 | * This program and the accompanying materials are made |
| 5 | * available under the terms of the Eclipse Public License 2.0 |
| 6 | * which is available at https://www.eclipse.org/legal/epl-2.0/ |
| 7 | * |
| 8 | * SPDX-License-Identifier: EPL-2.0 |
| 9 | * |
| 10 | * Contributors: |
| 11 | * Dortmund University of Applied Sciences and Arts - initial API and implementation |
| 12 | *******************************************************************************/ |
| 13 | #include "AmaltheaConverter.h" |
Anand Prakash | f364467 | 2020-08-21 15:11:08 +0200 | [diff] [blame] | 14 | #include "debugFlags.h" |
| 15 | #include "trace_utils_BTF.h" |
Mahmoud Bazzal | 69a0a24 | 2019-08-22 17:36:17 +0200 | [diff] [blame] | 16 | |
| 17 | #include "FreeRTOS.h" |
| 18 | #include "task.h" |
| 19 | #include <stdarg.h> |
Mahmoud Bazzal | 69a0a24 | 2019-08-22 17:36:17 +0200 | [diff] [blame] | 20 | |
| 21 | |
Anand Prakash | f364467 | 2020-08-21 15:11:08 +0200 | [diff] [blame] | 22 | /** |
| 23 | * Generating Amalthea task model |
| 24 | */ |
| 25 | AmaltheaTask createAmaltheaTask(void *taskHandler,void *cInHandler,void *cOutHandler, |
| 26 | unsigned int period,unsigned int deadline, unsigned int WCET, |
| 27 | unsigned int src_id, unsigned int src_instance, unsigned int task_id, unsigned int task_instance) |
| 28 | { |
| 29 | if (WCET >= period) |
| 30 | { |
| 31 | AmaltheaTask retValNull = {0, 0, 0, 0, NULL, 0, 0, 0, NULL, NULL}; |
| 32 | return retValNull; |
| 33 | }else |
| 34 | { |
| 35 | AmaltheaTask retVal = {src_id, src_instance, task_id, task_instance, |
| 36 | taskHandler, WCET, deadline, period, cInHandler, cOutHandler}; |
| 37 | return retVal; |
| 38 | } |
Mahmoud Bazzal | 69a0a24 | 2019-08-22 17:36:17 +0200 | [diff] [blame] | 39 | } |
| 40 | |
Anand Prakash | f364467 | 2020-08-21 15:11:08 +0200 | [diff] [blame] | 41 | |
| 42 | |
| 43 | /** |
| 44 | * This function returns the additional stack size (in words) needed for the task to handle its labels |
| 45 | * |
| 46 | */ |
| 47 | |
| 48 | unsigned int calculateStackSize(int labelBitCount, int labelCount) |
| 49 | { |
| 50 | return ((labelBitCount * labelCount) / PLATFORM_WORD_LENGTH); |
Mahmoud Bazzal | 69a0a24 | 2019-08-22 17:36:17 +0200 | [diff] [blame] | 51 | } |
| 52 | |
Anand Prakash | f364467 | 2020-08-21 15:11:08 +0200 | [diff] [blame] | 53 | |
| 54 | /** |
| 55 | * Create the RTOS task that represents a given Amalthea task. |
| 56 | */ |
| 57 | void createRTOSTask(AmaltheaTask* task, int priority, int argCount, ...) |
| 58 | { |
| 59 | /* cycle through the stack arguments and add the needed numbers to the stack */ |
| 60 | int stack_size = 0; |
| 61 | /* make sure the stack size is at least big enough to run the task. */ |
| 62 | stack_size += configMINIMAL_STACK_SIZE; |
| 63 | /* create the RTOS task with the generalized form */ |
| 64 | xTaskCreate((TaskFunction_t)generalizedRTOSTask, "Task", stack_size, &(*task), priority, NULL); |
Mahmoud Bazzal | 69a0a24 | 2019-08-22 17:36:17 +0200 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | |
| 68 | #ifdef use_LET_COMM_SEMANTICS |
| 69 | void generalizedRTOSTask(AmaltheaTask task){ |
Anand Prakash | f364467 | 2020-08-21 15:11:08 +0200 | [diff] [blame] | 70 | TickType_t xLastWakeTime = xTaskGetTickCount(); |
| 71 | //task.cInHandler(); |
| 72 | for (;;){ |
| 73 | //execute cIn |
| 74 | task.cInHandler(); |
| 75 | task.taskHandler(); |
| 76 | vTaskDelayUntil( &xLastWakeTime, task.period); |
| 77 | task.cOutHandler(); |
| 78 | } |
Mahmoud Bazzal | 69a0a24 | 2019-08-22 17:36:17 +0200 | [diff] [blame] | 79 | } |
| 80 | #else |
Anand Prakash | f364467 | 2020-08-21 15:11:08 +0200 | [diff] [blame] | 81 | /** |
| 82 | * This RTOS task invokes the task handlers and realizes periodic task execution according to |
| 83 | * Amalthea model |
| 84 | */ |
Mahmoud Bazzal | 69a0a24 | 2019-08-22 17:36:17 +0200 | [diff] [blame] | 85 | void generalizedRTOSTask(AmaltheaTask task){ |
Anand Prakash | f364467 | 2020-08-21 15:11:08 +0200 | [diff] [blame] | 86 | TickType_t xLastWakeTime = xTaskGetTickCount(); |
| 87 | for (;;) |
| 88 | { |
| 89 | /* CDGen specific code changes. It will be made consistent in future. */ |
| 90 | #ifndef CDGEN_BTF_TRACE |
| 91 | traceTaskEvent(task.src_id, task.src_instance, TASK_EVENT, task.task_id, |
| 92 | task.task_instance, PROCESS_START, 0); |
| 93 | task.cInHandler(); |
| 94 | task.taskHandler(task.task_id, task.task_instance); |
| 95 | task.cOutHandler(); |
| 96 | traceTaskEvent(task.src_id, task.src_instance, TASK_EVENT, task.task_id, |
| 97 | task.task_instance, PROCESS_TERMINATE, 0); |
| 98 | vTaskDelayUntil( &xLastWakeTime, task.period); |
| 99 | task.task_instance++; |
| 100 | #else |
| 101 | task.cInHandler(); |
| 102 | task.taskHandler(task.src_id, task.src_instance); |
| 103 | task.cOutHandler(); |
| 104 | vTaskDelayUntil( &xLastWakeTime, task.period); |
| 105 | #endif |
| 106 | } |
Mahmoud Bazzal | 69a0a24 | 2019-08-22 17:36:17 +0200 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | #endif |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |