16bit timebase so the read in delay is atomic

master
Ondřej Hruška 8 years ago
parent f064bc6fb6
commit 0736081111
  1. 21
      User/bootstrap.c
  2. 2
      User/bootstrap.h

@ -6,7 +6,7 @@
#include "bootstrap.h" #include "bootstrap.h"
/** Global time base */ /** Global time base */
volatile uint32_t time_ms; volatile uint16_t time_ms;
/** /**
* Putchar for printf * Putchar for printf
@ -61,8 +61,23 @@ INTERRUPT_HANDLER(TIM4_UPD_OVF_IRQHandler, 23)
/** Delay ms */ /** Delay ms */
void Delay(uint16_t ms) void Delay(uint16_t ms)
{ {
uint32_t start = time_ms; uint16_t start = time_ms;
while ((time_ms - start) < ms); uint16_t t2;
while (1) {
t2 = time_ms;
if ((t2 - start) >= ms) {
break;
}
}
}
/** Delay N seconds */
void Delay_s(uint16_t s)
{
while (s != 0) {
Delay(1000);
s--;
}
} }
/** /**

@ -6,7 +6,7 @@
#define STM8S_STDINIT_H #define STM8S_STDINIT_H
/** Global timebase */ /** Global timebase */
extern volatile uint32_t time_ms; extern volatile uint16_t time_ms;
/** Uart IRQ handler */ /** Uart IRQ handler */
void UART1_RX_IRQHandler(void) INTERRUPT(18); void UART1_RX_IRQHandler(void) INTERRUPT(18);

Loading…
Cancel
Save