DSP 之中断控制(Interrupt)

DSP 之中断控制(Interrupt)DSP 之中断控制 Interrupt Copyright C 2004TexasIns AllRightsRes include include mmc0 从 cslmem 中分配内存 pragmaDATA SECTION mmc0 cslmem MMC Hand

DSP 之中断控制(Interrupt):

DSP 之中断控制(Interrupt)

/* * Copyright (C) 2004 Texas Instruments Incorporated * All Rights Reserved */ #include <csl_mmc.h> #include <stdio.h> /* mmc0 从cslmem中分配内存 */ #pragma DATA_SECTION(mmc0, "cslmem") MMC_Handle mmc0; MMC_CardObj *card, cardalloc; MMC_CardIdObj *cid, cardid; int retVal,count; Uint16 rca; Uint16 cardtype; /* Because of different operating clock frequencies, the Init structure for c5509 * * and c5509a have different values for memory and function clock divide down values */ #if CHIP_5509A /* Native mode Initialization Structure * 本机模式初始化 */ MMC_SetupNative Init = { 0, /* disable DMA for data read/write */ 0, /* Set level of edge detection for DAT3 pin */ 0, /* Determines if MMC goes IDLE during IDLE instr */ 1, /* Memory clk reflected on CLK Pin */ 7, /* CPU CLK to MMC function clk divide down */ 5, /* MMC function clk to memory clk divide down */ 0, /* No. memory clks to wait before response timeout */ 0, /* No. memory clks to wait before data timeout */ 512, /* Block Length must be same as CSD */ }; #else MMC_SetupNative Init = { 0, /* disable DMA for data read/write */ 0, /* Set level of edge detection for DAT3 pin */ 0, /* Determines if MMC goes IDLE during IDLE instr */ 1, /* Memory clk reflected on CLK Pin */ 3, /* CPU CLK to MMC function clk divide down */ 3, /* MMC function clk to memory clk divide down */ 0, /* No. memory clks to wait before response timeout */ 0, /* No. memory clks to wait before data timeout */ 512, /* Block Length must be same as CSD */ }; #endif /* read with write function allocate in .text */ #pragma CODE_SECTION(read_interrupt,".text") #pragma CODE_SECTION(write_interrupt,".text") /* These are the interrupts to be called for each write and read */ void read_interrupt(); void write_interrupt(); /* * * How MMC interrupts work. * * MMC Registers for interrupts * - MMCIE : MMC Interrupt Enable Register * - MMCST0: MMC Status 0 Register * * Structures * - MMC_CallBackObj : Has the call back table for interrupts for different * MMC operations * * Functions * - MMC_dispatch0 : * - MMC_dispatch1 : Functions plugged in to service the MMC interrupt * generated by the CPU * - MMC_setCallBack : Sets the functions to be called as ISRs for MMC * events (e.g. read, write interrupts) into the * MMC_CallBackObj structure * - MMC_intEnable : Write to the MMCIE to enable the interrupt for a * particular MMC event * * Working * The MMC device (in this case device 1) has an associated MMC_dispatch function * (defined in mmc_disp1.c) which is the ISR. This is plugged in to service * interrupts for the MMC. When an interrupt is triggered, the MMC_dispatch checks * the MMCIE and MMCST0 and decodes which event (read, write, etc.) the MMC interrupt * is triggered for and calls the service function for the event from the entries in * the call back structure. * */ #pragma DATA_SECTION(cback, ".csldata"); /* Call back structure: This holds the functions to be called when an interrupt for a * particular MMC event is triggered */ MMC_CallBackObj cback = { (MMC_CallBackPtr)0x0000, /* Callback for Data Transfer Done */ (MMC_CallBackPtr)0x0000, /* Callback for Busy Done */ (MMC_CallBackPtr)0x0000, /* Callback for response Done */ (MMC_CallBackPtr)0x0000, /* Callback for Read-data time-out */ (MMC_CallBackPtr)0x0000, /* Callback for Response time-out */ (MMC_CallBackPtr)0x0000, /* Callback for write-data CRC error */ (MMC_CallBackPtr)0x0000, /* Callback for read-data CRC error */ (MMC_CallBackPtr)0x0000, /* Callback for response CRC error */ (MMC_CallBackPtr)0x0000, /* This is never used */ write_interrupt, /* Callback for data xmt ready */ read_interrupt, /* Callback for data rcv ready */ (MMC_CallBackPtr)0x0000 /* Callback for DAT3 edge */ } ; volatile int reads_done = 0; volatile int writes_done = 0; Uint16 datasend[512]; Uint16 datareceive[512]; /* Function to be called on data receive ready */ void read_interrupt(void) { ++reads_done; return; } /* Function to be called on data transmit ready */ void write_interrupt(void) { ++writes_done; return; } void main() { Uint16 old_intm; /* CSL libary initialize */ CSL_init(); /* Clear all interrupt register */ IRQ_globalDisable(); /* Set interrupt vector table */ IRQ_setVecs(0x10000); printf ("\nStarting interrupt test...\n"); /* Fill in source and destination buffers */ for (count=0; count<=256; count++) { datasend[count] = count; datareceive[count] = 0xFFFF; } /* Refer to mmc_setup example for explanation * Reserves the MMC device as specified by device */ mmc0 = MMC_open(MMC_DEV1); /* Native mode Initialization Structure */ MMC_setupNative(mmc0,&Init); /* Sends a broadcast GO_IDLE command */ MMC_sendGoIdle(mmc0); for (retVal=0; retVal<4016; retVal++) asm(" NOP"); /* Sets the operating voltage window while in Native mode * 设置操作电压窗口,为本机模式 */ cardtype = MMC_sendOpCond(mmc0,0x00); if (cardtype == 0xFFFF){ printf ("Card not recognized\n"); exit(0); } if (cardtype == MMC_CARD){ cid = &cardid; /* Sends a broadcast command to all cards to identify themselves */ MMC_sendAllCID(mmc0,cid); // get the CID structure for all cards. card = &cardalloc; /* Sets the relative card address of an attatched memory card */ retVal = MMC_setRca(mmc0,card,10); } else { cid = &cardid; /* Sends a broadcast command to all cards to identify themselves */ SD_sendAllCID(mmc0,cid); // get the CID structure for all cards. card = &cardalloc; /* Sets the relative card address of an attatched memory card */ rca = SD_sendRca(mmc0,card); printf ("RCA sent is 0x%x\n", rca); } /* Refer to mmc_setup example for explanation of the above code */ /* Fill in the handle's callback function structure with contents of the cback * * structure. These will be the functions called when the MMC interrupt occurs * 给中断安装调度程序 */ MMC_setCallBack(mmc0, &cback); /* Write to the MMCIE register to enable interrupts for particular events * 0x200 enables an interrupt on data transmit ready * Enables interrupts by writing to the MMCIE register */ MMC_intEnable(mmc0, 0x200); /* IRQ Enable interrupt register */ IRQ_globalEnable(); /* pick the card to transfer data to/from */ retVal = MMC_selectCard(mmc0, card); /* start data write. mmc_read_write example provides a more detailed explanation */ printf ("Writing data to card...\n"); /* Writes a block of data to a pre-selected memory card */ retVal = MMC_write(mmc0, /* MMC Handle returned by call to MMC_open */ 0x00000000,/* Address on card where read begins */ datasend, /* Pointer to buffer where received data should be stored */ 512); /* number of bytes to store in buffer */ for (retVal = 0; retVal <= 256; ++retVal) asm(" NOP"); /* Globally disables interrupts */ old_intm = IRQ_globalDisable(); /* Enable interrupts for data recieve ready now */ MMC_intEnable(mmc0, 0x400); /* Restores the global interrupt mask state */ IRQ_globalRestore(old_intm); /* delay before we start reading the data */ for (retVal = 0; retVal <= 25000; ++retVal) asm(" NOP"); for (retVal = 0; retVal <= 25000; ++retVal) asm(" NOP"); #if CHIP_5509A /* This requires a longer delay */ for (retVal = 0; retVal <= 25000; ++retVal) asm(" NOP"); for (retVal = 0; retVal <= 25000; ++retVal) asm(" NOP"); #endif printf ("Reading data from card...\n"); /* Reads a block of data from a pre-selected memory card */ retVal = MMC_read(mmc0,0x00000000,datareceive,512); /* check if data has been tranmitted and received correctly */ for (count = 0; count < 256; ++count) if (datasend[count] != datareceive[count]) break; if (count < 256) printf ("\nNot all data was transferred/read successfully!\n"); else printf ("\nData transfer successful\n"); if (writes_done != 256) printf ("Not all data writes triggered interrupts\n"); else printf ("Interrupts triggered for each data transmit ready\n"); if (reads_done != 256) printf ("Not all data reads triggered interrupts\n"); else printf ("Interrupts triggered for each data receive ready\n"); if ((reads_done == 256) && (writes_done == 256)) printf ("TEST PASSED"); else printf ("TEST FAILED"); } 
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/232447.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • matlab之极坐标绘图函数_如何用极坐标画图

    matlab之极坐标绘图函数_如何用极坐标画图阅读数:5134转发:https://blog.csdn.net/Sumujingling/article/details/50884209目标是要绘制一个二维的极坐标彩色图。输入参数有三个,一个是角度,一个是半径,一个是颜色。说到极坐标绘图,第一个想到的就是polar啦~那就先试试吧!1.polar绘图polar函数用来绘制极坐标图,调用格式为:polar(theta,rho,选项)其中,the…

    2025年7月29日
    6
  • 源码免杀教程 源码免杀思路详解

    绝对不一样的源码免杀教程!绝对不一样的免杀实战体验!清晰的思路!细致全面的思路详解!让你感到免杀原来可以这么简单!教你如何在源代码中找出被杀代码,修改代码从而达到免杀效果!免杀之-网络攻防入门书籍推荐《精通黑客免杀》一部关于黑客免杀技术的书籍,学习各种免杀,躲避杀毒软件的追杀,为自己的马放下一道赦免令。目前国内关于黑客免杀技术的书籍应该很少的,大致可以说是没有。在本书中所介绍的启发式扫描免杀…

    2022年4月4日
    362
  • 物联网数据采集

    物联网数据采集大致方案为:硬件采集数据(包含采集协议和通讯协议)硬件与网络通讯(传输数据和传输方式)网络前端的显示和展示1、硬件采集数据我们现在用到的传感器大都是有固定通讯协议的,例如串口通讯(https://blog.csdn.net/qq_36629451/article/details/76038673),模拟量与数据量的直接读取(需要硬件设备留有相应的接口)…

    2022年5月15日
    41
  • linux中mknod_linux命令解析器

    linux中mknod_linux命令解析器个人觉得linux的软件设计思想异常强大,比如把所有的设备都当做文件来处理,大大简化了程序员的负担,向提出这个思想的大神s致敬!!先来看看linux系统中设备管理的基本知识:     我们的linux操作系统跟外部设备(如磁盘、光盘等)的通信都是通过设备文件进行的,应用程序可以打开、关闭、读写这些设备文件,从而对设备进行读写,这种操作就像读写普通的文件一样easy。linux为不同种类的…

    2025年8月12日
    3
  • 基础工具之消息队列、线程池、缓冲区抽象、事件循环和日志实现

    正所谓“工欲善其事,必先利其器”,我们在实现通信设计任务的过程中需要一些基础工具来帮助我们搭建部分基础组件,这些基础工具包括消息队列,线程池,缓冲区抽象,事件循环和日志工具。接下来对这部分基础工具进

    2021年12月28日
    42
  • 网站防攻击

    网站防攻击网站如何防御DDos攻击和CC攻击?网站如何防御DDoS攻击和CC攻击?如果网站所在的服务器不是高仿服务器,一旦遭遇DDos攻击或大量的CC攻击,那么自己的网站很有可能会处于瘫痪状态,甚至会引起服务器所在的整个机房服务器受影响,自己的服务器则很有可能陷入“黑洞”或者机房管理员暂时封闭IP,给网站拥有者带来严重的影响。一、网站为什么会遭遇DDos攻击或CC攻击?网站之所以会遭受DDo…

    2022年6月15日
    40

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号