Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
16 years ago

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's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Can't you do this check in a separate task, that would just go to sleep between two checks?

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    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
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    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.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    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.

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    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...)
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    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