Implemented EEPROM settings

This commit is contained in:
Mark Qvist 2014-06-19 10:36:16 +02:00
parent 7484883c1b
commit e6def21716
10 changed files with 3480 additions and 2924 deletions

View File

@ -95,6 +95,9 @@ static void init(void)
// ... and a protocol context with the modem
ax25_init(&ax25, &afsk.fd, message_callback);
// Init SimpleSerial
ss_init();
// That's all!
}

View File

@ -1,4 +1,7 @@
#include <string.h>
#include <avr/eeprom.h>
#define F_CPU 16000000UL
#include <util/delay.h>
#include "protocol/SimpleSerial.h"
bool PRINT_SRC = true;
@ -6,8 +9,9 @@ bool PRINT_DST = true;
bool PRINT_PATH = true;
bool PRINT_DATA = true;
bool PRINT_INFO = true;
bool VERBOSE = false;
bool VERBOSE = true;
bool SS_INIT = false;
bool SS_DEFAULT_CONF = false;
AX25Call src;
AX25Call dst;
@ -25,6 +29,99 @@ int PATH2_SSID = 2;
AX25Call path[4];
#define NV_MAGIC_BYTE 0x69
uint8_t EEMEM nvMagicByte;
uint8_t EEMEM nvCALL[6];
uint8_t EEMEM nvDST[6];
uint8_t EEMEM nvPATH1[6];
uint8_t EEMEM nvPATH2[6];
uint8_t EEMEM nvCALL_SSID;
uint8_t EEMEM nvDST_SSID;
uint8_t EEMEM nvPATH1_SSID;
uint8_t EEMEM nvPATH2_SSID;
bool EEMEM nvPRINT_SRC;
bool EEMEM nvPRINT_DST;
bool EEMEM nvPRINT_PATH;
bool EEMEM nvPRINT_DATA;
bool EEMEM nvPRINT_INFO;
bool EEMEM nvVERBOSE;
void ss_init(void) {
ss_loadSettings();
SS_INIT = true;
if (VERBOSE) {
_delay_ms(500);
kprintf("\n---------------\n");
kprintf("MicroAPRS v0.1a\n");
if (SS_DEFAULT_CONF) kprintf("Default configuration loaded!\n");
kprintf("Modem ready\n");
kprintf("---------------\n");
}
}
void ss_clearSettings(void) {
eeprom_update_byte((void*)&nvMagicByte, 0xFF);
if (VERBOSE) kprintf("Settings cleared\n");
}
void ss_loadSettings(void) {
uint8_t verification = eeprom_read_byte((void*)&nvMagicByte);
if (verification == NV_MAGIC_BYTE) {
eeprom_read_block((void*)CALL, (void*)nvCALL, 6);
eeprom_read_block((void*)DST, (void*)nvDST, 6);
eeprom_read_block((void*)PATH1, (void*)nvPATH1, 6);
eeprom_read_block((void*)PATH2, (void*)nvPATH2, 6);
CALL_SSID = eeprom_read_byte((void*)&nvCALL_SSID);
DST_SSID = eeprom_read_byte((void*)&nvDST_SSID);
PATH1_SSID = eeprom_read_byte((void*)&nvPATH1_SSID);
PATH2_SSID = eeprom_read_byte((void*)&nvPATH2_SSID);
PRINT_SRC = eeprom_read_byte((void*)&nvPRINT_SRC);
PRINT_DST = eeprom_read_byte((void*)&nvPRINT_DST);
PRINT_PATH = eeprom_read_byte((void*)&nvPRINT_PATH);
PRINT_DATA = eeprom_read_byte((void*)&nvPRINT_DATA);
PRINT_INFO = eeprom_read_byte((void*)&nvPRINT_INFO);
VERBOSE = eeprom_read_byte((void*)&nvVERBOSE);
if (VERBOSE && SS_INIT) kprintf("Settings loaded\n");
} else {
if (SS_INIT) kprintf("Error: No stored settings to load!\n");
SS_DEFAULT_CONF = true;
}
}
void ss_saveSettings(void) {
eeprom_update_block((void*)CALL, (void*)nvCALL, 6);
eeprom_update_block((void*)DST, (void*)nvDST, 6);
eeprom_update_block((void*)PATH1, (void*)nvPATH1, 6);
eeprom_update_block((void*)PATH2, (void*)nvPATH2, 6);
eeprom_update_byte((void*)&nvCALL_SSID, CALL_SSID);
eeprom_update_byte((void*)&nvDST_SSID, DST_SSID);
eeprom_update_byte((void*)&nvPATH1_SSID, PATH1_SSID);
eeprom_update_byte((void*)&nvPATH2_SSID, PATH2_SSID);
eeprom_update_byte((void*)&nvPRINT_SRC, PRINT_SRC);
eeprom_update_byte((void*)&nvPRINT_DST, PRINT_DST);
eeprom_update_byte((void*)&nvPRINT_PATH, PRINT_PATH);
eeprom_update_byte((void*)&nvPRINT_DATA, PRINT_DATA);
eeprom_update_byte((void*)&nvPRINT_INFO, PRINT_INFO);
eeprom_update_byte((void*)&nvVERBOSE, VERBOSE);
eeprom_update_byte((void*)&nvMagicByte, NV_MAGIC_BYTE);
if (VERBOSE) kprintf("Settings saved\n");
}
void ss_printSettings(void) {
kprintf("Configuration:\n");
kprintf("Callsign: %.6s-%d\n", CALL, CALL_SSID);
kprintf("Destination: %.6s-%d\n", DST, DST_SSID);
kprintf("Path1: %.6s-%d\n", PATH1, PATH1_SSID);
kprintf("Path2: %.6s-%d\n", PATH2, PATH2_SSID);
}
void ss_messageCallback(struct AX25Msg *msg, Serial *ser) {
if (PRINT_SRC) {
if (PRINT_INFO) kfile_print(&ser->fd, "SRC: ");
@ -49,16 +146,24 @@ void ss_messageCallback(struct AX25Msg *msg, Serial *ser) {
}
void ss_serialCallback(void *_buffer, size_t length, Serial *ser, AX25Ctx *ctx) {
if (VERBOSE) {
kfile_printf(&ser->fd, "Serial input");
}
uint8_t *buffer = (uint8_t *)_buffer;
if (length > 0) {
// ! as first char to send packet
if (buffer[0] == '!' && length > 1) {
buffer++; length--;
ss_sendMsg(buffer, length, ctx);
} else if (buffer[0] == 'h') {
ss_printSettings();
} else if (buffer[0] == 'j') {
ss_saveSettings();
} else if (buffer[0] == 'k') {
ss_clearSettings();
} else if (buffer[0] == 'l') {
ss_loadSettings();
} else if (buffer[0] == 'c' && length > 3) {
buffer++; length--;
int count = 0;
@ -67,10 +172,15 @@ void ss_serialCallback(void *_buffer, size_t length, Serial *ser, AX25Ctx *ctx)
if (c != 0 && c != 10 && c != 13) {
CALL[count] = c;
} else {
CALL[count] = 0;
CALL[count] = 0x00;
}
count++;
}
while (count < 6) {
CALL[count] = 0x00;
count++;
}
if (VERBOSE) kprintf("Callsign: %.6s-%d\n", CALL, CALL_SSID);
} else if (buffer[0] == 'd' && length > 3) {
buffer++; length--;
@ -84,6 +194,11 @@ void ss_serialCallback(void *_buffer, size_t length, Serial *ser, AX25Ctx *ctx)
}
count++;
}
while (count < 6) {
DST[count] = 0x00;
count++;
}
if (VERBOSE) kprintf("Destination: %.6s-%d\n", DST, DST_SSID);
} else if (buffer[0] == '1' && length > 1) {
@ -98,6 +213,11 @@ void ss_serialCallback(void *_buffer, size_t length, Serial *ser, AX25Ctx *ctx)
}
count++;
}
while (count < 6) {
PATH1[count] = 0x00;
count++;
}
if (VERBOSE) kprintf("Path1: %.6s-%d\n", PATH1, PATH1_SSID);
} else if (buffer[0] == '2' && length > 1) {
@ -112,14 +232,31 @@ void ss_serialCallback(void *_buffer, size_t length, Serial *ser, AX25Ctx *ctx)
}
count++;
}
while (count < 6) {
PATH2[count] = 0x00;
count++;
}
if (VERBOSE) kprintf("Path2: %.6s-%d\n", PATH2, PATH2_SSID);
} else if (buffer[0] == 's' && length > 2) {
buffer++; length--;
if (buffer[0] == 'c') CALL_SSID = buffer[1]-48;
if (buffer[0] == 'd') DST_SSID = buffer[1]-48;
if (buffer[0] == '1') PATH1_SSID = buffer[1]-48;
if (buffer[0] == '2') PATH2_SSID = buffer[1]-48;
if (buffer[0] == 'c') {
CALL_SSID = buffer[1]-48;
if (VERBOSE) kprintf("Callsign: %.6s-%d\n", CALL, CALL_SSID);
}
if (buffer[0] == 'd') {
DST_SSID = buffer[1]-48;
if (VERBOSE) kprintf("Destination: %.6s-%d\n", DST, DST_SSID);
}
if (buffer[0] == '1') {
PATH1_SSID = buffer[1]-48;
if (VERBOSE) kprintf("Path1: %.6s-%d\n", PATH1, PATH1_SSID);
}
if (buffer[0] == '2') {
PATH2_SSID = buffer[1]-48;
if (VERBOSE) kprintf("Path2: %.6s-%d\n", PATH2, PATH2_SSID);
}
} else if (buffer[0] == 'p' && length > 2) {
buffer++; length--;
@ -138,7 +275,14 @@ void ss_serialCallback(void *_buffer, size_t length, Serial *ser, AX25Ctx *ctx)
if (buffer[0] == 'i') {
if (buffer[1] == 49) { PRINT_INFO = true; } else { PRINT_INFO = false; }
}
} else if (buffer[0] == 'v') {
if (buffer[1] == 49) {
VERBOSE = true;
kfile_printf(&ser->fd, "Verbose mode enabled\n");
} else {
VERBOSE = false;
kfile_printf(&ser->fd, "Verbose mode disabled\n");
}
}
}

View File

@ -7,6 +7,8 @@
#define DEFAULT_CALLSIGN "NOCALL"
#define DEFAULT_DESTINATION_CALL "APZMDM"
void ss_init(void);
void ss_messageCallback(struct AX25Msg *msg, Serial *ser);
void ss_serialCallback(void *_buffer, size_t length, Serial *ser, AX25Ctx *ctx);
void ss_printSrc(bool val);
@ -17,4 +19,9 @@ void ss_printInfo(bool val);
void ss_sendMsg(void *_buffer, size_t length, AX25Ctx *ax25);
void ss_clearSettings(void);
void ss_loadSettings(void);
void ss_saveSettings(void);
void ss_printSettings(void);
#endif

View File

@ -316,7 +316,7 @@ fuses_$(1):
fi
$$(OUTDIR)/$(1).hex: $$(OUTDIR)/$(1).elf
$$($(1)_OBJCOPY) -O ihex $$< $$@
$$($(1)_OBJCOPY) -R .eeprom -O ihex $$< $$@
$$(OUTDIR)/$(1).s19: $$(OUTDIR)/$(1).elf
$$($(1)_OBJCOPY) -O srec $$< $$@

View File

@ -1,2 +1,2 @@
#define VERS_BUILD 1937
#define VERS_BUILD 1993
#define VERS_HOST "shard"

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff