andrewm@0
|
1 .origin 0
|
andrewm@0
|
2 .entrypoint START
|
andrewm@0
|
3
|
andrewm@0
|
4 #define DBOX_CAPE // Define this to use new cape hardware
|
andrewm@0
|
5
|
andrewm@0
|
6 #define CLOCK_BASE 0x44E00000
|
andrewm@0
|
7 #define CLOCK_SPI0 0x4C
|
andrewm@0
|
8 #define CLOCK_SPI1 0x50
|
andrewm@0
|
9 #define CLOCK_L4LS 0x60
|
andrewm@0
|
10
|
andrewm@0
|
11 #define SPI0_BASE 0x48030100
|
andrewm@0
|
12 #define SPI1_BASE 0x481A0100
|
andrewm@0
|
13 #define SPI_BASE SPI0_BASE
|
andrewm@0
|
14
|
andrewm@0
|
15 #define SPI_SYSCONFIG 0x10
|
andrewm@0
|
16 #define SPI_SYSSTATUS 0x14
|
andrewm@0
|
17 #define SPI_MODULCTRL 0x28
|
andrewm@0
|
18 #define SPI_CH0CONF 0x2C
|
andrewm@0
|
19 #define SPI_CH0STAT 0x30
|
andrewm@0
|
20 #define SPI_CH0CTRL 0x34
|
andrewm@0
|
21 #define SPI_CH0TX 0x38
|
andrewm@0
|
22 #define SPI_CH0RX 0x3C
|
andrewm@0
|
23 #define SPI_CH1CONF 0x40
|
andrewm@0
|
24 #define SPI_CH1STAT 0x44
|
andrewm@0
|
25 #define SPI_CH1CTRL 0x48
|
andrewm@0
|
26 #define SPI_CH1TX 0x4C
|
andrewm@0
|
27 #define SPI_CH1RX 0x50
|
andrewm@0
|
28
|
andrewm@0
|
29 #define GPIO0 0x44E07000
|
andrewm@0
|
30 #define GPIO1 0x4804C000
|
andrewm@0
|
31 #define GPIO_CLEARDATAOUT 0x190
|
andrewm@0
|
32 #define GPIO_SETDATAOUT 0x194
|
andrewm@0
|
33
|
andrewm@0
|
34 #define PRU0_ARM_INTERRUPT 19
|
andrewm@0
|
35
|
andrewm@0
|
36 #define C_ADC_DAC_MEM C24 // PRU0 mem
|
andrewm@0
|
37 #ifdef DBOX_CAPE
|
andrewm@0
|
38 #define DAC_GPIO GPIO0
|
andrewm@0
|
39 #define DAC_CS_PIN (1<<5) // GPIO0:5 = P9 pin 17
|
andrewm@0
|
40 #else
|
andrewm@0
|
41 #define DAC_GPIO GPIO1
|
andrewm@0
|
42 #define DAC_CS_PIN (1<<16) // GPIO1:16 = P9 pin 15
|
andrewm@0
|
43 #endif
|
andrewm@0
|
44 #define DAC_TRM 0 // SPI transmit and receive
|
andrewm@0
|
45 #define DAC_WL 32 // Word length
|
andrewm@0
|
46 #define DAC_CLK_MODE 1 // SPI mode
|
andrewm@0
|
47 #define DAC_CLK_DIV 1 // Clock divider (48MHz / 2^n)
|
andrewm@0
|
48 #define DAC_DPE 1 // d0 = receive, d1 = transmit
|
andrewm@0
|
49
|
andrewm@0
|
50 #define AD5668_COMMAND_OFFSET 24
|
andrewm@0
|
51 #define AD5668_ADDRESS_OFFSET 20
|
andrewm@0
|
52 #define AD5668_DATA_OFFSET 4
|
andrewm@0
|
53 #define AD5668_REF_OFFSET 0
|
andrewm@0
|
54
|
andrewm@0
|
55 #ifdef DBOX_CAPE
|
andrewm@0
|
56 #define ADC_GPIO GPIO1
|
andrewm@0
|
57 #define ADC_CS_PIN (1<<16) // GPIO1:16 = P9 pin 15
|
andrewm@0
|
58 #else
|
andrewm@0
|
59 #define ADC_GPIO GPIO1
|
andrewm@0
|
60 #define ADC_CS_PIN (1<<17) // GPIO1:17 = P9 pin 23
|
andrewm@0
|
61 #endif
|
andrewm@0
|
62 #define ADC_TRM 0 // SPI transmit and receive
|
andrewm@0
|
63 #define ADC_WL 16 // Word length
|
andrewm@0
|
64 #define ADC_CLK_MODE 0 // SPI mode
|
andrewm@0
|
65 #define ADC_CLK_DIV 1 // Clock divider (48MHz / 2^n)
|
andrewm@0
|
66 #define ADC_DPE 1 // d0 = receive, d1 = transmit
|
andrewm@0
|
67
|
andrewm@0
|
68 #define AD7699_CFG_MASK 0xF120 // Mask for config update, unipolar, full BW
|
andrewm@0
|
69 #define AD7699_CHANNEL_OFFSET 9 // 7 bits offset of a 14-bit left-justified word
|
andrewm@0
|
70 #define AD7699_SEQ_OFFSET 3 // sequencer (0 = disable, 3 = scan all)
|
andrewm@0
|
71
|
andrewm@0
|
72 #define SHARED_COMM_MEM_BASE 0x00010000 // Location where comm flags are written
|
andrewm@0
|
73 #define COMM_SHOULD_STOP 0 // Set to be nonzero when loop should stop
|
andrewm@0
|
74 #define COMM_CURRENT_BUFFER 4 // Which buffer we are on
|
andrewm@0
|
75 #define COMM_BUFFER_FRAMES 8 // How many frames per buffer
|
andrewm@0
|
76 #define COMM_SHOULD_SYNC 12 // Whether to synchronise to an external clock
|
andrewm@0
|
77 #define COMM_SYNC_ADDRESS 16 // Which memory address to find the GPIO on
|
andrewm@0
|
78 #define COMM_SYNC_PIN_MASK 20 // Which pin to read for the sync
|
andrewm@0
|
79 #define COMM_LED_ADDRESS 24 // Which memory address to find the status LED on
|
andrewm@0
|
80 #define COMM_LED_PIN_MASK 28 // Which pin to write to change LED
|
andrewm@0
|
81 #define COMM_FRAME_COUNT 32 // How many frames have elapse since beginning
|
andrewm@0
|
82 #define COMM_USE_SPI 36 // Whether or not to use SPI ADC and DAC
|
andrewm@12
|
83 #define COMM_NUM_CHANNELS 40 // Low 2 bits indicate 8 [0x3], 4 [0x1] or 2 [0x0] channels
|
giuliomoro@16
|
84 #define COMM_USE_MATRIX_GPIO 44 // Whether or not to use MATRIX_GPIO
|
giuliomoro@16
|
85
|
andrewm@0
|
86 #define MCASP0_BASE 0x48038000
|
andrewm@0
|
87 #define MCASP1_BASE 0x4803C000
|
andrewm@0
|
88
|
andrewm@0
|
89 #define MCASP_PWRIDLESYSCONFIG 0x04
|
andrewm@0
|
90 #define MCASP_PFUNC 0x10
|
andrewm@0
|
91 #define MCASP_PDIR 0x14
|
andrewm@0
|
92 #define MCASP_PDOUT 0x18
|
andrewm@0
|
93 #define MCASP_PDSET 0x1C
|
andrewm@0
|
94 #define MCASP_PDIN 0x1C
|
andrewm@0
|
95 #define MCASP_PDCLR 0x20
|
andrewm@0
|
96 #define MCASP_GBLCTL 0x44
|
andrewm@0
|
97 #define MCASP_AMUTE 0x48
|
andrewm@0
|
98 #define MCASP_DLBCTL 0x4C
|
andrewm@0
|
99 #define MCASP_DITCTL 0x50
|
andrewm@0
|
100 #define MCASP_RGBLCTL 0x60
|
andrewm@0
|
101 #define MCASP_RMASK 0x64
|
andrewm@0
|
102 #define MCASP_RFMT 0x68
|
andrewm@0
|
103 #define MCASP_AFSRCTL 0x6C
|
andrewm@0
|
104 #define MCASP_ACLKRCTL 0x70
|
andrewm@0
|
105 #define MCASP_AHCLKRCTL 0x74
|
andrewm@0
|
106 #define MCASP_RTDM 0x78
|
andrewm@0
|
107 #define MCASP_RINTCTL 0x7C
|
andrewm@0
|
108 #define MCASP_RSTAT 0x80
|
andrewm@0
|
109 #define MCASP_RSLOT 0x84
|
andrewm@0
|
110 #define MCASP_RCLKCHK 0x88
|
andrewm@0
|
111 #define MCASP_REVTCTL 0x8C
|
andrewm@0
|
112 #define MCASP_XGBLCTL 0xA0
|
andrewm@0
|
113 #define MCASP_XMASK 0xA4
|
andrewm@0
|
114 #define MCASP_XFMT 0xA8
|
andrewm@0
|
115 #define MCASP_AFSXCTL 0xAC
|
andrewm@0
|
116 #define MCASP_ACLKXCTL 0xB0
|
andrewm@0
|
117 #define MCASP_AHCLKXCTL 0xB4
|
andrewm@0
|
118 #define MCASP_XTDM 0xB8
|
andrewm@0
|
119 #define MCASP_XINTCTL 0xBC
|
andrewm@0
|
120 #define MCASP_XSTAT 0xC0
|
andrewm@0
|
121 #define MCASP_XSLOT 0xC4
|
andrewm@0
|
122 #define MCASP_XCLKCHK 0xC8
|
andrewm@0
|
123 #define MCASP_XEVTCTL 0xCC
|
andrewm@0
|
124 #define MCASP_SRCTL0 0x180
|
andrewm@0
|
125 #define MCASP_SRCTL1 0x184
|
andrewm@0
|
126 #define MCASP_SRCTL2 0x188
|
andrewm@0
|
127 #define MCASP_SRCTL3 0x18C
|
andrewm@0
|
128 #define MCASP_SRCTL4 0x190
|
andrewm@0
|
129 #define MCASP_SRCTL5 0x194
|
andrewm@0
|
130 #define MCASP_XBUF0 0x200
|
andrewm@0
|
131 #define MCASP_XBUF1 0x204
|
andrewm@0
|
132 #define MCASP_XBUF2 0x208
|
andrewm@0
|
133 #define MCASP_XBUF3 0x20C
|
andrewm@0
|
134 #define MCASP_XBUF4 0x210
|
andrewm@0
|
135 #define MCASP_XBUF5 0x214
|
andrewm@0
|
136 #define MCASP_RBUF0 0x280
|
andrewm@0
|
137 #define MCASP_RBUF1 0x284
|
andrewm@0
|
138 #define MCASP_RBUF2 0x288
|
andrewm@0
|
139 #define MCASP_RBUF3 0x28C
|
andrewm@0
|
140 #define MCASP_RBUF4 0x290
|
andrewm@0
|
141 #define MCASP_RBUF5 0x294
|
andrewm@0
|
142 #define MCASP_WFIFOCTL 0x1000
|
andrewm@0
|
143 #define MCASP_WFIFOSTS 0x1004
|
andrewm@0
|
144 #define MCASP_RFIFOCTL 0x1008
|
andrewm@0
|
145 #define MCASP_RFIFOSTS 0x100C
|
andrewm@0
|
146
|
andrewm@0
|
147 #define MCASP_XSTAT_XDATA_BIT 5 // Bit to test for transmit ready
|
andrewm@0
|
148 #define MCASP_RSTAT_RDATA_BIT 5 // Bit to test for receive ready
|
andrewm@0
|
149
|
andrewm@0
|
150 // Constants used for this particular audio setup
|
andrewm@0
|
151 #define MCASP_BASE MCASP0_BASE
|
andrewm@0
|
152 #ifdef DBOX_CAPE
|
andrewm@0
|
153 #define MCASP_SRCTL_X MCASP_SRCTL2 // Ser. 2 is transmitter
|
andrewm@0
|
154 #define MCASP_SRCTL_R MCASP_SRCTL0 // Ser. 0 is receiver
|
andrewm@0
|
155 #define MCASP_XBUF MCASP_XBUF2
|
andrewm@0
|
156 #define MCASP_RBUF MCASP_RBUF0
|
andrewm@0
|
157 #else
|
andrewm@0
|
158 #define MCASP_SRCTL_X MCASP_SRCTL3 // Ser. 3 is transmitter
|
andrewm@0
|
159 #define MCASP_SRCTL_R MCASP_SRCTL2 // Ser. 2 is receiver
|
andrewm@0
|
160 #define MCASP_XBUF MCASP_XBUF3
|
andrewm@0
|
161 #define MCASP_RBUF MCASP_RBUF2
|
andrewm@0
|
162 #endif
|
andrewm@0
|
163
|
andrewm@0
|
164 #define MCASP_PIN_AFSX (1 << 28)
|
andrewm@0
|
165 #define MCASP_PIN_AHCLKX (1 << 27)
|
andrewm@0
|
166 #define MCASP_PIN_ACLKX (1 << 26)
|
andrewm@0
|
167 #define MCASP_PIN_AMUTE (1 << 25) // Also, 0 to 3 are XFR0 to XFR3
|
andrewm@0
|
168
|
andrewm@0
|
169 #ifdef DBOX_CAPE
|
andrewm@0
|
170 #define MCASP_OUTPUT_PINS MCASP_PIN_AHCLKX | (1 << 2) // AHCLKX and AXR2 outputs
|
andrewm@0
|
171 #else
|
andrewm@0
|
172 #define MCASP_OUTPUT_PINS (1 << 3) // Which pins are outputs
|
andrewm@0
|
173 #endif
|
andrewm@0
|
174
|
andrewm@0
|
175 #define MCASP_DATA_MASK 0xFFFF // 16 bit data
|
andrewm@0
|
176 #define MCASP_DATA_FORMAT 0x807C // MSB first, 0 bit delay, 16 bits, CFG bus, ROR 16bits
|
andrewm@0
|
177
|
andrewm@12
|
178 #define C_MCASP_MEM C28 // Shared PRU mem
|
andrewm@0
|
179
|
andrewm@0
|
180 // Flags for the flags register
|
andrewm@0
|
181 #define FLAG_BIT_BUFFER1 0
|
andrewm@0
|
182 #define FLAG_BIT_USE_SPI 1
|
andrewm@12
|
183 #define FLAG_BIT_MCASP_HWORD 2 // Whether we are on the high word for McASP transmission
|
giuliomoro@16
|
184 #define FLAG_BIT_USE_MATRIX_GPIO 3
|
giuliomoro@16
|
185 /*#define FLAG_BIT_MATRIX_GPIO_BUFFER 4 //Whether we are using buffer located at
|
giuliomoro@16
|
186 // 0: MEM_MATRIX_GPIO_BASE or
|
giuliomoro@16
|
187 */ // 1: MEM_MATRIX_GPIO_BASE + 512
|
andrewm@0
|
188 // Registers used throughout
|
andrewm@0
|
189
|
andrewm@0
|
190 // r1, r2, r3 are used for temporary storage
|
giuliomoro@16
|
191 #define MEM_MATRIX_GPIO_BASE 0x11000 //Base address for MATRIX_GPIO : Shared RAM + 0x400
|
giuliomoro@16
|
192 #define MEM_MATRIX_GPIO_BUFFER1_OFFSET 0x400 //Start pointer to MATRIX_GPIO_BUFFER1, which is 256 words after.
|
giuliomoro@16
|
193 // 256 is the maximum number of frames allowed
|
giuliomoro@16
|
194
|
giuliomoro@16
|
195 #define reg_matrix_gpio_current r6 // Pointer to current storage location of MATRIX_GPIO
|
andrewm@12
|
196 #define reg_num_channels r9 // Number of SPI ADC/DAC channels to use
|
andrewm@0
|
197 #define reg_frame_current r10 // Current frame count in SPI ADC/DAC transfer
|
andrewm@0
|
198 #define reg_frame_total r11 // Total frame count for SPI ADC/DAC
|
andrewm@0
|
199 #define reg_dac_data r12 // Current dword for SPI DAC
|
andrewm@0
|
200 #define reg_adc_data r13 // Current dword for SPI ADC
|
andrewm@0
|
201 #define reg_mcasp_dac_data r14 // Current dword for McASP DAC
|
andrewm@0
|
202 #define reg_mcasp_adc_data r15 // Current dword for McASP ADC
|
andrewm@0
|
203 #define reg_dac_buf0 r16 // Start pointer to SPI DAC buffer 0
|
andrewm@0
|
204 #define reg_dac_buf1 r17 // Start pointer to SPI DAC buffer 1
|
andrewm@0
|
205 #define reg_dac_current r18 // Pointer to current storage location of SPI DAC
|
andrewm@0
|
206 #define reg_adc_current r19 // Pointer to current storage location of SPI ADC
|
andrewm@0
|
207 #define reg_mcasp_buf0 r20 // Start pointer to McASP DAC buffer 0
|
andrewm@0
|
208 #define reg_mcasp_buf1 r21 // Start pointer to McASP DAC buffer 1
|
andrewm@0
|
209 #define reg_mcasp_dac_current r22 // Pointer to current storage location of McASP DAC
|
andrewm@0
|
210 #define reg_mcasp_adc_current r23 // Pointer to current storage location of McASP ADC
|
andrewm@0
|
211 #define reg_flags r24 // Buffer ID (0 and 1) and other flags
|
andrewm@0
|
212 #define reg_comm_addr r25 // Memory address for communicating with ARM
|
andrewm@0
|
213 #define reg_spi_addr r26 // Base address for SPI
|
andrewm@0
|
214 // r27, r28 used in macros
|
andrewm@0
|
215 #define reg_mcasp_addr r29 // Base address for McASP
|
andrewm@0
|
216
|
giuliomoro@16
|
217 // MATRIX_GPIO new code starts here
|
giuliomoro@16
|
218 //0 P8_07 36 0x890/090 66 gpio2[2]
|
giuliomoro@16
|
219 //1 P8_08 37 0x894/094 67 gpio2[3]
|
giuliomoro@16
|
220 //2 P8_09 39 0x89c/09c 69 gpio2[5]
|
giuliomoro@16
|
221 //3 P8_10 38 0x898/098 68 gpio2[4]
|
giuliomoro@16
|
222 //4 P8_11 13 0x834/034 45 gpio1[13]
|
giuliomoro@16
|
223 //5 P8_12 12 0x830/030 44 gpio1[12]
|
giuliomoro@16
|
224 //6 P9_12 30 0x878/078 60 gpio1[28]
|
giuliomoro@16
|
225 //7 P9_14 18 0x848/048 50 gpio1[18]
|
giuliomoro@16
|
226 //8 P8_15 15 0x83c/03c 47 gpio1[15]
|
giuliomoro@16
|
227 //9 P8_16 14 0x838/038 46 gpio1[14]
|
giuliomoro@16
|
228 //10 P9_16 19 0x84c/04c 51 gpio1[19]
|
giuliomoro@16
|
229 //11 P8_18 35 0x88c/08c 65 gpio2[1]
|
giuliomoro@16
|
230 //12 P8_27 56 0x8e0/0e0 86 gpio2[22]
|
giuliomoro@16
|
231 //13 P8_28 58 0x8e8/0e8 88 gpio2[24]
|
giuliomoro@16
|
232 //14 P8_29 57 0x8e4/0e4 87 gpio2[23]
|
giuliomoro@16
|
233 //15 P8_30 59 0x8ec/0ec 89 gpio2[25]
|
giuliomoro@16
|
234
|
giuliomoro@16
|
235 //TODO during initialization, set the pinmuxers to mode 7, input enable
|
giuliomoro@16
|
236
|
giuliomoro@16
|
237 //generic GPIOs constants
|
giuliomoro@16
|
238 //#define GPIO1 0x4804c000
|
giuliomoro@16
|
239 #define GPIO2 0x481ac000
|
giuliomoro@16
|
240 //#define GPIO_CLEARDATAOUT 0x190 //SETDATAOUT is CLEARDATAOUT+4
|
giuliomoro@16
|
241 #define GPIO_OE 0x134
|
giuliomoro@16
|
242 #define GPIO_DATAIN 0x138
|
giuliomoro@16
|
243
|
giuliomoro@16
|
244 //gpioX_oe must be adjacent to gpioX_datain
|
giuliomoro@16
|
245 //gpioX_cleardataout must be adjacent to gpioX_setdataout
|
giuliomoro@16
|
246 #define reg_gpio1_oe r2
|
giuliomoro@16
|
247 #define reg_gpio2_oe r3
|
giuliomoro@16
|
248 #define reg_gpio2_cleardataout r4
|
giuliomoro@16
|
249 #define reg_gpio2_setdataout r5
|
giuliomoro@16
|
250 #define reg_gpio1_cleardataout r7
|
giuliomoro@16
|
251 #define reg_gpio1_setdataout r8
|
giuliomoro@16
|
252 #define reg_matrix_gpio r27 //will first contain matrixGpioOut from render() and matrixGpioIn to render() later
|
giuliomoro@16
|
253 //aliases
|
giuliomoro@16
|
254 #define reg_gpio1_datain reg_gpio1_oe
|
giuliomoro@16
|
255 #define reg_gpio2_datain reg_gpio2_oe
|
giuliomoro@16
|
256
|
giuliomoro@16
|
257 .macro SET_GPIO1_BITS
|
giuliomoro@16
|
258 .mparam gpio_num_bit, matrix_gpio_bit
|
giuliomoro@16
|
259 SET_GPIO_BITS reg_gpio1_oe, reg_gpio1_setdataout, reg_gpio1_cleardataout, gpio_num_bit, matrix_gpio_bit, reg_matrix_gpio
|
giuliomoro@16
|
260 .endm
|
giuliomoro@16
|
261 .macro SET_GPIO2_BITS
|
giuliomoro@16
|
262 .mparam gpio_num_bit, matrix_gpio_bit
|
giuliomoro@16
|
263 SET_GPIO_BITS reg_gpio2_oe, reg_gpio2_setdataout, reg_gpio2_cleardataout, gpio_num_bit, matrix_gpio_bit, reg_matrix_gpio
|
giuliomoro@16
|
264 .endm
|
giuliomoro@16
|
265 .macro READ_GPIO1_BITS
|
giuliomoro@16
|
266 .mparam gpio_num_bit, matrix_gpio_bit
|
giuliomoro@16
|
267 READ_GPIO_BITS reg_gpio1_datain, gpio_num_bit, matrix_gpio_bit, reg_matrix_gpio
|
giuliomoro@16
|
268 .endm
|
giuliomoro@16
|
269 .macro READ_GPIO2_BITS
|
giuliomoro@16
|
270 .mparam gpio_num_bit, matrix_gpio_bit
|
giuliomoro@16
|
271 READ_GPIO_BITS reg_gpio2_datain, gpio_num_bit, matrix_gpio_bit, reg_matrix_gpio
|
giuliomoro@16
|
272 .endm
|
giuliomoro@16
|
273
|
giuliomoro@16
|
274 .macro READ_GPIO_BITS
|
giuliomoro@16
|
275 .mparam gpio_data, gpio_num_bit, matrix_gpio_bit, matrix_gpio
|
giuliomoro@16
|
276 QBBC DONE, matrix_gpio, matrix_gpio_bit //if the pin is set as an output, nothing to do here
|
giuliomoro@16
|
277 SET r30.t14
|
giuliomoro@16
|
278 QBBC CLEAR, gpio_data, gpio_num_bit
|
giuliomoro@16
|
279 SET matrix_gpio, matrix_gpio_bit+16
|
giuliomoro@16
|
280 QBA DONE
|
giuliomoro@16
|
281 CLEAR:
|
giuliomoro@16
|
282 CLR matrix_gpio, matrix_gpio_bit+16
|
giuliomoro@16
|
283 QBA DONE
|
giuliomoro@16
|
284 DONE:
|
giuliomoro@16
|
285 CLR r30.t14
|
giuliomoro@16
|
286 .endm
|
giuliomoro@16
|
287
|
giuliomoro@16
|
288 .macro SET_GPIO_BITS
|
giuliomoro@16
|
289 .mparam gpio_oe, gpio_setdataout, gpio_cleardataout, gpio_num_bit, matrix_gpio_bit, matrix_gpio //sets the bits in GPIO_OE, GPIO_SETDATAOUT and GPIO_CLEARDATAOUT
|
giuliomoro@16
|
290 //Remember that the GPIO_OE Output data enable register behaves as follows for each bit:
|
giuliomoro@16
|
291 //0 = The corresponding GPIO pin is configured as an output.
|
giuliomoro@16
|
292 //1 = The corresponding GPIO pin is configured as an input.
|
giuliomoro@16
|
293 QBBS SETINPUT, matrix_gpio, matrix_gpio_bit
|
giuliomoro@16
|
294 CLR gpio_oe, gpio_num_bit //if it is an output, configure pin as output
|
giuliomoro@16
|
295 QBBC CLEARDATAOUT, matrix_gpio, matrix_gpio_bit+16 // check the output value. If it is 0, branch
|
giuliomoro@16
|
296 SET gpio_setdataout, gpio_num_bit //if it is 1, set output to high
|
giuliomoro@16
|
297 QBA DONE
|
giuliomoro@16
|
298 CLEARDATAOUT:
|
giuliomoro@16
|
299 SET gpio_cleardataout, gpio_num_bit // set output to low
|
giuliomoro@16
|
300 QBA DONE
|
giuliomoro@16
|
301 SETINPUT: //if it is an input, set the relevant bit
|
giuliomoro@16
|
302 SET gpio_oe, gpio_num_bit
|
giuliomoro@16
|
303 QBA DONE
|
giuliomoro@16
|
304 DONE:
|
giuliomoro@16
|
305 .endm
|
giuliomoro@16
|
306
|
giuliomoro@16
|
307 .macro PROCESS_GPIO1_BITS
|
giuliomoro@16
|
308 //- sets appropriate bits for output in reg_gpio1_oe, reg_gpio1_cleardataout, reg_gpio1_data
|
giuliomoro@16
|
309 //- sets appropriate bits in reg_matrix_gpio to reflect the input values
|
giuliomoro@16
|
310 .mparam gpio_num_bit, matrix_gpio_bit
|
giuliomoro@16
|
311 // params to SET_GPIO_BITS gpio_oe, gpio_setdataout, gpio_cleardataout, gpio_num_bit, matrix_gpio_bit, matrix_gpio //sets the bits in GPIO_OE, GPIO_SETDATAOUT and GPIO_CLEARDATAOUT
|
giuliomoro@16
|
312 SET_GPIO_BITS reg_gpio1_oe, reg_gpio1_setdataout, reg_gpio1_cleardataout, gpio_num_bit, matrix_gpio_bit, reg_matrix_gpio
|
giuliomoro@16
|
313 READ_GPIO_BITS reg_gpio1_oe, reg_gpio1_datain, gpio_num_bit, matrix_gpio_bit, reg_matrix_gpio
|
giuliomoro@16
|
314 .endm
|
giuliomoro@16
|
315
|
giuliomoro@16
|
316 .macro PROCESS_GPIO2_BITS
|
giuliomoro@16
|
317 //- sets appropriate bits for output in reg_gpio2_oe, reg_gpio2_cleardataout, reg_gpio2_data
|
giuliomoro@16
|
318 //- sets appropriate bits in reg_matrix_gpio to reflect the input values
|
giuliomoro@16
|
319 .mparam gpio_num_bit, matrix_gpio_bit
|
giuliomoro@16
|
320 SET_GPIO_BITS reg_gpio2_oe, reg_gpio2_setdataout, reg_gpio2_cleardataout, gpio_num_bit, matrix_gpio_bit, reg_matrix_gpio
|
giuliomoro@16
|
321 READ_GPIO_BITS reg_gpio2_oe, reg_gpio2_datain, gpio_num_bit, matrix_gpio_bit, reg_matrix_gpio
|
giuliomoro@16
|
322 .endm
|
giuliomoro@16
|
323
|
giuliomoro@16
|
324 QBA START // when first starting, go to START, skipping this section.
|
giuliomoro@16
|
325
|
giuliomoro@16
|
326 MATRIX_GPIO:
|
giuliomoro@16
|
327 //reg_matrix_gpio is now the input word passed in render(), one word per frame
|
giuliomoro@16
|
328 //[31:16]: data(1=high, 0=low), [15:0]: direction (0=output, 1=input) )
|
giuliomoro@16
|
329 //Preparing the gpio_oe, gpio_cleardataout and gpio_setdataout for each module
|
giuliomoro@16
|
330
|
giuliomoro@16
|
331 //load current status of GPIO_OE in reg_gpioX_oe
|
giuliomoro@16
|
332 MOV reg_gpio1_oe, GPIO1 | GPIO_OE
|
giuliomoro@16
|
333 //takes ...ns to go through the next two instructions
|
giuliomoro@16
|
334 LBBO reg_gpio1_oe, reg_gpio1_oe, 0, 4
|
giuliomoro@16
|
335 //GPIO1-start
|
giuliomoro@16
|
336 //process oe and datain and prepare dataout for GPIO1
|
giuliomoro@16
|
337 LDI reg_gpio1_setdataout, 0
|
giuliomoro@16
|
338 LDI reg_gpio1_cleardataout, 0
|
giuliomoro@16
|
339 //map GPIO_MATRIX to gpio1 pins, affects reg_gpio1_oe, reg_gpio1_cleardataout, reg_gpio1_data, reg_matrix_gpio
|
giuliomoro@16
|
340 SET_GPIO1_BITS 13, 4
|
giuliomoro@16
|
341 SET_GPIO1_BITS 12, 5
|
giuliomoro@16
|
342 SET_GPIO1_BITS 28, 6
|
giuliomoro@16
|
343 SET_GPIO1_BITS 18, 7
|
giuliomoro@16
|
344 SET_GPIO1_BITS 15, 8
|
giuliomoro@16
|
345 SET_GPIO1_BITS 14, 9
|
giuliomoro@16
|
346 SET_GPIO1_BITS 19, 10
|
giuliomoro@16
|
347 //set the output enable register for gpio1.
|
giuliomoro@16
|
348 MOV reg_gpio2_oe, GPIO1 | GPIO_OE //reg_gpio2_oe is now unused. It is here used as a temp
|
giuliomoro@16
|
349 SBBO reg_gpio1_oe, reg_gpio2_oe, 0, 4 //takes two cycles (10ns)
|
giuliomoro@16
|
350 //GPIO1-end
|
giuliomoro@16
|
351
|
giuliomoro@16
|
352 // reg_gpio1_oe is now unused, its register is taken by gpio2_cleardataout
|
giuliomoro@16
|
353 // reg_gpio1_datain now unused, its register is taken by gpio2_setdataout
|
giuliomoro@16
|
354 //GPIO2-start
|
giuliomoro@16
|
355 //load current status of GPIO_OE in reg_gpioX_oe
|
giuliomoro@16
|
356 MOV reg_gpio2_oe, GPIO2 | GPIO_OE
|
giuliomoro@16
|
357 //takes ...ns to go through the next two instructions
|
giuliomoro@16
|
358 LBBO reg_gpio2_oe, reg_gpio1_oe, 0, 4
|
giuliomoro@16
|
359 //process oe and datain and prepare dataout for GPIO2
|
giuliomoro@16
|
360 LDI reg_gpio2_setdataout, 0
|
giuliomoro@16
|
361 LDI reg_gpio2_cleardataout, 0
|
giuliomoro@16
|
362 //map GPIO_MATRIX to gpio2 pins, affects reg_gpio2_oe, reg_gpio2_cleardataout, reg_gpio2_data, reg_matrix_gpio
|
giuliomoro@16
|
363 SET_GPIO2_BITS 2, 0
|
giuliomoro@16
|
364 SET_GPIO2_BITS 3, 1
|
giuliomoro@16
|
365 SET_GPIO2_BITS 5, 2
|
giuliomoro@16
|
366 SET_GPIO2_BITS 4, 3
|
giuliomoro@16
|
367 SET_GPIO2_BITS 1, 11
|
giuliomoro@16
|
368 SET_GPIO2_BITS 22, 12
|
giuliomoro@16
|
369 SET_GPIO2_BITS 24, 13
|
giuliomoro@16
|
370 SET_GPIO2_BITS 23, 14
|
giuliomoro@16
|
371 SET_GPIO2_BITS 25, 15
|
giuliomoro@16
|
372 //set the output enable register for gpio2.
|
giuliomoro@16
|
373 MOV reg_gpio1_oe, GPIO2 | GPIO_OE //reg_gpio1_oe is now unused. It is here used as a temp
|
giuliomoro@16
|
374 SBBO reg_gpio2_oe, reg_gpio1_oe, 0, 4 //takes two cycles (10ns)
|
giuliomoro@16
|
375 //GPIO2-end
|
giuliomoro@16
|
376
|
giuliomoro@16
|
377 //load current inputs in reg_gpioX_datain
|
giuliomoro@16
|
378 MOV reg_gpio1_datain, GPIO1 | GPIO_DATAIN
|
giuliomoro@16
|
379 MOV reg_gpio2_datain, GPIO2 | GPIO_DATAIN
|
giuliomoro@16
|
380 //takes ...ns to go through the next two instructions
|
giuliomoro@16
|
381 LBBO reg_gpio1_datain, reg_gpio1_datain, 0, 4
|
giuliomoro@16
|
382 LBBO reg_gpio2_datain, reg_gpio2_datain, 0, 4
|
giuliomoro@16
|
383 //TODO: read inputs
|
giuliomoro@16
|
384 READ_GPIO1_BITS 13, 4
|
giuliomoro@16
|
385 READ_GPIO1_BITS 12, 5
|
giuliomoro@16
|
386 READ_GPIO1_BITS 28, 6
|
giuliomoro@16
|
387 READ_GPIO1_BITS 18, 7
|
giuliomoro@16
|
388 READ_GPIO1_BITS 15, 8
|
giuliomoro@16
|
389 READ_GPIO1_BITS 14, 9
|
giuliomoro@16
|
390 READ_GPIO1_BITS 19, 10
|
giuliomoro@16
|
391 READ_GPIO2_BITS 2, 0
|
giuliomoro@16
|
392 READ_GPIO2_BITS 3, 1
|
giuliomoro@16
|
393 READ_GPIO2_BITS 5, 2
|
giuliomoro@16
|
394 READ_GPIO2_BITS 4, 3
|
giuliomoro@16
|
395 READ_GPIO2_BITS 1, 11
|
giuliomoro@16
|
396 READ_GPIO2_BITS 22, 12
|
giuliomoro@16
|
397 READ_GPIO2_BITS 24, 13
|
giuliomoro@16
|
398 READ_GPIO2_BITS 23, 14
|
giuliomoro@16
|
399 READ_GPIO2_BITS 25, 15
|
giuliomoro@16
|
400 //reg_gpio2_oe is now unused, so reg_temp1 is available for temporary storage from now on
|
giuliomoro@16
|
401 //reg_gpio2_datain is now unsued, so reg_temp2 is available for temporary storage from now on
|
giuliomoro@16
|
402
|
giuliomoro@16
|
403 //now all the setdataout and cleardataout are ready to be written to the GPIO register.
|
giuliomoro@16
|
404 //CLEARDATAOUT and SETDATAOUT are consecutive positions in memory, so we write 8 bytes to CLEARDATAOUT.
|
giuliomoro@16
|
405 //We can do this because we chose reg_gpio1_cleardataout and reg_gpioX_setdataout to be consecutive
|
giuliomoro@16
|
406 //load the memory addresses to be written to
|
giuliomoro@16
|
407 MOV reg_gpio1_datain, GPIO1 | GPIO_CLEARDATAOUT //reg_gpio1_datain is now unused and is used here as a temp
|
giuliomoro@16
|
408 MOV reg_gpio2_datain, GPIO2 | GPIO_CLEARDATAOUT //reg_gpio2_datain is now unused and is used here as a temp
|
giuliomoro@16
|
409 //write 8 bytes for each GPIO
|
giuliomoro@16
|
410 //takes 30ns in total to go through the followint two lines
|
giuliomoro@16
|
411 SBBO reg_gpio1_cleardataout, reg_gpio1_datain, 0, 8 // takes 145ns to be effective when going low, 185ns when going high
|
giuliomoro@16
|
412 SBBO reg_gpio2_cleardataout, reg_gpio2_datain, 0, 8 //takes 95ns to be effective when going low, 130ns when going high
|
giuliomoro@16
|
413 //reversing the order of the two lines above will swap the performances between the GPIO modules
|
giuliomoro@16
|
414 //i.e.: the first line will always take 145ns/185ns and the second one will always take 95ns/130ns,
|
giuliomoro@16
|
415 //regardless of whether the order is gpio1-gpio2 or gpio2-gpio1
|
giuliomoro@16
|
416 JMP r28.w0 // go back to ADC_WRITE_GPIO
|
giuliomoro@16
|
417
|
giuliomoro@16
|
418 // MATRIX_GPIO new code ends here
|
giuliomoro@16
|
419
|
andrewm@0
|
420
|
andrewm@0
|
421 // Bring CS line low to write to DAC
|
andrewm@0
|
422 .macro DAC_CS_ASSERT
|
andrewm@0
|
423 MOV r27, DAC_CS_PIN
|
andrewm@0
|
424 MOV r28, DAC_GPIO + GPIO_CLEARDATAOUT
|
andrewm@0
|
425 SBBO r27, r28, 0, 4
|
andrewm@0
|
426 .endm
|
andrewm@0
|
427
|
andrewm@0
|
428 // Bring CS line high at end of DAC transaction
|
andrewm@0
|
429 .macro DAC_CS_UNASSERT
|
andrewm@0
|
430 MOV r27, DAC_CS_PIN
|
andrewm@0
|
431 MOV r28, DAC_GPIO + GPIO_SETDATAOUT
|
andrewm@0
|
432 SBBO r27, r28, 0, 4
|
andrewm@0
|
433 .endm
|
andrewm@0
|
434
|
andrewm@0
|
435 // Write to DAC TX register
|
andrewm@0
|
436 .macro DAC_TX
|
andrewm@0
|
437 .mparam data
|
andrewm@0
|
438 SBBO data, reg_spi_addr, SPI_CH0TX, 4
|
andrewm@0
|
439 .endm
|
andrewm@0
|
440
|
andrewm@0
|
441 // Wait for SPI to finish (uses RXS indicator)
|
andrewm@0
|
442 .macro DAC_WAIT_FOR_FINISH
|
andrewm@0
|
443 LOOP:
|
andrewm@0
|
444 LBBO r27, reg_spi_addr, SPI_CH0STAT, 4
|
andrewm@0
|
445 QBBC LOOP, r27, 0
|
andrewm@0
|
446 .endm
|
andrewm@0
|
447
|
andrewm@0
|
448 // Read the RX word to clear
|
andrewm@0
|
449 .macro DAC_DISCARD_RX
|
andrewm@0
|
450 LBBO r27, reg_spi_addr, SPI_CH0RX, 4
|
andrewm@0
|
451 .endm
|
andrewm@0
|
452
|
andrewm@0
|
453 // Complete DAC write with chip select
|
andrewm@0
|
454 .macro DAC_WRITE
|
andrewm@0
|
455 .mparam reg
|
andrewm@0
|
456 DAC_CS_ASSERT
|
andrewm@0
|
457 DAC_TX reg
|
andrewm@0
|
458 DAC_WAIT_FOR_FINISH
|
andrewm@0
|
459 DAC_CS_UNASSERT
|
andrewm@0
|
460 DAC_DISCARD_RX
|
andrewm@0
|
461 .endm
|
andrewm@0
|
462
|
andrewm@0
|
463 // Bring CS line low to write to ADC
|
andrewm@0
|
464 .macro ADC_CS_ASSERT
|
andrewm@0
|
465 MOV r27, ADC_CS_PIN
|
andrewm@0
|
466 MOV r28, ADC_GPIO + GPIO_CLEARDATAOUT
|
andrewm@0
|
467 SBBO r27, r28, 0, 4
|
andrewm@0
|
468 .endm
|
andrewm@0
|
469
|
andrewm@0
|
470 // Bring CS line high at end of ADC transaction
|
andrewm@0
|
471 .macro ADC_CS_UNASSERT
|
andrewm@0
|
472 MOV r27, ADC_CS_PIN
|
andrewm@0
|
473 MOV r28, ADC_GPIO + GPIO_SETDATAOUT
|
andrewm@0
|
474 SBBO r27, r28, 0, 4
|
andrewm@0
|
475 .endm
|
andrewm@0
|
476
|
andrewm@0
|
477 // Write to ADC TX register
|
andrewm@0
|
478 .macro ADC_TX
|
andrewm@0
|
479 .mparam data
|
andrewm@0
|
480 SBBO data, reg_spi_addr, SPI_CH1TX, 4
|
andrewm@0
|
481 .endm
|
andrewm@0
|
482
|
andrewm@0
|
483 // Wait for SPI to finish (uses RXS indicator)
|
andrewm@0
|
484 .macro ADC_WAIT_FOR_FINISH
|
andrewm@0
|
485 LOOP:
|
andrewm@0
|
486 LBBO r27, reg_spi_addr, SPI_CH1STAT, 4
|
andrewm@0
|
487 QBBC LOOP, r27, 0
|
andrewm@0
|
488 .endm
|
andrewm@0
|
489
|
andrewm@0
|
490 // Read the RX word to clear; store output
|
andrewm@0
|
491 .macro ADC_RX
|
andrewm@0
|
492 .mparam data
|
andrewm@0
|
493 LBBO data, reg_spi_addr, SPI_CH1RX, 4
|
andrewm@0
|
494 .endm
|
andrewm@0
|
495
|
andrewm@0
|
496 // Complete ADC write+read with chip select
|
andrewm@0
|
497 .macro ADC_WRITE
|
andrewm@0
|
498 .mparam in, out
|
andrewm@0
|
499 ADC_CS_ASSERT
|
andrewm@0
|
500 ADC_TX in
|
andrewm@0
|
501 ADC_WAIT_FOR_FINISH
|
andrewm@0
|
502 ADC_RX out
|
andrewm@0
|
503 ADC_CS_UNASSERT
|
andrewm@0
|
504 .endm
|
andrewm@0
|
505
|
giuliomoro@16
|
506 // Complete ADC write+read with chip select and also performs IO for matrix_gpio
|
giuliomoro@16
|
507 .macro ADC_WRITE_GPIO
|
giuliomoro@16
|
508 .mparam in, out, do_gpio
|
giuliomoro@16
|
509 ADC_CS_ASSERT
|
giuliomoro@16
|
510 ADC_TX in
|
giuliomoro@16
|
511 QBBC GPIO_DONE, reg_flags, FLAG_BIT_USE_MATRIX_GPIO //skip if MATRIX_GPIO is disabled
|
giuliomoro@16
|
512 AND r27, do_gpio, 0x3 // only do a MATRIX_GPIO every 2 SPI I/O
|
giuliomoro@16
|
513 QBNE GPIO_DONE, r27, 0
|
giuliomoro@16
|
514 //from here to GPIO_DONE takes 1.8us, while usually ADC_WAIT_FOR_FINISH only waits for 1.14us.
|
giuliomoro@16
|
515 //TODO: it would be better to split the MATRIX_GPIO stuff in two parts:
|
giuliomoro@16
|
516 //- one taking place during DAC_WRITE which sets the GPIO_OE
|
giuliomoro@16
|
517 //- and the other during ADC_WRITE which actually reads DATAIN and writes CLEAR/SET DATAOUT
|
giuliomoro@16
|
518 //reg_matrix_gpio is actually r27, so do not use r27 from here to ...
|
giuliomoro@16
|
519 LBBO reg_matrix_gpio, reg_matrix_gpio_current, 0, 4
|
giuliomoro@16
|
520 JAL r28.w0, MATRIX_GPIO
|
giuliomoro@16
|
521 SBBO reg_matrix_gpio, reg_matrix_gpio_current, 0, 4
|
giuliomoro@16
|
522 //..here you can start using r27 again
|
giuliomoro@16
|
523 ADD reg_matrix_gpio_current, reg_matrix_gpio_current, 4 //increment pointer
|
giuliomoro@16
|
524 GPIO_DONE:
|
giuliomoro@16
|
525 ADC_WAIT_FOR_FINISH
|
giuliomoro@16
|
526 ADC_RX out
|
giuliomoro@16
|
527 ADC_CS_UNASSERT
|
giuliomoro@16
|
528 .endm
|
giuliomoro@16
|
529
|
andrewm@0
|
530 // Write a McASP register
|
andrewm@0
|
531 .macro MCASP_REG_WRITE
|
andrewm@0
|
532 .mparam reg, value
|
andrewm@0
|
533 MOV r27, value
|
andrewm@0
|
534 SBBO r27, reg_mcasp_addr, reg, 4
|
andrewm@0
|
535 .endm
|
andrewm@0
|
536
|
andrewm@0
|
537 // Write a McASP register beyond the 0xFF boundary
|
andrewm@0
|
538 .macro MCASP_REG_WRITE_EXT
|
andrewm@0
|
539 .mparam reg, value
|
andrewm@0
|
540 MOV r27, value
|
andrewm@0
|
541 MOV r28, reg
|
andrewm@0
|
542 ADD r28, reg_mcasp_addr, r28
|
andrewm@0
|
543 SBBO r27, r28, 0, 4
|
andrewm@0
|
544 .endm
|
andrewm@0
|
545
|
andrewm@0
|
546 // Read a McASP register
|
andrewm@0
|
547 .macro MCASP_REG_READ
|
andrewm@0
|
548 .mparam reg, value
|
andrewm@0
|
549 LBBO value, reg_mcasp_addr, reg, 4
|
andrewm@0
|
550 .endm
|
andrewm@0
|
551
|
andrewm@0
|
552 // Read a McASP register beyond the 0xFF boundary
|
andrewm@0
|
553 .macro MCASP_REG_READ_EXT
|
andrewm@0
|
554 .mparam reg, value
|
andrewm@0
|
555 MOV r28, reg
|
andrewm@0
|
556 ADD r28, reg_mcasp_addr, r28
|
andrewm@0
|
557 LBBO value, r28, 0, 4
|
andrewm@0
|
558 .endm
|
andrewm@0
|
559
|
andrewm@0
|
560 // Set a bit and wait for it to come up
|
andrewm@0
|
561 .macro MCASP_REG_SET_BIT_AND_POLL
|
andrewm@0
|
562 .mparam reg, mask
|
andrewm@0
|
563 MOV r27, mask
|
andrewm@0
|
564 LBBO r28, reg_mcasp_addr, reg, 4
|
andrewm@0
|
565 OR r28, r28, r27
|
andrewm@0
|
566 SBBO r28, reg_mcasp_addr, reg, 4
|
andrewm@0
|
567 POLL:
|
andrewm@0
|
568 LBBO r28, reg_mcasp_addr, reg, 4
|
andrewm@0
|
569 AND r28, r28, r27
|
andrewm@0
|
570 QBEQ POLL, r28, 0
|
andrewm@0
|
571 .endm
|
andrewm@0
|
572
|
andrewm@0
|
573 START:
|
giuliomoro@16
|
574 MOV r30, 0
|
andrewm@0
|
575 // Set up c24 and c25 offsets with CTBIR register
|
andrewm@0
|
576 // Thus C24 points to start of PRU0 RAM
|
andrewm@0
|
577 MOV r3, 0x22020 // CTBIR0
|
andrewm@0
|
578 MOV r2, 0
|
andrewm@0
|
579 SBBO r2, r3, 0, 4
|
andrewm@0
|
580
|
andrewm@0
|
581 // Set up c28 pointer offset for shared PRU RAM
|
andrewm@0
|
582 MOV r3, 0x22028 // CTPPR0
|
andrewm@0
|
583 MOV r2, 0x00000120 // To get address 0x00012000
|
andrewm@0
|
584 SBBO r2, r3, 0, 4
|
andrewm@0
|
585
|
andrewm@0
|
586 // Load useful registers for addressing SPI
|
andrewm@0
|
587 MOV reg_comm_addr, SHARED_COMM_MEM_BASE
|
andrewm@0
|
588 MOV reg_spi_addr, SPI_BASE
|
andrewm@0
|
589 MOV reg_mcasp_addr, MCASP_BASE
|
andrewm@0
|
590
|
andrewm@0
|
591 // Set ARM such that PRU can write to registers
|
andrewm@0
|
592 LBCO r0, C4, 4, 4
|
andrewm@0
|
593 CLR r0, r0, 4
|
andrewm@0
|
594 SBCO r0, C4, 4, 4
|
andrewm@0
|
595
|
andrewm@0
|
596 // Clear flags
|
andrewm@0
|
597 MOV reg_flags, 0
|
andrewm@0
|
598
|
andrewm@12
|
599 // Default number of channels in case SPI disabled
|
andrewm@12
|
600 LDI reg_num_channels, 8
|
andrewm@12
|
601
|
giuliomoro@16
|
602 // Find out whether we should use MATRIX_GPIO
|
giuliomoro@16
|
603 LBBO r2, reg_comm_addr, COMM_USE_MATRIX_GPIO, 4
|
giuliomoro@16
|
604 QBEQ MATRIX_GPIO_FLAG_CHECK_DONE, r2, 0
|
giuliomoro@16
|
605 SET reg_flags, reg_flags, FLAG_BIT_USE_MATRIX_GPIO
|
giuliomoro@16
|
606 // SET reg_flags, reg_flags, FLAG_BIT_MATRIX_GPIO_BUFFER //set the flag, so that in WRITE_ONE_BUFFER we will start from buffer0
|
giuliomoro@16
|
607 MATRIX_GPIO_FLAG_CHECK_DONE:
|
andrewm@0
|
608 // Find out whether we should use SPI ADC and DAC
|
andrewm@0
|
609 LBBO r2, reg_comm_addr, COMM_USE_SPI, 4
|
andrewm@0
|
610 QBEQ SPI_FLAG_CHECK_DONE, r2, 0
|
andrewm@0
|
611 SET reg_flags, reg_flags, FLAG_BIT_USE_SPI
|
andrewm@0
|
612
|
andrewm@0
|
613 SPI_FLAG_CHECK_DONE:
|
andrewm@0
|
614 // If we don't use SPI, then skip all this init
|
andrewm@0
|
615 QBBC SPI_INIT_DONE, reg_flags, FLAG_BIT_USE_SPI
|
andrewm@12
|
616
|
andrewm@12
|
617 // Load the number of channels: valid values are 8, 4 or 2
|
andrewm@12
|
618 LBBO reg_num_channels, reg_comm_addr, COMM_NUM_CHANNELS, 4
|
andrewm@12
|
619 QBGT SPI_NUM_CHANNELS_LT8, reg_num_channels, 8 // 8 > num_channels ?
|
andrewm@12
|
620 LDI reg_num_channels, 8 // If N >= 8, N = 8
|
andrewm@12
|
621 QBA SPI_NUM_CHANNELS_DONE
|
andrewm@12
|
622 SPI_NUM_CHANNELS_LT8:
|
andrewm@12
|
623 QBGT SPI_NUM_CHANNELS_LT4, reg_num_channels, 4 // 4 > num_channels ?
|
andrewm@12
|
624 LDI reg_num_channels, 4 // If N >= 4, N = 4
|
andrewm@12
|
625 QBA SPI_NUM_CHANNELS_DONE
|
andrewm@12
|
626 SPI_NUM_CHANNELS_LT4:
|
andrewm@12
|
627 LDI reg_num_channels, 2 // else N = 2
|
andrewm@12
|
628 SPI_NUM_CHANNELS_DONE:
|
andrewm@0
|
629
|
andrewm@0
|
630 // Init SPI clock
|
andrewm@0
|
631 MOV r2, 0x02
|
andrewm@0
|
632 MOV r3, CLOCK_BASE + CLOCK_SPI0
|
andrewm@0
|
633 SBBO r2, r3, 0, 4
|
andrewm@0
|
634
|
andrewm@0
|
635 // Reset SPI and wait for finish
|
andrewm@0
|
636 MOV r2, 0x02
|
andrewm@0
|
637 SBBO r2, reg_spi_addr, SPI_SYSCONFIG, 4
|
andrewm@0
|
638
|
andrewm@0
|
639 SPI_WAIT_RESET:
|
andrewm@0
|
640 LBBO r2, reg_spi_addr, SPI_SYSSTATUS, 4
|
andrewm@0
|
641 QBBC SPI_WAIT_RESET, r2, 0
|
andrewm@0
|
642
|
andrewm@0
|
643 // Turn off SPI channels
|
andrewm@0
|
644 MOV r2, 0
|
andrewm@0
|
645 SBBO r2, reg_spi_addr, SPI_CH0CTRL, 4
|
andrewm@0
|
646 SBBO r2, reg_spi_addr, SPI_CH1CTRL, 4
|
andrewm@0
|
647
|
andrewm@0
|
648 // Set to master; chip select lines enabled (CS0 used for DAC)
|
andrewm@0
|
649 MOV r2, 0x00
|
andrewm@0
|
650 SBBO r2, reg_spi_addr, SPI_MODULCTRL, 4
|
andrewm@0
|
651
|
andrewm@0
|
652 // Configure CH0 for DAC
|
andrewm@0
|
653 MOV r2, (3 << 27) | (DAC_DPE << 16) | (DAC_TRM << 12) | ((DAC_WL - 1) << 7) | (DAC_CLK_DIV << 2) | DAC_CLK_MODE | (1 << 6)
|
andrewm@0
|
654 SBBO r2, reg_spi_addr, SPI_CH0CONF, 4
|
andrewm@0
|
655
|
andrewm@0
|
656 // Configure CH1 for ADC
|
andrewm@0
|
657 MOV r2, (3 << 27) | (ADC_DPE << 16) | (ADC_TRM << 12) | ((ADC_WL - 1) << 7) | (ADC_CLK_DIV << 2) | ADC_CLK_MODE
|
andrewm@0
|
658 SBBO r2, reg_spi_addr, SPI_CH1CONF, 4
|
andrewm@0
|
659
|
andrewm@0
|
660 // Turn on SPI channels
|
andrewm@0
|
661 MOV r2, 0x01
|
andrewm@0
|
662 SBBO r2, reg_spi_addr, SPI_CH0CTRL, 4
|
andrewm@0
|
663 SBBO r2, reg_spi_addr, SPI_CH1CTRL, 4
|
andrewm@0
|
664
|
andrewm@0
|
665 // DAC power-on reset sequence
|
andrewm@0
|
666 MOV r2, (0x07 << AD5668_COMMAND_OFFSET)
|
andrewm@0
|
667 DAC_WRITE r2
|
andrewm@0
|
668
|
andrewm@0
|
669 // Initialise ADC
|
andrewm@0
|
670 MOV r2, AD7699_CFG_MASK | (0 << AD7699_CHANNEL_OFFSET) | (0 << AD7699_SEQ_OFFSET)
|
andrewm@0
|
671 ADC_WRITE r2, r2
|
andrewm@0
|
672
|
andrewm@0
|
673 // Enable DAC internal reference
|
andrewm@0
|
674 MOV r2, (0x08 << AD5668_COMMAND_OFFSET) | (0x01 << AD5668_REF_OFFSET)
|
andrewm@0
|
675 DAC_WRITE r2
|
andrewm@0
|
676
|
andrewm@0
|
677 // Read ADC ch0 and ch1: result is always 2 samples behind so start here
|
andrewm@0
|
678 MOV r2, AD7699_CFG_MASK | (0x00 << AD7699_CHANNEL_OFFSET)
|
andrewm@0
|
679 ADC_WRITE r2, r2
|
andrewm@0
|
680
|
andrewm@0
|
681 MOV r2, AD7699_CFG_MASK | (0x01 << AD7699_CHANNEL_OFFSET)
|
andrewm@0
|
682 ADC_WRITE r2, r2
|
andrewm@0
|
683 SPI_INIT_DONE:
|
andrewm@0
|
684
|
andrewm@0
|
685 // Prepare McASP0 for audio
|
andrewm@0
|
686 MCASP_REG_WRITE MCASP_GBLCTL, 0 // Disable McASP
|
andrewm@0
|
687 MCASP_REG_WRITE_EXT MCASP_SRCTL0, 0 // All serialisers off
|
andrewm@0
|
688 MCASP_REG_WRITE_EXT MCASP_SRCTL1, 0
|
andrewm@0
|
689 MCASP_REG_WRITE_EXT MCASP_SRCTL2, 0
|
andrewm@0
|
690 MCASP_REG_WRITE_EXT MCASP_SRCTL3, 0
|
andrewm@0
|
691 MCASP_REG_WRITE_EXT MCASP_SRCTL4, 0
|
andrewm@0
|
692 MCASP_REG_WRITE_EXT MCASP_SRCTL5, 0
|
andrewm@0
|
693
|
andrewm@0
|
694 MCASP_REG_WRITE MCASP_PWRIDLESYSCONFIG, 0x02 // Power on
|
andrewm@0
|
695 MCASP_REG_WRITE MCASP_PFUNC, 0x00 // All pins are McASP
|
andrewm@0
|
696 MCASP_REG_WRITE MCASP_PDIR, MCASP_OUTPUT_PINS // Set pin direction
|
andrewm@0
|
697 MCASP_REG_WRITE MCASP_DLBCTL, 0x00
|
andrewm@0
|
698 MCASP_REG_WRITE MCASP_DITCTL, 0x00
|
andrewm@0
|
699 MCASP_REG_WRITE MCASP_RMASK, MCASP_DATA_MASK // 16 bit data receive
|
andrewm@0
|
700 MCASP_REG_WRITE MCASP_RFMT, MCASP_DATA_FORMAT // Set data format
|
andrewm@0
|
701 MCASP_REG_WRITE MCASP_AFSRCTL, 0x100 // I2S mode
|
andrewm@0
|
702 MCASP_REG_WRITE MCASP_ACLKRCTL, 0x80 // Sample on rising edge
|
andrewm@0
|
703 MCASP_REG_WRITE MCASP_AHCLKRCTL, 0x8001 // Internal clock, not inv, /2; irrelevant?
|
andrewm@0
|
704 MCASP_REG_WRITE MCASP_RTDM, 0x03 // Enable TDM slots 0 and 1
|
andrewm@0
|
705 MCASP_REG_WRITE MCASP_RINTCTL, 0x00 // No interrupts
|
andrewm@0
|
706 MCASP_REG_WRITE MCASP_XMASK, MCASP_DATA_MASK // 16 bit data transmit
|
andrewm@0
|
707 MCASP_REG_WRITE MCASP_XFMT, MCASP_DATA_FORMAT // Set data format
|
andrewm@0
|
708 MCASP_REG_WRITE MCASP_AFSXCTL, 0x100 // I2S mode
|
andrewm@0
|
709 MCASP_REG_WRITE MCASP_ACLKXCTL, 0x00 // Transmit on rising edge, sync. xmit and recv
|
andrewm@0
|
710 MCASP_REG_WRITE MCASP_AHCLKXCTL, 0x8001 // External clock from AHCLKX
|
andrewm@0
|
711 MCASP_REG_WRITE MCASP_XTDM, 0x03 // Enable TDM slots 0 and 1
|
andrewm@0
|
712 MCASP_REG_WRITE MCASP_XINTCTL, 0x00 // No interrupts
|
andrewm@0
|
713
|
andrewm@0
|
714 MCASP_REG_WRITE_EXT MCASP_SRCTL_R, 0x02 // Set up receive serialiser
|
andrewm@0
|
715 MCASP_REG_WRITE_EXT MCASP_SRCTL_X, 0x01 // Set up transmit serialiser
|
andrewm@0
|
716 MCASP_REG_WRITE_EXT MCASP_WFIFOCTL, 0x00 // Disable FIFOs
|
andrewm@0
|
717 MCASP_REG_WRITE_EXT MCASP_RFIFOCTL, 0x00
|
andrewm@0
|
718
|
andrewm@0
|
719 MCASP_REG_WRITE MCASP_XSTAT, 0xFF // Clear transmit errors
|
andrewm@0
|
720 MCASP_REG_WRITE MCASP_RSTAT, 0xFF // Clear receive errors
|
andrewm@0
|
721
|
andrewm@0
|
722 MCASP_REG_SET_BIT_AND_POLL MCASP_RGBLCTL, (1 << 1) // Set RHCLKRST
|
andrewm@0
|
723 MCASP_REG_SET_BIT_AND_POLL MCASP_XGBLCTL, (1 << 9) // Set XHCLKRST
|
andrewm@0
|
724
|
andrewm@0
|
725 // The above write sequence will have temporarily changed the AHCLKX frequency
|
andrewm@0
|
726 // The PLL needs time to settle or the sample rate will be unstable and possibly
|
andrewm@0
|
727 // cause an underrun. Give it ~1ms before going on.
|
andrewm@0
|
728 // 10ns per loop iteration = 10^-8s --> 10^5 iterations needed
|
andrewm@0
|
729
|
andrewm@0
|
730 MOV r2, 1 << 28
|
andrewm@0
|
731 MOV r3, GPIO1 + GPIO_SETDATAOUT
|
andrewm@0
|
732 SBBO r2, r3, 0, 4
|
andrewm@0
|
733
|
andrewm@0
|
734 MOV r2, 100000
|
andrewm@0
|
735 MCASP_INIT_WAIT:
|
andrewm@0
|
736 SUB r2, r2, 1
|
andrewm@0
|
737 QBNE MCASP_INIT_WAIT, r2, 0
|
andrewm@0
|
738
|
andrewm@0
|
739 MOV r2, 1 << 28
|
andrewm@0
|
740 MOV r3, GPIO1 + GPIO_CLEARDATAOUT
|
andrewm@0
|
741 SBBO r2, r3, 0, 4
|
andrewm@0
|
742
|
andrewm@0
|
743 MCASP_REG_SET_BIT_AND_POLL MCASP_RGBLCTL, (1 << 0) // Set RCLKRST
|
andrewm@0
|
744 MCASP_REG_SET_BIT_AND_POLL MCASP_XGBLCTL, (1 << 8) // Set XCLKRST
|
andrewm@0
|
745 MCASP_REG_SET_BIT_AND_POLL MCASP_RGBLCTL, (1 << 2) // Set RSRCLR
|
andrewm@0
|
746 MCASP_REG_SET_BIT_AND_POLL MCASP_XGBLCTL, (1 << 10) // Set XSRCLR
|
andrewm@0
|
747 MCASP_REG_SET_BIT_AND_POLL MCASP_RGBLCTL, (1 << 3) // Set RSMRST
|
andrewm@0
|
748 MCASP_REG_SET_BIT_AND_POLL MCASP_XGBLCTL, (1 << 11) // Set XSMRST
|
andrewm@0
|
749
|
andrewm@0
|
750 MCASP_REG_WRITE_EXT MCASP_XBUF, 0x00 // Write to the transmit buffer to prevent underflow
|
andrewm@0
|
751
|
andrewm@0
|
752 MCASP_REG_SET_BIT_AND_POLL MCASP_RGBLCTL, (1 << 4) // Set RFRST
|
andrewm@0
|
753 MCASP_REG_SET_BIT_AND_POLL MCASP_XGBLCTL, (1 << 12) // Set XFRST
|
andrewm@0
|
754
|
andrewm@0
|
755 // Initialisation
|
andrewm@12
|
756 LBBO reg_frame_total, reg_comm_addr, COMM_BUFFER_FRAMES, 4 // Total frame count (SPI; 0.5x-2x for McASP)
|
andrewm@0
|
757 MOV reg_dac_buf0, 0 // DAC buffer 0 start pointer
|
andrewm@12
|
758 LSL reg_dac_buf1, reg_frame_total, 1 // DAC buffer 1 start pointer = N[ch]*2[bytes]*bufsize
|
andrewm@12
|
759 LMBD r2, reg_num_channels, 1 // Returns 1, 2 or 3 depending on the number of channels
|
andrewm@12
|
760 LSL reg_dac_buf1, reg_dac_buf1, r2 // Multiply by 2, 4 or 8 to get the N[ch] scaling above
|
andrewm@0
|
761 MOV reg_mcasp_buf0, 0 // McASP DAC buffer 0 start pointer
|
andrewm@12
|
762 LSL reg_mcasp_buf1, reg_frame_total, r2 // McASP DAC buffer 1 start pointer = 2[ch]*2[bytes]*(N/4)[samples/spi]*bufsize
|
andrewm@0
|
763 CLR reg_flags, reg_flags, FLAG_BIT_BUFFER1 // Bit 0 holds which buffer we are on
|
andrewm@0
|
764 MOV r2, 0
|
andrewm@0
|
765 SBBO r2, reg_comm_addr, COMM_FRAME_COUNT, 4 // Start with frame count of 0
|
andrewm@0
|
766
|
andrewm@0
|
767 // Here we are out of sync by one TDM slot since the 0 word transmitted above will have occupied
|
andrewm@0
|
768 // the first output slot. Send one more word before jumping into the loop.
|
andrewm@0
|
769 MCASP_DAC_WAIT_BEFORE_LOOP:
|
andrewm@0
|
770 LBBO r2, reg_mcasp_addr, MCASP_XSTAT, 4
|
andrewm@0
|
771 QBBC MCASP_DAC_WAIT_BEFORE_LOOP, r2, MCASP_XSTAT_XDATA_BIT
|
andrewm@0
|
772
|
andrewm@0
|
773 MCASP_REG_WRITE_EXT MCASP_XBUF, 0x00
|
andrewm@0
|
774
|
andrewm@0
|
775 // Likewise, read and discard the first sample we get back from the ADC. This keeps the DAC and ADC
|
andrewm@0
|
776 // in sync in terms of which TDM slot we are reading (empirically found that we should throw this away
|
andrewm@0
|
777 // rather than keep it and invert the phase)
|
andrewm@0
|
778 MCASP_ADC_WAIT_BEFORE_LOOP:
|
andrewm@0
|
779 LBBO r2, reg_mcasp_addr, MCASP_RSTAT, 4
|
andrewm@0
|
780 QBBC MCASP_ADC_WAIT_BEFORE_LOOP, r2, MCASP_RSTAT_RDATA_BIT
|
andrewm@0
|
781
|
andrewm@0
|
782 MCASP_REG_READ_EXT MCASP_RBUF, r2
|
andrewm@0
|
783
|
andrewm@0
|
784 WRITE_ONE_BUFFER:
|
andrewm@0
|
785 // Write a single buffer of DAC samples and read a buffer of ADC samples
|
andrewm@0
|
786 // Load starting positions
|
giuliomoro@16
|
787 SET r30.t15
|
andrewm@0
|
788 MOV reg_dac_current, reg_dac_buf0 // DAC: reg_dac_current is current pointer
|
andrewm@12
|
789 LMBD r2, reg_num_channels, 1 // 1, 2 or 3 for 2, 4 or 8 channels
|
andrewm@12
|
790 LSL reg_adc_current, reg_frame_total, r2
|
andrewm@12
|
791 LSL reg_adc_current, reg_adc_current, 2 // N * 2 * 2 * bufsize
|
andrewm@12
|
792 ADD reg_adc_current, reg_adc_current, reg_dac_current // ADC: starts N * 2 * 2 * bufsize beyond DAC
|
andrewm@0
|
793 MOV reg_mcasp_dac_current, reg_mcasp_buf0 // McASP: set current DAC pointer
|
andrewm@12
|
794 LSL reg_mcasp_adc_current, reg_frame_total, r2 // McASP ADC: starts (N/2)*2*2*bufsize beyond DAC
|
andrewm@12
|
795 LSL reg_mcasp_adc_current, reg_mcasp_adc_current, 1
|
andrewm@0
|
796 ADC reg_mcasp_adc_current, reg_mcasp_adc_current, reg_mcasp_dac_current
|
andrewm@0
|
797 MOV reg_frame_current, 0
|
giuliomoro@16
|
798 QBBS MATRIX_GPIO_BASE_CHECK_SET, reg_flags, FLAG_BIT_BUFFER1 //check which buffer we are using for MATRIX_GPIO
|
giuliomoro@16
|
799 // if we are here, we are using buffer0
|
giuliomoro@16
|
800 MOV r2, 0 //so adjust offset appropriately
|
giuliomoro@16
|
801 QBA MATRIX_GPIO_BASE_CHECK_DONE
|
giuliomoro@16
|
802 MATRIX_GPIO_BASE_CHECK_SET: //if we are here, we are using buffer1
|
giuliomoro@16
|
803 MOV r2, MEM_MATRIX_GPIO_BUFFER1_OFFSET //so adjust offset appropriately
|
giuliomoro@16
|
804 MATRIX_GPIO_BASE_CHECK_DONE:
|
giuliomoro@16
|
805 MOV reg_matrix_gpio_current, MEM_MATRIX_GPIO_BASE
|
giuliomoro@16
|
806 ADD reg_matrix_gpio_current, reg_matrix_gpio_current, r2
|
giuliomoro@16
|
807
|
giuliomoro@16
|
808 CLR r30.t15
|
andrewm@0
|
809 WRITE_LOOP:
|
andrewm@12
|
810 // Write N channels to DAC from successive values in memory
|
andrewm@12
|
811 // At the same time, read N channels from ADC
|
andrewm@0
|
812 // Unrolled by a factor of 2 to get high and low words
|
andrewm@0
|
813 MOV r1, 0
|
andrewm@0
|
814 ADC_DAC_LOOP:
|
andrewm@0
|
815 QBBC SPI_DAC_LOAD_DONE, reg_flags, FLAG_BIT_USE_SPI
|
andrewm@0
|
816 // Load next 2 SPI DAC samples and store zero in their place
|
andrewm@0
|
817 LBCO reg_dac_data, C_ADC_DAC_MEM, reg_dac_current, 4
|
andrewm@0
|
818 MOV r2, 0
|
andrewm@0
|
819 SBCO r2, C_ADC_DAC_MEM, reg_dac_current, 4
|
andrewm@0
|
820 ADD reg_dac_current, reg_dac_current, 4
|
andrewm@0
|
821 SPI_DAC_LOAD_DONE:
|
andrewm@0
|
822
|
andrewm@0
|
823 // On even iterations, load two more samples and choose the first one
|
andrewm@0
|
824 // On odd iterations, transmit the second of the samples already loaded
|
andrewm@12
|
825 // QBBS MCASP_DAC_HIGH_WORD, r1, 1
|
andrewm@12
|
826 QBBS MCASP_DAC_HIGH_WORD, reg_flags, FLAG_BIT_MCASP_HWORD
|
andrewm@0
|
827 MCASP_DAC_LOW_WORD:
|
andrewm@0
|
828 // Load next 2 Audio DAC samples and store zero in their place
|
andrewm@0
|
829 LBCO reg_mcasp_dac_data, C_MCASP_MEM, reg_mcasp_dac_current, 4
|
andrewm@0
|
830 MOV r2, 0
|
andrewm@0
|
831 SBCO r2, C_MCASP_MEM, reg_mcasp_dac_current, 4
|
andrewm@0
|
832 ADD reg_mcasp_dac_current, reg_mcasp_dac_current, 4
|
andrewm@0
|
833
|
andrewm@0
|
834 // Mask out the low word (first in little endian)
|
andrewm@0
|
835 MOV r2, 0xFFFF
|
andrewm@0
|
836 AND r7, reg_mcasp_dac_data, r2
|
andrewm@0
|
837
|
andrewm@0
|
838 QBA MCASP_WAIT_XSTAT
|
andrewm@0
|
839 MCASP_DAC_HIGH_WORD:
|
andrewm@0
|
840 // Take the high word of the previously loaded data
|
andrewm@0
|
841 LSR r7, reg_mcasp_dac_data, 16
|
andrewm@0
|
842
|
andrewm@12
|
843 // Every 2 channels we send one audio sample; this loop already
|
andrewm@0
|
844 // sends exactly two SPI channels.
|
andrewm@0
|
845 // Wait for McASP XSTAT[XDATA] to set indicating we can write more data
|
andrewm@0
|
846 MCASP_WAIT_XSTAT:
|
andrewm@0
|
847 LBBO r2, reg_mcasp_addr, MCASP_XSTAT, 4
|
andrewm@0
|
848 QBBC MCASP_WAIT_XSTAT, r2, MCASP_XSTAT_XDATA_BIT
|
andrewm@0
|
849
|
andrewm@0
|
850 MCASP_REG_WRITE_EXT MCASP_XBUF, r7
|
andrewm@0
|
851
|
andrewm@0
|
852 // Same idea with ADC: even iterations, load the sample into the low word, odd
|
andrewm@0
|
853 // iterations, load the sample into the high word and store
|
andrewm@12
|
854 // QBBS MCASP_ADC_HIGH_WORD, r1, 1
|
andrewm@12
|
855 QBBS MCASP_ADC_HIGH_WORD, reg_flags, FLAG_BIT_MCASP_HWORD
|
andrewm@0
|
856 MCASP_ADC_LOW_WORD:
|
andrewm@0
|
857 // Start ADC data at 0
|
andrewm@0
|
858 LDI reg_mcasp_adc_data, 0
|
andrewm@0
|
859
|
andrewm@0
|
860 // Now wait for a received word to become available from the audio ADC
|
andrewm@0
|
861 MCASP_WAIT_RSTAT_LOW:
|
andrewm@0
|
862 LBBO r2, reg_mcasp_addr, MCASP_RSTAT, 4
|
andrewm@0
|
863 QBBC MCASP_WAIT_RSTAT_LOW, r2, MCASP_RSTAT_RDATA_BIT
|
andrewm@0
|
864
|
andrewm@0
|
865 // Mask low word and store in ADC data register
|
andrewm@0
|
866 MCASP_REG_READ_EXT MCASP_RBUF, r3
|
andrewm@0
|
867 MOV r2, 0xFFFF
|
andrewm@0
|
868 AND reg_mcasp_adc_data, r3, r2
|
andrewm@0
|
869 QBA MCASP_ADC_DONE
|
andrewm@0
|
870
|
andrewm@0
|
871 MCASP_ADC_HIGH_WORD:
|
andrewm@0
|
872 // Wait for a received word to become available from the audio ADC
|
andrewm@0
|
873 MCASP_WAIT_RSTAT_HIGH:
|
andrewm@0
|
874 LBBO r2, reg_mcasp_addr, MCASP_RSTAT, 4
|
andrewm@0
|
875 QBBC MCASP_WAIT_RSTAT_HIGH, r2, MCASP_RSTAT_RDATA_BIT
|
andrewm@0
|
876
|
andrewm@0
|
877 // Read data and shift 16 bits to the left (into the high word)
|
andrewm@0
|
878 MCASP_REG_READ_EXT MCASP_RBUF, r3
|
andrewm@0
|
879 LSL r3, r3, 16
|
andrewm@0
|
880 OR reg_mcasp_adc_data, reg_mcasp_adc_data, r3
|
andrewm@0
|
881
|
andrewm@0
|
882 // Now store the result and increment the pointer
|
andrewm@0
|
883 SBCO reg_mcasp_adc_data, C_MCASP_MEM, reg_mcasp_adc_current, 4
|
andrewm@0
|
884 ADD reg_mcasp_adc_current, reg_mcasp_adc_current, 4
|
andrewm@0
|
885 MCASP_ADC_DONE:
|
andrewm@0
|
886 QBBC SPI_SKIP_WRITE, reg_flags, FLAG_BIT_USE_SPI
|
andrewm@0
|
887
|
andrewm@0
|
888 // DAC: transmit low word (first in little endian)
|
andrewm@0
|
889 MOV r2, 0xFFFF
|
andrewm@0
|
890 AND r7, reg_dac_data, r2
|
andrewm@0
|
891 LSL r7, r7, AD5668_DATA_OFFSET
|
andrewm@0
|
892 MOV r8, (0x03 << AD5668_COMMAND_OFFSET)
|
andrewm@0
|
893 OR r7, r7, r8
|
andrewm@0
|
894 LSL r8, r1, AD5668_ADDRESS_OFFSET
|
andrewm@0
|
895 OR r7, r7, r8
|
andrewm@0
|
896 DAC_WRITE r7
|
andrewm@0
|
897
|
andrewm@0
|
898 // Read ADC channels: result is always 2 commands behind
|
andrewm@0
|
899 // Start by reading channel 2 (result is channel 0) and go
|
andrewm@12
|
900 // to N+2, but masking the channel number to be between 0 and N-1
|
andrewm@0
|
901 LDI reg_adc_data, 0
|
andrewm@12
|
902 ADD r8, r1, 2
|
andrewm@12
|
903 SUB r7, reg_num_channels, 1
|
andrewm@12
|
904 AND r8, r8, r7
|
andrewm@12
|
905 LSL r8, r8, AD7699_CHANNEL_OFFSET
|
andrewm@0
|
906 MOV r7, AD7699_CFG_MASK
|
andrewm@0
|
907 OR r7, r7, r8
|
giuliomoro@16
|
908 //ssssssssssssssssssssssssssss
|
giuliomoro@16
|
909 ADC_WRITE_GPIO r7, r7, r1
|
andrewm@0
|
910
|
andrewm@0
|
911 // Mask out only the relevant 16 bits and store in reg_adc_data
|
andrewm@0
|
912 MOV r2, 0xFFFF
|
andrewm@0
|
913 AND reg_adc_data, r7, r2
|
andrewm@0
|
914
|
andrewm@0
|
915 // Increment channel index
|
andrewm@0
|
916 ADD r1, r1, 1
|
andrewm@0
|
917
|
andrewm@0
|
918 // DAC: transmit high word (second in little endian)
|
andrewm@0
|
919 LSR r7, reg_dac_data, 16
|
andrewm@0
|
920 LSL r7, r7, AD5668_DATA_OFFSET
|
andrewm@0
|
921 MOV r8, (0x03 << AD5668_COMMAND_OFFSET)
|
andrewm@0
|
922 OR r7, r7, r8
|
andrewm@0
|
923 LSL r8, r1, AD5668_ADDRESS_OFFSET
|
andrewm@0
|
924 OR r7, r7, r8
|
andrewm@0
|
925 DAC_WRITE r7
|
andrewm@0
|
926
|
andrewm@0
|
927 // Read ADC channels: result is always 2 commands behind
|
andrewm@0
|
928 // Start by reading channel 2 (result is channel 0) and go
|
andrewm@12
|
929 // to N+2, but masking the channel number to be between 0 and N-1
|
andrewm@12
|
930 ADD r8, r1, 2
|
andrewm@12
|
931 SUB r7, reg_num_channels, 1
|
andrewm@12
|
932 AND r8, r8, r7
|
andrewm@12
|
933 LSL r8, r8, AD7699_CHANNEL_OFFSET
|
andrewm@0
|
934 MOV r7, AD7699_CFG_MASK
|
andrewm@0
|
935 OR r7, r7, r8
|
andrewm@0
|
936 ADC_WRITE r7, r7
|
andrewm@0
|
937
|
andrewm@0
|
938 // Move this result up to the 16 high bits
|
andrewm@0
|
939 LSL r7, r7, 16
|
andrewm@0
|
940 OR reg_adc_data, reg_adc_data, r7
|
andrewm@0
|
941
|
andrewm@0
|
942 // Store 2 ADC words in memory
|
andrewm@0
|
943 SBCO reg_adc_data, C_ADC_DAC_MEM, reg_adc_current, 4
|
andrewm@0
|
944 ADD reg_adc_current, reg_adc_current, 4
|
andrewm@0
|
945
|
andrewm@12
|
946 // Toggle the high/low word for McASP control (since we send one word out of
|
andrewm@12
|
947 // 32 bits for each pair of SPI channels)
|
andrewm@12
|
948 XOR reg_flags, reg_flags, (1 << FLAG_BIT_MCASP_HWORD)
|
andrewm@12
|
949
|
andrewm@12
|
950 // Repeat 4 times for 8 channels (2 samples per loop, r1 += 1 already happened)
|
andrewm@12
|
951 // For 4 or 2 channels, repeat 2 or 1 times, according to flags
|
andrewm@0
|
952 ADD r1, r1, 1
|
andrewm@12
|
953 QBNE ADC_DAC_LOOP, r1, reg_num_channels
|
andrewm@0
|
954 QBA ADC_DAC_LOOP_DONE
|
andrewm@12
|
955
|
andrewm@0
|
956 SPI_SKIP_WRITE:
|
andrewm@0
|
957 // We get here only if the SPI ADC and DAC are disabled
|
andrewm@0
|
958 // Just keep the loop going for McASP
|
andrewm@12
|
959
|
andrewm@12
|
960 // Toggle the high/low word for McASP control (since we send one word out of
|
andrewm@12
|
961 // 32 bits for each pair of SPI channels)
|
andrewm@12
|
962 XOR reg_flags, reg_flags, (1 << FLAG_BIT_MCASP_HWORD)
|
andrewm@12
|
963
|
andrewm@0
|
964 ADD r1, r1, 2
|
andrewm@12
|
965 QBNE ADC_DAC_LOOP, r1, reg_num_channels
|
andrewm@0
|
966
|
andrewm@0
|
967 ADC_DAC_LOOP_DONE:
|
andrewm@0
|
968 // Increment number of frames, see if we have more to write
|
andrewm@0
|
969 ADD reg_frame_current, reg_frame_current, 1
|
andrewm@0
|
970 QBNE WRITE_LOOP, reg_frame_current, reg_frame_total
|
andrewm@0
|
971
|
andrewm@0
|
972 WRITE_LOOP_DONE:
|
andrewm@0
|
973 // Now done, swap the buffers and do the next one
|
andrewm@0
|
974 // Use r2 as a temp register
|
andrewm@0
|
975 MOV r2, reg_dac_buf0
|
andrewm@0
|
976 MOV reg_dac_buf0, reg_dac_buf1
|
andrewm@0
|
977 MOV reg_dac_buf1, r2
|
andrewm@0
|
978 MOV r2, reg_mcasp_buf0
|
andrewm@0
|
979 MOV reg_mcasp_buf0, reg_mcasp_buf1
|
andrewm@0
|
980 MOV reg_mcasp_buf1, r2
|
giuliomoro@16
|
981 XOR reg_flags, reg_flags, (1 << FLAG_BIT_BUFFER1) //flip the buffer flag
|
andrewm@0
|
982
|
andrewm@0
|
983 // Notify ARM of buffer swap
|
andrewm@0
|
984 AND r2, reg_flags, (1 << FLAG_BIT_BUFFER1) // Mask out every but low bit
|
andrewm@0
|
985 SBBO r2, reg_comm_addr, COMM_CURRENT_BUFFER, 4
|
andrewm@0
|
986
|
andrewm@0
|
987 // Increment the frame count in the comm buffer (for status monitoring)
|
andrewm@0
|
988 LBBO r2, reg_comm_addr, COMM_FRAME_COUNT, 4
|
andrewm@0
|
989 ADD r2, r2, reg_frame_total
|
andrewm@0
|
990 SBBO r2, reg_comm_addr, COMM_FRAME_COUNT, 4
|
andrewm@0
|
991
|
andrewm@0
|
992 // If LED blink enabled, toggle every 4096 frames
|
andrewm@0
|
993 LBBO r3, reg_comm_addr, COMM_LED_ADDRESS, 4
|
andrewm@0
|
994 QBEQ LED_BLINK_DONE, r3, 0
|
andrewm@0
|
995 MOV r1, 0x1000
|
andrewm@0
|
996 AND r2, r2, r1 // Test (frame count & 4096)
|
andrewm@0
|
997 QBEQ LED_BLINK_OFF, r2, 0
|
andrewm@0
|
998 LBBO r2, reg_comm_addr, COMM_LED_PIN_MASK, 4
|
andrewm@0
|
999 MOV r1, GPIO_SETDATAOUT
|
andrewm@0
|
1000 ADD r3, r3, r1 // Address for GPIO set register
|
andrewm@0
|
1001 SBBO r2, r3, 0, 4 // Set GPIO pin
|
andrewm@0
|
1002 QBA LED_BLINK_DONE
|
andrewm@0
|
1003 LED_BLINK_OFF:
|
andrewm@0
|
1004 LBBO r2, reg_comm_addr, COMM_LED_PIN_MASK, 4
|
andrewm@0
|
1005 MOV r1, GPIO_CLEARDATAOUT
|
andrewm@0
|
1006 ADD r3, r3, r1 // Address for GPIO clear register
|
andrewm@0
|
1007 SBBO r2, r3, 0, 4 // Clear GPIO pin
|
andrewm@0
|
1008 LED_BLINK_DONE:
|
andrewm@0
|
1009
|
andrewm@0
|
1010 // Check if we should finish: flag is zero as long as it should run
|
andrewm@0
|
1011 LBBO r2, reg_comm_addr, COMM_SHOULD_STOP, 4
|
andrewm@0
|
1012 QBEQ WRITE_ONE_BUFFER, r2, 0
|
andrewm@0
|
1013
|
andrewm@0
|
1014 CLEANUP:
|
andrewm@0
|
1015 MCASP_REG_WRITE MCASP_GBLCTL, 0x00 // Turn off McASP
|
andrewm@0
|
1016
|
andrewm@0
|
1017 // Turn off SPI if enabled
|
andrewm@0
|
1018 QBBC SPI_CLEANUP_DONE, reg_flags, FLAG_BIT_USE_SPI
|
andrewm@0
|
1019
|
andrewm@0
|
1020 MOV r3, SPI_BASE + SPI_CH0CONF
|
andrewm@0
|
1021 LBBO r2, r3, 0, 4
|
andrewm@0
|
1022 CLR r2, r2, 13
|
andrewm@0
|
1023 CLR r2, r2, 27
|
andrewm@0
|
1024 SBBO r2, r3, 0, 4
|
andrewm@0
|
1025
|
andrewm@0
|
1026 MOV r3, SPI_BASE + SPI_CH0CTRL
|
andrewm@0
|
1027 LBBO r2, r3, 0, 4
|
andrewm@0
|
1028 CLR r2, r2, 1
|
andrewm@0
|
1029 SBBO r2, r3, 0, 4
|
andrewm@0
|
1030 SPI_CLEANUP_DONE:
|
andrewm@0
|
1031
|
andrewm@0
|
1032 // Signal the ARM that we have finished
|
andrewm@0
|
1033 MOV R31.b0, PRU0_ARM_INTERRUPT + 16
|
giuliomoro@16
|
1034 HALT
|