Forum Discussion
alt_alarm_start()
int alt_alarm_start (alt_alarm* alarm,
alt_u32 nticks, alt_u32 (*callback) (void* context), void* context); according to the handbook, program would transfer alt_u32 (*callback)(void* context) after nticks, void* context is the input parameter of the function, does the two void* contexts are the same? and how to receive the return value of the (*callback) function?16 Replies
- Altera_Forum
Honored Contributor
Your call back function is called with the same context parameter that was given to the alt_alarm_start function.
The return value of the callback function is used to determine when it should be called again, it is automatically picked up by the alarm driver. - Altera_Forum
Honored Contributor
daixiwen (http://www.alteraforum.com/forum/member.php?u=4443)
thanks for your reply! underside is my program, could you do me a favor to figure out can the parameter i can be transfer to the called function my_alarm_callback?if can't,how can the parameter be transfer into this function? Thank you very much! alt_u32 my_alarm_callback (void* context) { /* This function will be called once/second */ *(alt_u8 *)context++; return alt_ticks_per_second(); } int main() { static alt_alarm alarm; static alt_u8 i; if (alt_alarm_start (&alarm, alt_ticks_per_second(), my_alarm_callback(&i), NULL) < 0) { printf ("No system clock available\n"); } else printf("alarm exist\n"); while(1) { if(i==1) {printf("call happend\n"); i=0;} } } - Altera_Forum
Honored Contributor
Try to replace the function call with
alt_alarm_start (&alarm, alt_ticks_per_second(), my_alarm_callback, (void*)&i) - Altera_Forum
Honored Contributor
:mad: it doesn't work .
- Altera_Forum
Honored Contributor
HaHa, it works!
alt_u32 my_alarm_callback (void* context) { /* This function will be called once/second */ *(alt_u8 *)context++; //this line should be replaced by (*(alt_u8 * //)context)++; return alt_ticks_per_second(); } Thanks for reply! - Altera_Forum
Honored Contributor
I used your example code 100%, but the alarm only executed ONCE. Did you have the same problem?
- Altera_Forum
Honored Contributor
As long as your callback returns a positive non zero value, it should be called again. Are the interrupts still enabled? Is the timer working? What does alt_ticks_per_second() return?
- Altera_Forum
Honored Contributor
Hi everyone.
I'm pretty new of this forum and i hope you could help me. I'm fighting wit the alt_alarm_function (). To explain better my problem I have to do a little introduction on my project. I'm working with an CycloneIII and I have build a Real-time application using the MicroC-OSII. I have four different tasks which run on my machine.At the power up the four task and the different peripheral are initialized, then start a task which take care to grab data from an external device for the FPGA. After a certain number of data another task is called and start to process the collected raw data. This two task run continuously and for fixed time step I' d like to check the connection with the peripheral. I'm trying to the alt_start function but after the first call the program does't 'm come back to the task who was running and all the system is completely stuck until the next alarm event happens. Does anyone know how to handle the alt_alarm_start() with a multitasking system? Have I clean some IRQ register? Thanks in advance for your help - Altera_Forum
Honored Contributor
If the timer used by the alarm functions is also the one used by MicroC-OS' scheduler then there could be a clash. I don't think you should use the alarm functions in a multi-tasked environment.
Doesn't uC-OS II provide similar alarm or wait functions you could use for that purpose? - Altera_Forum
Honored Contributor
Thanks for your answer.
I checked the Micro_OS function but seems that there are no such function or better all the timer function are related to task so the only function that could help me is the OSTimeDly that allows a task to delay itself for a number of clock ticks. What I need in my program it's timer clock that tell me when i have to do a check and then return to the normal operation.