update credits
[librepilot.git] / flight / pios / stm32f10x / pios_debug.c
blob9f641f16239654c9f20251eeaef65a719db9172b
1 /**
2 ******************************************************************************
3 * @addtogroup PIOS PIOS Core hardware abstraction layer
4 * @{
5 * @defgroup PIOS_DEBUG Debugging Functions
6 * @brief Debugging functionality
7 * @{
9 * @file pios_debug.c
10 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2013.
11 * @brief Debugging Functions
12 * @see The GNU Public License (GPL) Version 3
14 *****************************************************************************/
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 3 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful, but
22 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
23 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24 * for more details.
26 * You should have received a copy of the GNU General Public License along
27 * with this program; if not, write to the Free Software Foundation, Inc.,
28 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #include "pios.h"
33 // Global variables
34 const char *PIOS_DEBUG_AssertMsg = "ASSERT FAILED";
36 #ifdef PIOS_ENABLE_DEBUG_PINS
37 static const struct pios_tim_channel *debug_channels;
38 static uint8_t debug_num_channels;
39 #endif /* PIOS_ENABLE_DEBUG_PINS */
41 /**
42 * Initialise Debug-features
44 void PIOS_DEBUG_Init(__attribute__((unused)) const struct pios_tim_channel *channels,
45 __attribute__((unused)) uint8_t num_channels)
47 #ifdef PIOS_ENABLE_DEBUG_PINS
48 PIOS_Assert(channels);
49 PIOS_Assert(num_channels);
51 /* Store away the GPIOs we've been given */
52 debug_channels = channels;
53 debug_num_channels = num_channels;
55 /* Configure the GPIOs we've been given */
56 for (uint8_t i = 0; i < num_channels; i++) {
57 const struct pios_tim_channel *chan = &channels[i];
59 // Initialise pins as standard output pins
60 GPIO_InitTypeDef GPIO_InitStructure;
61 GPIO_StructInit(&GPIO_InitStructure);
62 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
63 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
64 GPIO_InitStructure.GPIO_Pin = chan->pin.init.GPIO_Pin;
66 /* Initialize the GPIO */
67 GPIO_Init(chan->pin.gpio, &GPIO_InitStructure);
69 /* Set the pin low */
70 GPIO_WriteBit(chan->pin.gpio, chan->pin.init.GPIO_Pin, Bit_RESET);
72 #endif // PIOS_ENABLE_DEBUG_PINS
75 /**
76 * Set debug-pin high
77 * \param pin 0 for S1 output
79 void PIOS_DEBUG_PinHigh(__attribute__((unused)) uint8_t pin)
81 #ifdef PIOS_ENABLE_DEBUG_PINS
82 if (!debug_channels || pin >= debug_num_channels) {
83 return;
86 const struct pios_tim_channel *chan = &debug_channels[pin];
88 GPIO_WriteBit(chan->pin.gpio, chan->pin.init.GPIO_Pin, Bit_SET);
90 #endif // PIOS_ENABLE_DEBUG_PINS
93 /**
94 * Set debug-pin low
95 * \param pin 0 for S1 output
97 void PIOS_DEBUG_PinLow(__attribute__((unused)) uint8_t pin)
99 #ifdef PIOS_ENABLE_DEBUG_PINS
100 if (!debug_channels || pin >= debug_num_channels) {
101 return;
104 const struct pios_tim_channel *chan = &debug_channels[pin];
106 GPIO_WriteBit(chan->pin.gpio, chan->pin.init.GPIO_Pin, Bit_RESET);
108 #endif // PIOS_ENABLE_DEBUG_PINS
112 void PIOS_DEBUG_PinValue8Bit(__attribute__((unused)) uint8_t value)
114 #ifdef PIOS_ENABLE_DEBUG_PINS
115 if (!debug_channels) {
116 return;
119 uint32_t bsrr_l = (((~value) & 0x0F) << (16 + 6)) | ((value & 0x0F) << 6);
120 uint32_t bsrr_h = (((~value) & 0xF0) << (16 + 6 - 4)) | ((value & 0xF0) << (6 - 4));
122 PIOS_IRQ_Disable();
125 * This is sketchy since it assumes a particular ordering
126 * and bitwise layout of the channels provided to the debug code.
128 debug_channels[0].pin.gpio->BSRR = bsrr_l;
129 debug_channels[4].pin.gpio->BSRR = bsrr_h;
131 PIOS_IRQ_Enable();
132 #endif // PIOS_ENABLE_DEBUG_PINS
135 void PIOS_DEBUG_PinValue4BitL(__attribute__((unused)) uint8_t value)
137 #ifdef PIOS_ENABLE_DEBUG_PINS
138 if (!debug_channels) {
139 return;
143 * This is sketchy since it assumes a particular ordering
144 * and bitwise layout of the channels provided to the debug code.
146 uint32_t bsrr_l = ((~(value & 0x0F) << (16 + 6))) | ((value & 0x0F) << 6);
147 debug_channels[0].pin.gpio->BSRR = bsrr_l;
148 #endif // PIOS_ENABLE_DEBUG_PINS
153 * Report a serious error and halt
155 void PIOS_DEBUG_Panic(__attribute__((unused)) const char *msg)
157 #ifdef PIOS_INCLUDE_DEBUG_CONSOLE
158 register int *lr asm ("lr"); // Link-register holds the PC of the caller
159 DEBUG_PRINTF(0, "\r%s @0x%x\r", msg, lr);
160 #endif
162 // Stay put
163 while (1) {
169 * @}
170 * @}