dRonin  adbada4
dRonin firmware
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
chibi_main.c
Go to the documentation of this file.
1 
12 /*
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 3 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful, but
19  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  * for more details.
22  *
23  * You should have received a copy of the GNU General Public License along
24  * with this program; if not, see <http://www.gnu.org/licenses/>
25  */
26 
27 
28 /* OpenPilot Includes */
29 #include "openpilot.h"
30 
31 #include "misc_math.h"
32 
33 #include "pios_config.h"
34 #include "pios_hal.h"
35 #include "uavobjectsinit.h"
36 #include "systemmod.h"
37 #include "pios_thread.h"
38 
39 /* Function Prototypes */
40 extern void PIOS_Board_Init(void);
41 extern void Stack_Change(void);
42 static void initTask(void);
43 
49 void __early_init(void) {
50 
51  stm32_clock_init();
52 }
53 
58 void boardInit(void) {
59 }
60 
69 int main()
70 {
71  /* NOTE: Do NOT modify the following start-up sequence */
73 
74  halInit();
75  chSysInit(); /* Enables interrupts */
76 
77  boardInit();
78 
79  /* Brings up System using CMSIS functions, enables the LEDs. */
80  PIOS_SYS_Init();
81 
82  initTask();
83 
84  while(1)
86 
87  return 0;
88 }
89 
90 #if defined(STM32F4XX)
91 
92 #include <stm32f4xx_flash.h>
97 void check_bor()
98 {
99  uint8_t bor = FLASH_OB_GetBOR();
100 
101  if (bor != OB_BOR_LEVEL3) {
102  FLASH_OB_Unlock();
103  FLASH_OB_BORConfig(OB_BOR_LEVEL3);
104  FLASH_OB_Launch();
105  while (FLASH_WaitForLastOperation() == FLASH_BUSY) {
106  ;
107  }
108  FLASH_OB_Lock();
109  while (FLASH_WaitForLastOperation() == FLASH_BUSY) {
110  ;
111  }
112  }
113 }
114 
115 #else
116 void check_bor()
117 {
118 }
119 #endif
120 
121 void system_task();
122 
128 void initTask(void)
129 {
130  /* Ensure BOR is programmed sane */
131  check_bor();
132 
133  /* Init delay system */
134  PIOS_DELAY_Init();
135 
136  /* Initialize the task monitor library */
138 
139  /* Initialize UAVObject libraries */
141 
142 #ifndef PIPXTREME
143  /* Initialize the alarms library. Reads RCC reset flags */
145 #endif
146 
147  uint8_t serial[PIOS_SYS_SERIAL_NUM_BINARY_LEN];
149 
150  for (int i = 0; i < PIOS_SYS_SERIAL_NUM_BINARY_LEN; i += 4) {
151  /* TODO: consider mixing in HRNG on F4 */
153  (serial[i]) |
154  (serial[i+1] << 8) |
155  (serial[i+2] << 16) |
156  (serial[i+3] << 24));
157  }
158 
160 
161  /* board driver init */
162  PIOS_Board_Init();
163 
164  /* Initialize modules */
166 
167  /* create all modules thread */
169 
170  /* Explicitly invoke system task, in this thread stack. */
171  system_task();
172 }
173 
void PIOS_HAL_InitUAVTalkReceiver()
Definition: pios_hal.c:1435
#define MODULE_TASKCREATE_ALL
Definition: pios_initcall.h:77
#define PIOS_THREAD_TIMEOUT_MAX
Definition: pios_thread.h:29
System module.
void PIOS_Board_Init(void)
Definition: pios_board.c:65
static void initTask(void)
Definition: chibi_main.c:128
#define PIOS_SYS_SERIAL_NUM_BINARY_LEN
Definition: pios_sys.h:36
void PIOS_SYS_Init(void)
int32_t PIOS_DELAY_Init(void)
Definition: pios_delay.c:98
#define MODULE_INITIALISE_ALL(wdgfn)
Definition: pios_initcall.h:69
void PIOS_WDG_Clear(void)
Clear the watchdog timer.
Definition: pios_wdg.c:147
void __early_init(void)
Early initialization code.
Definition: chibi_main.c:49
void PIOS_heap_initialize_blocks(void)
Definition: pios_heap.c:228
uint8_t i
Definition: msp_messages.h:97
int main()
Definition: chibi_main.c:69
void PIOS_Thread_Sleep(uint32_t time_ms)
Definition: pios_thread.c:229
void check_bor()
Definition: chibi_main.c:116
void randomize_addseed(uint32_t seed)
Definition: misc_math.c:315
int32_t TaskMonitorInitialize(void)
Definition: taskmonitor.c:50
void Stack_Change(void)
Definition: pios_board.c:53
Includes PiOS and core architecture components.
void system_task()
Definition: systemmod.c:223
int32_t UAVObjInitialize()
int32_t AlarmsInitialize(void)
Definition: alarms.c:51
void boardInit(void)
Board-specific initialization code.
Definition: chibi_main.c:58
int32_t PIOS_SYS_SerialNumberGetBinary(uint8_t array[PIOS_SYS_SERIAL_NUM_BINARY_LEN])