2 ******************************************************************************
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
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
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 */
33 #if defined(PIOS_INCLUDE_SYS)
36 /* Private Function Prototypes */
37 void NVIC_Configuration(void);
38 void SysTick_Handler(void);
41 #define MEM8(addr) (*((volatile uint8_t *)(addr)))
44 * Initialises all system peripherals
46 void PIOS_SYS_Init(void)
51 printf("PIOS_SYS_Init\n");
53 /* Initialise Basic NVIC */
56 #if defined(PIOS_INCLUDE_LED)
63 * Shutdown PIOS and reset the microcontroller:<BR>
65 * <LI>Disable all RTOS tasks
66 * <LI>Disable all interrupts
67 * <LI>Turn off all board LEDs
70 * \return < 0 if reset failed
72 int32_t PIOS_SYS_Reset(void)
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) */
84 // disable all interrupts
85 // PIOS_IRQ_Disable();
87 // turn off all board LEDs
88 #if (PIOS_LED_NUM == 1)
90 #elif (PIOS_LED_NUM == 2)
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);
109 /* We will never reach this point */
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
) {
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" */
141 for (i
= 0; i
< PIOS_SYS_SERIAL_NUM_ASCII_LEN
; ++i
) {
151 * Configures Vector Table base location and SysTick
153 void NVIC_Configuration(void)
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
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 */
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) */