Files @ d429d5902330
Branch filter:

Location: HydroBot/hydrobot-sharedlibs/src/can_buffer.c

matthewreed
Fixed uninitialized variable.
#include "can_buffer.h"

void can_buffer_init(volatile CanBuffer *buffer)
{
    memset((void*)buffer, 0, sizeof(CanBuffer));
}

CanBufferStatus can_buffer_add(volatile CanBuffer *buffer, CanRxMsgTypeDef *msg)
{
    if ((uint16_t) buffer->count < ((uint16_t) CAN_BUFFER_SIZE)) {
        buffer->data[buffer->head] = *msg;
        buffer->head = (buffer->head + 1) % CAN_BUFFER_SIZE;
        buffer->count++;
        return CAN_BUFFER_OK;
    }
    else {
        return CAN_BUFFER_FULL;
    }
}

volatile CanRxMsgTypeDef* can_buffer_remove(volatile CanBuffer *buffer)
{
    volatile CanRxMsgTypeDef* msg = NULL;
    if (buffer->count > 0) {
        msg = &buffer->data[buffer->tail];
        buffer->tail = (buffer->tail + 1) % CAN_BUFFER_SIZE;
        buffer->count--;
    }
    return msg;
}

bool can_buffer_is_empty(volatile CanBuffer *buffer)
{
    return (buffer->count < 1);
}

uint8_t can_buffer_size(volatile CanBuffer *buffer)
{
    return buffer->count;
}