Flash saving. SD card work (for gruvin9x / ersky9x boards)

This commit is contained in:
bsongis
2012-05-29 17:06:40 +00:00
parent a462949bc2
commit 249e6f2e63
12 changed files with 166 additions and 102 deletions
+104 -51
View File
@@ -47,13 +47,14 @@
// States for initialising card
#define SD_ST_EMPTY 0
#define SD_ST_IDLE 1
#define SD_ST_READY 2
#define SD_ST_IDENT 3
#define SD_ST_STBY 4
#define SD_ST_TRAN 5
#define SD_ST_DATA 6
#define SD_ST_INIT1 1
#define SD_ST_INIT2 2
#define SD_ST_IDLE 3
#define SD_ST_READY 4
#define SD_ST_IDENT 5
#define SD_ST_STBY 6
#define SD_ST_TRAN 7
#define SD_ST_DATA 8
uint32_t Card_ID[4] ;
uint32_t Card_SCR[2] ;
@@ -62,6 +63,8 @@ uint32_t Card_state = SD_ST_EMPTY ;
uint32_t Sd_128_resp[4] ;
uint32_t Sd_rca ;
//uint32_t Cmd_55_resp ;
uint32_t Cmd_8_resp ;
uint32_t Cmd_A41_resp ;
/**
* Initializes a MCI peripheral.
@@ -224,51 +227,87 @@ void SD_Reset( uint8_t keepSettings)
void sd_cmd55()
{
uint32_t i ;
uint32_t i ;
Hsmci *phsmci = HSMCI ;
if ( CardIsConnected() )
{
phsmci->HSMCI_ARGR = Sd_rca ;
phsmci->HSMCI_CMDR = 0x00001077 ;
if ( CardIsConnected() )
{
phsmci->HSMCI_ARGR = Sd_rca ;
phsmci->HSMCI_CMDR = 0x00001077 ;
for ( i = 0 ; i < 30000 ; i += 1 )
{
if ( phsmci->HSMCI_SR & HSMCI_SR_CMDRDY )
{
break ;
}
}
for ( i = 0 ; i < 30000 ; i += 1 )
{
if ( phsmci->HSMCI_SR & HSMCI_SR_CMDRDY )
{
break ;
}
}
// Cmd_55_resp = phsmci->HSMCI_RSPR[0] ;
}
}
}
uint32_t sd_cmd0()
{
uint32_t i;
Hsmci *phsmci = HSMCI;
if (CardIsConnected()) {
phsmci->HSMCI_ARGR = 0;
phsmci->HSMCI_CMDR = 0x00001000;
for (i = 0; i < 30000; i += 1) {
if (phsmci->HSMCI_SR & HSMCI_SR_CMDRDY) {
break;
}
}
return phsmci->HSMCI_RSPR[0];
}
else {
return 0;
}
}
uint32_t sd_cmd8()
{
uint32_t i;
Hsmci *phsmci = HSMCI;
if (CardIsConnected()) {
phsmci->HSMCI_ARGR = 0X000001AA;
phsmci->HSMCI_CMDR = 0x00001048;
for (i = 0; i < 30000; i += 1) {
if (phsmci->HSMCI_SR & HSMCI_SR_CMDRDY) {
break;
}
}
return Cmd_8_resp = phsmci->HSMCI_RSPR[0];
}
else {
return 0;
}
}
uint32_t sd_acmd41()
{
uint32_t i ;
Hsmci *phsmci = HSMCI ;
uint32_t i;
Hsmci *phsmci = HSMCI;
if ( CardIsConnected() )
{
sd_cmd55() ;
phsmci->HSMCI_ARGR = 0X001F8000 ;
phsmci->HSMCI_CMDR = 0x00001069 ;
if (CardIsConnected()) {
sd_cmd55();
phsmci->HSMCI_ARGR = 0x403F8000;
phsmci->HSMCI_CMDR = 0x00001069;
for ( i = 0 ; i < 30000 ; i += 1 )
{
if ( phsmci->HSMCI_SR & HSMCI_SR_CMDRDY )
{
break ;
}
}
return phsmci->HSMCI_RSPR[0] ;
}
else
{
return 0 ;
}
for (i = 0; i < 30000; i += 1) {
if (phsmci->HSMCI_SR & HSMCI_SR_CMDRDY) {
break;
}
}
return Cmd_A41_resp = phsmci->HSMCI_RSPR[0] ;
}
else {
return 0;
}
}
// Get Card ID
@@ -498,19 +537,27 @@ void sd_poll_10mS()
switch ( Card_state )
{
case SD_ST_EMPTY :
if ( CardIsConnected() )
{
Card_state = SD_ST_IDLE ;
}
break ;
if ( CardIsConnected() ) {
Card_state = SD_ST_INIT1 ;
}
break ;
case SD_ST_INIT1 :
i = sd_cmd0() ;
Card_state = SD_ST_INIT2 ;
break ;
case SD_ST_INIT2 :
i = sd_cmd8() ;
Card_state = SD_ST_IDLE ;
break ;
case SD_ST_IDLE :
i = sd_acmd41() ;
if ( i & 0x80000000 )
{
Card_state = SD_ST_READY ;
}
break ;
i = sd_acmd41() ;
if ( i & 0x80000000 ) {
Card_state = SD_ST_READY ;
}
break ;
case SD_ST_READY :
i = sd_cmd2() ;
@@ -662,6 +709,12 @@ uint32_t sd_write_block( uint32_t block_no, uint32_t *data )
/*
Notes on SD card:
1) CMD8 fails and CMD58 fails: must be MMC, thus initialize using CMD1
2) CMD8 fails and CMD58 passes: must be Ver1.x Standard Capacity SD Memory Card
3) CMD8 passes and CMD58 passes (CCS = 0): must be Ver2.00 or later Standard Capacity SD Memory Card
4) CMD8 passes and CMD58 passes (CCS = 1): must be Ver2.00 or later High Capacity SD Memory Card
5) CMD8 passes and CMD58 passes but indicates non compatible voltage range: unusable card
On card present
1. Send CMD 55 (resp 48bit)
followed by ACMD41 (resp48bit)
+1 -1
View File
@@ -311,7 +311,7 @@ void menuMainView(uint8_t event)
#if defined(PCBV4)
for (uint8_t i=0; i<NUM_ROTARY_ENCODERS; i++) {
int16_t val = getRotaryEncoder(i);
int8_t len = limit((int16_t)0, (int16_t)(((val+1024) * BAR_HEIGHT) / 2048), (int16_t)BAR_HEIGHT); // TODO uint16_t?
int8_t len = limit((int16_t)0, (int16_t)(((val+1024) * BAR_HEIGHT) / 2048), (int16_t)BAR_HEIGHT);
#if defined(EXTRA_ROTARY_ENCODERS)
#define V_BAR_W 5
V_BAR(SCREEN_WIDTH/2-8+V_BAR_W*i, SCREEN_HEIGHT-8, len)
-3
View File
@@ -33,14 +33,11 @@
#include "open9x.h"
int16_t calibratedStick[NUM_STICKS+NUM_POTS];
uint8_t s_pgOfs;
int8_t s_editMode;
uint8_t s_noHi;
uint8_t s_noScroll;
int16_t g_chans512[NUM_CHNOUT]; // TODO not here!
void menu_lcd_onoff(uint8_t x,uint8_t y, uint8_t value, uint8_t attr)
{
#if defined(GRAPHICS)
+12 -17
View File
@@ -242,9 +242,7 @@ void menuProcModelSelect(uint8_t event)
{
case EVT_ENTRY:
m_posVert = sub = g_eeGeneral.currModel;
s_copyMode = 0; // TODO only this one?
s_copyTgtOfs = 0;
s_copySrcRow = -1;
s_copyMode = 0;
s_editMode = -1;
eeCheck(true);
break;
@@ -257,10 +255,8 @@ void menuProcModelSelect(uint8_t event)
// no break
case EVT_KEY_BREAK(KEY_EXIT):
if (s_copyMode) {
sub = m_posVert = (s_copyMode == MOVE_MODE || s_copySrcRow<0) ? (MAX_MODELS+sub+s_copyTgtOfs) % MAX_MODELS : s_copySrcRow; // TODO reset s_copySrcRow?
s_copyMode = 0; // TODO only this one?
s_copySrcRow = -1;
s_copyTgtOfs = 0;
sub = m_posVert = (s_copyMode == MOVE_MODE || s_copySrcRow<0) ? (MAX_MODELS+sub+s_copyTgtOfs) % MAX_MODELS : s_copySrcRow;
s_copyMode = 0;
killEvents(_event);
}
break;
@@ -305,9 +301,7 @@ void menuProcModelSelect(uint8_t event)
STORE_GENERALVARS;
}
s_copyMode = 0; // TODO only this one?
s_copySrcRow = -1;
s_copyTgtOfs = 0;
s_copyMode = 0;
return;
}
else if (_event == EVT_KEY_LONG(KEY_MENU) || IS_RE_NAVIGATION_EVT_TYPE(_event, EVT_KEY_LONG)) {
@@ -342,6 +336,8 @@ void menuProcModelSelect(uint8_t event)
}
else if (eeModelExists(sub)) {
s_copyMode = (s_copyMode == COPY_MODE ? MOVE_MODE : COPY_MODE);
s_copyTgtOfs = 0;
s_copySrcRow = -1;
}
break;
case EVT_KEY_FIRST(KEY_LEFT):
@@ -367,9 +363,7 @@ void menuProcModelSelect(uint8_t event)
// no free room for duplicating the model
AUDIO_ERROR();
m_posVert = oldSub;
s_copyMode = 0; // TODO only this one?
s_copyTgtOfs = 0;
s_copySrcRow = -1;
s_copyMode = 0;
}
next_ofs = 0;
sub = m_posVert;
@@ -424,7 +418,7 @@ void menuProcModelSelect(uint8_t event)
putsModelName(4*FW, y, name, k, 0);
lcd_outdezAtt(20*FW, y, size, 0);
#endif
if (k==g_eeGeneral.currModel && (s_copySrcRow<0 || i+s_pgOfs!=sub)) lcd_putc(1, y, '*');
if (k==g_eeGeneral.currModel && (s_copyMode!=COPY_MODE || s_copySrcRow<0 || i+s_pgOfs!=sub)) lcd_putc(1, y, '*');
}
if (s_copyMode && sub==i+s_pgOfs) {
@@ -505,7 +499,6 @@ void EditName(uint8_t x, uint8_t y, char *name, uint8_t size, uint8_t event, boo
|| event==EVT_KEY_REPT(KEY_DOWN) || event==EVT_KEY_REPT(KEY_UP)) {
v = checkIncDec(event, abs(v), 0, ZCHAR_MAX, 0);
if (c < 0) v = -v;
STORE_MODELVARS;
}
switch (event) {
@@ -531,14 +524,16 @@ void EditName(uint8_t x, uint8_t y, char *name, uint8_t size, uint8_t event, boo
case EVT_KEY_LONG(KEY_RIGHT):
if (v>=-26 && v<=26) {
v = -v; // toggle case
STORE_MODELVARS; // TODO optim if (c!=v) at the end
if (event==EVT_KEY_LONG(KEY_LEFT))
killEvents(KEY_LEFT);
}
break;
}
name[cur] = v;
if (c != v) {
name[cur] = v;
STORE_MODELVARS;
}
lcd_putcAtt(x+cur*FW, y, idx2char(v), INVERS);
cur = next;
}
+28 -9
View File
@@ -398,6 +398,8 @@ int16_t applyLimits(uint8_t channel, int32_t value)
return ofs;
}
int16_t calibratedStick[NUM_STICKS+NUM_POTS];
int16_t g_chans512[NUM_CHNOUT];
int16_t ex_chans[NUM_CHNOUT] = {0}; // Outputs (before LIMITS) of the last perMain
#ifdef HELI
int16_t cyc_anas[3] = {0};
@@ -1326,20 +1328,19 @@ FORCEINLINE void evalTrims()
uint8_t phase = s_perout_flight_phase;
for (uint8_t i=0; i<NUM_STICKS; i++) {
// do trim -> throttle trim if applicable
// TODO avoid int32_t vv
int32_t vv = 2*RESX;
int16_t trim = getTrimValue(phase, i);
if (i==THR_STICK && g_model.thrTrim) {
if (g_eeGeneral.throttleReversed)
trim = -trim;
int16_t v = anas[i];
vv = ((int32_t)trim-TRIM_MIN)*(RESX-v)/(2*RESX);
int32_t vv = ((int32_t)trim-TRIM_MIN)*(RESX-v)/(2*RESX);
trim = vv;
}
else if (trimsCheckTimer > 0) {
trim = 0;
}
trims[i] = (vv==2*RESX) ? trim*2 : (int16_t)vv*2; // if throttle trim -> trim low end
trims[i] = trim*2;
}
}
@@ -1747,12 +1748,16 @@ void perOut()
if (tick10ms) {
int32_t rate = (int32_t)DEL_MULT*2048*100;
if(md->weight) rate /= abs(md->weight);
// TODO port optim er9x by Mike
act[i] = (diff>0) ? ((md->speedUp>0) ? act[i]+(rate)/((int16_t)100*md->speedUp) : (int32_t)v*DEL_MULT) :
((md->speedDown>0) ? act[i]-(rate)/((int16_t)100*md->speedDown) : (int32_t)v*DEL_MULT) ;
}
if(((diff>0) && (v<(act[i]/DEL_MULT))) || ((diff<0) && (v>(act[i]/DEL_MULT)))) act[i]=(int32_t)v*DEL_MULT; //deal with overflow
{
int32_t tmp = act[i]/DEL_MULT ;
if(((diff>0) && (v<tmp)) || ((diff<0) && (v>tmp))) act[i]=(int32_t)v*DEL_MULT; //deal with overflow
}
v = act[i]/DEL_MULT;
}
}
@@ -2563,6 +2568,20 @@ uint16_t stack_free()
int main(void)
{
// The WDT remains active after a WDT reset -- at maximum clock speed. So it's
// important to disable it before commencing with system initialisation (or
// we could put a bunch more wdt_reset()s in. But I don't like that approach
// during boot up.)
#if defined(PCBV4)
uint8_t mcusr_mirror = MCUSR; // save the WDT (etc) flags
MCUSR = 0; // must be zeroed before disabling the WDT
#elif defined(PCBSTD)
uint8_t mcusr_mirror = MCUCSR;
MCUCSR = 0;
#endif
wdt_disable();
board_init();
lcd_init();
@@ -2629,13 +2648,13 @@ int main(void)
#endif
#if defined(PCBV4)
if ((~MCUSR & (1 << WDRF)) && !g_eeGeneral.unexpectedShutdown)
if ((~mcusr_mirror & (1 << WDRF)) && !g_eeGeneral.unexpectedShutdown)
#elif defined(PCBSTD)
if (~MCUCSR & (1 << WDRF))
if (~mcusr_mirror & (1 << WDRF))
#else
if (!g_eeGeneral.unexpectedShutdown)
#endif
{
{
#ifdef SPLASH
#ifdef DSM2
// TODO rather use another Model Parameter
+1 -1
View File
@@ -762,7 +762,7 @@ extern int16_t applyCurve(int16_t, int8_t);
extern void applyExpos(int16_t *anas);
extern uint16_t anaIn(uint8_t chan);
extern int16_t calibratedStick[7];
extern int16_t calibratedStick[NUM_STICKS+NUM_POTS];
#define FLASH_DURATION 50
+3 -3
View File
@@ -76,7 +76,7 @@
#else
#define TR_EXPLABEL_FP
#endif
#define TR_EXPLABELS "V\200ha ""Expo ""K\206ivka" TR_EXPLABEL_FP "Sp\204na\201""Strana"" " // TODO remove all the trailing spaces
#define TR_EXPLABELS "V\200ha ""Expo ""K\206ivka" TR_EXPLABEL_FP "Sp\204na\201""Strana""\0"
#define LEN_VMLTPX "\010"
#define TR_VMLTPX "Se\201\204st ""N\200sobit ""Zam\203nit "
@@ -166,7 +166,7 @@
#endif
#define LEN_VARIOSRC "\006"
#define TR_VARIOSRC "BaroV1""BaroV2""A1 ""A2 "
#define TR_VARIOSRC "BaroV1""BaroV2""A1\0 ""A2\0"
#define LEN_GPSFORMAT "\004"
#define TR_GPSFORMAT "HMS NMEA"
@@ -176,7 +176,7 @@
#define TR_VTEMPLATES "Smazat Mixy\0\0""Z\200kl. 4kan\200l\0""T-Cut \0""V-Ocas \0""Elevon\\Delta\0""eCCPM \0""Heli Setup \0""Servo Test \0"
#define LEN_VSWASHTYPE "\004"
#define TR_VSWASHTYPE "--- ""120 ""120X""140 ""90 "
#define TR_VSWASHTYPE "--- ""120 ""120X""140 ""90\0"
#define LEN_VKEYS "\005"
#define TR_VKEYS " Menu"" Exit"" Dol\211""Nhoru""Vprvo""Vlevo"
+3 -3
View File
@@ -71,7 +71,7 @@
#else
#define TR_EXPLABEL_FP
#endif
#define TR_EXPLABELS "Gew. ""Expo ""Kurve " TR_EXPLABEL_FP "Switch""Seite"" " // TODO remove all the trailing spaces
#define TR_EXPLABELS "Gew. ""Expo ""Kurve " TR_EXPLABEL_FP "Switch""Seite ""\0"
#define LEN_VMLTPX "\010"
#define TR_VMLTPX "Add ""Multiply""Replace "
@@ -161,7 +161,7 @@
#endif
#define LEN_VARIOSRC "\006"
#define TR_VARIOSRC "BaroV1""BaroV2""A1 ""A2 "
#define TR_VARIOSRC "BaroV1""BaroV2""A1\0 ""A2\0"
#define LEN_GPSFORMAT "\004"
#define TR_GPSFORMAT "HMS NMEA"
@@ -171,7 +171,7 @@
#define TR_VTEMPLATES "Clear Mixes\0\0""Simple 4-CH \0""T-Cut \0""V-Tail \0""Elevon\\Delta\0""eCCPM \0""Heli Setup \0""Servo Test \0"
#define LEN_VSWASHTYPE "\004"
#define TR_VSWASHTYPE "--- ""120 ""120X""140 ""90 "
#define TR_VSWASHTYPE "--- ""120 ""120X""140 ""90\0"
#define LEN_VKEYS "\005"
#define TR_VKEYS " Menu"" Exit""Unten"" Oben"" Re."" Li."
+4 -4
View File
@@ -76,7 +76,7 @@
#else
#define TR_EXPLABEL_FP
#endif
#define TR_EXPLABELS "Weight""Expo ""Curve " TR_EXPLABEL_FP "Swtch ""Side "" " // TODO remove all the trailing spaces
#define TR_EXPLABELS "Weight""Expo ""Curve " TR_EXPLABEL_FP "Swtch ""Side\0 ""\0"
#define LEN_VMLTPX "\010"
#define TR_VMLTPX "Add ""Multiply""Replace "
@@ -122,7 +122,7 @@
#define TR_SOMO
#endif
#ifdef DEBUG
#define TR_TEST "Test\0 "
#define TR_TEST "Test\0"
#else
#define TR_TEST
#endif
@@ -166,7 +166,7 @@
#endif
#define LEN_VARIOSRC "\006"
#define TR_VARIOSRC "BaroV1""BaroV2""A1 ""A2 "
#define TR_VARIOSRC "BaroV1""BaroV2""A1\0 ""A2\0"
#define LEN_GPSFORMAT "\004"
#define TR_GPSFORMAT "HMS NMEA"
@@ -176,7 +176,7 @@
#define TR_VTEMPLATES "Clear Mixes\0\0""Simple 4-CH \0""T-Cut \0""V-Tail \0""Elevon\\Delta\0""eCCPM \0""Heli Setup \0""Servo Test \0"
#define LEN_VSWASHTYPE "\004"
#define TR_VSWASHTYPE "--- ""120 ""120X""140 ""90 "
#define TR_VSWASHTYPE "--- ""120 ""120X""140 ""90\0"
#define LEN_VKEYS "\005"
#define TR_VKEYS " Menu"" Exit"" Down"" Up""Right"" Left"
+3 -3
View File
@@ -71,7 +71,7 @@
#else
#define TR_EXPLABEL_FP
#endif
#define TR_EXPLABELS "Ratio ""Expo ""Courbe" TR_EXPLABEL_FP "Inter ""Mode "" "
#define TR_EXPLABELS "Ratio ""Expo ""Courbe" TR_EXPLABEL_FP "Inter ""Mode ""\0"
#define LEN_VMLTPX "\010"
#define TR_VMLTPX "Ajoute ""Multipl.""Remplace"
@@ -161,7 +161,7 @@
#endif
#define LEN_VARIOSRC "\006"
#define TR_VARIOSRC "BaroV1""BaroV2""A1 ""A2 "
#define TR_VARIOSRC "BaroV1""BaroV2""A1\0 ""A2\0"
#define LEN_GPSFORMAT "\004"
#define TR_GPSFORMAT "HMS NMEA"
@@ -174,7 +174,7 @@
#define TR_VTEMPLATES "Suppr Mixages\0\0""4 Voies simple\0""Coupure Gaz \0""Empennage V \0""Elevon\\Delta \0""eCCPM \0""Conf. H\200lico \0""Servo Test \0"
#define LEN_VSWASHTYPE "\004"
#define TR_VSWASHTYPE "--- ""120 ""120X""140 ""90 "
#define TR_VSWASHTYPE "--- ""120 ""120X""140 ""90\0"
#define LEN_VKEYS "\005"
#define TR_VKEYS " Menu"" Exit"" Bas"" Haut""Droit""Gauch"
+3 -3
View File
@@ -76,7 +76,7 @@
#else
#define TR_EXPLABEL_FP
#endif
#define TR_EXPLABELS "Peso ""Expo ""Curva " TR_EXPLABEL_FP "Switch""Lato "" " // TODO remove all the trailing spaces
#define TR_EXPLABELS "Peso ""Expo ""Curva " TR_EXPLABEL_FP "Switch""Lato ""\0"
#define LEN_VMLTPX "\010"
#define TR_VMLTPX "Aggiungi""Moltipl.""Riscrivi"
@@ -166,7 +166,7 @@
#endif
#define LEN_VARIOSRC "\006"
#define TR_VARIOSRC "BaroV1""BaroV2""A1 ""A2 "
#define TR_VARIOSRC "BaroV1""BaroV2""A1\0 ""A2\0"
#define LEN_GPSFORMAT "\004"
#define TR_GPSFORMAT "HMS NMEA"
@@ -176,7 +176,7 @@
#define TR_VTEMPLATES "Clear Mixes\0\0""Simple 4-CH \0""T-Cut \0""V-Tail \0""Elevon\\Delta\0""eCCPM \0""Heli Setup \0""Servo Test \0"
#define LEN_VSWASHTYPE "\004"
#define TR_VSWASHTYPE "--- ""120 ""120X""140 ""90 "
#define TR_VSWASHTYPE "--- ""120 ""120X""140 ""90\0"
#define LEN_VKEYS "\005"
#define TR_VKEYS " Men\200"" EXIT"" DN "" UP"" SX"" DX"
+4 -4
View File
@@ -71,10 +71,10 @@
#else
#define TR_EXPLABEL_FP
#endif
#define TR_EXPLABELS "Vikt ""Expo ""Kurva " TR_EXPLABEL_FP "Brytar""N\201r "" " // TODO remove all the trailing spaces
#define TR_EXPLABELS "Vikt ""Expo ""Kurva " TR_EXPLABEL_FP "Brytar""N\201r ""\0"
#define LEN_VMLTPX "\010"
#define TR_VMLTPX "Addera ""F\202rst\201rk""Ers\201tt "
#define TR_VMLTPX "Addera ""F\202rst\201rk""Ers\201tt\0"
#define LEN_VMLTPX2 "\002"
#define TR_VMLTPX2 "+=""*="":="
@@ -161,7 +161,7 @@
#endif
#define LEN_VARIOSRC "\006"
#define TR_VARIOSRC "BaroV1""BaroV2""A1 ""A2 "
#define TR_VARIOSRC "BaroV1""BaroV2""A1 ""A2\0"
#define LEN_GPSFORMAT "\004"
#define TR_GPSFORMAT "HMS NMEA"
@@ -174,7 +174,7 @@
#define TR_VTEMPLATES "Nolla Mixar\0\0""Enkel 4kanal\0""Gasklippning\0""V-Stj\201rt \0""Deltavinge \0""eCCPM \0""Helikopter \0""Servotest \0"
#define LEN_VSWASHTYPE "\004"
#define TR_VSWASHTYPE "--- ""120 ""120X""140 ""90 "
#define TR_VSWASHTYPE "--- ""120 ""120X""140 ""90\0"
#define LEN_VKEYS "\005"
#define TR_VKEYS " MENU"" EXIT"" Ned"" Upp""H\202ger""V\201nst"