Files
charge-controller-firmware/src/ext/can_msg_queue.cpp
T
Martin Jäger 2a71d02aeb Move PCB and user config to board Kconfig
Files in src/pcbs/xyz.h are moved to boards/xyz/board.h. User settings from
src/config.h are also configured via Kconfig, so the file is removed.
2020-04-30 10:53:58 +02:00

70 lines
1.1 KiB
C++

/*
* Copyright (c) 2017 Martin Jäger / Libre Solar
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef UNIT_TEST
#if CONFIG_EXT_THINGSET_CAN
#include "ext/can_msg_queue.h"
bool CanMsgQueue::full()
{
return _length == CAN_QUEUE_SIZE;
}
bool CanMsgQueue::empty()
{
return _length == 0;
}
void CanMsgQueue::enqueue(CanFrame frame)
{
if (!full()) {
_queue[(_first + _length) % CAN_QUEUE_SIZE] = frame;
_length++;
}
}
int CanMsgQueue::dequeue()
{
if (!empty()) {
_first = (_first + 1) % CAN_QUEUE_SIZE;
_length--;
return 1;
}
else {
return 0;
}
}
int CanMsgQueue::dequeue(CanFrame &frame)
{
if (!empty()) {
frame = _queue[_first];
_first = (_first + 1) % CAN_QUEUE_SIZE;
_length--;
return 1;
}
else {
return 0;
}
}
int CanMsgQueue::first(CanFrame &frame)
{
if (!empty()) {
frame = _queue[_first];
return 1;
}
else {
return 0;
}
}
#endif /* CONFIG_EXT_THINGSET_CAN */
#endif /* UNIT_TEST */