Bluenet  5.7.0
Bluenet, firmware for nRF52 smart home devices
Loading...
Searching...
No Matches
cs_BleError.h
Go to the documentation of this file.
1
6#pragma once
7
8#include <ble/cs_Nordic.h>
10#include <util/cs_Error.h>
11
12// These macros can end up in C code, so use the C logger.
13
14#ifdef __cplusplus
15extern "C" {
16#endif
17
19void ble_error_handler(const char* msg, uint32_t line_num, const char* p_file_name);
20
22// void app_error_handler (uint32_t error_code, uint32_t line_num, const uint8_t * p_file_name);
23
24// called by NRF SDK when it has an internal error.
25void assert_nrf_callback(uint16_t line_num, const uint8_t* file_name);
26
27// called by soft device when it has an internal error.
28void softdevice_assertion_handler(uint32_t pc, uint16_t line_num, const uint8_t* file_name);
29
30void mesh_assertion_handler(uint32_t pc);
31
34#define FDS_ERROR_CHECK(ret_code_t) \
35 do { \
36 const uint32_t LOCAL_ret_code_t = (ret_code_t); \
37 if (LOCAL_ret_code_t != NRF_SUCCESS) { \
38 CLOGe("ret_code_t: $nordicFDSTypeName(%u) (0x%X)", LOCAL_ret_code_t, LOCAL_ret_code_t); \
39 } \
40 } while (0)
41
46#ifdef APP_ERROR_HANDLER
47#undef APP_ERROR_HANDLER
48#endif
49#define APP_ERROR_HANDLER(cs_ret_code_t) \
50 do { \
51 app_error_handler((cs_ret_code_t), __LINE__, (uint8_t*)__FILE__); \
52 } while (0)
53
58#ifdef APP_ERROR_CHECK
59#undef APP_ERROR_CHECK
60#endif
61#define APP_ERROR_CHECK(cs_ret_code_t) \
62 do { \
63 const uint32_t LOCAL_cs_ret_code_t = (cs_ret_code_t); \
64 if (LOCAL_cs_ret_code_t != NRF_SUCCESS) { \
65 CLOGe("cs_ret_code_t: $nordicTypeName(%u) (0x%X)", LOCAL_cs_ret_code_t, LOCAL_cs_ret_code_t); \
66 APP_ERROR_HANDLER(LOCAL_cs_ret_code_t); \
67 } \
68 } while (0)
69
70#define APP_ERROR_CHECK_EXCEPT(cs_ret_code_t, EXCEPTION) \
71 if (cs_ret_code_t == EXCEPTION) { \
72 CLOGw(STRINGIFY((int)EXCEPTION)); \
73 } \
74 else { \
75 APP_ERROR_CHECK(cs_ret_code_t); \
76 }
77
78#ifdef __EXCEPTIONS
79#include <exception>
80
81class ble_exception : public std::exception {
82public:
83 char* _message;
84 ble_exception(char* message, char* file = "<unknown>", int line = 0) : _message(message) {}
85 virtual ~ble_exception() throw() {}
86
87 virtual char const* what() const throw() { return _message; }
88};
89
91//#define BLE_CALL(function, args) do { uint32_t result = function args; if (result != NRF_SUCCESS) throw
92// ble_exception(#function, __FILE__, __LINE__); } while(0)
93
94#define BLE_CALL(function, args) \
95 do { \
96 uint32_t result = function args; \
97 APP_ERROR_CHECK(result); \
98 } while (0)
99
100#define BLE_THROW_IF(result, message) \
101 do { \
102 if (result != NRF_SUCCESS) throw ble_exception(message, __FILE__, __LINE__); \
103 } while (0)
104
105#define BLE_THROW(message) throw ble_exception(message, __FILE__, __LINE__)
106
107#else
109//#define BLE_CALL(function, args) do {volatile uint32_t result = function args; if (result != NRF_SUCCESS) {std::string
110// ble_error_message(# function ); ble_error_handler(ble_error_message, __LINE__, __FILE__); } } while(0)
111#define BLE_CALL(function, args) \
112 do { \
113 uint32_t result = function args; \
114 APP_ERROR_CHECK(result); \
115 } while (0)
116
117#define BLE_THROW_IF(result, message) \
118 do { \
119 if (result != NRF_SUCCESS) { \
120 CLOGd("BLE_THROW: %s", message); \
121 ble_error_handler(message, __LINE__, __FILE__); \
122 } \
123 } while (0)
124
125#define BLE_THROW(message) \
126 do { \
127 CLOGd("BLE_THROW: %s", message); \
128 ble_error_handler(message, __LINE__, __FILE__); \
129 } while (0)
130
131#endif
133#ifdef __cplusplus
134}
135#endif
void softdevice_assertion_handler(uint32_t pc, uint16_t line_num, const uint8_t *file_name)
void mesh_assertion_handler(uint32_t pc)
void ble_error_handler(const char *msg, uint32_t line_num, const char *p_file_name)
Author: Crownstone Team Date: 21 Sep., 2013 License: LGPLv3+, Apache License 2.0, and/or MIT (triple-...
void assert_nrf_callback(uint16_t line_num, const uint8_t *file_name)
called by soft device when you pass bad parameters, etc.