Tool/software: Code Composer Studio
Hi Hercules team,
I am currently looking to use the rti module as a "sleep()" function.
I noticed that the rtiSetPeriod() function updates only after an additional "tick" of the previous period length has passed (expected behavior).
This unfortunately means that when setting the period to a large value (like 1000ms) then trying to change to a small value (100us), we must wait up to an additional 1000ms before the timer can change.
Is there a way to force the "tick" to happen faster so that we can immediately switch the period to something smaller?
Here's the code I am currently trying to use as a "sleep" or "delay" function, to help clarify what I am trying to do:
//************** //delay function, input = number of microseconds //************** void delayus(uint16 us) { if (us == 0) return; else { rtiSetPeriod(rtiCOMPARE0, 10*us); rtiEnableNotification(rtiNOTIFICATION_COMPARE0); rtiStartCounter(rtiCOUNTER_BLOCK0); while(RTI_TIMEOUT==0); //this is set to 1 in notificaiton.c rtiNotification RTI_TIMEOUT = 0; rtiDisableNotification(rtiNOTIFICATION_COMPARE0); rtiStopCounter(rtiCOUNTER_BLOCK0); rtiResetCounter(rtiCOUNTER_BLOCK0); } } //*************** //notificaiton.c: //*************** void rtiNotification(uint32 notification) { /* enter user code between the USER CODE BEGIN and USER CODE END. */ /* USER CODE BEGIN (9) */ RTI_TIMEOUT = 1; /* USER CODE END */ }
To get the above code to work, I need to add another "while()" loop to wait for a tick to occur before the "rtiSetPeriod" takes effect.
Thanks!
Vince Toledo