Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BLE_API mbed nRF51822 nRF51_Vdd
debug_common.h
00001 /* 00002 * mbed Application program (part of debuf_xxx.cpp) 00003 * 00004 * Copyright (c) 2010-2014 Kenji Arai / JH1PJL 00005 * http://www.page.sannet.ne.jp/kenjia/index.html 00006 * http://mbed.org/users/kenjiArai/ 00007 * Created: October 16th, 2014 00008 * Revised: Nobember 2nd, 2014 00009 * 00010 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 00011 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE 00012 * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 00013 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00014 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00015 */ 00016 00017 // Definition ------------------------------------------------------------------------------------ 00018 #define BAUD(x) pcm.baud(x) 00019 #define GETC(x) pcm.getc(x) 00020 #define PUTC(x) pcm.putc(x) 00021 #define PRINTF(...) pcm.printf(__VA_ARGS__) 00022 #define READABLE(x) pcm.readable(x) 00023 00024 #define BAUD_RATE 9600 00025 00026 // Object ---------------------------------------------------------------------------------------- 00027 Serial pcm(USBTX, USBRX); 00028 00029 // RAM ------------------------------------------------------------------------------------------- 00030 char linebuf[64]; 00031 int buf_size = sizeof(linebuf); 00032 00033 // ROM / Constant data --------------------------------------------------------------------------- 00034 char *const mon_msg = 00035 "Debug Interface for mbed system, created on UTC: "__DATE__"("__TIME__")"; 00036 00037 // Function prototypes --------------------------------------------------------------------------- 00038 extern int mon_hw(void); 00039 extern void get_freq(int pr); 00040 00041 //------------------------------------------------------------------------------------------------- 00042 // Control Program 00043 //------------------------------------------------------------------------------------------------- 00044 // Put \r\n 00045 void put_rn ( void ) 00046 { 00047 PUTC('\r'); 00048 PUTC('\n'); 00049 } 00050 00051 // Put \r 00052 void put_r ( void ) 00053 { 00054 PUTC('\r'); 00055 } 00056 00057 // Put ", " 00058 void put_lin ( void ) 00059 { 00060 PRINTF(", "); 00061 } 00062 00063 // Put space n 00064 void put_spc( uint8_t n) 00065 { 00066 for(; n > 0; n--) { 00067 PUTC(' '); 00068 } 00069 } 00070 00071 // Change string -> integer 00072 //int xatoi (char **str, unsigned long *res){ 00073 int xatoi (char **str, int32_t *res) 00074 { 00075 unsigned long val; 00076 unsigned char c, radix, s = 0; 00077 00078 while ((c = **str) == ' ') (*str)++; 00079 if (c == '-') { 00080 s = 1; 00081 c = *(++(*str)); 00082 } 00083 if (c == '0') { 00084 c = *(++(*str)); 00085 if (c <= ' ') { 00086 *res = 0; 00087 return 1; 00088 } 00089 if (c == 'x') { 00090 radix = 16; 00091 c = *(++(*str)); 00092 } else { 00093 if (c == 'b') { 00094 radix = 2; 00095 c = *(++(*str)); 00096 } else { 00097 if ((c >= '0')&&(c <= '9')) { 00098 radix = 8; 00099 } else { 00100 return 0; 00101 } 00102 } 00103 } 00104 } else { 00105 if ((c < '1')||(c > '9')) { 00106 return 0; 00107 } 00108 radix = 10; 00109 } 00110 val = 0; 00111 while (c > ' ') { 00112 if (c >= 'a') c -= 0x20; 00113 c -= '0'; 00114 if (c >= 17) { 00115 c -= 7; 00116 if (c <= 9) return 0; 00117 } 00118 if (c >= radix) return 0; 00119 val = val * radix + c; 00120 c = *(++(*str)); 00121 } 00122 if (s) val = -val; 00123 *res = val; 00124 return 1; 00125 } 00126 00127 // Get key input data 00128 void get_line (char *buff, int len) 00129 { 00130 char c; 00131 int idx = 0; 00132 00133 for (;;) { 00134 c = GETC(); 00135 // Added by Kenji Arai / JH1PJL May 9th, 2010 00136 if (c == '\r') { 00137 buff[idx++] = c; 00138 break; 00139 } 00140 if ((c == '\b') && idx) { 00141 idx--; 00142 PUTC(c); 00143 PUTC(' '); 00144 PUTC(c); 00145 } 00146 if (((uint8_t)c >= ' ') && (idx < len - 1)) { 00147 buff[idx++] = c; 00148 PUTC(c); 00149 } 00150 } 00151 buff[idx] = 0; 00152 PUTC('\n'); 00153 } 00154 00155 void get_line_no_param (char *buff) 00156 { 00157 get_line(buff, buf_size); 00158 } 00159 00160 // RTC related subroutines 00161 void chk_and_set_time(char *ptr) 00162 { 00163 //unsigned long p1; 00164 int32_t p1; 00165 struct tm t; 00166 time_t seconds; 00167 char buf[40]; 00168 00169 if (xatoi(&ptr, &p1)) { 00170 t.tm_year = (uint8_t)p1 + 100; 00171 PRINTF("Year:%d ",p1); 00172 xatoi( &ptr, &p1 ); 00173 t.tm_mon = (uint8_t)p1 - 1; 00174 PRINTF("Month:%d ",p1); 00175 xatoi( &ptr, &p1 ); 00176 t.tm_mday = (uint8_t)p1; 00177 PRINTF("Day:%d ",p1); 00178 xatoi( &ptr, &p1 ); 00179 t.tm_hour = (uint8_t)p1; 00180 PRINTF("Hour:%d ",p1); 00181 xatoi( &ptr, &p1 ); 00182 t.tm_min = (uint8_t)p1; 00183 PRINTF("Min:%d ",p1); 00184 xatoi( &ptr, &p1 ); 00185 t.tm_sec = (uint8_t)p1; 00186 PRINTF("Sec: %d \r\n",p1); 00187 seconds = mktime(&t); 00188 set_time(seconds); 00189 } 00190 seconds = time(NULL); 00191 strftime(buf, 40, "%B %d,'%y, %H:%M:%S", localtime(&seconds)); 00192 PRINTF("Date: %s\r\n", buf); 00193 }
Generated on Sat Jul 16 2022 22:24:09 by
