Skip to content

Instantly share code, notes, and snippets.

@wa5znu
Created June 25, 2015 23:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wa5znu/ffb603f96bbdf209c0ba to your computer and use it in GitHub Desktop.
Save wa5znu/ffb603f96bbdf209c0ba to your computer and use it in GitHub Desktop.
byte check
#include <stdio.h>
// wall_ticks counts seconds and goes from 0-180 because there is a 3-minute beacon schedule.
volatile unsigned char wall_ticks = 0;
volatile unsigned char next_tx_click = 255;
struct station {
char *call;
char *location;
char *op;
unsigned char start_time;
};
struct station station;
void txon() {
}
void print(unsigned int x, unsigned char y) {
printf("%d %d\n", x, y);
}
// tick interrupt
// keep track of wall_ticks; use GPS PPS to discipline millis_per_second when it's safe to do so (no interrupts masked).
void tick() {
wall_ticks = (wall_ticks+1) % (3*60);
if ((wall_ticks - station.start_time) == next_tx_click) {
txon();
}
print(wall_ticks, wall_ticks);
}
int gps_discipline_clock_byte(unsigned char minutes, unsigned char seconds) {
wall_ticks = ((minutes * 60) + seconds) % (3*60);
return wall_ticks;
}
int gps_discipline_clock_int(int minutes, int seconds) {
int foo = ((minutes * 60) + seconds) % (3*60);
wall_ticks = foo;
return wall_ticks;
}
int main(int argc, char *argv[]) {
for (int i = 0; i < 1000; i++) {
printf("%d: ", i);
tick();
}
for (int minutes = 0; minutes < 60; minutes++) {
for (int seconds = 0; seconds < 60; seconds++) {
if (gps_discipline_clock_byte(minutes, seconds) != gps_discipline_clock_int(minutes, seconds)) {
printf("fail %d %d\n", minutes, seconds);
return -1;
} else {
printf("OK %d %d\n", minutes, seconds);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment