|
| 1 | +/* ========================================================================= |
| 2 | + Unity - A Test Framework for C |
| 3 | + ThrowTheSwitch.org |
| 4 | + Copyright (c) 2007-25 Mike Karlesky, Mark VanderVoord, & Greg Williams |
| 5 | + SPDX-License-Identifier: MIT |
| 6 | +========================================================================= */ |
| 7 | + |
| 8 | +#include "ProductionCode.h" |
| 9 | + |
| 10 | +#include <stdint.h> |
| 11 | + |
| 12 | +#ifdef UNIT_TESTING |
| 13 | +#include "unity.h" |
| 14 | +#else |
| 15 | +/* No-Op when not testing */ |
| 16 | +#define UNITY_DETAIL_PUSH |
| 17 | +#define UNITY_DETAIL_POP |
| 18 | +#endif |
| 19 | + |
| 20 | +static void BitExtractor_up(uint8_t input, callback_t cb) |
| 21 | +{ |
| 22 | + int32_t pos; |
| 23 | + UNITY_DETAIL_PUSH(UNITY_DETAIL_CALL, __FUNCTION__); |
| 24 | + for(pos=0; pos<8; pos++) { |
| 25 | + UNITY_DETAIL_PUSH(UNITY_DETAIL_BIT_POS, pos); |
| 26 | + UNITY_DETAIL_PUSH(UNITY_DETAIL_BIT_MASK, 1<<pos); |
| 27 | + cb(pos, !!(input & (1<<pos))); |
| 28 | + UNITY_DETAIL_POP(UNITY_DETAIL_BIT_MASK, 1<<pos); |
| 29 | + UNITY_DETAIL_POP(UNITY_DETAIL_BIT_POS, pos); |
| 30 | + } |
| 31 | + UNITY_DETAIL_POP(UNITY_DETAIL_CALL, __FUNCTION__); |
| 32 | +} |
| 33 | + |
| 34 | +static void BitExtractor_down(uint8_t input, callback_t cb) |
| 35 | +{ |
| 36 | + int32_t pos; |
| 37 | + UNITY_DETAIL_PUSH(UNITY_DETAIL_CALL, __FUNCTION__); |
| 38 | + for(pos=0; pos<8; pos++) { |
| 39 | + UNITY_DETAIL_PUSH(UNITY_DETAIL_BIT_POS, pos); |
| 40 | + UNITY_DETAIL_PUSH(UNITY_DETAIL_BIT_MASK, 0x80>>pos); |
| 41 | + cb(pos, !!(input & (0x80>>pos))); |
| 42 | + UNITY_DETAIL_POP(UNITY_DETAIL_BIT_MASK, 0x80>>pos); |
| 43 | + UNITY_DETAIL_POP(UNITY_DETAIL_BIT_POS, pos); |
| 44 | + } |
| 45 | + UNITY_DETAIL_POP(UNITY_DETAIL_CALL, __FUNCTION__); |
| 46 | +} |
| 47 | +void BitExtractor(bit_direction_t dir, uint8_t input, callback_t cb) |
| 48 | +{ |
| 49 | + UNITY_DETAIL_PUSH(UNITY_DETAIL_CALL, __FUNCTION__); |
| 50 | + if(dir == BIT_DIRECTION_UP) { |
| 51 | + BitExtractor_up(input, cb); |
| 52 | + } else { |
| 53 | + BitExtractor_down(input, cb); |
| 54 | + } |
| 55 | + UNITY_DETAIL_POP(UNITY_DETAIL_CALL, __FUNCTION__); |
| 56 | +} |
0 commit comments