📄 monitor.c
字号:
monitorDumpMemory (address, A24C1024_SIZE - 1, (unsigned int) buffer, l); } return 0;}static int monitorEEIReadAddr (int argc, portCHAR **argv){ unsigned int address; if (!getNumber (argv [0], &address)) return 0; if (a24c1024SetAddress (address)) { printf ("Error: address out of range\n"); return 0; } return monitorEEIRead (--argc, ++argv);}static int monitorEEIWriteCommon (int argc, portCHAR **argv, unsigned char *buffer, int bufferLength){ int i; for (i = 0; i < argc; i++) { unsigned int n; if (i >= bufferLength) { printf ("Error: buffer too small for number of arguments\n"); return -1; } if (!getNumber (argv [i], &n)) return 0; if (n > 255) { printf ("Error: data must be 0x00..0xff (0..255)\n"); return -1; } buffer [i] = n; } return 0;}//// Note the two reserved bytes at the beginning of the buffer. These are// reserved for the address we're writing to in the EEPROM. They're populated// by the a24c1024Write() routine. This feel hackish, but unlike the read// routines, we can't send the address, then a repeated start bit to switch to// write.//static int monitorEEIWrite (int argc, portCHAR **argv){ unsigned char buffer [18]; if (monitorEEIWriteCommon (argc, argv, &buffer [2], sizeof (buffer) - 2)) return 0; if (((a24c1024GetAddress () + (argc - 1)) ^ a24c1024GetAddress ()) & A24C1024_PAGESIZE) printf ("Error: write would cross a %d page boundary\n", A24C1024_PAGESIZE); else if (a24c1024Write (buffer, argc)) printf ("a24c1024Write() returned %d/%s\n", i2cGetErrno (), i2cStrerror (i2cGetErrno ())); return 0;}static int monitorEEIWriteAddr (int argc, portCHAR **argv){ unsigned int address; if (!getNumber (argv [0], &address)) return 0; if (a24c1024SetAddress (address)) { printf ("Error: address out of range\n"); return 0; } return monitorEEIWrite (--argc, ++argv);}static int monitorEEIFillAddr (int argc __attribute__ ((unused)), portCHAR **argv){ unsigned int address; unsigned int length; unsigned int fillChar; if (!getNumber (argv [0], &address) || !getNumber (argv [1], &length) || !getNumber (argv [2], &fillChar)) return 0; if (fillChar > 255) printf ("Error: fill value must be 0x00..0xff (0..255)\n"); else if (a24c1024FillAddress (address, length, fillChar)) printf ("a24c1024FillAddress() returned error %d/%s\n", i2cGetErrno (), i2cStrerror (i2cGetErrno ())); return 0;}#endif#ifdef CFG_M25LC512//// Why, yes, some of this code *is* nearly identical to the 'eei' commands...//static int m25lc512WriteGate = FALSE;static int monitorEESuIPCheck (void){#ifdef CFG_UIP if (uipIsRunning ()) { printf ("Can't use 'ees' commands while uIP is running\n"); return 1; }#endif return 0;}static m25lc_e monitorEESWriteGate (void){ if (m25lc512WriteGate) { m25lc_e r; if ((r = m25lc512WriteEnable ()) != M25LC_OK) printf ("m25lc512WriteEnable() returned error %d/%s\n", r, m25lc512Strerror (r)); return r; } printf ("Write has not enabled with 'ees wren'\n"); return M25LC_WP;}static int monitorEESAddr (int argc __attribute__ ((unused)), portCHAR **argv){ unsigned int address; m25lc_e r; if (monitorEESuIPCheck ()) return 0; if (!getNumber (argv [0], &address)) return 0; if ((r = m25lc512SetAddress (address)) != M25LC_OK) { printf ("m25lc512SetAddress() returned error %d/%s\n", r, m25lc512Strerror (r)); m25lc512SetAddress (0); } return 0;}static int monitorEESRead (int argc, portCHAR **argv){ unsigned int address; unsigned int length = 256; unsigned char buffer [64]; unsigned int i; m25lc_e r; if (monitorEESuIPCheck ()) return 0; if (argc && !getNumber (argv [0], &length)) return 0; for (address = m25lc512GetAddress (), i = 0; i < length; i += sizeof (buffer), address = (address + sizeof (buffer)) % M25LC512_SIZE) { unsigned int l; if (!(l = i % sizeof (buffer))) l = MIN (length, sizeof (buffer)); if ((r = m25lc512Read (buffer, l)) != M25LC_OK) { printf ("m25lc512Read() returned error %d/%s\n", r, m25lc512Strerror (r)); return 0; } monitorDumpMemory (address, M25LC512_SIZE - 1, (unsigned int) buffer, l); } return 0;}static int monitorEESReadAddr (int argc, portCHAR **argv){ unsigned int address; m25lc_e r; if (monitorEESuIPCheck ()) return 0; if (!getNumber (argv [0], &address)) return 0; if ((r = m25lc512SetAddress (address)) != M25LC_OK) { printf ("m25lc512SetAddress() returned error %d/%s\n", r, m25lc512Strerror (r)); return 0; } return monitorEESRead (--argc, ++argv);}static int monitorEESWriteCommon (int argc, portCHAR **argv, unsigned char *buffer, int bufferLength){ int i; for (i = 0; i < argc; i++) { unsigned int n; if (i >= bufferLength) { printf ("Error: buffer too small for number of arguments\n"); return -1; } if (!getNumber (argv [i], &n)) return 0; if (n > 255) { printf ("Error: data must be 0x00..0xff (0..255)\n"); return -1; } buffer [i] = n; } return 0;}static int monitorEESWrite (int argc, portCHAR **argv){ unsigned char buffer [16]; m25lc_e r; if (monitorEESuIPCheck ()) return 0; if (monitorEESWriteCommon (argc, argv, buffer, sizeof (buffer))) return 0; if (monitorEESWriteGate () == M25LC_OK) { if (((m25lc512GetAddress () + (argc - 1)) ^ m25lc512GetAddress ()) & M25LC512_PAGESIZE) printf ("Error: write would cross a %d page boundary\n", M25LC512_PAGESIZE); else if ((r = m25lc512Write (buffer, argc)) != M25LC_OK) printf ("m25lc512Write() returned error %d/%s\n", r, m25lc512Strerror (r)); } return 0;}static int monitorEESWriteAddr (int argc, portCHAR **argv){ unsigned int address; m25lc_e r; if (monitorEESuIPCheck ()) return 0; if (!getNumber (argv [0], &address)) return 0; if ((r = m25lc512SetAddress (address)) != M25LC_OK) { printf ("m25lc512SetAddress() returned error %d/%s\n", r, m25lc512Strerror (r)); return 0; } return monitorEESWrite (--argc, ++argv);}static int monitorEESFillAddr (int argc __attribute__ ((unused)), portCHAR **argv){ unsigned int address; unsigned int length; unsigned int fillChar; m25lc_e r; if (monitorEESuIPCheck ()) return 0; if (!getNumber (argv [0], &address) || !getNumber (argv [1], &length) || !getNumber (argv [2], &fillChar)) return 0; if (fillChar > 255) printf ("Error: fill value must be 0x00..0xff (0..255)\n"); else if (monitorEESWriteGate () == M25LC_OK) if ((r = m25lc512FillAddress (address, length, fillChar)) != M25LC_OK) printf ("m25lc512FillAddress() returned error %d/%s\n", r, m25lc512Strerror (r)); return 0;}static int monitorEESEraseChip (int argc __attribute__ ((unused)), portCHAR **argv __attribute__ ((unused))){ m25lc_e r; if (monitorEESuIPCheck ()) return 0; if (monitorEESWriteGate () == M25LC_OK) if ((r = m25lc512EraseChip ()) != M25LC_OK) printf ("m25lc512EraseChip() returned error %d/%s\n", r, m25lc512Strerror (r)); return 0;}static int monitorEESEraseSector (int argc __attribute__ ((unused)), portCHAR **argv){ unsigned int sector; m25lc_e r; if (monitorEESuIPCheck ()) return 0; if (!getNumber (argv [0], §or)) return 0; if (monitorEESWriteGate () == M25LC_OK) { if ((r = m25lc512EraseSector (sector)) == M25LC_SECTORERR) printf ("Error: sector out of range, must be 0..0x%x (0..%d)\n", M25LC512_LASTSECTOR, M25LC512_LASTSECTOR); else if (r != M25LC_OK) printf ("m25lc512EraseSector() returned error %d/%s\n", r, m25lc512Strerror (r)); } return 0;}static int monitorEESErasePage (int argc __attribute__ ((unused)), portCHAR **argv){ unsigned int page; m25lc_e r; if (monitorEESuIPCheck ()) return 0; if (!getNumber (argv [0], &page)) return 0; if (monitorEESWriteGate () == M25LC_OK) { if ((r = m25lc512ErasePage (page)) == M25LC_PAGEERR) printf ("Error: page out of range, must be 0..0x%x (0..%d)\n", M25LC512_LASTPAGE, M25LC512_LASTPAGE); else if (r != M25LC_OK) printf ("m25lc512ErasePage() returned error %d/%s\n", r, m25lc512Strerror (r)); } return 0;}static int monitorEESWriteEnable (int argc __attribute__ ((unused)), portCHAR **argv __attribute__ ((unused))){ m25lc_e r; if (monitorEESuIPCheck ()) return 0; if ((r = m25lc512WriteEnable ()) != M25LC_OK) printf ("m25lc512WriteEnable() returned error %d/%s\n", r, m25lc512Strerror (r)); else m25lc512WriteGate = TRUE; return 0;}static int monitorEESWriteDisable (int argc __attribute__ ((unused)), portCHAR **argv __attribute__ ((unused))){ m25lc_e r; if (monitorEESuIPCheck ()) return 0; if ((r = m25lc512WriteDisable ()) != M25LC_OK)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -