untested persistence
This commit is contained in:
parent
8001b5edc5
commit
467f4606fb
|
@ -133,6 +133,7 @@ CSRC = $(ALLCSRC) \
|
||||||
CPPSRC = $(ALLCPPSRC) \
|
CPPSRC = $(ALLCPPSRC) \
|
||||||
uart.cpp \
|
uart.cpp \
|
||||||
mc33816_control.cpp \
|
mc33816_control.cpp \
|
||||||
|
persistence.cpp \
|
||||||
can.cpp \
|
can.cpp \
|
||||||
fault.cpp \
|
fault.cpp \
|
||||||
main.cpp
|
main.cpp
|
||||||
|
|
|
@ -1,11 +1,16 @@
|
||||||
#include "can.h"
|
#include "can.h"
|
||||||
#include "hal.h"
|
#include "hal.h"
|
||||||
|
|
||||||
#include "fault.h"
|
|
||||||
#include "io_pins.h"
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
|
#include "fault.h"
|
||||||
|
#include "io_pins.h"
|
||||||
|
#include "persistence.h"
|
||||||
|
|
||||||
|
|
||||||
|
int flashVersion;
|
||||||
|
|
||||||
static const CANConfig canConfig500 =
|
static const CANConfig canConfig500 =
|
||||||
{
|
{
|
||||||
CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP,
|
CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP,
|
||||||
|
@ -25,6 +30,7 @@ void SendSomething()
|
||||||
m_frame.RTR = CAN_RTR_DATA;
|
m_frame.RTR = CAN_RTR_DATA;
|
||||||
m_frame.DLC = 8;
|
m_frame.DLC = 8;
|
||||||
memset(m_frame.data8, 0, sizeof(m_frame.data8));
|
memset(m_frame.data8, 0, sizeof(m_frame.data8));
|
||||||
|
m_frame.data8[2] = flashVersion;
|
||||||
m_frame.data8[3] = 0x33;
|
m_frame.data8[3] = 0x33;
|
||||||
m_frame.data8[6] = 0x66;
|
m_frame.data8[6] = 0x66;
|
||||||
|
|
||||||
|
@ -50,6 +56,27 @@ void CanRxThread(void*)
|
||||||
{
|
{
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
|
CANRxFrame frame;
|
||||||
|
msg_t msg = canReceiveTimeout(&CAND1, CAN_ANY_MAILBOX, &frame, TIME_INFINITE);
|
||||||
|
|
||||||
|
// Ignore non-ok results...
|
||||||
|
if (msg != MSG_OK)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ignore std frames, only listen to ext
|
||||||
|
if (frame.IDE != CAN_IDE_EXT)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (frame.EID == 0x200) {
|
||||||
|
flashVersion = IncAndGet();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
chThdSleepMilliseconds(100);
|
chThdSleepMilliseconds(100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,24 +5,13 @@
|
||||||
#include "fault.h"
|
#include "fault.h"
|
||||||
#include "uart.h"
|
#include "uart.h"
|
||||||
#include "io_pins.h"
|
#include "io_pins.h"
|
||||||
|
#include "persistence.h"
|
||||||
#include "hal_mfs.h"
|
|
||||||
|
|
||||||
#include "mc33816_control.h"
|
#include "mc33816_control.h"
|
||||||
#include "mc33816_data.h"
|
#include "mc33816_data.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
const MFSConfig mfscfg1 = {
|
|
||||||
.flashp = (BaseFlash *)&EFLD1,
|
|
||||||
.erased = 0xFFFFFFFFU,
|
|
||||||
.bank_size = 1024U,
|
|
||||||
.bank0_start = 126U,
|
|
||||||
.bank0_sectors = 1U,
|
|
||||||
.bank1_start = 127U,
|
|
||||||
.bank1_sectors = 1U
|
|
||||||
};
|
|
||||||
|
|
||||||
static void InitPins() {
|
static void InitPins() {
|
||||||
// stm32 TX - dongle RX often White
|
// stm32 TX - dongle RX often White
|
||||||
palSetPadMode(GPIOA, 9, PAL_MODE_STM32_ALTERNATE_PUSHPULL );
|
palSetPadMode(GPIOA, 9, PAL_MODE_STM32_ALTERNATE_PUSHPULL );
|
||||||
|
@ -123,6 +112,8 @@ void setBoostVoltage(float volts)
|
||||||
// Remember to strobe driven!!
|
// Remember to strobe driven!!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// todo: use me!!
|
||||||
|
/*
|
||||||
static bool check_flash() {
|
static bool check_flash() {
|
||||||
spiSelect(driver);
|
spiSelect(driver);
|
||||||
|
|
||||||
|
@ -146,6 +137,7 @@ static bool check_flash() {
|
||||||
spiUnselect(driver);
|
spiUnselect(driver);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
static unsigned short readDriverStatus(){
|
static unsigned short readDriverStatus(){
|
||||||
unsigned short driverStatus;
|
unsigned short driverStatus;
|
||||||
|
@ -336,6 +328,7 @@ int main() {
|
||||||
// Fire up all of our threads
|
// Fire up all of our threads
|
||||||
|
|
||||||
InitPins();
|
InitPins();
|
||||||
|
InitFlash();
|
||||||
InitCan();
|
InitCan();
|
||||||
InitUart();
|
InitUart();
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
#include "ch.h"
|
||||||
|
#include "hal.h"
|
||||||
|
|
||||||
|
#include "persistence.h"
|
||||||
|
#include "hal_mfs.h"
|
||||||
|
|
||||||
|
const MFSConfig mfscfg1 = {
|
||||||
|
.flashp = (BaseFlash *)&EFLD1,
|
||||||
|
.erased = 0xFFFFFFFFU,
|
||||||
|
.bank_size = 1024U,
|
||||||
|
.bank0_start = 126U,
|
||||||
|
.bank0_sectors = 1U,
|
||||||
|
.bank1_start = 127U,
|
||||||
|
.bank1_sectors = 1U
|
||||||
|
};
|
||||||
|
|
||||||
|
static MFSDriver mfs1;
|
||||||
|
uint8_t mfs_buffer[512];
|
||||||
|
|
||||||
|
void InitFlash() {
|
||||||
|
mfsObjectInit(&mfs1);
|
||||||
|
mfs_error_t err = mfsStart(&mfs1, &mfscfg1);
|
||||||
|
// assert(err == MFS_NO_ERROR, "initialization error with erased flash");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
mfs_error_t readErr;
|
||||||
|
mfs_error_t writeErr;
|
||||||
|
int IncAndGet() {
|
||||||
|
size_t size = sizeof mfs_buffer;
|
||||||
|
readErr = mfsReadRecord(&mfs1, 1, &size, mfs_buffer);
|
||||||
|
int result;
|
||||||
|
if (readErr == MFS_NO_ERROR) {
|
||||||
|
result = 5;
|
||||||
|
} else {
|
||||||
|
result = mfs_buffer[0];
|
||||||
|
}
|
||||||
|
result++;
|
||||||
|
mfs_buffer[0] = result;
|
||||||
|
size = sizeof mfs_buffer;
|
||||||
|
writeErr = mfsWriteRecord(&mfs1, 1, sizeof mfs_buffer, mfs_buffer);
|
||||||
|
return result;
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
void InitFlash();
|
||||||
|
int IncAndGet();
|
Loading…
Reference in New Issue