Compare commits
No commits in common. "1e644b9a5e7580a9991aca16f118babe1863eaaf" and "3a07b3ab6f43877f689c2e29ea248e9872f9d30e" have entirely different histories.
1e644b9a5e
...
3a07b3ab6f
|
|
@ -1,12 +1,11 @@
|
||||||
|
#include "config.h"
|
||||||
#include "commands.h"
|
#include "commands.h"
|
||||||
#include "common.h"
|
|
||||||
#include "parsing.h"
|
#include "parsing.h"
|
||||||
#include "uart.h"
|
#include "uart.h"
|
||||||
#include "eeprom.h"
|
#include "eeprom.h"
|
||||||
|
|
||||||
#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>
|
||||||
|
|
||||||
|
|
@ -58,33 +57,8 @@ void commandRead(char* arg) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
uartPutString("OK\n");
|
// TODO read data and output it
|
||||||
|
uartPutString("ERR not implemented\n");
|
||||||
uint8_t byteBuffer[DATA_BLOCK_SIZE];
|
|
||||||
DataBuffer buffer = {
|
|
||||||
.data = byteBuffer,
|
|
||||||
.maxSize = DATA_BLOCK_SIZE,
|
|
||||||
.bytes = 0
|
|
||||||
};
|
|
||||||
|
|
||||||
do {
|
|
||||||
// Read a single block with up to DATA_BLOCK_SIZE bytes
|
|
||||||
range.from = eepromReadBlock(range, &buffer);
|
|
||||||
|
|
||||||
// TODO binary output
|
|
||||||
|
|
||||||
// ASCII output
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
uartPutChar('\n');
|
|
||||||
} while (buffer.bytes > 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void commandWrite(char* arg) {
|
void commandWrite(char* arg) {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef COMMANDS_H_
|
#ifndef COMMANDS_H_
|
||||||
#define COMMANDS_H_
|
#define COMMANDS_H_
|
||||||
|
|
||||||
#include "common.h"
|
#include "config.h"
|
||||||
#include "parsing.h"
|
#include "parsing.h"
|
||||||
|
|
||||||
void executeCommand(CommandLine cmdLine);
|
void executeCommand(CommandLine cmdLine);
|
||||||
|
|
|
||||||
|
|
@ -1,33 +0,0 @@
|
||||||
#ifndef COMMON_H_
|
|
||||||
#define COMMON_H_
|
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
#include <avr/io.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
|
|
||||||
// Define macro for NOP instruction
|
|
||||||
#define _NOP() __asm__ __volatile__ ("nop");
|
|
||||||
|
|
||||||
// Define type for EEPROM addresses
|
|
||||||
typedef uint16_t address_t;
|
|
||||||
|
|
||||||
// Define highest valid address for the EEPROM
|
|
||||||
#define HIGHEST_VALID_ADDRESS 0x7fff
|
|
||||||
|
|
||||||
// Type definition for address ranges (from-to)
|
|
||||||
typedef struct {
|
|
||||||
bool isValid;
|
|
||||||
address_t from;
|
|
||||||
address_t to;
|
|
||||||
} AddressRange;
|
|
||||||
|
|
||||||
// Define type for a block of data (bytes)
|
|
||||||
typedef struct {
|
|
||||||
uint8_t* data;
|
|
||||||
uint8_t maxSize;
|
|
||||||
uint8_t bytes;
|
|
||||||
} DataBuffer;
|
|
||||||
|
|
||||||
#define DATA_BLOCK_SIZE 64
|
|
||||||
|
|
||||||
#endif /* COMMON_H_ */
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
#include "config.h"
|
||||||
#include "eeprom.h"
|
#include "eeprom.h"
|
||||||
|
|
||||||
#include <avr/io.h>
|
#include <avr/io.h>
|
||||||
|
|
@ -113,37 +114,3 @@ void eepromWriteByte(address_t address, uint8_t data) {
|
||||||
// Write pulse width high (50ns)
|
// Write pulse width high (50ns)
|
||||||
_NOP();
|
_NOP();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read multiple bytes from EEPROM into a buffer
|
|
||||||
address_t eepromReadBlock(AddressRange addressRange, DataBuffer* buffer) {
|
|
||||||
// Set read mode
|
|
||||||
eepromSetReadMode();
|
|
||||||
|
|
||||||
buffer->bytes = 0;
|
|
||||||
|
|
||||||
address_t currentAddress = addressRange.from;
|
|
||||||
address_t highestAddress = addressRange.to;
|
|
||||||
|
|
||||||
if (highestAddress > HIGHEST_VALID_ADDRESS) {
|
|
||||||
highestAddress = HIGHEST_VALID_ADDRESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (currentAddress <= highestAddress && buffer->bytes < buffer->maxSize) {
|
|
||||||
buffer->data[buffer->bytes++] = eepromReadByte(currentAddress++);
|
|
||||||
}
|
|
||||||
|
|
||||||
return currentAddress;
|
|
||||||
}
|
|
||||||
|
|
||||||
// // Write multiple bytes from a buffer to EEPROM
|
|
||||||
// address_t eepromWriteBlock(address_t currentAddress, DataBuffer buffer) {
|
|
||||||
// // Set write mode
|
|
||||||
// eepromSetWriteMode();
|
|
||||||
|
|
||||||
// for (uint8_t i = 0; currentAddress <= HIGHEST_VALID_ADDRESS && i < buffer.bytes; i++) {
|
|
||||||
// eepromWriteByte(currentAddress++, buffer.data[i]);
|
|
||||||
// // TODO address overflow
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return currentAddress;
|
|
||||||
// }
|
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,14 @@
|
||||||
#define EEPROM_H_
|
#define EEPROM_H_
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "common.h"
|
|
||||||
#include <avr/io.h>
|
#include <avr/io.h>
|
||||||
|
|
||||||
|
// Define macro for NOP instruction
|
||||||
|
#define _NOP() __asm__ __volatile__ ("nop");
|
||||||
|
|
||||||
|
// Define type for (to be shifted) addresses
|
||||||
|
typedef uint16_t address_t;
|
||||||
|
|
||||||
// Define address length
|
// Define address length
|
||||||
// TODO 15 or 16?
|
// TODO 15 or 16?
|
||||||
#define ADDRESS_LENGTH 15
|
#define ADDRESS_LENGTH 15
|
||||||
|
|
@ -40,10 +45,4 @@ uint8_t eepromReadByte(address_t address);
|
||||||
// Write byte (assumes we're in write mode)
|
// Write byte (assumes we're in write mode)
|
||||||
void eepromWriteByte(address_t address, uint8_t data);
|
void eepromWriteByte(address_t address, uint8_t data);
|
||||||
|
|
||||||
// Read multiple bytes from EEPROM into a buffer
|
|
||||||
address_t eepromReadBlock(AddressRange addressRange, DataBuffer* buffer);
|
|
||||||
|
|
||||||
// // Write multiple bytes from a buffer to EEPROM
|
|
||||||
// address_t eepromWriteBlock(address_t addressRange, DataBuffer buffer);
|
|
||||||
|
|
||||||
#endif /* EEPROM_H_ */
|
#endif /* EEPROM_H_ */
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "common.h"
|
|
||||||
#include "uart.h"
|
#include "uart.h"
|
||||||
#include "eeprom.h"
|
#include "eeprom.h"
|
||||||
#include "parsing.h"
|
#include "parsing.h"
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
#ifndef PARSING_H_
|
#ifndef PARSING_H_
|
||||||
#define PARSING_H_
|
#define PARSING_H_
|
||||||
|
|
||||||
#include "common.h"
|
#include "config.h"
|
||||||
|
#include "eeprom.h"
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
// Type definition for a command line with optional argument (actually just two pointers to strings)
|
// Type definition for a command line with optional argument (actually just two pointers to strings)
|
||||||
|
|
@ -10,6 +11,13 @@ typedef struct {
|
||||||
char* arg;
|
char* arg;
|
||||||
} CommandLine;
|
} CommandLine;
|
||||||
|
|
||||||
|
// Type definition for address ranges (from-to)
|
||||||
|
typedef struct {
|
||||||
|
bool isValid;
|
||||||
|
address_t from;
|
||||||
|
address_t to;
|
||||||
|
} AddressRange;
|
||||||
|
|
||||||
void parseNextCommand();
|
void parseNextCommand();
|
||||||
CommandLine readNextCommand(char* buffer, uint8_t bufferLength);
|
CommandLine readNextCommand(char* buffer, uint8_t bufferLength);
|
||||||
CommandLine tokenizeCommand(char* cmd);
|
CommandLine tokenizeCommand(char* cmd);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue