Strange printf behavior

Technical questions regarding the xTIMEcomposer, xSOFTip Explorer and Programming with XMOS.
User avatar
notDilbert
Member
Posts: 9
Joined: Mon Feb 25, 2019 3:05 pm

Strange printf behavior

Postby notDilbert » Wed Feb 19, 2020 4:16 pm

Hi,

I'm using notifications on an array of interfaces and found something odd testing the server side.

In the select case section where get_data() get's handled if I do not include a new line in the printf the values get displayed in the console in batches and some time after the clients have sent there debug data to the console.

It's a bit hard to explain so see attached project.

Using xTIMEcomposer v14.4.1 (build 235-acbb966, Dec-01-2019)

Kind regards
You do not have the required permissions to view the files attached to this post.
User avatar
mon2
XCore Legend
Posts: 1849
Joined: Thu Jun 10, 2010 11:43 am

Postby mon2 » Thu Feb 20, 2020 9:50 am

Hi. Have not reviewed your code but:

a) standard printf is blocking and not recommended for use

b) instead, consider the use of real-time printf. See the attached document.


Debug-with-printf-in-real-time_X1093A.pdf
You do not have the required permissions to view the files attached to this post.
User avatar
notDilbert
Member
Posts: 9
Joined: Mon Feb 25, 2019 3:05 pm

Postby notDilbert » Thu Feb 20, 2020 12:56 pm

Hi,

Thanks for the reply.

I am using real-time/xScope/xTag printf. But with the adding -fxscope arg to XCC_FLAGS in makefile and creating config.xscope file method.

Come on have a look, you will be surprised.... I think.

Uncommenting the the line printf("\n"); in app_server.xc

Code: Select all

void server_task(server interface notify_if c[n], unsigned n)
{
    timer t;
    uint32_t time;
    const uint32_t period = 200000000;  // 1=100us
    t :> time;
    int data = 0;

    printf("server_task() started\n");

    while(1)
    {
        select
        {
            case c[int i].get_data(int id) -> int return_value:
                printf("id=%d i=%d", id, i);  // unexpected console output without new line
                //printf("\n");  // adding this produces expected console output
                return_value = data;
                break;

            case t when timerafter(time) :> void:
                if (++data == 0) break;

                //printf("server_task: sending notifications\n");

                for (int i=0; i<n; i++) c[i].data_ready();

                time += period;
                break;
        }
    }
}

Changes the console output from

Code: Select all

server_task() started
client_a_task() started
client_b_task() started
1
1
2
2
3
3
4
4
id=1 i=0id=2 i=1id=1 i=0id=2 i=1id=1 i=0id=2 i=1id=1 i=0id=2 i=15
5
6
6

to

Code: Select all

server_task() started
client_a_task() started
client_b_task() started
id=1 i=0
1
id=2 i=1
1
id=1 i=0
2
id=2 i=1
2
id=1 i=0
3
id=2 i=1
3
id=1 i=0
4
id=2 i=1
4
id=1 i=0
5
id=2 i=1
5
id=1 i=0
6
id=2 i=1
6

Notice the two notifications fire two seconds apart.

So I doubt it is a timing/blocking issue.

Who is online

Users browsing this forum: No registered users and 6 guests