Skip to content

Commit 5c461c0

Browse files
committed
Some changes to the comments
1 parent 9ba2c96 commit 5c461c0

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

pio/uart_pio_dma/uart_pio_dma.c

+20-16
Original file line numberDiff line numberDiff line change
@@ -104,49 +104,53 @@ int main()
104104
uart_init(HARD_UART_INST, SERIAL_BAUD);
105105
#endif
106106

107-
// setup pio for rx
108107
#if USE_PIO_FOR_RX
108+
// setup pio for rx
109109
if (!pio_claim_free_sm_and_add_program_for_gpio_range(&uart_rx_mini_program, &pio_hw_rx, &pio_sm_rx, &offset_rx, GPIO_RX, 1, true)) {
110110
panic("failed to allocate pio for rx");
111111
}
112112
uart_rx_mini_program_init(pio_hw_rx, pio_sm_rx, offset_rx, GPIO_RX, SERIAL_BAUD);
113113
#else
114+
// setup the rx gpio for the uart hardware
114115
gpio_set_function(GPIO_RX, GPIO_FUNC_UART);
115116
#endif
116117

117-
// setup pio for tx
118118
#if USE_PIO_FOR_TX
119+
// setup pio for tx
119120
if (!pio_claim_free_sm_and_add_program_for_gpio_range(&uart_tx_program, &pio_hw_tx, &pio_sm_tx, &offset_tx, GPIO_TX, 1, true)) {
120121
panic("failed to allocate pio for tx");
121122
}
122123
uart_tx_program_init(pio_hw_tx, pio_sm_tx, offset_tx, GPIO_TX, SERIAL_BAUD);
123124
#else
125+
// setup the tx gpio for the uart hardware
124126
gpio_set_function(GPIO_TX, GPIO_FUNC_UART);
125127
#endif
126128

127-
// setup pio interrupt
128129
#if USE_PIO_FOR_RX
130+
// check the pio irq is available
129131
if (irq_get_exclusive_handler(pio_get_irq_num(pio_hw_rx, PIO_IRQ_TO_USE))) {
130132
panic("PIO IRQ in use");
131133
}
132134
#if USE_DMA_FOR_RX
135+
// add a shared pio handler
133136
irq_add_shared_handler(pio_get_irq_num(pio_hw_rx, PIO_IRQ_TO_USE), pio_irq_handler, PIO_IRQ_PRIORITY);
134137
pio_set_irqn_source_enabled(pio_hw_rx, PIO_IRQ_TO_USE, pis_sm0_rx_fifo_not_empty + pio_sm_rx, true);
135138
irq_set_enabled(pio_get_irq_num(pio_hw_rx, PIO_IRQ_TO_USE), true);
136139
#endif
137140
#endif
138141

139-
// add dma handler
140142
#if USE_DMA_FOR_RX || USE_DMA_FOR_TX
143+
// check the dma irq is available
141144
if (irq_get_exclusive_handler(dma_get_irq_num(DMA_IRQ_TO_USE))) {
142145
panic("DMA IRQ in use");
143146
}
147+
// add a shared dma handler
144148
irq_add_shared_handler(dma_get_irq_num(DMA_IRQ_TO_USE), dma_irq_handler, DMA_IRQ_PRIORITY);
145149
irq_set_enabled(dma_get_irq_num(DMA_IRQ_TO_USE), true);
146150
#endif
147151

148-
// Setup dma for read
149152
#if USE_DMA_FOR_RX
153+
// Setup dma for read
150154
dma_channel_rx = dma_claim_unused_channel(false);
151155
if (dma_channel_rx < 0) {
152156
panic("No free dma channels");
@@ -159,19 +163,19 @@ int main()
159163
// enable irq for rx
160164
dma_irqn_set_channel_enabled(DMA_IRQ_TO_USE, dma_channel_rx, true);
161165
#if USE_PIO_FOR_RX
162-
// read from pio fifo
166+
// setup dma to read from pio fifo
163167
channel_config_set_dreq(&config_rx, pio_get_dreq(pio_hw_rx, pio_sm_rx, false));
164168
// 8-bit read from the uppermost byte of the FIFO, as data is left-justified so need to add 3. Don't forget the cast!
165169
dma_channel_configure(dma_channel_rx, &config_rx, buffer_rx, (io_rw_8*)&pio_hw_rx->rxf[pio_sm_rx] + 3, read_size, true); // dma started
166170
#else
167-
// read from uart hardware
171+
// setup dma to read from uart hardware
168172
channel_config_set_dreq(&config_rx, uart_get_dreq(HARD_UART_INST, false));
169173
dma_channel_configure(dma_channel_rx, &config_rx, buffer_rx, &uart_get_hw(HARD_UART_INST)->dr, read_size, true); // dma started
170174
#endif
171175
#endif
172176

173-
// setup dma for write
174177
#if USE_DMA_FOR_TX
178+
// setup dma for write
175179
dma_channel_tx = dma_claim_unused_channel(false);
176180
if (dma_channel_tx < 0) {
177181
panic("No free dma channels");
@@ -183,32 +187,32 @@ int main()
183187
// enable irq for tx
184188
dma_irqn_set_channel_enabled(DMA_IRQ_TO_USE, dma_channel_tx, true);
185189
#if USE_PIO_FOR_RX
186-
// write to pio fifo
190+
// setup dma to write to pio fifo
187191
channel_config_set_dreq(&config_tx, pio_get_dreq(pio_hw_tx, pio_sm_tx, true));
188192
dma_channel_configure(dma_channel_tx, &config_tx, &pio_hw_rx->txf[pio_sm_tx], buffer_tx, sizeof(buffer_tx) - 1, true); // dma started
189193
#else
190-
// write to uart hardware
194+
// setup dma to write to uart hardware
191195
channel_config_set_dreq(&config_tx, uart_get_dreq(HARD_UART_INST, true));
192196
dma_channel_configure(dma_channel_tx, &config_tx, &uart_get_hw(HARD_UART_INST)->dr, buffer_tx, sizeof(buffer_tx) - 1, true); // dma started
193197
#endif
194198
#endif
195199

196-
// send data
197200
#if USE_DMA_FOR_TX
198-
dma_channel_wait_for_finish_blocking(dma_channel_tx); // wait for tx
201+
// Just wait for dma tx to finish
202+
dma_channel_wait_for_finish_blocking(dma_channel_tx);
199203
#elif USE_PIO_FOR_TX
200204
// write to the pio fifo
201205
int count_pio_tx = 0;
202206
while(count_pio_tx < sizeof(buffer_tx) - 1) {
203207
uart_tx_program_putc(pio_hw_tx, pio_sm_tx, buffer_tx[count_pio_tx++]);
204208
}
205209
#else
210+
// write to the uart
206211
uart_puts(HARD_UART_INST, buffer_tx);
207212
#endif
208213

209-
// Receive the data
210214
#if USE_DMA_FOR_RX
211-
// wait for dma rx
215+
// Just wait for dma rx to finish
212216
dma_channel_wait_for_finish_blocking(dma_channel_rx);
213217
#elif USE_PIO_FOR_RX
214218
// read from the pio fifo
@@ -217,14 +221,14 @@ int main()
217221
buffer_rx[count_pio_rx++] = uart_rx_program_getc(pio_hw_rx, pio_sm_rx);
218222
}
219223
#else
220-
// use the uart hardware
224+
// read from the uart
221225
int count_uart_rx = 0;
222226
while(count_uart_rx < sizeof(buffer_tx) - 1) {
223227
buffer_rx[count_uart_rx++] = uart_getc(HARD_UART_INST);
224228
}
225229
#endif
226230

227-
// check
231+
// check the buffer we received
228232
if (memcmp(buffer_rx, buffer_tx, sizeof(buffer_tx) - 1) == 0) {
229233
printf("Test passed\n");
230234
} else {

0 commit comments

Comments
 (0)