Skip to content

Commit 3690af6

Browse files
Martinhoff-makerjhedberg
authored andcommitted
simplicity_sdk: Patch dmadrv to support cross channel allocator
Patch needed to remain synchronize between zephyr DMA channels allocator and dmadrv channel allocator. Signed-off-by: Martin Hoff <[email protected]> (cherry picked from commit 1e60d97)
1 parent 18f6b7f commit 3690af6

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

simplicity_sdk/platform/emdrv/dmadrv/inc/dmadrv.h

+2
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ typedef bool (*DMADRV_Callback_t)(unsigned int channel,
102102

103103
Ecode_t DMADRV_AllocateChannel(unsigned int *channelId,
104104
void *capabilities);
105+
Ecode_t DMADRV_AllocateChannelById(unsigned int channelId,
106+
void *capabilities);
105107
Ecode_t DMADRV_DeInit(void);
106108
Ecode_t DMADRV_FreeChannel(unsigned int channelId);
107109
Ecode_t DMADRV_Init(void);

simplicity_sdk/platform/emdrv/dmadrv/src/dmadrv.c

+38
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,44 @@ Ecode_t DMADRV_AllocateChannel(unsigned int *channelId, void *capabilities)
165165
return ECODE_EMDRV_DMADRV_CHANNELS_EXHAUSTED;
166166
}
167167

168+
/***************************************************************************//**
169+
* @brief
170+
* Allocate (reserve) the given DMA channel if he is free.
171+
*
172+
* @param[out] channelId
173+
* The channel ID to be assigned by DMADRV.
174+
*
175+
* @param[in] capabilities
176+
* Not used.
177+
*
178+
* @return
179+
* @ref ECODE_EMDRV_DMADRV_OK on success. On failure, an appropriate
180+
* DMADRV @ref Ecode_t is returned.
181+
******************************************************************************/
182+
Ecode_t DMADRV_AllocateChannelById(unsigned int channelId, void *capabilities)
183+
{
184+
(void)capabilities;
185+
CORE_DECLARE_IRQ_STATE;
186+
187+
if ( !initialized ) {
188+
return ECODE_EMDRV_DMADRV_NOT_INITIALIZED;
189+
}
190+
191+
if ( channelId >= EMDRV_DMADRV_DMA_CH_COUNT ) {
192+
return ECODE_EMDRV_DMADRV_PARAM_ERROR;
193+
}
194+
195+
CORE_ENTER_ATOMIC();
196+
if ( !chTable[channelId].allocated ) {
197+
chTable[channelId].allocated = true;
198+
chTable[channelId].callback = NULL;
199+
CORE_EXIT_ATOMIC();
200+
return ECODE_EMDRV_DMADRV_OK;
201+
}
202+
CORE_EXIT_ATOMIC();
203+
return ECODE_EMDRV_DMADRV_IN_USE;
204+
}
205+
168206
/***************************************************************************//**
169207
* @brief
170208
* Deinitialize DMADRV.

0 commit comments

Comments
 (0)