Statistics
| Branch: | Tag: | Revision:

amiro-os / core / src / aos_debug.c @ 8a183f9a

History | View | Annotate | Download (3.64 KB)

1 e545e620 Thomas Schöpping
/*
2
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
3 84f0ce9e Thomas Schöpping
Copyright (C) 2016..2019  Thomas Schöpping et al.
4 e545e620 Thomas Schöpping

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 53710ca3 Marc Rothmann
/**
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 e545e620 Thomas Schöpping
#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 8a183f9a Thomas Schöpping
  while (!((sdp->usart->SR) & USART_SR_TC)) {
55 e545e620 Thomas Schöpping
    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
    _serialWaitForEmpty(sdp);
72 8a183f9a Thomas Schöpping
    sdp->usart->DR = str[i];
73 e545e620 Thomas Schöpping
    ++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 8a183f9a Thomas Schöpping
    return;
88
  } else if (sdp->state == SD_READY) {
89 e545e620 Thomas Schöpping
    _printString(sdp, "\nSystem halt! error code / function name: ");
90
    _printString(sdp, reason);
91
    _printString(sdp, "\n");
92
  }
93
94
  return;
95
}
96
97
#endif /* ((CH_DBG_SYSTEM_STATE_CHECK == TRUE) && (HAL_USE_SERIAL == TRUE)) || defined(__DOXYGEN__) */
98
99
/**
100
 * @brief   Prints an error message.
101
 *
102
 * @param[in] reason  The string to print.
103
 */
104
void aosPrintHaltErrorCode(const char* reason)
105
{
106
#if (CH_DBG_SYSTEM_STATE_CHECK == TRUE) && (HAL_USE_SERIAL == TRUE)
107
  #if STM32_SERIAL_USE_USART1
108
  _printError(&SD1, reason);
109
  #endif
110
  #if STM32_SERIAL_USE_USART2
111
  _printError(&SD2, reason);
112
  #endif
113
  #if STM32_SERIAL_USE_USART3
114
  _printError(&SD3, reason);
115
  #endif
116
  #if STM32_SERIAL_USE_UART4
117
  _printError(&SD4, reason);
118
  #endif
119
  #if STM32_SERIAL_USE_UART5
120
  _printError(&SD5, reason);
121
  #endif
122
  #if STM32_SERIAL_USE_USART6
123
  _printError(&SD6, reason);
124
  #endif
125
  #if STM32_SERIAL_USE_UART7
126
  _printError(&SD7, reason);
127
  #endif
128
  #if STM32_SERIAL_USE_UART8
129
  _printError(&SD8, reason);
130
  #endif
131
#else
132
  (void)reason;
133
#endif /* (CH_DBG_SYSTEM_STATE_CHECK == TRUE) && (HAL_USE_SERIAL == TRUE) */
134
135
  return;
136
}
137 53710ca3 Marc Rothmann
138
/** @} */