MMEx with SPI Slave to allow legacy devices to communicate with modern media such as USB, SD cards, the internet and all of the mbed\'s other interfaces
Dependencies: NetServices MSCUsbHost mbed TMP102 SDFileSystem
debug.cpp@0:67a55a82ce06, 2011-02-27 (annotated)
- Committer:
- DeMein
- Date:
- Sun Feb 27 18:54:40 2011 +0000
- Revision:
- 0:67a55a82ce06
Version as submitted to the NXP Design Challenge
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
DeMein | 0:67a55a82ce06 | 1 | /* MMEx for MBED - Debug messages |
DeMein | 0:67a55a82ce06 | 2 | * Copyright (c) 2011 MK |
DeMein | 0:67a55a82ce06 | 3 | * |
DeMein | 0:67a55a82ce06 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
DeMein | 0:67a55a82ce06 | 5 | * of this software and associated documentation files (the "Software"), to deal |
DeMein | 0:67a55a82ce06 | 6 | * in the Software without restriction, including without limitation the rights |
DeMein | 0:67a55a82ce06 | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
DeMein | 0:67a55a82ce06 | 8 | * copies of the Software, and to permit persons to whom the Software is |
DeMein | 0:67a55a82ce06 | 9 | * furnished to do so, subject to the following conditions: |
DeMein | 0:67a55a82ce06 | 10 | * |
DeMein | 0:67a55a82ce06 | 11 | * The above copyright notice and this permission notice shall be included in |
DeMein | 0:67a55a82ce06 | 12 | * all copies or substantial portions of the Software. |
DeMein | 0:67a55a82ce06 | 13 | * |
DeMein | 0:67a55a82ce06 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
DeMein | 0:67a55a82ce06 | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
DeMein | 0:67a55a82ce06 | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
DeMein | 0:67a55a82ce06 | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
DeMein | 0:67a55a82ce06 | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
DeMein | 0:67a55a82ce06 | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
DeMein | 0:67a55a82ce06 | 20 | * THE SOFTWARE. |
DeMein | 0:67a55a82ce06 | 21 | */ |
DeMein | 0:67a55a82ce06 | 22 | |
DeMein | 0:67a55a82ce06 | 23 | /** |
DeMein | 0:67a55a82ce06 | 24 | \file debug.cpp |
DeMein | 0:67a55a82ce06 | 25 | \brief Functions for generating console debug messages |
DeMein | 0:67a55a82ce06 | 26 | */ |
DeMein | 0:67a55a82ce06 | 27 | |
DeMein | 0:67a55a82ce06 | 28 | #include "debug.h" |
DeMein | 0:67a55a82ce06 | 29 | |
DeMein | 0:67a55a82ce06 | 30 | /** DBG_level |
DeMein | 0:67a55a82ce06 | 31 | * |
DeMein | 0:67a55a82ce06 | 32 | * @brief global variable for level of debug messages |
DeMein | 0:67a55a82ce06 | 33 | */ |
DeMein | 0:67a55a82ce06 | 34 | int DBG_level = DBG_ON; |
DeMein | 0:67a55a82ce06 | 35 | |
DeMein | 0:67a55a82ce06 | 36 | /** show a debug message with two strings |
DeMein | 0:67a55a82ce06 | 37 | * |
DeMein | 0:67a55a82ce06 | 38 | * @param src this will typically be the name of the function |
DeMein | 0:67a55a82ce06 | 39 | * @param msg message specific information |
DeMein | 0:67a55a82ce06 | 40 | */ |
DeMein | 0:67a55a82ce06 | 41 | void DBG_msg(char* src, char *msg) { |
DeMein | 0:67a55a82ce06 | 42 | if (DBG_level != DBG_OFF) { |
DeMein | 0:67a55a82ce06 | 43 | printf("%s :: %s\n", src, msg); |
DeMein | 0:67a55a82ce06 | 44 | } |
DeMein | 0:67a55a82ce06 | 45 | } |
DeMein | 0:67a55a82ce06 | 46 | |
DeMein | 0:67a55a82ce06 | 47 | /** show a debug message with a string and an integer |
DeMein | 0:67a55a82ce06 | 48 | * |
DeMein | 0:67a55a82ce06 | 49 | * @param src this will typically be the name of the function |
DeMein | 0:67a55a82ce06 | 50 | * @param i integer passed |
DeMein | 0:67a55a82ce06 | 51 | */ |
DeMein | 0:67a55a82ce06 | 52 | void DBG_int(char* src, int i) { |
DeMein | 0:67a55a82ce06 | 53 | // prints a single integer as debug message |
DeMein | 0:67a55a82ce06 | 54 | if (DBG_level != DBG_OFF) { |
DeMein | 0:67a55a82ce06 | 55 | printf("%s : %d\n", src, i); |
DeMein | 0:67a55a82ce06 | 56 | } |
DeMein | 0:67a55a82ce06 | 57 | } |
DeMein | 0:67a55a82ce06 | 58 | |
DeMein | 0:67a55a82ce06 | 59 | /** show a debug message with a string and a character both a character and hex value |
DeMein | 0:67a55a82ce06 | 60 | * |
DeMein | 0:67a55a82ce06 | 61 | * @param src this will typically be the name of the function |
DeMein | 0:67a55a82ce06 | 62 | * @param c character to be shown |
DeMein | 0:67a55a82ce06 | 63 | */ |
DeMein | 0:67a55a82ce06 | 64 | void DBG_chr(char* src, char c) { |
DeMein | 0:67a55a82ce06 | 65 | if (DBG_level != DBG_OFF) { |
DeMein | 0:67a55a82ce06 | 66 | int cc = c; |
DeMein | 0:67a55a82ce06 | 67 | if (c < 32) c = '.'; |
DeMein | 0:67a55a82ce06 | 68 | printf("%s : %c [%02x]\n", src, c, cc); |
DeMein | 0:67a55a82ce06 | 69 | } |
DeMein | 0:67a55a82ce06 | 70 | } |
DeMein | 0:67a55a82ce06 | 71 | |
DeMein | 0:67a55a82ce06 | 72 | /** show one character in hex, input from SPI to the MBED |
DeMein | 0:67a55a82ce06 | 73 | * |
DeMein | 0:67a55a82ce06 | 74 | * @param c input to be shown |
DeMein | 0:67a55a82ce06 | 75 | */ |
DeMein | 0:67a55a82ce06 | 76 | void DBG_inchar(char C) { |
DeMein | 0:67a55a82ce06 | 77 | // prints only one char in hex, preceded by a + for input followed by a space |
DeMein | 0:67a55a82ce06 | 78 | if (DBG_level == DBG_FULL) { |
DeMein | 0:67a55a82ce06 | 79 | printf("+%02x ", C); |
DeMein | 0:67a55a82ce06 | 80 | } |
DeMein | 0:67a55a82ce06 | 81 | } |
DeMein | 0:67a55a82ce06 | 82 | |
DeMein | 0:67a55a82ce06 | 83 | /** show one character in hex, output from MBED to SPI |
DeMein | 0:67a55a82ce06 | 84 | * |
DeMein | 0:67a55a82ce06 | 85 | * @param c output to be shown |
DeMein | 0:67a55a82ce06 | 86 | */ |
DeMein | 0:67a55a82ce06 | 87 | void DBG_outchar(char C) { |
DeMein | 0:67a55a82ce06 | 88 | if (DBG_level == DBG_FULL) { |
DeMein | 0:67a55a82ce06 | 89 | printf("-%02x ", C); |
DeMein | 0:67a55a82ce06 | 90 | } |
DeMein | 0:67a55a82ce06 | 91 | } |