mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
sys/tsrb: add tsrb_clear
This commit is contained in:
parent
c84a40abc4
commit
de4b32ef54
@ -67,6 +67,17 @@ static inline void tsrb_init(tsrb_t *rb, uint8_t *buffer, unsigned bufsize)
|
|||||||
rb->writes = 0;
|
rb->writes = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Clear a tsrb.
|
||||||
|
* @param[out] rb Ringbuffer to operate on
|
||||||
|
*/
|
||||||
|
static inline void tsrb_clear(tsrb_t *rb)
|
||||||
|
{
|
||||||
|
unsigned irq_state = irq_disable();
|
||||||
|
rb->reads = rb->writes;
|
||||||
|
irq_restore(irq_state);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Test if the tsrb is empty.
|
* @brief Test if the tsrb is empty.
|
||||||
* @param[in] rb Ringbuffer to operate on
|
* @param[in] rb Ringbuffer to operate on
|
||||||
|
@ -37,6 +37,20 @@ static void tear_down(void)
|
|||||||
tsrb_init(&_tsrb, _tsrb_buffer, BUFFER_SIZE);
|
tsrb_init(&_tsrb, _tsrb_buffer, BUFFER_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_clear(void)
|
||||||
|
{
|
||||||
|
TEST_ASSERT_EQUAL_INT(0, tsrb_avail(&_tsrb));
|
||||||
|
|
||||||
|
for (int i = 0; i < BUFFER_SIZE; i++) {
|
||||||
|
TEST_ASSERT_EQUAL_INT(0, tsrb_add_one(&_tsrb, TEST_INPUT));
|
||||||
|
TEST_ASSERT_EQUAL_INT(i + 1, tsrb_avail(&_tsrb));
|
||||||
|
}
|
||||||
|
|
||||||
|
tsrb_clear(&_tsrb);
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL_INT(0, tsrb_avail(&_tsrb));
|
||||||
|
}
|
||||||
|
|
||||||
static void test_empty(void)
|
static void test_empty(void)
|
||||||
{
|
{
|
||||||
TEST_ASSERT_EQUAL_INT(1, tsrb_empty(&_tsrb));
|
TEST_ASSERT_EQUAL_INT(1, tsrb_empty(&_tsrb));
|
||||||
@ -202,6 +216,7 @@ static void test_add(void)
|
|||||||
static Test *tests_tsrb_tests(void)
|
static Test *tests_tsrb_tests(void)
|
||||||
{
|
{
|
||||||
EMB_UNIT_TESTFIXTURES(fixtures) {
|
EMB_UNIT_TESTFIXTURES(fixtures) {
|
||||||
|
new_TestFixture(test_clear),
|
||||||
new_TestFixture(test_empty),
|
new_TestFixture(test_empty),
|
||||||
new_TestFixture(test_avail),
|
new_TestFixture(test_avail),
|
||||||
new_TestFixture(test_full),
|
new_TestFixture(test_full),
|
||||||
|
Loading…
Reference in New Issue
Block a user