2013-02-28 16:23:19 +00:00
|
|
|
/*
|
|
|
|
ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
|
|
|
|
2011,2012,2013 Giovanni Di Sirio.
|
|
|
|
|
|
|
|
This file is part of ChibiOS/RT.
|
|
|
|
|
|
|
|
ChibiOS/RT is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
ChibiOS/RT is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file SPC5xx/edma.h
|
|
|
|
* @brief EDMA helper driver header.
|
|
|
|
*
|
|
|
|
* @addtogroup SPC5xx_EDMA
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _EDMA_H_
|
|
|
|
#define _EDMA_H_
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver constants. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2013-03-04 08:17:33 +00:00
|
|
|
/**
|
|
|
|
* @brief EDMA channel allocation error.
|
|
|
|
*/
|
2013-03-06 11:36:21 +00:00
|
|
|
#define EDMA_ERROR -1
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name EDMA mode constants
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
#define EDMA_TCD_MODE_START (1U << 0)
|
|
|
|
#define EDMA_TCD_MODE_INT_END (1U << 1)
|
|
|
|
#define EDMA_TCD_MODE_INT_HALF (1U << 2)
|
|
|
|
#define EDMA_TCD_MODE_DREQ (1U << 3)
|
|
|
|
#define EDMA_TCD_MODE_ACTIVE (1U << 6)
|
|
|
|
#define EDMA_TCD_MODE_DONE (1U << 7)
|
|
|
|
/** @} */
|
2013-03-04 08:17:33 +00:00
|
|
|
|
2013-02-28 16:23:19 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver pre-compile time settings. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2013-03-04 11:10:29 +00:00
|
|
|
/**
|
|
|
|
* @brief Default EDMA CR register initialization.
|
|
|
|
*/
|
|
|
|
#if !defined(SPC5_EDMA_ERROR_HANDLER) || defined(__DOXYGEN__)
|
|
|
|
#define SPC5_EDMA_CR_SETTING 0x0000C400
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief EDMA critical error handler, must not return.
|
|
|
|
*/
|
|
|
|
#if !defined(SPC5_EDMA_ERROR_HANDLER) || defined(__DOXYGEN__)
|
|
|
|
#define SPC5_EDMA_ERROR_HANDLER() chSysHalt()
|
|
|
|
#endif
|
|
|
|
|
2013-02-28 16:23:19 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* Derived constants and error checks. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2013-03-04 11:10:29 +00:00
|
|
|
#if !SPC5_HAS_EDMAA
|
|
|
|
#error "this device does not have an eDMA unit"
|
|
|
|
#endif
|
|
|
|
|
2013-02-28 16:23:19 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver data structures and types. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2013-03-04 08:17:33 +00:00
|
|
|
/**
|
|
|
|
* @brief Type of and EDMA channel number.
|
|
|
|
*/
|
|
|
|
typedef int32_t edma_channel_t;
|
|
|
|
|
2013-02-28 16:23:19 +00:00
|
|
|
/**
|
|
|
|
* @brief Type of an EDMA TCD.
|
|
|
|
*/
|
|
|
|
typedef struct {
|
2013-03-06 11:36:21 +00:00
|
|
|
union {
|
|
|
|
uint32_t word[8];
|
|
|
|
uint32_t hword[16];
|
|
|
|
};
|
2013-02-28 16:23:19 +00:00
|
|
|
} edma_tcd_t;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief DMA ISR function type.
|
|
|
|
*
|
2013-03-04 11:10:29 +00:00
|
|
|
* @param[in] channel the channel number
|
2013-02-28 16:23:19 +00:00
|
|
|
* @param[in] p parameter for the registered function
|
|
|
|
*/
|
2013-03-04 11:10:29 +00:00
|
|
|
typedef void (*edma_callback_t)(edma_channel_t channel, void *p);
|
2013-02-28 16:23:19 +00:00
|
|
|
|
2013-03-01 14:37:07 +00:00
|
|
|
/**
|
|
|
|
* @brief Type of an EDMA channel configuration structure.
|
|
|
|
*/
|
2013-02-28 16:23:19 +00:00
|
|
|
typedef struct {
|
2013-03-04 11:10:29 +00:00
|
|
|
uint8_t dma_periph; /**< @brief Peripheral to be
|
2013-03-04 08:17:33 +00:00
|
|
|
associated to the channel. */
|
2013-03-04 15:11:20 +00:00
|
|
|
uint8_t dma_prio; /**< @brief Priority register value
|
2013-03-04 11:10:29 +00:00
|
|
|
for this channel. */
|
2013-03-04 15:11:20 +00:00
|
|
|
uint8_t dma_irq_prio; /**< @brief IRQ priority level for
|
|
|
|
this channel. */
|
2013-03-04 11:10:29 +00:00
|
|
|
edma_callback_t dma_func; /**< @brief Channel callback. */
|
|
|
|
edma_callback_t dma_error_func; /**< @brief Channel error callback. */
|
2013-03-01 14:37:07 +00:00
|
|
|
void *dma_param; /**< @brief Channel callback param. */
|
|
|
|
} edma_channel_config_t;
|
2013-02-28 16:23:19 +00:00
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver macros. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2013-03-05 15:37:10 +00:00
|
|
|
/**
|
|
|
|
* @brief Returns the TCD address associated to a channel.
|
|
|
|
*
|
|
|
|
* @param[in] channel the channel number
|
|
|
|
* @return A pointer to an @p edma_tcd_t structure.
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
|
|
|
#define edmaGetTCD(channel) ((edma_tcd_t *)&EDMA.TCD[channel])
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Sets the source address into a TCD.
|
|
|
|
*
|
|
|
|
* @param[in] tcdp pointer to an @p edma_tcd_t structure
|
2013-03-06 11:36:21 +00:00
|
|
|
* @param[in] dst the source address
|
2013-03-05 15:37:10 +00:00
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
2013-03-06 11:36:21 +00:00
|
|
|
#define edmaTCDSetSourceAddress(tcdp, src) \
|
2013-03-05 15:37:10 +00:00
|
|
|
((tcdp)->word[0] = (uint32_t)(src))
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Sets the destination address into a TCD.
|
|
|
|
*
|
|
|
|
* @param[in] tcdp pointer to an @p edma_tcd_t structure
|
2013-03-06 11:36:21 +00:00
|
|
|
* @param[in] dst the destination address
|
2013-03-05 15:37:10 +00:00
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
2013-03-06 11:36:21 +00:00
|
|
|
#define edmaTCDSetDestinationAddress(tcdp, dst) \
|
2013-03-05 15:37:10 +00:00
|
|
|
((tcdp)->word[4] = (uint32_t)(dst))
|
|
|
|
|
2013-03-06 11:36:21 +00:00
|
|
|
/**
|
|
|
|
* @brief Sets the transfer widths into a TCD.
|
|
|
|
*
|
|
|
|
* @param[in] tcdp pointer to an @p edma_tcd_t structure
|
|
|
|
* @param[in] ssize the source width
|
|
|
|
* @param[in] dst the destination width
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
|
|
|
#define edmaTCDSetTransferWidths(tcdp, ssize, dsize) \
|
|
|
|
((tcdp)->hword[2] = ((uint16_t)((ssize) << 8) | (uint16_t)(dsize)))
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Sets the inner loop counter value into a TCD.
|
|
|
|
*
|
|
|
|
* @param[in] tcdp pointer to an @p edma_tcd_t structure
|
|
|
|
* @param[in] nbytes the inner counter value
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
|
|
|
#define edmaTCDSetInnnerLoopCount(tcdp, nbytes) \
|
|
|
|
((tcdp)->word[2] = (uint32_t)(nbytes))
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Sets the source 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 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] iter the adjustment value
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
|
|
|
#define edmaTCDSetSourceAdjustment(tcdp, slast) \
|
|
|
|
((tcdp)->word[3] = (uint32_t)(slast))
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Sets the destination address adjustment into a TCD.
|
|
|
|
*
|
|
|
|
* @param[in] tcdp pointer to an @p edma_tcd_t structure
|
|
|
|
* @param[in] iter the adjustment value
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
|
|
|
#define edmaTCDSetDestinationAdjustment(tcdp, dlast) \
|
|
|
|
((tcdp)->word[6] = (uint32_t)(dlast))
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Sets the channel mode bits into a TCD.
|
|
|
|
*
|
|
|
|
* @param[in] tcdp pointer to an @p edma_tcd_t structure
|
|
|
|
* @param[in] iter the adjustment value
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
|
|
|
#define edmaTCDSetMode(tcdp, mode) ((tcdp)->hword[15] = (uint16_t)(mode))
|
|
|
|
|
2013-03-04 11:10:29 +00:00
|
|
|
/**
|
|
|
|
* @brief Starts or restarts an EDMA channel.
|
|
|
|
*
|
|
|
|
* @param[in] channel the channel number
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
|
|
|
#define edmaChannelStart(channel) (EDMA.SERQR.R = (channel))
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Stops an EDMA channel.
|
|
|
|
*
|
|
|
|
* @param[in] channel the channel number
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
|
|
|
#define edmaChannelStop(channel) (EDMA.CERQR.R = (channel))
|
|
|
|
|
2013-03-05 15:37:10 +00:00
|
|
|
/**
|
|
|
|
* @brief EDMA channel setup.
|
|
|
|
*
|
|
|
|
* @param[in] channel eDMA channel number
|
|
|
|
* @param[in] src source address
|
|
|
|
* @param[in] dst destination address
|
|
|
|
* @param[in] soff source address offset
|
|
|
|
* @param[in] doff destination address offset
|
|
|
|
* @param[in] ssize source transfer size
|
|
|
|
* @param[in] dsize destination transfer size
|
|
|
|
* @param[in] nbytes minor loop count
|
|
|
|
* @param[in] iter major loop count
|
|
|
|
* @param[in] dlast last destination address adjustment
|
|
|
|
* @param[in] slast last source address adjustment
|
|
|
|
* @param[in] mode LSW of TCD register 7
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
|
|
|
#define edmaChannelSetup(channel, src, dst, soff, doff, ssize, dsize, \
|
2013-03-06 11:36:21 +00:00
|
|
|
nbytes, iter, slast, dlast, mode) { \
|
2013-03-05 15:37:10 +00:00
|
|
|
edma_tcd_t *tcdp = edmaGetTCD(channel); \
|
2013-03-06 11:36:21 +00:00
|
|
|
edmaTCDSetSourceAddress(tcdp, src); \
|
|
|
|
edmaTCDSetDestinationAddress(tcdp, dst); \
|
|
|
|
edmaTCDSetSetSourceIncrement(tcdp, soff); \
|
|
|
|
edmaTCDSetSetDestinationIncrement(tcdp, doff); \
|
|
|
|
edmaTCDSetTransferWidths(tcdp, ssize, dsize); \
|
|
|
|
edmaTCDSetInnnerLoopCount(tcdp, nbytes); \
|
|
|
|
edmaTCDSetOuterLoopCount(tcdp, iter); \
|
|
|
|
edmaTCDSetSourceAdjustment(tcdp, slast); \
|
|
|
|
edmaTCDSetDestinationAdjustment(tcdp, dlast); \
|
|
|
|
edmaTCDSetMode(tcdp, dlast); \
|
2013-03-05 15:37:10 +00:00
|
|
|
}
|
|
|
|
|
2013-03-06 11:36:21 +00:00
|
|
|
#if 0
|
|
|
|
tcdp->word[0] = (uint32_t)(src); \
|
|
|
|
tcdp->word[1] = ((uint32_t)(ssize) << 24) | ((uint32_t)(dsize) << 16) | \
|
|
|
|
(uint32_t)(soff); \
|
|
|
|
tcdp->word[2] = (uint32_t)(nbytes); \
|
|
|
|
tcdp->word[3] = (uint32_t)(slast); \
|
|
|
|
tcdp->word[0] = (uint32_t)(dst); \
|
|
|
|
tcdp->word[5] = ((uint32_t)(iter) << 16) | (uint32_t)(doff); \
|
|
|
|
tcdp->word[6] = (uint32_t)(dlast); \
|
|
|
|
tcdp->word[7] = ((uint32_t)(iter) << 16) | (uint32_t)(mode);
|
|
|
|
#endif
|
|
|
|
|
2013-02-28 16:23:19 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* External declarations. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
void edmaInit(void);
|
2013-03-04 08:57:20 +00:00
|
|
|
edma_channel_t edmaChannelAllocate(const edma_channel_config_t *ccfg);
|
|
|
|
void edmaChannelRelease(edma_channel_t channel);
|
2013-02-28 16:23:19 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* _EDMA_H_ */
|
|
|
|
|
|
|
|
/** @} */
|