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