removed bit_stuff from adidas so v1.1
This commit is contained in:
1
C/C3 Watch/.~lock.Watch-Registers-Assignment.docx#
Normal file
1
C/C3 Watch/.~lock.Watch-Registers-Assignment.docx#
Normal file
@@ -0,0 +1 @@
|
||||
,rens,hp-arch,05.06.2025 15:24,file:///home/rens/.config/libreoffice/4;
|
||||
Binary file not shown.
@@ -1,40 +0,0 @@
|
||||
#include "bit_stuff.h"
|
||||
#include <limits.h>
|
||||
#include <stddef.h>
|
||||
|
||||
unsigned int count_ones(unsigned int value){
|
||||
unsigned int count = 0;
|
||||
while (value){
|
||||
count += value & 1;
|
||||
value >>= 1;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
void make_bitmask(unsigned int width, unsigned int shift, unsigned int* mask){
|
||||
if (width == 0 || width > sizeof(unsigned int)*CHAR_BIT) return;
|
||||
if (width == sizeof(unsigned int) * CHAR_BIT) *mask = ~0U << shift;
|
||||
else *mask = ((1U << width) - 1) << shift;
|
||||
}
|
||||
|
||||
void apply_bitmask(unsigned int value, unsigned int mask, unsigned int* masked_value) {
|
||||
if (masked_value != NULL) {
|
||||
*masked_value = value & mask;
|
||||
}
|
||||
}
|
||||
|
||||
void flip_bit(unsigned int value, unsigned int bit_index, unsigned int* updated_value){
|
||||
if (updated_value == 0 || bit_index >= sizeof(unsigned int) * CHAR_BIT) return;
|
||||
*updated_value = value ^ (1U << bit_index);
|
||||
}
|
||||
|
||||
void extract_nibbles_from_byte(uint8_t value, uint8_t* high_nibble, uint8_t* low_nibble){
|
||||
if (high_nibble == NULL || low_nibble == NULL) return;
|
||||
*high_nibble = (value >> 4) & 0xF;
|
||||
*low_nibble = value & 0xF;
|
||||
}
|
||||
|
||||
void combine_nibles_to_byte(uint8_t high_nibble, uint8_t low_nibble, uint8_t* value){
|
||||
if (value == NULL) return;
|
||||
*value = (high_nibble << 4) | (low_nibble);
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/* pre : -
|
||||
* post: the number of bits with value 1 is counted and returned
|
||||
*/
|
||||
unsigned int count_ones(unsigned int value);
|
||||
|
||||
/* pre : -
|
||||
* post: a bitmask with a given width and a given shift is generated (so w=5 and
|
||||
* s=1 gives 00111110)
|
||||
*/
|
||||
void make_bitmask(unsigned int width, unsigned int shift, unsigned int* mask);
|
||||
|
||||
/* pre : -
|
||||
* post: 'masked_value' is assigned the value of 'value' with the 'mask' applied
|
||||
*/
|
||||
void apply_bitmask(unsigned int value, unsigned int mask, unsigned int* masked_value);
|
||||
|
||||
/* pre : -
|
||||
* post: the bit of index 'bit_index' of 'value' is flipped: 0 --> 1, 1 --> 0.
|
||||
*/
|
||||
void flip_bit(unsigned int value, unsigned int bit_index, unsigned int* updated_value);
|
||||
|
||||
/* pre : -
|
||||
* post: the high and low nibbles of 'value' of stored in 'high_nibble' and
|
||||
* 'low_nibble'.
|
||||
*/
|
||||
void extract_nibbles_from_byte(uint8_t value, uint8_t* high_nibble, uint8_t* low_nibbe);
|
||||
|
||||
/* pre : -
|
||||
* post: the nibble values of the 'high_nibble' and 'low_nibble' are combined
|
||||
* and stored in 'value'
|
||||
*/
|
||||
void combine_nibles_to_byte(uint8_t high_nibble, uint8_t low_nibbe, uint8_t* value);
|
||||
@@ -1,5 +1,4 @@
|
||||
#include "decode.h"
|
||||
#include "bit_stuff.h"
|
||||
|
||||
uint8_t decode_combine_nibbles(uint8_t high, uint8_t low){
|
||||
uint8_t byte;
|
||||
@@ -7,7 +6,7 @@ uint8_t decode_combine_nibbles(uint8_t high, uint8_t low){
|
||||
uint8_t low_nibble;
|
||||
decode_byte(high,&high_nibble);
|
||||
decode_byte(low,&low_nibble);
|
||||
combine_nibles_to_byte(high_nibble, low_nibble, &byte);
|
||||
byte = (high_nibble << 4) | (low_nibble);
|
||||
return byte;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#include "encode.h"
|
||||
#include "parity.h"
|
||||
#include "bit_stuff.h"
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
@@ -10,7 +9,8 @@ void encode_get_nibbles(uint8_t value, uint8_t* high, uint8_t* low) {
|
||||
return;
|
||||
}
|
||||
// Just extract the nibbles without encoding them
|
||||
extract_nibbles_from_byte(value, high, low);
|
||||
*high = (value >> 4) & 0xF;
|
||||
*low = value & 0xF;
|
||||
}
|
||||
|
||||
uint8_t encode_nibble(uint8_t nibble) {
|
||||
|
||||
@@ -52,6 +52,14 @@ void test_decode_parity_flip(void){
|
||||
TEST_ASSERT_EQUAL(0xD, right_data); // so the result should be 0b01101100 or 0xD
|
||||
}
|
||||
//
|
||||
// mutiple bit flip test
|
||||
void test_decode_multi_bit_flip(void){
|
||||
uint8_t wrong_data = 0b01111101; // this should be 0b01101100 or unparityd 0b1101, 0xD
|
||||
uint8_t right_data; // this is the correct data
|
||||
decode_byte(wrong_data, &right_data);
|
||||
TEST_ASSERT_NOT_EQUAL(0xD, right_data); // so the result should be 0b01101100 or 0xD
|
||||
}
|
||||
//
|
||||
void run_decode_tests(){
|
||||
UnityRegisterSetupTearDown(decode_setUp, decode_tearDown);
|
||||
|
||||
@@ -60,6 +68,9 @@ void run_decode_tests(){
|
||||
MY_RUN_TEST(test_decode_get_nibbles_all_ones);
|
||||
MY_RUN_TEST(test_decode_MSB_flip);
|
||||
MY_RUN_TEST(test_decode_databit_flip);
|
||||
MY_RUN_TEST(test_decode_common_databit_flip);
|
||||
MY_RUN_TEST(test_decode_parity_flip);
|
||||
MY_RUN_TEST(test_decode_multi_bit_flip);
|
||||
|
||||
UnityUnregisterSetupTearDown();
|
||||
}
|
||||
|
||||
BIN
C/C6 Adidas.zip
Normal file
BIN
C/C6 Adidas.zip
Normal file
Binary file not shown.
Reference in New Issue
Block a user