2 *****************************************************************************
4 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
5 * @author PhoenixPilot, http://github.com/PhoenixPilot, Copyright (C) 2012
6 * @addtogroup OpenPilotSystem OpenPilot System
8 * @addtogroup OpenPilotCore OpenPilot Core
10 * @brief Defines board specific static initializers for hardware for the CopterControl board.
11 *****************************************************************************/
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.
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
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include "inc/openpilot.h"
29 #include <pios_board_info.h>
30 #include <uavobjectsinit.h>
31 #include <hwsettings.h>
32 #include <manualcontrolsettings.h>
33 #include <gcsreceiver.h>
36 * Pull in the board-specific static HW definitions.
37 * Including .c files is a bit ugly but this allows all of
38 * the HW definitions to be const and static to limit their
41 * NOTE: THIS IS THE ONLY PLACE THAT SHOULD EVER INCLUDE THIS FILE
43 #include "../board_hw_defs.c"
45 #define PIOS_COM_MAIN_RX_BUF_LEN 32
46 #define PIOS_COM_MAIN_TX_BUF_LEN 128
48 uint32_t pios_com_main_id
;
52 * initializes all the core subsystems on this specific hardware
53 * called from System/openpilot.c
56 void PIOS_Board_Init(void)
61 const struct pios_board_info
*bdinfo
= &pios_board_info_blob
;
63 #if defined(PIOS_INCLUDE_LED)
64 const struct pios_gpio_cfg
*led_cfg
= PIOS_BOARD_HW_DEFS_GetLedCfg(bdinfo
->board_rev
);
66 PIOS_LED_Init(led_cfg
);
67 #endif /* PIOS_INCLUDE_LED */
69 /* Initialize watchdog as early as possible to catch faults during init */
70 #ifdef PIOS_INCLUDE_WDG
73 #if defined(PIOS_INCLUDE_SPI)
74 /* Set up the SPI interface to the serial flash */
75 if (PIOS_SPI_Init(&pios_spi_mag_flash_id
, &pios_spi_mag_flash_cfg
)) {
79 #ifdef PIOS_INCLUDE_HMC5X83
80 PIOS_SPI_SetClockSpeed(pios_spi_mag_flash_id
, SPI_BaudRatePrescaler_16
);
81 onboard_mag
= PIOS_HMC5x83_Init(&pios_mag_cfg
, pios_spi_mag_flash_id
, 0);
82 if (PIOS_Flash_Jedec_Init(&flash_id
, pios_spi_mag_flash_id
, 1)) {
89 #if defined(PIOS_INCLUDE_RTC)
90 /* Initialize the real-time clock and its associated tick */
91 PIOS_RTC_Init(&pios_rtc_main_cfg
);
95 /* Check for repeated boot failures */
96 uint16_t boot_count
= PIOS_IAP_ReadBootCount();
98 PIOS_IAP_WriteBootCount(++boot_count
);
101 #if defined(PIOS_INCLUDE_COM)
103 uint32_t pios_usart_generic_id
;
104 if (PIOS_USART_Init(&pios_usart_generic_id
, &pios_usart_generic_main_cfg
)) {
107 uint8_t *rx_buffer
= (uint8_t *)pvPortMalloc(PIOS_COM_MAIN_RX_BUF_LEN
);
108 PIOS_Assert(rx_buffer
);
110 uint8_t *tx_buffer
= (uint8_t *)pvPortMalloc(PIOS_COM_MAIN_TX_BUF_LEN
);
111 PIOS_Assert(tx_buffer
);
112 if (PIOS_COM_Init(&pios_com_main_id
, &pios_usart_com_driver
, pios_usart_generic_id
,
113 rx_buffer
, PIOS_COM_MAIN_RX_BUF_LEN
,
114 tx_buffer
, PIOS_COM_MAIN_TX_BUF_LEN
)) {
118 PIOS_COM_ChangeBaud(pios_com_main_id
, 57600);
122 #if defined(PIOS_INCLUDE_I2C)
124 if (PIOS_I2C_Init(&pios_i2c_gps_id
, &pios_i2c_gps_cfg
)) {
128 #endif /* PIOS_INCLUDE_I2C */