| 37 | } |
| 38 | |
| 39 | static rt_err_t _block_device_test(rt_device_t device) |
| 40 | { |
| 41 | rt_err_t result; |
| 42 | struct rt_device_blk_geometry geometry; |
| 43 | rt_uint8_t * read_buffer = RT_NULL; |
| 44 | rt_uint8_t * write_buffer = RT_NULL; |
| 45 | |
| 46 | rt_kprintf("\r\n"); |
| 47 | |
| 48 | if( (device->flag & RT_DEVICE_FLAG_RDWR) == RT_DEVICE_FLAG_RDWR ) |
| 49 | { |
| 50 | // device can read and write. |
| 51 | // step 1: open device |
| 52 | result = rt_device_open(device,RT_DEVICE_FLAG_RDWR); |
| 53 | if( result != RT_EOK ) |
| 54 | { |
| 55 | return result; |
| 56 | } |
| 57 | |
| 58 | // step 2: get device info |
| 59 | rt_memset(&geometry, 0, sizeof(geometry)); |
| 60 | result = rt_device_control(device, |
| 61 | RT_DEVICE_CTRL_BLK_GETGEOME, |
| 62 | &geometry); |
| 63 | if( result != RT_EOK ) |
| 64 | { |
| 65 | rt_kprintf("device : %s cmd RT_DEVICE_CTRL_BLK_GETGEOME failed.\r\n"); |
| 66 | return result; |
| 67 | } |
| 68 | rt_kprintf("device info:\r\n"); |
| 69 | rt_kprintf("sector size : %d byte\r\n", geometry.bytes_per_sector); |
| 70 | rt_kprintf("sector count : %d \r\n", geometry.sector_count); |
| 71 | rt_kprintf("block size : %d byte\r\n", geometry.block_size); |
| 72 | |
| 73 | rt_kprintf("\r\n"); |
| 74 | read_buffer = rt_malloc(geometry.bytes_per_sector); |
| 75 | if( read_buffer == RT_NULL ) |
| 76 | { |
| 77 | rt_kprintf("no memory for read_buffer!\r\n"); |
| 78 | goto __return; |
| 79 | } |
| 80 | write_buffer = rt_malloc(geometry.bytes_per_sector); |
| 81 | if( write_buffer == RT_NULL ) |
| 82 | { |
| 83 | rt_kprintf("no memory for write_buffer!\r\n"); |
| 84 | goto __return; |
| 85 | } |
| 86 | |
| 87 | /* step 3: R/W test */ |
| 88 | { |
| 89 | rt_uint32_t i, err_count, sector_no; |
| 90 | rt_uint8_t * data_point; |
| 91 | |
| 92 | i = rt_device_read(device, 0, read_buffer, 1); |
| 93 | if(i != 1) |
| 94 | { |
| 95 | rt_kprintf("read device :%s ", device->parent.name); |
| 96 | rt_kprintf("the first sector failed.\r\n"); |
no test coverage detected