-
Notifications
You must be signed in to change notification settings - Fork 1
/
arduino_support_code.ino
100 lines (82 loc) · 2.54 KB
/
arduino_support_code.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <Arduino_FreeRTOS.h>
#include <queue.h>
#include <stdint.h>
#define messageQueueSize 3
#define runoff_uint8 uint8_t
#define runoff_uint16 uint16_t
#define runoff_uint32 uint32_t
#define runoff_uint64 uint64_t
#define runoff_int8 int8_t
#define runoff_int16 int16_t
#define runoff_int32 int32_t
#define runoff_int64 int64_t
#define runoff_float float
#define runoff_void void
#define runoff_bool bool
#define runoff_msg struct Message
#define runoff_taskid int8_t
#define runoff_pinid int8_t
TaskHandle_t taskhandles[N_TASKS];
QueueHandle_t Mailbox[N_TASKS];
void loop(){}
// Helper function to create tasks
void createTask(TaskFunction_t taskFunction, void *args){
BaseType_t xReturned;
/* Create the task, storing the handle. */
xReturned = xTaskCreate(
taskFunction, /* Function that implements the task. *\ */
"", /* Text name for the task. *\ */
configMINIMAL_STACK_SIZE, /* 196 * 8 * 2 = bits allocated to this task*\ */
args, /* Parameter passed into the task. *\ */
10, /* Priority at which the task is created. *\ */
NULL ); /* Used to pass out the created task's handle. *\ */
if( xReturned != pdPASS ){
return;
}
}
// Helper functions
runoff_void runoff_turnOn(runoff_pinid pin){
digitalWrite(pin, HIGH);
}
runoff_void runoff_turnOff(runoff_pinid pin){
digitalWrite(pin, LOW);
}
runoff_bool runoff_readInput(runoff_pinid pin){
return digitalRead(pin);
}
runoff_uint16 runoff_readAnalogInput(runoff_pinid pin){
return analogRead(pin);
}
runoff_void runoff_analogWrite(runoff_pinid pin, runoff_uint8 val){
analogWrite(pin, val);
}
runoff_void runoff_advancedInputPin(runoff_pinid pin, runoff_taskid task, runoff_msg lowmsg, runoff_msg highmsg);
runoff_void runoff_outputPin(runoff_pinid pin){
pinMode(pin, OUTPUT);
}
runoff_void runoff_inputPin(runoff_pinid pin){
pinMode(pin, INPUT);
}
runoff_void runoff_setOutput(runoff_pinid pin, runoff_bool b){
if(b)
runoff_turnOn(pin);
else
runoff_turnOff(pin);
}
runoff_void runoff_delay(runoff_uint32 miliSeconds){
vTaskDelay(pdMS_TO_TICKS(miliSeconds));
}
runoff_void runoff_setup(runoff_void);
void setup(void) {
runoff_setup();
}
runoff_taskid runoff_self(void) {
TaskHandle_t h = xTaskGetCurrentTaskHandle();
runoff_taskid i;
for(i = 0; i < N_TASKS; i++){
if(taskhandles[i] == h)
return i;
}
return -1;
}
// End of helper file