diff --git a/F1-nolib/chronometer/Makefile b/F1-nolib/chronometer/Makefile index d253d7a..b1946cb 100644 --- a/F1-nolib/chronometer/Makefile +++ b/F1-nolib/chronometer/Makefile @@ -8,10 +8,10 @@ MCU ?= F103x8 # density (stm32f10x.h, lines 70-84) DENSITY ?= MD # change this linking script depending on particular MCU model, -LDSCRIPT ?= stm32f103x8.ld +LDSCRIPT ?= stm32f103xB.ld DEFS = -DVERSION=\"0.0.1\" # debug -DEFS += -DEBUG +#DEFS += -DEBUG # proxy GPS output over USART1 DEFS += -DUSART1PROXY diff --git a/F1-nolib/chronometer/Readme.md b/F1-nolib/chronometer/Readme.md index e85cb05..6c6e3a5 100644 --- a/F1-nolib/chronometer/Readme.md +++ b/F1-nolib/chronometer/Readme.md @@ -19,8 +19,15 @@ Chronometer for downhill competitions - PC13 - buzzer +## LEDS + +- LED0 - shining when there's no PPS signal, fades for 0.25s on PPS +- LED1 - don't shines if no GPS found, shines when time not valid, blinks when time valid + ### Not implemented yet: - PA5,6,7 (SCK, MISO, MOSI) - SPI - PB0 - TRIG4 - ADC channel 8 - PB6/7 (SCL, SDA) - I2C + + diff --git a/F1-nolib/chronometer/chrono.bin b/F1-nolib/chronometer/chrono.bin index e543be8..42a21dd 100755 Binary files a/F1-nolib/chronometer/chrono.bin and b/F1-nolib/chronometer/chrono.bin differ diff --git a/F1-nolib/chronometer/flash.c b/F1-nolib/chronometer/flash.c index 34353ea..a0b3b6f 100644 --- a/F1-nolib/chronometer/flash.c +++ b/F1-nolib/chronometer/flash.c @@ -39,9 +39,7 @@ #include "adc.h" #include "flash.h" #include "lidar.h" -#ifdef EBUG -#include "usart.h" -#endif +#include "usart.h" // DBG #include // memcpy extern uint32_t _edata, _etext, _sdata; @@ -49,22 +47,22 @@ static int maxnum = FLASH_BLOCK_SIZE / sizeof(user_conf); typedef struct{ - const user_conf all_stored; + const user_conf all_stored; } flash_storage; #define USERCONF_INITIALIZER { \ - .userconf_sz = sizeof(user_conf) \ - ,.dist_min = LIDAR_MIN_DIST \ - ,.dist_max = LIDAR_MAX_DIST \ + .userconf_sz = sizeof(user_conf) \ + ,.dist_min = LIDAR_MIN_DIST \ + ,.dist_max = LIDAR_MAX_DIST \ ,.trig_pullups = 0xff \ ,.trigstate = 0 \ ,.trigpause = {400, 400, 400, 300, 300} \ ,.ADC_min = ADC_MIN_VAL \ ,.ADC_max = ADC_MAX_VAL \ - } + } __attribute__((section(".myvars"))) static const flash_storage Flash_Storage = { - .all_stored = USERCONF_INITIALIZER + .all_stored = USERCONF_INITIALIZER }; static const user_conf *Flash_Data = &Flash_Storage.all_stored; diff --git a/F1-nolib/chronometer/hardware.h b/F1-nolib/chronometer/hardware.h index a746279..fd5bad8 100644 --- a/F1-nolib/chronometer/hardware.h +++ b/F1-nolib/chronometer/hardware.h @@ -46,9 +46,11 @@ extern uint8_t buzzer_on; // PPS and triggers state // amount of triggers, should be less than 9; 5 - 0..2 - switches, 3 - LIDAR, 4 - ADC -#define TRIGGERS_AMOUNT (5) +#define TRIGGERS_AMOUNT (5) +// number of LIDAR trigger +#define LIDAR_TRIGGER (3) // amount of digital triggers (on interrupts) -#define DIGTRIG_AMOUNT (3) +#define DIGTRIG_AMOUNT (3) uint8_t gettrig(uint8_t N); void fillshotms(int i); diff --git a/F1-nolib/chronometer/lidar.c b/F1-nolib/chronometer/lidar.c index ae37189..45b3fc0 100644 --- a/F1-nolib/chronometer/lidar.c +++ b/F1-nolib/chronometer/lidar.c @@ -50,7 +50,7 @@ void parse_lidar_data(char *txt){ savetrigtime(); triggered = 1; lidar_triggered_dist = last_lidar_dist; - fillshotms(3); + fillshotms(LIDAR_TRIGGER); #ifdef EBUG SEND("Triggered! distance="); printu(1, last_lidar_dist); diff --git a/F1-nolib/chronometer/main.c b/F1-nolib/chronometer/main.c index 66c8916..6889944 100644 --- a/F1-nolib/chronometer/main.c +++ b/F1-nolib/chronometer/main.c @@ -240,7 +240,7 @@ int main(void){ } #endif RCC->CSR |= RCC_CSR_RMVF; // remove reset flags - //iwdg_setup(); + iwdg_setup(); while (1){ IWDG->KR = IWDG_REFRESH; // refresh watchdog diff --git a/F1-nolib/chronometer/str.c b/F1-nolib/chronometer/str.c index a51e7b0..8f6929e 100644 --- a/F1-nolib/chronometer/str.c +++ b/F1-nolib/chronometer/str.c @@ -19,6 +19,7 @@ #include "adc.h" #include "flash.h" #include "GPS.h" +#include "lidar.h" #include "str.h" #include "time.h" #include "usart.h" @@ -285,8 +286,14 @@ void show_trigger_shot(uint8_t tshot){ if(tshot & X) tshot &= ~X; else continue; if(trigger_shot & X) trigger_shot &= ~X; - USB_send("TRIG"); - sendu(i); + if(i == LIDAR_TRIGGER){ + USB_send("LIDAR, dist="); + sendu(lidar_triggered_dist); + USB_send(", TRIG="); + }else{ + USB_send("TRIG"); + sendu(i); + } USB_send("="); USB_send(get_time(&shottime[i].Time, shottime[i].millis)); USB_send("\n"); diff --git a/F1-nolib/chronometer/time.c b/F1-nolib/chronometer/time.c index cd23253..d36c9b7 100644 --- a/F1-nolib/chronometer/time.c +++ b/F1-nolib/chronometer/time.c @@ -121,8 +121,9 @@ char *get_time(curtime *Tm, uint32_t T){ #ifdef EBUG -int32_t ticksdiff=0, timecntr=0, timerval, Tms1; +int32_t timerval, Tms1; #endif +int32_t timecntr=0, ticksdiff=0; uint32_t last_corr_time = 0; @@ -145,8 +146,10 @@ void systick_correction(){ SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk; // stop systick for a while uint32_t systick_val = SysTick->VAL, L = SysTick->LOAD + 1; int32_t timer_val = Timer; +#ifdef EBUG timerval = Timer; Tms1 = Tms; +#endif Timer = 0; SysTick->VAL = SysTick->LOAD; SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk; // start it again @@ -155,7 +158,9 @@ void systick_correction(){ if(last_corr_time){ if(Tms - last_corr_time < 1500){ // there was perevious PPS signal int32_t D = L * (Tms - 1000 - last_corr_time) + (SysTick->LOAD - systick_val); // amount of spare ticks +#ifdef EBUG ++timecntr; +#endif ticksdiff += D; uint32_t ticksabs = (ticksdiff < 0) ? -ticksdiff : ticksdiff; // 10000 == 30 seconds * 1000 interrupts per second