本文整理汇总了C++中rt_device_t::read方法的典型用法代码示例。如果您正苦于以下问题:C++ rt_device_t::read方法的具体用法?C++ rt_device_t::read怎么用?C++ rt_device_t::read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rt_device_t
的用法示例。
在下文中一共展示了rt_device_t::read方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MAL_Read
uint16_t MAL_Read(uint8_t lun, uint32_t Memory_Offset, uint32_t *Readbuff, uint16_t Transfer_Length)
{
#if (USB_USE_AUTO_REMOVE == 1)
test_unit_ready_last = rt_tick_get();
#endif
switch (lun)
{
case 0:
{
dev_sdio->read(dev_sdio,Memory_Offset/Mass_Block_Size[0],Readbuff,Transfer_Length/Mass_Block_Size[0]);
}
break;
case 1:
{
dev_spi_flash->read(dev_spi_flash,Memory_Offset/Mass_Block_Size[1],Readbuff,Transfer_Length/Mass_Block_Size[1]);
}
break;
default:
return MAL_FAIL;
}
return MAL_OK;
}
示例2:
rt_size_t recv_data_by_tl16_485(rt_device_t dev_485, void *buf, rt_size_t len)
{
rt_size_t size;
if (NULL==dev_485 || NULL==buf) {
rs485_info(("recv_data_by_485() param invalid\n"));
return 0;
}
size = dev_485->read(dev_485, 0, buf, len);
return size;
}
示例3: if
rt_size_t recv_data_by_485(USART_TypeDef *dev_485, void *buf, rt_size_t len)
{
rt_size_t size;
if (NULL==dev_485 || NULL==buf) {
rs485_info(("recv_data_by_485() param invalid\n"));
return 0;
}
if (UART_485_1_DEV_PTR == dev_485) {
size = dev_485_1->read(dev_485_1, 0, buf, len);
} else if (UART_485_2_DEV_PTR == dev_485) {
size = dev_485_2->read(dev_485_2, 0, buf, len);
} else if (UART_485_3_DEV_PTR == dev_485) {
size = dev_485_3->read(dev_485_3, 0, buf, len);
} else {
size = 0;
rs485_info(("*revc invalid 485 dev param(0x%x)\n", dev_485));
}
return size;
}
示例4: info_tran_stream_analysis
void info_tran_stream_analysis(rt_device_t dev)
{
static int info_id;
static int revc_state = IAS_IDEL;
int cnt, index, temp;
index = 0;
cnt = dev->read(dev, 0, info_tran_buf, sizeof(info_tran_buf));
while (0 != cnt--) {
temp = info_tran_buf[index++];
#if 0
info_tran_debug(("index:%d, data:0x%x\n", index-1, temp));
#endif
switch (revc_state) {
case IAS_IDEL:
info_id = temp;
if (0 != (info_id & 0xf0)) {
info_tran_data.data_len = get_info_data_len((info_id & 0xf0)>>4, info_id & 0x0f);
if (0 != info_tran_data.data_len) {
/* 由于每个字节是4位有效数据,所以实际字节长度是除以2 */
temp = info_tran_data.data_len>>1;
if ( temp <= sizeof(info_tran_data.data)) {
rt_memset(info_tran_data.data, 0, sizeof(info_tran_data.data));
revc_state = IAS_WAIT_DATA;
info_tran_data.ind = 0;
} else {
rt_kprintf("error!! func:%s, data buf too small\n", __FUNCTION__);
}
}
}
break;
case IAS_WAIT_DATA:
if (0 == (temp&0xf0)) {
if (0 == (info_tran_data.ind&0x01)) {
info_tran_data.data[info_tran_data.ind>>1] |= temp<<4;
} else {
示例5: rt_device_read
/**
* This function will read some data from a device.
*
* @param dev the pointer of device driver structure
* @param pos the position of reading
* @param buffer the data buffer to save read data
* @param size the size of buffer
*
* @return the actually read size on successful, otherwise negative returned.
*
* @note since 0.4.0, the unit of size/pos is a block for block device.
*/
rt_size_t rt_device_read(rt_device_t dev,
rt_off_t pos,
void *buffer,
rt_size_t size)
{
RT_ASSERT(dev != RT_NULL);
if (dev->ref_count == 0)
{
rt_set_errno(-RT_ERROR);
return 0;
}
/* call device read interface */
if (dev->read != RT_NULL)
{
return dev->read(dev, pos, buffer, size);
}
/* set error code */
rt_set_errno(-RT_ENOSYS);
return 0;
}
示例6: _block_device_test
static rt_err_t _block_device_test(rt_device_t device)
{
rt_err_t result;
struct rt_device_blk_geometry geometry;
rt_uint8_t * read_buffer = RT_NULL;
rt_uint8_t * write_buffer = RT_NULL;
rt_kprintf("\r\n");
if( (device->flag & RT_DEVICE_FLAG_RDWR) == RT_DEVICE_FLAG_RDWR )
{
// device can read and write.
// step 1: open device
result = device->open(device,RT_DEVICE_FLAG_RDWR);
if( result == RT_EOK )
{
device->open_flag |= RT_DEVICE_OFLAG_RDWR | RT_DEVICE_OFLAG_OPEN;
}
else
{
return result;
}
// step 2: get device info
rt_memset(&geometry, 0, sizeof(geometry));
result = rt_device_control(device, RT_DEVICE_CTRL_BLK_GETGEOME, &geometry);
if( result != RT_EOK )
{
rt_kprintf("device : %s cmd RT_DEVICE_CTRL_BLK_GETGEOME failed.\r\n");
return result;
}
rt_kprintf("device info:\r\n");
rt_kprintf("sector size : %d byte\r\n",geometry.bytes_per_sector);
rt_kprintf("sector count : %d \r\n",geometry.sector_count);
rt_kprintf("block size : %d byte\r\n",geometry.block_size);
rt_kprintf("\r\n");
read_buffer = rt_malloc(geometry.bytes_per_sector);
if( read_buffer == RT_NULL )
{
rt_kprintf("no memory for read_buffer!\r\n");
goto __return;
}
write_buffer = rt_malloc(geometry.bytes_per_sector);
if( write_buffer == RT_NULL )
{
rt_kprintf("no memory for write_buffer!\r\n");
goto __return;
}
//step 3: I/O R/W test
{
rt_uint32_t i,err_count,sector_no;
rt_uint8_t * data_point;
// the first sector
sector_no = 0;
data_point = write_buffer;
*data_point++ = (rt_uint8_t)sector_no;
for(i=1; i<geometry.bytes_per_sector; i++)
{
*data_point++ = (rt_uint8_t)i;
}
i = device->write(device,sector_no,write_buffer,1);
if( i != 1 )
{
rt_kprintf("write device :%s ",device->parent.name);
rt_kprintf("the first sector failed.\r\n");
goto __return;
}
i = device->read(device,sector_no,read_buffer,1);
if( i != 1 )
{
rt_kprintf("read device :%s ",device->parent.name);
rt_kprintf("the first sector failed.\r\n");
goto __return;
}
err_count = 0;
data_point = read_buffer;
if( (*data_point++) != (rt_uint8_t)sector_no)
{
err_count++;
}
for(i=1; i<geometry.bytes_per_sector; i++)
{
if( (*data_point++) != (rt_uint8_t)i )
{
err_count++;
}
}
if( err_count > 0 )
{
rt_kprintf("verify device :%s ",device->parent.name);
rt_kprintf("the first sector failed.\r\n");
goto __return;
}
// the second sector
sector_no = 1;
data_point = write_buffer;
*data_point++ = (rt_uint8_t)sector_no;
//.........这里部分代码省略.........