src/ssx/occhw/occhw_ocb.c
/// Set up an OCB timer and interrupt handler
///
/// \param timer A valid OCB timer index
///
/// \param auto_reload A non-0 value indicates to run the timer in auto-reload
/// mode.
///
/// \param timeout_ns The timeout specified in nanoseconds. The actual timeout
/// will rounded down to the underlying timer tick, with a minimum 1 tick
/// timeout. However if the \a timeout_ns argument is explicity 0, then the
/// timer wil be initialized with a 0 timeout, effectively disabling the
/// timer.
///
/// \param handler The interrupt handler for the timer interrupt
///
/// \param arg The private argument of the interrupt handler
///
/// \param priority The SSX/PPC405 interrupt priority to assign to the
/// interrupt.
///
/// This API sets up and starts the timer and unmasks the timer
/// interrupt. Once set up, the timer can be reset using ocb_timer_reset(). As
/// a fine point of the specification, if a timer interrupt is already pending
/// when this API is invoked then that interrupt will be cleared.  Only the
/// next interrupt (corresponding to the new programming) will be serviced by
/// the newly installed handler.
///
/// Note that the interrupt handler is responsible for clearing the timer
/// interrupt status. An API ocb_timer_status_clear() is available for this.
///
/// \retval 0 Success
///
/// \retval -OCB_INVALID_ARGUMENT_TIMER Causes include illegal timer
/// numbers and illegal or unrepresntable timeouts.
///
/// Other errors may be returned by the underlying calls to SSX routines that
/// set up interrupts.
Set up an OCB timer and interrupt handler
\param timer A valid OCB timer index

\param auto_reload A non-0 value indicates to run the timer in auto-reload
mode.

\param timeout_ns The timeout specified in nanoseconds. The actual timeout
will rounded down to the underlying timer tick, with a minimum 1 tick
timeout. However if the \a timeout_ns argument is explicity 0, then the
timer wil be initialized with a 0 timeout, effectively disabling the
timer.

\param handler The interrupt handler for the timer interrupt

\param arg The private argument of the interrupt handler

\param priority The SSX/PPC405 interrupt priority to assign to the
interrupt.

This API sets up and starts the timer and unmasks the timer
interrupt. Once set up, the timer can be reset using ocb_timer_reset(). As
a fine point of the specification, if a timer interrupt is already pending
when this API is invoked then that interrupt will be cleared.  Only the
next interrupt (corresponding to the new programming) will be serviced by
the newly installed handler.

Note that the interrupt handler is responsible for clearing the timer
interrupt status. An API ocb_timer_status_clear() is available for this.

\retval 0 Success

\retval -OCB_INVALID_ARGUMENT_TIMER Causes include illegal timer
numbers and illegal or unrepresntable timeouts.

Other errors may be returned by the underlying calls to SSX routines that
set up interrupts.
Set up an OCB timer and interrupt handler \ param timer A valid OCB timer index \ param auto_reload A non - 0 value indicates to run the timer in auto - reload mode . \ param timeout_ns The timeout specified in nanoseconds . The actual timeout will rounded down to the underlying timer tick with a minimum 1 tick timeout . However if the \ a timeout_ns argument is explicity 0 then the timer wil be initialized with a 0 timeout effectively disabling the timer . \ param handler The interrupt handler for the timer interrupt \ param arg The private argument of the interrupt handler \ param priority The SSX / PPC405 interrupt priority to assign to the interrupt . This API sets up and starts the timer and unmasks the timer interrupt . Once set up the timer can be reset using ocb_timer_reset () . As a fine point of the specification if a timer interrupt is already pending when this API is invoked then that interrupt will be cleared . Only the next interrupt ( corresponding to the new programming ) will be serviced by the newly installed handler . Note that the interrupt handler is responsible for clearing the timer interrupt status . An API ocb_timer_status_clear () is available for this . \ retval 0 Success \ retval - OCB_INVALID_ARGUMENT_TIMER Causes include illegal timer numbers and illegal or unrepresntable timeouts . Other errors may be returned by the underlying calls to SSX routines that set up interrupts .
int
ocb_timer_setup(int timer,
                int auto_reload,
                int timeout_ns,
                SsxIrqHandler handler,
                void* arg,
                int priority)
{
    int rc;
    ssx_irq_disable(OCCHW_IRQ_OCC_TIMER0 + timer);
    ssx_irq_setup(OCCHW_IRQ_OCC_TIMER0 + timer,
                  SSX_IRQ_POLARITY_ACTIVE_HIGH,
                  SSX_IRQ_TRIGGER_LEVEL_SENSITIVE);
    ssx_irq_handler_set(OCCHW_IRQ_OCC_TIMER0 + timer,
                        handler,
                        arg,
                        priority);
    rc = ocb_timer_reset(timer, auto_reload, timeout_ns);
    ssx_irq_enable(OCCHW_IRQ_OCC_TIMER0 + timer);
    return rc;
}
int ocb_timer_setup ( int timer , int auto_reload , int timeout_ns , SsxIrqHandler handler , void * arg , int priority ) { int rc ; ssx_irq_disable ( OCCHW_IRQ_OCC_TIMER0 + timer ) ; ssx_irq_setup ( OCCHW_IRQ_OCC_TIMER0 + timer , SSX_IRQ_POLARITY_ACTIVE_HIGH , SSX_IRQ_TRIGGER_LEVEL_SENSITIVE ) ; ssx_irq_handler_set ( OCCHW_IRQ_OCC_TIMER0 + timer , handler , arg , priority ) ; rc = ocb_timer_reset ( timer , auto_reload , timeout_ns ) ; ssx_irq_enable ( OCCHW_IRQ_OCC_TIMER0 + timer ) ; return rc ; }
Set up an OCB timer and interrupt handler
\param timer A valid OCB timer index
Set up an OCB timer and interrupt handler \ param timer A valid OCB timer index
//printk("ocb_timer_setup(%d, %d, %d, %p, %p, %d)\n", //       timer, auto_reload, timeout_ns, //       handler, arg, priority);