max.kriegleder-/E1597aS9LQAvxtiuMwx3w@public.gmane.org [nuttx]
2014-08-19 12:30:25 UTC
Hi Greg,I am observing some strange behaviour, which I can not make sense of and I am hoping that you can point me in the right direction. It is related to I2C on a stm32f103 when run in interrupt driven mode. I am using nuttx 7.2.
I am reading out a sensor at 500 Hz and the read operation takes about 400 us to complete. At the same time I am runnig a different app, where I want to output some data to the nsh.
The code is the following
while(true){
printf("\033[H"); // move cursor home and clear screen
printf("Hello World! %u\n",count++);
printf("Hello World, again %u", count++);
/* Sleep 20 ms waiting for user input five times ~ 0.1s */
for (int k = 0; k < 5; k++) {
char c;
struct pollfd fds;
int ret;
fds.fd = 0; /* stdin */
fds.events = POLLIN;
ret = poll(&fds, 1, 20);
if (ret > 0) {
read(0, &c, 1);
switch (c) {
case 0x03: // ctrl-c
case 0x1b: // esc
case 'c':
case 'q':
printf("\n");
exit(0);
return 0;
/* not reached */
}
}
//usleep(20000);
}
}
This works in principle. However, if I add a few more printf lines, the app blocks and only if I hit the keyboard (or hold a key down) the output refreshes. So I guess the poll blocks?.
If I then uncomment the usleep I get an assertion failed error in sig_timedwait at the line DEBUGASSERT(rtcb->waitdog); and I have no clue how the I2C ISR and that part of the code could be related. The odd thing is that if I run the I2C in polled mode, everything works fine (more printfs or the usleep cause no problem). Any ideas?
Thanks!
Max
I am reading out a sensor at 500 Hz and the read operation takes about 400 us to complete. At the same time I am runnig a different app, where I want to output some data to the nsh.
The code is the following
while(true){
printf("\033[H"); // move cursor home and clear screen
printf("Hello World! %u\n",count++);
printf("Hello World, again %u", count++);
/* Sleep 20 ms waiting for user input five times ~ 0.1s */
for (int k = 0; k < 5; k++) {
char c;
struct pollfd fds;
int ret;
fds.fd = 0; /* stdin */
fds.events = POLLIN;
ret = poll(&fds, 1, 20);
if (ret > 0) {
read(0, &c, 1);
switch (c) {
case 0x03: // ctrl-c
case 0x1b: // esc
case 'c':
case 'q':
printf("\n");
exit(0);
return 0;
/* not reached */
}
}
//usleep(20000);
}
}
This works in principle. However, if I add a few more printf lines, the app blocks and only if I hit the keyboard (or hold a key down) the output refreshes. So I guess the poll blocks?.
If I then uncomment the usleep I get an assertion failed error in sig_timedwait at the line DEBUGASSERT(rtcb->waitdog); and I have no clue how the I2C ISR and that part of the code could be related. The odd thing is that if I run the I2C in polled mode, everything works fine (more printfs or the usleep cause no problem). Any ideas?
Thanks!
Max