This is a monitor program for BLE NRF51822 chip. You can check memory, register and system information.
Dependencies: BLE_API mbed nRF51822 nRF51_Vdd
Please refer follows.
/users/kenjiArai/code/debug_tools/
/users/kenjiArai/notebook/ble--tytaiyo-yuden-module-for-mbed/
debug_tools/debug_common.h@4:36ad7c7d0400, 2016-02-14 (annotated)
- Committer:
- kenjiArai
- Date:
- Sun Feb 14 21:55:30 2016 +0000
- Revision:
- 4:36ad7c7d0400
- Parent:
- 0:08c935d6c28f
added some new functions
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kenjiArai | 0:08c935d6c28f | 1 | /* |
kenjiArai | 0:08c935d6c28f | 2 | * mbed Application program (part of debuf_xxx.cpp) |
kenjiArai | 0:08c935d6c28f | 3 | * |
kenjiArai | 0:08c935d6c28f | 4 | * Copyright (c) 2010-2014 Kenji Arai / JH1PJL |
kenjiArai | 0:08c935d6c28f | 5 | * http://www.page.sannet.ne.jp/kenjia/index.html |
kenjiArai | 0:08c935d6c28f | 6 | * http://mbed.org/users/kenjiArai/ |
kenjiArai | 0:08c935d6c28f | 7 | * Created: October 16th, 2014 |
kenjiArai | 0:08c935d6c28f | 8 | * Revised: Nobember 2nd, 2014 |
kenjiArai | 0:08c935d6c28f | 9 | * |
kenjiArai | 0:08c935d6c28f | 10 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, |
kenjiArai | 0:08c935d6c28f | 11 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE |
kenjiArai | 0:08c935d6c28f | 12 | * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
kenjiArai | 0:08c935d6c28f | 13 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
kenjiArai | 0:08c935d6c28f | 14 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
kenjiArai | 0:08c935d6c28f | 15 | */ |
kenjiArai | 0:08c935d6c28f | 16 | |
kenjiArai | 0:08c935d6c28f | 17 | // Definition ------------------------------------------------------------------------------------ |
kenjiArai | 0:08c935d6c28f | 18 | #define BAUD(x) pcm.baud(x) |
kenjiArai | 0:08c935d6c28f | 19 | #define GETC(x) pcm.getc(x) |
kenjiArai | 0:08c935d6c28f | 20 | #define PUTC(x) pcm.putc(x) |
kenjiArai | 0:08c935d6c28f | 21 | #define PRINTF(...) pcm.printf(__VA_ARGS__) |
kenjiArai | 0:08c935d6c28f | 22 | #define READABLE(x) pcm.readable(x) |
kenjiArai | 0:08c935d6c28f | 23 | |
kenjiArai | 0:08c935d6c28f | 24 | #define BAUD_RATE 9600 |
kenjiArai | 0:08c935d6c28f | 25 | |
kenjiArai | 0:08c935d6c28f | 26 | // Object ---------------------------------------------------------------------------------------- |
kenjiArai | 0:08c935d6c28f | 27 | Serial pcm(USBTX, USBRX); |
kenjiArai | 0:08c935d6c28f | 28 | |
kenjiArai | 0:08c935d6c28f | 29 | // RAM ------------------------------------------------------------------------------------------- |
kenjiArai | 0:08c935d6c28f | 30 | char linebuf[64]; |
kenjiArai | 0:08c935d6c28f | 31 | int buf_size = sizeof(linebuf); |
kenjiArai | 0:08c935d6c28f | 32 | |
kenjiArai | 0:08c935d6c28f | 33 | // ROM / Constant data --------------------------------------------------------------------------- |
kenjiArai | 0:08c935d6c28f | 34 | char *const mon_msg = |
kenjiArai | 0:08c935d6c28f | 35 | "Debug Interface for mbed system, created on UTC: "__DATE__"("__TIME__")"; |
kenjiArai | 0:08c935d6c28f | 36 | |
kenjiArai | 0:08c935d6c28f | 37 | // Function prototypes --------------------------------------------------------------------------- |
kenjiArai | 0:08c935d6c28f | 38 | extern int mon_hw(void); |
kenjiArai | 0:08c935d6c28f | 39 | extern void get_freq(int pr); |
kenjiArai | 0:08c935d6c28f | 40 | |
kenjiArai | 0:08c935d6c28f | 41 | //------------------------------------------------------------------------------------------------- |
kenjiArai | 0:08c935d6c28f | 42 | // Control Program |
kenjiArai | 0:08c935d6c28f | 43 | //------------------------------------------------------------------------------------------------- |
kenjiArai | 0:08c935d6c28f | 44 | // Put \r\n |
kenjiArai | 0:08c935d6c28f | 45 | void put_rn ( void ) |
kenjiArai | 0:08c935d6c28f | 46 | { |
kenjiArai | 0:08c935d6c28f | 47 | PUTC('\r'); |
kenjiArai | 0:08c935d6c28f | 48 | PUTC('\n'); |
kenjiArai | 0:08c935d6c28f | 49 | } |
kenjiArai | 0:08c935d6c28f | 50 | |
kenjiArai | 0:08c935d6c28f | 51 | // Put \r |
kenjiArai | 0:08c935d6c28f | 52 | void put_r ( void ) |
kenjiArai | 0:08c935d6c28f | 53 | { |
kenjiArai | 0:08c935d6c28f | 54 | PUTC('\r'); |
kenjiArai | 0:08c935d6c28f | 55 | } |
kenjiArai | 0:08c935d6c28f | 56 | |
kenjiArai | 0:08c935d6c28f | 57 | // Put ", " |
kenjiArai | 0:08c935d6c28f | 58 | void put_lin ( void ) |
kenjiArai | 0:08c935d6c28f | 59 | { |
kenjiArai | 0:08c935d6c28f | 60 | PRINTF(", "); |
kenjiArai | 0:08c935d6c28f | 61 | } |
kenjiArai | 0:08c935d6c28f | 62 | |
kenjiArai | 0:08c935d6c28f | 63 | // Put space n |
kenjiArai | 0:08c935d6c28f | 64 | void put_spc( uint8_t n) |
kenjiArai | 0:08c935d6c28f | 65 | { |
kenjiArai | 0:08c935d6c28f | 66 | for(; n > 0; n--) { |
kenjiArai | 0:08c935d6c28f | 67 | PUTC(' '); |
kenjiArai | 0:08c935d6c28f | 68 | } |
kenjiArai | 0:08c935d6c28f | 69 | } |
kenjiArai | 0:08c935d6c28f | 70 | |
kenjiArai | 0:08c935d6c28f | 71 | // Change string -> integer |
kenjiArai | 0:08c935d6c28f | 72 | //int xatoi (char **str, unsigned long *res){ |
kenjiArai | 0:08c935d6c28f | 73 | int xatoi (char **str, int32_t *res) |
kenjiArai | 0:08c935d6c28f | 74 | { |
kenjiArai | 0:08c935d6c28f | 75 | unsigned long val; |
kenjiArai | 0:08c935d6c28f | 76 | unsigned char c, radix, s = 0; |
kenjiArai | 0:08c935d6c28f | 77 | |
kenjiArai | 0:08c935d6c28f | 78 | while ((c = **str) == ' ') (*str)++; |
kenjiArai | 0:08c935d6c28f | 79 | if (c == '-') { |
kenjiArai | 0:08c935d6c28f | 80 | s = 1; |
kenjiArai | 0:08c935d6c28f | 81 | c = *(++(*str)); |
kenjiArai | 0:08c935d6c28f | 82 | } |
kenjiArai | 0:08c935d6c28f | 83 | if (c == '0') { |
kenjiArai | 0:08c935d6c28f | 84 | c = *(++(*str)); |
kenjiArai | 0:08c935d6c28f | 85 | if (c <= ' ') { |
kenjiArai | 0:08c935d6c28f | 86 | *res = 0; |
kenjiArai | 0:08c935d6c28f | 87 | return 1; |
kenjiArai | 0:08c935d6c28f | 88 | } |
kenjiArai | 0:08c935d6c28f | 89 | if (c == 'x') { |
kenjiArai | 0:08c935d6c28f | 90 | radix = 16; |
kenjiArai | 0:08c935d6c28f | 91 | c = *(++(*str)); |
kenjiArai | 0:08c935d6c28f | 92 | } else { |
kenjiArai | 0:08c935d6c28f | 93 | if (c == 'b') { |
kenjiArai | 0:08c935d6c28f | 94 | radix = 2; |
kenjiArai | 0:08c935d6c28f | 95 | c = *(++(*str)); |
kenjiArai | 0:08c935d6c28f | 96 | } else { |
kenjiArai | 0:08c935d6c28f | 97 | if ((c >= '0')&&(c <= '9')) { |
kenjiArai | 0:08c935d6c28f | 98 | radix = 8; |
kenjiArai | 0:08c935d6c28f | 99 | } else { |
kenjiArai | 0:08c935d6c28f | 100 | return 0; |
kenjiArai | 0:08c935d6c28f | 101 | } |
kenjiArai | 0:08c935d6c28f | 102 | } |
kenjiArai | 0:08c935d6c28f | 103 | } |
kenjiArai | 0:08c935d6c28f | 104 | } else { |
kenjiArai | 0:08c935d6c28f | 105 | if ((c < '1')||(c > '9')) { |
kenjiArai | 0:08c935d6c28f | 106 | return 0; |
kenjiArai | 0:08c935d6c28f | 107 | } |
kenjiArai | 0:08c935d6c28f | 108 | radix = 10; |
kenjiArai | 0:08c935d6c28f | 109 | } |
kenjiArai | 0:08c935d6c28f | 110 | val = 0; |
kenjiArai | 0:08c935d6c28f | 111 | while (c > ' ') { |
kenjiArai | 0:08c935d6c28f | 112 | if (c >= 'a') c -= 0x20; |
kenjiArai | 0:08c935d6c28f | 113 | c -= '0'; |
kenjiArai | 0:08c935d6c28f | 114 | if (c >= 17) { |
kenjiArai | 0:08c935d6c28f | 115 | c -= 7; |
kenjiArai | 0:08c935d6c28f | 116 | if (c <= 9) return 0; |
kenjiArai | 0:08c935d6c28f | 117 | } |
kenjiArai | 0:08c935d6c28f | 118 | if (c >= radix) return 0; |
kenjiArai | 0:08c935d6c28f | 119 | val = val * radix + c; |
kenjiArai | 0:08c935d6c28f | 120 | c = *(++(*str)); |
kenjiArai | 0:08c935d6c28f | 121 | } |
kenjiArai | 0:08c935d6c28f | 122 | if (s) val = -val; |
kenjiArai | 0:08c935d6c28f | 123 | *res = val; |
kenjiArai | 0:08c935d6c28f | 124 | return 1; |
kenjiArai | 0:08c935d6c28f | 125 | } |
kenjiArai | 0:08c935d6c28f | 126 | |
kenjiArai | 0:08c935d6c28f | 127 | // Get key input data |
kenjiArai | 0:08c935d6c28f | 128 | void get_line (char *buff, int len) |
kenjiArai | 0:08c935d6c28f | 129 | { |
kenjiArai | 0:08c935d6c28f | 130 | char c; |
kenjiArai | 0:08c935d6c28f | 131 | int idx = 0; |
kenjiArai | 0:08c935d6c28f | 132 | |
kenjiArai | 0:08c935d6c28f | 133 | for (;;) { |
kenjiArai | 0:08c935d6c28f | 134 | c = GETC(); |
kenjiArai | 0:08c935d6c28f | 135 | // Added by Kenji Arai / JH1PJL May 9th, 2010 |
kenjiArai | 0:08c935d6c28f | 136 | if (c == '\r') { |
kenjiArai | 0:08c935d6c28f | 137 | buff[idx++] = c; |
kenjiArai | 0:08c935d6c28f | 138 | break; |
kenjiArai | 0:08c935d6c28f | 139 | } |
kenjiArai | 0:08c935d6c28f | 140 | if ((c == '\b') && idx) { |
kenjiArai | 0:08c935d6c28f | 141 | idx--; |
kenjiArai | 0:08c935d6c28f | 142 | PUTC(c); |
kenjiArai | 0:08c935d6c28f | 143 | PUTC(' '); |
kenjiArai | 0:08c935d6c28f | 144 | PUTC(c); |
kenjiArai | 0:08c935d6c28f | 145 | } |
kenjiArai | 0:08c935d6c28f | 146 | if (((uint8_t)c >= ' ') && (idx < len - 1)) { |
kenjiArai | 0:08c935d6c28f | 147 | buff[idx++] = c; |
kenjiArai | 0:08c935d6c28f | 148 | PUTC(c); |
kenjiArai | 0:08c935d6c28f | 149 | } |
kenjiArai | 0:08c935d6c28f | 150 | } |
kenjiArai | 0:08c935d6c28f | 151 | buff[idx] = 0; |
kenjiArai | 0:08c935d6c28f | 152 | PUTC('\n'); |
kenjiArai | 0:08c935d6c28f | 153 | } |
kenjiArai | 0:08c935d6c28f | 154 | |
kenjiArai | 4:36ad7c7d0400 | 155 | void get_line_no_param (char *buff) |
kenjiArai | 4:36ad7c7d0400 | 156 | { |
kenjiArai | 4:36ad7c7d0400 | 157 | get_line(buff, buf_size); |
kenjiArai | 4:36ad7c7d0400 | 158 | } |
kenjiArai | 4:36ad7c7d0400 | 159 | |
kenjiArai | 0:08c935d6c28f | 160 | // RTC related subroutines |
kenjiArai | 0:08c935d6c28f | 161 | void chk_and_set_time(char *ptr) |
kenjiArai | 0:08c935d6c28f | 162 | { |
kenjiArai | 0:08c935d6c28f | 163 | //unsigned long p1; |
kenjiArai | 0:08c935d6c28f | 164 | int32_t p1; |
kenjiArai | 0:08c935d6c28f | 165 | struct tm t; |
kenjiArai | 0:08c935d6c28f | 166 | time_t seconds; |
kenjiArai | 0:08c935d6c28f | 167 | char buf[40]; |
kenjiArai | 0:08c935d6c28f | 168 | |
kenjiArai | 0:08c935d6c28f | 169 | if (xatoi(&ptr, &p1)) { |
kenjiArai | 0:08c935d6c28f | 170 | t.tm_year = (uint8_t)p1 + 100; |
kenjiArai | 0:08c935d6c28f | 171 | PRINTF("Year:%d ",p1); |
kenjiArai | 0:08c935d6c28f | 172 | xatoi( &ptr, &p1 ); |
kenjiArai | 0:08c935d6c28f | 173 | t.tm_mon = (uint8_t)p1 - 1; |
kenjiArai | 0:08c935d6c28f | 174 | PRINTF("Month:%d ",p1); |
kenjiArai | 0:08c935d6c28f | 175 | xatoi( &ptr, &p1 ); |
kenjiArai | 0:08c935d6c28f | 176 | t.tm_mday = (uint8_t)p1; |
kenjiArai | 0:08c935d6c28f | 177 | PRINTF("Day:%d ",p1); |
kenjiArai | 0:08c935d6c28f | 178 | xatoi( &ptr, &p1 ); |
kenjiArai | 0:08c935d6c28f | 179 | t.tm_hour = (uint8_t)p1; |
kenjiArai | 0:08c935d6c28f | 180 | PRINTF("Hour:%d ",p1); |
kenjiArai | 0:08c935d6c28f | 181 | xatoi( &ptr, &p1 ); |
kenjiArai | 0:08c935d6c28f | 182 | t.tm_min = (uint8_t)p1; |
kenjiArai | 0:08c935d6c28f | 183 | PRINTF("Min:%d ",p1); |
kenjiArai | 0:08c935d6c28f | 184 | xatoi( &ptr, &p1 ); |
kenjiArai | 0:08c935d6c28f | 185 | t.tm_sec = (uint8_t)p1; |
kenjiArai | 0:08c935d6c28f | 186 | PRINTF("Sec: %d \r\n",p1); |
kenjiArai | 0:08c935d6c28f | 187 | seconds = mktime(&t); |
kenjiArai | 0:08c935d6c28f | 188 | set_time(seconds); |
kenjiArai | 0:08c935d6c28f | 189 | } |
kenjiArai | 0:08c935d6c28f | 190 | seconds = time(NULL); |
kenjiArai | 0:08c935d6c28f | 191 | strftime(buf, 40, "%B %d,'%y, %H:%M:%S", localtime(&seconds)); |
kenjiArai | 0:08c935d6c28f | 192 | PRINTF("Date: %s\r\n", buf); |
kenjiArai | 0:08c935d6c28f | 193 | } |