SpiNNFrontEndCommon  7.4.2
Common support code for user-facing front end systems.
debug.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 The University of Manchester
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * https://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
69 #ifndef __DEBUG_H__
70 #define __DEBUG_H__
71 
72 #include <stdint.h>
73 #include "spin-print.h"
74 #include <assert.h>
75 
84 extern void log_error(const char *message, ...);
85 
93 extern void log_warning(const char *message, ...);
94 
103 extern void log_info(const char *message, ...);
104 
113 extern void log_debug(const char *message, ...);
114 
121 static inline uint32_t float_to_int(float f) {
122  union {
123  float f;
124  uint32_t i;
125  } dat;
126 
127  dat.f = f;
128  return dat.i;
129 }
130 
131 typedef struct {
132  uint32_t lower;
133  uint32_t upper;
134 } __upper_lower_t;
135 
142 static inline uint32_t double_to_lower(double d) {
143  union {
144  double d;
145  __upper_lower_t ints;
146  } dat;
147 
148  dat.d = d;
149  return dat.ints.lower;
150 }
151 
158 static inline uint32_t double_to_upper(double d) {
159  union {
160  double d;
161  __upper_lower_t ints;
162  } dat;
163 
164  dat.d = d;
165  return dat.ints.upper;
166 }
167 
176 #define __log_mini(level, message, ...) \
177  do { \
178  if (level <= LOG_LEVEL) { \
179  uint _debug_cpsr = spin1_int_disable(); \
180  fprintf(stderr, message "\n", ##__VA_ARGS__); \
181  spin1_mode_restore(_debug_cpsr); \
182  } \
183  } while (0)
184 
187 #define log_mini_error(message, ...) \
188  __log_mini(LOG_ERROR, message, ##__VA_ARGS__)
189 
192 #define log_mini_warning(message, ...) \
193  __log_mini(LOG_WARNING, message, ##__VA_ARGS__)
194 
197 #define log_mini_info(message, ...) \
198  __log_mini(LOG_INFO, message, ##__VA_ARGS__)
199 
202 #define log_mini_debug(message, ...) \
203  __log_mini(LOG_DEBUG, message, ##__VA_ARGS__)
204 
205 #endif /* __DEBUG_H__ */
void log_error(const char *message,...)
This function logs errors. Errors usually indicate a serious fault in the program,...
void log_warning(const char *message,...)
This function logs warnings.
static uint32_t double_to_upper(double d)
Type-pun the higher 32 bits of a double as a 32-bit unsigned integer.
Definition: debug.h:158
static uint32_t float_to_int(float f)
Type-pun a float as a 32-bit unsigned integer.
Definition: debug.h:121
void log_debug(const char *message,...)
This function logs debugging messages. This level of message is normally not printed except when the ...
static uint32_t double_to_lower(double d)
Type-pun the lower 32 bits of a double as a 32-bit unsigned integer.
Definition: debug.h:142
void log_info(const char *message,...)
This function logs informational messages. This is the lowest level of message normally printed.