KurtE
Senior Member+
I know the title is sort of vague and also covers a lot of ground.
But wondering what approaches we should take when we are developing (hopefully) reusable code for Teensy and hopefully the more global Arduino system.
There are many parts to this and I also have a feeling that what is easiest for beginners to understand may not always be what advanced users would prefer, but hopefully there is enough common ground.
But for example: working on the DMA code.
There is currently a method: void transferCount(unsigned int len) ;
Now on the T3.x there are cases where the maximum count is 32767 and other cases where the maximum is 511.
Currently the code does a check for > 32767 and just returns doing nothing...
Now what should it do? If I should pass in 65535 for example, the function will silently fail, and then when I start the DMA transfer it will simply try to use whatever was in the field and in many cases the code will just hang or will return with other code expecting that many bytes transferred and did not. Either way not good.
So what should it do? Again trying to think more global.
a) simply remove the tests, as it does not help recover and the programmer should know better.
b) Change code to return something like a bool, so it would return false. Could help, but I bet the return value would not be looked at by 90+% of code.
c) like b) but maybe add either it returns an error code or there is a system error facility, that it would set the last error and return false...
d) Throw some form of exception - Which some code higher up try/catch could handle or not...
There are times where I personally would like something like d) but not sure if it fits with the Arduino world.
Also wish there was a default handler, that would catch most errors probably in main which would maybe try to print out what error happened and maybe a little more info like the address where the fault happened. So for example if you are working on T3.5 and have an 8 bit access to a 32 bit register which faults, it might give you an idea of the fault and where it happened.... But maybe just wishful thinking.
Thoughts?
But wondering what approaches we should take when we are developing (hopefully) reusable code for Teensy and hopefully the more global Arduino system.
There are many parts to this and I also have a feeling that what is easiest for beginners to understand may not always be what advanced users would prefer, but hopefully there is enough common ground.
But for example: working on the DMA code.
There is currently a method: void transferCount(unsigned int len) ;
Now on the T3.x there are cases where the maximum count is 32767 and other cases where the maximum is 511.
Currently the code does a check for > 32767 and just returns doing nothing...
Now what should it do? If I should pass in 65535 for example, the function will silently fail, and then when I start the DMA transfer it will simply try to use whatever was in the field and in many cases the code will just hang or will return with other code expecting that many bytes transferred and did not. Either way not good.
So what should it do? Again trying to think more global.
a) simply remove the tests, as it does not help recover and the programmer should know better.
b) Change code to return something like a bool, so it would return false. Could help, but I bet the return value would not be looked at by 90+% of code.
c) like b) but maybe add either it returns an error code or there is a system error facility, that it would set the last error and return false...
d) Throw some form of exception - Which some code higher up try/catch could handle or not...
There are times where I personally would like something like d) but not sure if it fits with the Arduino world.
Also wish there was a default handler, that would catch most errors probably in main which would maybe try to print out what error happened and maybe a little more info like the address where the fault happened. So for example if you are working on T3.5 and have an 8 bit access to a 32 bit register which faults, it might give you an idea of the fault and where it happened.... But maybe just wishful thinking.
Thoughts?