Revision efbf7cb1

View differences:

core/inc/aos_debug.h
28 28
#define _AMIROOS_DEBUG_H_
29 29

  
30 30
#include <aosconf.h>
31
#include <ch.h>
31
#include <hal.h>
32
#include <chprintf.h>
32 33

  
33 34
#if (AMIROOS_CFG_DBG == true) || defined(__DOXYGEN__)
34 35

  
......
67 68
 *
68 69
 * @param[in] fmt   Formatted string to print.
69 70
 */
70
#define aosDbgPrintf(fmt, ...)           chprintf((BaseSequentialStream*)&aos.iostream, fmt, ##__VA_ARGS__)
71
#define aosDbgPrintf(fmt, ...)        chprintf((BaseSequentialStream*)&aos.iostream, fmt, ##__VA_ARGS__)
71 72

  
72 73
#else /* (AMIROOS_CFG_DBG != true) */
73 74

  
......
90 91

  
91 92
#endif
92 93

  
93
#ifdef __cplusplus
94
extern "C" {
95
#endif
96
  void aosPrintHaltErrorCode(const char* reason);
97
#ifdef __cplusplus
98
}
99
#endif
100

  
101 94
#endif /* _AMIROOS_DEBUG_H_ */
102 95

  
103 96
/** @} */
core/src/aos_debug.c
1
/*
2
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
3
Copyright (C) 2016..2019  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
    _serialWaitForEmpty(sdp);
72
    sdp->usart->DR = str[i];
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
    return;
88
  } else if (sdp->state == SD_READY) {
89
    _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

  
138
/** @} */
modules/aos_chconf.h
646 646
 *          the system is halted.
647 647
 */
648 648
#define CH_CFG_SYSTEM_HALT_HOOK(reason) {                                   \
649
  extern void aosPrintHaltErrorCode(const char* reason);                    \
650
  aosPrintHaltErrorCode(reason);                                            \
649
  /* System halt code here.*/                                               \
651 650
}
652 651

  
653 652
/**

Also available in: Unified diff