This commit is contained in:
Rens Pastoor
2025-05-27 22:41:46 +02:00
parent d141296aea
commit 11b391b8a1
416 changed files with 25232 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
#ifndef CHANNEL_H
#define CHANNEL_H
#include <stdint.h>
/*!
* Initialiase the channel module
*/
void channel_init();
/*!
* Randomly invert one the bits of the input 'value' parameter
*
* @param value: A byte
*
* @return: The input 'value' where on of the bits is randomly inverted
*/
uint8_t channel_change_one_random_bit(uint8_t value);
#endif

View File

@@ -0,0 +1,29 @@
#ifndef DECODE_H_
#define DECODE_H_
#include <stdint.h>
/*!
* Combines the nibbles located at the 4-least-significant bits of
* parameters 'low' and 'high' into one byte.
*
* @param high: A nibble that contains the 4 most-significant bits
* @param low: A nibble that contains the 4 most-significant bits
*
* @return: A byte that combines the high and low nibble.
*/
uint8_t decode_combine_nibbles(uint8_t high, uint8_t low);
/*!
* Decodes a nibble from a byte that contains the nible (4-bits) and
* corresponding parity bits (3-bits). See assignment for more details.
*
* @param in: A bytes that contains a nibble and parity bits.
* @param nibble: The address to which the decoded nibble
* of 'in' will be written.
*
*/
void decode_byte(uint8_t in, uint8_t* nibble);
#endif

View File

@@ -0,0 +1,27 @@
#include "encode.h"
#include "parity.h"
#include <stdint.h>
#include <stddef.h>
void encode_get_nibbles(uint8_t value, uint8_t* high, uint8_t* low) {
if (high == NULL || low == NULL) {
return;
}
*high = (value >> 4) & 0x0F; // bits 7-4
*low = value & 0x0F; // bits 3-0
}
void encode_value(uint8_t input, uint8_t* high, uint8_t* low) {
if (high == NULL || low == NULL) {
return;
}
uint8_t nibble_high, nibble_low;
// Splits input-byte in twee nibbles
encode_get_nibbles(input, &nibble_high, &nibble_low);
// Voeg pariteitsbits toe
*high = add_parity(nibble_high);
*low = add_parity(nibble_low);
}

View File

@@ -0,0 +1,32 @@
#ifndef ENCODE_H_
#define ENCODE_H_
#include <stdbool.h>
#include <stdint.h>
/*!
* Split a byte 'value' into two nibbles (4-bits) named 'low' and 'high'.
* See assignment for more details.
*
* @param value: A byte that will be encoded.
* @param low: The address to which the 4 least-significant-bits
* of 'value' will be written.
* @param high: The address to which the 4 most-significant-bits
* of 'value' will be written.
*/
void encode_get_nibbles(uint8_t value, uint8_t* high, uint8_t* low);
/*!
* Encodes a the byte 'value' into two bytes named 'low' and 'high'.
* The encoded bytes contain the parity bits. See assignment for more details.
*
* @param value: A byte that will be encoded.
* @param low: The address to which the encoded value of the
* 4 least-significant-bits of 'value' will be written.
* @param high: The address to which the encoded value of the
* 4 most-significant-bits of 'value' will be written.
*/
void encode_value(uint8_t input, uint8_t* high, uint8_t* low);
#endif

View File

@@ -0,0 +1,16 @@
#include "parity.h"
uint8_t add_parity(uint8_t nibble) {
uint8_t d0 = (nibble >> 0) & 1;
uint8_t d1 = (nibble >> 1) & 1;
uint8_t d2 = (nibble >> 2) & 1;
uint8_t d3 = (nibble >> 3) & 1;
// Stel pariteitsbits samen (voorbeeld: p0 = even(d0, d1, d3), etc.)
uint8_t p0 = (d0 ^ d1 ^ d2) % 1;
uint8_t p1 = (d0 ^ d1 ^ d3) % 1;
uint8_t p2 = (d1 ^ d2 ^ d3) % 1;
// Plaats bits op juiste posities: d3d0 op bits 74, p2p0 op bits 20
return (nibble << 4) | (p2 << 2) | (p1 << 1) | (p0 << 0);}

View File

@@ -0,0 +1,8 @@
#ifndef PARITY_H
#define PARITY_H
#include <stdint.h>
uint8_t add_parity(uint8_t nibble);
#endif