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