LP-311 Remove basic/advanced stabilization tab auto-switch (autotune/txpid lock issues)
[librepilot.git] / flight / pios / posix / pios_sys.c
blob7e9d5df7b2b3ec36e27b7eece6fe084234d13c4f
1 /**
2 ******************************************************************************
4 * @file pios_sys.c
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
6 * Parts by Thorsten Klose (tk@midibox.org) (tk@midibox.org)
7 * @brief Sets up basic system hardware, functions are called from Main.
8 * @see The GNU Public License (GPL) Version 3
9 * @defgroup PIOS_SYS System Functions
10 * @{
12 *****************************************************************************/
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * for more details.
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 /* Project Includes */
31 #include <pios.h>
33 #if defined(PIOS_INCLUDE_SYS)
36 /* Private Function Prototypes */
37 void NVIC_Configuration(void);
38 void SysTick_Handler(void);
40 /* Local Macros */
41 #define MEM8(addr) (*((volatile uint8_t *)(addr)))
43 /**
44 * Initialises all system peripherals
46 void PIOS_SYS_Init(void)
48 /**
49 * stub
51 printf("PIOS_SYS_Init\n");
53 /* Initialise Basic NVIC */
54 NVIC_Configuration();
56 #if defined(PIOS_INCLUDE_LED)
57 /* Initialise LEDs */
58 PIOS_LED_Init();
59 #endif
62 /**
63 * Shutdown PIOS and reset the microcontroller:<BR>
64 * <UL>
65 * <LI>Disable all RTOS tasks
66 * <LI>Disable all interrupts
67 * <LI>Turn off all board LEDs
68 * <LI>Reset STM32
69 * </UL>
70 * \return < 0 if reset failed
72 int32_t PIOS_SYS_Reset(void)
74 /**
75 * stub
77 printf("PIOS_SYS_Reset\n");
78 /* Disable all RTOS tasks */
79 #if defined(PIOS_INCLUDE_FREERTOS)
80 /* port specific FreeRTOS function to disable tasks (nested) */
81 portENTER_CRITICAL();
82 #endif
84 // disable all interrupts
85 // PIOS_IRQ_Disable();
87 // turn off all board LEDs
88 #if (PIOS_LED_NUM == 1)
89 PIOS_LED_Off(LED1);
90 #elif (PIOS_LED_NUM == 2)
91 PIOS_LED_Off(LED1);
92 PIOS_LED_Off(LED2);
93 #endif
96 /* Reset STM32 */
97 // RCC_APB2PeriphResetCmd(0xfffffff8, ENABLE); /* MBHP_CORE_STM32: don't reset GPIOA/AF due to USB pins */
98 // RCC_APB1PeriphResetCmd(0xff7fffff, ENABLE); /* don't reset USB, so that the connection can survive! */
100 // RCC_APB2PeriphResetCmd(0xffffffff, DISABLE);
101 // RCC_APB1PeriphResetCmd(0xffffffff, DISABLE);
102 // SCB->AIRCR = NVIC_AIRCR_VECTKEY | (1 << NVIC_VECTRESET);
103 exit(1);
105 while (1) {
109 /* We will never reach this point */
110 return -1;
114 * Returns the serial number as a string
115 * param[out] uint8_t pointer to a string which can store at least 12 bytes
116 * (12 bytes returned for STM32)
117 * return < 0 if feature not supported
119 int32_t PIOS_SYS_SerialNumberGetBinary(uint8_t *array)
121 /* Stored in the so called "electronic signature" */
122 for (int i = 0; i < PIOS_SYS_SERIAL_NUM_BINARY_LEN; ++i) {
123 array[i] = 0xff;
126 /* No error */
127 return 0;
131 * Returns the serial number as a string
132 * param[out] str pointer to a string which can store at least 32 digits + zero terminator!
133 * (24 digits returned for STM32)
134 * return < 0 if feature not supported
136 int32_t PIOS_SYS_SerialNumberGet(char *str)
138 /* Stored in the so called "electronic signature" */
139 int i;
141 for (i = 0; i < PIOS_SYS_SERIAL_NUM_ASCII_LEN; ++i) {
142 str[i] = 'F';
144 str[i] = '\0';
146 /* No error */
147 return 0;
151 * Configures Vector Table base location and SysTick
153 void NVIC_Configuration(void)
156 * stub
158 printf("NVIC_Configuration\n");
159 /* Set the Vector Table base address as specified in .ld file */
160 // NVIC_SetVectorTable(PIOS_NVIC_VECTTAB_FLASH, 0x0);
162 /* 4 bits for Interrupt priorities so no sub priorities */
163 // NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
165 /* Configure HCLK clock as SysTick clock source. */
166 // SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK);
169 #ifdef USE_FULL_ASSERT
171 * Reports the name of the source file and the source line number
172 * where the assert_param error has occurred.
173 * \param[in] file pointer to the source file name
174 * \param[in] line assert_param error line source number
175 * \retval None
177 void assert_failed(uint8_t *file, uint32_t line)
179 /* When serial debugging is implemented, use something like this. */
180 /* printf("Wrong parameters value: file %s on line %d\r\n", file, line); */
181 printf("Wrong parameters value: file %s on line %d\r\n", file, line);
183 /* Setup the LEDs to Alternate */
184 PIOS_LED_On(LED1);
185 PIOS_LED_Off(LED2);
187 /* Infinite loop */
188 while (1) {
189 PIOS_LED_Toggle(LED1);
190 PIOS_LED_Toggle(LED2);
191 for (int i = 0; i < 1000000; i++) {
196 #endif /* ifdef USE_FULL_ASSERT */
198 #endif /* if defined(PIOS_INCLUDE_SYS) */