contiki/cpu/cc2430/dev/dma.c

70 lines
1.8 KiB
C
Raw Normal View History

/**
* \file
2012-03-05 16:28:06 +00:00
* Driver for the cc2430 DMA controller. Can be assigned to any bank
*
* \author
* Original: Martti Huttunen <martti@sensinode.com>
* Port: Zach Shelby <zach@sensinode.com>
2012-03-05 16:28:06 +00:00
* Further Modifications:
* George Oikonomou <oikonomou@users.sourceforge.net>
*
*/
#include "contiki.h"
#include "dev/dma.h"
#include "cc2430_sfr.h"
2012-03-05 16:28:06 +00:00
#if DMA_ON
struct dma_config dma_conf[DMA_CHANNEL_COUNT]; /* DMA Descriptors */
2012-12-16 12:44:44 +00:00
struct process *dma_callback[DMA_CHANNEL_COUNT];
/*---------------------------------------------------------------------------*/
void
2012-03-05 16:28:06 +00:00
dma_init(void)
{
uint16_t tmp_ptr;
2012-03-05 16:28:06 +00:00
memset(dma_conf, 0, 4 * sizeof(dma_config_t));
for(tmp_ptr = 0; tmp_ptr < DMA_CHANNEL_COUNT; tmp_ptr++) {
dma_callback[tmp_ptr] = 0;
}
2012-03-05 16:28:06 +00:00
/* The address of the descriptor for Channel 0 is configured separately */
2012-12-16 12:44:44 +00:00
tmp_ptr = (uint16_t)&(dma_conf[0]);
2012-03-05 16:28:06 +00:00
DMA0CFGH = tmp_ptr >> 8;
DMA0CFGL = tmp_ptr;
2012-03-05 16:28:06 +00:00
/*
* Descriptors for Channels 1-4 must be consecutive in RAM.
* We write the address of the 1st one to the register and the rest are
* derived by the SoC
*/
#if (DMA_CHANNEL_COUNT > 1)
2012-12-16 12:44:44 +00:00
tmp_ptr = (uint16_t)&(dma_conf[1]);
DMA1CFGH = tmp_ptr >> 8;
DMA1CFGL = tmp_ptr;
2012-03-05 16:28:06 +00:00
#endif
2012-03-05 16:28:06 +00:00
IEN1_DMAIE = 1; /* Enable DMA interrupts */
}
/*---------------------------------------------------------------------------*/
2012-03-05 16:28:06 +00:00
/*
* Associate process p with DMA channel c. When a transfer on that channel
* completes, the ISR will poll this process.
*/
void
2012-12-16 12:44:44 +00:00
dma_associate_process(struct process *p, uint8_t c)
{
2012-03-05 16:28:06 +00:00
if((!c) || (c >= DMA_CHANNEL_COUNT)) {
return;
}
2012-03-05 16:28:06 +00:00
if(p) {
dma_conf[c].inc_prio |= 8; /* Enable interrupt generation */
IEN1_DMAIE = 1; /* Make sure DMA interrupts are acknowledged */
}
2012-03-05 16:28:06 +00:00
dma_callback[c] = p;
}
2012-03-05 16:28:06 +00:00
/*---------------------------------------------------------------------------*/
#endif