Code compiles
This commit is contained in:
parent
7a74273ca7
commit
2aa08f20a0
118 changed files with 119250 additions and 34 deletions
122
lib/crc_handler.c
Normal file
122
lib/crc_handler.c
Normal file
|
@ -0,0 +1,122 @@
|
|||
/*
|
||||
* interrupt.c
|
||||
*
|
||||
* Created on: Aug 29, 2019
|
||||
* Author: abody
|
||||
*/
|
||||
#include <dma.h>
|
||||
#include <string.h>
|
||||
#include "crc.h"
|
||||
#include "dma_helper.h"
|
||||
#include "diag.h"
|
||||
#include "crc_handler.h"
|
||||
|
||||
#ifndef DIAG_CRC_CALC_START
|
||||
# define DIAG_CRC_CALC_START()
|
||||
#endif
|
||||
|
||||
#ifndef DIAG_CRC_CALC_END
|
||||
# define DIAG_CRC_CALC_END()
|
||||
#endif
|
||||
|
||||
void InitCrcStatus(struct crcstatus_t *st, DMA_TypeDef *dma, uint32_t stream)
|
||||
{
|
||||
InitDmaInfo(&st->dmaInfo, dma, stream);
|
||||
LL_DMA_EnableIT_TC(dma, stream);
|
||||
LL_DMA_EnableIT_TE(dma, stream);
|
||||
LL_DMA_SetM2MDstAddress(dma, stream, (uint32_t)&CRC->DR);
|
||||
st->activeSlot = 0xff;
|
||||
memset((void*)st->crcTasks, 0, sizeof(st->crcTasks));
|
||||
}
|
||||
|
||||
uint8_t EnqueueCrcTask(struct crcstatus_t *status, uint8_t slot, uint8_t *address, uint16_t len,
|
||||
void (*callback)(void*, uint32_t, uint8_t), void* callbackParam)
|
||||
{
|
||||
uint32_t prim = __get_PRIMASK();
|
||||
uint16_t need_start;
|
||||
|
||||
while(status->activeSlot == slot);
|
||||
__disable_irq();
|
||||
need_start = (status->activeSlot == 0xff);
|
||||
status->crcTasks[slot].address = need_start ? NULL : address;
|
||||
status->crcTasks[slot].wordCount = (len+3)/4;
|
||||
status->crcTasks[slot].callback = callback;
|
||||
status->crcTasks[slot].callbackParam = callbackParam;
|
||||
if(need_start)
|
||||
status->activeSlot = slot;
|
||||
__set_PRIMASK(prim);
|
||||
|
||||
if(need_start) {
|
||||
CRC->CR = 1;
|
||||
LL_DMA_SetM2MSrcAddress(status->dmaInfo.dma, status->dmaInfo.stream, (uint32_t)address);
|
||||
LL_DMA_SetDataLength(status->dmaInfo.dma, status->dmaInfo.stream, (len+3)/4);
|
||||
DIAG_CRC_CALC_START();
|
||||
LL_DMA_EnableStream(status->dmaInfo.dma, status->dmaInfo.stream);
|
||||
}
|
||||
return need_start;
|
||||
}
|
||||
|
||||
void WaitCrcResults(struct crcstatus_t *status, uint8_t slot)
|
||||
{
|
||||
while(IsSlotQueued(status, slot));
|
||||
while(GetActiveSlot(status) == slot);
|
||||
}
|
||||
|
||||
uint32_t ComputeCrc(struct crcstatus_t *status, uint8_t slot, uint8_t *address, uint16_t len)
|
||||
{
|
||||
uint32_t result;
|
||||
EnqueueCrcTask(status, slot, address, len, NULL, &result);
|
||||
while(status->crcTasks[slot].callbackParam);
|
||||
return result;
|
||||
}
|
||||
|
||||
void StartNextCrcTask(struct crcstatus_t *status)
|
||||
{
|
||||
uint16_t slot;
|
||||
for(slot = 0; slot < CRCTASKCOUNT; ++slot)
|
||||
if(status->crcTasks[slot].address) {
|
||||
status->activeSlot = slot;
|
||||
CRC->CR = 1;
|
||||
LL_DMA_SetM2MSrcAddress(status->dmaInfo.dma, status->dmaInfo.stream, (uint32_t)status->crcTasks[slot].address);
|
||||
LL_DMA_SetDataLength(status->dmaInfo.dma, status->dmaInfo.stream, status->crcTasks[slot].wordCount);
|
||||
DIAG_CRC_CALC_START();
|
||||
LL_DMA_EnableStream(status->dmaInfo.dma, status->dmaInfo.stream);
|
||||
status->crcTasks[slot].address = NULL; // marking as started
|
||||
return;
|
||||
}
|
||||
|
||||
status->activeSlot = 0xff;
|
||||
}
|
||||
|
||||
void HandleCrcDmaIrq(struct crcstatus_t *status)
|
||||
{
|
||||
if(*status->dmaInfo.isReg & status->dmaInfo.tcMask) { // DMA transfer complete
|
||||
*status->dmaInfo.ifcReg = status->dmaInfo.tcMask;
|
||||
LL_DMA_DisableStream(status->dmaInfo.dma, status->dmaInfo.stream);
|
||||
if(status->activeSlot != 0xff) {
|
||||
struct crctask_t *tsk = (struct crctask_t *)&status->crcTasks[status->activeSlot];
|
||||
if(tsk->callback)
|
||||
tsk->callback(tsk->callbackParam, CRC->DR, 1);
|
||||
else if(tsk->callbackParam)
|
||||
*(uint32_t*)tsk->callbackParam = CRC->DR;
|
||||
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 != 0xff) {
|
||||
struct crctask_t *tsk = (struct crctask_t *)&status->crcTasks[status->activeSlot];
|
||||
if(tsk->callback)
|
||||
tsk->callback(tsk->callbackParam, CRC->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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue