-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a15ed79
commit 165db5a
Showing
12 changed files
with
158 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "proto.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#include "mutex.h" | ||
|
||
void Mutex::lock() { | ||
|
||
} | ||
|
||
void Mutex::unlock() { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#ifndef LIGHT_DETECTOR_MUTEX_H | ||
#define LIGHT_DETECTOR_MUTEX_H | ||
|
||
/** | ||
* Represents mutex implementation for the board. | ||
*/ | ||
class Mutex { | ||
public: | ||
/** | ||
* Attempts to perform lock operation for the mutex. | ||
*/ | ||
static void lock(); | ||
|
||
/** | ||
* Attempts to perform unlock operation for the mutex. | ||
*/ | ||
static void unlock(); | ||
}; | ||
|
||
#endif //LIGHT_DETECTOR_MUTEX_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#include "ring_buffer.h" | ||
|
||
#include <string.h> | ||
|
||
uint16_t RingBuffer_GetFreeSpace(RingBuffer *buf) { | ||
if(buf->tail == buf->head) | ||
return RING_BUFFER_LENGTH - 1; | ||
|
||
if(buf->head > buf->tail) | ||
return RING_BUFFER_LENGTH - ((buf->head - buf->tail) + 1); | ||
else | ||
return (buf->tail - buf->head) - 1; | ||
} | ||
|
||
uint16_t RingBuffer_GetDataLength(RingBuffer *buf) { | ||
return RING_BUFFER_LENGTH - (RingBuffer_GetFreeSpace(buf) + 1); | ||
} | ||
|
||
void RingBuffer_Init(RingBuffer *buf) { | ||
buf->head = buf->tail = 0; | ||
memset(buf->buf, 0, RING_BUFFER_LENGTH); | ||
} | ||
|
||
uint16_t RingBuffer_Read(RingBuffer *buf, uint8_t *data, uint16_t len) { | ||
uint16_t counter = 0; | ||
|
||
while(buf->tail != buf->head && counter < len) { | ||
data[counter++] = buf->buf[buf->tail]; | ||
buf->tail = (buf->tail + 1) % RING_BUFFER_LENGTH; | ||
} | ||
return counter; | ||
} | ||
|
||
uint8_t RingBuffer_Write(RingBuffer *buf, uint8_t *data, uint16_t len) { | ||
uint16_t counter = 0; | ||
uint16_t freeSpace = RingBuffer_GetFreeSpace(buf); | ||
|
||
if(freeSpace == 0) | ||
return RING_BUFFER_FULL; | ||
else if (freeSpace < len) | ||
return RING_BUFFER_NO_SUFFICIENT_SPACE; | ||
|
||
while(counter < len) { | ||
buf->buf[buf->head] = data[counter++]; | ||
buf->head = (buf->head + 1) % RING_BUFFER_LENGTH; | ||
} | ||
return RING_BUFFER_OK; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#ifndef LIGHT_DETECTOR_RING_BUFFER_H | ||
#define LIGHT_DETECTOR_RING_BUFFER_H | ||
|
||
#include <stdint.h> | ||
|
||
#define RING_BUFFER_LENGTH 1000 | ||
|
||
typedef struct { | ||
uint8_t buf[RING_BUFFER_LENGTH]; | ||
#if RING_BUFFER_LENGTH < 255 | ||
uint8_t head, tail; | ||
#else | ||
uint16_t head, tail; | ||
#endif | ||
} RingBuffer; | ||
|
||
typedef enum { | ||
RING_BUFFER_OK = 0x0, | ||
RING_BUFFER_FULL, | ||
RING_BUFFER_NO_SUFFICIENT_SPACE | ||
} RingBuffer_Status; | ||
|
||
uint16_t RingBuffer_GetDataLength(RingBuffer *buf); | ||
uint16_t RingBuffer_GetFreeSpace(RingBuffer *buf); | ||
void RingBuffer_Init(RingBuffer *buf); | ||
uint16_t RingBuffer_Read(RingBuffer *buf, uint8_t *data, uint16_t len); | ||
uint8_t RingBuffer_Write(RingBuffer *buf, uint8_t *data, uint16_t len); | ||
|
||
|
||
#endif //LIGHT_DETECTOR_RING_BUFFER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters