This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
最近在用28388的以太网接口与电脑通信。由于以太网只能用CM核心访问,所以得实现从CPU到CM核的通信。
C2000ware例程里面ex1是从CPU1发送指令到CM。调试时候发现直接换成CM到CPU1会有一些问题。
感觉注释写的挺详细的。就不过多解释了。给需要的人参考一下。
CPU1的代码:
//############################################################################# //此文件改编于F28388的C2000ware的IPC例程ex1 //原文件是从CPU1发指令到CM。此文件从CM发指令到CPU1 // FILE: ipc_ex1_basic_c28x1.c // // TITLE: IPC example with interrupt // //! \addtogroup driver_cm_c28x_dual_example_list //! <h1> IPC basic message passing example with interrupt </h1> //! //! This example demonstrates how to configure IPC and pass information from //! C28x to CM core without message queues. //! It is recommended to run the C28x1 core first, followed by the CM core. //! //! \b External \b Connections \n //! - None. //! //! \b Watch \b Variables \n //! - pass //! // //############################################################################# // $Copyright: // Copyright (C) 2022 Texas Instruments Incorporated - http://www.ti.com // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions // are met: // // Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the // distribution. // // Neither the name of Texas Instruments Incorporated nor the names of // its contributors may be used to endorse or promote products derived // from this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // $ //########################################################################### // // Included Files // #include "driverlib.h" #include "device.h" // // 定义了两个指令数字,其实是随机的。文件里只用到了IPC_CMD_READ_MEM // #define IPC_CMD_READ_MEM 0x1001 #define IPC_CMD_RESP 0x2001 //就是俩指示符 #define TEST_PASS 0x5555 #define TEST_FAIL 0xAAAA //IPC传输位32位数字。这里定义32问数组,大小为10 uint32_t readData[10]; uint32_t pass; uint32_t data;//data为readData[10]长度,这里应该是10 // __interrupt void IPC_ISR0() { uint8_t i; uint32_t command, addr; bool status = false; // // CPU1从CM读取指令。由于CPU1和CM内核共享区域不是共用地址的,所以得enable correction // command读出来的就是IPC_CMD_READ_MEM // addr是转化过来的存储数据的起始地址 // data是数组长度 // IPC_readCommand(IPC_CPU1_L_CM_R, IPC_FLAG1, IPC_ADDR_CORRECTION_ENABLE, &command, &addr, &data); if(command == IPC_CMD_READ_MEM)//如果读出来的指令是IPC_CMD_READ_MEM { status = true;//把状态定义为true // // 由于读到的数据是起始位addr,32位数据,data长度的数组 // 以下操作吧数据写进read // 可以用CCS的watch variable实时观察数据变化 // for(i=0; i<data; i++) { readData[i] = *((uint32_t *)addr + i); } } // // 将读数正确或者错误信息返回给CM // if(status) { IPC_sendResponse(IPC_CPU1_L_CM_R, TEST_PASS); } else { IPC_sendResponse(IPC_CPU1_L_CM_R, TEST_FAIL); } // // Acknowledge the flag // IPC_ackFlagRtoL(IPC_CPU1_L_CM_R, IPC_FLAG1); //这个是必须得加的。接收中断如果在CM里面,不用有这句 //如果接收中断在C28x内核(CPU1和CPU2),就得加上这句 Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP11); } // // Main // void main(void) { // // Initialize device clock and peripherals // Device_init(); // // Boot CM core // #ifdef _FLASH Device_bootCM(BOOTMODE_BOOT_TO_FLASH_SECTOR0); #else Device_bootCM(BOOTMODE_BOOT_TO_S0RAM); #endif // // Initialize PIE and clear PIE registers. Disables CPU interrupts. // Interrupt_initModule(); // // Initialize the PIE vector table with pointers to the shell Interrupt // Service Routines (ISR). // Interrupt_initVectorTable(); // // Clear any IPC flags if set already // IPC_clearFlagLtoR(IPC_CPU1_L_CM_R, IPC_FLAG_ALL); // // Enable IPC interrupts // IPC_registerInterrupt(IPC_CPU1_L_CM_R, IPC_INT1, IPC_ISR0); // // Synchronize both the cores. // IPC_sync(IPC_CPU1_L_CM_R, IPC_FLAG31); // // Enable Global Interrupt (INTM) and realtime interrupt (DBGM) // EINT; ERTM; // // End of example. Loop forever // while(1) { } } // // End of File //
CM代码
//############################################################################# ////此文件改编于F28388的C2000ware的IPC例程ex1 //原文件是从CPU1发指令到CM。此文件从CM发指令到CPU1 // FILE: ipc_ex1_basic_cm.c // // TITLE: IPC example with interrupt // //! \addtogroup driver_cm_c28x_dual_example_list //! <h1> IPC basic message passing example with interrupt </h1> //! //! This example demonstrates how to configure IPC and pass information from //! C28x to CM core without message queues //! It is recommended to run the C28x1 core first, followed by the CM core. //! //! \b External \b Connections \n //! - None. //! //! \b Watch \b Variables \n //! - None. //! // //############################################################################# // $Copyright: // Copyright (C) 2022 Texas Instruments Incorporated - http://www.ti.com // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions // are met: // // Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the // distribution. // // Neither the name of Texas Instruments Incorporated nor the names of // its contributors may be used to endorse or promote products derived // from this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // $ //########################################################################### // // Included Files // #include "cm.h" #include "ipc.h" // // 定义了两个指令数字,其实是随机的。文件里只用到了IPC_CMD_READ_MEM // #define IPC_CMD_READ_MEM 0x1001 #define IPC_CMD_RESP 0x2001 #define TEST_PASS 0x5555 #define TEST_FAIL 0xAAAA //readData是要传输给CPU1的数据。要注意数组长度。MSGRAM_CM_TO_CPU1内存长度只有800 uint32_t readData[10]={11,12,13,14,15,16,17,18,19,20}; //MSGRAM_CM_TO_CPU1是从cmd文件里面查出来的 //这是把readData的首地址放到了MSGRAM_CM_TO_CPU1内存块里面 //由于要进行地址变换,这句话是放在发送的那个核心里面。 #pragma DATA_SECTION(readData, "MSGRAM_CM_TO_CPU1") // // Main // void main(void) { int i; uint32_t pass; // // Initialize device clock and peripherals // CM_init(); // // Loop forever. Wait for IPC interrupt // IPC_clearFlagLtoR(IPC_CM_L_CPU1_R, IPC_FLAG_ALL); // // Synchronize both the cores. // IPC_sync(IPC_CM_L_CPU1_R, IPC_FLAG31); // // Enable Global Interrupt (INTM) and realtime interrupt (DBGM) // // // 循环发送数字给CPU1 // while(1) { SysCtl_delay(6000000);//等待一下,要不然发送太频繁了 // // CM往CPU1发送数字。由于CPU1和CM内核共享区域不是共用地址的,所以得enable correction // addr是转化过来的存储数据的起始地址 // readData传输的是首地址 // 10是readData数组长度 // IPC_sendCommand(IPC_CM_L_CPU1_R, IPC_FLAG1, IPC_ADDR_CORRECTION_ENABLE, IPC_CMD_READ_MEM, (uint32_t)readData, 10); // // Wait for acknowledgment // IPC_waitForAck(IPC_CM_L_CPU1_R, IPC_FLAG1); // // Read response // if(IPC_getResponse(IPC_CM_L_CPU1_R) == TEST_PASS) { pass = 1; } else { pass = 0; } //持续让数据增加 //这样就可以用CCS的watch variable实时观察数据变化,判断程序是否持续运行 for(i=0; i<10; i++) { readData[i]++; } } } // // End of File //