The API

This section details the Driver Kernel Interface. Note that most of these functions are identical to Kernel C API calls, and will in most configurations be wrappers for them. In non-kernel configurations they will be supported directly by the HAL, or by code to emulate the required behavior.

This API is defined in the header file cyg/hal/drv_api.h.

cyg_drv_isr_lock

Function:
	void cyg_drv_isr_lock()
	
Arguments:

None

Result:

None

Level:

DSR

Description:

Disables delivery of interrupts, preventing all ISRs running. This function maintains a counter of the number of times it is called.

cyg_drv_isr_unlock

Function:
	void cyg_drv_isr_unlock()
	
Arguments:

None

Result:

None

Level:

DSR

Description:

Re-enables delivery of interrupts, allowing ISRs to run. This function decrements the counter maintained by cyg_drv_isr_lock(), and only re-allows interrupts when it goes to zero.

Function:
void cyg_drv_dsr_lock()
Arguments:

None

Result:

None

Level:

Thread

Description:

Disables scheduling of DSRs. This function maintains a counter of the number of times it has been called.

cyg_drv_dsr_unlock

Function:
void cyg_drv_dsr_unlock()
Arguments:

None

Result:

None

Level:

Thread

Description:

Re-enables scheduling of DSRs. This function decrements the counter incremented by cyg_drv_dsr_lock(). DSRs are only allowed to be delivered when the counter goes to zero.

cyg_drv_mutex_init

Function:
void cyg_drv_mutex_init(cyg_drv_mutex *mutex)
Arguments:

mutex - pointer to mutex to initialize

Result:

None

Level:

Thread

Description:

Initialize the mutex pointer to by the mutex argument.

cyg_drv_mutex_destroy

Function:
void cyg_drv_mutex_destroy( cyg_drv_mutex *mutex )
Arguments:

mutex - pointer to mutex to destroy

Result:

None

Level:

Thread

Description:

Destroy the mutex pointed to by the mutex argument.

cyg_drv_mutex_lock

Function:
cyg_bool cyg_drv_mutex_lock( cyg_drv_mutex *mutex )
Arguments:

mutex - pointer to mutex to lock

Result:

TRUE it the thread has claimed the lock, FALSE otherwise.

Level:

Thread

Description:

Attempt to lock the mutex pointed to by the mutex argument. If the mutex is already locked by another thread then this thread will wait until that thread is finished. If the result from this function is FALSE then the thread was broken out of its wait by some other thread. In this case the mutex will not have been locked.

cyg_drv_mutex_trylock

Function:
cyg_bool cyg_drv_mutex_trylock( cyg_drv_mutex *mutex )
Arguments:

mutex - pointer to mutex to lock

Result:

TRUE if the mutex has been locked, FALSE otherwise.

Level:

Thread

Description:

Attempt to lock the mutex pointed to by the mutex argument without waiting. If the mutex is already locked by some other thread then this function returns FALSE. If the function can lock the mutex without waiting, then TRUE is returned.

cyg_drv_mutex_unlock

Function:
void cyg_drv_mutex_unlock( cyg_drv_mutex *mutex )
Arguments:

mutex - pointer to mutex to unlock

Result:

None

Level:

Thread

Description:

Unlock the mutex pointed to by the mutex argument. If there are any threads waiting to claim the lock, one of them is woken up to try and claim it.

cyg_drv_mutex_release

Function:
void cyg_drv_mutex_release( cyg_drv_mutex *mutex )
Arguments:

mutex - pointer to mutex to release

Result:

None

Level:

Thread

Description:

Release all threads waiting on the mutex pointed to by the mutex argument. These threads will return from cyg_drv_mutex_lock() with a FALSE result and will not have claimed the mutex. This function has no effect on any thread that may have the mutex claimed.

cyg_drv_cond_init

Function:
 void cyg_drv_cond_init( cyg_drv_cond *cond,
 cyg_drv_mutex *mutex )
	
Arguments:

  • cond—condition variable to initialize

  • mutex—mutex to associate with this condition variable

Result:

None

Level:

Thread

Description:

Initialize the condition variable pointed to by the cond argument. The mutex argument must point to a mutex with which this condition variable is associated. A thread may only wait on this condition variable when it has already locked the associated mutex. Waiting will cause the mutex to be unlocked, and when the thread is reawakened, it will automatically claim the mutex before continuing.

cyg_drv_cond_destroy

Function:
 void cyg_drv_cond_destroy( cyg_drv_cond *cond )
Arguments:

cond - condition variable to destroy

Result:

None

Level:

Thread

Description:

Destroy the condition variable pointed to by the cond argument.

cyg_drv_cond_wait

Function:
void cyg_drv_cond_wait( cyg_drv_cond *cond )
Arguments:

cond - condition variable to wait on

Result:

None

Level:

Thread

Description:

Wait for a signal on the condition variable pointed to by the cond argument. The thread must have locked the associated mutex before waiting on this condition variable. While the thread waits, the mutex will be unlocked, and will be re-locked before this function returns. It is possible for threads waiting on a condition variable to occasionally wake up spuriously. For this reason it is necessary to use this function in a loop that re-tests the condition each time it returns.

cyg_drv_cond_signal

Function:
void cyg_drv_cond_signal( cyg_drv_cond *cond )
Arguments:

cond - condition variable to signal

Result:

None

Level:

DSR

Description:

Signal the condition variable pointed to by the cond argument. If there are any threads waiting on this variable at least one of them will be awakened. Note that in some configurations there may not be any difference between this function and cyg_drv_cond_broadcast().

cyg_drv_cond_broadcast

Function:
void cyg_drv_cond_broadcast( cyg_drv_cond *cond )
Arguments:

cond - condition variable to broadcast to

Result:

None

Level:

DSR

Description:

Signal the condition variable pointed to by the cond argument. If there are any threads waiting on this variable they will all be awakened.

cyg_drv_interrupt_create

Function:
 void cyg_drv_interrupt_create(
 cyg_vector_t vector,
 cyg_priority_t priority,
 cyg_addrword_t data,
 cyg_ISR_t *isr,
 cyg_DSR_t *dsr,
 cyg_handle_t *handle,
 cyg_interrupt *intr
 )
	
Arguments:

  • vector—vector to attach to

  • priority—queueing priority

  • data—data pointer

  • isr—interrupt service routine

  • dsr—deferred service routine

  • handle—returned handle

  • intr—put interrupt object here

Result:

None

Level:

Thread

Description:

Create an interrupt object and returns a handle to it. The object contains information about which interrupt vector to use and the ISR and DSR that will be called after the interrupt object is attached. The interrupt object will be allocated in the memory passed in the intr parameter. The interrupt object is not immediately attached; it must be attached with the cyg_interrupt_attach() call.

cyg_drv_interrupt_delete

Function:
 void cyg_drv_interrupt_delete( cyg_handle_t interrupt )
Arguments:

interrupt—interrupt to delete

Result:

None

Level:

Thread

Description:

Detach the interrupt from the vector and free the memory passed in the intr argument to cyg_drv_interrupt_create() for reuse.

cyg_drv_interrupt_attach

Function:
	void cyg_drv_interrupt_attach( cyg_handle_t interrupt )
	
Arguments:

interrupt—interrupt to attach

Result:

None

Level:

ISR

Description:

Attach the interrupt to the vector so that interrupts will be delivered to the ISR when the interrupt occurs.

cyg_drv_interrupt_detach

Function:
void cyg_drv_interrupt_detach( cyg_handle_t interrupt )
Arguments:

interrupt—interrupt to detach

Result:

None

Level:

ISR

Description:

Detach the interrupt from the vector so that interrupts will no longer be delivered to the ISR.

cyg_drv_interrupt_mask

Function:
void cyg_drv_interrupt_mask(cyg_vector_t vector )
Arguments:

vector—vector to mask

Result:

None

Level:

ISR

Description:

Program the interrupt controller to stop delivery of interrupts on the given vector. On architectures which implement interrupt priority levels this may also disable all lower priority interrupts.

cyg_drv_interrupt_unmask

Function:
	void cyg_drv_interrupt_unmask(cyg_vector_t vector )
	
Arguments:

vector—vector to unmask

Result:

None

Level:

ISR

Description:

Program the interrupt controller to re-allow delivery of interrupts on the given vector.

cyg_drv_interrupt_acknowledge

Function:
	void cyg_drv_interrupt_acknowledge( cyg_vector_t vector )
	
Arguments:

vector—vector to acknowledge

Result:

None

Level:

ISR

Description:

Perform any processing required at the interrupt controller and in the CPU to cancel the interrupt request. An ISR may also need to program the hardware of the device to prevent an immediate re-triggering of the interrupt.

cyg_drv_interrupt_configure

Function:
	void cyg_drv_interrupt_configure(
 cyg_vector_t vector,
 cyg_bool_t level, 
 cyg_bool_t up 
 )
	
Arguments:

  • vector—vector to configure

  • level—level or edge triggered

  • up—rising/falling edge, high/low level

Result:

None

Level:

ISR

Description:

Program the interrupt controller with the characteristics of the interrupt source. The level argument chooses between level- or edge-triggered interrupts. The up argument chooses between high and low level for level triggered interrupts or rising and falling edges for edge triggered interrupts. This function only works with interrupt controllers that can control these parameters.

cyg_drv_interrupt_level

Function:
	void cyg_drv_interrupt_level(
 cyg_vector_t vector,
 cyg_priority_t level
 )
	
Arguments:

  • vector—vector to configure

  • level—level to set

Result:

None

Level:

ISR

Description:

Program the interrupt controller to deliver the given interrupt at the supplied priority level. This function only works with interrupt controllers that can control this parameter.

cyg_ISR_t

Type:
	typedef cyg_uint32 cyg_ISR_t(
 cyg_vector_t vector,
 cyg_addrword_t data
 )
	
Fields:

  • vector—vector being delivered

  • data—data value supplied by client

Result:

Bit mask indicating whether interrupt was handled and whether the DSR should be called.

Description:

Interrupt Service Routines definition. A pointer to a function with this prototype is passed to cyg_interrupt_create() when an interrupt object is created. When an interrupt is delivered the function will be called with the vector number and the data value that was passed to cyg_interrupt_create().

The return value is a bit mask containing one or both of the following bits:

CYG_ISR_HANDLED

indicates that the interrupt was handled by this ISR. It is a configuration option whether this will prevent further ISR being run.

CYG_ISR_CALL_DSR

causes the DSR that was passed to cyg_interrupt_create() to be scheduled to be called.

cyg_DSR_t

Type:
 typedef void cyg_DSR_t(
 cyg_vector_t vector,
 cyg_ucount32 count,
 cyg_addrword_t data
 )
	
Fields:

  • vector—vector being delivered

  • count—number of times DSR has been scheduled

  • data—data value supplied by client

Result:

None

Description:

Deferred Service Routine definition. A pointer to a function with this prototype is passed to cyg_interrupt_create() when an interrupt object is created. When the ISR request the scheduling of its DSR, this function will be called at some later point. In addition to the vector and data arguments, which will be the same as those passed to the ISR, this routine is also passed a count of the number of times the ISR has requested that this DSR be scheduled. This counter is zeroed each time the DSR actually runs, so it indicates how many interrupts have occurred since it last ran.