MQX error strategy

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

MQX error strategy

575 Views
intertronic
Contributor II

Hi,

there are some mqx functions that return an error-code and some functions set the task-error-code internal. Such a mixed / inconsistent system is perplexing.

If someone want to add custom error-codes this system is unnecessary complicated. Because you have to clear the old error before you can set your custom code.

And also if you don't want to add custom error-codes your sourcecode is full of _task_set_error(MQX_OK);

You just have to look at the mqx source, then you see a lot of unnecessary task-error-handling.

Sometimes the error is returned as pointer and also the task error is set. And maybe the error is also get and cleared in the calling function.

Sometimes the calling functions gets the task-error before an internal call, to clear it after a call to some other function.

Is this overhead really necessary?

What is the actual/future strategy of freescale?

Regards

Tags (1)
1 Reply

321 Views
RadekS
NXP Employee
NXP Employee

Yes, you are right. We know about that issue.

Some of the API functions return error code, while other ones set task specific error. In addition to that some internal functions return error code via pointer.

Unfortunately most of this inconsistency is caused by history evolution and it remains here mainly for backward compatibility. We agree that complete revision of error handling strategy would be great, but it is hard to change because it will definitely lead to requirement of almost complete redesign customer’s codes.

Concerning public API:

using task specific error is not an ideal solution because it may not be clear from which system call the error comes from and the code to check for errors after every system call bloats the application.

Some functions also return positive value as valid result and negative values as error code. This is error prone because error codes in MQX are positive and there may be bugs when it may not be possible to distinguish between return value and an error code.

However it is not easy to change this because we would break backwards compatibility. What we can do (and we are doing) is to think about proper way to return errors in new or redesigned API. Sometimes we are bound by conventions and compatibility with libraries.

One of the examples is nIO (new IO subsystem).

It was designed to be usable as underlying layer for library IO (read/write, fread/fwrite). The library functions tend to utilize “errno”. It is quite problematic to implement it so that it is task specific and it is not a good idea to directly access errno in device drivers at all.

The approach we took is to return -1 to indicate and error (in compliance with POSIX IO) and pass specific error code from drivers to NIO and from NIO to the caller via pointer (avoiding errno in drivers).

This specific error code is then stored to errno in the library-NIO adaptation layer (this is probably the only clean solution).

So short answer is that we are aware about the situation and we are trying to improve it where we can, but backward compatibility, at least to certain extent, is important to customers so it is not possible to change it all at once.

I hope it helps you.

Have a great day,
RadekS

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------