This is my quadcopter prototype software, still in development!

Committer:
Anaesthetix
Date:
Wed Jan 30 13:14:44 2013 +0000
Revision:
0:978110f7f027
My quadcopter prototype software, still in development.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Anaesthetix 0:978110f7f027 1 /* mbed Microcontroller Library - error
Anaesthetix 0:978110f7f027 2 * Copyright (c) 2006-2009 ARM Limited. All rights reserved.
Anaesthetix 0:978110f7f027 3 */
Anaesthetix 0:978110f7f027 4
Anaesthetix 0:978110f7f027 5 #ifndef MBED_ERROR_H
Anaesthetix 0:978110f7f027 6 #define MBED_ERROR_H
Anaesthetix 0:978110f7f027 7
Anaesthetix 0:978110f7f027 8 /* Reporting Compile-Time Errors:
Anaesthetix 0:978110f7f027 9 * To generate a fatal compile-time error, you can use the pre-processor #error directive.
Anaesthetix 0:978110f7f027 10 *
Anaesthetix 0:978110f7f027 11 * > #error "That shouldn't have happened!"
Anaesthetix 0:978110f7f027 12 *
Anaesthetix 0:978110f7f027 13 * If the compiler evaluates this line, it will report the error and stop the compile.
Anaesthetix 0:978110f7f027 14 *
Anaesthetix 0:978110f7f027 15 * For example, you could use this to check some user-defined compile-time variables:
Anaesthetix 0:978110f7f027 16 *
Anaesthetix 0:978110f7f027 17 * > #define NUM_PORTS 7
Anaesthetix 0:978110f7f027 18 * > #if (NUM_PORTS > 4)
Anaesthetix 0:978110f7f027 19 * > #error "NUM_PORTS must be less than 4"
Anaesthetix 0:978110f7f027 20 * > #endif
Anaesthetix 0:978110f7f027 21 *
Anaesthetix 0:978110f7f027 22 * Reporting Run-Time Errors:
Anaesthetix 0:978110f7f027 23 * To generate a fatal run-time error, you can use the mbed error() function.
Anaesthetix 0:978110f7f027 24 *
Anaesthetix 0:978110f7f027 25 * > error("That shouldn't have happened!");
Anaesthetix 0:978110f7f027 26 *
Anaesthetix 0:978110f7f027 27 * If the mbed running the program executes this function, it will print the
Anaesthetix 0:978110f7f027 28 * message via the USB serial port, and then die with the blue lights of death!
Anaesthetix 0:978110f7f027 29 *
Anaesthetix 0:978110f7f027 30 * The message can use printf-style formatting, so you can report variables in the
Anaesthetix 0:978110f7f027 31 * message too. For example, you could use this to check a run-time condition:
Anaesthetix 0:978110f7f027 32 *
Anaesthetix 0:978110f7f027 33 * > if(x >= 5) {
Anaesthetix 0:978110f7f027 34 * > error("expected x to be less than 5, but got %d", x);
Anaesthetix 0:978110f7f027 35 * > }
Anaesthetix 0:978110f7f027 36 */
Anaesthetix 0:978110f7f027 37
Anaesthetix 0:978110f7f027 38 #if 0 // for documentation only
Anaesthetix 0:978110f7f027 39 /* Function: error
Anaesthetix 0:978110f7f027 40 * Report a fatal runtime error
Anaesthetix 0:978110f7f027 41 *
Anaesthetix 0:978110f7f027 42 * Outputs the specified error message to stderr so it will appear via the USB
Anaesthetix 0:978110f7f027 43 * serial port, and then calls exit(1) to die with the blue lights of death.
Anaesthetix 0:978110f7f027 44 *
Anaesthetix 0:978110f7f027 45 * Variables:
Anaesthetix 0:978110f7f027 46 * format - printf-style format string, followed by associated variables
Anaesthetix 0:978110f7f027 47 */
Anaesthetix 0:978110f7f027 48 void error(const char* format, ...);
Anaesthetix 0:978110f7f027 49 #endif
Anaesthetix 0:978110f7f027 50
Anaesthetix 0:978110f7f027 51 #include <stdlib.h>
Anaesthetix 0:978110f7f027 52
Anaesthetix 0:978110f7f027 53 #ifdef NDEBUG
Anaesthetix 0:978110f7f027 54 #define error(...) (exit(1))
Anaesthetix 0:978110f7f027 55 #else
Anaesthetix 0:978110f7f027 56 #include <stdio.h>
Anaesthetix 0:978110f7f027 57 #define error(...) (fprintf(stderr, __VA_ARGS__), exit(1))
Anaesthetix 0:978110f7f027 58 #endif
Anaesthetix 0:978110f7f027 59
Anaesthetix 0:978110f7f027 60 #endif