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