|
1 | 1 | #include "obc_logging.h" |
2 | | -#include "obc_adc.h" |
3 | 2 | #include "obc_sci_io.h" |
4 | | -#include "obc_errors.h" |
5 | | -#include "obc_print.h" |
| 3 | +#include "obc_i2c_io.h" |
| 4 | +#include "obc_spi_io.h" |
| 5 | +#include "obc_reset.h" |
6 | 6 | #include "obc_scheduler_config.h" |
7 | | -#include "obc_metadata.h" |
| 7 | +#include "state_mgr.h" |
8 | 8 |
|
9 | 9 | #include <FreeRTOS.h> |
10 | 10 | #include <os_task.h> |
11 | | -#include <sci.h> |
12 | | -#include <adc.h> |
13 | | -#include <metadata_struct.h> |
14 | 11 |
|
15 | 12 | #include <sys_common.h> |
16 | 13 | #include <sys_core.h> |
| 14 | +#include <gio.h> |
| 15 | +#include <sci.h> |
| 16 | +#include <i2c.h> |
| 17 | +#include <spi.h> |
| 18 | +#include <can.h> |
| 19 | +#include <het.h> |
17 | 20 |
|
18 | | -static StaticTask_t taskBuffer; |
19 | | -static StackType_t taskStack[1024]; |
20 | | - |
21 | | -extern uint32_t __metadata_start__; |
22 | | - |
23 | | -void vTask1(void *pvParameters) { |
24 | | - while (1) { |
25 | | - app_metadata_t metadata = {0}; |
26 | | - obc_error_code_t errCode; |
| 21 | +// This is the stack canary. It should never be overwritten. |
| 22 | +// Ideally, it would be a random value, but we don't have a good source of entropy |
| 23 | +// that we can use. |
| 24 | +void *__stack_chk_guard = (void *)0xDEADBEEF; |
27 | 25 |
|
28 | | - errCode = readAppMetadata(&metadata); |
29 | | - |
30 | | - if (errCode == OBC_ERR_CODE_NO_METADATA) { |
31 | | - sciPrintf("\r\nNO METADATA, APP NOT SENT TO BL OVER SERIAL\r\n"); |
32 | | - } else { |
33 | | - sciPrintf("\r\nParsed values:\r\n"); |
34 | | - sciPrintf("Version: 0x%x\r\n", metadata.vers); |
35 | | - sciPrintf("Binary Size: 0x%x\r\n", metadata.binSize); |
36 | | - sciPrintf("Board Type(0 = Launchpad, 1 = Rev1, 2 = Rev2): 0x%x\r\n", metadata.boardType); |
37 | | - vTaskDelay(2000); |
38 | | - } |
39 | | - } |
40 | | -} |
| 26 | +void __stack_chk_fail(void) { resetSystem(RESET_REASON_STACK_CHECK_FAIL); } |
41 | 27 |
|
42 | 28 | int main(void) { |
| 29 | + // Run hardware initialization code |
| 30 | + gioInit(); |
43 | 31 | sciInit(); |
44 | | - initSciPrint(); |
| 32 | + i2cInit(); |
| 33 | + spiInit(); |
| 34 | + canInit(); |
| 35 | + hetInit(); |
45 | 36 |
|
46 | | - xTaskCreateStatic(vTask1, "Demo", 1024, NULL, 1, taskStack, &taskBuffer); |
| 37 | + _enable_interrupt_(); |
47 | 38 |
|
48 | | - vTaskStartScheduler(); |
| 39 | + // Initialize bus mutexes |
| 40 | + initSciMutex(); |
| 41 | + initI2CMutex(); |
| 42 | + initSpiMutex(); |
49 | 43 |
|
50 | | - while (1) |
51 | | - ; |
| 44 | + // The state_mgr is the only task running initially. |
| 45 | + obcSchedulerInitTask(OBC_SCHEDULER_CONFIG_ID_STATE_MGR); |
| 46 | + obcSchedulerCreateTask(OBC_SCHEDULER_CONFIG_ID_STATE_MGR); |
| 47 | + |
| 48 | + vTaskStartScheduler(); |
52 | 49 | } |
0 commit comments