1 | #include <stdio.h> |
---|
2 | |
---|
3 | #include <rtems/irq.h> |
---|
4 | |
---|
5 | #include <mpc55xx/regs.h> |
---|
6 | #include <mpc55xx/mpc55xx.h> |
---|
7 | #include <mpc55xx/dspi.h> |
---|
8 | #include <mpc55xx/edma.h> |
---|
9 | |
---|
10 | #include <libchip/spi-sd-card.h> |
---|
11 | |
---|
12 | #include <bsp.h> |
---|
13 | #include <bsp/irq.h> |
---|
14 | |
---|
15 | #include <rtems/irq-extension.h> |
---|
16 | |
---|
17 | #include <libcpu/powerpc-utility.h> |
---|
18 | |
---|
19 | // #define DEBUG |
---|
20 | |
---|
21 | #include <rtems/status-checks.h> |
---|
22 | |
---|
23 | static rtems_driver_address_table test_mpc55xx_drv_ops = { |
---|
24 | initialization_entry : NULL, |
---|
25 | open_entry : NULL, |
---|
26 | close_entry : NULL, |
---|
27 | read_entry : NULL, |
---|
28 | write_entry : NULL, |
---|
29 | control_entry : NULL |
---|
30 | }; |
---|
31 | |
---|
32 | static rtems_libi2c_drv_t test_mpc55xx_dspi_drv = { |
---|
33 | ops : &test_mpc55xx_drv_ops, |
---|
34 | size : sizeof( rtems_libi2c_drv_t) |
---|
35 | }; |
---|
36 | |
---|
37 | #define MPC55XX_TEST_DSPI_ADDRESS 0 |
---|
38 | |
---|
39 | // #define MPC55XX_TEST_DSPI_BUFSIZE (16 * 32) |
---|
40 | #define MPC55XX_TEST_DSPI_BUFSIZE 8 |
---|
41 | |
---|
42 | // #define MPC55XX_TEST_DSPI_BUFSIZE_CACHE_PROOF MPC55XX_TEST_DSPI_BUFSIZE |
---|
43 | #define MPC55XX_TEST_DSPI_BUFSIZE_CACHE_PROOF 32 |
---|
44 | |
---|
45 | rtems_device_minor_number test_mpc55xx_dspi_bus [MPC55XX_DSPI_NUMBER]; |
---|
46 | |
---|
47 | static rtems_libi2c_tfr_mode_t test_mpc55xx_dspi_transfer_mode = { baudrate : 550000, bits_per_char : 8, lsb_first : FALSE, clock_inv : FALSE, clock_phs : FALSE }; |
---|
48 | |
---|
49 | static rtems_id test_mpc55xx_dspi_ping; |
---|
50 | |
---|
51 | static rtems_id test_mpc55xx_dspi_pong; |
---|
52 | |
---|
53 | static unsigned char test_mpc55xx_dspi_writer_outbuf [2] [MPC55XX_TEST_DSPI_BUFSIZE_CACHE_PROOF] __attribute__ ((aligned (32))); |
---|
54 | |
---|
55 | static unsigned char test_mpc55xx_dspi_writer_inbuf [MPC55XX_TEST_DSPI_BUFSIZE_CACHE_PROOF] __attribute__ ((aligned (32))); |
---|
56 | |
---|
57 | static unsigned char test_mpc55xx_dspi_reader_inbuf [MPC55XX_TEST_DSPI_BUFSIZE_CACHE_PROOF] __attribute__ ((aligned (32))); |
---|
58 | |
---|
59 | static rtems_task test_mpc55xx_dspi_writer( rtems_task_argument arg) |
---|
60 | { |
---|
61 | rtems_status_code sc = RTEMS_SUCCESSFUL; |
---|
62 | int rv = 0; |
---|
63 | rtems_device_minor_number device; |
---|
64 | rtems_libi2c_read_write_t read_and_write = { rd_buf : NULL, wr_buf : NULL, byte_cnt : 0 }; |
---|
65 | int i = 0; |
---|
66 | |
---|
67 | DEBUG_PRINT( "Task started\n"); |
---|
68 | |
---|
69 | device = rtems_libi2c_register_drv( NULL, &test_mpc55xx_dspi_drv, test_mpc55xx_dspi_bus [2], 0); |
---|
70 | CHECK_RV_TASK( device, "rtems_libi2c_register_drv"); |
---|
71 | |
---|
72 | sc = rtems_libi2c_send_start( device); |
---|
73 | CHECK_SC_TASK( sc, "rtems_libi2c_send_start"); |
---|
74 | |
---|
75 | rv = rtems_libi2c_ioctl( device, RTEMS_LIBI2C_IOCTL_SET_TFRMODE, &test_mpc55xx_dspi_transfer_mode); |
---|
76 | CHECK_RV_TASK( rv, "rtems_libi2c_ioctl"); |
---|
77 | |
---|
78 | sc = rtems_libi2c_send_addr( device, MPC55XX_TEST_DSPI_ADDRESS); |
---|
79 | CHECK_SC_TASK( sc, "rtems_libi2c_send_addr"); |
---|
80 | |
---|
81 | for (i = 0; i < MPC55XX_TEST_DSPI_BUFSIZE; ++i) { |
---|
82 | test_mpc55xx_dspi_writer_outbuf [0] [i] = 0xa5; |
---|
83 | test_mpc55xx_dspi_writer_outbuf [1] [i] = 0xa5; |
---|
84 | // test_mpc55xx_dspi_writer_outbuf [0] [i] = i + 1; |
---|
85 | // test_mpc55xx_dspi_writer_outbuf [1] [i] = -(i + 1); |
---|
86 | } |
---|
87 | |
---|
88 | int toggle = 0; |
---|
89 | read_and_write.byte_cnt = MPC55XX_TEST_DSPI_BUFSIZE; |
---|
90 | read_and_write.rd_buf = test_mpc55xx_dspi_writer_inbuf; |
---|
91 | read_and_write.wr_buf = test_mpc55xx_dspi_writer_outbuf [toggle]; |
---|
92 | while (1) { |
---|
93 | tic(); |
---|
94 | |
---|
95 | // sc = rtems_semaphore_obtain( test_mpc55xx_dspi_pong, RTEMS_WAIT, RTEMS_NO_TIMEOUT); |
---|
96 | // CHECK_SC_TASK( sc, "rtems_semaphore_obtain"); |
---|
97 | |
---|
98 | DEBUG_PRINT( "Ping\n"); |
---|
99 | |
---|
100 | // sc = rtems_libi2c_send_start( device); |
---|
101 | // CHECK_SC_TASK( sc, "rtems_libi2c_send_start"); |
---|
102 | |
---|
103 | // sc = rtems_libi2c_send_addr( device, MPC55XX_TEST_DSPI_ADDRESS); |
---|
104 | // CHECK_SC_TASK( sc, "rtems_libi2c_send_addr"); |
---|
105 | |
---|
106 | rv = rtems_libi2c_ioctl( device, RTEMS_LIBI2C_IOCTL_READ_WRITE, &read_and_write); |
---|
107 | CHECK_RV_TASK( rv, "rtems_libi2c_ioctl: RTEMS_LIBI2C_IOCTL_READ_WRITE"); |
---|
108 | |
---|
109 | // rv = rtems_libi2c_write_bytes( device, test_mpc55xx_dspi_writer_outbuf [0], MPC55XX_TEST_DSPI_BUFSIZE); |
---|
110 | // CHECK_RV_TASK( rv, "rtems_libi2c_write_bytes"); |
---|
111 | |
---|
112 | // sc = rtems_libi2c_send_stop( device); |
---|
113 | // CHECK_SC_TASK( sc, "rtems_libi2c_send_stop"); |
---|
114 | |
---|
115 | toggle = toggle ? 0 : 1; |
---|
116 | read_and_write.wr_buf = test_mpc55xx_dspi_writer_outbuf [toggle]; |
---|
117 | |
---|
118 | // sc = rtems_semaphore_release( test_mpc55xx_dspi_ping); |
---|
119 | // CHECK_SC_TASK( sc, "rtems_semaphore_release"); |
---|
120 | } |
---|
121 | |
---|
122 | sc = rtems_libi2c_send_stop( device); |
---|
123 | CHECK_SC_TASK( sc, "rtems_libi2c_send_stop"); |
---|
124 | |
---|
125 | sc = rtems_task_delete( RTEMS_SELF); |
---|
126 | CHECK_SC_TASK( sc, "rtems_task_delete"); |
---|
127 | } |
---|
128 | |
---|
129 | static rtems_task test_mpc55xx_dspi_reader( rtems_task_argument arg) |
---|
130 | { |
---|
131 | rtems_status_code sc = RTEMS_SUCCESSFUL; |
---|
132 | int rv = 0; |
---|
133 | rtems_device_minor_number device; |
---|
134 | int i = 0; |
---|
135 | |
---|
136 | DEBUG_PRINT( "Task started\n"); |
---|
137 | |
---|
138 | device = rtems_libi2c_register_drv( NULL, &test_mpc55xx_dspi_drv, test_mpc55xx_dspi_bus [3], 0); |
---|
139 | CHECK_RV_TASK( device, "rtems_libi2c_register_drv"); |
---|
140 | |
---|
141 | sc = rtems_libi2c_send_start( device); |
---|
142 | CHECK_SC_TASK( sc, "rtems_libi2c_send_start"); |
---|
143 | |
---|
144 | rv = rtems_libi2c_ioctl( device, RTEMS_LIBI2C_IOCTL_SET_TFRMODE, &test_mpc55xx_dspi_transfer_mode); |
---|
145 | CHECK_RV_TASK( rv, "rtems_libi2c_ioctl"); |
---|
146 | |
---|
147 | sc = rtems_libi2c_send_addr( device, MPC55XX_TEST_DSPI_ADDRESS); |
---|
148 | CHECK_SC_TASK( sc, "rtems_libi2c_send_addr"); |
---|
149 | |
---|
150 | for (i = 0; i < MPC55XX_TEST_DSPI_BUFSIZE; ++i) { |
---|
151 | test_mpc55xx_dspi_reader_inbuf [i] = -1; |
---|
152 | } |
---|
153 | |
---|
154 | sc = rtems_semaphore_obtain( test_mpc55xx_dspi_ping, RTEMS_WAIT, RTEMS_NO_TIMEOUT); |
---|
155 | CHECK_SC_TASK( sc, "rtems_semaphore_obtain"); |
---|
156 | |
---|
157 | DEBUG_PRINT( "Pong\n"); |
---|
158 | |
---|
159 | sc = rtems_semaphore_release( test_mpc55xx_dspi_pong); |
---|
160 | CHECK_SC_TASK( sc, "rtems_semaphore_release"); |
---|
161 | |
---|
162 | while (1) { |
---|
163 | sc = rtems_semaphore_obtain( test_mpc55xx_dspi_ping, RTEMS_WAIT, RTEMS_NO_TIMEOUT); |
---|
164 | CHECK_SC_TASK( sc, "rtems_semaphore_obtain"); |
---|
165 | |
---|
166 | DEBUG_PRINT( "Pong\n"); |
---|
167 | |
---|
168 | rv = rtems_libi2c_read_bytes( device, test_mpc55xx_dspi_reader_inbuf, MPC55XX_TEST_DSPI_BUFSIZE); |
---|
169 | CHECK_RV_TASK( rv, "rtems_libi2c_read_bytes"); |
---|
170 | |
---|
171 | sc = rtems_semaphore_release( test_mpc55xx_dspi_pong); |
---|
172 | CHECK_SC_TASK( sc, "rtems_semaphore_release"); |
---|
173 | |
---|
174 | printk( "Time: %i, Value: 0x%02x%02x%02x%02x\n", tac(), |
---|
175 | test_mpc55xx_dspi_reader_inbuf [0], test_mpc55xx_dspi_reader_inbuf [1], |
---|
176 | test_mpc55xx_dspi_reader_inbuf [2], test_mpc55xx_dspi_reader_inbuf [3]); |
---|
177 | } |
---|
178 | |
---|
179 | sc = rtems_libi2c_send_stop( device); |
---|
180 | CHECK_SC_TASK( sc, "rtems_libi2c_send_stop"); |
---|
181 | |
---|
182 | sc = rtems_task_delete( RTEMS_SELF); |
---|
183 | CHECK_SC_TASK( sc, "rtems_task_delete"); |
---|
184 | } |
---|
185 | |
---|
186 | rtems_task test_sd_card( rtems_task_argument arg); |
---|
187 | |
---|
188 | static rtems_task test_mpc55xx_intc( rtems_task_argument arg); |
---|
189 | |
---|
190 | rtems_status_code mpc55xx_dspi_register() |
---|
191 | { |
---|
192 | rtems_status_code sc = RTEMS_SUCCESSFUL; |
---|
193 | int rv = 0; |
---|
194 | int i = 0; |
---|
195 | char device_name [] = "/dev/spi0"; |
---|
196 | union SIU_PCR_tag pcr = MPC55XX_ZERO_FLAGS; |
---|
197 | |
---|
198 | printk( "Boot time: %u\n", ppc_time_base()); |
---|
199 | test_mpc55xx_intc( 0); |
---|
200 | |
---|
201 | rv = rtems_libi2c_initialize(); |
---|
202 | CHECK_RVSC( rv, "rtems_libi2c_initialize"); |
---|
203 | |
---|
204 | /* DSPI D inputs are taken from DSPI C */ |
---|
205 | SIU.DISR.R = 0x000000FC; |
---|
206 | |
---|
207 | /* DSPI A signals */ |
---|
208 | pcr.B.PA = 1; |
---|
209 | pcr.B.ODE = 0; |
---|
210 | pcr.B.HYS = 0; |
---|
211 | pcr.B.SRC = 3; |
---|
212 | pcr.B.WPE = 1; |
---|
213 | pcr.B.WPS = 1; |
---|
214 | |
---|
215 | /* SCK */ |
---|
216 | pcr.B.OBE = 1; |
---|
217 | pcr.B.IBE = 0; |
---|
218 | SIU.PCR [93].R = pcr.R; |
---|
219 | |
---|
220 | /* SIN */ |
---|
221 | pcr.B.OBE = 0; |
---|
222 | pcr.B.IBE = 1; |
---|
223 | SIU.PCR [94].R = pcr.R; |
---|
224 | |
---|
225 | /* SOUT */ |
---|
226 | pcr.B.OBE = 1; |
---|
227 | pcr.B.IBE = 0; |
---|
228 | SIU.PCR [95].R = pcr.R; |
---|
229 | |
---|
230 | /* PCSx */ |
---|
231 | pcr.B.OBE = 1; |
---|
232 | pcr.B.IBE = 0; |
---|
233 | SIU.PCR [96].R = pcr.R; |
---|
234 | SIU.PCR [97].R = pcr.R; |
---|
235 | SIU.PCR [98].R = pcr.R; |
---|
236 | SIU.PCR [99].R = pcr.R; |
---|
237 | SIU.PCR [100].R = pcr.R; |
---|
238 | SIU.PCR [101].R = pcr.R; |
---|
239 | |
---|
240 | mpc55xx_dspi_bus_table [3].master = 0; |
---|
241 | for (i = 0; i < MPC55XX_DSPI_NUMBER; ++i) { |
---|
242 | device_name [8] = '0' + i; |
---|
243 | rv = rtems_libi2c_register_bus( device_name, (rtems_libi2c_bus_t *) &mpc55xx_dspi_bus_table [i]); |
---|
244 | CHECK_RVSC( rv, device_name); |
---|
245 | test_mpc55xx_dspi_bus [i] = rv; |
---|
246 | } |
---|
247 | |
---|
248 | sc = rtems_semaphore_create ( |
---|
249 | rtems_build_name ( 'P', 'I', 'N', 'G'), |
---|
250 | 1, |
---|
251 | RTEMS_SIMPLE_BINARY_SEMAPHORE | RTEMS_INHERIT_PRIORITY | RTEMS_PRIORITY, |
---|
252 | RTEMS_NO_PRIORITY, |
---|
253 | &test_mpc55xx_dspi_ping |
---|
254 | ); |
---|
255 | CHECK_SC( sc, "rtems_semaphore_create"); |
---|
256 | |
---|
257 | sc = rtems_semaphore_create ( |
---|
258 | rtems_build_name ( 'P', 'O', 'N', 'G'), |
---|
259 | 0, |
---|
260 | RTEMS_SIMPLE_BINARY_SEMAPHORE | RTEMS_INHERIT_PRIORITY | RTEMS_PRIORITY, |
---|
261 | RTEMS_NO_PRIORITY, |
---|
262 | &test_mpc55xx_dspi_pong |
---|
263 | ); |
---|
264 | CHECK_SC( sc, "rtems_semaphore_create"); |
---|
265 | |
---|
266 | // rtems_id writer_task_id; |
---|
267 | // rtems_id reader_task_id; |
---|
268 | // |
---|
269 | // sc = rtems_task_create( |
---|
270 | // rtems_build_name( 'T', 'W', 'R', 'T'), |
---|
271 | // 2, |
---|
272 | // RTEMS_MINIMUM_STACK_SIZE, |
---|
273 | // RTEMS_DEFAULT_MODES, |
---|
274 | // RTEMS_DEFAULT_ATTRIBUTES, |
---|
275 | // &writer_task_id |
---|
276 | // ); |
---|
277 | // CHECK_SC( sc, "rtems_task_create"); |
---|
278 | // sc = rtems_task_create( |
---|
279 | // rtems_build_name( 'T', 'R', 'D', 'R'), |
---|
280 | // 1, |
---|
281 | // RTEMS_MINIMUM_STACK_SIZE, |
---|
282 | // RTEMS_DEFAULT_MODES, |
---|
283 | // RTEMS_DEFAULT_ATTRIBUTES, |
---|
284 | // &reader_task_id |
---|
285 | // ); |
---|
286 | // CHECK_SC( sc, "rtems_task_create"); |
---|
287 | // |
---|
288 | // sc = rtems_task_start( writer_task_id, test_mpc55xx_dspi_writer, 0); |
---|
289 | // CHECK_SC( sc, "rtems_task_start"); |
---|
290 | // sc = rtems_task_start( reader_task_id, test_mpc55xx_dspi_reader, 0); |
---|
291 | // CHECK_SC( sc, "rtems_task_start"); |
---|
292 | |
---|
293 | rtems_id sd_card_task_id; |
---|
294 | sc = rtems_task_create( |
---|
295 | rtems_build_name( 'T', 'S', 'D', 'C'), |
---|
296 | 1, |
---|
297 | RTEMS_MINIMUM_STACK_SIZE, |
---|
298 | RTEMS_DEFAULT_MODES, |
---|
299 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
300 | &sd_card_task_id |
---|
301 | ); |
---|
302 | CHECK_SC( sc, "rtems_task_create"); |
---|
303 | sc = rtems_task_start( sd_card_task_id, test_sd_card, 0); |
---|
304 | CHECK_SC( sc, "rtems_task_start"); |
---|
305 | |
---|
306 | rtems_id intc_id; |
---|
307 | sc = rtems_task_create( |
---|
308 | rtems_build_name( 'I', 'N', 'T', 'C'), |
---|
309 | 2, |
---|
310 | RTEMS_MINIMUM_STACK_SIZE, |
---|
311 | RTEMS_DEFAULT_MODES, |
---|
312 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
313 | &intc_id |
---|
314 | ); |
---|
315 | CHECK_SC( sc, "rtems_task_create"); |
---|
316 | sc = rtems_task_start( intc_id, test_mpc55xx_intc, 0); |
---|
317 | CHECK_SC( sc, "rtems_task_start"); |
---|
318 | |
---|
319 | sc = rtems_task_delete( RTEMS_SELF); |
---|
320 | CHECK_SC( sc, "rtems_task_delete"); |
---|
321 | |
---|
322 | return RTEMS_SUCCESSFUL; |
---|
323 | } |
---|
324 | |
---|
325 | #include <sys/types.h> |
---|
326 | #include <sys/stat.h> |
---|
327 | #include <unistd.h> |
---|
328 | #include <fcntl.h> |
---|
329 | #include <dirent.h> |
---|
330 | #include <stdio.h> |
---|
331 | #include <rtems/fsmount.h> |
---|
332 | #include <rtems/dosfs.h> |
---|
333 | #include <rtems/ide_part_table.h> |
---|
334 | |
---|
335 | #define TEST_SD_CARD_BUF_SIZE 512 |
---|
336 | #define TEST_SD_CARD_BIGBUF_SIZE (256 * 1024) |
---|
337 | |
---|
338 | #define TEST_SD_CARD_DEVICE_FILE "/dev/sd-card-a" |
---|
339 | #define TEST_SD_CARD_PARTITION "/dev/sd-card-a1" |
---|
340 | #define TEST_SD_CARD_MOUNT_POINT "/mnt" |
---|
341 | #define TEST_SD_CARD_DIRECTORY "/mnt/testdir" |
---|
342 | |
---|
343 | static fstab_t test_sd_card_fs_table [] = { { |
---|
344 | TEST_SD_CARD_PARTITION, TEST_SD_CARD_MOUNT_POINT, |
---|
345 | &msdos_ops, RTEMS_FILESYSTEM_READ_WRITE, |
---|
346 | FSMOUNT_MNT_OK | FSMOUNT_MNTPNT_CRTERR | FSMOUNT_MNT_FAILED, |
---|
347 | FSMOUNT_MNT_OK |
---|
348 | }, { |
---|
349 | TEST_SD_CARD_DEVICE_FILE, TEST_SD_CARD_MOUNT_POINT, |
---|
350 | &msdos_ops, RTEMS_FILESYSTEM_READ_WRITE, |
---|
351 | FSMOUNT_MNT_OK | FSMOUNT_MNTPNT_CRTERR | FSMOUNT_MNT_FAILED, |
---|
352 | 0 |
---|
353 | } |
---|
354 | }; |
---|
355 | |
---|
356 | static uint8_t test_sd_card_buf [TEST_SD_CARD_BUF_SIZE] __attribute__ ((aligned (32))); |
---|
357 | |
---|
358 | static int test_sd_card_print_dir( const char* dirname, unsigned level) |
---|
359 | { |
---|
360 | int rv = 0; |
---|
361 | DIR *dir = NULL; |
---|
362 | struct dirent *ent; |
---|
363 | struct stat s; |
---|
364 | int i = 0; |
---|
365 | |
---|
366 | /* Open */ |
---|
367 | dir = opendir( dirname); |
---|
368 | rv = dir == NULL ? -1 : 0; |
---|
369 | CHECK_RV( rv, "Open directory"); |
---|
370 | |
---|
371 | /* Change CWD */ |
---|
372 | rv = chdir( dirname); |
---|
373 | CHECK_RV( rv, "Change directory"); |
---|
374 | |
---|
375 | /* Read */ |
---|
376 | ent = readdir( dir); |
---|
377 | while (ent != NULL) { |
---|
378 | if (stat( ent->d_name, &s) == 0 && strcmp( ".", ent->d_name) != 0 && strcmp( "..", ent->d_name)) { |
---|
379 | for (i = 0; i < level; ++i) { |
---|
380 | printk( "\t"); |
---|
381 | } |
---|
382 | printk( "<%s>\n", ent->d_name); |
---|
383 | if (S_ISDIR( s.st_mode)) { |
---|
384 | rv = test_sd_card_print_dir( ent->d_name, level + 1); |
---|
385 | CHECK_RV( rv, "Next directory"); |
---|
386 | } |
---|
387 | } |
---|
388 | ent = readdir( dir); |
---|
389 | } |
---|
390 | |
---|
391 | /* Change CWD */ |
---|
392 | rv = chdir( ".."); |
---|
393 | CHECK_RV( rv, "Change directory"); |
---|
394 | |
---|
395 | /* Close */ |
---|
396 | rv = closedir( dir); |
---|
397 | CHECK_RV( rv, "Close directory"); |
---|
398 | |
---|
399 | return 0; |
---|
400 | } |
---|
401 | |
---|
402 | #define SD_CARD_NUMBER 1 |
---|
403 | |
---|
404 | static sd_card_driver_entry sd_card_driver_table_XXX [SD_CARD_NUMBER] = { { |
---|
405 | driver : { |
---|
406 | ops : &sd_card_driver_ops, |
---|
407 | size : sizeof( sd_card_driver_entry) |
---|
408 | }, |
---|
409 | table_index : 0, |
---|
410 | minor : 0, |
---|
411 | device_name : "sd-card-a", |
---|
412 | disk_device_name : "/dev/sd-card-a", |
---|
413 | transfer_mode : SD_CARD_TRANSFER_MODE_DEFAULT, |
---|
414 | command : SD_CARD_COMMAND_DEFAULT, |
---|
415 | /* response : whatever, */ |
---|
416 | response_index : SD_CARD_COMMAND_SIZE, |
---|
417 | n_ac_max : SD_CARD_N_AC_MAX_DEFAULT, |
---|
418 | block_number : 0, |
---|
419 | block_size : 0, |
---|
420 | block_size_shift : 0, |
---|
421 | busy : 1, |
---|
422 | verbose : 1, |
---|
423 | schedule_if_busy : 0, |
---|
424 | } |
---|
425 | }; |
---|
426 | |
---|
427 | rtems_task test_sd_card( rtems_task_argument arg) |
---|
428 | { |
---|
429 | rtems_status_code sc = RTEMS_SUCCESSFUL; |
---|
430 | int rv = 0; |
---|
431 | rtems_device_minor_number minor; |
---|
432 | sd_card_driver_entry *e = &sd_card_driver_table [0]; |
---|
433 | int fd = 0; |
---|
434 | unsigned i = 0; |
---|
435 | unsigned avg = 0; |
---|
436 | unsigned t = 0; |
---|
437 | char file_name [] = "00000000.TXT"; |
---|
438 | uint8_t *buf = NULL; |
---|
439 | |
---|
440 | DEBUG_PRINT( "Task started\n"); |
---|
441 | |
---|
442 | minor = rtems_libi2c_register_drv( e->device_name, (rtems_libi2c_drv_t *) e, test_mpc55xx_dspi_bus [0], 0); |
---|
443 | CHECK_RV_TASK( (int) minor, "rtems_libi2c_register_drv"); |
---|
444 | |
---|
445 | buf = malloc( TEST_SD_CARD_BIGBUF_SIZE); |
---|
446 | for (i = 0; i < TEST_SD_CARD_BIGBUF_SIZE; ++i) { |
---|
447 | if (i % 27 == 26) { |
---|
448 | buf [i] = '\n'; |
---|
449 | } else { |
---|
450 | buf [i] = 'A' + i % 27; |
---|
451 | } |
---|
452 | } |
---|
453 | buf [i - 1] = '\n'; |
---|
454 | |
---|
455 | rv = test_sd_card_print_dir( "/dev", 0); |
---|
456 | CHECK_RV_TASK( rv, "Print directory"); |
---|
457 | |
---|
458 | sc = rtems_ide_part_table_initialize( TEST_SD_CARD_DEVICE_FILE); |
---|
459 | CHECK_SC_TASK( sc, "Initialize IDE partition table"); |
---|
460 | |
---|
461 | rv = test_sd_card_print_dir( "/dev", 0); |
---|
462 | CHECK_RV_TASK( rv, "Print directory"); |
---|
463 | |
---|
464 | rv = mkdir( TEST_SD_CARD_MOUNT_POINT, S_IRWXU); |
---|
465 | CHECK_RV_TASK( rv, "Create mount point"); |
---|
466 | |
---|
467 | rv = rtems_fsmount( test_sd_card_fs_table, sizeof( test_sd_card_fs_table) / sizeof( test_sd_card_fs_table [0]), NULL); |
---|
468 | CHECK_RV_TASK( rv, "Mount file systems"); |
---|
469 | |
---|
470 | //rv = test_sd_card_print_dir( TEST_SD_CARD_MOUNT_POINT, 0); |
---|
471 | //CHECK_RV_TASK( rv, "Print directory"); |
---|
472 | |
---|
473 | rv = mkdir( TEST_SD_CARD_DIRECTORY, S_IRWXU); |
---|
474 | |
---|
475 | rv = chdir( TEST_SD_CARD_DIRECTORY); |
---|
476 | CHECK_RV_TASK( rv, "Change directory"); |
---|
477 | |
---|
478 | i = 0; |
---|
479 | while (1) { |
---|
480 | snprintf( file_name, 13, "%08i.TXT", i); |
---|
481 | tic(); |
---|
482 | fd = creat( file_name, S_IREAD | S_IWRITE); |
---|
483 | CHECK_RV_TASK( fd, "Create file"); |
---|
484 | rv = write( fd, buf, TEST_SD_CARD_BIGBUF_SIZE); |
---|
485 | CHECK_RV_TASK( rv, "Write file"); |
---|
486 | rv = close( fd); |
---|
487 | CHECK_RV_TASK( rv, "Close file"); |
---|
488 | t = tac(); |
---|
489 | avg = ((uint64_t) avg * ((uint64_t) i) + (uint64_t) t) / ((uint64_t) i + 1); |
---|
490 | printk( "%s: %u (%u)\n", file_name, tac(), avg); |
---|
491 | ++i; |
---|
492 | } |
---|
493 | |
---|
494 | rv = chdir( ".."); |
---|
495 | CHECK_RV_TASK( rv, "Change directory"); |
---|
496 | |
---|
497 | rv = test_sd_card_print_dir( TEST_SD_CARD_DIRECTORY, 0); |
---|
498 | CHECK_RV_TASK( rv, "Print directory"); |
---|
499 | |
---|
500 | |
---|
501 | // /* Write */ |
---|
502 | // int b = 0; |
---|
503 | // const char device_name [] = "/dev/spi0.sd-card-0"; |
---|
504 | // fd = open( device_name, O_RDWR); |
---|
505 | // |
---|
506 | // CHECK_RV_TASK( fd, "open"); |
---|
507 | // while (1) { |
---|
508 | // for (i = 0; i < TEST_SD_CARD_BUF_SIZE; ++i) { |
---|
509 | // test_sd_card_buf [i] = b; |
---|
510 | // } |
---|
511 | // ++b; |
---|
512 | // rv = write( fd, test_sd_card_buf, TEST_SD_CARD_BUF_SIZE); |
---|
513 | // if (rv < 0) { |
---|
514 | // break; |
---|
515 | // } |
---|
516 | // } |
---|
517 | // rv = close( fd); |
---|
518 | // CHECK_RV_TASK( rv, "close"); |
---|
519 | // |
---|
520 | // /* Read */ |
---|
521 | // fd = open( device_name, O_RDWR); |
---|
522 | // CHECK_RV_TASK( fd, "open"); |
---|
523 | // while (1) { |
---|
524 | // rv = read( fd, test_sd_card_buf, TEST_SD_CARD_BUF_SIZE); |
---|
525 | // if (rv < 0) { |
---|
526 | // break; |
---|
527 | // } |
---|
528 | // printk( "%02x", test_sd_card_buf [rv - 1]); |
---|
529 | // if (i++ % 64 == 0) { |
---|
530 | // printk( "\n"); |
---|
531 | // } |
---|
532 | // } |
---|
533 | // rv = close( fd); |
---|
534 | // CHECK_RV_TASK( rv, "close"); |
---|
535 | |
---|
536 | sc = rtems_task_delete( RTEMS_SELF); |
---|
537 | CHECK_SC_TASK( sc, "rtems_task_delete"); |
---|
538 | } |
---|
539 | |
---|
540 | #define ITER 4 |
---|
541 | #define BUFSIZE (128 * ITER) |
---|
542 | |
---|
543 | static char inbuf [BUFSIZE]; |
---|
544 | static char outbuf [BUFSIZE]; |
---|
545 | |
---|
546 | static rtems_status_code test_mpc55xx_edma() |
---|
547 | { |
---|
548 | rtems_status_code sc = RTEMS_SUCCESSFUL; |
---|
549 | int rv = 0; |
---|
550 | int channel = 0; |
---|
551 | uint32_t error_status = 0; |
---|
552 | rtems_id transfer_update; |
---|
553 | |
---|
554 | sc = rtems_semaphore_create ( |
---|
555 | rtems_build_name ( 'T', 'S', 'T', 'C'), |
---|
556 | 0, |
---|
557 | RTEMS_SIMPLE_BINARY_SEMAPHORE | RTEMS_INHERIT_PRIORITY | RTEMS_PRIORITY, |
---|
558 | RTEMS_NO_PRIORITY, |
---|
559 | &transfer_update |
---|
560 | ); |
---|
561 | CHECK_SC( sc, "rtems_semaphore_create"); |
---|
562 | |
---|
563 | rv = mpc55xx_edma_obtain_channel( channel, &error_status, transfer_update); |
---|
564 | CHECK_RV( rv, "mpc55xx_edma_obtain_channel"); |
---|
565 | |
---|
566 | int i = 0; |
---|
567 | for (i = 0; i < BUFSIZE; ++i) { |
---|
568 | inbuf [i] = i; |
---|
569 | outbuf [i] = -1; |
---|
570 | } |
---|
571 | rtems_cache_flush_multiple_data_lines( inbuf, BUFSIZE); |
---|
572 | rtems_cache_flush_multiple_data_lines( outbuf, BUFSIZE); |
---|
573 | |
---|
574 | struct tcd_t tcd = MPC55XX_EDMA_TCD_DEFAULT; |
---|
575 | tcd.SADDR = (uint32_t) &inbuf; |
---|
576 | tcd.DADDR = (uint32_t) &outbuf; |
---|
577 | tcd.NBYTES = BUFSIZE / ITER; |
---|
578 | tcd.SLAST = -BUFSIZE; |
---|
579 | tcd.CITER = ITER; |
---|
580 | tcd.BITER = ITER; |
---|
581 | tcd.INT_HALF = 1; |
---|
582 | |
---|
583 | EDMA.TCD [channel] = tcd; |
---|
584 | |
---|
585 | while (1) { |
---|
586 | while (1) { |
---|
587 | if (EDMA.TCD [channel].DONE == 1) { |
---|
588 | EDMA.TCD [channel].DONE = 0; |
---|
589 | printk( "%s: Done\n", __func__); |
---|
590 | break; |
---|
591 | } else if (EDMA.TCD [channel].ACTIVE == 0) { |
---|
592 | EDMA.SSBR.R = channel; |
---|
593 | printk( "%s: Start: %i (%i)\n", __func__, EDMA.TCD [channel].CITER, EDMA.TCD [channel].BITER); |
---|
594 | } |
---|
595 | sc = rtems_semaphore_obtain( transfer_update, RTEMS_WAIT, 10); |
---|
596 | if (sc == RTEMS_TIMEOUT) { |
---|
597 | continue; |
---|
598 | } |
---|
599 | CHECK_SC( sc, "rtems_semaphore_obtain"); |
---|
600 | } |
---|
601 | printk( "%s: Error status: 0x%08x\n", __func__, error_status); |
---|
602 | } |
---|
603 | |
---|
604 | return sc; |
---|
605 | } |
---|
606 | |
---|
607 | static unsigned test_mpc55xx_intc_counter = 0; |
---|
608 | |
---|
609 | static inline void test_mpc55xx_intc_worker( void *data) |
---|
610 | { |
---|
611 | int s = 0; |
---|
612 | int i = *(int *) data; |
---|
613 | printk( "(%i): Start: %u\n", i, tac()); |
---|
614 | s = mpc55xx_intc_clear_software_irq( i); |
---|
615 | if (i < MPC55XX_IRQ_SOFTWARE_NUMBER) { |
---|
616 | tic(); |
---|
617 | s = mpc55xx_intc_raise_software_irq( i + 1); |
---|
618 | } |
---|
619 | ++test_mpc55xx_intc_counter; |
---|
620 | printk( "(%i): Done\n", i); |
---|
621 | } |
---|
622 | |
---|
623 | static void test_mpc55xx_intc_handler( rtems_vector_number vector, void *data) |
---|
624 | { |
---|
625 | test_mpc55xx_intc_worker( data); |
---|
626 | } |
---|
627 | |
---|
628 | static void test_mpc55xx_intc_handler_2( void *data) |
---|
629 | { |
---|
630 | test_mpc55xx_intc_worker( data); |
---|
631 | } |
---|
632 | |
---|
633 | static void test_mpc55xx_intc_handler_3( void *data) |
---|
634 | { |
---|
635 | test_mpc55xx_intc_worker( data); |
---|
636 | } |
---|
637 | |
---|
638 | static int test_mpc55xx_intc_handler_data [MPC55XX_IRQ_SOFTWARE_NUMBER]; |
---|
639 | |
---|
640 | static rtems_task test_mpc55xx_intc( rtems_task_argument arg) |
---|
641 | { |
---|
642 | volatile int i = 0; |
---|
643 | int p = 0; |
---|
644 | unsigned s = 0; |
---|
645 | rtems_irq_connect_data e; |
---|
646 | rtems_status_code sc = RTEMS_SUCCESSFUL; |
---|
647 | |
---|
648 | for (i = MPC55XX_IRQ_SOFTWARE_MIN, p = MPC55XX_INTC_MIN_PRIORITY; i <= MPC55XX_IRQ_SOFTWARE_MAX; ++i, ++p) { |
---|
649 | test_mpc55xx_intc_handler_data [i] = i; |
---|
650 | e.name = i; |
---|
651 | e.handle = &test_mpc55xx_intc_handler_data [i]; |
---|
652 | |
---|
653 | sc = rtems_interrupt_handler_install( i, "test_mpc55xx_intc_handler", RTEMS_INTERRUPT_SHARED, test_mpc55xx_intc_handler, e.handle); |
---|
654 | if (sc != RTEMS_SUCCESSFUL) { |
---|
655 | BSP_panic( "Handler install failed"); |
---|
656 | } |
---|
657 | |
---|
658 | e.hdl = test_mpc55xx_intc_handler_2; |
---|
659 | if (BSP_install_rtems_shared_irq_handler( &e) != RTEMS_SUCCESSFUL) { |
---|
660 | BSP_panic( "Handler install 2 failed"); |
---|
661 | } |
---|
662 | |
---|
663 | e.hdl = test_mpc55xx_intc_handler_3; |
---|
664 | if (BSP_install_rtems_shared_irq_handler( &e) != RTEMS_SUCCESSFUL) { |
---|
665 | BSP_panic( "Handler install 3 failed"); |
---|
666 | } |
---|
667 | } |
---|
668 | |
---|
669 | while (1) { |
---|
670 | i = (int) (7.0 * (rand_r( &s) / (RAND_MAX + 1.0))); |
---|
671 | tic(); |
---|
672 | mpc55xx_intc_raise_software_irq( i); |
---|
673 | } |
---|
674 | } |
---|