ErichStyger / mcuoneclipse

McuOnEclipse Processor Expert components and example projects
Other
731 stars 1.29k forks source link

TIMEOUT Component Enhancement #9

Closed axelriet closed 10 years ago

axelriet commented 10 years ago

Hello,

I like the Timeout component but I'd like to see a Reset function added, to be able to reuse a timeout instance insdead of destroying it/creating a new one just to get a fresh countdown timer or change the value on-the-fly. The Reset function could be as follow:

/ * =================================================================== * Method : TMOUT1_Reset(component Timeout) * Description : * Resets the counter value and return the value just prior to * the call. * Parameters : * NAME - DESCRIPTION * handle - Counter handle * nofTicks - Number of ticks for the counter * until it expires. * Returns : \ --- - The previous value of the counter (ticks) * * =================================================================== */

TMOUT1_CounterType TMOUT1_Reset(TMOUT1_CounterHandle handle, TMOUT1_CounterType nofTicks) { TMOUT1_CounterType res; CS1_CriticalVariable();

if (handle==TMOUT1_OUT_OF_HANDLE) { return; } if (nofTicks==0) { nofTicks = 1; /* wait at least for one tick, otherwise will timeout immediately */ } CS1_EnterCritical(); res = TMOUT1_Counters[handle]; TMOUT1_Counters[handle] = nofTicks; CS1_ExitCritical(); return res; }

As a side note, TMOUT1_Value() does not check the validity of the handle, and the documentation says it returns nothing.

As another side note, I'm not sure of the need for the nofTicks==0 then nofTicks=1, there are cases where the timeout must be zero, for example you may want to compute a delay that makes sure a given operations lasts at least a given amount of time, and in some cases the computed additional delay may very well be zero. I'd drop those ifs: when the app says zero then the timout object starts as "expired" which is what the app asked for. You can make it a codegen preference option perhaps?

Cheers from Geneva, Axel

ErichStyger commented 10 years ago

Hi Alex, many thanks for your feedback on comments! I have fixed the return hint for the Value() function. I implemented your function/suggestion, but I named it SetCounter() as it actually not resets (to zero), but to a given value. Your check on nofTicks==0 I have omitted, as I think if you want to have one tick, then simply pass that one tick to the function? You can check the changes in this commit: https://github.com/ErichStyger/mcuoneclipse/commit/a876a90433f33bd31bc299b7ee524473b4e8faba

Let me know if this is ok for you. I close for now the ticket, be free to re-open it or create another one. If you want the .PEupd, drop me an email and I can send it to you. I will probably release the updated components next weekend (I hope I find time).

Cheers from Lucerne, Erich

zeged commented 10 years ago

Eduardo Zegarra Ch. sent you an invitation

Twitter helps you stay connected with what's happening right now and with the people and organizations you care about.

Accept invitation

https://twitter.com/i/e0b42578-5496-4755-8d57-3e2a1e2dca59

You can unsubscribe from receiving email notifications from Twitter at anytime. For general inquiries, please visit us at Twitter Support. Unsubscribe: https://twitter.com/i/o?t=1&iid=fa5ac7353d3d4ff5969b5a4fecef12a9&uid=0&c=IuVwbCB3dgHcg%2B5VWrMxMfNKIzdCxQP7r2SbMTsTMC%2FgxJiRRg4rEVXlCPEVQDVrPcg9A%2FwaBrZkPHDqCQkwXJduZp4Jxu%2FFvvcxhWxTKPRdlUlKeBnURg%3D%3D&nid=9+26

Need help? https://support.twitter.com