Resource Management
CSL provides a limited set of functions that enable resource management for applications which may support multiple algorithms, such as two McBSP or two TIMERs, and may reuse the same type of peripheral device. Resource management in CSL is achieved through API calls to the PER_open() and
PER_close()
functions. The
PER_open() function normally takes a device number and a reset flag as the primary arguments and returns a pointer to a handle structure that contains information about which channel
(DMA) or port (McBSP) was opened, then set “Allocate” flag defined in the handle structure to 1, meaning the channel or port is in use. When given a specific device number, the open function checks a global “allocate” flag to determine its availability.
If the device/channel is available, then it returns a pointer to a predefined handle structure for this device. If the device has already been opened by another process, then an invalid handle is returned whose value is equal to the CSL symbolic constant, INV. Note that CSL does nothing other than return an invalid handle from PER_open().
You must use this to insure that no resource-usage conflicts occur. It is left to the user to check
the value returned from the
PER_open() function to guarantee that the resource has been allocated.
A device/channel may be freed for use by other processes by a call to PER_close() .
PER_close()
clears the allocate flag defined under the handle structure object and resets the device/channel. All CSL modules that support multiple devices or channels, such as McBSP and DMA, require a device handle as a primary argument to most API functions. For
these APIs, the definition of a PER_Handle object is required.
Using CSL Handles
Handles
are required
only for peripherals that have multiple channels or ports, such as DMA, EDMA, GPIO, McBSP, TIMER, I2C, and VP. You obtain a handle by calling the
PER_open() function.
When you no longer need a particular channel, free those resources by calling the
PER_close() function.
The PER_open() and PER_close() functions ensure that you do not initialize the same channel more than once. CSL handle objects are used to uniquely identify an open peripheral channel/port or
device. Handle objects must be declared in the C source, and initialized by a call to a
PER_open() function before calling any other API functions that require a handle object as an argument. PER_open() returns a value of “INV” if the resource is already allocated.
DMA_Handle myDma;
Once defined, the CSL handle object is initialized by a call to PER_open .
The call to
DMA_open
initializes the handle, myDma. This handle can then be
used in calls to other API functions.
DMA_start (myDma);