本文整理汇总了C++中rt_device_t::write方法的典型用法代码示例。如果您正苦于以下问题:C++ rt_device_t::write方法的具体用法?C++ rt_device_t::write怎么用?C++ rt_device_t::write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rt_device_t
的用法示例。
在下文中一共展示了rt_device_t::write方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
rt_size_t send_data_by_485(USART_TypeDef *dev_485, void *data, rt_size_t len)
{
rt_size_t size;
if (NULL==dev_485 || NULL==data) {
rs485_info(("send_data_by_485() param invalid\n"));
return 0;
}
set_485_tx_rx_state(dev_485, 1);
//rt_thread_delay(2);
if (UART_485_1_DEV_PTR == dev_485) {
size = dev_485_1->write(dev_485_1, 0, data, len);
} else if (UART_485_2_DEV_PTR == dev_485) {
size = dev_485_2->write(dev_485_2, 0, data, len);
} else if (UART_485_3_DEV_PTR == dev_485) {
size = dev_485_3->write(dev_485_3, 0, data, len);
} else {
size = 0;
rs485_info(("revc invalid 485 dev param(0x%x)\n", dev_485));
}
//rt_thread_delay(1);
wait_usartx_send_over(dev_485);
set_485_tx_rx_state(dev_485, 0);
return size;
}
示例2:
/***************************************************************************//**
* @brief
* Write data to SSD2119 controller
*
* @param[in] reg
* Register to write to
*
* @param[in] data
* 16-bit data to write into register
*
* @note
* It's not possible to read back register value through SSD2119 SPI interface
******************************************************************************/
rt_err_t efm32_spiLcd_writeRegister(rt_uint8_t reg, rt_uint16_t data)
{
struct efm32_usart_device_t *usart;
rt_uint8_t buf_ins[3];
rt_uint8_t buf_res[3];
RT_ASSERT(lcd != RT_NULL);
usart = (struct efm32_usart_device_t *)(lcd->user_data);
/* Build instruction buffer */
buf_res[0] = (data & 0xff00) >> 8;
buf_res[1] = data & 0x00ff;
buf_ins[0] = 1; /* Instruction length */
buf_ins[1] = reg; /* Instruction */
*(rt_uint8_t **)(&buf_ins[2]) = buf_res; /* Data */
efm32_spiLcd_cs(1);
if (lcd->write(lcd, EFM32_NO_DATA, buf_ins, 2) == 0)
{
lcd_debug("LCD: Write data failed!\n");
return -RT_ERROR;
}
efm32_spiLcd_cs(0);
return RT_EOK;
}
示例3: MAL_Write
uint16_t MAL_Write(uint8_t lun, uint32_t Memory_Offset, uint32_t *Writebuff, uint16_t Transfer_Length)
{
#if (USB_USE_AUTO_REMOVE == 1)
test_unit_ready_last = rt_tick_get();
#endif
switch (lun)
{
case 0:
{
dev_sdio->write(dev_sdio,Memory_Offset/Mass_Block_Size[0],Writebuff,Transfer_Length/Mass_Block_Size[0]);
}
break;
case 1:
{
dev_spi_flash->write(dev_spi_flash,Memory_Offset/Mass_Block_Size[1],Writebuff,Transfer_Length/Mass_Block_Size[1]);
}
break;
default:
return MAL_FAIL;
}
return MAL_OK;
}
示例4:
rt_size_t send_data_by_tl16_485(rt_device_t dev_485, void *data, rt_size_t len)
{
rt_size_t size;
if (NULL==dev_485 || NULL==data) {
rs485_info(("send_data_by_485() param invalid\n"));
return 0;
}
set_tl16_485_tx_rx_state(dev_485, 1);
//rt_thread_delay(2);
size = dev_485->write(dev_485, 0, data, len);
//rt_thread_delay(1);
while (TRUE != is_tl16_485_tx_over(dev_485))
;
set_tl16_485_tx_rx_state(dev_485, 0);
return size;
}
示例5: rt_device_write
/**
* This function will write some data to a device.
*
* @param dev the pointer of device driver structure
* @param pos the position of written
* @param buffer the data buffer to be written to device
* @param size the size of buffer
*
* @return the actually written 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_write(rt_device_t dev,
rt_off_t pos,
const 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 write interface */
if (dev->write != RT_NULL)
{
return dev->write(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;
//.........这里部分代码省略.........
示例7: usart_tx_thread_entry
void usart_tx_thread_entry(void *p)
{
fd_set readset;
struct timeval timeout;
int fd_max;
timeout.tv_sec = 0; // second.
timeout.tv_usec = 100*1000; //wait micro second.
while( 1 )
{
int i;
// prepare select fd.
FD_ZERO(&readset);
fd_max = 0;
for( i = 0 ; i < SOCKET_LIST_SIZE ; i++ )
{
if( socket_list[i].used )
{
if( fd_max < socket_list[i].socket )
fd_max = socket_list[i].socket;
FD_SET(socket_list[i].socket,&readset);
}
}
// no connection.
if( fd_max == 0 )
{
rt_thread_delay(1); // delay 10ms.
continue;
}
if( lwip_select(fd_max+1,&readset,NULL,0,&timeout) == 0 )
continue;
for( i = 0 ; i < SOCKET_LIST_SIZE ; i++ )
{
rt_err_t ret;
// NOTE: we can take tx semaphore here means that the DMA buffer is not in use.
// We must NOT write the DMA buffer until notified to be used.
rt_sem_take(&tx1_sem,RT_WAITING_FOREVER);
rt_sem_take(&tx2_sem,RT_WAITING_FOREVER);
// Timeout 100ms.
ret = rt_mutex_take(&(socket_list[i].mu_sock),10);
if( ret == -RT_ETIMEOUT )
{
rt_kprintf("Taking mu_sock timeout.\n");
rt_sem_release(&tx2_sem);
rt_sem_release(&tx1_sem);
continue;
}
if( socket_list[i].used && FD_ISSET(socket_list[i].socket,&readset) )
{
unsigned short dataLen = lwip_recv(socket_list[i].socket,tx_buf,TX_BUF_SIZE,MSG_DONTWAIT);
if( dataLen > 0 )
{
usart_bytes_sent += dataLen;
usart_led_flash();
dev_uart1->write(dev_uart1,0,tx_buf,dataLen);
dev_uart2->write(dev_uart2,0,tx_buf,dataLen);
// we have sent data to usart.
rt_mutex_release(&(socket_list[i].mu_sock));
continue;
}
else
{
lwip_close(socket_list[i].socket);
socket_list[i].used = 0;
rt_kprintf("recv failed or FIN recv, close socket.\n");
}
}
rt_mutex_release(&(socket_list[i].mu_sock));
rt_sem_release(&tx2_sem);
rt_sem_release(&tx1_sem);
}
}
}
示例8: usart_rx_thread_entry
void usart_rx_thread_entry(void *p)
{
unsigned short max_interval,max_datalen;
unsigned int current_mode;
getFrameSplit(&max_interval,&max_datalen);
current_mode = getWorkingMode();
while( rt_sem_take(&rx_sem,RT_WAITING_FOREVER) == RT_EOK )
{
register rt_base_t temp;
FEED_THE_DOG();
// if rj45 not connected, we should route data between 232 and 485.
if( getLinkStatus() == 0 )
{
// we split rx_buf to 2 parts in order to save space.
int len1,len2;
// Clear the semaphore.
temp = rt_hw_interrupt_disable();
rx_sem.value = 0;
rt_hw_interrupt_enable(temp);
do
{
usart_led_flash();
// recv usart1
rt_sem_take(&tx2_sem,RT_WAITING_FOREVER);
len1 = rt_device_read(dev_uart1,0,rx_buf,RX_BUF_SIZE/2);
if( len1 )
dev_uart2->write(dev_uart2, 0, rx_buf, len1);
else
rt_sem_release(&tx2_sem);
// recv usart2
rt_sem_take(&tx1_sem,RT_WAITING_FOREVER);
len2 = rt_device_read(dev_uart2,0,rx_buf+RX_BUF_SIZE/2,RX_BUF_SIZE/2);
if( len2 )
dev_uart1->write(dev_uart1, 0, rx_buf+RX_BUF_SIZE/2, len2);
else
rt_sem_release(&tx1_sem);
}while( (len1 != 0) && (len2 != 0) );
continue;
}
else
{
// Clear the semaphore.
temp = rt_hw_interrupt_disable();
rx_sem.value = 0;
rt_hw_interrupt_enable(temp);
while( 1 )
{
int len;
usart_led_flash();
// read data.
len = rt_device_read(dev_uart1,0,rx_buf+rx_buf_offset,RX_BUF_SIZE-rx_buf_offset);
if( len == 0 )
{
len = rt_device_read(dev_uart2,0,rx_buf+rx_buf_offset,RX_BUF_SIZE-rx_buf_offset);
}
usart_bytes_recv += len;
// If buffer is empty and we received data, start the timer.
if( rx_buf_offset == 0 )
{
if( len == 0 )
{
break;
}
else
{
// if interval less than 10ms, we send data immediately.
if( max_interval >= 10 )
rt_timer_start(&max_interval_timer);
}
}
// move offset pointer.
rx_buf_offset += len;
// check if we should send data out.
if( rx_buf_offset < max_datalen &&
max_interval_timer.parent.flag & RT_TIMER_FLAG_ACTIVATED )
{
break;
}
// Send data out.
if((current_mode == TCP_SERVER)||
(current_mode == TCP_CLIENT)||
(current_mode == TCP_AUTO))
{
int i;
// send data.
for( i = 0 ; i < SOCKET_LIST_SIZE ; i++ )
{
// we should not use RT_WAITING_FOREVER here.
if( rt_mutex_take(&(socket_list[i].mu_sock),10) != RT_EOK )
//.........这里部分代码省略.........