GPIO_OPEN and CLOSE

来源:互联网 发布:小米盒子直播软件 编辑:程序博客网 时间:2024/05/04 09:51
Resource Management
CSL provides a limited set of functions that enable resourcemanagement for applications which may support multiple algorithms,such as two McBSP or two TIMERs, and may reuse the same type ofperipheral device. Resource management in CSL is achieved throughAPI calls to the PER_open() and  PER_close() functions. The  PER_open()function normally takes a device number and a reset flag as theprimary arguments and returns a pointer to a handle structure thatcontains information about which channel  (DMA) orport (McBSP) was opened, then set “Allocate” flag defined in thehandle structure to 1, meaning the channel or port is in use. Whengiven 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 apointer to a predefined handle structure for this device. If thedevice has already been opened by another process, then an invalidhandle is returned whose value  is equal to theCSL symbolic constant, INV. Note that CSL does nothing otherthan return an invalid handle from PER_open(). You must use this to insure that noresource-usage conflicts occur. It is left to the user to check the value returned from the PER_open() function to guarantee that theresource has been allocated. 

A device/channel may be freed for use by other processes by acall to PER_close() .  PER_close() clears the allocate flag defined under the handlestructure object and resets the device/channel. All CSL modulesthat support multiple devices or channels, such as McBSP and DMA,require a device handle as a primary argument to most APIfunctions. For  these APIs, the definition of aPER_Handle object is required.

Using CSL Handles

Handles  are required only for peripherals that have multiple channels orports, 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 thoseresources by calling the  PER_close() function.The  PER_open() andPER_close()  functions ensure that you do notinitialize the same channel more than once. CSL handleobjects are used to uniquely identify an open peripheralchannel/port or  device. Handle objects must bedeclared in the C source, and initialized by a call to a PER_open() function before calling any other APIfunctions that require a handle object as an argument. PER_open()returns a value of “INV” if the resource is alreadyallocated.
DMA_Handle myDma;
 
Once defined, the CSL handle object is initialized by a callto PER_open .
   
   
  myDma = DMA_open (DMA_CHA0,DMA_OPEN_RESET);
 
The call to  DMA_open initializes the handle, myDma. This handle canthen be
used in calls to other API functions.
  if(myDma != INV) {
DMA_start (myDma);            
   
   
  DMA_close (myDma); }          
原创粉丝点击