- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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;} } }- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Try to replace the function call withalt_alarm_start (&alarm, alt_ticks_per_second(), my_alarm_callback, (void*)&i)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
:mad: it doesn't work .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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!- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I used your example code 100%, but the alarm only executed ONCE. Did you have the same problem?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Can't you do this check in a separate task, that would just go to sleep between two checks?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I already have four task running in a Cyclone III. I prefer for design complexity use as less task as I can. I'm trying to add another timer and handle at hardware level the interrupt....I'm not sure but these could help to solve the problem- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Using hardware level interrupts is not recommended with an OS. Anyway you can do it and I myself (alas!) have sometimes used this kind of unfair practice.
But, you must be VERY careful because your isr call can easily conflict with OS. So, your isr must be as small as possible and have a well defined context. I think you will use alt_irq_register() to enable the interrupt: if I remember correctly, the call to this function must be made in the highest priority task, otherwise it won't work.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It depends what you mean by "Design Complexity". Adding a task won't use so many resources (just some memory) but will probably make the code more reusable and maintainable than adding another hardware timer.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Daixiwen is right. Adding a task will ease code portability and maintenance.
You must consider the hw timer and isr solution only if you have particular requirements which can't be fulfilled by OS features. For example, in my case, I needed a function to execute at very precise timing, in the us range, which could not be achieved by uC-RTOS scheduler (the RT applies only down to the ms range...)- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ok guys thanks for your advice, you have been very helpful.
Basically in my design I don't have strong time requirements like microseconds. I have 8 ADC to contol and each adc is connetted to 5 sensors. I wanna use the timer just for a periodic check on sensors. So Daixiwen is right maybe the best solution is adding another task. Anyway I'll play a little bit with hardware intterupts to understand better how they works. Thanks again- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page