00001 /** 00002 * \file 00003 * DMA driver header 00004 * \author 00005 * Original: Martti Huttunen <martti@sensinode.com> 00006 * Port: Zach Shelby <zach@sensinode.com> 00007 */ 00008 00009 #ifndef __DMA_H 00010 #define __DMA_H 00011 #include "banked.h" 00012 #include "cc2430_sfr.h" 00013 00014 /** DMA triggers */ 00015 typedef enum dma_trigger_t 00016 { 00017 DMA_T_NONE=0, /*!<DMA No trigger, setting DMAREQ.DMAREQx bit starts transfer*/ 00018 DMA_T_PREV=1, /*!<DMA DMA channel is triggered by completion of previous channel*/ 00019 DMA_T_T1_CH0=2, /*!<Timer 1 Timer 1, compare, channel 0*/ 00020 DMA_T_T1_CH1=3, /*!<Timer 1 Timer 1, compare, channel 1*/ 00021 DMA_T_T1_CH2=4, /*!<Timer 1 Timer 1, compare, channel 2*/ 00022 DMA_T_T2_COMP=5, /*!<Timer 2 Timer 2, compare*/ 00023 DMA_T_T2_OVFL=6, /*!<Timer 2 Timer 2, overflow*/ 00024 DMA_T_T3_CH0=7, /*!<Timer 3 Timer 3, compare, channel 0*/ 00025 DMA_T_T3_CH1=8, /*!<Timer 3 Timer 3, compare, channel 1*/ 00026 DMA_T_T4_CH0=9, /*!<Timer 4 Timer 4, compare, channel 0*/ 00027 DMA_T_T4_CH1=10, /*!<Timer 4 Timer 4, compare, channel 1*/ 00028 DMA_T_ST=11, /*!<Sleep Timer Sleep Timer compare*/ 00029 DMA_T_IOC_0=12, /*!<IO Controller Port 0 I/O pin input transition*/ 00030 DMA_T_IOC_1=13, /*!<IO Controller Port 1 I/O pin input transition*/ 00031 DMA_T_URX0=14, /*!<USART0 USART0 RX complete*/ 00032 DMA_T_UTX0=15, /*!<USART0 USART0 TX complete*/ 00033 DMA_T_URX1=16, /*!<USART1 USART1 RX complete*/ 00034 DMA_T_UTX1=17, /*!<USART1 USART1 TX complete*/ 00035 DMA_T_FLASH=18, /*!<Flash controller Flash data write complete*/ 00036 DMA_T_RADIO=19, /*!<Radio RF packet byte received/transmit*/ 00037 DMA_T_ADC_CHALL=20, /*!<ADC ADC end of a conversion in a sequence, sample ready*/ 00038 DMA_T_ADC_CH11=21, /*!<ADC ADC end of conversion channel 0 in sequence, sample ready*/ 00039 DMA_T_ADC_CH21=22, /*!<ADC ADC end of conversion channel 1 in sequence, sample ready*/ 00040 DMA_T_ADC_CH32=23, /*!<ADC ADC end of conversion channel 2 in sequence, sample ready*/ 00041 DMA_T_ADC_CH42=24, /*!<ADC ADC end of conversion channel 3 in sequence, sample ready*/ 00042 DMA_T_ADC_CH53=25, /*!<ADC ADC end of conversion channel 4 in sequence, sample ready*/ 00043 DMA_T_ADC_CH63=26, /*!<ADC ADC end of conversion channel 5 in sequence, sample ready*/ 00044 DMA_T_ADC_CH74=27, /*!<ADC ADC end of conversion channel 6 in sequence, sample ready*/ 00045 DMA_T_ADC_CH84=28, /*!<ADC ADC end of conversion channel 7 in sequence, sample ready*/ 00046 DMA_T_ENC_DW=29, /*!<AES AES encryption processor requests download input data*/ 00047 DMA_T_ENC_UP=30, /*!<AES AES encryption processor requests upload output data*/ 00048 DMA_T_RES=31 00049 }dma_trigger_t; 00050 00051 /** variable DMA length modes */ 00052 typedef enum dma_vlen_t 00053 { 00054 DMA_VLEN_LEN = (0 << 5),/*!<Use LEN for transfer count*/ 00055 DMA_VLEN_N1 = (1 << 5),/*!<Transfer the number of bytes/words specified by first byte/word + 1 (up to a maximum specified by LEN). Thus transfer count excludes length byte/word.*/ 00056 DMA_VLEN_N = (2 << 5),/*!<Transfer the number of bytes/words specified by first byte/word (up to a maximum specified by LEN). Thus transfer count includes length byte/word.*/ 00057 DMA_VLEN_N2 = (3 << 5),/*!<Transfer the number of bytes/words specified by first byte/word + 2 (up to a maximum specified by LEN).*/ 00058 DMA_VLEN_N3 = (4 << 5),/*!<Transfer the number of bytes/words specified by first byte/word + 3 (up to a maximum specified by LEN).*/ 00059 DMA_VLEN_RES1 = (5 << 5),/*!<reserved*/ 00060 DMA_VLEN_RES2 = (6 << 5),/*!<reserved*/ 00061 DMA_VLEN_LEN2 = (7 << 5) /*!<Use LEN for transfer count*/ 00062 }dma_vlen_t; 00063 00064 /** address increment modes */ 00065 typedef enum dma_inc_t 00066 { 00067 DMA_NOINC = 0, /*!<No increment*/ 00068 DMA_INC = 1, /*!<Increment*/ 00069 DMA_INC2 = 2, /*!<Increment 2*/ 00070 DMA_DEC = 3 /*!<Decrement*/ 00071 }dma_inc_t; 00072 00073 /** transfer types */ 00074 typedef enum dma_type_t 00075 { 00076 DMA_SINGLE = 0, /*!<Single*/ 00077 DMA_BLOCK = 1, /*!<Block*/ 00078 DMA_RPT = 2, /*!<Repeated single*/ 00079 DMA_BLOCK_RPT=3 /*!<Repeated block*/ 00080 }dma_type_t; 00081 00082 /** DMA configuration structure */ 00083 typedef struct dma_config_t 00084 { 00085 uint8_t src_h; /*!<source address high byte*/ 00086 uint8_t src_l; /*!<source address low byte*/ 00087 uint8_t dst_h; /*!<dest. address high byte*/ 00088 uint8_t dst_l; /*!<dest. address low byte*/ 00089 uint8_t len_h; /*!<transfer mode in high 3 bits, length high byte, 4 lowest bits*/ 00090 uint8_t len_l; /*!<length low byte*/ 00091 uint8_t t_mode; /*!<transfer mode: bit7=word mode, 6-5=block/single 4-0=trigger */ 00092 uint8_t addr_mode; /*!<address mode: 7-6=src inc, 5-4=dst_inc, 3=IRQ, 2=M8(vlen) 1-0:priority*/ 00093 00094 }dma_config_t; 00095 00096 extern void dma_init(void) __banked; 00097 typedef void (*dma_func)(void *); 00098 00099 extern dma_config_t dma_conf[4]; 00100 00101 #ifdef HAVE_DMA 00102 typedef uint8_t xDMAHandle; 00103 00104 #define dma_config(channel, src, src_inc, dst, dst_inc, length, vlen_mode, t_mode, trigger, proc) dma_config2(channel,src,src_inc, dst, dst_inc, length, 0, vlen_mode, t_mode, trigger, proc) 00105 /* 00106 extern xDMAHandle dma_config(uint8_t channel, void *src, dma_inc_t src_inc, void *dst, dma_inc_t dst_inc, 00107 uint16_t length, dma_vlen_t vlen_mode, dma_type_t t_mode, 00108 dma_trigger_t trigger, struct process * p); 00109 */ 00110 extern xDMAHandle dma_config2(uint8_t channel, void *src, dma_inc_t src_inc, void *dst, dma_inc_t dst_inc, 00111 uint16_t length, uint8_t word_mode, dma_vlen_t vlen_mode, dma_type_t t_mode, 00112 dma_trigger_t trigger, struct process * p) __banked; 00113 extern uint8_t dma_arm(xDMAHandle channel) __banked; 00114 extern uint8_t dma_abort(xDMAHandle channel) __banked; 00115 extern uint8_t dma_trigger(xDMAHandle channel) __banked; 00116 extern uint8_t dma_state(xDMAHandle channel) __banked; 00117 void dma_config_print(xDMAHandle channel) __banked; 00118 #endif 00119 00120 extern void dma_ISR( void ) __interrupt (DMA_VECTOR); 00121 00122 #endif /*__DMA_H*/