-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
195 lines (142 loc) · 4.68 KB
/
main.c
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/*
* Fred for Linux. Experimental support.
*
* Copyright (C) 2018-2021, Marco Pagani, ReTiS Lab.
* <marco.pag(at)outlook.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "fred_lib.h"
#include "periodic_task.h"
#include "demo_hw_task.h"
//-------------------------------------------------------------------------------
struct demo_hw_task sum_hw_task;
const uint32_t sum_hw_task_hw_id = 100;
struct periodic_task sum_task;
const int sum_task_period = 100;
uint32_t sum_op(uint32_t a, uint32_t b)
{
return (a + b);
}
//-------------------------------------------------------------------------------
struct demo_hw_task sub_hw_task;
const uint32_t sub_hw_task_hw_id = 101;
struct periodic_task sub_task;
const int sub_task_period = 110;
uint32_t sub_op(uint32_t a, uint32_t b)
{
return (a - b);
}
//-------------------------------------------------------------------------------
struct demo_hw_task mul_hw_task;
const uint32_t mul_hw_task_hw_id = 102;
struct periodic_task mul_task;
const int mul_task_period = 120;
uint32_t mul_op(uint32_t a, uint32_t b)
{
return (a * b);
}
//-------------------------------------------------------------------------------
struct demo_hw_task xor_hw_task;
const uint32_t xor_hw_task_hw_id = 200;
struct periodic_task xor_task;
const int xor_task_period = 130;
uint32_t xor_op(uint32_t a, uint32_t b)
{
return (a ^ b);
}
//-------------------------------------------------------------------------------
struct demo_hw_task nor_hw_task;
const uint32_t nor_hw_task_hw_id = 201;
struct periodic_task nor_task;
const int nor_task_period = 140;
uint32_t nor_op(uint32_t a, uint32_t b)
{
return ~(a | b);
}
//-------------------------------------------------------------------------------
int main()
{
int retval;
//---------------------------------------------------------------------------
srand(time(NULL));
//---------------------------------------------------------------------------
// Initialize hw-task component
retval = demo_hw_task_init(&sum_hw_task, sum_hw_task_hw_id, sum_op);
if (retval)
return -1;
// initialize periodic sw-task wrapper
retval = periodic_task_init(&sum_task ,demo_hw_task_wrapper,
&sum_hw_task, sum_task_period);
if (retval)
return -1;
//---------------------------------------------------------------------------
retval = demo_hw_task_init(&sub_hw_task, sub_hw_task_hw_id, sub_op);
if (retval)
return -1;
retval = periodic_task_init(&sub_task ,demo_hw_task_wrapper,
&sub_hw_task, sub_task_period);
if (retval)
return -1;
//---------------------------------------------------------------------------
retval = demo_hw_task_init(&mul_hw_task, mul_hw_task_hw_id, mul_op);
if (retval)
return -1;
retval = periodic_task_init(&mul_task ,demo_hw_task_wrapper,
&mul_hw_task, mul_task_period);
if (retval)
return -1;
//---------------------------------------------------------------------------
retval = demo_hw_task_init(&xor_hw_task, xor_hw_task_hw_id, xor_op);
if (retval)
return -1;
retval = periodic_task_init(&xor_task ,demo_hw_task_wrapper,
&xor_hw_task, xor_task_period);
if (retval)
return -1;
//---------------------------------------------------------------------------
retval = demo_hw_task_init(&nor_hw_task, nor_hw_task_hw_id, nor_op);
if (retval)
return -1;
retval = periodic_task_init(&nor_task ,demo_hw_task_wrapper,
&nor_hw_task, nor_task_period);
if (retval)
return -1;
//---------------------------------------------------------------------------
// Start all sw-tasks
retval = periodic_task_start(&sum_task);
if (retval)
return -1;
retval = periodic_task_start(&sub_task);
if (retval)
return -1;
retval = periodic_task_start(&mul_task);
if (retval)
return -1;
retval = periodic_task_start(&xor_task);
if (retval)
return -1;
retval = periodic_task_start(&nor_task);
if (retval)
return -1;
//---------------------------------------------------------------------------
periodic_task_join(&sum_task);
periodic_task_join(&sub_task);
periodic_task_join(&mul_task);
periodic_task_join(&xor_task);
periodic_task_join(&nor_task);
//---------------------------------------------------------------------------
demo_hw_task_free(&sum_hw_task);
demo_hw_task_free(&sub_hw_task);
demo_hw_task_free(&mul_hw_task);
demo_hw_task_free(&xor_hw_task);
demo_hw_task_free(&nor_hw_task);
//---------------------------------------------------------------------------
return 0;
}