reduce number of variables in isr and output

This commit is contained in:
Wolfgang Hottgenroth 2019-10-05 11:30:53 +01:00
parent 3bb0daacda
commit 4b5ba236c5

View File

@ -12,8 +12,6 @@ const int SPI_CHAN = 0;
const int SPI_SPEED = 1000000;
uint32_t ec = 0;
uint32_t counter = 0;
uint32_t diff = 0;
pthread_mutex_t counterMutex = PTHREAD_MUTEX_INITIALIZER;
@ -28,8 +26,6 @@ void isr() {
pthread_mutex_lock(&counterMutex);
diff = currentCounter - lastCounter;
counter = currentCounter;
ec++;
pthread_mutex_unlock(&counterMutex);
@ -53,8 +49,6 @@ void init() {
}
int main (void) {
uint32_t my_ec = 0;
uint32_t my_counter = 0;
uint32_t my_diff = 0;
init();
@ -66,12 +60,10 @@ int main (void) {
pthread_mutex_unlock(&eventMutex);
pthread_mutex_lock(&counterMutex);
my_ec = ec;
my_counter = counter;
my_diff = diff;
pthread_mutex_unlock(&counterMutex);
double f = 1.0 / (((double) my_diff) / 1000000.0);
printf("%u %u %u %f\n", my_ec, my_counter, my_diff, f);
printf("%f\n", f);
}
}