Set blackbox file handler to NULL after closing file
[inav.git] / src / main / drivers / sdcard / sdcard_standard.c
blob00fb770ff14c83c729f0ee91a52e1f05773dc221
1 #include <stdint.h>
3 #include "sdcard_standard.h"
5 #define MIN(a, b) ((a) < (b) ? (a) : (b))
7 /**
8 * Read a bitfield from an array of bits (the bit at index 0 being the most-significant bit of the first byte in
9 * the buffer).
11 uint32_t readBitfield(uint8_t *buffer, unsigned bitIndex, unsigned bitLen)
13 uint32_t result = 0;
14 unsigned bitInByteOffset = bitIndex % 8;
15 uint8_t bufferByte;
17 buffer += bitIndex / 8;
19 // Align the bitfield to be read to the top of the buffer
20 bufferByte = *buffer << bitInByteOffset;
22 while (bitLen > 0) {
23 unsigned bitsThisLoop = MIN(8 - bitInByteOffset, bitLen);
25 result = (result << bitsThisLoop) | (bufferByte >> (8 - bitsThisLoop));
27 buffer++;
28 bufferByte = *buffer;
30 bitLen -= bitsThisLoop;
31 bitInByteOffset = 0;
34 return result;