* @brief This function will read some data from a device. * * @param dev is the pointer of device driver structure. * * @param pos is the position when reading. * * @param buffer is a data buffer to save the read data. * * @param size is the size of buffer. * * @return the actually read size on successful, otherwise 0 will be returned. * * @note the unit of size/pos is a block for bloc
| 335 | * @note the unit of size/pos is a block for block device. |
| 336 | */ |
| 337 | rt_ssize_t rt_device_read(rt_device_t dev, |
| 338 | rt_off_t pos, |
| 339 | void *buffer, |
| 340 | rt_size_t size) |
| 341 | { |
| 342 | /* parameter check */ |
| 343 | RT_ASSERT(dev != RT_NULL); |
| 344 | RT_ASSERT(rt_object_get_type(&dev->parent) == RT_Object_Class_Device); |
| 345 | |
| 346 | if (dev->ref_count == 0) |
| 347 | { |
| 348 | rt_set_errno(-RT_ERROR); |
| 349 | return 0; |
| 350 | } |
| 351 | |
| 352 | /* call device_read interface */ |
| 353 | if (device_read != RT_NULL) |
| 354 | { |
| 355 | return device_read(dev, pos, buffer, size); |
| 356 | } |
| 357 | |
| 358 | /* set error code */ |
| 359 | rt_set_errno(-RT_ENOSYS); |
| 360 | |
| 361 | return 0; |
| 362 | } |
| 363 | RTM_EXPORT(rt_device_read); |
| 364 | |
| 365 | /** |