53 lines
1.3 KiB
C
53 lines
1.3 KiB
C
#ifndef TASK01_ISR_SEMAPHORE_MODEL_H
|
|
#define TASK01_ISR_SEMAPHORE_MODEL_H
|
|
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
|
|
typedef struct IsrEvidence
|
|
{
|
|
uint32_t sequence;
|
|
uint32_t event;
|
|
uint32_t tick;
|
|
uint32_t actor;
|
|
uint32_t value;
|
|
uint32_t committed;
|
|
} IsrEvidence;
|
|
|
|
static inline int fc07_order_is_valid( const IsrEvidence * events,
|
|
size_t count )
|
|
{
|
|
size_t index;
|
|
if( count != 9U )
|
|
{
|
|
return 0;
|
|
}
|
|
for( index = 0U; index < count; ++index )
|
|
{
|
|
if( events[ index ].sequence != index + 1U ||
|
|
events[ index ].event != index + 1U ||
|
|
events[ index ].committed !=
|
|
( 0xFC070000U | ( uint32_t ) ( index + 1U ) ) )
|
|
{
|
|
return 0;
|
|
}
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
static inline uint32_t fc07_digest( const IsrEvidence * 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;
|
|
}
|
|
#endif
|