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)
上一篇 2025年10月11日 上午8:01
下一篇 2025年10月11日 上午8:22


相关推荐

  • 源码剖析signal和sigaction的区别[通俗易懂]

    源码剖析signal和sigaction的区别[通俗易懂]这两个函数都是Linux下注册信号处理函数有关,但是它们的区别一般我们都是从书上、网上、man手册得知,要想对它们的区别了然于胸,源码剖析才是彻底的方法。先来看这两个函数的区别和实验:1、signal比sigaction简单,但signal注册的信号在sa_handler被调用之前把会把信号的sa_handler指针恢复,而sigaction注册的信号在处理信号时不会恢复sa_handle

    2022年5月9日
    93
  • GAN网络详解(从零入门)

    GAN网络详解(从零入门)从一个小白的方式理解 GAN 网络 生成对抗网络 可以认为是一个造假机器 造出来的东西跟真的一样 下面开始讲如何造假 主要讲解 GAN 代码 代码很简单 我们首先以造小狗的假图片为例 首先需要一个生成小狗图片的模型 我们称之为 generator 还有一个判断小狗图片是否是真假的判别模型 discrimator 首先输入一个 1000 维的噪声 然后送入生成器 生成器的具体结构如下所示 不看也

    2026年3月19日
    2
  • c语言typedef struct

    c语言typedef struct结构 typedefstruc structaaa p bbb typedefstruc bbb 两者没有什么区别都是定义 bbb 为结构别名 第二种定义的时候短一点 更好用 但是如果定义的结构内部需要有一个结构本身的结构指针则需要用第一种 typedefstruc intaaa bbb bbb b1 b1 gt aaa 1 bbbb2 b2 a

    2026年3月17日
    2
  • ora 12154: tns: could not resolve the connect identifier specified问题的一种解决方法

    ora 12154: tns: could not resolve the connect identifier specified问题的一种解决方法
     
    开发环境:VS2010,Oracle10gXE.
     
    不熟悉C#连接Oracle数据库,从Baidu上Copy了一段相关代码,谁知道这么悲剧,还得我调了三天……
     
    先贴上害我不浅的小小两行代码:

    stringConnectionString=”DataSource=oraDB;User=Username;Password=Password”;//连接字符串 
     
     OracleConn

    2022年7月19日
    24
  • 🔥文心一言制作PPT教程,小白也能轻松上手!建议收藏

    🔥文心一言制作PPT教程,小白也能轻松上手!建议收藏

    2026年3月12日
    2
  • 总结一下SQL语句中引号()、quotedstr()、()、format()在SQL语句中的用法[通俗易懂]

    总结一下SQL语句中引号()、quotedstr()、()、format()在SQL语句中的用法[通俗易懂]ViewCode总结一下SQL语句中引号(”)、quotedstr()、(””)、format()在SQL语句中的用法以及SQL语句中日期格式的表示(#)、(””)在Delphi中进行字符变量连接相加时单引号用(”””),又引号用(””””)表示首先定义变量varAnInt:integer=123;//为了方便在此都给它们赋初值。虽然可能在引赋初值在…

    2022年10月17日
    2

发表回复

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

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