diff --git a/C/C3 Watch/.~lock.Watch-Registers-Assignment.docx# b/C/C3 Watch/.~lock.Watch-Registers-Assignment.docx# new file mode 100644 index 0000000..ab60b5b --- /dev/null +++ b/C/C3 Watch/.~lock.Watch-Registers-Assignment.docx# @@ -0,0 +1 @@ +,rens,hp-arch,05.06.2025 15:24,file:///home/rens/.config/libreoffice/4; \ No newline at end of file diff --git a/C/C5 and C6 Adidas/build/main_test b/C/C5 and C6 Adidas/build/main_test index 6115af8..66699e7 100755 Binary files a/C/C5 and C6 Adidas/build/main_test and b/C/C5 and C6 Adidas/build/main_test differ diff --git a/C/C5 and C6 Adidas/shared/bit_stuff.c b/C/C5 and C6 Adidas/shared/bit_stuff.c deleted file mode 100644 index 29a4a08..0000000 --- a/C/C5 and C6 Adidas/shared/bit_stuff.c +++ /dev/null @@ -1,40 +0,0 @@ -#include "bit_stuff.h" -#include -#include - -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); -} \ No newline at end of file diff --git a/C/C5 and C6 Adidas/shared/bit_stuff.h b/C/C5 and C6 Adidas/shared/bit_stuff.h deleted file mode 100644 index 9326db1..0000000 --- a/C/C5 and C6 Adidas/shared/bit_stuff.h +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once - -#include - -/* 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); diff --git a/C/C5 and C6 Adidas/shared/decode.c b/C/C5 and C6 Adidas/shared/decode.c index dff285a..9568e05 100644 --- a/C/C5 and C6 Adidas/shared/decode.c +++ b/C/C5 and C6 Adidas/shared/decode.c @@ -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; } diff --git a/C/C5 and C6 Adidas/shared/encode.c b/C/C5 and C6 Adidas/shared/encode.c index c2eef0d..13408b9 100644 --- a/C/C5 and C6 Adidas/shared/encode.c +++ b/C/C5 and C6 Adidas/shared/encode.c @@ -1,6 +1,5 @@ #include "encode.h" #include "parity.h" -#include "bit_stuff.h" #include #include #include @@ -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) { diff --git a/C/C5 and C6 Adidas/test/decode_test.c b/C/C5 and C6 Adidas/test/decode_test.c index 6e608a0..b527b3f 100644 --- a/C/C5 and C6 Adidas/test/decode_test.c +++ b/C/C5 and C6 Adidas/test/decode_test.c @@ -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(); } diff --git a/C/C6 Adidas.zip b/C/C6 Adidas.zip new file mode 100644 index 0000000..e39b60d Binary files /dev/null and b/C/C6 Adidas.zip differ