injecting CRC peripheral as dependency

This commit is contained in:
Attila Body 2019-11-21 12:43:42 +01:00
parent a17ad75673
commit d63d225817
2 changed files with 11 additions and 9 deletions

View file

@ -7,7 +7,6 @@
#include <f4ll_c/crcscheduler.h> #include <f4ll_c/crcscheduler.h>
#include "main.h" #include "main.h"
#include <string.h> #include <string.h>
#include <platform/crc_ll.h>
#include "diag.h" #include "diag.h"
#include "f4ll_c/dmahelper.h" #include "f4ll_c/dmahelper.h"
@ -27,12 +26,13 @@
# define DIAG_INTERRUPT_OUT() # define DIAG_INTERRUPT_OUT()
#endif #endif
void Crc_InitStatus(struct crcstatus_t *st, DMA_TypeDef *dma, uint32_t stream) void Crc_InitStatus(struct crcstatus_t *st, CRC_TypeDef *crcUnit, DMA_TypeDef *dma, uint32_t stream)
{ {
st->crcUnit = crcUnit;
Dma_Init(&st->dmaInfo, dma, stream); Dma_Init(&st->dmaInfo, dma, stream);
LL_DMA_EnableIT_TC(dma, stream); LL_DMA_EnableIT_TC(dma, stream);
LL_DMA_EnableIT_TE(dma, stream); LL_DMA_EnableIT_TE(dma, stream);
LL_DMA_SetM2MDstAddress(dma, stream, (uint32_t)&CRC->DR); LL_DMA_SetM2MDstAddress(dma, stream, (uint32_t)&crcUnit->DR);
st->activeSlot = NULL; st->activeSlot = NULL;
st->first = NULL; st->first = NULL;
} }
@ -86,7 +86,7 @@ uint8_t Crc_Enqueue(struct crcstatus_t *status, struct crcslotlistitem_t *slot,
__set_PRIMASK(prim); __set_PRIMASK(prim);
if(need_start) { if(need_start) {
CRC->CR = 1; status->crcUnit->CR = 1;
LL_DMA_SetM2MSrcAddress(status->dmaInfo.dma, status->dmaInfo.stream, (uint32_t)address); LL_DMA_SetM2MSrcAddress(status->dmaInfo.dma, status->dmaInfo.stream, (uint32_t)address);
LL_DMA_SetDataLength(status->dmaInfo.dma, status->dmaInfo.stream, (len+3)/4); LL_DMA_SetDataLength(status->dmaInfo.dma, status->dmaInfo.stream, (len+3)/4);
DIAG_CRC_CALC_START(); DIAG_CRC_CALC_START();
@ -126,7 +126,7 @@ static void StartNextCrcTask(struct crcstatus_t *status)
if(slot->tasks[index].address) { if(slot->tasks[index].address) {
status->activeSlot = slot; status->activeSlot = slot;
status->activeTask = index; status->activeTask = index;
CRC->CR = 1; status->crcUnit->CR = 1;
LL_DMA_SetM2MSrcAddress(status->dmaInfo.dma, status->dmaInfo.stream, (uint32_t)slot->tasks[index].address); LL_DMA_SetM2MSrcAddress(status->dmaInfo.dma, status->dmaInfo.stream, (uint32_t)slot->tasks[index].address);
LL_DMA_SetDataLength(status->dmaInfo.dma, status->dmaInfo.stream, slot->tasks[index].wordCount); LL_DMA_SetDataLength(status->dmaInfo.dma, status->dmaInfo.stream, slot->tasks[index].wordCount);
LL_DMA_EnableStream(status->dmaInfo.dma, status->dmaInfo.stream); LL_DMA_EnableStream(status->dmaInfo.dma, status->dmaInfo.stream);
@ -152,9 +152,9 @@ void Crc_HandleDmaIrq(struct crcstatus_t *status)
if(status->activeSlot) { if(status->activeSlot) {
struct crcslottask_t *tsk = &status->activeSlot->tasks[status->activeTask]; struct crcslottask_t *tsk = &status->activeSlot->tasks[status->activeTask];
if(tsk->callback) if(tsk->callback)
tsk->callback(tsk->callbackParam, CRC->DR, 1); tsk->callback(tsk->callbackParam, status->crcUnit->DR, 1);
else if(tsk->callbackParam) else if(tsk->callbackParam)
*(uint32_t*)tsk->callbackParam = CRC->DR; *(uint32_t*)tsk->callbackParam = status->crcUnit->DR;
tsk->callback = tsk->callbackParam = NULL; // marking as inactive tsk->callback = tsk->callbackParam = NULL; // marking as inactive
DIAG_CRC_CALC_END(); DIAG_CRC_CALC_END();
StartNextCrcTask(status); StartNextCrcTask(status);
@ -166,7 +166,7 @@ void Crc_HandleDmaIrq(struct crcstatus_t *status)
if(status->activeSlot) { if(status->activeSlot) {
struct crcslottask_t *tsk = &status->activeSlot->tasks[status->activeTask]; struct crcslottask_t *tsk = &status->activeSlot->tasks[status->activeTask];
if(tsk->callback) if(tsk->callback)
tsk->callback(tsk->callbackParam, CRC->DR, 0); tsk->callback(tsk->callbackParam, status->crcUnit->DR, 0);
else if(tsk->callbackParam) else if(tsk->callbackParam)
*(uint32_t*)tsk->callbackParam = 0xffffffff; *(uint32_t*)tsk->callbackParam = 0xffffffff;
tsk->callback = tsk->callbackParam = NULL; // marking as inactive tsk->callback = tsk->callbackParam = NULL; // marking as inactive

View file

@ -14,6 +14,7 @@
#include "config.h" #include "config.h"
#endif // HAVE_CONFIG #endif // HAVE_CONFIG
#include <platform/crc_ll.h>
#include <f4ll_c/dmahelper.h> #include <f4ll_c/dmahelper.h>
struct crcslottask_t { struct crcslottask_t {
@ -30,13 +31,14 @@ struct crcslotlistitem_t {
}; };
struct crcstatus_t { struct crcstatus_t {
CRC_TypeDef *crcUnit;
struct dmainfo_t dmaInfo; struct dmainfo_t dmaInfo;
struct crcslotlistitem_t *activeSlot; struct crcslotlistitem_t *activeSlot;
uint8_t activeTask; uint8_t activeTask;
struct crcslotlistitem_t *first; struct crcslotlistitem_t *first;
}; };
void Crc_InitStatus(struct crcstatus_t *status, DMA_TypeDef *dma, uint32_t stream); void Crc_InitStatus(struct crcstatus_t *status, CRC_TypeDef *crcUnit, DMA_TypeDef *dma, uint32_t stream);
uint8_t Crc_GetActiveTask(struct crcslotlistitem_t **slot_out, struct crcstatus_t volatile *status); uint8_t Crc_GetActiveTask(struct crcslotlistitem_t **slot_out, struct crcstatus_t volatile *status);