git subrepo pull components/f4ll_c
subrepo: subdir: "components/f4ll_c" merged: "4754b65" upstream: origin: "git@git.pcmuhely.hu:compi/f4ll_c.git" branch: "master" commit: "4754b65" git-subrepo: version: "0.4.0" origin: "https://github.com/ingydotnet/git-subrepo" commit: "5d6aba9"
This commit is contained in:
parent
6f89e70a2a
commit
357b30b344
11 changed files with 140 additions and 72 deletions
|
@ -5,9 +5,10 @@
|
|||
* Author: abody
|
||||
*/
|
||||
#include <f4ll_c/crcscheduler.h>
|
||||
#include "main.h"
|
||||
#include <string.h>
|
||||
#if defined(HAVE_DIAG)
|
||||
#include "diag.h"
|
||||
#endif
|
||||
#include "f4ll_c/dmahelper.h"
|
||||
|
||||
#ifndef DIAG_CRC_CALC_START
|
||||
|
@ -26,6 +27,12 @@
|
|||
# define DIAG_INTERRUPT_OUT()
|
||||
#endif
|
||||
|
||||
#ifdef UNITTEST
|
||||
#define STATIC_MOCKME
|
||||
#else
|
||||
#define STATIC_MOCKME static
|
||||
#endif
|
||||
|
||||
void Crc_InitStatus(struct crcstatus_t *st, CRC_TypeDef *crcUnit, DMA_TypeDef *dma, uint32_t stream)
|
||||
{
|
||||
st->crcUnit = crcUnit;
|
||||
|
@ -34,7 +41,7 @@ void Crc_InitStatus(struct crcstatus_t *st, CRC_TypeDef *crcUnit, DMA_TypeDef *d
|
|||
LL_DMA_EnableIT_TE(dma, stream);
|
||||
LL_DMA_SetM2MDstAddress(dma, stream, (uint32_t)&crcUnit->DR);
|
||||
st->activeSlot = NULL;
|
||||
st->first = NULL;
|
||||
st->firstSlot = NULL;
|
||||
}
|
||||
|
||||
void Crc_AttachTask(struct crcstatus_t *status, struct crcslotlistitem_t *slot, struct crcslottask_t *tasks, uint8_t taskCount)
|
||||
|
@ -45,8 +52,8 @@ void Crc_AttachTask(struct crcstatus_t *status, struct crcslotlistitem_t *slot,
|
|||
|
||||
uint32_t prim = __get_PRIMASK();
|
||||
__disable_irq();
|
||||
slot->next = status->first;
|
||||
status->first = slot;
|
||||
slot->next = status->firstSlot;
|
||||
status->firstSlot = slot;
|
||||
__set_PRIMASK(prim);
|
||||
}
|
||||
|
||||
|
@ -72,7 +79,7 @@ uint8_t Crc_Enqueue(struct crcstatus_t *status, struct crcslotlistitem_t *slot,
|
|||
uint16_t need_start;
|
||||
struct crcstatus_t volatile *st = status;
|
||||
|
||||
while(st->activeSlot == slot && st->activeTask == task);
|
||||
while(Crc_IsSlotBusy(slot, task));
|
||||
__disable_irq();
|
||||
need_start = (st->activeSlot == NULL);
|
||||
slot->tasks[task].address = need_start ? NULL : address;
|
||||
|
@ -95,15 +102,6 @@ uint8_t Crc_Enqueue(struct crcstatus_t *status, struct crcslotlistitem_t *slot,
|
|||
return need_start;
|
||||
}
|
||||
|
||||
void Crc_WaitResults(struct crcstatus_t *status, struct crcslotlistitem_t *slot, uint8_t task)
|
||||
{
|
||||
struct crcslotlistitem_t *slotQueued;
|
||||
|
||||
while(Crc_IsSlotQueued(slot, task));
|
||||
while(Crc_GetActiveTask(&slotQueued, status) == task && slotQueued == slot);
|
||||
}
|
||||
|
||||
|
||||
uint32_t Crc_Compute(struct crcstatus_t *status, struct crcslotlistitem_t *slot, uint8_t task, uint8_t *address, uint16_t len)
|
||||
{
|
||||
uint32_t result;
|
||||
|
@ -113,13 +111,13 @@ uint32_t Crc_Compute(struct crcstatus_t *status, struct crcslotlistitem_t *slot,
|
|||
}
|
||||
|
||||
// only called from ISR context
|
||||
static void StartNextCrcTask(struct crcstatus_t *status)
|
||||
STATIC_MOCKME void Crc_StartNextTask(struct crcstatus_t *status)
|
||||
{
|
||||
char moreTasks;
|
||||
uint8_t index = 0;
|
||||
|
||||
do {
|
||||
struct crcslotlistitem_t *slot = status->first;
|
||||
struct crcslotlistitem_t *slot = status->firstSlot;
|
||||
moreTasks = 0;
|
||||
while(slot) {
|
||||
if(index < slot->count) {
|
||||
|
@ -143,35 +141,27 @@ static void StartNextCrcTask(struct crcstatus_t *status)
|
|||
status->activeSlot = NULL;
|
||||
}
|
||||
|
||||
// !!!PORTABILITY WARNING!!! using registers and bits directly. should be reviewed extremely t
|
||||
void Crc_HandleDmaIrq(struct crcstatus_t *status)
|
||||
{
|
||||
uint8_t success = 1;
|
||||
|
||||
DIAG_INTERRUPT_IN();
|
||||
if(*status->dmaInfo.isReg & status->dmaInfo.tcMask) { // DMA transfer complete
|
||||
*status->dmaInfo.ifcReg = status->dmaInfo.tcMask;
|
||||
if((*status->dmaInfo.isReg & status->dmaInfo.tcMask) ||
|
||||
(*status->dmaInfo.isReg & status->dmaInfo.teMask)) {
|
||||
if(*status->dmaInfo.isReg & status->dmaInfo.teMask)
|
||||
success = 0;
|
||||
*status->dmaInfo.ifcReg = *status->dmaInfo.isReg & (status->dmaInfo.tcMask | status->dmaInfo.teMask);
|
||||
LL_DMA_DisableStream(status->dmaInfo.dma, status->dmaInfo.stream);
|
||||
if(status->activeSlot) {
|
||||
struct crcslottask_t *tsk = &status->activeSlot->tasks[status->activeTask];
|
||||
if(tsk->callback)
|
||||
tsk->callback(tsk->callbackParam, status->crcUnit->DR, 1);
|
||||
tsk->callback(tsk->callbackParam, status->crcUnit->DR, success);
|
||||
else if(tsk->callbackParam)
|
||||
*(uint32_t*)tsk->callbackParam = status->crcUnit->DR;
|
||||
*(uint32_t*)tsk->callbackParam = success ? status->crcUnit->DR : 0xffffffff;
|
||||
tsk->callback = tsk->callbackParam = NULL; // marking as inactive
|
||||
DIAG_CRC_CALC_END();
|
||||
StartNextCrcTask(status);
|
||||
}
|
||||
}
|
||||
else if(*status->dmaInfo.isReg & status->dmaInfo.teMask) {
|
||||
*status->dmaInfo.ifcReg = status->dmaInfo.teMask;
|
||||
LL_DMA_DisableStream(status->dmaInfo.dma, status->dmaInfo.stream);
|
||||
if(status->activeSlot) {
|
||||
struct crcslottask_t *tsk = &status->activeSlot->tasks[status->activeTask];
|
||||
if(tsk->callback)
|
||||
tsk->callback(tsk->callbackParam, status->crcUnit->DR, 0);
|
||||
else if(tsk->callbackParam)
|
||||
*(uint32_t*)tsk->callbackParam = 0xffffffff;
|
||||
tsk->callback = tsk->callbackParam = NULL; // marking as inactive
|
||||
DIAG_CRC_CALC_END();
|
||||
StartNextCrcTask(status);
|
||||
Crc_StartNextTask(status);
|
||||
}
|
||||
}
|
||||
DIAG_INTERRUPT_OUT();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue