dma.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include <stdio.h>
00012
00013 #include "contiki.h"
00014 #include "banked.h"
00015
00016 #include "dev/dma.h"
00017 #include "cc2430_sfr.h"
00018
00019 dma_config_t dma_conf[4];
00020 struct process * dma_callback[4];
00021
00022
00023 void
00024 dma_init(void) __banked
00025 {
00026 uint16_t tmp_ptr;
00027 memset(dma_conf, 0, 4*sizeof(dma_config_t));
00028 for(tmp_ptr = 0; tmp_ptr < 4; tmp_ptr++) {
00029 dma_callback[tmp_ptr] = 0;
00030 }
00031 tmp_ptr = (uint16_t) &(dma_conf[0]);
00032
00033 DMA1CFGH = tmp_ptr >> 8;
00034 DMA1CFGL = tmp_ptr;
00035 IEN1_DMAIE = 1;
00036 }
00037
00038 #ifdef HAVE_DMA
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084 xDMAHandle
00085 dma_config2(uint8_t channel, void *src, dma_inc_t src_inc, void *dst, dma_inc_t dst_inc,
00086 uint16_t length, uint8_t word_mode, dma_vlen_t vlen_mode, dma_type_t t_mode, dma_trigger_t trigger,
00087 struct process * proc) __banked
00088 {
00089 unsigned char jj;
00090 if((!channel) || (channel > 4)) {
00091 return 0;
00092 }
00093
00094 DMAIRQ &= ~(1 << channel);
00095
00096 channel--;
00097
00098 dma_conf[channel].src_h = ((uint16_t) src) >> 8;
00099 dma_conf[channel].src_l = ((uint16_t) src);
00100 dma_conf[channel].dst_h = ((uint16_t) dst) >> 8;
00101 dma_conf[channel].dst_l = ((uint16_t) dst);
00102 dma_conf[channel].len_h = vlen_mode + (length >> 8);
00103 dma_conf[channel].len_l = length;
00104 dma_conf[channel].t_mode = ((word_mode&0x1)<<7) | (t_mode << 5) | trigger;
00105 dma_conf[channel].addr_mode = (src_inc << 6) + (dst_inc << 4) + 2;
00106
00107
00108 if(proc) {
00109 dma_conf[channel].addr_mode |= 8;
00110 IEN1_DMAIE = 1;
00111 }
00112 dma_callback[channel] = proc;
00113
00114 return (xDMAHandle)channel + 1;
00115 }
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125 uint8_t
00126 dma_arm(xDMAHandle channel) __banked
00127 {
00128 uint8_t ch_id = ((uint8_t)channel);
00129 if(!ch_id || (ch_id > 4)) {
00130 return 0;
00131 }
00132 DMAARM |= (1 << ch_id);
00133 return 1;
00134 }
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144 uint8_t
00145 dma_abort(xDMAHandle channel) __banked
00146 {
00147 uint8_t ch_id = ((uint8_t) channel);
00148 if(!ch_id || (ch_id > 4)) {
00149 return 0;
00150 }
00151 DMAARM = 0x80 + (1 << ch_id);
00152 return 1;
00153 }
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163 uint8_t
00164 dma_trigger(xDMAHandle channel) __banked
00165 {
00166 uint8_t ch_id = ((uint8_t) channel);
00167 if(!ch_id || (ch_id > 4)) {
00168 return 0;
00169 }
00170 DMAREQ |= (1 << ch_id);
00171 return 1;
00172 }
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182 uint8_t
00183 dma_state(xDMAHandle channel) __banked
00184 {
00185 uint8_t ch_id = ((uint8_t)channel);
00186 if(!ch_id || (ch_id > 4)) {
00187 return 0;
00188 }
00189 if((DMAIRQ &(1 << ch_id)) == 0) {
00190 return 1;
00191 }
00192 return 0;
00193 }
00194
00195 void
00196 dma_config_print(xDMAHandle channel) __banked
00197 {
00198 uint8_t ch_id = channel - 1;
00199
00200 if(ch_id > 4) {
00201 return;
00202 }
00203
00204 printf("DMA channel %d @ %x %x ", ch_id, (uint16_t) &(dma_conf[ch_id]) >> 8, (uint16_t) &(dma_conf[ch_id]) & 0xFF);
00205 {
00206 uint8_t i;
00207 uint8_t *ptr = (uint8_t *)&(dma_conf[ch_id]);
00208 for(i = 0; i< 8; i++) {
00209 if(i != 0) {
00210 printf(":%02x", *ptr++);
00211 }
00212 }
00213 printf("\n");
00214 }
00215 }
00216 #endif