add ringbuffer

This commit is contained in:
2019-10-06 00:11:39 +02:00
parent c90ffe6509
commit 33939d3b59
4 changed files with 70 additions and 30 deletions

View File

@ -2,11 +2,10 @@
#include <wiringPiSPI.h>
#include <stdint.h>
#include <stdio.h>
#include <pthread.h>
#include "LS7366R.h"
#include "influx.h"
#include "ringbuffer.h"
const int CTRL_OUT = 16;
const int INTR_IN = 19;
@ -14,28 +13,15 @@ const int SPI_CHAN = 0;
const int SPI_SPEED = 1000000;
uint32_t diff = 0;
pthread_mutex_t counterMutex = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t eventMutex = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t eventSignal = PTHREAD_COND_INITIALIZER;
void isr() {
static uint32_t lastCounter = 0;
uint32_t currentCounter = ls7366rReadOTR();
pthread_mutex_lock(&counterMutex);
diff = currentCounter - lastCounter;
pthread_mutex_unlock(&counterMutex);
uint32_t diff = currentCounter - lastCounter;
lastCounter = currentCounter;
pthread_mutex_lock(&eventMutex);
pthread_cond_signal(&eventSignal);
pthread_mutex_unlock(&eventMutex);
ringbufferPut(diff);
}
void init() {
@ -51,21 +37,13 @@ void init() {
}
int main (void) {
uint32_t my_diff = 0;
init();
ls7366rInit(SPI_CHAN);
while (1) {
pthread_mutex_lock(&eventMutex);
pthread_cond_wait(&eventSignal, &eventMutex);
pthread_mutex_unlock(&eventMutex);
pthread_mutex_lock(&counterMutex);
my_diff = diff;
pthread_mutex_unlock(&counterMutex);
double f = 1.0 / (((double) my_diff) / 1000000.0);
uint32_t diff = ringbufferGet();
double f = 1.0 / (((double) diff) / 1000000.0);
printf("%f\n", f);
influxSendFrequency(f);
}