Merged in f5soh/librepilot/update_credits (pull request #529)
[librepilot.git] / flight / targets / boards / oplinkmini / pios_board.h
blob752ec3054d92f31f71c489e1e0d5ab95ab29d822
1 /**
2 ******************************************************************************
4 * @file pios_board.h
5 * @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2016.
6 * The OpenPilot Team, http://www.openpilot.org Copyright (C) 2013.
7 * @brief Defines PiOS board hardware for the OpenPilot OPLink Mini board.
8 * @see The GNU Public License (GPL) Version 3
10 *****************************************************************************/
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #ifndef PIOS_BOARD_H
28 #define PIOS_BOARD_H
29 #define ADD_ONE_ADC
31 // ------------------------
32 // Timers and Channels Used
33 // ------------------------
35 Timer | Channel 1 | Channel 2 | Channel 3 | Channel 4
36 ------+-----------+-----------+-----------+----------
37 TIM1 | Servo 4 | | |
38 TIM2 | RC In 5 | RC In 6 | Servo 6 |
39 TIM3 | Servo 5 | RC In 2 | RC In 3 | RC In 4
40 TIM4 | RC In 1 | Servo 3 | Servo 2 | Servo 1
41 ------+-----------+-----------+-----------+----------
44 // ------------------------
45 // DMA Channels Used
46 // ------------------------
47 /* Channel 1 - */
48 /* Channel 2 - */
49 /* Channel 3 - */
50 /* Channel 4 - */
51 /* Channel 5 - */
52 /* Channel 6 - */
53 /* Channel 7 - */
54 /* Channel 8 - */
55 /* Channel 9 - */
56 /* Channel 10 - */
57 /* Channel 11 - */
58 /* Channel 12 - */
61 // ------------------------
62 // BOOTLOADER_SETTINGS
63 // ------------------------
64 #define BOARD_READABLE TRUE
65 #define BOARD_WRITABLE TRUE
66 #define MAX_DEL_RETRYS 3
69 // ------------------------
70 // WATCHDOG_SETTINGS
71 // ------------------------
72 #define PIOS_WATCHDOG_TIMEOUT 500
73 #define PIOS_WDG_REGISTER BKP_DR4
74 #define PIOS_WDG_TELEMETRYTX 0x0001
75 #define PIOS_WDG_TELEMETRYRX 0x0002
76 #define PIOS_WDG_TELEMRADIOTX 0x0004
77 #define PIOS_WDG_TELEMRADIORX 0x0008
78 #define PIOS_WDG_RFM22B 0x000f
79 #define PIOS_WDG_PPMINPUT 0x0010
81 // ------------------------
82 // TELEMETRY
83 // ------------------------
84 #define TELEM_QUEUE_SIZE 20
86 // ------------------------
87 // PIOS_LED
88 // ------------------------
89 #define PIOS_LED_USB 0
90 #define PIOS_LED_LINK 1
91 #define PIOS_LED_RX 2
92 #define PIOS_LED_TX 3
93 #ifdef PIOS_RFM22B_DEBUG_ON_TELEM
94 #define PIOS_LED_D1 4
95 #define PIOS_LED_D2 5
96 #define PIOS_LED_D3 6
97 #define PIOS_LED_D4 7
98 #endif
100 #define PIOS_LED_HEARTBEAT PIOS_LED_LINK
101 #define PIOS_LED_ALARM PIOS_LED_TX
103 #define USB_LED_ON PIOS_LED_On(PIOS_LED_USB)
104 #define USB_LED_OFF PIOS_LED_Off(PIOS_LED_USB)
105 #define USB_LED_TOGGLE PIOS_LED_Toggle(PIOS_LED_USB)
107 #define LINK_LED_ON PIOS_LED_On(PIOS_LED_LINK)
108 #define LINK_LED_OFF PIOS_LED_Off(PIOS_LED_LINK)
109 #define LINK_LED_TOGGLE PIOS_LED_Toggle(PIOS_LED_LINK)
111 #define RX_LED_ON PIOS_LED_On(PIOS_LED_RX)
112 #define RX_LED_OFF PIOS_LED_Off(PIOS_LED_RX)
113 #define RX_LED_TOGGLE PIOS_LED_Toggle(PIOS_LED_RX)
115 #define TX_LED_ON PIOS_LED_On(PIOS_LED_TX)
116 #define TX_LED_OFF PIOS_LED_Off(PIOS_LED_TX)
117 #define TX_LED_TOGGLE PIOS_LED_Toggle(PIOS_LED_TX)
119 #ifdef PIOS_RFM22B_DEBUG_ON_TELEM
120 #define D1_LED_ON PIOS_LED_On(PIOS_LED_D1)
121 #define D1_LED_OFF PIOS_LED_Off(PIOS_LED_D1)
122 #define D1_LED_TOGGLE PIOS_LED_Toggle(PIOS_LED_D1)
124 #define D2_LED_ON PIOS_LED_On(PIOS_LED_D2)
125 #define D2_LED_OFF PIOS_LED_Off(PIOS_LED_D2)
126 #define D2_LED_TOGGLE PIOS_LED_Toggle(PIOS_LED_D2)
128 #define D3_LED_ON PIOS_LED_On(PIOS_LED_D3)
129 #define D3_LED_OFF PIOS_LED_Off(PIOS_LED_D3)
130 #define D3_LED_TOGGLE PIOS_LED_Toggle(PIOS_LED_D3)
132 #define D4_LED_ON PIOS_LED_On(PIOS_LED_D4)
133 #define D4_LED_OFF PIOS_LED_Off(PIOS_LED_D4)
134 #define D4_LED_TOGGLE PIOS_LED_Toggle(PIOS_LED_D4)
135 #endif
137 // -------------------------
138 // System Settings
139 // -------------------------
140 #define PIOS_MASTER_CLOCK 72000000
142 // -------------------------
143 // Interrupt Priorities
144 // -------------------------
145 #define PIOS_IRQ_PRIO_LOW 12 // lower than RTOS
146 #define PIOS_IRQ_PRIO_MID 8 // higher than RTOS
147 #define PIOS_IRQ_PRIO_HIGH 5 // for SPI, ADC, I2C etc...
148 #define PIOS_IRQ_PRIO_HIGHEST 4 // for USART etc...
150 // ------------------------
151 // PIOS_I2C
152 // See also pios_board.c
153 // ------------------------
154 #define PIOS_I2C_MAX_DEVS 1
155 extern uint32_t pios_i2c_flexi_adapter_id;
156 #define PIOS_I2C_MAIN_ADAPTER (pios_i2c_flexi_adapter_id)
158 // ------------------------
159 // PIOS_SPI
160 // See also pios_board.c
161 // ------------------------
162 #define PIOS_SPI_MAX_DEVS 1
163 #define PIOS_SPI_RFM22B_ADAPTER (pios_spi_rfm22b_id)
165 // -------------------------
166 // PIOS_USART
167 // -------------------------
168 #define PIOS_USART_MAX_DEVS 3
170 // -------------------------
171 // PIOS_COM
173 // See also pios_board.c
174 // -------------------------
175 #define PIOS_COM_MAX_DEVS 5
177 /* USB telemetry */
178 #define PIOS_COM_TELEM_USB_RX_BUF_LEN 256
179 #define PIOS_COM_TELEM_USB_TX_BUF_LEN 256
181 /* VCP Bridge */
182 #define PIOS_COM_TELEM_VCP_RX_BUF_LEN 128
183 #define PIOS_COM_TELEM_VCP_TX_BUF_LEN 128
185 // The direct com ports
186 extern uint32_t pios_com_hid_id;
187 extern uint32_t pios_com_vcp_id;
188 extern uint32_t pios_com_main_id;
189 extern uint32_t pios_com_flexi_id;
190 extern uint32_t pios_com_pri_radio_id;
191 extern uint32_t pios_com_aux_radio_id;
192 // The port that the GCS is connected to
193 extern uint32_t pios_com_gcs_id;
194 // The destination port from the GCS port
195 extern uint32_t pios_com_gcs_out_id;
196 // The destination port from the VCP com bridge
197 extern uint32_t pios_com_bridge_id;
198 // The destination port for the primary radio port
199 extern uint32_t pios_com_pri_radio_out_id;
200 // The destination port for the auxiliary radio port.
201 extern uint32_t pios_com_aux_radio_out_id;
202 // The PPM IDs
203 extern uint32_t pios_ppm_out_id;
204 #define PIOS_COM_HID (pios_com_hid_id)
205 #define PIOS_COM_VCP (pios_com_vcp_id)
206 #define PIOS_COM_MAIN (pios_com_main_id)
207 #define PIOS_COM_FLEXI (pios_com_flexi_id)
208 #define PIOS_COM_PRI_RADIO (pios_com_pri_radio_id)
209 #define PIOS_COM_AUX_RADIO (pios_com_aux_radio_id)
210 #define PIOS_COM_PRI_RADIO_OUT (pios_com_pri_radio_out_id)
211 #define PIOS_COM_AUX_RADIO_OUT (pios_com_aux_radio_out_id)
212 #define PIOS_COM_GCS (pios_com_gcs_id)
213 #define PIOS_COM_GCS_OUT (pios_com_gcs_out_id)
214 #define PIOS_COM_BRIDGE (pios_com_bridge_id)
215 #define PIOS_PPM_OUTPUT (pios_ppm_out_id)
216 #define RFM22_DEBUG 1
218 // -------------------------
219 // ADC
220 // None
221 // -------------------------
222 // #define PIOS_ADC_OVERSAMPLING_RATE 1
223 #define PIOS_ADC_USE_TEMP_SENSOR 0
224 #define PIOS_ADC_TEMP_SENSOR_ADC ADC1
225 #define PIOS_ADC_TEMP_SENSOR_ADC_CHANNEL 1
227 #define PIOS_ADC_NUM_PINS 0
229 #define PIOS_ADC_PORTS {}
230 #define PIOS_ADC_PINS {}
231 #define PIOS_ADC_CHANNELS {}
232 #define PIOS_ADC_MAPPING {}
233 #define PIOS_ADC_CHANNEL_MAPPING {}
234 #define PIOS_ADC_NUM_CHANNELS (PIOS_ADC_NUM_PINS + PIOS_ADC_USE_TEMP_SENSOR)
235 #define PIOS_ADC_NUM_ADC_CHANNELS 0
236 #define PIOS_ADC_USE_ADC2 0
237 #define PIOS_ADC_CLOCK_FUNCTION RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_ADC2, ENABLE)
238 #define PIOS_ADC_ADCCLK RCC_PCLK2_Div8
239 /* RCC_PCLK2_Div2: ADC clock = PCLK2/2 */
240 /* RCC_PCLK2_Div4: ADC clock = PCLK2/4 */
241 /* RCC_PCLK2_Div6: ADC clock = PCLK2/6 */
242 /* RCC_PCLK2_Div8: ADC clock = PCLK2/8 */
243 #define PIOS_ADC_SAMPLE_TIME ADC_SampleTime_239Cycles5
244 /* Sample time: */
245 /* With an ADCCLK = 14 MHz and a sampling time of 239.5 cycles: */
246 /* Tconv = 239.5 + 12.5 = 252 cycles = 18�s */
247 /* (1 / (ADCCLK / CYCLES)) = Sample Time (�S) */
248 #define PIOS_ADC_IRQ_PRIO PIOS_IRQ_PRIO_LOW
250 // Currently analog acquistion hard coded at 480 Hz
251 // PCKL2 = HCLK / 16
252 // ADCCLK = PCLK2 / 2
253 #define PIOS_ADC_RATE (72.0e6 / 1.0 / 8.0 / 252.0 / (PIOS_ADC_NUM_CHANNELS >> PIOS_ADC_USE_ADC2))
254 #define PIOS_ADC_MAX_OVERSAMPLING 36
256 #define PIOS_ADC_TEMPERATURE_PIN 0
258 // ------------------------
259 // PIOS_RCVR
260 // See also pios_board.c
261 // ------------------------
262 #define PIOS_RCVR_MAX_DEVS 3
263 #define PIOS_RCVR_MAX_CHANNELS 12
264 #define PIOS_GCSRCVR_TIMEOUT_MS 100
266 // -------------------------
267 // Receiver PPM input
268 // -------------------------
269 #define PIOS_PPM_MAX_DEVS 1
270 #define PIOS_PPM_NUM_INPUTS 12
272 // -------------------------
273 // Receiver PWM inputs
274 // -------------------------
275 #define PIOS_PWM_NUM_INPUTS 4
277 // -------------------------
278 // Servo outputs
279 // -------------------------
280 #define PIOS_SERVO_UPDATE_HZ 50
281 #define PIOS_SERVOS_INITIAL_POSITION 0 /* dont want to start motors, have no pulse till settings loaded */
282 #define PIOS_SERVO_BANKS 6
284 // --------------------------
285 // Timer controller settings
286 // --------------------------
287 #define PIOS_TIM_MAX_DEVS 3
289 // -------------------------
290 // GPIO
291 // -------------------------
292 #define PIOS_GPIO_PORTS {}
293 #define PIOS_GPIO_PINS {}
294 #define PIOS_GPIO_CLKS {}
295 #define PIOS_GPIO_NUM 0
297 // -------------------------
298 // USB
299 // -------------------------
300 #define PIOS_USB_HID_MAX_DEVS 1
301 #define PIOS_USB_ENABLED 1
302 #define PIOS_USB_HID_MAX_DEVS 1
303 #define PIOS_USB_MAX_DEVS 1
304 #define PIOS_USB_DETECT_GPIO_PORT GPIOC
305 #define PIOS_USB_DETECT_GPIO_PIN GPIO_Pin_15
306 #define PIOS_USB_DETECT_EXTI_LINE EXTI_Line15
308 // -------------------------
309 // RFM22
310 // -------------------------
312 #if defined(PIOS_INCLUDE_RFM22B)
313 extern uint32_t pios_spi_rfm22b_id;
314 #define PIOS_RFM22_SPI_PORT (pios_spi_rfm22b_id)
315 extern uint32_t pios_rfm22b_id;
316 #endif /* PIOS_INCLUDE_RFM22B */
318 // -------------------------
319 // Packet Handler
320 // -------------------------
321 extern uint32_t pios_packet_handler;
322 #define PIOS_PACKET_HANDLER (pios_packet_handler)
323 #define PIOS_PH_MAX_PACKET 255
324 #define PIOS_PH_WIN_SIZE 3
325 #define PIOS_PH_MAX_CONNECTIONS 1
326 #define RS_ECC_NPARITY 4
328 // -------------------------
329 // Reed-Solomon ECC
330 // -------------------------
332 #define RS_ECC_NPARITY 4
334 // -------------------------
335 // Flash EEPROM Emulation
336 // -------------------------
338 #define PIOS_FLASH_SIZE 0x20000
339 #define PIOS_FLASH_EEPROM_START_ADDR 0x08000000
340 #define PIOS_FLASH_PAGE_SIZE 1024
341 #define PIOS_FLASH_EEPROM_ADDR (PIOS_FLASH_EEPROM_START_ADDR + PIOS_FLASH_SIZE - PIOS_FLASH_PAGE_SIZE)
342 #define PIOS_FLASH_EEPROM_LEN PIOS_FLASH_PAGE_SIZE
344 #endif /* PIOS_BOARD_H */