blob: d894ac611e81086c884d5125a98cd80c2875cb9d [file] [log] [blame]
Mahmoud Bazzal69a0a242019-08-22 17:36:17 +02001/*******************************************************************************
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 Prakashf3644672020-08-21 15:11:08 +020014#include "debugFlags.h"
15#include "trace_utils_BTF.h"
Mahmoud Bazzal69a0a242019-08-22 17:36:17 +020016
17#include "FreeRTOS.h"
18#include "task.h"
19#include <stdarg.h>
Mahmoud Bazzal69a0a242019-08-22 17:36:17 +020020
21
Anand Prakashf3644672020-08-21 15:11:08 +020022/**
23 * Generating Amalthea task model
24 */
25AmaltheaTask 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 Bazzal69a0a242019-08-22 17:36:17 +020039}
40
Anand Prakashf3644672020-08-21 15:11:08 +020041
42
43/**
44 * This function returns the additional stack size (in words) needed for the task to handle its labels
45 *
46 */
47
48unsigned int calculateStackSize(int labelBitCount, int labelCount)
49{
50 return ((labelBitCount * labelCount) / PLATFORM_WORD_LENGTH);
Mahmoud Bazzal69a0a242019-08-22 17:36:17 +020051}
52
Anand Prakashf3644672020-08-21 15:11:08 +020053
54/**
55 * Create the RTOS task that represents a given Amalthea task.
56 */
57void 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 Bazzal69a0a242019-08-22 17:36:17 +020065}
66
67
68#ifdef use_LET_COMM_SEMANTICS
69void generalizedRTOSTask(AmaltheaTask task){
Anand Prakashf3644672020-08-21 15:11:08 +020070 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 Bazzal69a0a242019-08-22 17:36:17 +020079}
80#else
Anand Prakashf3644672020-08-21 15:11:08 +020081/**
82 * This RTOS task invokes the task handlers and realizes periodic task execution according to
83 * Amalthea model
84 */
Mahmoud Bazzal69a0a242019-08-22 17:36:17 +020085void generalizedRTOSTask(AmaltheaTask task){
Anand Prakashf3644672020-08-21 15:11:08 +020086 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 Bazzal69a0a242019-08-22 17:36:17 +0200107}
108
109#endif
110
111
112
113
114
115
116
117
118
119
120