Does MQX 381 preserve Kinetis FP registers?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Does MQX 381 preserve Kinetis FP registers?

Jump to solution
1,083 Views
OldNick
Contributor IV

Code on a K60FN1M0 behaves very strangely unless I turn off the vfpv4 option in IAR General Options.


walking it thorugh, I came across a strange thing where a float variable was held in S16, and the thread called _time_delay(n).  When it came back, the value in S16 was lost.

My user config has FP config turned on

#define MQXCFG_ENABLE_FP           1

So I presumed FP registers would be preserved.

0 Kudos
Reply
1 Solution
762 Views
Martin_
NXP Employee
NXP Employee

You have user_config.h settings correct. Besides them, floating point tasks need be configured to save/restore floating point registers on context switch. This is done by assigning MQX_FLOATING_POINT_TASK attribute to a task.

const TASK_TEMPLATE_STRUCT  MQX_template_list[] =

   /* Task Index,   Function,   Stack,  Priority, Name,     Attributes,          Param, Time Slice */

    { WORLD_TASK,   world_task, 1000,   9,        "world",  0, 0,     0 },

    { HELLO_TASK,   hello_task, 1000,   8,        "hello",  0,                   0,     0 },

    { FLOAT_TASK,   float_task, 1000,   10, "float",  MQX_AUTO_START_TASK | MQX_FLOATING_POINT_TASK, 0,     0 },

    { 0 }

};

Attached you may find standard hello2 example modified to do some floating point math and print results on terminal after context switches.

View solution in original post

0 Kudos
Reply
4 Replies
763 Views
Martin_
NXP Employee
NXP Employee

You have user_config.h settings correct. Besides them, floating point tasks need be configured to save/restore floating point registers on context switch. This is done by assigning MQX_FLOATING_POINT_TASK attribute to a task.

const TASK_TEMPLATE_STRUCT  MQX_template_list[] =

   /* Task Index,   Function,   Stack,  Priority, Name,     Attributes,          Param, Time Slice */

    { WORLD_TASK,   world_task, 1000,   9,        "world",  0, 0,     0 },

    { HELLO_TASK,   hello_task, 1000,   8,        "hello",  0,                   0,     0 },

    { FLOAT_TASK,   float_task, 1000,   10, "float",  MQX_AUTO_START_TASK | MQX_FLOATING_POINT_TASK, 0,     0 },

    { 0 }

};

Attached you may find standard hello2 example modified to do some floating point math and print results on terminal after context switches.

0 Kudos
Reply
762 Views
OldNick
Contributor IV

Thanks Martin.

Does the MQX_FLOATING_POINT_TASK attribute have any adverse effect if you are not using hardware floating point?

We are building on two targets, so I need to know whether to put a conditional compile around that?

PS, where is this attribute described in the documentation?

0 Kudos
Reply
762 Views
Martin_
NXP Employee
NXP Employee

Assuming one target has PSP_HAS_FPU=1 and the other PSP_HAS_FPU=0, it seems MQX_FLOATING_POINT attribute has no effect. I searched all MQX source code for MQX_FLOATING_POINT string; when PSP and RTCS is built with PSP_HAS_FPU being zero, it is not used.

In case you will decide to use conditional compilation, MQX source code approach to this is:

#if MQXCFG_ENABLE_FP && PSP_HAS_FPU

  /* reference to MQX_FLOATING_POINT attribute */

#endif

In documentation, task attributes are discussed in MQX User's Guide.

0 Kudos
Reply
762 Views
OldNick
Contributor IV

Thanks for answering so quickly.  Searching the source code and reverse engineering it seems the only way to answer these sorts of questions. Can't do that until I know what I am looking for.

Did you also find the reference in SNMP/mqx_mib where the conditional is subtly different?

Perhaps the user guide or reference manual could be edited to suggest where in the source code the complete list of attributes can be found (mqx_cnfg.h) since they are described better in there than they are in the documentation.:smileywink:

0 Kudos
Reply