]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/blob - apps/helloworld/main.c
535eddd023a9e96eca1174088a1cc224861316b7
[pes-rpp/rpp-lib.git] / apps / helloworld / main.c
1 /* Copyright (C) 2013, 2015 Czech Technical University in Prague
2  *
3  * Authors:
4  *     - Carlos Jenkins <carlos@jenkins.co.cr>
5  *
6  * This document contains proprietary information belonging to Czech
7  * Technical University in Prague. Passing on and copying of this
8  * document, and communication of its contents is not permitted
9  * without prior written authorization.
10  *
11  * File : main.c
12  * Abstract:
13  *     Example/Base main file for RPP API library.
14  *
15  * References:
16  *     RPP API documentation.
17  */
18
19
20 #include "rpp/rpp.h"
21
22
23 void my_task(void *p)
24 {
25         static const portTickType freq_ticks = 1000 / portTICK_RATE_MS;
26         portTickType last_wake_time = xTaskGetTickCount();
27
28         while (TRUE) {
29
30                 /* Wait until next step */
31                 vTaskDelayUntil(&last_wake_time, freq_ticks);
32                 rpp_sci_printf((const char *)"Hello RPP.\r\n");
33
34         }
35 }
36
37
38 void main(void)
39 {
40         /* Initialize RPP board */
41         rpp_init();
42
43         /* Spawn tasks */
44         if (xTaskCreate(my_task, FREERTOS_TASK_NAME("my_task"),
45                                         512, NULL, 0, NULL) != pdPASS) {
46                 #ifdef DEBUG
47                 rpp_sci_printf((const char *)
48                                            "ERROR: Cannot spawn control task.\r\n"
49                                            );
50                 #endif
51                 while (TRUE)
52                         asm (" nop");
53         }
54
55         /* Start the FreeRTOS Scheduler */
56         vTaskStartScheduler();
57
58         /* Catch scheduler start error */
59         #ifdef DEBUG
60         rpp_sci_printf((const char *)
61                                    "ERROR: Problem allocating memory for idle task.\r\n"
62                                    );
63         #endif
64         while (TRUE)
65                 asm (" nop");
66 }
67
68
69 #if configUSE_MALLOC_FAILED_HOOK == 1
70 /**
71  * FreeRTOS malloc() failed hook.
72  */
73 void vApplicationMallocFailedHook(void)
74 {
75         #ifdef DEBUG
76         rpp_sci_printf((const char *)
77                                    "ERROR: manual memory allocation failed.\r\n"
78                                    );
79         #endif
80 }
81 #endif
82
83
84 #if configCHECK_FOR_STACK_OVERFLOW > 0
85 /**
86  * FreeRTOS stack overflow hook.
87  */
88 void vApplicationStackOverflowHook(xTaskHandle xTask,
89                                                                    signed portCHAR *pcTaskName)
90 {
91         #ifdef DEBUG
92         rpp_sci_printf((const char *)
93                                    "ERROR: Stack overflow : \"%s\".\r\n", pcTaskName
94                                    );
95         #endif
96 }
97 #endif