Merge git://github.com/r0ket/r0ket

This commit is contained in:
bernd 2011-08-04 14:16:12 +02:00
commit cf7602a388
6 changed files with 64 additions and 16 deletions

View File

@ -42,13 +42,13 @@ void queue_unsetinvert(void){
#define EVERY(x,y) if((ctr+y)%(x/SYSTICKSPEED)==0) #define EVERY(x,y) if((ctr+y)%(x/SYSTICKSPEED)==0)
// every 10 ms // every SYSTICKSPEED ms
void tick_default(void) { void tick_default(void) {
static int ctr; static int ctr;
ctr++; ctr++;
incTimer(); incTimer();
EVERY(1000,0){ EVERY(1024,0){
if(!adcMutex){ if(!adcMutex){
VoltageCheck(); VoltageCheck();
LightCheck(); LightCheck();
@ -58,7 +58,7 @@ void tick_default(void) {
}; };
static char night=0; static char night=0;
EVERY(100,2){ EVERY(128,2){
if(night!=isNight()){ if(night!=isNight()){
night=isNight(); night=isNight();
if(night){ if(night){
@ -82,5 +82,9 @@ void tick_default(void) {
gpioSetValue (RB_LED3, 0); gpioSetValue (RB_LED3, 0);
}; };
}; };
EVERY(4096,17){
nrf_check_reset();
};
return; return;
}; };

View File

@ -70,7 +70,7 @@ void init(void)
void mount(void) void mount(void)
{ {
int res; int res;
lcdPrintln("Mount DF:"); lcdPrint("Mount:");
res=f_mount(0, &FatFs); res=f_mount(0, &FatFs);
lcdPrintln(f_get_rc_string(res)); lcdPrintln(f_get_rc_string(res));
lcdRefresh(); lcdRefresh();
@ -79,7 +79,8 @@ void mount(void)
void format(void) void format(void)
{ {
int res; int res;
lcdPrintln("Formatting DF..."); lcdPrintln("Format DF:");
res=f_mount(0, &FatFs);
res=f_mkfs(0,1,0); res=f_mkfs(0,1,0);
lcdPrintln(f_get_rc_string(res)); lcdPrintln(f_get_rc_string(res));
lcdRefresh(); lcdRefresh();
@ -91,29 +92,34 @@ int check(void)
int res = 1; int res = 1;
res=f_open(&file, "flashed.cfg", FA_OPEN_EXISTING|FA_READ); res=f_open(&file, "flashed.cfg", FA_OPEN_EXISTING|FA_READ);
lcdPrint("open:"); lcdPrint("open:");
lcdPrintln(f_get_rc_string(res)); lcdPrint(f_get_rc_string(res));
lcdPrintln(" ");
lcdRefresh(); lcdRefresh();
return res; return res;
} }
void msc(int timeout) void msc(int timeout)
{ {
lcdPrintln("MSC Enabled."); lcdPrintln("MSC: Wait4data...");
lcdRefresh(); lcdRefresh();
delayms_power(300); delayms_power(300);
usbMSCInit(); usbMSCInit();
while(check()){ while(1){
lcdSetCrsr(0,3*8);
mount(); mount();
if(!check())
break;
if(getInputRaw())
break;
delayms(100); delayms(100);
f_recv(); f_recv();
lcdRefresh();
} }
while(timeout--){ while(timeout--){
//f_recv();
delayms(100); delayms(100);
} }
lcdPrintln("MSC Disabled."); lcdPrintln("MSC:Off.");
usbMSCOff(); usbMSCOff();
lcdRefresh(); lcdRefresh();
} }
@ -127,11 +133,13 @@ void isp(void)
void main_initial(void) { void main_initial(void) {
init(); init();
mount();
//if( check() )
format(); format();
msc(5); msc(5);
delayms(200); delayms(200);
lcdPrintln("ISP:ON");
lcdPrintln("turn off");
lcdPrintln("when done.");
lcdRefresh();
ReinvokeISP(); ReinvokeISP();
} }

View File

@ -191,8 +191,7 @@ int nrf_rcv_pkt_time_encr(int maxtime, int maxsize, uint8_t * pkt, uint32_t cons
#define LOOPY 10 #define LOOPY 10
for (;maxtime >= LOOPY;maxtime-=LOOPY){ for (;maxtime >= LOOPY;maxtime-=LOOPY){
delayms(LOOPY); delayms(LOOPY);
// status =nrf_cmd_status(C_NOP); status =nrf_cmd_status(C_NOP);
CS_LOW(); status=C_NOP; sspSendReceive(0, &status, 1); CS_HIGH();
if( (status & R_STATUS_RX_DR) == R_STATUS_RX_DR){ if( (status & R_STATUS_RX_DR) == R_STATUS_RX_DR){
if( (status & R_STATUS_RX_P_NO) == R_STATUS_RX_FIFO_EMPTY){ if( (status & R_STATUS_RX_P_NO) == R_STATUS_RX_FIFO_EMPTY){
nrf_cmd(C_FLUSH_RX); nrf_cmd(C_FLUSH_RX);
@ -392,6 +391,9 @@ void nrf_init() {
// Set speed / strength // Set speed / strength
nrf_write_reg(R_RF_SETUP,DEFAULT_SPEED|R_RF_SETUP_RF_PWR_3); nrf_write_reg(R_RF_SETUP,DEFAULT_SPEED|R_RF_SETUP_RF_PWR_3);
// Clear MAX_RT, just in case.
nrf_write_reg(R_STATUS,R_STATUS_MAX_RT);
}; };
void nrf_off() { void nrf_off() {
@ -401,3 +403,13 @@ void nrf_off() {
R_CONFIG_MASK_MAX_RT R_CONFIG_MASK_MAX_RT
); // Most important: no R_CONFIG_PWR_UP ); // Most important: no R_CONFIG_PWR_UP
}; };
uint8_t nrf_check_reset(void){
static uint8_t _nrfresets=0;
if(nrf_cmd_status(C_NOP) & R_STATUS_MAX_RT){
_nrfresets++;
nrf_init();
};
return _nrfresets;
};

View File

@ -162,7 +162,10 @@ void nrf_set_strength(unsigned char strength);
void nrf_rcv_pkt_start(void); void nrf_rcv_pkt_start(void);
int nrf_rcv_pkt_poll(int maxsize, uint8_t * pkt); int nrf_rcv_pkt_poll(int maxsize, uint8_t * pkt);
int nrf_rcv_pkt_poll_dec(int maxsize, uint8_t * pkt, uint32_t const key[4]); int nrf_rcv_pkt_poll_dec(int maxsize, uint8_t * pkt, uint32_t const key[4]);
// more utility.
void nrf_rcv_pkt_end(void); void nrf_rcv_pkt_end(void);
uint8_t nrf_check_reset(void);
/* END */ /* END */

View File

@ -67,3 +67,8 @@ uint32touint8p
uint8ptouint32 uint8ptouint32
memset memset
nrf_config_set nrf_config_set
nrf_read_reg
nrf_check_reset
sspSend
sspReceive
sspSendReceive

View File

@ -11,12 +11,13 @@
#include "core/iap/iap.h" #include "core/iap/iap.h"
#include "funk/nrf24l01p.h"
#include "funk/mesh.h" #include "funk/mesh.h"
#include "usetable.h" #include "usetable.h"
/**************************************************************************/ /**************************************************************************/
void ChkFlame(void); void ChkFunk(void);
void ChkLight(void); void ChkLight(void);
void ChkBattery(void); void ChkBattery(void);
void m_time(void); void m_time(void);
@ -29,6 +30,7 @@ static const struct MENU submenu_debug={ "debug", {
{ "ChkBattery", &ChkBattery}, { "ChkBattery", &ChkBattery},
{ "ChkLight", &ChkLight}, { "ChkLight", &ChkLight},
{ "MeshInfo", &m_time}, { "MeshInfo", &m_time},
{ "ChkFunk", &ChkFunk},
{ "Qstatus", &Qstatus}, { "Qstatus", &Qstatus},
{ "ShowSP", &getsp}, { "ShowSP", &getsp},
{ "Uptime", &uptime}, { "Uptime", &uptime},
@ -226,3 +228,17 @@ void m_time(void){
delayms_queue(50); delayms_queue(50);
}while ((getInputRaw())==BTN_NONE); }while ((getInputRaw())==BTN_NONE);
}; };
void ChkFunk(){
lcdPrint("st: ");
lcdPrintln(IntToStrX(nrf_read_reg(R_STATUS),2));
lcdPrint("fifost:");
lcdPrintln(IntToStrX(nrf_read_reg(R_FIFO_STATUS),2));
lcdPrint("cfg:");
lcdPrintln(IntToStrX(nrf_read_reg(R_CONFIG),2));
lcdPrintln("Resets:");
lcdPrintln(IntToStr(nrf_check_reset(),3,0));
lcdRefresh();
while(!getInputRaw())work_queue();
};