Skip to content

Instantly share code, notes, and snippets.

@ermacv
Created May 15, 2019 17:14
Show Gist options
  • Save ermacv/67f909b48faa4eee8dfbaf4d53337520 to your computer and use it in GitHub Desktop.
Save ermacv/67f909b48faa4eee8dfbaf4d53337520 to your computer and use it in GitHub Desktop.
#include <stdbool.h>
#include <stdint.h>
#define DELAY_INIT {0x0000, false}
typedef struct{
uint16_t time;
bool set;
}delay_t;
void setDelay(volatile delay_t*, uint16_t);
bool isDelayCount(volatile delay_t*);
void handleDelayInterrupt(volatile delay_t*);
void setDelay(volatile delay_t* delay, uint16_t time){
delay->set = false;
delay->time = time;
if (time)
delay->set = true;
}
bool isDelayCount(volatile delay_t* delay){
return delay->set;
}
void handleDelayInterrupt(volatile delay_t* delay){
if ((delay->set)&&(!(--delay->time)))
delay->set = false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment