Add nrf_check_reset, and run it every 5 seconds.

Also: add more debugging
This commit is contained in:
Stefan `Sec` Zehl 2011-08-04 13:11:28 +02:00
parent 55d15269c5
commit 64d22980f2
5 changed files with 46 additions and 6 deletions

View File

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

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
for (;maxtime >= LOOPY;maxtime-=LOOPY){
delayms(LOOPY);
// status =nrf_cmd_status(C_NOP);
CS_LOW(); status=C_NOP; sspSendReceive(0, &status, 1); CS_HIGH();
status =nrf_cmd_status(C_NOP);
if( (status & R_STATUS_RX_DR) == R_STATUS_RX_DR){
if( (status & R_STATUS_RX_P_NO) == R_STATUS_RX_FIFO_EMPTY){
nrf_cmd(C_FLUSH_RX);
@ -392,6 +391,9 @@ void nrf_init() {
// Set speed / strength
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() {
@ -401,3 +403,13 @@ void nrf_off() {
R_CONFIG_MASK_MAX_RT
); // 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);
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]);
// more utility.
void nrf_rcv_pkt_end(void);
uint8_t nrf_check_reset(void);
/* END */

View File

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

View File

@ -11,12 +11,13 @@
#include "core/iap/iap.h"
#include "funk/nrf24l01p.h"
#include "funk/mesh.h"
#include "usetable.h"
/**************************************************************************/
void ChkFlame(void);
void ChkFunk(void);
void ChkLight(void);
void ChkBattery(void);
void m_time(void);
@ -29,6 +30,7 @@ static const struct MENU submenu_debug={ "debug", {
{ "ChkBattery", &ChkBattery},
{ "ChkLight", &ChkLight},
{ "MeshInfo", &m_time},
{ "ChkFunk", &ChkFunk},
{ "Qstatus", &Qstatus},
{ "ShowSP", &getsp},
{ "Uptime", &uptime},
@ -226,3 +228,17 @@ void m_time(void){
delayms_queue(50);
}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();
};