robinfawell Posted April 7, 2008 Report Share Posted April 7, 2008 In TK's and QBas 8 x 8 and 16 x 16 keyboard Scan Matrix the SM_ButtonHandler is called from USER_Tick.This is described in the MIOS Functions Reference as "This function called by MIOS in the mainloop when nothing else is to do"A number of questions occur.If called does the SM-ButtonHandler function perform once only? Or can it perform several times ?What happens if the function takes too much time?Thanks in advanceRobin Quote Link to comment Share on other sites More sharing options...
TK. Posted April 7, 2008 Report Share Posted April 7, 2008 Hi Robin,If called does the SM-ButtonHandler function perform once only? Or can it perform several times ?USER_Tick will be called by MIOS in an endless loop, so yes: it will be called several times until you power-off the core.Beside of USER_Tick, several other handlers will be called consecutively, e.g. the DIN and AIN input checking routine, the MIDI parser, the MIOS_DISPLAY_Tick routine, etc... and once the execution of these handlers has been finished, the sequence re-starts at USER_TickThis method is also called cooperative multitaskingSo long the other handlers are idle (no DIN/AIN change, no incoming MIDI events, no LCD output, etc) USER_Tick will be called with a period of 20 uS, which is pretty fast! :)What happens if the function takes too much time?In this case, the other tasks will be blocked. The max. acceptable delay depends on your application.There is only one strict requirement: it should never take more than ca. 20 mS, because if the MIDI parser is not called within this time span, the MIDI IN buffer could overrunNote also: than longer USER_Tick takes, than longer the slack time of the other tasksIf my own applications, I'm trying to reduce the max. execution time of USER_Tick to less than 1 mSIf it takes longer, I program the functions which are handled by USER_Tick in a way that they will be processed step by step with each call of USER_Tick - example: when I'm checking if a new (of up to 8 ) BankStick has been connected to the core module, I'm only checking a single BankStick with each USER_Tick execution. I'm using a counter which is incremented and reset if >= 8 each time my BankStick handler is called, and this counter addresses the BankStick which should be checked. This easy method reduces the execution time of USER_Tick dramatically, and therefore improves the overall performance of the application.Best Regards, Thorsten. Quote Link to comment Share on other sites More sharing options...
robinfawell Posted April 9, 2008 Author Report Share Posted April 9, 2008 Thanks ThorstenIf I understand your answer properly, the USER_Tick follows the other tasks you mentioned. Then when USER_Tick is completed the other tasks will immediately be restarted then followed by a second USER_Tick and so on until the system is closed down. Best Regards Robin Quote Link to comment Share on other sites More sharing options...
stryd_one Posted April 10, 2008 Report Share Posted April 10, 2008 You got it right robin.I tagged the **** out of this post cause it's a good plain-english explanation of how the main loop works. People learning to write MIOS apps should read this :) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.