alan broad
/
carbon_v5_arm_studio
arm studio build
Diff: src/main.cpp
- Revision:
- 10:061fab1195e7
- Parent:
- 9:cc23b2049639
- Child:
- 11:77fe4f18a81b
--- a/src/main.cpp Mon Aug 13 15:58:00 2018 +0000 +++ b/src/main.cpp Wed Aug 15 13:51:13 2018 +0000 @@ -13,7 +13,7 @@ bool verbose = true; //======================================================================================================= -// enable some GPIO for scope trigger or led +// enable GPIO for scope trigger //======================================================================================================= //#define GPIO_ENABLE //======================================================================================================= @@ -56,17 +56,11 @@ #endif bool adr = false; //set adaptive data rate -//------------------------------------------------------------------------------------------------------ -//wait_after_sleep_usec ---------------- NO !!!!!!!!!!!!!!! -// -when xdot terminal display is disabled we need to add a delay between exiting sleep and polling for -// incoming i2c data from proc -// values of 300-5000 usec works -// - not sure why this is needed, it may take additional time for the uP to power up i2c io? -int16_t wait_after_sleep_usec =2500; -//------------------------------------------------------------------------------------------------------ - - - +//======================================================================================================= +// -need to add a delay between exiting i2c read->proc and before putting xdot to sleep to allow for final +// xfr of bytes in i2c buffer to be xfrd to proc. If log output enabled then it causes enough delay when +// it prints status info to make the delay ok. For now add this delay when both log enabled and disabled. +int16_t wait_before_sleep_usec = 10000; //======================================================================================================= // deepsleep consumes slightly less current than sleep // in sleep mode, IO state is maintained, RAM is retained, and application will resume after waking up @@ -90,32 +84,11 @@ std::vector<uint8_t> upstream_packet; #ifdef GPIO_ENABLE -DigitalOut led1(PB_0); //LED1); DigitalInOut gpio1(PA_5); //scope debug PA-5 is connected to SW1 pads on Loren v04 and can be used for scope debug #endif Serial pc(USBTX, USBRX); //serial port output -//================================================================================================= -//LED_test -//================================================================================================= -void LED_test(int num) -{ - #ifdef GPIO_ENABLE - if (led_enabled) - { - if(verbose)pc.printf("LED_test()\r\n"); - int test; - for (test=0; test<num; test++) - { - led1 = 0; - wait_ms(500); - led1 = 1; - wait_ms(500); - } - } - #endif -} //================================================================================== //chksum //compute checksum over i2c buffer except for last byte (chksum byte) @@ -208,7 +181,6 @@ #ifdef GPIO_ENABLE gpio1.output(); gpio1 =0; - led1 = 1; #endif pc.baud(115200); @@ -226,9 +198,8 @@ if (pNvmData->bLogOutputOn == 0){ pc.printf("\r\nDISABLING TERMINAL OUTPUT\r\n"); - //dot->setLogLevel(mts::MTSLog::NONE_LEVEL); //doesn't work - //dot->setLogLevel((true) ? mts::MTSLog::WARNING_LEVEL : mts::MTSLog::WARNING_LEVEL); //!!!!!!!!!!!! deosn't work - dot->setLogLevel((true) ? mts::MTSLog::INFO_LEVEL : mts::MTSLog::INFO_LEVEL); //!!!!!!!!!!!! this works + dot->setLogLevel(mts::MTSLog::NONE_LEVEL); //doesn't work + //dot->setLogLevel((true) ? mts::MTSLog::INFO_LEVEL : mts::MTSLog::INFO_LEVEL); //!!!!!!!!!!!! this works //dot->setLogLevel((true) ? mts::MTSLog::TRACE_LEVEL : mts::MTSLog::TRACE_LEVEL); //!!!!!!!!!!!! this works verbose = false; } @@ -274,9 +245,10 @@ i2c_proc_init(); //init i2c comm sleep_wake_interrupt_only(deep_sleep); //wake on rising edge of wake signal from proc - // wait_us(wait_after_sleep_usec); //scope test -// gpio1 =1; +#ifdef GPIO_ENABLE + gpio1 =1; +#endif //============================================================================== // -loop here forever // -sleep until LORA_WAKE goes hi => proc ready to send i2c cmd @@ -295,10 +267,14 @@ case I2C_WRITE: //xdot ack ->proc if(verbose)pc.printf("\n\r xdot ack -> proc done,going to sleep\n\r "); bPulseLoraWake = false; -// gpio1 =0; +#ifdef GPIO_ENABLE + gpio1 =0; +#endif + wait_us(wait_before_sleep_usec); //wait for i2c to complete data transfer before sleeping sleep_wake_interrupt_only(deep_sleep); ////sleep until rising edge of wake signal from proc - // wait_us(wait_after_sleep_usec); -// gpio1 =1; +#ifdef GPIO_ENABLE + gpio1 =1; +#endif if(verbose)pc.printf("\n\r lora wake detected -> monitoring i2c bus\n\r "); break; case I2C_READ: //xdot <- proc @@ -426,8 +402,8 @@ if(verbose)pc.printf("\n\r setting antenna gain to %d ",pUpRadio->params.antennaGaindBi); dot->setAntennaGain(pUpRadio->params.antennaGaindBi); - if(verbose)pc.printf("\n\r setting radio tx power to %d ",pUpRadio->params.txPowerdBm); - dot->setTxPower(pUpRadio->params.txPowerdBm); + if(verbose)pc.printf("\n\r setting radio tx power to %d ",pUpRadio->params.txPower); + dot->setTxPower(pUpRadio->params.txPower); if(verbose)pc.printf("\n\r setting tx datarate to %d ",pUpRadio->params.dataRate); dot->setTxDataRate(pUpRadio->params.dataRate); if(verbose)pc.printf("\n\r setting tx inverted to %d ",(bool)pUpRadio->params.txInverted); @@ -455,9 +431,13 @@ pDwnRadio->params.minTxPowerdBm = dot->getMinTxPower(); pDwnRadio->params.aDR = dot->getAdr(); pDwnRadio->params.antennaGaindBi = dot->getAntennaGain(); - pDwnRadio->params.txPowerdBm = dot->getTxPower(); - pDwnRadio->params.dataRate = dot->getTxDataRate(); - pDwnRadio->params.dataRateCurrent = dot->getSessionDataRate(); + pDwnRadio->params.txPower = dot->getTxPower(); //programmed tx power (non-adr) + pDwnRadio->params.dataRate = dot->getTxDataRate(); //programmed data rate (non-adr) + pDwnRadio->params.dataRateCurrent = dot->getSettings()->Session.TxDatarate; //presently used data rate (adr can change this);see Lora.h + pDwnRadio->params.txPowerCurrent = dot->getSettings()->Session.TxPower;//presently used tx power (adr can change this);see Lora.h + pDwnRadio->params.rx1DelayCurrent = dot->getSettings()->Session.RxDelay;//presently used rx1_delay;see Lora.h + + break; case XDOT_CMD_GET_EUI: //0307: modified to include radio parameter settings if(verbose)pc.printf("\n\r proc cmd: get EUI");