/
init.c
89 lines (72 loc) · 2.25 KB
/
init.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
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#define CONFIGURE_INIT
#include "system.h"
rtems_gpio *led;
rtems_id sem_on_id, sem_off_id;
#define ARGUMENT 0
rtems_task Init(
rtems_task_argument ignored
)
{
rtems_status_code volatile status;
status = rtems_gpio_get(LED_VPIN, &led);
if (status != RTEMS_SUCCESSFUL) {
Error_Handler();
}
rtems_gpio_set_pin_mode(led, RTEMS_GPIO_PINMODE_OUTPUT_PP);
rtems_gpio_set_pull(led, RTEMS_GPIO_NOPULL);
rtems_gpio_write(led, RTEMS_GPIO_PIN_RESET);
rtems_name sem_name, task_name_1, task_name_2;
rtems_id tid_1, tid_2;
sem_name = rtems_build_name( 'S', 'O', 'N', ' ' );
status = rtems_semaphore_create(
sem_name,
0,
RTEMS_SIMPLE_BINARY_SEMAPHORE,
RTEMS_NO_INHERIT_PRIORITY + RTEMS_NO_MULTIPROCESSOR_RESOURCE_SHARING + RTEMS_NO_PRIORITY_CEILING,
&sem_on_id
);
if (status != RTEMS_SUCCESSFUL) {
Error_Handler();
}
sem_name = rtems_build_name( 'S', 'O', 'F', 'F' );
status = rtems_semaphore_create(
sem_name,
1,
RTEMS_SIMPLE_BINARY_SEMAPHORE,
RTEMS_NO_INHERIT_PRIORITY + RTEMS_NO_MULTIPROCESSOR_RESOURCE_SHARING + RTEMS_NO_PRIORITY_CEILING,
&sem_off_id
);
if (status != RTEMS_SUCCESSFUL) {
Error_Handler();
}
task_name_1 = rtems_build_name( 'L', 'O', 'N', ' ' );
status = rtems_task_create( task_name_1, 1, RTEMS_MINIMUM_STACK_SIZE,
RTEMS_DEFAULT_MODES, RTEMS_DEFAULT_ATTRIBUTES, &tid_1 );
if (status != RTEMS_SUCCESSFUL) {
Error_Handler();
}
task_name_2 = rtems_build_name( 'L', 'O', 'F', 'F' );
status = rtems_task_create( task_name_2, 1, RTEMS_MINIMUM_STACK_SIZE,
RTEMS_DEFAULT_MODES, RTEMS_DEFAULT_ATTRIBUTES, &tid_2 );
if (status != RTEMS_SUCCESSFUL) {
Error_Handler();
}
status = rtems_task_start( tid_1, LED_on_task, ARGUMENT );
if (status != RTEMS_SUCCESSFUL) {
Error_Handler();
}
status = rtems_task_start( tid_2, LED_off_task, ARGUMENT );
if (status != RTEMS_SUCCESSFUL) {
Error_Handler();
}
rtems_task_exit();
}
void Error_Handler(void) {
rtems_interrupt_level level;
rtems_interrupt_disable(level);
while (1) {
}
}