mirror of
https://codeberg.org/SiB64/turbo_weather.git
synced 2026-05-01 15:14:22 +02:00
Compare commits
2 commits
763ab24e9e
...
f692d97cf0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f692d97cf0 | ||
|
|
be5c18ca52 |
3 changed files with 36 additions and 14 deletions
32
src/bate.c
32
src/bate.c
|
|
@ -410,7 +410,11 @@ int main()
|
|||
sleep_enable();
|
||||
sei();
|
||||
|
||||
send_str("\nV Turbo Weather V0.03\n");
|
||||
uint8_t reset_source = RSTCTRL.RSTFR;
|
||||
RSTCTRL.RSTFR = reset_source;
|
||||
send_str("\nV Turbo Weather V0.04\nR ");
|
||||
send_hex_byte(reset_source);
|
||||
send_char('\n');
|
||||
|
||||
uint8_t test_calib = config.calib_test;
|
||||
if (test_calib > N_TESTDATA)
|
||||
|
|
@ -467,11 +471,15 @@ int main()
|
|||
}
|
||||
}
|
||||
if (!(trigger & config.triggers)) {
|
||||
if (config.power & POWER_DOWN) {
|
||||
if (config.power & (POWER_DOWN|POWER_STDBY)) {
|
||||
mclk(0);
|
||||
if (config.power & POWER_DOWN_CLI)
|
||||
cli();
|
||||
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
|
||||
if (config.power & POWER_DOWN) {
|
||||
if (config.power & POWER_DOWN_CLI)
|
||||
cli();
|
||||
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
|
||||
}
|
||||
else
|
||||
set_sleep_mode(SLEEP_MODE_STANDBY);
|
||||
sleep_enable();
|
||||
sleep_cpu();
|
||||
set_sleep_mode(SLEEP_MODE_IDLE);
|
||||
|
|
@ -480,12 +488,12 @@ int main()
|
|||
}
|
||||
|
||||
rfen(1);
|
||||
led(1);
|
||||
if (config.power & POWER_LED)
|
||||
led(1);
|
||||
|
||||
if (!mclk_status()) {
|
||||
mclk(1);
|
||||
if (!mclk_status())
|
||||
mclk_delay = config.mclk_delay;
|
||||
}
|
||||
mclk(1);
|
||||
|
||||
if (!tick)
|
||||
continue;
|
||||
|
|
@ -503,10 +511,10 @@ int main()
|
|||
if (config.send & SEND_ADC)
|
||||
start_adc();
|
||||
|
||||
cli();
|
||||
uint32_t time = clock;
|
||||
sei();
|
||||
if (config.send & SEND_CLOCK) {
|
||||
cli();
|
||||
uint32_t time = clock;
|
||||
sei();
|
||||
send_str("T 0x");
|
||||
send_hex_long(time);
|
||||
send_char('\n');
|
||||
|
|
|
|||
|
|
@ -36,6 +36,8 @@ enum power_flags {
|
|||
POWER_DOWN = 0x01,
|
||||
POWER_DOWN_CLI = 0x02,
|
||||
STOP_MCLK = 0x04,
|
||||
POWER_LED = 0x08,
|
||||
POWER_STDBY = 0x10,
|
||||
};
|
||||
enum send_flags {
|
||||
SEND_CONFIG = 0x01,
|
||||
|
|
|
|||
16
src/uart.c
16
src/uart.c
|
|
@ -56,6 +56,7 @@ uint8_t uart_tick()
|
|||
uint8_t uart_tx[128];
|
||||
volatile uint8_t uart_tx_w;
|
||||
volatile uint8_t uart_tx_r;
|
||||
volatile uint8_t uart_tx_b;
|
||||
static const uint8_t uart_tx_m = sizeof(uart_tx) - 1;
|
||||
|
||||
static inline void tx()
|
||||
|
|
@ -65,6 +66,8 @@ static inline void tx()
|
|||
while (r != uart_tx_w) {
|
||||
if (!(USART0.STATUS & USART_DREIF_bm)) {
|
||||
USART0.CTRLA |= USART_DREIE_bm;
|
||||
USART0.STATUS = USART_TXCIF_bm;
|
||||
uart_tx_b = USART_TXCIF_bm;
|
||||
uart_tx_r = r;
|
||||
return;
|
||||
}
|
||||
|
|
@ -84,11 +87,20 @@ ISR(USART0_DRE_vect)
|
|||
__attribute__ ((noinline, noclone))
|
||||
uint8_t uart_busy()
|
||||
{
|
||||
// How to test if we can power down?
|
||||
// `uart_tx_b` is set to `TXC` when a char is loaded for transmission
|
||||
// and the TXCIF is cleared.
|
||||
// When `uart_tx_b` is zero, we are good,
|
||||
// else when `TXCIF` is set we are also good.
|
||||
// When `uart_tx_b` is set but the `TXCIF` not yet, we are busy,
|
||||
//returning TXC.
|
||||
cli();
|
||||
tx();
|
||||
uint8_t r = uart_tx_w - uart_tx_r;
|
||||
uint8_t b = uart_tx_b;
|
||||
if (!b || USART0.STATUS & b)
|
||||
b = uart_tx_b = 0;
|
||||
sei();
|
||||
return r;
|
||||
return b;
|
||||
}
|
||||
|
||||
__attribute__ ((noinline, noclone))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue