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头文件:


 
 
  1. #ifndef _GPIO_H
  2. #define _GPIO_H
  3. /* GPIO 引脚 */
  4. typedef enum {
  5. /** Gpio pin 0 */
  6. GPIO_PIN0,
  7. /** Gpio pin 1 */
  8. GPIO_PIN1,
  9. /** Gpio pin 2 */
  10. GPIO_PIN2,
  11. /** Gpio pin 3 */
  12. GPIO_PIN3,
  13. /** Gpio pin 4 */
  14. GPIO_PIN4,
  15. /** Gpio pin 5 */
  16. GPIO_PIN5,
  17. /** Gpio pin 6 */
  18. GPIO_PIN6,
  19. /** Gpio pin 7 */
  20. GPIO_PIN7,
  21. /** Gpio pin 8 */
  22. GPIO_PIN8,
  23. /** Gpio pin 0 */
  24. GPIO_PIN9,
  25. /** Gpio pin 10 */
  26. GPIO_PIN10,
  27. /** Gpio pin 11 */
  28. GPIO_PIN11,
  29. /** Gpio pin 12 */
  30. GPIO_PIN12,
  31. /** Gpio pin 13 */
  32. GPIO_PIN13,
  33. /** Gpio pin 14 */
  34. GPIO_PIN14,
  35. /** Gpio pin 15 */
  36. GPIO_PIN15
  37. } GPIO_PIN;
  38. /* GPIO 方向 */
  39. typedef enum {
  40. GPIO_DIR_OUTPUT, /**<<b>: Output pin</b>*/
  41. GPIO_DIR_INPUT /**<<b>: Input pin</b>*/
  42. } GPIO_DIRCFG;
  43. /* GPIO配置值 */
  44. typedef enum {
  45. GPIO_SET_BIT = 4,
  46. GPIO_CLEAR_BIT = 5
  47. }GPIO_VAl;
  48. int gpio_init();
  49. void gpio_ctl(Uint32 gpioPin, Uint32 val);
  50. #endif



GPIO源文件:


 
 
  1. /* ============================================================================
  2. * Copyright (c) Texas Instruments Inc 2002, 2003, 2004, 2005
  3. *
  4. * Use of this software is controlled by the terms and conditions found
  5. * in the license agreement under which this software has been supplied.
  6. * ============================================================================
  7. */
  8. #include <csl_gpio.h>
  9. #include <csl_intc.h>
  10. #include <stdio.h>
  11. #include <string.h>
  12. #include <csl_intcAux.h>
  13. #include <cslr_dev.h>
  14. #include "gpio.h"
  15. int gpio_init()
  16. {
  17. Bool gpioEn;
  18. /* Unlock the control register */
  19. CSL_FINST(((CSL_DevRegs*)CSL_DEV_REGS)->PERLOCK, DEV_PERLOCK_LOCKVAL,
  20. UNLOCK);
  21. /* Enable the GPIO */
  22. CSL_FINST(((CSL_DevRegs*)CSL_DEV_REGS)->PERCFG0, DEV_PERCFG0_GPIOCTL,
  23. ENABLE);
  24. do {
  25. gpioEn = (Bool) CSL_FEXT(((CSL_DevRegs*)CSL_DEV_REGS)->PERSTAT0,
  26. DEV_PERSTAT0_GPIOSTAT);
  27. } while (gpioEn != TRUE);
  28. return 0;
  29. }
  30. /*
  31. * =============================================================================
  32. * @func gpioInternalLoopbackDemo
  33. *
  34. * @arg
  35. * NONE
  36. *
  37. * @desc
  38. * Gives demo for the internal loopback mechanism for the interrupt path;
  39. * the value sent on a output pin can trigger a Rising or Falling edge
  40. * interrupt.
  41. *
  42. * @return
  43. * NONE
  44. *
  45. * =============================================================================
  46. */
  47. void gpio_ctl(Uint32 gpioPin, Uint32 val)
  48. {
  49. CSL_GpioPinConfig config;
  50. CSL_GpioPinNum pinNum;
  51. CSL_Status status;
  52. CSL_GpioContext pContext;
  53. CSL_GpioObj gpioObj;
  54. CSL_GpioHwSetup hwSetup;
  55. CSL_GpioHandle hGpio;
  56. /* Initialize the GPIO CSL module */
  57. status = CSL_gpioInit(&pContext);
  58. if (status != CSL_SOK) {
  59. printf( "GPIO: Initialization error.\n");
  60. return;
  61. }
  62. /* Open the CSL module */
  63. hGpio = CSL_gpioOpen(&gpioObj, CSL_GPIO, NULL, &status);
  64. if ((hGpio == NULL) || (status != CSL_SOK)) {
  65. printf( "GPIO: Error opening the instance.\n");
  66. return;
  67. }
  68. /* Setup hardware parameters */
  69. hwSetup.extendSetup = NULL;
  70. /* Setup the General Purpose IO */
  71. status = CSL_gpioHwSetup(hGpio, &hwSetup);
  72. /* Configure pin 5 to generate an interrupt on Rising Edge, and
  73. * configure it as an output, then set the data High (Low->High).
  74. * Set Trigger:
  75. */
  76. config.pinNum = gpioPin;
  77. config.direction = GPIO_DIR_OUTPUT;
  78. /* configure the gpio pin */
  79. status = CSL_gpioHwControl(hGpio, CSL_GPIO_CMD_CONFIG_BIT, &config);
  80. if (status != CSL_SOK) {
  81. printf( "GPIO: GPIO pin configuration error.\n");
  82. return;
  83. }
  84. pinNum = gpioPin;
  85. status = CSL_gpioHwControl (hGpio, val, &pinNum);
  86. if (status != CSL_SOK) {
  87. printf( "GPIO: Command to set bit... Failed.\n");
  88. return;
  89. }
  90. status = CSL_gpioClose(hGpio);
  91. if (status != CSL_SOK) {
  92. printf( "GPIO: Unable to Close the instance.[status = 0x%x].\n", status);
  93. }
  94. }


编译工程成功 ,则说明CSL库环境搭建成功






  • 1
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
TMS320C6678是德州仪器(TI)公司推出的一款高性能数字信号处理器(DSP)。它内置多核ARM Cortex-A15和DSP处理器,具有强大的计算能力和高速的通信接口,因此在实现高速数据传输和处理方面具有很大的优势。下面是TMS320C6678以太网通信例程的代码: ```c #include <ti/drv/emac/emac_drv.h> #include <ti/drv/emac/soc/emac_soc_v4.h> #include <ti/csl/cslr_device.h> /* EMAC Configuration Parameters */ #define BOARD_PHY_ADDR (0) #define EMAC_PORT (1) #define EMAC_RX_MAX_CH (1) #define EMAC_TX_MAX_CH (1) #define EMAC_NUM_OF_RX_PKTS (32) #define EMAC_NUM_OF_TX_PKTS (32) #define EMAC_RX_PKT_SIZE (1522) #define EMAC_TX_PKT_SIZE (1522) /* EMAC Driver Handle */ static EMAC_DRV_Handle emacHandle = NULL; /* EMAC RX Queue Handle */ static EMAC_PKT_QUEUE_Handle rxQueueHandle = NULL; /* EMAC TX Queue Handle */ static EMAC_PKT_QUEUE_Handle txQueueHandle = NULL; /* EMAC Packet Buffer Pool */ static uint8_t pktBuf[EMAC_RX_MAX_CH][EMAC_NUM_OF_RX_PKTS * EMAC_RX_PKT_SIZE]; /* EMAC Init */ void emac_init() { EMAC_OPEN_CONFIG_INFO_T emacOpenConfig; EMAC_HwAttrs_V4 cfg; /* Get the default configuration */ EMAC_socGetInitCfg(EMAC_PORT, &cfg); /* Modify the default configuration as needed */ cfg.hwAttrs[0].phyAddr = BOARD_PHY_ADDR; cfg.rxChannel.numRxCps = EMAC_NUM_OF_RX_PKTS; cfg.txChannel.numTxCps = EMAC_NUM_OF_TX_PKTS; cfg.rxChannel.rxFlowCfg[0].cfg.rxMatchEn = 1; cfg.rxChannel.rxFlowCfg[0].cfg.matchEnMask = 0x00000000; /* Set the configuration */ EMAC_socSetInitCfg(EMAC_PORT, &cfg); /* Open the EMAC Driver */ memset(&emacOpenConfig, 0, sizeof(emacOpenConfig)); emacOpenConfig.hwAttrs = (void *)&cfg; emacOpenConfig.mdioBusFreq = EMAC_MDIO_FREQ_INPUT; emacHandle = EMAC_open(EMAC_PORT, EMAC_RX_MAX_CH, EMAC_TX_MAX_CH, &emacOpenConfig); /* Create the RX Queue */ rxQueueHandle = EMAC_pktQueueCreate(emacHandle, EMAC_NUM_OF_RX_PKTS, EMAC_RX_PKT_SIZE, (uint8_t *)&pktBuf[0][0], EMAC_PKT_DESC_SIZE); /* Create the TX Queue */ txQueueHandle = EMAC_pktQueueCreate(emacHandle, EMAC_NUM_OF_TX_PKTS, EMAC_TX_PKT_SIZE, NULL, EMAC_PKT_DESC_SIZE); /* Start the EMAC Driver */ EMAC_start(emacHandle); } int main() { emac_init(); while(1) { /* TODO: Add user code here */ } return 0; } ``` 上述代码,我们首先定义了一些EMAC的配置参数,包括PHY地址、端口、最大RX/TX通道数、RX/TX数据包数量、RX/TX数据包大小等。然后通过EMAC_socGetInitCfg和EMAC_socSetInitCfg函数来获取和修改默认配置。接着我们创建RX和TX队列,并通过EMAC_pktQueueCreate函数创建队列,最后启动EMAC驱动。 当然,上述代码只是EMAC的初始化部分,实际应用还需要编写发送和接收数据包的代码。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值