mirror of https://github.com/rusefi/ChibiOS.git
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5377 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
parent
09d8d2dfdc
commit
ba2057b89e
|
@ -711,7 +711,7 @@ edma_channel_t edmaChannelAllocate(const edma_channel_config_t *ccfg) {
|
||||||
/* Associating the configuration to the channel.*/
|
/* Associating the configuration to the channel.*/
|
||||||
channels[channel] = ccfg;
|
channels[channel] = ccfg;
|
||||||
|
|
||||||
/* If an error callback is defined then the erro interrupt source is
|
/* If an error callback is defined then the error interrupt source is
|
||||||
enabled for the channel.*/
|
enabled for the channel.*/
|
||||||
if (ccfg->dma_error_func != NULL)
|
if (ccfg->dma_error_func != NULL)
|
||||||
EDMA.SEEIR.R = channel;
|
EDMA.SEEIR.R = channel;
|
||||||
|
|
|
@ -93,7 +93,6 @@ typedef int32_t edma_channel_t;
|
||||||
typedef struct {
|
typedef struct {
|
||||||
union {
|
union {
|
||||||
uint32_t word[8];
|
uint32_t word[8];
|
||||||
uint32_t hword[16];
|
|
||||||
};
|
};
|
||||||
} edma_tcd_t;
|
} edma_tcd_t;
|
||||||
|
|
||||||
|
@ -148,116 +147,100 @@ typedef struct {
|
||||||
#define edmaGetTCD(channel) ((edma_tcd_t *)&EDMA.TCD[channel])
|
#define edmaGetTCD(channel) ((edma_tcd_t *)&EDMA.TCD[channel])
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Sets the source address into a TCD.
|
* @brief Sets the word 0 fields into a TCD.
|
||||||
*
|
*
|
||||||
* @param[in] tcdp pointer to an @p edma_tcd_t structure
|
* @param[in] tcdp pointer to an @p edma_tcd_t structure
|
||||||
* @param[in] dst the source address
|
* @param[in] src the source address
|
||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
#define edmaTCDSetSourceAddress(tcdp, src) \
|
#define edmaTCDSetWord0(tcdp, src) \
|
||||||
((tcdp)->word[0] = (uint32_t)(src))
|
((tcdp)->word[0] = (uint32_t)(src))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Sets the destination address into a TCD.
|
* @brief Sets the word 1 fields into a TCD.
|
||||||
*
|
|
||||||
* @param[in] tcdp pointer to an @p edma_tcd_t structure
|
|
||||||
* @param[in] dst the destination address
|
|
||||||
*
|
|
||||||
* @api
|
|
||||||
*/
|
|
||||||
#define edmaTCDSetDestinationAddress(tcdp, dst) \
|
|
||||||
((tcdp)->word[4] = (uint32_t)(dst))
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Sets the transfer widths into a TCD.
|
|
||||||
*
|
*
|
||||||
* @param[in] tcdp pointer to an @p edma_tcd_t structure
|
* @param[in] tcdp pointer to an @p edma_tcd_t structure
|
||||||
* @param[in] ssize the source width
|
* @param[in] ssize the source width
|
||||||
* @param[in] dst the destination width
|
* @param[in] dst the destination width
|
||||||
|
* @param[in] soff the source increment value
|
||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
#define edmaTCDSetTransferWidths(tcdp, ssize, dsize) \
|
#define edmaTCDSetWord1(tcdp, ssize, dsize, soff) \
|
||||||
((tcdp)->hword[2] = ((uint16_t)((ssize) << 8) | (uint16_t)(dsize)))
|
((tcdp)->word[1] = (((uint32_t)(ssize) << 24) | \
|
||||||
|
((uint32_t)(dsize) << 16) | \
|
||||||
|
((uint32_t)(soff) << 0)))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Sets the inner loop counter value into a TCD.
|
* @brief Sets the word 2 fields into a TCD.
|
||||||
*
|
*
|
||||||
* @param[in] tcdp pointer to an @p edma_tcd_t structure
|
* @param[in] tcdp pointer to an @p edma_tcd_t structure
|
||||||
* @param[in] nbytes the inner counter value
|
* @param[in] nbytes the inner counter value
|
||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
#define edmaTCDSetInnnerLoopCount(tcdp, nbytes) \
|
#define edmaTCDSetWord2(tcdp, nbytes) \
|
||||||
((tcdp)->word[2] = (uint32_t)(nbytes))
|
((tcdp)->word[2] = (uint32_t)(nbytes))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Sets the source address increment value into a TCD.
|
* @brief Sets the word 3 fields into a TCD.
|
||||||
*
|
|
||||||
* @param[in] tcdp pointer to an @p edma_tcd_t structure
|
|
||||||
* @param[in] soff the source increment value
|
|
||||||
*
|
|
||||||
* @api
|
|
||||||
*/
|
|
||||||
#define edmaTCDSetSetSourceIncrement(tcdp, soff) \
|
|
||||||
((tcdp)->hword[3] = (uint16_t)(soff))
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Sets the destination address increment value into a TCD.
|
|
||||||
*
|
|
||||||
* @param[in] tcdp pointer to an @p edma_tcd_t structure
|
|
||||||
* @param[in] soff the source increment value
|
|
||||||
*
|
|
||||||
* @api
|
|
||||||
*/
|
|
||||||
#define edmaTCDSetSetDestinationIncrement(tcdp, doff) \
|
|
||||||
((tcdp)->hword[3] = (uint16_t)(doff))
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Sets the outer loop counter value into a TCD.
|
|
||||||
*
|
|
||||||
* @param[in] tcdp pointer to an @p edma_tcd_t structure
|
|
||||||
* @param[in] iter the outer counter value
|
|
||||||
*
|
|
||||||
* @api
|
|
||||||
*/
|
|
||||||
#define edmaTCDSetOuterLoopCount(tcdp, iter) { \
|
|
||||||
((tcdp)->hword[10] = (uint16_t)(iter)); \
|
|
||||||
((tcdp)->hword[14] = (uint16_t)(iter)); \
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Sets the source address adjustment into a TCD.
|
|
||||||
*
|
*
|
||||||
* @param[in] tcdp pointer to an @p edma_tcd_t structure
|
* @param[in] tcdp pointer to an @p edma_tcd_t structure
|
||||||
* @param[in] slast the adjustment value
|
* @param[in] slast the adjustment value
|
||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
#define edmaTCDSetSourceAdjustment(tcdp, slast) \
|
#define edmaTCDSetWord3(tcdp, slast) \
|
||||||
((tcdp)->word[3] = (uint32_t)(slast))
|
((tcdp)->word[3] = (uint32_t)(slast))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Sets the destination address adjustment into a TCD.
|
* @brief Sets the word 4 fields into a TCD.
|
||||||
|
*
|
||||||
|
* @param[in] tcdp pointer to an @p edma_tcd_t structure
|
||||||
|
* @param[in] dst the destination address
|
||||||
|
*
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
#define edmaTCDSetWord4(tcdp, dst) \
|
||||||
|
((tcdp)->word[4] = (uint32_t)(dst))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Sets the word 5 fields into a TCD.
|
||||||
|
*
|
||||||
|
* @param[in] tcdp pointer to an @p edma_tcd_t structure
|
||||||
|
* @param[in] citer the current outer counter value
|
||||||
|
* @param[in] doff the destination increment value
|
||||||
|
*
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
#define edmaTCDSetWord5(tcdp, citer, doff) \
|
||||||
|
((tcdp)->word[5] = (((uint32_t)(citer) << 16) | \
|
||||||
|
((uint32_t)(doff) << 0)))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Sets the word 6 fields into a TCD.
|
||||||
*
|
*
|
||||||
* @param[in] tcdp pointer to an @p edma_tcd_t structure
|
* @param[in] tcdp pointer to an @p edma_tcd_t structure
|
||||||
* @param[in] dlast the adjustment value
|
* @param[in] dlast the adjustment value
|
||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
#define edmaTCDSetDestinationAdjustment(tcdp, dlast) \
|
#define edmaTCDSetWord6(tcdp, dlast) \
|
||||||
((tcdp)->word[6] = (uint32_t)(dlast))
|
((tcdp)->word[6] = (uint32_t)(dlast))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Sets the channel mode bits into a TCD.
|
* @brief Sets the word 7 fields into a TCD.
|
||||||
*
|
*
|
||||||
* @param[in] tcdp pointer to an @p edma_tcd_t structure
|
* @param[in] tcdp pointer to an @p edma_tcd_t structure
|
||||||
|
* @param[in] biter the base outer counter value
|
||||||
* @param[in] mode the mode value
|
* @param[in] mode the mode value
|
||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
#define edmaTCDSetMode(tcdp, mode) ((tcdp)->hword[15] = (uint16_t)(mode))
|
#define edmaTCDSetWord7(tcdp, biter, mode) \
|
||||||
|
((tcdp)->word[7] = (((uint32_t)(biter) << 16) | \
|
||||||
|
((uint32_t)(mode) << 0)))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Starts or restarts an EDMA channel.
|
* @brief Starts or restarts an EDMA channel.
|
||||||
|
@ -301,16 +284,14 @@ typedef struct {
|
||||||
#define edmaChannelSetup(channel, src, dst, soff, doff, ssize, dsize, \
|
#define edmaChannelSetup(channel, src, dst, soff, doff, ssize, dsize, \
|
||||||
nbytes, iter, slast, dlast, mode) { \
|
nbytes, iter, slast, dlast, mode) { \
|
||||||
edma_tcd_t *tcdp = edmaGetTCD(channel); \
|
edma_tcd_t *tcdp = edmaGetTCD(channel); \
|
||||||
edmaTCDSetSourceAddress(tcdp, src); \
|
edmaTCDSetWord0(tcdp, src); \
|
||||||
edmaTCDSetDestinationAddress(tcdp, dst); \
|
edmaTCDSetWord1(tcdp, ssize, dsize, soff); \
|
||||||
edmaTCDSetSetSourceIncrement(tcdp, soff); \
|
edmaTCDSetWord2(tcdp, nbytes); \
|
||||||
edmaTCDSetSetDestinationIncrement(tcdp, doff); \
|
edmaTCDSetWord3(tcdp, slast); \
|
||||||
edmaTCDSetTransferWidths(tcdp, ssize, dsize); \
|
edmaTCDSetWord4(tcdp, dst); \
|
||||||
edmaTCDSetInnnerLoopCount(tcdp, nbytes); \
|
edmaTCDSetWord5(tcdp, iter, doff); \
|
||||||
edmaTCDSetOuterLoopCount(tcdp, iter); \
|
edmaTCDSetWord6(tcdp, dlast); \
|
||||||
edmaTCDSetSourceAdjustment(tcdp, slast); \
|
edmaTCDSetWord7(tcdp, iter, mode); \
|
||||||
edmaTCDSetDestinationAdjustment(tcdp, dlast); \
|
|
||||||
edmaTCDSetMode(tcdp, dlast); \
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
|
|
|
@ -420,7 +420,7 @@ static void adc_serve_rfifo_irq(edma_channel_t channel, void *p) {
|
||||||
edma_tcd_t *tcdp = edmaGetTCD(channel);
|
edma_tcd_t *tcdp = edmaGetTCD(channel);
|
||||||
|
|
||||||
if (adcp->grpp != NULL) {
|
if (adcp->grpp != NULL) {
|
||||||
if (tcdp->hword[10] != tcdp->hword[14]) {
|
if ((tcdp->word[5] >> 16) != (tcdp->word[7] >> 16)) {
|
||||||
/* Half transfer processing.*/
|
/* Half transfer processing.*/
|
||||||
_adc_isr_half_code(adcp);
|
_adc_isr_half_code(adcp);
|
||||||
}
|
}
|
||||||
|
@ -597,34 +597,6 @@ void adc_lld_start(ADCDriver *adcp) {
|
||||||
(adcp->rfifo_channel != EDMA_ERROR),
|
(adcp->rfifo_channel != EDMA_ERROR),
|
||||||
"adc_lld_start(), #1", "channel cannot be allocated");
|
"adc_lld_start(), #1", "channel cannot be allocated");
|
||||||
|
|
||||||
/* Setting up TCD parameters that will not change during operations,
|
|
||||||
other parameters are set to a temporary value and will be changed
|
|
||||||
when starting a conversion.*/
|
|
||||||
edmaChannelSetup(adcp->cfifo_channel, /* channel. */
|
|
||||||
NULL, /* source, temporary. */
|
|
||||||
CFIFO_PUSH_ADDR(adcp->fifo), /* destination. */
|
|
||||||
4, /* soff, advance by 4. */
|
|
||||||
0, /* doff, do not advance. */
|
|
||||||
2, /* ssize, 32 bits transfers.*/
|
|
||||||
2, /* dsize, 32 bits transfers.*/
|
|
||||||
4, /* nbytes, always four. */
|
|
||||||
0, /* iter, temporary. */
|
|
||||||
0, /* slast, temporary. */
|
|
||||||
0, /* dlast, no dest.adjust. */
|
|
||||||
EDMA_TCD_MODE_DREQ); /* mode. */
|
|
||||||
edmaChannelSetup(adcp->rfifo_channel, /* channel. */
|
|
||||||
RFIFO_POP_ADDR(adcp->fifo), /* source. */
|
|
||||||
NULL, /* destination, temporary. */
|
|
||||||
0, /* soff, do not advance. */
|
|
||||||
2, /* doff, advance by two. */
|
|
||||||
1, /* ssize, 16 bits transfers.*/
|
|
||||||
1, /* dsize, 16 bits transfers.*/
|
|
||||||
2, /* nbytes, always two. */
|
|
||||||
0, /* iter, temporary. */
|
|
||||||
0, /* slast, no source adjust. */
|
|
||||||
0, /* dlast, temporary. */
|
|
||||||
0); /* mode, temporary. */
|
|
||||||
|
|
||||||
/* HW triggers setup.*/
|
/* HW triggers setup.*/
|
||||||
SIU.ETISR.R = adcp->config->etisr;
|
SIU.ETISR.R = adcp->config->etisr;
|
||||||
SIU.ISEL3.R = adcp->config->isel3;
|
SIU.ISEL3.R = adcp->config->isel3;
|
||||||
|
@ -659,31 +631,44 @@ void adc_lld_stop(ADCDriver *adcp) {
|
||||||
* @notapi
|
* @notapi
|
||||||
*/
|
*/
|
||||||
void adc_lld_start_conversion(ADCDriver *adcp) {
|
void adc_lld_start_conversion(ADCDriver *adcp) {
|
||||||
edma_tcd_t *ctcdp = edmaGetTCD(adcp->cfifo_channel);
|
|
||||||
edma_tcd_t *rtcdp = edmaGetTCD(adcp->rfifo_channel);
|
|
||||||
|
|
||||||
chDbgAssert(adcp->grpp->num_iterations >= adcp->depth,
|
chDbgAssert(adcp->grpp->num_iterations >= adcp->depth,
|
||||||
"adc_lld_start_conversion(), #1", "too many elements");
|
"adc_lld_start_conversion(), #1", "too many elements");
|
||||||
|
|
||||||
/* Updating the variable TCD fields for CFIFO.*/
|
/* Setting up CFIFO TCD parameters.*/
|
||||||
edmaTCDSetSourceAddress(ctcdp, adcp->grpp->commands);
|
edmaChannelSetup(adcp->cfifo_channel, /* channel. */
|
||||||
edmaTCDSetOuterLoopCount(ctcdp, (uint32_t)adcp->grpp->num_channels *
|
adcp->grpp->commands, /* src. */
|
||||||
(uint32_t)adcp->depth);
|
CFIFO_PUSH_ADDR(adcp->fifo), /* dst. */
|
||||||
edmaTCDSetSourceAdjustment(ctcdp,
|
4, /* soff, advance by 4. */
|
||||||
|
0, /* doff, do not advance. */
|
||||||
|
2, /* ssize, 32 bits transfers.*/
|
||||||
|
2, /* dsize, 32 bits transfers.*/
|
||||||
|
4, /* nbytes, always four. */
|
||||||
|
(uint32_t)adcp->grpp->num_channels *
|
||||||
|
(uint32_t)adcp->depth, /* iter. */
|
||||||
CPL2((uint32_t)adcp->grpp->num_channels *
|
CPL2((uint32_t)adcp->grpp->num_channels *
|
||||||
(uint32_t)adcp->depth *
|
(uint32_t)adcp->depth *
|
||||||
sizeof(adccommand_t)));
|
sizeof(adccommand_t)), /* slast. */
|
||||||
|
0, /* dlast, no dest.adjust. */
|
||||||
|
EDMA_TCD_MODE_DREQ); /* mode. */
|
||||||
|
|
||||||
/* Updating the variable TCD fields for RFIFO.*/
|
/* Setting up RFIFO TCD parameters.*/
|
||||||
edmaTCDSetDestinationAddress(rtcdp, adcp->samples);
|
edmaChannelSetup(adcp->rfifo_channel, /* channel. */
|
||||||
edmaTCDSetOuterLoopCount(rtcdp, (uint32_t)adcp->grpp->num_channels *
|
RFIFO_POP_ADDR(adcp->fifo), /* src. */
|
||||||
(uint32_t)adcp->depth);
|
adcp->samples, /* dst. */
|
||||||
edmaTCDSetDestinationAdjustment(ctcdp,
|
0, /* soff, do not advance. */
|
||||||
|
2, /* doff, advance by two. */
|
||||||
|
1, /* ssize, 16 bits transfers.*/
|
||||||
|
1, /* dsize, 16 bits transfers.*/
|
||||||
|
2, /* nbytes, always two. */
|
||||||
|
(uint32_t)adcp->grpp->num_channels *
|
||||||
|
(uint32_t)adcp->depth, /* iter. */
|
||||||
|
0, /* slast, no source adjust. */
|
||||||
CPL2((uint32_t)adcp->grpp->num_channels *
|
CPL2((uint32_t)adcp->grpp->num_channels *
|
||||||
(uint32_t)adcp->depth *
|
(uint32_t)adcp->depth *
|
||||||
sizeof(adcsample_t)));
|
sizeof(adcsample_t)), /* dlast. */
|
||||||
edmaTCDSetMode(rtcdp, EDMA_TCD_MODE_DREQ | EDMA_TCD_MODE_INT_END |
|
EDMA_TCD_MODE_DREQ | EDMA_TCD_MODE_INT_END |
|
||||||
(adcp->depth > 1) ? EDMA_TCD_MODE_INT_HALF: 0);
|
((adcp->depth > 1) ? EDMA_TCD_MODE_INT_HALF: 0));/* mode.*/
|
||||||
|
|
||||||
/* Starting DMA channels.*/
|
/* Starting DMA channels.*/
|
||||||
edmaChannelStart(adcp->rfifo_channel);
|
edmaChannelStart(adcp->rfifo_channel);
|
||||||
|
|
Loading…
Reference in New Issue