Compare commits
7 Commits
73c59c732a
...
main
Author | SHA1 | Date | |
---|---|---|---|
8cbd64034b | |||
99c2f4f0d4 | |||
095fca6b3d | |||
69d537bddd | |||
11146fb632 | |||
52e2c96e0e | |||
17a5b457d6 |
@ -1,3 +1,5 @@
|
||||
#define RINGBUFFER_THREAD_SAFE
|
||||
|
||||
#include <linux/i2c-dev.h>
|
||||
#include <i2c/smbus.h>
|
||||
#include <sys/ioctl.h>
|
||||
@ -9,14 +11,14 @@
|
||||
#include <stdint.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include "global.h"
|
||||
#ifndef RINGBUFFER_H
|
||||
#include "ringbuffer.h"
|
||||
#endif
|
||||
|
||||
#define IIC_DEVICE "/dev/i2c-7"
|
||||
#define BUFFER_BLOCKS 128
|
||||
#define BUFFER_DATA_SIZE 8
|
||||
|
||||
#define HEADING_SIM_UP "sim/autopilot/heading_up"
|
||||
#define HEADING_SIM_DOWN "sim/autopilot/heading_down"
|
||||
@ -31,7 +33,7 @@ struct ringBuffer i2cDataRead;
|
||||
struct ringBuffer i2cDataWrite;
|
||||
|
||||
struct blockData {
|
||||
char data[BUFFER_DATA_SIZE];
|
||||
char data[DATA_SIZE];
|
||||
int triggerBit;
|
||||
};
|
||||
|
||||
|
@ -8,3 +8,4 @@
|
||||
#define TRIGGER_BIT_2 4
|
||||
#define HIGH_BIT_2 8
|
||||
#define I2C_ADDRESS_START 0x08
|
||||
#define DATA_SIZE 8
|
||||
|
@ -1,10 +1,6 @@
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifndef RINGBUFFER_H
|
||||
#include "ringbuffer.h"
|
||||
#endif
|
||||
|
||||
void _ringBufferIncReader(struct ringBuffer *buf) {
|
||||
buf->reader += buf->blockSize;
|
||||
@ -34,32 +30,46 @@ void ringBufferCreate(int blocks, size_t blockSize, struct ringBuffer *out) {
|
||||
out->blockSize = blockSize;
|
||||
out->reader = out->buffer;
|
||||
out->writer = out->buffer;
|
||||
#ifdef RINGBUFFER_THREAD_SAFE
|
||||
pthread_mutex_init(&out->mutex, NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
void ringBufferDestroy(struct ringBuffer *buf) {
|
||||
free(buf->buffer);
|
||||
#ifdef RINGBUFFER_THREAD_SAFE
|
||||
pthread_mutex_destroy(&buf->mutex);
|
||||
#endif
|
||||
}
|
||||
|
||||
int ringBufferRead(struct ringBuffer *buf, void *out) {
|
||||
#ifdef RINGBUFFER_THREAD_SAFE
|
||||
pthread_mutex_lock(&buf->mutex);
|
||||
#endif
|
||||
if (buf->reader != buf->writer) {
|
||||
// we have data to read
|
||||
memcpy(out, buf->reader, buf->blockSize);
|
||||
_ringBufferIncReader(buf);
|
||||
#ifdef RINGBUFFER_THREAD_SAFE
|
||||
pthread_mutex_unlock(&buf->mutex);
|
||||
#endif
|
||||
return 0;
|
||||
} else {
|
||||
// nothing to read
|
||||
#ifdef RINGBUFFER_THREAD_SAFE
|
||||
pthread_mutex_unlock(&buf->mutex);
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
void ringBufferWrite(struct ringBuffer *buf, void *in) {
|
||||
#ifdef RINGBUFFER_THREAD_SAFE
|
||||
pthread_mutex_lock(&buf->mutex);
|
||||
#endif
|
||||
memcpy(buf->writer, in, buf->blockSize);
|
||||
_ringBufferIncWriter(buf);
|
||||
#ifdef RINGBUFFER_THREAD_SAFE
|
||||
pthread_mutex_unlock(&buf->mutex);
|
||||
#endif
|
||||
}
|
||||
|
@ -1,4 +1,12 @@
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef RINGBUFFER_THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
|
||||
#define RINGBUFFER_H
|
||||
|
||||
struct ringBuffer {
|
||||
void *buffer;
|
||||
@ -6,7 +14,9 @@ struct ringBuffer {
|
||||
size_t blockSize;
|
||||
void *reader;
|
||||
void *writer;
|
||||
#ifdef RINGBUFFER_THREAD_SAFE
|
||||
pthread_mutex_t mutex;
|
||||
#endif
|
||||
};
|
||||
|
||||
void ringBufferCreate(int blocks, size_t blockSize, struct ringBuffer *out);
|
||||
|
@ -2,6 +2,11 @@
|
||||
* two rotators
|
||||
* two displays
|
||||
|
||||
## required libraries
|
||||
* https://github.com/adafruit/Adafruit_SSD1306/
|
||||
* https://github.com/adafruit/Adafruit-GFX-Library
|
||||
* https://github.com/adafruit/Adafruit_BusIO
|
||||
|
||||
## PINs
|
||||
* IDE = Physical = Usage
|
||||
* x = 1 = reset (connecto to master)
|
||||
|
@ -51,6 +51,11 @@ uint8_t lastClk = HIGH;
|
||||
byte valueBuffer[VALUE_BUFFER] = { 0 };
|
||||
uint8_t readerPos, writerPos = 0;
|
||||
|
||||
// ringbuffer of display data
|
||||
struct {
|
||||
|
||||
}
|
||||
|
||||
void addValue(uint8_t value) {
|
||||
valueBuffer[writerPos++] = value;
|
||||
|
||||
|
Reference in New Issue
Block a user