Basic SD card functions

This commit is contained in:
Mark Qvist 2019-01-27 20:25:11 +01:00
parent 6258e1e62e
commit 23b6de25fb
16 changed files with 6133 additions and 155 deletions

31
main.c
View file

@ -1,16 +1,29 @@
#include <stdbool.h>
#include <avr/io.h>
#include <avr/wdt.h>
#include <string.h>
#include <stdlib.h>
#include "device.h"
#include "hardware/VREF.h"
#include "hardware/AFSK.h"
#include "hardware/Serial.h"
#include "hardware/LED.h"
#include "hardware/SD.h"
#include "protocol/AX25.h"
#include "protocol/KISS.h"
#include "util/time.h"
#include "util/FIFO.h"
uint8_t boot_vector = 0x00;
uint8_t OPTIBOOT_MCUSR __attribute__ ((section(".noinit")));
void resetFlagsInit(void) __attribute__ ((naked)) __attribute__ ((used)) __attribute__ ((section (".init0")));
void resetFlagsInit(void) {
__asm__ __volatile__ ("sts %0, r2\n" : "=m" (OPTIBOOT_MCUSR) :);
}
Serial serial;
Afsk modem;
AX25Ctx AX25;
@ -20,7 +33,21 @@ static void ax25_callback(struct AX25Ctx *ctx) {
}
void system_check(void) {
// TODO: Implement this
if (OPTIBOOT_MCUSR & (1<<PORF)) {
boot_vector = START_FROM_POWERON;
} else if (OPTIBOOT_MCUSR & (1<<BORF)) {
boot_vector = START_FROM_BROWNOUT;
} else if (OPTIBOOT_MCUSR & (1<<WDRF)) {
boot_vector = START_FROM_BOOTLOADER;
} else {
printf("Error, indeterminate boot vector %d\r\n", OPTIBOOT_MCUSR);
printf("System start has been halted\r\n");
while (true) {
LED_TX_ON();
LED_COM_ON();
}
}
LED_STATUS_ON();
}
@ -36,8 +63,10 @@ void init(void) {
AFSK_init(&modem);
ax25_init(&AX25, &modem, &modem.fd, ax25_callback);
kiss_init(&AX25, &modem, &serial);
sd_init();
system_check();
sd_test();
}