//========================================================================= // MAIN PROGRAM //========================================================================= int main (int argc, char *argv[]) { Aardvark handle; int port = 0; int bitrate = 100; u08 device; u08 addr; u16 length; int bus_timeout; const char *command; if (argc < 7) { printf("usage: aai2c_eeprom PORT BITRATE read SLAVE_ADDR OFFSET LENGTH\n"); printf("usage: aai2c_eeprom PORT BITRATE write SLAVE_ADDR OFFSET LENGTH\n"); printf("usage: aai2c_eeprom PORT BITRATE zero SLAVE_ADDR OFFSET LENGTH\n"); return 1; } port = atoi(argv[1]); bitrate = atoi(argv[2]); command = argv[3]; device = (u08)strtol(argv[4], 0, 0); addr = (u08)strtol(argv[5], 0, 0); length = atoi(argv[6]); // Open the device handle = aa_open(port); if (handle <= 0) { printf("Unable to open Aardvark device on port %d\n", port); printf("Error code = %d\n", handle); return 1; } // Ensure that the I2C subsystem is enabled aa_configure(handle, AA_CONFIG_SPI_I2C); // Enable the I2C bus pullup resistors (2.2k resistors). // This command is only effective on v2.0 hardware or greater. // The pullup resistors on the v1.02 hardware are enabled by default. aa_i2c_pullup(handle, AA_I2C_PULLUP_BOTH); // Power the EEPROM using the Aardvark adapter's power supply. // This command is only effective on v2.0 hardware or greater. // The power pins on the v1.02 hardware are not enabled by default. aa_target_power(handle, AA_TARGET_POWER_BOTH); // Set the bitrate bitrate = aa_i2c_bitrate(handle, bitrate); printf("Bitrate set to %d kHz\n", bitrate); // Set the bus lock timeout bus_timeout = aa_i2c_bus_timeout(handle, BUS_TIMEOUT); printf("Bus lock timeout set to %d ms\n", bus_timeout); // Perform the operation if (strcmp(command, "write") == 0) { _writeMemory(handle, device, addr, length, 0); printf("Wrote to EEPROM\n"); } else if (strcmp(command, "read") == 0) { _readMemory(handle, device, addr, length); } else if (strcmp(command, "zero") == 0) { _writeMemory(handle, device, addr, length, 1); printf("Zeroed EEPROM\n"); } else { printf("unknown command: %s\n", command); } // Close the device and exit aa_close(handle); return 0; }
size_t _parseGDBMessage(struct GDBStub* stub, const char* message) { uint8_t checksum = 0; int parsed = 1; switch (*message) { case '+': stub->lineAck = GDB_ACK_RECEIVED; return parsed; case '-': stub->lineAck = GDB_NAK_RECEIVED; return parsed; case '$': ++message; break; case '\x03': mDebuggerEnter(&stub->d, DEBUGGER_ENTER_MANUAL, 0); return parsed; default: _nak(stub); return parsed; } int i; char messageType = message[0]; for (i = 0; message[i] != '#'; ++i, ++parsed) { checksum += message[i]; } if (!message[i]) { _nak(stub); return parsed; } ++i; ++parsed; if (!message[i]) { _nak(stub); return parsed; } else if (!message[i + 1]) { ++parsed; _nak(stub); return parsed; } parsed += 2; int networkChecksum = _hex2int(&message[i], 2); if (networkChecksum != checksum) { mLOG(DEBUGGER, WARN, "Checksum error: expected %02x, got %02x", checksum, networkChecksum); _nak(stub); return parsed; } _ack(stub); ++message; switch (messageType) { case '?': snprintf(stub->outgoing, GDB_STUB_MAX_LINE - 4, "S%02x", SIGINT); _sendMessage(stub); break; case 'c': _continue(stub, message); break; case 'G': _writeGPRs(stub, message); break; case 'g': _readGPRs(stub, message); break; case 'H': // This is faked because we only have one thread strncpy(stub->outgoing, "OK", GDB_STUB_MAX_LINE - 4); _sendMessage(stub); break; case 'M': _writeMemory(stub, message); break; case 'm': _readMemory(stub, message); break; case 'P': _writeRegister(stub, message); break; case 'p': _readRegister(stub, message); break; case 'Q': _processQWriteCommand(stub, message); break; case 'q': _processQReadCommand(stub, message); break; case 's': _step(stub, message); break; case 'V': _processVWriteCommand(stub, message); break; case 'v': _processVReadCommand(stub, message); break; case 'X': _writeMemoryBinary(stub, message); break; case 'Z': _setBreakpoint(stub, message); break; case 'z': _clearBreakpoint(stub, message); break; default: _error(stub, GDB_UNSUPPORTED_COMMAND); break; } return parsed; }