8 years, 4 months ago.

us_ticker.c question

Hello,

does mbed provide documentation about software requirement for this module? in other word, what is it supposed to do exactly? I am asking also about HLD (High level design for the APIs) and HLD requirements?

2 Answers

8 years, 4 months ago.

us_ticker.h exist which specifies the functions that need to be implemented in us_ticker.c. And while I think it is a bit limited documentation wise, in general it should behave the same as other targets behave in case you want to add a new target. Do you have specific questions regarding its behavior?

Accepted Answer

hi Erik,

Yeah I do have specific questions, should the timer interrupt every 1us? what should the function `us_ticker_read()` return.?? if i load just 80 ticks in the timer (PLL=80Mhz) so it should read less than 1us.

(I have solved the previous problem about handler, In case you were interesting to know what was happening , the for loop inside the function 'NVIC_SetVector' has index i which is declared as uint32_t. and it was being compared to definition which was less than 255 so the compiler assumed it's uint8_t. when the for loop started, it overflow and corrupt the stack. the solution was to define 'NVIC_NUM_VECTORS' with (0x9AUL) which is unsigned long 154, Can you believe the pain :D )

posted by Mohamed Saleh 01 Aug 2016

First of all, I would check for example the LPC1768 code. That has a fairly easy Timer setup.

No the timer should only interrupt when the interrupt is set. Some targets do have also interrupts they use themselves to get to 32-bit level with a timer they can't set for 32-bit @ 1MHz, but if you interupt every 1us it will be pretty much permanently busy handling the interrupts. us_ticker_read() should return a value that always increments by '1' every 1us. If it is at its max it may overflow to zero again. If it is at 10000, and an interrupt is set for 10010, the code needs to make sure this interrupt is handled after 10us.

And good to know that that was the issue, one of those small bugs with a big impact.

posted by Erik - 01 Aug 2016

Thank you Erik, You gave me great tips and big help. I have finished porting mbed with GPIO and us_ticker for now.

posted by Mohamed Saleh 01 Aug 2016
8 years, 4 months ago.

Any chance you mean ticker.attach_us()? https://developer.mbed.org/handbook/Ticker