GPIO_OPEN and CLOSE

本文详细介绍了CSL中实现资源管理的方法,包括使用PER_open()和PER_close()函数来打开和关闭设备通道,确保资源不被重复初始化,并通过CSL handles管理多个通道或端口的资源。实例展示了如何初始化、使用和释放DMA通道。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 .
   
   
  myDma = DMA_open (DMA_CHA0, DMA_OPEN_RESET);
 
The call to   DMA_open   initializes the handle, myDma. This handle can then be
used in calls to other API functions.
  if(myDma != INV) {
DMA_start (myDma);              
   
   
  DMA_close (myDma); }            
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值