Hi, I am having some trouble with the following code
int i
scanf ("%d", &i);
-- Throws an error--> parse error before '&'token
Since somehow it is not recognizing the pointer, I tried
int i
scanf ("%d", i);
but then
xrun: Program received signal ET_LOAD_STORE, Memory access exception.
[Switching to stdcore[1] hwthread 0]
wich is the correct way of using it?
Thankyou
stdio scanf
-
- Active Member
- Posts: 40
- Joined: Fri Jul 22, 2011 2:31 pm
-
- XCore Expert
- Posts: 754
- Joined: Thu Dec 10, 2009 6:56 pm
Did you save it as a C file? XC does not support pointers.
-
- Active Member
- Posts: 40
- Joined: Fri Jul 22, 2011 2:31 pm
nope.. it was xc
but thankyou for the tip I will try it out..
on the mean time I found this workaround which gives me the same result
printstr ("Enter your family name: ");
scanf ("%s",str);
printstr ("Enter your age: ");
scanf ("%s", str_d);
i = atoi(str_d);
printf ("Mr. %s , %d years old.\n",str,i);
printf ("You have entered %#x (%d).\n",i,i);
Enter your family name: ruben
Enter your age: 30
Mr. ruben , 30 years old.
You have entered 0x1e (30).
Thankyou!
but thankyou for the tip I will try it out..
on the mean time I found this workaround which gives me the same result
printstr ("Enter your family name: ");
scanf ("%s",str);
printstr ("Enter your age: ");
scanf ("%s", str_d);
i = atoi(str_d);
printf ("Mr. %s , %d years old.\n",str,i);
printf ("You have entered %#x (%d).\n",i,i);
Enter your family name: ruben
Enter your age: 30
Mr. ruben , 30 years old.
You have entered 0x1e (30).
Thankyou!
-
- Active Member
- Posts: 40
- Joined: Fri Jul 22, 2011 2:31 pm
Thankyou for the previous info.
Now I am experiencing another trouble eith scanf
scanf is blocking somehow the mac_rx function.
I test this behaviour in a default example so that anyone can reproduce it.
sc_ethernet --> app_ethernet_demo3
In that example it is running as:
on stdcore[2]: ethernet_server
on stdcore[0]: demo
while adding:
on stdcore[1]: menu
with menuu defined as:
void menu()
{
char option[20];
while(1)
{
scanf ("%s",option);
printf ("Echo: %s",option);
}
}
Notice that menu function is running in another core and another thread... the question is why is it affecting the other mac_rx thread?
I am pinging the board and by adding this scanf function. it will just respond to one ping everythime something is entered + <enter>
is there some other way to do this that it is not blocking? however it shold not be like that right?
Now I am experiencing another trouble eith scanf
scanf is blocking somehow the mac_rx function.
I test this behaviour in a default example so that anyone can reproduce it.
sc_ethernet --> app_ethernet_demo3
In that example it is running as:
on stdcore[2]: ethernet_server
on stdcore[0]: demo
while adding:
on stdcore[1]: menu
with menuu defined as:
void menu()
{
char option[20];
while(1)
{
scanf ("%s",option);
printf ("Echo: %s",option);
}
}
Notice that menu function is running in another core and another thread... the question is why is it affecting the other mac_rx thread?
I am pinging the board and by adding this scanf function. it will just respond to one ping everythime something is entered + <enter>
is there some other way to do this that it is not blocking? however it shold not be like that right?
-
- XCore Expert
- Posts: 754
- Joined: Thu Dec 10, 2009 6:56 pm
The default stdout/stdin uses JTAG to communicate with the host.
That means that all threads in the system can be halted at for the ethernet stuff inconvenient times.
You can redirect stdout/in to a serial interface to avoid that.
I believe this is your issue.
That means that all threads in the system can be halted at for the ethernet stuff inconvenient times.
You can redirect stdout/in to a serial interface to avoid that.
I believe this is your issue.
-
- Active Member
- Posts: 40
- Joined: Fri Jul 22, 2011 2:31 pm
Then I would need to build some hardware to use a serial port right? :-( I wanted to avoid that. but if there is no other option I will give it a try.
Then I will add a UART to the project and...
Thankyou!
Then I will add a UART to the project and...
how can I redirect stdin/out to that serial interface? :-SBianco wrote: You can redirect stdout/in to a serial interface to avoid that.
Thankyou!
-
- XCore Expert
- Posts: 754
- Joined: Thu Dec 10, 2009 6:56 pm
-
- Active Member
- Posts: 40
- Joined: Fri Jul 22, 2011 2:31 pm
ok then. so I need to redefine
int _write(int fd, const char buf[], ___size_t count); // syscall.h
for printstr and printf I guess.
and then I asume that for scanf
it will be calling
int _read(int fd, char buf[], unsigned count); // syscall.h
am I right? But what about how should the new function behave?
I think that fd = filedescriptor is not required that the buff array has the content and size at size. but
I am concern on the return values? what is it expected?
Has anyone implemented something like this? because I havent find any project or example using it, is there another way? am I kind of crazy trying to do this? or is it really that nobody else finds it usefull enough to do it?
am I not going in the right direction?
int _write(int fd, const char buf[], ___size_t count); // syscall.h
for printstr and printf I guess.
and then I asume that for scanf
it will be calling
int _read(int fd, char buf[], unsigned count); // syscall.h
am I right? But what about how should the new function behave?
I think that fd = filedescriptor is not required that the buff array has the content and size at size. but
I am concern on the return values? what is it expected?
Has anyone implemented something like this? because I havent find any project or example using it, is there another way? am I kind of crazy trying to do this? or is it really that nobody else finds it usefull enough to do it?
am I not going in the right direction?
-
- Active Member
- Posts: 40
- Joined: Fri Jul 22, 2011 2:31 pm
will something like this do the trick?
int _write(int fd, const char buf[], ___size_t count)
{
send_uart(buff,count);
// udp_send(buff,count); -- or ethernet redirection
}
int _read(int fd, char buf[], unsigned count)
{
while(uart_empty);
count = receive_uart(buff);
return count;
}
## pseudocode. I still need to find the HW to test the stdout redirection to uart.
int _write(int fd, const char buf[], ___size_t count)
{
send_uart(buff,count);
// udp_send(buff,count); -- or ethernet redirection
}
int _read(int fd, char buf[], unsigned count)
{
while(uart_empty);
count = receive_uart(buff);
return count;
}
## pseudocode. I still need to find the HW to test the stdout redirection to uart.
-
- Active Member
- Posts: 40
- Joined: Fri Jul 22, 2011 2:31 pm
I received the recomendation of using sc_xlog instead. I think I will give it a try.
It seems that for printstr is working correctly. only the scanf is missing, but for the moment I will continue in a different way.
since I am using XC-3 I will use the additional ethernet connector for debuging purposes.
But it will be nice to know if someone completes the xlog for input also.
Thankyou.
It seems that for printstr is working correctly. only the scanf is missing, but for the moment I will continue in a different way.
since I am using XC-3 I will use the additional ethernet connector for debuging purposes.
But it will be nice to know if someone completes the xlog for input also.
Thankyou.