Contiki 2.6

dma.h

Go to the documentation of this file.
00001 /**
00002  * \file
00003  *       Header file for the cc2430 DMA controller
00004  *
00005  * \author
00006  *         Original: Martti Huttunen <martti@sensinode.com>
00007  *         Port: Zach Shelby <zach@sensinode.com>
00008  *         Further Modifications:
00009  *               George Oikonomou <oikonomou@users.sourceforge.net>
00010  */
00011 
00012 #ifndef __DMA_H
00013 #define __DMA_H
00014 #include "cc253x.h"
00015 
00016 /* DMA triggers */
00017 #define DMA_T_NONE       0 /* None, DMAREQ.DMAREQx bits start transfer */
00018 #define DMA_T_PREV       1 /* completion of previous channel */
00019 #define DMA_T_T1_CH0     2 /* Timer 1, compare, channel 0 */
00020 #define DMA_T_T1_CH1     3 /* Timer 1, compare, channel 1 */
00021 #define DMA_T_T1_CH2     4 /* Timer 1, compare, channel 2 */
00022 #define DMA_T_T2_COMP    5 /* Timer 2, compare */
00023 #define DMA_T_T2_OVFL    6 /* Timer 2, overflow */
00024 #define DMA_T_T3_CH0     7 /* Timer 3, compare, channel 0 */
00025 #define DMA_T_T3_CH1     8 /* Timer 3, compare, channel 1 */
00026 #define DMA_T_T4_CH0     9 /* Timer 4, compare, channel 0 */
00027 #define DMA_T_T4_CH1    10 /* Timer 4, compare, channel 1 */
00028 #define DMA_T_ST        11 /* Sleep Timer compare */
00029 #define DMA_T_IOC_0     12 /* Port 0 I/O pin input transition */
00030 #define DMA_T_IOC_1     13 /* Port 1 I/O pin input transition */
00031 #define DMA_T_URX0      14 /* USART0 RX complete */
00032 #define DMA_T_UTX0      15 /* USART0 TX complete */
00033 #define DMA_T_URX1      16 /* USART1 RX complete */
00034 #define DMA_T_UTX1      17 /* USART1 TX complete */
00035 #define DMA_T_FLASH     18 /* Flash data write complete */
00036 #define DMA_T_RADIO     19 /* RF packet byte received/transmit */
00037 #define DMA_T_ADC_CHALL 20 /* ADC end of a conversion in a sequence */
00038 #define DMA_T_ADC_CH11  21 /* ADC end of conversion channel 0 in sequence */
00039 #define DMA_T_ADC_CH21  22 /* ADC end of conversion channel 1 in sequence */
00040 #define DMA_T_ADC_CH32  23 /* ADC end of conversion channel 2 in sequence */
00041 #define DMA_T_ADC_CH42  24 /* ADC end of conversion channel 3 in sequence */
00042 #define DMA_T_ADC_CH53  25 /* ADC end of conversion channel 4 in sequence */
00043 #define DMA_T_ADC_CH63  26 /* ADC end of conversion channel 5 in sequence */
00044 #define DMA_T_ADC_CH74  27 /* ADC end of conversion channel 6 in sequence */
00045 #define DMA_T_ADC_CH84  28 /* ADC end of conversion channel 7 in sequence */
00046 #define DMA_T_ENC_DW    29 /* AES processor requests download input data */
00047 #define DMA_T_ENC_UP    30 /* AES processor requests upload output data */
00048 
00049 /* variable DMA length modes (VLEN) */
00050 #define DMA_VLEN_LEN  (0 << 5) /* Use LEN for transfer count*/
00051 /*
00052  * Transfer the number of bytes/words specified by first byte/word + 1
00053  * (up to a maximum specified by LEN).
00054  * Thus transfer count excludes length byte/word.
00055  */
00056 #define DMA_VLEN_N1   (1 << 5)
00057  /*
00058   * Transfer the number of bytes/words specified by first byte/word
00059   * (up to a maximum specified by LEN).
00060   * Thus transfer count includes length byte/word.
00061   */
00062 #define DMA_VLEN_N    (2 << 5)
00063  /*
00064   * Transfer the number of bytes/words specified by first byte/word + 2
00065   * (up to a maximum specified by LEN).
00066   */
00067 #define DMA_VLEN_N2   (3 << 5)
00068  /*
00069   * Transfer the number of bytes/words specified by first byte/word + 3
00070   * (up to a maximum specified by LEN).
00071   */
00072 #define DMA_VLEN_N3   (4 << 5)
00073 #define DMA_VLEN_RES1 (5 << 5) /* reserved */
00074 #define DMA_VLEN_RES2 (6 << 5) /* reserved */
00075 #define DMA_VLEN_LEN2 (7 << 5) /* Use LEN for transfer count */
00076 
00077 /* Transfer Types (Byte 6 [6:5]) */
00078 #define DMA_SINGLE           0x00 /* Single */
00079 #define DMA_BLOCK            0x20 /* Block */
00080 #define DMA_RPT_SINGLE       0x40 /* Repeated single */
00081 #define DMA_RPT_BLOCK        0x60 /* Repeated block */
00082 
00083 /* Source Increment Modes (Byte 7 [7:6])*/
00084 #define DMA_SRC_INC_NO       0x00 /* Source No increment */
00085 #define DMA_SRC_INC_1        0x40 /* Source Increment 1 */
00086 #define DMA_SRC_INC_2        0x80 /* Source Increment 2 */
00087 #define DMA_SRC_DEC          0xC0 /* Source Decrement 1 */
00088 /* Source Increment Modes (Byte 7 [5:4])*/
00089 #define DMA_DST_INC_NO       0x00 /* DestinationNo increment */
00090 #define DMA_DST_INC_1        0x10 /* Destination Increment 1 */
00091 #define DMA_DST_INC_2        0x20 /* Destination Increment 2 */
00092 #define DMA_DST_DEC          0x30 /* Destination Decrement 1 */
00093 
00094 /* Descriptor Byte 7, Bits[3:0] */
00095 #define DMA_IRQ_MASK_ENABLE  0x08
00096 #define DMA_MODE_7_BIT       0x04
00097 #define DMA_PRIO_HIGHEST     0x03
00098 #define DMA_PRIO_HIGH        0x02
00099 #define DMA_PRIO_GUARANTEED  0x01
00100 #define DMA_PRIO_LOW         0x00
00101 
00102 /** DMA configuration structure */
00103 typedef struct dma_config {
00104   uint8_t src_h; /* source address high byte*/
00105   uint8_t src_l; /* source address low byte*/
00106   uint8_t dst_h; /* dest. address high byte*/
00107   uint8_t dst_l; /* dest. address low byte*/
00108   uint8_t len_h; /* [7:5] VLEN, [4:0] length high byte, 5 lowest bits*/
00109   uint8_t len_l; /* length low byte*/
00110   uint8_t wtt;   /* 7: wordsize, [6:5] transfer mode, [4:0] trigger */
00111   /* [7:6] src inc, [5:4] dst_inc, 3: IRQ, 2: M8(vlen), [1-0] prio */
00112   uint8_t inc_prio;
00113 } dma_config_t;
00114 
00115 #ifdef DMA_CONF_ON
00116 #define DMA_ON DMA_CONF_ON
00117 #else
00118 #define DMA_ON 0
00119 #endif
00120 
00121 /* Number of DMA Channels and their Descriptors */
00122 #if DMA_ON
00123 #define DMA_CHANNEL_COUNT 2
00124 extern dma_config_t dma_conf[DMA_CHANNEL_COUNT];
00125 #endif
00126 
00127 /* DMA-Related Macros */
00128 #define DMA_ARM(c)      (DMAARM |= (1 << c)) /* Arm DMA Channel C */
00129 #define DMA_TRIGGER(c)  (DMAREQ |= (1 << c)) /* Trigger DMA Channel C */
00130 /*
00131  * Check Channel C for Transfer Status
00132  * 1: Complete, Pending Interrupt, 0: Incomplete
00133  */
00134 #define DMA_STATUS(c)   (DMAIRQ &(1 << c))
00135 /* Abort Ongoing DMA Transfers on Channel C */
00136 #define DMA_ABORT(c)    (DMAARM = ABORT | (1 << c))
00137 #define DMA_ABORT_ALL() (DMAARM = 0x9F) /* Abort ALL Ongoing DMA Transfers */
00138 
00139 /* Functions Declarations */
00140 void dma_init(void);
00141 void dma_associate_process (struct process * p, uint8_t c);
00142 
00143 /* Only link the ISR when DMA_ON is .... on */
00144 #if DMA_ON
00145 void dma_isr( void ) __interrupt (DMA_VECTOR);
00146 #endif
00147 
00148 #endif /*__DMA_H*/