• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ rt_device_t类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: rt_hw_usart_rx_isr

/***************************************************************************//**
 * @brief
 *  USART RX data valid interrupt handler
 *
 * @details
 *
 * @note
 *  9-bit SPI mode has not implemented yet and SPI slave mode is untested
 *
 * @param[in] dev
 *  Pointer to device descriptor
 ******************************************************************************/
void rt_hw_usart_rx_isr(rt_device_t dev)
{
    struct efm32_usart_device_t     *usart;
    struct efm32_usart_int_mode_t   *int_rx;
    rt_uint32_t                     flag;

    /* interrupt mode receive */
    RT_ASSERT(dev->flag & RT_DEVICE_FLAG_INT_RX);
    usart = (struct efm32_usart_device_t *)(dev->user_data);
    int_rx = (struct efm32_usart_int_mode_t *)(usart->rx_mode);
    RT_ASSERT(int_rx->data_ptr != RT_NULL);
#if defined(UART_PRESENT)
    if (usart->state & USART_STATE_ASYNC_ONLY)
    {
        flag = UART_STATUS_RXDATAV;
    }
    else
#endif
    {
        flag = USART_STATUS_RXDATAV;
    }

    /* Set status */
    usart->state |= USART_STATE_RX_BUSY;

    /* save into rx buffer */
    while (usart->usart_device->STATUS & flag)
    {
        rt_base_t level;

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

        /* save character */
        int_rx->data_ptr[int_rx->save_index] = \
                                               (rt_uint8_t)(usart->usart_device->RXDATA & 0xFFUL);
        int_rx->save_index ++;
        if (int_rx->save_index >= USART_RX_BUFFER_SIZE)
            int_rx->save_index = 0;

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

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

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

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

        dev->rx_indicate(dev, rx_length);
    }
}
开发者ID:hduffddybz,项目名称:rt-thread,代码行数:79,代码来源:drv_usart.c


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


示例18: 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;
}
开发者ID:eyyhappy,项目名称:network-radio,代码行数:22,代码来源:mass_mal.c


示例19: 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 )
//.........这里部分代码省略.........
开发者ID:visitor83,项目名称:fighting_stm32,代码行数:101,代码来源:apptasks.c


示例20: 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);
        }
    }
}
开发者ID:visitor83,项目名称:fighting_stm32,代码行数:77,代码来源:apptasks.c



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ rule类代码示例发布时间:2022-05-31
下一篇:
C++ rr_dev类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap