Skip to content

Commit

Permalink
cc253x: DMA Changes
Browse files Browse the repository at this point in the history
- Fixed DMA irq flag clearing
- Added a dma_reset helper

See Pull Request #18
  • Loading branch information
Philippe Rétornaz authored and g-oikonomou committed Nov 1, 2012
1 parent 898bd07 commit eabaa0c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
25 changes: 25 additions & 0 deletions cpu/cc253x/dev/dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,29 @@ dma_associate_process(struct process * p, uint8_t c)
dma_callback[c] = p;
}
/*---------------------------------------------------------------------------*/
/*
* Reset a channel to idle state. As per cc253x datasheet section 8.1,
* we must reconfigure the channel to trigger source 0 between each
* reconfiguration.
*/
void
dma_reset(uint8_t c)
{
static __xdata uint8_t dummy;
if(c >= DMA_CHANNEL_COUNT) {
return;
}
DMA_ABORT(c);
dma_conf[c].src_h = (uint16_t) &dummy >> 8;
dma_conf[c].src_l = (uint16_t) &dummy;
dma_conf[c].dst_h = (uint16_t) &dummy >> 8;
dma_conf[c].dst_l = (uint16_t) &dummy;
dma_conf[c].len_h = 0;
dma_conf[c].len_l = 1;
dma_conf[c].wtt = DMA_BLOCK;
dma_conf[c].inc_prio = DMA_PRIO_GUARANTEED;
DMA_TRIGGER(c); // The operation order is important
DMA_ARM(c);
while(DMAARM & (1 << c));
}
#endif
4 changes: 3 additions & 1 deletion cpu/cc253x/dev/dma.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#ifndef __DMA_H
#define __DMA_H
#include "cc253x.h"
#include "sfr-bits.h"

/* DMA triggers */
#define DMA_T_NONE 0 /* None, DMAREQ.DMAREQx bits start transfer */
Expand Down Expand Up @@ -133,12 +134,13 @@ extern dma_config_t dma_conf[DMA_CHANNEL_COUNT];
*/
#define DMA_STATUS(c) (DMAIRQ &(1 << c))
/* Abort Ongoing DMA Transfers on Channel C */
#define DMA_ABORT(c) (DMAARM = ABORT | (1 << c))
#define DMA_ABORT(c) (DMAARM = DMAARM_ABORT | (1 << c))
#define DMA_ABORT_ALL() (DMAARM = 0x9F) /* Abort ALL Ongoing DMA Transfers */

/* Functions Declarations */
void dma_init(void);
void dma_associate_process (struct process * p, uint8_t c);
void dma_reset(uint8_t c);

/* Only link the ISR when DMA_ON is .... on */
#if DMA_ON
Expand Down
6 changes: 3 additions & 3 deletions cpu/cc253x/dev/dma_intr.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,21 @@ dma_isr(void) __interrupt (DMA_VECTOR)
DMAIF = 0;
#ifdef HAVE_RF_DMA
if((DMAIRQ & 1) != 0) {
DMAIRQ &= ~1;
DMAIRQ = ~1;
DMAARM=0x81;
rf_dma_callback_isr();
}
#endif
#ifdef SPI_DMA_RX
if((DMAIRQ & 0x08) != 0) {
DMAIRQ &= ~(1 << 3);
DMAIRQ = ~(1 << 3);
spi_rx_dma_callback();
}
#endif
#if DMA_ON
for(i = 0; i < DMA_CHANNEL_COUNT; i++) {
if((DMAIRQ & (1 << i)) != 0) {
DMAIRQ &= ~(1 << i);
DMAIRQ = ~(1 << i);
if(dma_callback[i] != 0) {
process_poll(dma_callback[i]);
}
Expand Down

0 comments on commit eabaa0c

Please sign in to comment.