CCS V5中使用CSL库的方法 基于TMS320C6455讲解
前言:
芯片支持库(CSL)提供了一个用于配置和控制片上外设的C语言接口。它有各个分立的模块组成,并被编译成为库文件。每个模块对应一个单独的外设,除了个别提供通用程序支持的模块。使用CSL可以方便片上外设的使用,缩短开发周期,提高程序的可移植性,硬件抽象。
1.CSL库的下载
下载地址:http://processors.wiki.ti.com/index.php/Chip_support_library?keyMatch=CSL&tisearch=Search-CN-Everything
下载完成并解压重命名为CSL。
注意:这里应该选择对应系列和型号的DSP芯片支持库(CSL),这里是以TMS320C6455为例
2.在CCS5.2中指定头文件路径
具体路径更具个人情况而定。
本例路劲为E:\CSL\03.00.10.02\6455\6455_default_package\default_package\csl_c6455\inc
E:\CSL\03.00.10.02\6455\6455_default_package\default_package\csl_c64xplus_intc\inc
设置如图所示:
3.在CCS5.2中指定库文件路径
TMS320C6455需要的CSL库有csl_c64xplus_intc.lib和csl_c6455.lib
本例路径为:E:\CSL\03.00.10.02\6455\6455_default_package\default_package\csl_c6455\lib
E:\CSL\03.00.10.02\6455\6455_default_package\default_package\csl_c64xplus_intc\lib
设置如图所示:
4.在CCS5.2中设置预定义符号
对于TMS320C6455所需要的预定义符号有CHIP_C6455和_INCLUDE_NIMU_CODE
设置如图所示:
5.下面给出一个TMS320C6455GPIO的CSL使用代码
GPIO头文件:
#ifndef _GPIO_H
#define _GPIO_H
/* GPIO 引脚 */
typedef enum {
/** Gpio pin 0 */
GPIO_PIN0,
/** Gpio pin 1 */
GPIO_PIN1,
/** Gpio pin 2 */
GPIO_PIN2,
/** Gpio pin 3 */
GPIO_PIN3,
/** Gpio pin 4 */
GPIO_PIN4,
/** Gpio pin 5 */
GPIO_PIN5,
/** Gpio pin 6 */
GPIO_PIN6,
/** Gpio pin 7 */
GPIO_PIN7,
/** Gpio pin 8 */
GPIO_PIN8,
/** Gpio pin 0 */
GPIO_PIN9,
/** Gpio pin 10 */
GPIO_PIN10,
/** Gpio pin 11 */
GPIO_PIN11,
/** Gpio pin 12 */
GPIO_PIN12,
/** Gpio pin 13 */
GPIO_PIN13,
/** Gpio pin 14 */
GPIO_PIN14,
/** Gpio pin 15 */
GPIO_PIN15
} GPIO_PIN;
/* GPIO 方向 */
typedef enum {
GPIO_DIR_OUTPUT,/**<: Output pin*/
GPIO_DIR_INPUT /**<: Input pin*/
} GPIO_DIRCFG;
/* GPIO配置值 */
typedef enum {
GPIO_SET_BIT = 4,
GPIO_CLEAR_BIT = 5
}GPIO_VAl;
int gpio_init();
void gpio_ctl(Uint32 gpioPin, Uint32 val);
#endif
GPIO源文件:
/* ============================================================================
* Copyright (c) Texas Instruments Inc 2002, 2003, 2004, 2005
*
* Use of this software is controlled by the terms and conditions found
* in the license agreement under which this software has been supplied.
* ============================================================================
*/
#include
#include
#include
#include
#include
#include
#include "gpio.h"
int gpio_init()
{
Bool gpioEn;
/* Unlock the control register */
CSL_FINST(((CSL_DevRegs*)CSL_DEV_REGS)->PERLOCK, DEV_PERLOCK_LOCKVAL,
UNLOCK);
/* Enable the GPIO */
CSL_FINST(((CSL_DevRegs*)CSL_DEV_REGS)->PERCFG0, DEV_PERCFG0_GPIOCTL,
ENABLE);
do {
gpioEn = (Bool) CSL_FEXT(((CSL_DevRegs*)CSL_DEV_REGS)->PERSTAT0,
DEV_PERSTAT0_GPIOSTAT);
} while (gpioEn != TRUE);
return 0;
}
/*
* =============================================================================
* @func gpioInternalLoopbackDemo
*
* @arg
* NONE
*
* @desc
* Gives demo for the internal loopback mechanism for the interrupt path;
* the value sent on a output pin can trigger a Rising or Falling edge
* interrupt.
*
* @return
* NONE
*
* =============================================================================
*/
void gpio_ctl(Uint32 gpioPin, Uint32 val)
{
CSL_GpioPinConfig config;
CSL_GpioPinNum pinNum;
CSL_Status status;
CSL_GpioContext pContext;
CSL_GpioObj gpioObj;
CSL_GpioHwSetup hwSetup;
CSL_GpioHandle hGpio;
/* Initialize the GPIO CSL module */
status = CSL_gpioInit(&pContext);
if (status != CSL_SOK) {
printf("GPIO: Initialization error.\n");
return;
}
/* Open the CSL module */
hGpio = CSL_gpioOpen(&gpioObj, CSL_GPIO, NULL, &status);
if ((hGpio == NULL) || (status != CSL_SOK)) {
printf("GPIO: Error opening the instance.\n");
return;
}
/* Setup hardware parameters */
hwSetup.extendSetup = NULL;
/* Setup the General Purpose IO */
status = CSL_gpioHwSetup(hGpio, &hwSetup);
/* Configure pin 5 to generate an interrupt on Rising Edge, and
* configure it as an output, then set the data High (Low->High).
* Set Trigger:
*/
config.pinNum = gpioPin;
config.direction = GPIO_DIR_OUTPUT;
/* configure the gpio pin */
status = CSL_gpioHwControl(hGpio, CSL_GPIO_CMD_CONFIG_BIT, &config);
if (status != CSL_SOK) {
printf("GPIO: GPIO pin configuration error.\n");
return;
}
pinNum = gpioPin;
status = CSL_gpioHwControl (hGpio, val, &pinNum);
if (status != CSL_SOK) {
printf("GPIO: Command to set bit... Failed.\n");
return;
}
status = CSL_gpioClose(hGpio);
if (status != CSL_SOK) {
printf("GPIO: Unable to Close the instance.[status = 0x%x].\n", status);
}
}
编译工程成功 ,则说明CSL库环境搭建成功