-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7bbe23f
commit de22fcf
Showing
3 changed files
with
190 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#ifndef __CRC8_H_ | ||
#define __CRC8_H_ | ||
|
||
#include <heisen/typing.h> | ||
|
||
/* see usage of this value in crc8() description */ | ||
#define CRC8_INIT_VALUE 0xFF | ||
|
||
/* | ||
* Return value of crc8() indicating valid message+crc. This is true | ||
* if a CRC is inverted before transmission. The CRC computed over the | ||
* whole received bitstream is _table[x], where x is the bit pattern | ||
* of the modification (almost always 0xff). | ||
*/ | ||
#define CRC8_GOOD_VALUE(_table) (_table[0xFF]) | ||
|
||
/* required table size for crc8 algorithm */ | ||
#define CRC8_TABLE_SIZE 256 | ||
|
||
/* helper macro assuring right table size is used */ | ||
#define DECLARE_CRC8_TABLE(_table) \ | ||
static uint8_t _table[CRC8_TABLE_SIZE] | ||
|
||
/** | ||
* crc8_populate_lsb - fill crc table for given polynomial in regular bit order. | ||
* | ||
* @table: table to be filled. | ||
* @polynomial: polynomial for which table is to be filled. | ||
* | ||
* This function fills the provided table according the polynomial provided for | ||
* regular bit order (lsb first). Polynomials in CRC algorithms are typically | ||
* represented as shown below. | ||
* | ||
* poly = x^8 + x^7 + x^6 + x^4 + x^2 + 1 | ||
* | ||
* For lsb first direction x^7 maps to the lsb. So the polynomial is as below. | ||
* | ||
* - lsb first: poly = 10101011(1) = 0xAB | ||
*/ | ||
void crc8_populate_lsb(uint8_t table[CRC8_TABLE_SIZE], uint8_t polynomial); | ||
|
||
/** | ||
* crc8_populate_msb - fill crc table for given polynomial in reverse bit order. | ||
* | ||
* @table: table to be filled. | ||
* @polynomial: polynomial for which table is to be filled. | ||
* | ||
* This function fills the provided table according the polynomial provided for | ||
* reverse bit order (msb first). Polynomials in CRC algorithms are typically | ||
* represented as shown below. | ||
* | ||
* poly = x^8 + x^7 + x^6 + x^4 + x^2 + 1 | ||
* | ||
* For msb first direction x^7 maps to the msb. So the polynomial is as below. | ||
* | ||
* - msb first: poly = (1)11010101 = 0xD5 | ||
*/ | ||
void crc8_populate_msb(uint8_t table[CRC8_TABLE_SIZE], uint8_t polynomial); | ||
|
||
/** | ||
* crc8() - calculate a crc8 over the given input data. | ||
* | ||
* @table: crc table used for calculation. | ||
* @pdata: pointer to data buffer. | ||
* @nbytes: number of bytes in data buffer. | ||
* @crc: previous returned crc8 value. | ||
* | ||
* The CRC8 is calculated using the polynomial given in crc8_populate_msb() | ||
* or crc8_populate_lsb(). | ||
* | ||
* The caller provides the initial value (either %CRC8_INIT_VALUE | ||
* or the previous returned value) to allow for processing of | ||
* discontiguous blocks of data. When generating the CRC the | ||
* caller is responsible for complementing the final return value | ||
* and inserting it into the byte stream. When validating a byte | ||
* stream (including CRC8), a final return value of %CRC8_GOOD_VALUE | ||
* indicates the byte stream data can be considered valid. | ||
* | ||
* Reference: | ||
* "A Painless Guide to CRC Error Detection Algorithms", ver 3, Aug 1993 | ||
* Williams, Ross N., ross<at>ross.net | ||
* (see URL http://www.ross.net/crc/download/crc_v3.txt). | ||
*/ | ||
uint8_t crc8(const uint8_t table[CRC8_TABLE_SIZE], const uint8_t *pdata, size_t nbytes, uint8_t crc); | ||
|
||
#endif /* __CRC8_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#ifndef _UAPI_HEISEN_STDDEF_H | ||
#define _UAPI_HEISEN_STDDEF_H | ||
|
||
#include <heisen/compiler.h> | ||
|
||
#ifndef __always_inline | ||
#define __always_inline inline | ||
#endif | ||
|
||
|
||
|
||
/** | ||
* __struct_group() - Create a mirrored named and anonyomous struct | ||
* | ||
* @TAG: The tag name for the named sub-struct (usually empty) | ||
* @NAME: The identifier name of the mirrored sub-struct | ||
* @ATTRS: Any struct attributes (usually empty) | ||
* @MEMBERS: The member declarations for the mirrored structs | ||
* | ||
* Used to create an anonymous union of two structs with identical layout | ||
* and size: one anonymous and one named. The former's members can be used | ||
* normally without sub-struct naming, and the latter can be used to | ||
* reason about the start, end, and size of the group of struct members. | ||
* The named struct can also be explicitly tagged for layer reuse, as well | ||
* as both having struct attributes appended. | ||
*/ | ||
#define __struct_group(TAG, NAME, ATTRS, MEMBERS...) \ | ||
union { \ | ||
struct { MEMBERS } ATTRS; \ | ||
struct TAG { MEMBERS } ATTRS NAME; \ | ||
} ATTRS | ||
|
||
#ifdef __cplusplus | ||
/* sizeof(struct{}) is 1 in C++, not 0, can't use C version of the macro. */ | ||
#define __DECLARE_FLEX_ARRAY(T, member) \ | ||
T member[0] | ||
#else | ||
/** | ||
* __DECLARE_FLEX_ARRAY() - Declare a flexible array usable in a union | ||
* | ||
* @TYPE: The type of each flexible array element | ||
* @NAME: The name of the flexible array member | ||
* | ||
* In order to have a flexible array member in a union or alone in a | ||
* struct, it needs to be wrapped in an anonymous struct with at least 1 | ||
* named member, but that member can be empty. | ||
*/ | ||
#define __DECLARE_FLEX_ARRAY(TYPE, NAME) \ | ||
struct { \ | ||
struct { } __empty_ ## NAME; \ | ||
TYPE NAME[]; \ | ||
} | ||
#endif | ||
|
||
#ifndef __counted_by | ||
#define __counted_by(m) | ||
#endif | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
|
||
/** | ||
* MIT License | ||
* | ||
* Copyright (c) 2024 Heisenberg | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* @author Heisenberg | ||
* @file smt.h | ||
*/ | ||
#ifndef _UAPI_HESIEN_STM_H | ||
#define _UAPI_HESIEN_STM_H | ||
/* | ||
SMT stands for Simultaneous Multi-Threading. It is a technology that allows multiple threads to run concurrently on a single processor core*/ | ||
|
||
#include <heisen/typing.h> | ||
|
||
|
||
#define STP_MASTER_MASK 0xffff | ||
#define STP_CHANNEL_MAX 0xffff | ||
|
||
struct stp_policy_id{ | ||
uint32_t size; | ||
uint16_t master; | ||
uint16_t channel; | ||
uint16_t width; | ||
/*padding*/ | ||
uint16_t __reserved_0; | ||
uint32_t __reserved_1; | ||
char id[]; | ||
}; | ||
|
||
#define STP_POLICY_ID_SET _IOWR('%', 0, struct stp_policy_id) | ||
#define STP_POLICY_ID_GET _IOR('%', 1, struct stp_policy_id) | ||
#define STP_SET_OPTIONS _IOW('%', 2, __u64) | ||
|
||
|
||
#endif // _UAPI_HESIEN_STM_H |