Files
@ 659774b354b1
Branch filter:
Location: FeatherHAB/wsprhab/src/main.c
659774b354b1
3.1 KiB
text/plain
Add a bunch of nonworking state machine code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | //
// WSPRHAB: Minimal high-altitude balloon tracker with WSPR telemetry
//
#include "stm32f0xx_hal.h"
#include "adc.h"
#include "system.h"
#include "i2c.h"
#include "uart.h"
#include "gpio.h"
#include "wspr.h"
#include "gps.h"
// We have access to the 1PPS pin of the gps... could have trim routine for internal oscillator based on this when we have a fix
// Probabl wake up 1 minute early -- 0.45min possible +/- on wakeup time with 15min sync intervals
enum _state
{
SYSTEM_POWERUP_SYNC = 0, // on powerup, get a GPS fix and set the RTC
SYSTEM_IDLE, // awaiting RTC interrupt for wakeup TODO wake up before scheduled time to get fix?
SYSTEM_GPSACQ, // RTC interrupted
SYSTEM_WSPRTX, // Wait for timeslot and actually transmit the message
}
int main(void)
{
HAL_Init();
sysclk_init();
gpio_init();
adc_init();
i2c_init();
gps_init();
wspr_init();
uint32_t led_timer = HAL_GetTick();
led_blink(4);
uint16_t blink_rate = BLINK_FAST;
uint8_t state = SYSTEM_GPSACQ;
while (1)
{
switch(state)
{
// Idling: sleep and wait for RTC timeslot trigger
case SYSTEM_IDLE:
{
blink_rate = BLINK_SLOW;
// Wait for RTC wakeup interrupt
wfi();
//enter_sleep();
// Somehow go to another state when we get an interrupt
state = SYSTEM_GPSACQ;
} break;
// Attempt to acquire GPS fix
case SYSTEM_GPSACQ:
{
blink_rate = BLINK_FAST;
// TODO: probably don't power on all the time, just on state transition
gps_poweron();
HAL_Delay(500);
gps_update_position();
if(fix_ok)
{
// Disable GPS module
gps_poweroff();
// TODO: Set RTC from GPS time
// TODO: Set RTC for countdown to next transmission timeslot!
// TODO: Set wspr countdown timer for this transmission!
state = SYSTEM_WSPRTX;
}
else if(fix_timeout)
{
// Flash error code and go to idle probably? or just try forever?
}
} break;
// Wait for wspr timeslot and start transmitting
case SYSTEM_WSPRTX:
{
// Wait for wspr countdown timer to expire and go to tx
if(timeout_expired)
{
wspr_transmit();
}
// Schedule next wakeup (maybe 2mins prior ot timeslot if no osc trim)
// Next wakeup should enter SYSTEM_GPSACQ state...
state = SYSTEM_IDLE;
} break;
}
if(HAL_GetTick() - led_timer > blink_rate)
{
HAL_GPIO_TogglePin(LED_BLUE);
led_timer = HAL_GetTick();
}
}
}
|