📄 monitor.c
字号:
}int mkdir (const char *path, mode_t mode){ return _mkdir (path, mode);}int chmod (const char *path, mode_t mode){ return _chmod (path, mode);}#endif#if defined CFG_MD || defined CFG_MEM || defined CFG_IAP || defined CFG_UIP || defined CFG_SNTP || defined CFG_I2C || defined CFG_LM75 || defined CFG_AT24C1024 || defined CFG_M25LC512//////static int getNumber (char *s, unsigned int *result){ unsigned int value; unsigned int mustBeHex = FALSE; int sgn = 1; const unsigned char hexToDec [] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 255, 255, 255, 255, 255, 255, 255, 10, 11, 12, 13, 14, 15}; if (!s) return 0; if ((strlen (s) > 2) && (!strncmp (s, "0x", 2) || !strncmp (s, "0X", 2))) { mustBeHex = TRUE; s += 2; } if (!mustBeHex && *s && (*s == '-')) { sgn = -1; s++; } for (value = 0; *s; s++) { if (mustBeHex && isxdigit (*s)) value = (value << 4) | hexToDec [toupper (*s) - '0']; else if (isdigit (*s)) value = (value * 10) + (*s - '0'); else { printf ("Malformed number. Must be decimal number, or hex value preceeded by '0x'\n"); return 0; } } if (!mustBeHex) value *= sgn; *result = value; return 1;}#endif#ifdef CFG_UIPstatic int getIPAddress (char *s, unsigned int *ipAddress){ char *p = s; char *t = NULL; int i; for (*ipAddress = 0, i = 0; i < 4; i++) { unsigned int ipOctet; if (i != 3) { if ((t = index (p, '.')) && (t != p)) *t = '\0'; else { printf ("Incorrectly formatted IP address\n"); return 0; } } if (!*p) { printf ("Missing octet in IP address\n"); return 0; } if (!isDecimalString (p)) { printf ("Bad octet value in IP address: \"%s\"\n", p); return 0; } getNumber (p, &ipOctet); if (ipOctet > 255) { printf ("Illegal octet value: \"%s\"\n", p); return 0; } *ipAddress = (*ipAddress << 8) | ipOctet; p = t + 1; } return 1;}#endif#ifdef CFG_UIPstatic int atoh (char *s, unsigned int *r){ unsigned int i; unsigned int l; char buffer [(l = strlen (s)) + 3]; for (i = 0; i < l; i++) if (!isxdigit (s [i])) return 0; strcpy (buffer, "0x"); strcat (buffer, s); return getNumber (buffer, r);}#endif#ifdef CFG_MDCODE//////static int monitorDumpMemory (unsigned int displayAddress, unsigned int mask, unsigned int address, int length){ unsigned char *buffer; int i; if (!length) { printf ("Error: monitorDumpMemory() passed 0 for length\n"); return address; } for (buffer = (unsigned char *) address, i = 0; i < length; i += 16) { unsigned int l; unsigned int j; if (i) printf ("\n"); printf ("%08x: ", (displayAddress + i) & mask); if ((length - i) < 16) l = length & 15; else l = 16; for (j = 0; j < 16; j++) { if (j < l) printf ("%02x ", buffer [i+j]); else printf (" "); } printf (" "); for (j = 0; j < l; j++) { unsigned char c = buffer [i+j]; if (c < 32 || c > 127) c = '.'; printf ("%c", c); } } printf ("\n"); address += length; return address;}#endif//////static int monitorHelp (int argc __attribute__ ((unused)), portCHAR **argv __attribute__ ((unused))){ unsigned int i; int t; int longestCmd; portCHAR spaces [32]; memset (spaces, ' ', sizeof (spaces)); for (longestCmd = 0, i = 0; activeCommandList [i].command; i++) if ((t = strlen (activeCommandList [i].command)) > longestCmd) longestCmd = t; spaces [longestCmd] = '\0'; for (i = 0; activeCommandList [i].command; i++) { const commandList_t *cl = &activeCommandList [i]; printf ("%s%s -- %s\n", cl->command, &spaces [strlen (cl->command)], cl->description); } printf ("\nUse '<command> ?' for details on parameters to command\n"); return 0;}#ifdef CFG_MD//////static int monitorMd (int argc, portCHAR **argv){ static unsigned int address = 0x00000000; unsigned int length = 256; if ((argc >= 1)) { if (!getNumber (argv [0], &address)) return 0; if (argc == 2) if (!getNumber (argv [1], &length)) return 0; } address = monitorDumpMemory (address, 0xffffffff, address, length); return 0;}#endif#ifdef CFG_ABORT//////static int monitorAbortRegs (int argc __attribute__ ((unused)), portCHAR **argv __attribute__ ((unused))){ abortDat_t *ad = (abortDat_t *) &__abort_dat; printf ("contents=%s, sigil=0x%08x, count=%d\n", (ad->sigil == 0xdeadc0de) ? "probable" : "invalid", ad->sigil, ad->count); printf ("abort type=%s\n", (ad->type == 0) ? "undefined instruction" : (ad->type == 1) ? "prefetch abort" : (ad->type == 2) ? "data abort" : "unknown"); printf ("pc=0x%08x, opcode=0x%08x\n", ad->pc, ad->opcode); printf ("cpsr=0x%08x, sp=0x%08x, lr=0x%08x\n", ad->cpsr, ad->sp, ad->lr); printf ("r0=0x%08x, r1=0x%08x, r2=0x%08x, r3=0x%08x\n", ad->r0, ad->r1, ad->r2, ad->r3); printf ("r4=0x%08x, r5=0x%08x, r6=0x%08x, r7=0x%08x\n", ad->r4, ad->r5, ad->r6, ad->r7); printf ("r8=0x%08x, r9=0x%08x, r10=0x%08x, r11=0x%08x\n", ad->r8, ad->r9, ad->r10, ad->r11); printf ("r12=0x%08x\n", ad->r12); printf ("\n"); printf ("sp[0]=0x%08x, sp[1]=0x%08x, sp[2]=0x%08x, sp[3]=0x%08x\n", ad->stack [0], ad->stack [1], ad->stack [2], ad->stack [3]); printf ("sp[4]=0x%08x, sp[5]=0x%08x, sp[6]=0x%08x, sp[7]=0x%08x\n", ad->stack [4], ad->stack [5], ad->stack [6], ad->stack [7]); return 0;}static int monitorAbortClear (int argc __attribute__ ((unused)), portCHAR **argv __attribute__ ((unused))){ abortDat_t *ad = (abortDat_t *) &__abort_dat; memset (ad, 0, sizeof (* ad)); return 0;}static int monitorAbortDirty (int argc __attribute__ ((unused)), portCHAR **argv __attribute__ ((unused))){ abortDat_t *ad = (abortDat_t *) &__abort_dat; ad->sigil = 0; return 0;}static int monitorAbortUndef (int argc __attribute__ ((unused)), portCHAR **argv __attribute__ ((unused))){ asm volatile (" .word 0x06000010" : /* no output */ : /* no inputs */ ); return 0;}static int monitorAbortPabort (int argc __attribute__ ((unused)), portCHAR **argv __attribute__ ((unused))){ asm volatile (" ldr r0, =0x00080000" : /* no output */ : /* no inputs */ ); asm volatile (" mov pc, r0" : /* no output */ : /* no inputs */ ); return 0;}static int monitorAbortDabort (int argc __attribute__ ((unused)), portCHAR **argv __attribute__ ((unused))){ unsigned char c; volatile unsigned char *ptr = (unsigned char *) 0x40008000; c = *ptr; return 0;}#endif#ifdef CFG_BEEP//////static int monitorBeepOff (int argc __attribute__ ((unused)), portCHAR **argv __attribute__ ((unused))){ beepOff (); return 0;}static int monitorBeepOn (int argc __attribute__ ((unused)), portCHAR **argv){ int hz = atoi (argv [0]); if ((hz < 60) || (hz > 20000)) printf ("Frequency must be between 60 and 20000 Hertz\n"); else beepOn (hz); return 0;}static int monitorBeepMHALL (int argc __attribute__ ((unused)), portCHAR **argv __attribute__ ((unused))){ beepMHALL (); return 0;}static int monitorBeepSMOTW (int argc __attribute__ ((unused)), portCHAR **argv __attribute__ ((unused))){ beepSMOTW (); return 0;}#endif#ifdef CFG_AT24C1024//////static int monitorEEIAddr (int argc __attribute__ ((unused)), portCHAR **argv){ unsigned int address; if (!getNumber (argv [0], &address)) return 0; if (a24c1024SetAddress (address)) { printf ("Error: address out of range\n"); a24c1024SetAddress (0); } return 0;}static int monitorEEIRead (int argc, portCHAR **argv){ unsigned int address; unsigned int length = 256; unsigned char buffer [64]; unsigned int i; if (argc && !getNumber (argv [0], &length)) return 0; for (address = a24c1024GetAddress (), i = 0; i < length; i += sizeof (buffer), address = (address + sizeof (buffer)) % A24C1024_SIZE) { unsigned int l; if (!(l = i % sizeof (buffer))) l = MIN (length, sizeof (buffer)); if (a24c1024Read (buffer, l)) { printf ("a24c1024Read() returned error %d/%s\n", i2cGetErrno (), i2cStrerror (i2cGetErrno ())); return 0; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -