feat: publish FreeRTOS C FC10 card
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
#ifndef TASK01_NOTIFICATIONS_MODEL_H
|
||||
#define TASK01_NOTIFICATIONS_MODEL_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct NotificationEvidence
|
||||
{
|
||||
uint32_t sequence;
|
||||
uint32_t event;
|
||||
uint32_t tick;
|
||||
uint32_t actor;
|
||||
uint32_t value;
|
||||
uint32_t committed;
|
||||
} NotificationEvidence;
|
||||
|
||||
static inline uint32_t fc10_digest( const NotificationEvidence * events,
|
||||
size_t count )
|
||||
{
|
||||
uint32_t hash = 2166136261U;
|
||||
size_t index;
|
||||
|
||||
for( index = 0U; index < count; ++index )
|
||||
{
|
||||
hash = ( hash ^ events[ index ].event ) * 16777619U;
|
||||
hash = ( hash ^ events[ index ].actor ) * 16777619U;
|
||||
hash = ( hash ^ events[ index ].value ) * 16777619U;
|
||||
hash = ( hash ^ events[ index ].committed ) * 16777619U;
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
static inline int fc10_order_is_valid( const NotificationEvidence * events,
|
||||
size_t count )
|
||||
{
|
||||
size_t index;
|
||||
if( events == NULL || count != 12U )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
for( index = 0U; index < count; ++index )
|
||||
{
|
||||
if( events[ index ].sequence != index + 1U ||
|
||||
events[ index ].event != index + 1U ||
|
||||
events[ index ].committed != ( 0xFC100000U | ( index + 1U ) ) )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user