реклама на сайте
подробности

 
 
> Nios + STDIN Jtag-Uart, как пихнуть данные в консоль?
torik
сообщение Feb 8 2011, 17:06
Сообщение #1


Гуру
******

Группа: Свой
Сообщений: 2 113
Регистрация: 1-11-05
Пользователь №: 10 359



Из хела:
Цитата
Program output can appear in the Console view of the Nios II IDE. The Console view maintains a terminal I/O connection with a communication device, such as a JTAG UART, connected to the Nios II processor in the SOPC Builder system. When the Nios II program writes to stdout or stderr, the Console view displays the text. The Console view can also accept character input from the host keyboard, which is sent to the processor and read as stdin.

Т.е. вроде бы можно в консоли набрать данные и получить их в программе ниос через STDIN.

пишем
Код
char sss[5];
fgets (sss, 1, stdin);
if (sss != NULL)
   fprintf (stdout, "sss = %s", sss);


Пишу чё-нибудь в консоли, при этом sss всегда NULL. В bsp STDIN/STDOUT настроены на jtag-uart. fprintf работает без проблем.
ЧТо-то не так делаю?


--------------------
Быть. torizin-liteha@yandex.ru
Go to the top of the page
 
+Quote Post
 
Start new topic
Ответов
vadimuzzz
сообщение Feb 12 2011, 04:24
Сообщение #2


Гуру
******

Группа: Свой
Сообщений: 2 291
Регистрация: 21-07-05
Пользователь №: 6 988



хотя я погорячился. select - это системный вызов, без наличия оного в ОС указанный выше финт не прокатит. так что в вашем случае проще отключить jtag-uart от стандартного ввода/вывода и сделать свой обработчик прерывания (и обломаться с stdio.h, да). или сделать аналог системного вызова select. может проще ОС готовую воткнуть?

на всякий случай, в линуксе это выглядит примерно так:
CODE

#include <stdio.h>
#include <sys/select.h>
#include <sys/time.h>
#include <unistd.h>

int main()
{
//IOWR_ALTERA_AVALON_TIMER_CONTROL(TIMER_0_BASE,0);
fd_set rfds;
struct timeval tv;
int retval;
printf("Hello from Nios II!\n");
FD_ZERO(&rfds);
FD_SET(0, &rfds);
tv.tv_sec = 5;
tv.tv_usec = 0;
char sss[256];
while(1)
{
retval = select(1, &rfds, NULL, NULL, &tv);
if (retval == -1)
perror("select()");
else if (retval){
printf("Data is available now.\n");
tv.tv_sec = 5;
tv.tv_usec = 0;
FD_ZERO(&rfds);
scanf("%s",sss);
FD_SET(0, &rfds);
}
/* FD_ISSET(0, &rfds) will be true. */
else{
printf("No data within 5 seconds.\n");
tv.tv_sec = 5;
tv.tv_usec = 0;
FD_SET(0, &rfds);
}
}
return 0;
}
Go to the top of the page
 
+Quote Post



Reply to this topicStart new topic
1 чел. читают эту тему (гостей: 1, скрытых пользователей: 0)
Пользователей: 0

 


RSS Текстовая версия Сейчас: 20th July 2025 - 04:40
Рейтинг@Mail.ru


Страница сгенерированна за 0.01353 секунд с 7
ELECTRONIX ©2004-2016