mbed libraries for KL25Z
error.h@8:c14af7958ef5, 2012-11-09 (annotated)
- Committer:
- emilmont
- Date:
- Fri Nov 09 11:33:53 2012 +0000
- Revision:
- 8:c14af7958ef5
- Parent:
- 0:8024c367e29f
- Child:
- 9:663789d7729f
SPI driver; ADC driver; DAC driver; microlib support; general bugfixing
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
emilmont | 0:8024c367e29f | 1 | /* mbed Microcontroller Library - error |
emilmont | 0:8024c367e29f | 2 | * Copyright (c) 2006-2009 ARM Limited. All rights reserved. |
emilmont | 8:c14af7958ef5 | 3 | */ |
emilmont | 0:8024c367e29f | 4 | #ifndef MBED_ERROR_H |
emilmont | 0:8024c367e29f | 5 | #define MBED_ERROR_H |
emilmont | 0:8024c367e29f | 6 | |
emilmont | 8:c14af7958ef5 | 7 | /** To generate a fatal compile-time error, you can use the pre-processor #error directive. |
emilmont | 0:8024c367e29f | 8 | * |
emilmont | 8:c14af7958ef5 | 9 | * @code |
emilmont | 8:c14af7958ef5 | 10 | * #error "That shouldn't have happened!" |
emilmont | 8:c14af7958ef5 | 11 | * @endcode |
emilmont | 0:8024c367e29f | 12 | * |
emilmont | 0:8024c367e29f | 13 | * If the compiler evaluates this line, it will report the error and stop the compile. |
emilmont | 0:8024c367e29f | 14 | * |
emilmont | 0:8024c367e29f | 15 | * For example, you could use this to check some user-defined compile-time variables: |
emilmont | 0:8024c367e29f | 16 | * |
emilmont | 8:c14af7958ef5 | 17 | * @code |
emilmont | 8:c14af7958ef5 | 18 | * #define NUM_PORTS 7 |
emilmont | 8:c14af7958ef5 | 19 | * #if (NUM_PORTS > 4) |
emilmont | 8:c14af7958ef5 | 20 | * #error "NUM_PORTS must be less than 4" |
emilmont | 8:c14af7958ef5 | 21 | * #endif |
emilmont | 8:c14af7958ef5 | 22 | * @endcode |
emilmont | 0:8024c367e29f | 23 | * |
emilmont | 0:8024c367e29f | 24 | * Reporting Run-Time Errors: |
emilmont | 0:8024c367e29f | 25 | * To generate a fatal run-time error, you can use the mbed error() function. |
emilmont | 0:8024c367e29f | 26 | * |
emilmont | 8:c14af7958ef5 | 27 | * @code |
emilmont | 8:c14af7958ef5 | 28 | * error("That shouldn't have happened!"); |
emilmont | 8:c14af7958ef5 | 29 | * @endcode |
emilmont | 0:8024c367e29f | 30 | * |
emilmont | 0:8024c367e29f | 31 | * If the mbed running the program executes this function, it will print the |
emilmont | 0:8024c367e29f | 32 | * message via the USB serial port, and then die with the blue lights of death! |
emilmont | 0:8024c367e29f | 33 | * |
emilmont | 0:8024c367e29f | 34 | * The message can use printf-style formatting, so you can report variables in the |
emilmont | 0:8024c367e29f | 35 | * message too. For example, you could use this to check a run-time condition: |
emilmont | 0:8024c367e29f | 36 | * |
emilmont | 8:c14af7958ef5 | 37 | * @code |
emilmont | 8:c14af7958ef5 | 38 | * if(x >= 5) { |
emilmont | 8:c14af7958ef5 | 39 | * error("expected x to be less than 5, but got %d", x); |
emilmont | 8:c14af7958ef5 | 40 | * } |
emilmont | 8:c14af7958ef5 | 41 | * #endcode |
emilmont | 0:8024c367e29f | 42 | */ |
emilmont | 0:8024c367e29f | 43 | |
emilmont | 0:8024c367e29f | 44 | #include <stdlib.h> |
emilmont | 0:8024c367e29f | 45 | |
emilmont | 0:8024c367e29f | 46 | #ifdef NDEBUG |
emilmont | 0:8024c367e29f | 47 | #define error(...) (exit(1)) |
emilmont | 0:8024c367e29f | 48 | #else |
emilmont | 0:8024c367e29f | 49 | #include <stdio.h> |
emilmont | 0:8024c367e29f | 50 | #define error(...) (fprintf(stderr, __VA_ARGS__), exit(1)) |
emilmont | 0:8024c367e29f | 51 | #endif |
emilmont | 0:8024c367e29f | 52 | |
emilmont | 0:8024c367e29f | 53 | #endif |