Repo unification
This commit is contained in:
81
firmware/src/hw/board/utils/fuses.c
Normal file
81
firmware/src/hw/board/utils/fuses.c
Normal file
@@ -0,0 +1,81 @@
|
||||
/**** Includes ****/
|
||||
#include "fuses.h"
|
||||
#include "utils.h"
|
||||
|
||||
/**** Private definitions ****/
|
||||
/**** Private constants ****/
|
||||
/**** Private variables ****/
|
||||
/**** Mapping function declarations ****/
|
||||
/**** Private function declarations ****/
|
||||
/**** Public function definitions ****/
|
||||
#ifdef TESTING
|
||||
#endif
|
||||
|
||||
void fuse_reset(fuse_t* fuse)
|
||||
{
|
||||
fuse->state = FUSE_OFF;
|
||||
fuse->timer = 0;
|
||||
fuse->count = 0;
|
||||
}
|
||||
|
||||
uint8_t fuse_process(fuse_t* fuse, uint8_t fault, fuse_cfg_t* cfg)
|
||||
{
|
||||
// Active fault condition
|
||||
if(fault)
|
||||
{
|
||||
// Note fuse time count
|
||||
if((fuse->state == FUSE_OFF)||(fuse->state == FUSE_RETRY)) fuse->count++;
|
||||
|
||||
// Go to fused state in any case
|
||||
fuse->state = FUSE_ACTIVE;
|
||||
fuse->timer = 0;
|
||||
return 1;
|
||||
};
|
||||
|
||||
// No active fault condition
|
||||
if(fuse->state==FUSE_ACTIVE)
|
||||
{
|
||||
// Go to cooldown
|
||||
fuse->state = FUSE_COOLDOWN;
|
||||
fuse->timer = cfg->cooldown_time;
|
||||
};
|
||||
|
||||
// Wait for timeout
|
||||
if(fuse->timer)
|
||||
{
|
||||
fuse->timer--;
|
||||
if(fuse->state == FUSE_RETRY) return 0;
|
||||
else return 1;
|
||||
};
|
||||
|
||||
// Timeout end, transition logic
|
||||
switch(fuse->state)
|
||||
{
|
||||
case FUSE_COOLDOWN:
|
||||
// Cooldown end
|
||||
if(cfg->retry_time)
|
||||
{
|
||||
fuse->state = FUSE_RETRY;
|
||||
fuse->timer = cfg->retry_time;
|
||||
}
|
||||
else
|
||||
{
|
||||
fuse->state = FUSE_OFF;
|
||||
fuse->timer = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case FUSE_RETRY:
|
||||
// Go back to normal
|
||||
fuse->state = FUSE_OFF;
|
||||
break;
|
||||
|
||||
default:
|
||||
// Nothing to do
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**** Private function definitions ****/
|
||||
Reference in New Issue
Block a user