Beispiel #1
0
/**
 * @ingroup finsh
 *
 * This function sets the input device of finsh shell.
 *
 * @param device_name the name of new input device.
 */
void finsh_set_device(const char *device_name)
{
    rt_device_t dev = RT_NULL;

    RT_ASSERT(shell != RT_NULL);
    dev = rt_device_find(device_name);
    if (dev == RT_NULL)
    {
        rt_kprintf("finsh: can not find device: %s\n", device_name);
        return;
    }

    /* check whether it's a same device */
    if (dev == shell->device) return;
    /* open this device and set the new device in finsh shell */
    if (rt_device_open(dev, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_INT_RX | \
                       RT_DEVICE_FLAG_STREAM) == RT_EOK)
    {
        if (shell->device != RT_NULL)
        {
            /* close old finsh device */
            rt_device_close(shell->device);
            rt_device_set_rx_indicate(shell->device, RT_NULL);
        }

        /* clear line buffer before switch to new device */
        memset(shell->line, 0, sizeof(shell->line));
        shell->line_curpos = shell->line_position = 0;

        shell->device = dev;
        rt_device_set_rx_indicate(dev, finsh_rx_ind);
    }
}
Beispiel #2
0
void uart1_rs485_set_device(void)
{
	    rt_device_t dev = RT_NULL;

    dev = rt_device_find("uart2");
	if (dev == RT_NULL)
    {
        rt_kprintf("finsh: can not find device: %s\n", "uart1");
        return;
    }

    /* check whether it's a same device */
    if (dev == uart1_dev_my->device) return;
		
    if (rt_device_open(dev, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_INT_RX |\
                       RT_DEVICE_FLAG_STREAM) == RT_EOK)
    {
        if (uart1_dev_my->device != RT_NULL)
        {
            /* close old finsh device */
            rt_device_close(uart1_dev_my->device);
            rt_device_set_rx_indicate(uart1_dev_my->device, RT_NULL);
        }

        uart1_dev_my->device = dev;
        rt_device_set_rx_indicate(dev, rs485_rx_ind);
    }
}
Beispiel #3
0
void finsh_lua(struct para *parameters)
{
    rt_err_t (*rx_indicate)(rt_device_t dev, rt_size_t size);

    rt_sem_init(&(dev4lua.sem), "luasem", 0, 0);

    /* save old rx_indicate */
    rx_indicate = dev4lua.device->rx_indicate;

    /* set new rx_indicate */
    rt_device_set_rx_indicate(dev4lua.device, lua_rx_ind);

    {
	    int argc = parameters->argc;
	    char **argv = parameters->argv;
	    /*
	    rt_kprintf("argc =%d, argv[1] =%d\n", argc, argv[1]);
	    while(1);
	    */
	    /* run lua interpreter */
	    lua_main(argc, argv);
    }
    if (parameters->argc > 1)
	    rt_free(parameters->argv[1]);
    rt_free(parameters);

    /* recover old rx_indicate */
    rt_device_set_rx_indicate(dev4lua.device, rx_indicate);
}
Beispiel #4
0
/**
 * @ingroup finsh
 *
 * This function sets the input device of finsh shell.
 *
 * @param device_name the name of new input device.
 */
void finsh_set_device(const char* device_name)
{
	rt_device_t dev = RT_NULL;

	RT_ASSERT(shell != RT_NULL);
	dev = rt_device_find(device_name);
	if (dev == RT_NULL)
	{
		rt_kprintf("finsh: can not find device: %s\n", device_name);
		return;
	}

	/* check whether it's a same device */
	if (dev == shell->device) return;
	/* open this device and set the new device in finsh shell */
	if (rt_device_open(dev, RT_DEVICE_OFLAG_RDWR) == RT_EOK)
	{
		if (shell->device != RT_NULL)
		{
			/* close old finsh device */
			rt_device_close(shell->device);
            rt_device_set_rx_indicate(dev, RT_NULL);
		}

		shell->device = dev;
		rt_device_set_rx_indicate(dev, finsh_rx_ind);
	}
}
Beispiel #5
0
void rcu_uart_set_device(char* uartStr)
{
    static int isInited=0;
    rt_device_t dev = RT_NULL;
                                                        
    if(isInited==1)
        return;

    dev = rt_device_find(uartStr);
    if (dev == RT_NULL)
    {
        hclog("finsh: can not find device: %s\n", uartStr);
        return;
    }
    if(dev == rcuDevice)
        return;

    /* open this device and set the new device */
    if (rt_device_open(dev, RT_DEVICE_OFLAG_RDWR) == RT_EOK)
    {
        if (rcuDevice != RT_NULL)
        {
            /* close old  device */
            rt_device_close(rcuDevice);
            rt_device_set_rx_indicate(dev, RT_NULL);
        }
        rcuDevice = dev;
        rt_device_set_rx_indicate(dev, rcu_rx_ind);
    }
    isInited = 1;
                        
}
Beispiel #6
0
//串口接收数据线程
void uart_thread_entry(void* parameter)
{
    char ch;

    device = rt_device_find("uart3");
    if(device != RT_NULL)
    {
        rt_device_open(device, RT_DEVICE_OFLAG_RDWR);
			
        rt_kprintf("open device uart3 succeed!\r\n");
				rt_sem_init(&rx_sem, "uartrx", 0, 0);
				
				rt_device_set_rx_indicate(device, uart_rx_ind);
				
        while(1)
        {
            if (rt_sem_take(&rx_sem, RT_WAITING_FOREVER) != RT_EOK) //默认情况线程挂起,有数据时,系统会调用uart_rx_ind函数,释放信号量,线程得以执行
							continue;
						while(rt_device_read(device, 0, &ch, 1) == 1)
            {
                uartRecvProc(ch);
            }
				}
    }
}
Beispiel #7
0
void usart_dev_init(void)
{
    dev_uart1 = rt_device_find("uart1");
    if( dev_uart1 == RT_NULL )
    {
        rt_kprintf("uart1 not found!!\n");
        return;
    }
    dev_uart2 = rt_device_find("uart2");
    if( dev_uart2 == RT_NULL )
    {
        rt_kprintf("uart2 not found!!\n");
        return;
    }
    rt_device_set_rx_indicate(dev_uart1,usart_rx_indicate);
    rt_device_set_rx_indicate(dev_uart2,usart_rx_indicate);
    rt_device_set_tx_complete(dev_uart1,usart0_tx_complete);
    rt_device_set_tx_complete(dev_uart2,usart1_tx_complete);
    rt_device_open(dev_uart1,RT_DEVICE_OFLAG_RDWR);
    rt_device_open(dev_uart2,RT_DEVICE_OFLAG_RDWR);
}
Beispiel #8
0
rt_err_t remote_init(const char * uart_name)
{
	uart = rt_device_find(uart_name);

	RT_ASSERT(uart != RT_NULL);

	rt_device_set_rx_indicate(uart, byte_recv);

	rt_device_open(uart, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_STREAM | RT_DEVICE_FLAG_INT_RX);
	
	rt_sem_init(&remote_sem,"remote",0,RT_IPC_FLAG_FIFO);
	
	remote_thread = rt_thread_create("remote",remote_thread_entry,RT_NULL,512,9,3);

	rt_thread_startup(remote_thread);
	
	return RT_EOK;
}
Beispiel #9
0
void rt_can_thread_entry(void* parameter)
{
    struct rt_can_msg msg;
    struct can_app_struct* canpara = (struct can_app_struct*) parameter;
    rt_device_t candev;

    candev = rt_device_find(canpara->name);
    RT_ASSERT(candev);
    rt_sem_init(&canpara->sem, canpara->name, 0, RT_IPC_FLAG_FIFO);
    rt_device_open(candev, (RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_INT_TX));
    rt_device_control(candev,RT_CAN_CMD_SET_FILTER,canpara->filter);
    rt_device_set_rx_indicate(candev, lpccanind);
    while(1) {
        rt_sem_take(&canpara->sem, RT_WAITING_FOREVER);
        while (rt_device_read(candev, 0, &msg, sizeof(msg)) == sizeof(msg)) {
            rt_device_write(candev, 0, &msg, sizeof(msg));
        }
    }
}
Beispiel #10
0
FtkSource* ftk_source_input_create(const char* filename, FtkOnEvent on_event, void* user_data)
{
    FtkSource* thiz = (FtkSource*)FTK_ZALLOC(sizeof(FtkSource) + sizeof(PrivInfo));
    rt_device_t device = NULL;

    if (thiz != NULL)
    {
        DECL_PRIV(thiz, priv);

        thiz->get_fd   = ftk_source_input_get_fd;
        thiz->check	= ftk_source_input_check;
        thiz->dispatch = ftk_source_input_dispatch;
        thiz->destroy  = ftk_source_input_destroy;

        thiz->ref = 1;

        priv->device = rt_device_find(filename);
        if (priv->device == NULL)
        {
            FTK_ZFREE(thiz, sizeof(thiz) + sizeof(PrivInfo));
            return NULL;
        }
        if (rt_device_open(priv->device, RT_DEVICE_OFLAG_RDONLY) != RT_EOK)
        {
            FTK_ZFREE(thiz, sizeof(thiz) + sizeof(PrivInfo));
            return NULL;
        }

        priv->device->user_data = (void *)thiz;
        rt_device_set_rx_indicate(priv->device, ftk_source_input_rx_ind);

        priv->fd = ftk_rtthread_select_fd_alloc();

        priv->on_event  = on_event;
        priv->user_data = user_data;

        ftk_keymap_init();
        ftk_logd("%s: %d=%s priv->user_data=%p\n", __func__, priv->fd, filename, priv->user_data);
    }

    return thiz;
}
/*GPRS端口初始化,打开设备,注册回调函数*/
rt_bool_t sysconfig(void)
{
  gprs_device = rt_device_find("uart3");
  
  if (gprs_device != RT_NULL)    
  {
    rt_kprintf("\r\n GPRS port initialized!\r\n");
    GPRSPortConfig();
    /* 设置回调函数及打开设备*/
    rt_device_set_rx_indicate(gprs_device, uart_input);
    rt_device_open(gprs_device, RT_DEVICE_OFLAG_RDWR);  
  }
  else
  {
    rt_kprintf("\r\n GPRS port not find !\r\n");
    return RT_FALSE;
  }
  /*GPRS串口打开后,初始化串口接收事件*/
  rt_event_init(&rev_event, "rev_ev", RT_IPC_FLAG_FIFO);
  return RT_TRUE;
}
void Commander::Init(const char *name)
{
	rt_thread_t recv_thread;
	dev  = rt_device_find(name);
	if(dev == RT_NULL)
  {
	 rt_kprintf("can not find %s!\n", name);
		return ;
	}
	recv_event = rt_event_create("cmdrecv",RT_IPC_FLAG_FIFO);
	if(recv_event==RT_NULL)
  {
	 rt_kprintf("commander recv event create error!\n");
		return ;
	}
	rt_device_set_rx_indicate(dev,data_rx_callback);
	rt_device_open(dev,RT_DEVICE_FLAG_INT_RX|RT_DEVICE_FLAG_RDWR);
	recv_thread = rt_thread_create("cmd_recv",recv_thread_entry,RT_NULL,1024,12,5);
	if(recv_thread != RT_NULL)
		rt_thread_startup(recv_thread);
}
Beispiel #13
0
/**
 * @ingroup finsh
 *
 * This function sets the input device of finsh shell.
 *
 * @param device_name the name of new input device.
 */
void finsh_set_device(const char* device_name)
{
	rt_device_t dev = RT_NULL;

	RT_ASSERT(shell != RT_NULL);
	dev = rt_device_find(device_name);
	if (dev != RT_NULL && rt_device_open(dev, RT_DEVICE_OFLAG_RDWR) == RT_EOK)
	{
		if (shell->device != RT_NULL)
		{
			/* close old finsh device */
			rt_device_close(shell->device);
		}

		shell->device = dev;
		rt_device_set_rx_indicate(dev, finsh_rx_ind);
	}
	else
	{
		rt_kprintf("finsh: can not find device:%s\n", device_name);
	}
}
Beispiel #14
0
void LCDPANELProcess_thread_entry(void* parameter)
{
	struct rx_msg msg;
    rt_device_t device;

	// 从RT系统中获取串口1设备
    device = rt_device_find("uart1");
    if (device != RT_NULL)
    {
    	/* 设置回调函数及打开设备*/
		rt_device_set_rx_indicate(device, uart_input);
		// 以读写方式打开设备
        rt_device_open(device, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_INT_RX);
    }
	rt_thread_delay(50);									//* Release 1 second cpu time solt for other module init function */
	IWDG_ReloadCounter();
	rt_thread_delay(50);

    while (1)
    {
		IWDG_ReloadCounter();
		MessageTX[7]=0X01;
        rt_thread_delay( RT_TICK_PER_SECOND/20 ); /* sleep 0.5 second and switch to other thread */

		while (rt_mq_recv(&rx_mq, &msg, sizeof(struct rx_msg), 50) == RT_EOK)
		{
			rt_uint32_t rx_length;
			test1++;
			rx_length = (sizeof(QueryLCDRxBuf) - 1) > msg.size ? msg.size : sizeof(QueryLCDRxBuf) - 1;
			/* 读取消息*/
			rx_length = rt_device_read(msg.dev, 0, &QueryLCDRxBuf[0], rx_length);
			if(QueryLCDRxBuf[0] != 0xaa)
			{
				break;
			}
			while (rx_length < 10)
			{
				if (rt_mq_recv(&rx_mq, &msg, sizeof(struct rx_msg), 5) == RT_EOK)
				{
					rt_device_read(msg.dev, 0, &QueryLCDRxBuf[rx_length++], 1);
				}
				else
				{
					break;
				}
			}
			if ((rx_length == 10) && (QueryLCDRxBuf[9] == 0xcc))
			{
				QueryLCDRxBuf[rx_length] = '\0';

				if((QueryLCDRxBuf[1]==0x01)&&(StartupMark==1))//LCD启动,而且车启动时
				{
					if((QueryLCDRxBuf[2]==0x01)|(GSM_flag==1))//LCD手动模式开,且GSM有信号时
					{
//						MessageTX[12] = rxlen;
						MessageTX[13] = 0x03;
						MD=0; //开风机
						MessageTX[11]=0x01;//风机启动状态
						fwsRlyWindOpen(RLY_WIND_MD_FLAG,FELAY_DELAY_FOREVER);
					}
	    			else if((QueryLCDRxBuf[2]==0x00)&(GSM_flag==0))//LCD手动模式关,且GSM有信号时
    				{
//    					MessageTX[12] = rxlen;
    					MessageTX[13] = 0x04;
    					MD=1;//关风机
						fwsRlyWindClose(RLY_WIND_MD_FLAG);
	    			}
	    			else
	    			{
//						MessageTX[12] = rxlen;
						MessageTX[13] = 0x02;
	    			}
    			}
    			else if((QueryLCDRxBuf[1]==0x00)||(StartupMark==0))//LCD关闭,而且车熄火
    			{
					MessageTX[12] = StartupMark;
    				MessageTX[13] = 0x05;
					MD=1; //关风机
					if(StartupMark==0)
						fwsRlyWindClose(RLY_WIND_ALLOFF_FLAG);
					else
						fwsRlyWindClose(RLY_WIND_MD_FLAG);
    			}
    			else
    			{
//					MessageTX[12] = rxlen;
					MessageTX[13] = 0x06;
				}
//				if(QueryLCDRxBuf[7]==0x01)//自动模式时
//				{
//    			     MessageTX[12]=QueryLCDRxBuf[5];
//    			     MessageTX[13]=QueryLCDRxBuf[6];
//    	    	}
			}
			else
			{
				break;
			}
			rt_device_write(msg.dev, 0, &MessageTX[0], SENDTO_LCD_LEN);
		}
    }
}
Beispiel #15
0
void finsh_thread_entry(void* parameter)
{
    char ch;

	/* normal is echo mode */
	shell->echo_mode = 1;

    finsh_init(&shell->parser);
	rt_kprintf(FINSH_PROMPT);

	/* set console device as shell device */
	shell->device = rt_console_get_device();
	if (shell->device != RT_NULL)
	{
		rt_device_open(shell->device, RT_DEVICE_OFLAG_RDWR);
		rt_device_set_rx_indicate(shell->device, finsh_rx_ind);
	}

	while (1)
	{
		/* wait receive */
		if (rt_sem_take(&shell->rx_sem, RT_WAITING_FOREVER) != RT_EOK) continue;

		/* read one character from device */
		while (rt_device_read(shell->device, 0, &ch, 1) == 1)
		{
			/*
			 * handle control key
			 * up key  : 0x1b 0x5b 0x41
			 * down key: 0x1b 0x5b 0x42
			 * right key:0x1b 0x5b 0x43
			 * left key: 0x1b 0x5b 0x44
			 */
			if (ch == 0x1b)
			{
				shell->stat = WAIT_SPEC_KEY;
				continue;
			}
			else if (shell->stat == WAIT_SPEC_KEY)
			{
				if (ch == 0x5b)
				{
					shell->stat = WAIT_FUNC_KEY;
					continue;
				}

				shell->stat = WAIT_NORMAL;
			}
			else if (shell->stat == WAIT_FUNC_KEY)
			{
				shell->stat = WAIT_NORMAL;

				if (ch == 0x41) /* up key */
				{
#ifdef FINSH_USING_HISTORY
					/* prev history */
					if (shell->current_history > 0)
						shell->current_history --;
					else
					{
						shell->current_history = 0;
						continue;
					}

					/* copy the history command */
					memcpy(shell->line, &shell->cmd_history[shell->current_history][0],
						   FINSH_CMD_SIZE);
					shell->line_curpos = shell->line_position = strlen(shell->line);
					finsh_handle_history(shell);
#endif
					continue;
				}
				else if (ch == 0x42) /* down key */
				{
#ifdef FINSH_USING_HISTORY
					/* next history */
					if (shell->current_history < shell->history_count - 1)
						shell->current_history ++;
					else
					{
						/* set to the end of history */
						if (shell->history_count != 0)
							shell->current_history = shell->history_count - 1;
						else
							continue;
					}

					memcpy(shell->line, &shell->cmd_history[shell->current_history][0],
						   FINSH_CMD_SIZE);
					shell->line_curpos = shell->line_position = strlen(shell->line);
					finsh_handle_history(shell);
#endif
					continue;
				}
				else if (ch == 0x44) /* left key */
				{
					if (shell->line_curpos)
					{
						rt_kprintf("\b");
						shell->line_curpos --;
					}

					continue;
				}
				else if (ch == 0x43) /* right key */
				{
					if (shell->line_curpos < shell->line_position)
					{
						rt_kprintf("%c", shell->line[shell->line_curpos]);
						shell->line_curpos ++;
					}

					continue;
				}

			}

			/* handle CR key */
			if (ch == '\r')
			{
				char next;

				if (rt_device_read(shell->device, 0, &next, 1) == 1)
					ch = next;
				else ch = '\r';
			}
			/* handle tab key */
			else if (ch == '\t')
			{
				int i;
				/* move the cursor to the beginning of line */
				for (i = 0; i < shell->line_curpos; i++)
					rt_kprintf("\b");

				/* auto complete */
				finsh_auto_complete(&shell->line[0]);
				/* re-calculate position */
				shell->line_curpos = shell->line_position = strlen(shell->line);

				continue;
			}
			/* handle backspace key */
			else if (ch == 0x7f || ch == 0x08)
			{
				/* note that shell->line_curpos >= 0 */
				if (shell->line_curpos == 0)
					continue;

				shell->line_position--;
				shell->line_curpos--;

				if (shell->line_position > shell->line_curpos)
				{
					int i;

					rt_memmove(&shell->line[shell->line_curpos],
							   &shell->line[shell->line_curpos + 1],
							   shell->line_position - shell->line_curpos);
					shell->line[shell->line_position] = 0;

					rt_kprintf("\b%s  \b", &shell->line[shell->line_curpos]);

					/* move the cursor to the origin position */
					for (i = shell->line_curpos; i <= shell->line_position; i++)
						rt_kprintf("\b");
				}
				else
				{
					rt_kprintf("\b \b");
					shell->line[shell->line_position] = 0;
				}

				continue;
			}

			/* handle end of line, break */
			if (ch == '\r' || ch == '\n')
			{
#ifdef FINSH_USING_MSH
				if (msh_is_used() == RT_TRUE && shell->line_position != 0)
				{
					rt_kprintf("\n");
					msh_exec(shell->line, shell->line_position);
					#ifdef FINSH_USING_HISTORY
					finsh_push_history(shell);
					#endif
				}
				else
#endif
				{
					/* add ';' and run the command line */
					shell->line[shell->line_position] = ';';

					#ifdef FINSH_USING_HISTORY
					finsh_push_history(shell);
					#endif

					if (shell->line_position != 0) finsh_run_line(&shell->parser, shell->line);
					else rt_kprintf("\n");
				}

				rt_kprintf(FINSH_PROMPT);
				memset(shell->line, 0, sizeof(shell->line));
				shell->line_curpos = shell->line_position = 0;

				break;
			}

			/* it's a large line, discard it */
			if (shell->line_position >= FINSH_CMD_SIZE)
				shell->line_position = 0;

			/* normal character */
			if (shell->line_curpos < shell->line_position)
			{
				int i;

				rt_memmove(&shell->line[shell->line_curpos + 1],
						   &shell->line[shell->line_curpos],
						   shell->line_position - shell->line_curpos);
				shell->line[shell->line_curpos] = ch;
				if (shell->echo_mode)
					rt_kprintf("%s", &shell->line[shell->line_curpos]);

				/* move the cursor to new position */
				for (i = shell->line_curpos; i < shell->line_position; i++)
					rt_kprintf("\b");
			}
			else
			{
				shell->line[shell->line_position] = ch;
				rt_kprintf("%c", ch);
			}

			ch = 0;
			shell->line_position ++;
			shell->line_curpos++;
		} /* end of device read */
	}
}
Beispiel #16
0
void init_sys_485(void)
{

//	rt_sem_init(&uart485_1_rx_byte_sem, "u485-1", 0, RT_IPC_FLAG_PRIO);
//	rt_sem_init(&uart485_2_rx_byte_sem, "u485-2", 0, RT_IPC_FLAG_PRIO);
//	rt_sem_init(&uart485_3_rx_byte_sem, "u485-3", 0, RT_IPC_FLAG_PRIO);

	rt_event_init(&em_protocol_data_event_set, "tl16_eve", RT_IPC_FLAG_PRIO);

	rs485_recv_buf= (rt_uint8_t *)rt_malloc(FRAME_485_LEN);
	if(rs485_recv_buf == RT_NULL) {
		rs485_info(("func:%s(), line:%d malloc fail\n",__FUNCTION__, __LINE__));
		return;		
	}
	rt_memset(rs485_recv_buf, 0, FRAME_485_LEN);

	dev_485_1 = rt_device_find(UART_485_1_DEV);
	if (dev_485_1 != RT_NULL && rt_device_open(dev_485_1, RT_DEVICE_OFLAG_RDWR) == RT_EOK) {
		rs485_info(("open device:%s succ\n", UART_485_1_DEV));
		rt_device_set_rx_indicate(dev_485_1, uart485_1_rx_ind);
	} else {
		rs485_info(("can not find device:%s\n", UART_485_1_DEV));
//		goto err_ret;
	}

	dev_485_2 = rt_device_find(UART_485_2_DEV);
	if (dev_485_2 != RT_NULL && rt_device_open(dev_485_2, RT_DEVICE_OFLAG_RDWR) == RT_EOK) {
		rs485_info(("open device:%s succ\n", UART_485_2_DEV));
		rt_device_set_rx_indicate(dev_485_2, uart485_2_rx_ind);
	} else {
		rs485_info(("can not find device:%s\n", UART_485_2_DEV));
//		goto err_ret;
	}

	dev_485_3 = rt_device_find(UART_485_3_DEV);
	if (dev_485_3 != RT_NULL && rt_device_open(dev_485_3, RT_DEVICE_OFLAG_RDWR) == RT_EOK) {
		rs485_info(("open device:%s succ\n", UART_485_3_DEV));
		rt_device_set_rx_indicate(dev_485_3, uart485_3_rx_ind);
	} else {
		rs485_info(("can not find device:%s\n", UART_485_3_DEV));
//		goto err_ret;
	}

	dev_485_tl16_1 = rt_device_find(UART_485_TL16_1_DEV);
	if (dev_485_tl16_1 != RT_NULL && rt_device_open(dev_485_tl16_1, RT_DEVICE_OFLAG_RDWR) == RT_EOK) {
		rs485_info(("open device:%s succ\n", UART_485_TL16_1_DEV));
		rt_device_set_rx_indicate(dev_485_tl16_1, uart485_tl16_1_rx_ind);
	} else {
		rs485_info(("can not find device:%s\n", UART_485_TL16_1_DEV));
//		goto err_ret;
	}

	dev_485_tl16_2 = rt_device_find(UART_485_TL16_2_DEV);
	if (dev_485_tl16_2 != RT_NULL && rt_device_open(dev_485_tl16_2, RT_DEVICE_OFLAG_RDWR) == RT_EOK) {
		rs485_info(("open device:%s succ\n", UART_485_TL16_2_DEV));
		rt_device_set_rx_indicate(dev_485_tl16_2, uart485_tl16_2_rx_ind);
	} else {
		rs485_info(("can not find device:%s\n", UART_485_TL16_2_DEV));
//		goto err_ret;
	}

	dev_485_tl16_3 = rt_device_find(UART_485_TL16_3_DEV);
	if (dev_485_tl16_3 != RT_NULL && rt_device_open(dev_485_tl16_3, RT_DEVICE_OFLAG_RDWR) == RT_EOK) {
		rs485_info(("open device:%s succ\n", UART_485_TL16_3_DEV));
		rt_device_set_rx_indicate(dev_485_tl16_3, uart485_tl16_3_rx_ind);
	} else {
		rs485_info(("can not find device:%s\n", UART_485_TL16_3_DEV));
//		goto err_ret;
	}

	dev_485_tl16_4 = rt_device_find(UART_485_TL16_4_DEV);
	if (dev_485_tl16_4 != RT_NULL && rt_device_open(dev_485_tl16_4, RT_DEVICE_OFLAG_RDWR) == RT_EOK) {
		rs485_info(("open device:%s succ\n", UART_485_TL16_4_DEV));
		rt_device_set_rx_indicate(dev_485_tl16_4, uart485_tl16_4_rx_ind);
	} else {
		rs485_info(("can not find device:%s\n", UART_485_TL16_4_DEV));
//		goto err_ret;
	}

	dev_485_tl16_5 = rt_device_find(UART_485_TL16_5_DEV);
	if (dev_485_tl16_5 != RT_NULL && rt_device_open(dev_485_tl16_5, RT_DEVICE_OFLAG_RDWR) == RT_EOK) {
		rs485_info(("open device:%s succ\n", UART_485_TL16_5_DEV));
		rt_device_set_rx_indicate(dev_485_tl16_5, uart485_tl16_5_rx_ind);
	} else {
		rs485_info(("can not find device:%s\n", UART_485_TL16_5_DEV));
//		goto err_ret;
	}

	dev_485_tl16_6 = rt_device_find(UART_485_TL16_6_DEV);
	if (dev_485_tl16_6 != RT_NULL && rt_device_open(dev_485_tl16_6, RT_DEVICE_OFLAG_RDWR) == RT_EOK) {
		rs485_info(("open device:%s succ\n", UART_485_TL16_6_DEV));
		rt_device_set_rx_indicate(dev_485_tl16_6, uart485_tl16_6_rx_ind);
	} else {
		rs485_info(("can not find device:%s\n", UART_485_TL16_6_DEV));
//		goto err_ret;
	}

	dev_485_tl16_7 = rt_device_find(UART_485_TL16_7_DEV);
	if (dev_485_tl16_7 != RT_NULL && rt_device_open(dev_485_tl16_7, RT_DEVICE_OFLAG_RDWR) == RT_EOK) {
		rs485_info(("open device:%s succ\n", UART_485_TL16_7_DEV));
		rt_device_set_rx_indicate(dev_485_tl16_7, uart485_tl16_7_rx_ind);
	} else {
		rs485_info(("can not find device:%s\n", UART_485_TL16_7_DEV));
//		goto err_ret;
	}

	dev_485_tl16_8 = rt_device_find(UART_485_TL16_8_DEV);
	if (dev_485_tl16_8 != RT_NULL && rt_device_open(dev_485_tl16_8, RT_DEVICE_OFLAG_RDWR) == RT_EOK) {
		rs485_info(("open device:%s succ\n", UART_485_TL16_8_DEV));
		rt_device_set_rx_indicate(dev_485_tl16_8, uart485_tl16_8_rx_ind);
	} else {
		rs485_info(("can not find device:%s\n", UART_485_TL16_8_DEV));
//		goto err_ret;
	}

	return;

//err_ret:
//	rt_free(rs485_recv_buf);
//	return;
}
Beispiel #17
0
static void rt_test_485_entry(void* parameter)
{
	rt_device_t dev_485_1;
	rt_device_t dev_485_2;
	rt_device_t dev_485_3;

	rt_size_t read_cnt;

	unsigned char tx_ch = 0;
	unsigned char rx_ch = 0;
	unsigned char rx_buf[4];

	rt_sem_init(&uart485_1_rx_msg_sem, "u485-1", 0, RT_IPC_FLAG_PRIO);
	rt_sem_init(&uart485_2_rx_msg_sem, "u485-2", 0, RT_IPC_FLAG_PRIO);
	rt_sem_init(&uart485_3_rx_msg_sem, "u485-3", 0, RT_IPC_FLAG_PRIO);
#if !EM_ALL_TYPE_BASE
	uart485_mb = rt_mb_create("485_mb", 1, RT_IPC_FLAG_FIFO);
	if (RT_NULL == uart485_mb) {
		printf_syn("func:%s(), line:%d malloc fail\n",__FUNCTION__, __LINE__);
		return;
	}
#endif
	dev_485_1 = rt_device_find(UART_485_1_DEV);
	if (dev_485_1 != RT_NULL && rt_device_open(dev_485_1, RT_DEVICE_OFLAG_RDWR) == RT_EOK) {
		printf_syn("rt_test_485_entry open device:%s succ\n", UART_485_1_DEV);
		rt_device_set_rx_indicate(dev_485_1, uart485_1_rx_ind);
	} else {
		printf_syn("rt_test_485_entry can not find device:%s\n", UART_485_1_DEV);
		return;
	}

	dev_485_2 = rt_device_find(UART_485_2_DEV);
	if (dev_485_2 != RT_NULL && rt_device_open(dev_485_2, RT_DEVICE_OFLAG_RDWR) == RT_EOK) {
		printf_syn("rt_test_485_entry open device:%s succ\n", UART_485_2_DEV);
		rt_device_set_rx_indicate(dev_485_2, uart485_2_rx_ind);
	} else {
		printf_syn("rt_test_485_entry can not find device:%s\n", UART_485_2_DEV);
		return;
	}

	dev_485_3 = rt_device_find(UART_485_3_DEV);
	if (dev_485_3 != RT_NULL && rt_device_open(dev_485_3, RT_DEVICE_OFLAG_RDWR) == RT_EOK) {
		printf_syn("rt_test_485_entry open device:%s succ\n", UART_485_3_DEV);
		rt_device_set_rx_indicate(dev_485_3, uart485_3_rx_ind);
	} else {
		printf_syn("rt_test_485_entry can not find device:%s\n", UART_485_3_DEV);
		return;
	}

	while (1) {
#if 0
		tx_en_rev_disable_485_1();
#else
#if 0
		int rx_cnt, err_cnt;
		rt_err_t err;
		int i;

		rx_cnt = 0;
		err_cnt = 0;

		printf_syn("send cmd: ");
		for (i=0; i<sizeof(cmd_485_seq); ++i)
			printf_syn("%02x ", cmd_485_seq[i]);
		printf_syn("\n");

		//rt_enter_critical();
		tx_en_rev_disable_485_2();
		//rt_thread_delay(2);
		dev_485_2->write(dev_485_2, 0, cmd_485_seq, sizeof(cmd_485_seq));
		//rt_thread_delay(1);
		wait_usartx_send_over(USART3);
			
		tx_disable_rev_en_485_2();

		//rt_exit_critical();

		printf_syn("485-2 485 cmd had send over\n");

		while (rx_cnt<23 && err_cnt<2) {
			if (RT_EOK == (err=rt_sem_take(&uart485_2_rx_msg_sem, WAIT_RX_MSG_TIMEOUT))) {
				while (1 == dev_485_2->read(dev_485_2, 0, &rx_ch, 1)) {
					++rx_cnt;
					printf_syn("485-2 recv ind[%3d]:0x%2x\n", rx_cnt, rx_ch);
				}
			} else {
				printf_syn("485-2 recv error(%d)\n", err);
				++err_cnt;
			}
		}

		rt_thread_delay(get_ticks_of_ms(5 * 1000));

#else
		tx_en_rev_disable_485_1();
		rt_thread_delay(2);
		printf_syn("485-1 send:%d\n", tx_ch);
		dev_485_1->write(dev_485_1, 0, &tx_ch, 1);
		rt_thread_delay(2);
		tx_disable_rev_en_485_1();
#if 0
#if 0
		if (RT_EOK == rt_sem_take(&uart485_3_rx_msg_sem, WAIT_RX_MSG_TIMEOUT)) {
			read_cnt = dev_485_3->read(dev_485_3, 0, rx_buf, sizeof(rx_buf));
			if (read_cnt != 0) {
				rx_ch = rx_buf[read_cnt - 1];
			} else {
				rx_ch = 0;
				printf_syn("485-3 recv error(%d)\n", rt_get_errno());
			}

			printf_syn("485-3 recv:%d, read_cnt:%d\n", rx_ch, read_cnt);

			rt_thread_delay(5);

			tx_en_rev_disable_485_3();
			rt_thread_delay(2);
			printf_syn("485-3 send:%d\n", rx_ch);
			dev_485_3->write(dev_485_3, 0, &rx_ch, 1);
			rt_thread_delay(2);
			tx_disable_rev_en_485_3();

		} else {
			printf_syn("485-3 recv error\n");
		}
#else
		if (RT_EOK == rt_sem_take(&uart485_2_rx_msg_sem, WAIT_RX_MSG_TIMEOUT)) {
			read_cnt = dev_485_2->read(dev_485_2, 0, rx_buf, sizeof(rx_buf));
			if (read_cnt != 0) {
				rx_ch = rx_buf[read_cnt - 1];
			} else {
				rx_ch = 0;
				printf_syn("485-2 recv error(%d)\n", rt_get_errno());
			}

			printf_syn("485-2 recv:%d, read_cnt:%d\n", rx_ch, read_cnt);

			rt_thread_delay(5);

			tx_en_rev_disable_485_2();
			rt_thread_delay(2);
			printf_syn("485-2 send:%d\n", rx_ch);
			dev_485_2->write(dev_485_2, 0, &rx_ch, 1);
			rt_thread_delay(2);
			tx_disable_rev_en_485_2();

		} else {
			printf_syn("485-2 recv error\n");
		}

#endif
#else
		if (tx_ch & 0x01) {
			if (RT_EOK == rt_sem_take(&uart485_3_rx_msg_sem, WAIT_RX_MSG_TIMEOUT)) {
				read_cnt = dev_485_3->read(dev_485_3, 0, rx_buf, sizeof(rx_buf));
				if (read_cnt != 0) {
					rx_ch = rx_buf[read_cnt - 1];
				} else {
					rx_ch = 0;
					printf_syn("485-3 recv error(%d)\n", rt_get_errno());
				}

				printf_syn("485-3 recv:%d, read_cnt:%d\n", rx_ch, read_cnt);

				rt_thread_delay(5);

				tx_en_rev_disable_485_3();
				rt_thread_delay(2);
				printf_syn("485-3 send:%d\n", rx_ch);
				dev_485_3->write(dev_485_3, 0, &rx_ch, 1);
				rt_thread_delay(2);
				tx_disable_rev_en_485_3();

			} else {
				printf_syn("485-3 recv error\n");
			}
		} else {
			if (RT_EOK == rt_sem_take(&uart485_2_rx_msg_sem, WAIT_RX_MSG_TIMEOUT)) {
				read_cnt = dev_485_2->read(dev_485_2, 0, rx_buf, sizeof(rx_buf));
				if (read_cnt != 0) {
					rx_ch = rx_buf[read_cnt - 1];
				} else {
					rx_ch = 0;
					printf_syn("485-2 recv error(%d)\n", rt_get_errno());
				}

				printf_syn("485-2 recv:%d, read_cnt:%d\n", rx_ch, read_cnt);

				rt_thread_delay(5);

				tx_en_rev_disable_485_2();
				rt_thread_delay(2);
				printf_syn("485-2 send:%d\n", rx_ch);
				dev_485_2->write(dev_485_2, 0, &rx_ch, 1);
				rt_thread_delay(2);
				tx_disable_rev_en_485_2();

			} else {
				printf_syn("485-2 recv error\n");
			}
		}
#endif
		if (RT_EOK == rt_sem_take(&uart485_1_rx_msg_sem, WAIT_RX_MSG_TIMEOUT)) {
			dev_485_1->read(dev_485_1, 0, &rx_ch, 1);
			printf_syn("485-1 recv echo:%d\n\n", rx_ch);

		} else {
			printf_syn("485-1 recv echo error\n\n");
		}

		rt_thread_delay(get_ticks_of_ms(1*1000));
		++tx_ch;

#endif
#endif
	} /* while(1) */

	return;
}