diff options
author | Fred Sundvik <fsundvik@gmail.com> | 2016-02-21 18:30:04 +0200 |
---|---|---|
committer | Fred Sundvik <fsundvik@gmail.com> | 2016-02-21 18:30:04 +0200 |
commit | 2710361cd818aae6dd349fa433ebff365908de06 (patch) | |
tree | bd9be3408d5fcc629f66d4b09c6f464ff00eb989 /serial_link/protocol/triple_buffered_object.c | |
parent | 679bfe7c5452f69a790e648c7661bbbdb12ce4ae (diff) |
Change the triple buffer object interface
Diffstat (limited to 'serial_link/protocol/triple_buffered_object.c')
-rw-r--r-- | serial_link/protocol/triple_buffered_object.c | 32 |
1 files changed, 8 insertions, 24 deletions
diff --git a/serial_link/protocol/triple_buffered_object.c b/serial_link/protocol/triple_buffered_object.c index 3fabb7d84b..6b3cf75adf 100644 --- a/serial_link/protocol/triple_buffered_object.c +++ b/serial_link/protocol/triple_buffered_object.c @@ -43,7 +43,7 @@ void triple_buffer_init(triple_buffer_object_t* object) { SET_DATA_AVAILABLE(0); } -static bool triple_buffer_begin_read(uint16_t object_size, triple_buffer_object_t* object) { +void* triple_buffer_read_internal(uint16_t object_size, triple_buffer_object_t* object) { serial_link_lock(); if (GET_DATA_AVAILABLE()) { uint8_t shared_index = GET_SHARED_INDEX(); @@ -52,41 +52,25 @@ static bool triple_buffer_begin_read(uint16_t object_size, triple_buffer_object_ SET_SHARED_INDEX(read_index); SET_DATA_AVAILABLE(false); serial_link_unlock(); - return true; + return object->buffer + object_size * shared_index; } else { serial_link_unlock(); - return false; + return NULL; } } -static void triple_buffer_actual_read(uint16_t object_size, triple_buffer_object_t* object, void* dst) { - uint8_t read_index = GET_READ_INDEX(); - memcpy(dst, object->buffer + object_size*read_index, object_size); -} - -static void triple_buffer_end_read(uint16_t object_size, triple_buffer_object_t* object) { +void* triple_buffer_begin_write_internal(uint16_t object_size, triple_buffer_object_t* object) { + uint8_t write_index = GET_WRITE_INDEX(); + return object->buffer + object_size * write_index; } -void triple_buffer_write(uint16_t object_size, triple_buffer_object_t* object, void* src) { - - uint8_t write_index = GET_WRITE_INDEX(); - memcpy(object->buffer + object_size * write_index, src, object_size); +void triple_buffer_end_write_internal(triple_buffer_object_t* object) { serial_link_lock(); uint8_t shared_index = GET_SHARED_INDEX(); + uint8_t write_index = GET_WRITE_INDEX(); SET_SHARED_INDEX(write_index); SET_WRITE_INDEX(shared_index); SET_DATA_AVAILABLE(true); serial_link_unlock(); } - -bool triple_buffer_read(uint16_t object_size, triple_buffer_object_t* object, void* dst) { - if (triple_buffer_begin_read(object_size, object)) { - triple_buffer_actual_read(object_size, object, dst); - triple_buffer_end_read(object_size, object); - return true; - } - else { - return false; - } -} |