Add initializer and constructor functions for the packet buffer

This commit is contained in:
Savanni D'Gerinel 2022-07-29 14:04:30 -04:00
parent 4aa9598e00
commit bc09a7e411
2 changed files with 32 additions and 2 deletions

View File

@ -1,3 +1,14 @@
/*
Copyright 2022, Savanni D'Gerinel <savanni@luminescent-dreams.com>
This file is part of Savanni's AVR library.
This AVR library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This AVR library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this AVR library. If not, see <https://www.gnu.org/licenses/>.
*/
#include "radio.h" #include "radio.h"
#include "packet.h" #include "packet.h"
@ -7,7 +18,15 @@
size_t circular_next(size_t current, size_t max); size_t circular_next(size_t current, size_t max);
packet_buffer_t *packet_buffer_new() { packet_buffer_t *packet_buffer_new() {
return malloc(sizeof(packet_buffer_t)); packet_buffer_t *buffer = malloc(sizeof(packet_buffer_t));
packet_buffer_init(buffer);
return buffer;
}
void packet_buffer_init(packet_buffer_t *buffer) {
buffer->count = 0;
buffer->bottom = 0;
buffer->top = 0;
} }
packet_t *packet_buffer_enqueue(packet_buffer_t *self, packet_buffer_status_e *status) { packet_t *packet_buffer_enqueue(packet_buffer_t *self, packet_buffer_status_e *status) {

View File

@ -1,9 +1,19 @@
/*
Copyright 2022, Savanni D'Gerinel <savanni@luminescent-dreams.com>
This file is part of Savanni's AVR library.
This AVR library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This AVR library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this AVR library. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef __PACKET_BUFFER_H__ #ifndef __PACKET_BUFFER_H__
#define __PACKET_BUFFER_H__ #define __PACKET_BUFFER_H__
#include "packet.h" #include "packet.h"
#include <stdlib.h>
typedef enum { typedef enum {
packet_buffer_status_ok, packet_buffer_status_ok,
@ -19,6 +29,7 @@ typedef struct {
} packet_buffer_t; } packet_buffer_t;
packet_buffer_t *packet_buffer_new(); packet_buffer_t *packet_buffer_new();
void packet_buffer_init(packet_buffer_t *);
packet_t * packet_buffer_enqueue(packet_buffer_t *, packet_buffer_status_e *); packet_t * packet_buffer_enqueue(packet_buffer_t *, packet_buffer_status_e *);
packet_t * packet_buffer_head(packet_buffer_t *, packet_buffer_status_e *); packet_t * packet_buffer_head(packet_buffer_t *, packet_buffer_status_e *);