Compare commits
2 Commits
67beda0dbd
...
9e0ffd394b
| Author | SHA1 | Date |
|---|---|---|
|
|
9e0ffd394b | |
|
|
5d5e452136 |
|
|
@ -6,13 +6,9 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <util/delay.h>
|
#include <util/delay.h>
|
||||||
|
|
||||||
// Internal function prototypes
|
|
||||||
void _uartPutAsciiBlock(DataBuffer buffer);
|
|
||||||
|
|
||||||
// Mode: ASCII (false) or binary (true)
|
// Mode: ASCII (false) or binary (true)
|
||||||
bool binary_mode = false;
|
bool binary_mode = false;
|
||||||
|
|
||||||
|
|
@ -23,6 +19,10 @@ void executeCommand(CommandLine cmdLine) {
|
||||||
// INIT command: Initializes connection.
|
// INIT command: Initializes connection.
|
||||||
commandInit(cmdLine.arg);
|
commandInit(cmdLine.arg);
|
||||||
}
|
}
|
||||||
|
else if (strcmp(cmdLine.command, "HELP") == 0) {
|
||||||
|
// HELP command: Print a list of supported commands.
|
||||||
|
commandHelp(cmdLine.arg);
|
||||||
|
}
|
||||||
else if (strcmp(cmdLine.command, "READ") == 0) {
|
else if (strcmp(cmdLine.command, "READ") == 0) {
|
||||||
// READ command: Takes a hex address range (or single address) as argument,
|
// READ command: Takes a hex address range (or single address) as argument,
|
||||||
// reads data and returns it in hexadecimal ASCII format.
|
// reads data and returns it in hexadecimal ASCII format.
|
||||||
|
|
@ -32,6 +32,10 @@ void executeCommand(CommandLine cmdLine) {
|
||||||
// WRITE command: Takes a hex address as argument, reads data from UART and writes it to the EEPROM.
|
// WRITE command: Takes a hex address as argument, reads data from UART and writes it to the EEPROM.
|
||||||
commandRead(cmdLine.arg);
|
commandRead(cmdLine.arg);
|
||||||
}
|
}
|
||||||
|
else if (strcmp(cmdLine.command, "ERASE") == 0) {
|
||||||
|
// ERASE command: Takes a hex address range as argument and writes 0x00 bytes to the specified range.
|
||||||
|
commandRead(cmdLine.arg);
|
||||||
|
}
|
||||||
else if (strcmp(cmdLine.command, "TESTREAD") == 0) {
|
else if (strcmp(cmdLine.command, "TESTREAD") == 0) {
|
||||||
// TESTREAD command: for testing purposes, reads a few bytes and returns them in a human readable format.
|
// TESTREAD command: for testing purposes, reads a few bytes and returns them in a human readable format.
|
||||||
commandTestRead();
|
commandTestRead();
|
||||||
|
|
@ -68,6 +72,21 @@ void commandInit(char* arg) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void commandHelp() {
|
||||||
|
uartPutLine("HELP - Supported commands:");
|
||||||
|
uartPutLine("HELP - HELP");
|
||||||
|
uartPutLine("HELP - INIT [BINARY|ASCII]");
|
||||||
|
uartPutLine("HELP - READ 0000:0FFF");
|
||||||
|
uartPutLine("HELP - WRITE 0000");
|
||||||
|
uartPutLine("HELP - ERASE 0000:0FFF");
|
||||||
|
|
||||||
|
// TODO remove those
|
||||||
|
uartPutLine("HELP - TESTREAD (only for testing)");
|
||||||
|
uartPutLine("HELP - TESTWRITE (only for testing)");
|
||||||
|
|
||||||
|
uartPutLine("OK");
|
||||||
|
}
|
||||||
|
|
||||||
void commandRead(char* arg) {
|
void commandRead(char* arg) {
|
||||||
if (arg == NULL) {
|
if (arg == NULL) {
|
||||||
uartPutLine("ERR READ needs an address or address range");
|
uartPutLine("ERR READ needs an address or address range");
|
||||||
|
|
@ -104,25 +123,17 @@ void commandRead(char* arg) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Fancy ASCII output
|
// Fancy ASCII output
|
||||||
_uartPutAsciiBlock(buffer);
|
uartPrintf("<%d>", buffer.bytes);
|
||||||
|
|
||||||
|
for (int i = 0; i < buffer.bytes; i++) {
|
||||||
|
uartPrintf(" %02X", buffer.data[i]);
|
||||||
|
}
|
||||||
|
uartPutLine(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
} while (buffer.bytes > 0);
|
} while (buffer.bytes > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _uartPutAsciiBlock(DataBuffer buffer) {
|
|
||||||
char outBuffer[20];
|
|
||||||
sprintf(outBuffer, "<%d>", buffer.bytes);
|
|
||||||
uartPutString(outBuffer);
|
|
||||||
|
|
||||||
for (int i = 0; i < buffer.bytes; i++) {
|
|
||||||
sprintf(outBuffer, " %02X", buffer.data[i]);
|
|
||||||
uartPutString(outBuffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
uartPutLine(NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
void commandWrite(char* arg) {
|
void commandWrite(char* arg) {
|
||||||
if (arg == NULL) {
|
if (arg == NULL) {
|
||||||
uartPutLine("ERR WRITE needs a start address");
|
uartPutLine("ERR WRITE needs a start address");
|
||||||
|
|
@ -153,26 +164,20 @@ void commandErase() {
|
||||||
|
|
||||||
// TESTREAD command: for testing purposes, reads a few bytes and returns them in a human readable format.
|
// TESTREAD command: for testing purposes, reads a few bytes and returns them in a human readable format.
|
||||||
void commandTestRead() {
|
void commandTestRead() {
|
||||||
uint8_t byte;
|
|
||||||
char outBuffer[20];
|
|
||||||
|
|
||||||
eepromSetReadMode();
|
eepromSetReadMode();
|
||||||
|
|
||||||
for (int i = 0x00; i < 0x20; i++) {
|
for (int i = 0x00; i < 0x20; i++) {
|
||||||
itoa(i, outBuffer, 16);
|
uartPrintf("TESTREAD 0x%02X: ", i);
|
||||||
uartPutString("TESTREAD 0x");
|
|
||||||
uartPutString(outBuffer);
|
|
||||||
uartPutString(": ");
|
|
||||||
|
|
||||||
byte = eepromReadByte(i);
|
uint8_t byte = eepromReadByte(i);
|
||||||
itoa(byte, outBuffer, 16);
|
|
||||||
|
|
||||||
uartPutChar(byte);
|
if (byte >= 32 && byte <= 126) {
|
||||||
uartPutString(" (0x");
|
uartPutChar(byte);
|
||||||
uartPutString(outBuffer);
|
} else {
|
||||||
uartPutString(")");
|
uartPutChar('?');
|
||||||
|
}
|
||||||
|
|
||||||
uartPutLine(NULL);
|
uartPrintf(" (0x%02X)\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,8 @@
|
||||||
|
|
||||||
void executeCommand(CommandLine cmdLine);
|
void executeCommand(CommandLine cmdLine);
|
||||||
|
|
||||||
void commandInit();
|
void commandHelp();
|
||||||
|
void commandInit(char* arg);
|
||||||
void commandRead(char* arg);
|
void commandRead(char* arg);
|
||||||
void commandWrite(char* arg);
|
void commandWrite(char* arg);
|
||||||
void commandErase();
|
void commandErase();
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ int main(void) {
|
||||||
_delay_ms(100);
|
_delay_ms(100);
|
||||||
|
|
||||||
// Write initial message via UART
|
// Write initial message via UART
|
||||||
uartPutLine("INFO -- EEPROM programmer by binaryDiv");
|
uartPutLine("INFO - EEPROM programmer by binaryDiv");
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
// Run main loop endlessly
|
// Run main loop endlessly
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@
|
||||||
#include "uart.h"
|
#include "uart.h"
|
||||||
|
|
||||||
#include <avr/io.h>
|
#include <avr/io.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <util/setbaud.h>
|
#include <util/setbaud.h>
|
||||||
|
|
||||||
// Initialize UART
|
// Initialize UART
|
||||||
|
|
@ -54,6 +56,19 @@ void uartPutLine(char* data) {
|
||||||
uartPutChar('\n');
|
uartPutChar('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Transmit a sprintf formatted string (maximum buffer: 256 bytes!)
|
||||||
|
void uartPrintf(const char* format, ...) {
|
||||||
|
char outBuffer[256];
|
||||||
|
|
||||||
|
va_list args;
|
||||||
|
va_start(args, format);
|
||||||
|
|
||||||
|
vsprintf(outBuffer, format, args);
|
||||||
|
uartPutString(outBuffer);
|
||||||
|
|
||||||
|
va_end(args);
|
||||||
|
}
|
||||||
|
|
||||||
// Receive a single character (blocking)
|
// Receive a single character (blocking)
|
||||||
unsigned char uartGetChar() {
|
unsigned char uartGetChar() {
|
||||||
// Block until a character has been received
|
// Block until a character has been received
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,9 @@ void uartPutString(char* data);
|
||||||
// Transmit a string followed by a line break
|
// Transmit a string followed by a line break
|
||||||
void uartPutLine(char* data);
|
void uartPutLine(char* data);
|
||||||
|
|
||||||
|
// Transmit a sprintf formatted string (maximum buffer: 256 bytes!)
|
||||||
|
void uartPrintf(const char* format, ...);
|
||||||
|
|
||||||
// Read a single character (blocking)
|
// Read a single character (blocking)
|
||||||
unsigned char uartGetChar();
|
unsigned char uartGetChar();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue