amiro-os / os / core / src / aos_debug.c @ 2674917e
History | View | Annotate | Download (3.543 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 |
#include <aos_debug.h> |
20 |
|
21 |
#include <hal.h> |
22 |
|
23 |
/*
|
24 |
* System_halt
|
25 |
* ChibiOS error code (see chdebug.c)
|
26 |
*
|
27 |
* - SV#1, misplaced @p chSysDisable().
|
28 |
* - SV#2, misplaced @p chSysSuspend()
|
29 |
* - SV#3, misplaced @p chSysEnable().
|
30 |
* - SV#4, misplaced @p chSysLock().
|
31 |
* - SV#5, misplaced @p chSysUnlock().
|
32 |
* - SV#6, misplaced @p chSysLockFromIsr().
|
33 |
* - SV#7, misplaced @p chSysUnlockFromIsr().
|
34 |
* - SV#8, misplaced @p CH_IRQ_PROLOGUE().
|
35 |
* - SV#9, misplaced @p CH_IRQ_EPILOGUE().
|
36 |
* - SV#10, misplaced I-class function.
|
37 |
* - SV#11, misplaced S-class function.
|
38 |
*/
|
39 |
|
40 |
#if ((CH_DBG_SYSTEM_STATE_CHECK == TRUE) && (HAL_USE_SERIAL == TRUE)) || defined(__DOXYGEN__)
|
41 |
|
42 |
/**
|
43 |
* @brief Actively waits for the serial driver to be empty.
|
44 |
*/
|
45 |
static inline void _serialWaitForEmpty(SerialDriver* sdp) { |
46 |
while (!((sdp->usart->SR) & USART_SR_TC)) {
|
47 |
continue;
|
48 |
} |
49 |
return;
|
50 |
} |
51 |
|
52 |
/**
|
53 |
* @brief Prints the specified string without suspending the thread.
|
54 |
*
|
55 |
* @param[in] str The string to print.
|
56 |
*
|
57 |
* @return The number of characters printed.
|
58 |
*/
|
59 |
static inline unsigned int _printString(SerialDriver* sdp, const char* str) |
60 |
{ |
61 |
unsigned int i = 0; |
62 |
while (str[i] != '\0') { |
63 |
sdp->usart->DR = str[i]; |
64 |
_serialWaitForEmpty(sdp); |
65 |
++i; |
66 |
} |
67 |
return i;
|
68 |
} |
69 |
|
70 |
/**
|
71 |
* @brief Prints the specified string to the given serial stream.
|
72 |
*
|
73 |
* @param[in] sdp serial stream to print to
|
74 |
* @param[in] reason string to print
|
75 |
*/
|
76 |
static void _printError(SerialDriver* sdp, const char* reason) |
77 |
{ |
78 |
if (sdp->state != SD_STOP && sdp->state != SD_READY) {
|
79 |
sd_lld_start(sdp, NULL);
|
80 |
sdp->state = SD_READY; |
81 |
} |
82 |
if (sdp->state == SD_READY) {
|
83 |
_printString(sdp, "\nSystem halt! error code / function name: ");
|
84 |
_printString(sdp, reason); |
85 |
_printString(sdp, "\n");
|
86 |
} |
87 |
|
88 |
return;
|
89 |
} |
90 |
|
91 |
#endif /* ((CH_DBG_SYSTEM_STATE_CHECK == TRUE) && (HAL_USE_SERIAL == TRUE)) || defined(__DOXYGEN__) */ |
92 |
|
93 |
/**
|
94 |
* @brief Prints an error message.
|
95 |
*
|
96 |
* @param[in] reason The string to print.
|
97 |
*/
|
98 |
void aosPrintHaltErrorCode(const char* reason) |
99 |
{ |
100 |
#if (CH_DBG_SYSTEM_STATE_CHECK == TRUE) && (HAL_USE_SERIAL == TRUE)
|
101 |
#if STM32_SERIAL_USE_USART1
|
102 |
_printError(&SD1, reason); |
103 |
#endif
|
104 |
#if STM32_SERIAL_USE_USART2
|
105 |
_printError(&SD2, reason); |
106 |
#endif
|
107 |
#if STM32_SERIAL_USE_USART3
|
108 |
_printError(&SD3, reason); |
109 |
#endif
|
110 |
#if STM32_SERIAL_USE_UART4
|
111 |
_printError(&SD4, reason); |
112 |
#endif
|
113 |
#if STM32_SERIAL_USE_UART5
|
114 |
_printError(&SD5, reason); |
115 |
#endif
|
116 |
#if STM32_SERIAL_USE_USART6
|
117 |
_printError(&SD6, reason); |
118 |
#endif
|
119 |
#if STM32_SERIAL_USE_UART7
|
120 |
_printError(&SD7, reason); |
121 |
#endif
|
122 |
#if STM32_SERIAL_USE_UART8
|
123 |
_printError(&SD8, reason); |
124 |
#endif
|
125 |
#else
|
126 |
(void)reason;
|
127 |
#endif /* (CH_DBG_SYSTEM_STATE_CHECK == TRUE) && (HAL_USE_SERIAL == TRUE) */ |
128 |
|
129 |
return;
|
130 |
} |