amiro-os / core / src / aos_debug.c @ 57a5ea60
History | View | Annotate | Download (3.684 KB)
1 |
/*
|
---|---|
2 |
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
|
3 |
Copyright (C) 2016..2018 Thomas Schöpping et al.
|
4 |
|
5 |
This program is free software: you can redistribute it and/or modify
|
6 |
it under the terms of the GNU General Public License as published by
|
7 |
the Free Software Foundation, either version 3 of the License, or
|
8 |
(at your option) any later version.
|
9 |
|
10 |
This program is distributed in the hope that it will be useful,
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
GNU General Public License for more details.
|
14 |
|
15 |
You should have received a copy of the GNU General Public License
|
16 |
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17 |
*/
|
18 |
|
19 |
/**
|
20 |
* @file aos_debug.c
|
21 |
* @brief Functions necessary to print an error on system halt.
|
22 |
*
|
23 |
* @addtogroup aos_debug
|
24 |
* @{
|
25 |
*/
|
26 |
|
27 |
#include <aos_debug.h> |
28 |
|
29 |
#include <hal.h> |
30 |
|
31 |
/*
|
32 |
* System_halt
|
33 |
* ChibiOS error code (see chdebug.c)
|
34 |
*
|
35 |
* - SV#1, misplaced @p chSysDisable().
|
36 |
* - SV#2, misplaced @p chSysSuspend()
|
37 |
* - SV#3, misplaced @p chSysEnable().
|
38 |
* - SV#4, misplaced @p chSysLock().
|
39 |
* - SV#5, misplaced @p chSysUnlock().
|
40 |
* - SV#6, misplaced @p chSysLockFromIsr().
|
41 |
* - SV#7, misplaced @p chSysUnlockFromIsr().
|
42 |
* - SV#8, misplaced @p CH_IRQ_PROLOGUE().
|
43 |
* - SV#9, misplaced @p CH_IRQ_EPILOGUE().
|
44 |
* - SV#10, misplaced I-class function.
|
45 |
* - SV#11, misplaced S-class function.
|
46 |
*/
|
47 |
|
48 |
#if ((CH_DBG_SYSTEM_STATE_CHECK == TRUE) && (HAL_USE_SERIAL == TRUE)) || defined(__DOXYGEN__)
|
49 |
|
50 |
/**
|
51 |
* @brief Actively waits for the serial driver to be empty.
|
52 |
*/
|
53 |
static inline void _serialWaitForEmpty(SerialDriver* sdp) { |
54 |
while (!((sdp->usart->SR) & USART_SR_TC)) {
|
55 |
continue;
|
56 |
} |
57 |
return;
|
58 |
} |
59 |
|
60 |
/**
|
61 |
* @brief Prints the specified string without suspending the thread.
|
62 |
*
|
63 |
* @param[in] str The string to print.
|
64 |
*
|
65 |
* @return The number of characters printed.
|
66 |
*/
|
67 |
static inline unsigned int _printString(SerialDriver* sdp, const char* str) |
68 |
{ |
69 |
unsigned int i = 0; |
70 |
while (str[i] != '\0') { |
71 |
sdp->usart->DR = str[i]; |
72 |
_serialWaitForEmpty(sdp); |
73 |
++i; |
74 |
} |
75 |
return i;
|
76 |
} |
77 |
|
78 |
/**
|
79 |
* @brief Prints the specified string to the given serial stream.
|
80 |
*
|
81 |
* @param[in] sdp serial stream to print to
|
82 |
* @param[in] reason string to print
|
83 |
*/
|
84 |
static void _printError(SerialDriver* sdp, const char* reason) |
85 |
{ |
86 |
if (sdp->state != SD_STOP && sdp->state != SD_READY) {
|
87 |
sd_lld_start(sdp, NULL);
|
88 |
sdp->state = SD_READY; |
89 |
} |
90 |
if (sdp->state == SD_READY) {
|
91 |
_printString(sdp, "\nSystem halt! error code / function name: ");
|
92 |
_printString(sdp, reason); |
93 |
_printString(sdp, "\n");
|
94 |
} |
95 |
|
96 |
return;
|
97 |
} |
98 |
|
99 |
#endif /* ((CH_DBG_SYSTEM_STATE_CHECK == TRUE) && (HAL_USE_SERIAL == TRUE)) || defined(__DOXYGEN__) */ |
100 |
|
101 |
/**
|
102 |
* @brief Prints an error message.
|
103 |
*
|
104 |
* @param[in] reason The string to print.
|
105 |
*/
|
106 |
void aosPrintHaltErrorCode(const char* reason) |
107 |
{ |
108 |
#if (CH_DBG_SYSTEM_STATE_CHECK == TRUE) && (HAL_USE_SERIAL == TRUE)
|
109 |
#if STM32_SERIAL_USE_USART1
|
110 |
_printError(&SD1, reason); |
111 |
#endif
|
112 |
#if STM32_SERIAL_USE_USART2
|
113 |
_printError(&SD2, reason); |
114 |
#endif
|
115 |
#if STM32_SERIAL_USE_USART3
|
116 |
_printError(&SD3, reason); |
117 |
#endif
|
118 |
#if STM32_SERIAL_USE_UART4
|
119 |
_printError(&SD4, reason); |
120 |
#endif
|
121 |
#if STM32_SERIAL_USE_UART5
|
122 |
_printError(&SD5, reason); |
123 |
#endif
|
124 |
#if STM32_SERIAL_USE_USART6
|
125 |
_printError(&SD6, reason); |
126 |
#endif
|
127 |
#if STM32_SERIAL_USE_UART7
|
128 |
_printError(&SD7, reason); |
129 |
#endif
|
130 |
#if STM32_SERIAL_USE_UART8
|
131 |
_printError(&SD8, reason); |
132 |
#endif
|
133 |
#else
|
134 |
(void)reason;
|
135 |
#endif /* (CH_DBG_SYSTEM_STATE_CHECK == TRUE) && (HAL_USE_SERIAL == TRUE) */ |
136 |
|
137 |
return;
|
138 |
} |
139 |
|
140 |
/** @} */
|