当前位置: 首页>>代码示例>>C++>>正文


C++ rt_device_t类代码示例

本文整理汇总了C++中rt_device_t的典型用法代码示例。如果您正苦于以下问题:C++ rt_device_t类的具体用法?C++ rt_device_t怎么用?C++ rt_device_t使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了rt_device_t类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: rt_device_open

/**
 * This function will open a device
 *
 * @param dev the pointer of device driver structure
 * @param oflag the flags for device open
 *
 * @return the result
 */
rt_err_t rt_device_open(rt_device_t dev, rt_uint16_t oflag)
{
    rt_err_t result = RT_EOK;

    RT_ASSERT(dev != RT_NULL);

    /* if device is not initialized, initialize it. */
    if (!(dev->flag & RT_DEVICE_FLAG_ACTIVATED))
    {
        if (dev->init != RT_NULL)
        {
            result = dev->init(dev);
            if (result != RT_EOK)
            {
                rt_kprintf("To initialize device:%s failed. The error code is %d\n",
                           dev->parent.name, result);

                return result;
            }
        }

        dev->flag |= RT_DEVICE_FLAG_ACTIVATED;
    }

    /* device is a stand alone device and opened */
    if ((dev->flag & RT_DEVICE_FLAG_STANDALONE) &&
        (dev->open_flag & RT_DEVICE_OFLAG_OPEN))
    {
        return -RT_EBUSY;
    }

    /* call device open interface */
    if (dev->open != RT_NULL)
    {
        result = dev->open(dev, oflag);
    }

    /* set open flag */
    if (result == RT_EOK || result == -RT_ENOSYS)
    {
        dev->open_flag = oflag | RT_DEVICE_OFLAG_OPEN;

        dev->ref_count++;
        /* don't let bad things happen silently. If you are bitten by this assert,
         * please set the ref_count to a bigger type. */
        RT_ASSERT(dev->ref_count != 0);
    }

    return result;
}
开发者ID:1847123212,项目名称:SFUD,代码行数:58,代码来源:device.c

示例2: efm32_spiLcd_writeRegister

/***************************************************************************//**
 * @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;
}
开发者ID:304471720,项目名称:rt-thread,代码行数:38,代码来源:dev_lcd.c

示例3: rt_device_init

/**
 * This function will initialize the specified device
 *
 * @param dev the pointer of device driver structure
 *
 * @return the result
 */
rt_err_t rt_device_init(rt_device_t dev)
{
    rt_err_t result = RT_EOK;

    RT_ASSERT(dev != RT_NULL);

    /* get device init handler */
    if (dev->init != RT_NULL)
    {
        if (!(dev->flag & RT_DEVICE_FLAG_ACTIVATED))
        {
            result = dev->init(dev);
            if (result != RT_EOK)
            {
                rt_kprintf("To initialize device:%s failed. The error code is %d\n",
                           dev->parent.name, result);
            }
            else
            {
                dev->flag |= RT_DEVICE_FLAG_ACTIVATED;
            }
        }
    }

    return result;
}
开发者ID:1847123212,项目名称:SFUD,代码行数:33,代码来源:device.c

示例4: rt_hw_serial_isr

/* ISR for serial interrupt */
void rt_hw_serial_isr(rt_device_t device)
{
    struct serial_device* uart = (struct serial_device*) device->user_data;

    /* interrupt mode receive */
    RT_ASSERT(device->flag & RT_DEVICE_FLAG_INT_RX);

    /* save on rx buffer */
    while (uart->uart_device->ustat & USTAT_RCV_READY)
    {
        rt_serial_savechar(uart, uart->uart_device->urxh & 0xff);
    }

    /* invoke callback */
    if (device->rx_indicate != RT_NULL)
    {
        rt_size_t rx_length;

        /* get rx length */
        rx_length = uart->int_rx->read_index > uart->int_rx->save_index ?
                    UART_RX_BUFFER_SIZE - uart->int_rx->read_index + uart->int_rx->save_index :
                    uart->int_rx->save_index - uart->int_rx->read_index;

        device->rx_indicate(device, rx_length);
    }
}
开发者ID:cedar-renjun,项目名称:air-conditioning-assistant,代码行数:27,代码来源:serial.c

示例5: rt_device_close

/**
 * This function will close a device
 *
 * @param dev the pointer of device driver structure
 *
 * @return the result
 */
rt_err_t rt_device_close(rt_device_t dev)
{
    rt_err_t result = RT_EOK;

    RT_ASSERT(dev != RT_NULL);

    if (dev->ref_count == 0)
        return -RT_ERROR;

    dev->ref_count--;

    if (dev->ref_count != 0)
        return RT_EOK;

    /* call device close interface */
    if (dev->close != RT_NULL)
    {
        result = dev->close(dev);
    }

    /* set open flag */
    if (result == RT_EOK || result == -RT_ENOSYS)
        dev->open_flag = RT_DEVICE_OFLAG_CLOSE;

    return result;
}
开发者ID:1847123212,项目名称:SFUD,代码行数:33,代码来源:device.c

示例6: rt_hw_serial_isr

/* ISR for serial interrupt */
void rt_hw_serial_isr(rt_device_t device)
{
	struct stm32_serial_device* uart = (struct stm32_serial_device*) device->user_data;

	if(USART_GetITStatus(uart->uart_device, USART_IT_RXNE) != RESET)
	{
		/* interrupt mode receive */
		RT_ASSERT(device->flag & RT_DEVICE_FLAG_INT_RX);

		/* save on rx buffer */
		while (uart->uart_device->SR & USART_FLAG_RXNE)
		{
			rt_base_t level;

			/* disable interrupt */
			level = rt_hw_interrupt_disable();

			/* save character */
			uart->int_rx->rx_buffer[uart->int_rx->save_index] = uart->uart_device->DR & 0xff;
			uart->int_rx->save_index ++;
			if (uart->int_rx->save_index >= UART_RX_BUFFER_SIZE)
				uart->int_rx->save_index = 0;

			/* if the next position is read index, discard this 'read char' */
			if (uart->int_rx->save_index == uart->int_rx->read_index)
			{
				uart->int_rx->read_index ++;
				if (uart->int_rx->read_index >= UART_RX_BUFFER_SIZE)
					uart->int_rx->read_index = 0;
			}

			/* enable interrupt */
			rt_hw_interrupt_enable(level);
		}

		/* clear interrupt */
		USART_ClearITPendingBit(uart->uart_device, USART_IT_RXNE);

		/* invoke callback */
		if (device->rx_indicate != RT_NULL)
		{
			rt_size_t rx_length;

			/* get rx length */
			rx_length = uart->int_rx->read_index > uart->int_rx->save_index ?
				UART_RX_BUFFER_SIZE - uart->int_rx->read_index + uart->int_rx->save_index :
				uart->int_rx->save_index - uart->int_rx->read_index;

			device->rx_indicate(device, rx_length);
		}
	}

	if (USART_GetITStatus(uart->uart_device, USART_IT_TC) != RESET)
	{
		/* clear interrupt */
		USART_ClearITPendingBit(uart->uart_device, USART_IT_TC);
	}
}
开发者ID:yihui-he,项目名称:Badminton-Robot,代码行数:59,代码来源:serial.c

示例7: rt_device_control

/**
 * This function will perform a variety of control functions on devices.
 *
 * @param dev the pointer of device driver structure
 * @param cmd the command sent to device
 * @param arg the argument of command
 *
 * @return the result
 */
rt_err_t rt_device_control(rt_device_t dev, rt_uint8_t cmd, void *arg)
{
    RT_ASSERT(dev != RT_NULL);

    /* call device write interface */
    if (dev->control != RT_NULL)
    {
        return dev->control(dev, cmd, arg);
    }

    return RT_EOK;
}
开发者ID:1847123212,项目名称:SFUD,代码行数:21,代码来源:device.c

示例8: recv_data_by_tl16_485

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;
}
开发者ID:malooei,项目名称:yeejoin-workspace,代码行数:13,代码来源:rs485.c

示例9: rt_hw_serial_dma_tx_isr

/*
 * ISR for DMA mode Tx
 */
void rt_hw_serial_dma_tx_isr(rt_device_t device)
{
	rt_uint32_t level;
	struct stm32_serial_data_node* data_node;
	struct stm32_serial_device* uart = (struct stm32_serial_device*) device->user_data;

	/* DMA mode receive */
	RT_ASSERT(device->flag & RT_DEVICE_FLAG_DMA_TX);

	/* get the first data node */
	data_node = uart->dma_tx->list_head;
	RT_ASSERT(data_node != RT_NULL);

	/* invoke call to notify tx complete */
	if (device->tx_complete != RT_NULL)
		device->tx_complete(device, data_node->data_ptr);

	/* disable interrupt */
	level = rt_hw_interrupt_disable();

	/* remove list head */
	uart->dma_tx->list_head = data_node->next;
	if (uart->dma_tx->list_head == RT_NULL) /* data link empty */
		uart->dma_tx->list_tail = RT_NULL;

	/* enable interrupt */
	rt_hw_interrupt_enable(level);

	/* release data node memory */
	rt_mp_free(data_node);

	if (uart->dma_tx->list_head != RT_NULL)
	{
		/* transmit next data node */
		rt_serial_enable_dma(uart->dma_tx->dma_channel,
			(rt_uint32_t)uart->dma_tx->list_head->data_ptr,
			uart->dma_tx->list_head->data_size);
	}
	else
	{
		/* no data to be transmitted, disable DMA */
		DMA_Cmd(uart->dma_tx->dma_channel, DISABLE);
	}
}
开发者ID:yihui-he,项目名称:Badminton-Robot,代码行数:47,代码来源:serial.c

示例10: rt_hw_usart_dma_tx_isr

/***************************************************************************//**
 * @brief
 *  DMA for USART TX interrupt handler
 *
 * @details
 *
 * @note
 *
 * @param[in] dev
 *  Pointer to device descriptor
 ******************************************************************************/
void rt_hw_usart_dma_tx_isr(rt_device_t dev)
{
    /* DMA mode receive */
    struct efm32_usart_device_t     *usart;
    struct efm32_usart_dma_mode_t   *dma_tx;

    RT_ASSERT(dev->flag & RT_DEVICE_FLAG_DMA_TX);

    usart = (struct efm32_usart_device_t *)(dev->user_data);
    dma_tx = (struct efm32_usart_dma_mode_t *)(usart->tx_mode);

    /* invoke call to notify tx complete */
    if (dev->tx_complete != RT_NULL)
    {
        dev->tx_complete(dev, dma_tx->data_ptr);
    }

    /* Set status */
    usart->state &= ~(rt_uint32_t)USART_STATE_TX_BUSY;
}
开发者ID:hduffddybz,项目名称:rt-thread,代码行数:31,代码来源:drv_usart.c

示例11: send_data_by_tl16_485

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;
}
开发者ID:malooei,项目名称:yeejoin-workspace,代码行数:22,代码来源:rs485.c

示例12: 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 {
开发者ID:malooei,项目名称:yeejoin-workspace,代码行数:37,代码来源:info_tran.c

示例13: 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;
}
开发者ID:1847123212,项目名称:SFUD,代码行数:36,代码来源:device.c

示例14: rt_hw_serial_isr

/* ISR for serial interrupt */
void rt_hw_serial_isr(rt_device_t device)
{
    struct stm32_serial_device* uart = (struct stm32_serial_device*) device->user_data;
    static unsigned char checksum = 0;
    static uint16_t lenth;
    // static unsigned char gprmcbuf[400];
    static unsigned char isgprmc=0;
    static unsigned short gprmccnt = 0;

    if(USART_GetITStatus(uart->uart_device, USART_IT_RXNE) != RESET)
    {
        /* interrupt mode receive */
        RT_ASSERT(device->flag & RT_DEVICE_FLAG_INT_RX);

        /* save on rx buffer */
        while (uart->uart_device->SR & USART_FLAG_RXNE)
        {
            rt_base_t level;

            /* disable interrupt */
            level = rt_hw_interrupt_disable();

            /* save character */

            if((&uart2_device )== device)
            {
                uartcount++;
                uart->int_rx->rx_buffer[uart->int_rx->save_index] = uart->uart_device->DR & 0xff;
                rt_device_write(&uart2_device, 0,&(uart->int_rx->rx_buffer[uart->int_rx->save_index]), 1);
                checksum = checksum^(uart->int_rx->rx_buffer[uart->int_rx->save_index]);
                switch (Uart2PackStatus )
                {
                case Get_sync_head:
                    if ((uart->int_rx->rx_buffer[uart->int_rx->save_index])== 0xaa)
                    {
                        checksum = uart->int_rx->rx_buffer[uart->int_rx->save_index];
                        Uart2PackStatus = Start_head_end;
                    }
                    else
                    {
                        uart->int_rx->getcmd = 0x7f;
                    }
                    break;
                case Start_head_end:
                    if((uart->int_rx->rx_buffer[uart->int_rx->save_index])== 0x75)
                    {
                        Uart2PackStatus = Get_the_Command;
                        //rt_device_write(&uart2_device, 0,&(uart->int_rx->rx_buffer[uart->int_rx->save_index]), 1);
                    }
                    else
                    {
                        uart->int_rx->getcmd = 0x7f;
                        Uart2PackStatus = Get_sync_head;
                    }
                    break;
                case Get_the_Command:
                    if(((uart->int_rx->rx_buffer[uart->int_rx->save_index]) <0x16)
                            ||((uart->int_rx->rx_buffer[uart->int_rx->save_index])>0x81
                               &&(uart->int_rx->rx_buffer[uart->int_rx->save_index])<0x85 )
                            ||((uart->int_rx->rx_buffer[uart->int_rx->save_index])>0x81
                               &&(uart->int_rx->rx_buffer[uart->int_rx->save_index])<0x85 )
                            ||((uart->int_rx->rx_buffer[uart->int_rx->save_index])>0xc1
                               &&(uart->int_rx->rx_buffer[uart->int_rx->save_index])<0xc5 ))
                    {
                        Uart2PackStatus = Get_the_lenth_high;
                    }
                    else
                    {
                        uart->int_rx->getcmd = 0x7f;
                        Uart2PackStatus = Get_sync_head;
                    }

                    break;
                case Get_the_lenth_high:
                    lenth = uart->int_rx->rx_buffer[uart->int_rx->save_index];
                    Uart2PackStatus = Get_the_lenth_low;
                    break;
                case Get_the_lenth_low:
                    lenth = ((lenth<<8)&0xff00)+(uart->int_rx->rx_buffer[uart->int_rx->save_index]);
                    Uart2PackStatus = Get_the_reserve;
                    break;
                case Get_the_reserve:
                    if (lenth != 0)
                    {
                        Uart2PackStatus = Get_the_data;
                    }
                    else
                        Uart2PackStatus = Get_the_checksum;
                    break;
                case Get_the_data:
                    if(lenth )
                        lenth--;
                    if(lenth == 0)
                        Uart2PackStatus = Get_the_checksum;

                    break;
                case Get_the_checksum:
                    if(checksum == 0)
                    {
//.........这里部分代码省略.........
开发者ID:mxx,项目名称:cabra,代码行数:101,代码来源:serial.c

示例15: _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;
//.........这里部分代码省略.........
开发者ID:Ksangho,项目名称:stm32bootloader,代码行数:101,代码来源:device_test.c


注:本文中的rt_device_t类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。