mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2026-01-25 01:11:36 +01:00
Add example
This commit is contained in:
56
examples/example_5/src/ProductionCode.c
Normal file
56
examples/example_5/src/ProductionCode.c
Normal file
@@ -0,0 +1,56 @@
|
||||
/* =========================================================================
|
||||
Unity - A Test Framework for C
|
||||
ThrowTheSwitch.org
|
||||
Copyright (c) 2007-25 Mike Karlesky, Mark VanderVoord, & Greg Williams
|
||||
SPDX-License-Identifier: MIT
|
||||
========================================================================= */
|
||||
|
||||
#include "ProductionCode.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef UNIT_TESTING
|
||||
#include "unity.h"
|
||||
#else
|
||||
/* No-Op when not testing */
|
||||
#define UNITY_DETAIL_PUSH
|
||||
#define UNITY_DETAIL_POP
|
||||
#endif
|
||||
|
||||
static void BitExtractor_up(uint8_t input, callback_t cb)
|
||||
{
|
||||
int32_t pos;
|
||||
UNITY_DETAIL_PUSH(UNITY_DETAIL_CALL, __FUNCTION__);
|
||||
for(pos=0; pos<8; pos++) {
|
||||
UNITY_DETAIL_PUSH(UNITY_DETAIL_BIT_POS, pos);
|
||||
UNITY_DETAIL_PUSH(UNITY_DETAIL_BIT_MASK, 1<<pos);
|
||||
cb(pos, !!(input & (1<<pos)));
|
||||
UNITY_DETAIL_POP(UNITY_DETAIL_BIT_MASK, 1<<pos);
|
||||
UNITY_DETAIL_POP(UNITY_DETAIL_BIT_POS, pos);
|
||||
}
|
||||
UNITY_DETAIL_POP(UNITY_DETAIL_CALL, __FUNCTION__);
|
||||
}
|
||||
|
||||
static void BitExtractor_down(uint8_t input, callback_t cb)
|
||||
{
|
||||
int32_t pos;
|
||||
UNITY_DETAIL_PUSH(UNITY_DETAIL_CALL, __FUNCTION__);
|
||||
for(pos=0; pos<8; pos++) {
|
||||
UNITY_DETAIL_PUSH(UNITY_DETAIL_BIT_POS, pos);
|
||||
UNITY_DETAIL_PUSH(UNITY_DETAIL_BIT_MASK, 0x80>>pos);
|
||||
cb(pos, !!(input & (0x80>>pos)));
|
||||
UNITY_DETAIL_POP(UNITY_DETAIL_BIT_MASK, 0x80>>pos);
|
||||
UNITY_DETAIL_POP(UNITY_DETAIL_BIT_POS, pos);
|
||||
}
|
||||
UNITY_DETAIL_POP(UNITY_DETAIL_CALL, __FUNCTION__);
|
||||
}
|
||||
void BitExtractor(bit_direction_t dir, uint8_t input, callback_t cb)
|
||||
{
|
||||
UNITY_DETAIL_PUSH(UNITY_DETAIL_CALL, __FUNCTION__);
|
||||
if(dir == BIT_DIRECTION_UP) {
|
||||
BitExtractor_up(input, cb);
|
||||
} else {
|
||||
BitExtractor_down(input, cb);
|
||||
}
|
||||
UNITY_DETAIL_POP(UNITY_DETAIL_CALL, __FUNCTION__);
|
||||
}
|
||||
Reference in New Issue
Block a user