【问题标题】:How to change an array from a different file in my C code?如何从我的 C 代码中的不同文件更改数组?
【发布时间】:2021-10-06 06:22:00
【问题描述】:

我有两个单独的 C 文件,我需要更改一个名为 NDEF.C 的文件中的 const u08_t NFC_NDEF_Message。这个文件没有导入到我的 main.C 中,但是当它被调用时,void initISO15693(u16_t parameters ),它会进入另一个文件。我不明白这是怎么回事。我需要更改 NDEF 消息,但我不知道在主代码中的何处以及如何访问它。任何帮助,将不胜感激。这两个文件将在下面。

main.c:

/*
 * main.c
 *
 * RF430FRL152H NFC Only Example Project
 *
 * Copyright (C) 2014 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.
 *
*/

#include "NDEF.h"
#include "types.h"
#include "patch.h"
#include <rf430frl152h.h>

//*****************************FUNCTION PROTOTYPES********************************/
void DeviceInit(void);
//********************************************************************************/

/*********************** SUMMARY **************************************************************************************************
 * This project *only* utilizes the RF stack (ISO15693) on the ROM of the RF430FRL15xH. This setup allows the user to make a
 * custom application that is run from FRAM.  Only the RF13M vector that runs the RF stack needs to be pointing to its
 * ROM location.
 */

 /**************************************************************************************************************************************************
*   Code Space
***************************************************************************************************************************************************
*
*  Please check the lnk_rf430frl152h_NFC_Only.cmd file to customize how much code space is used for NDEF message ("FRAM_NDEF")
*  or for code ("FRAM_CODE").  
*
**************************************************************************************************************************************************/

/**************************************************************************************************************************************************
*   Main
***************************************************************************************************************************************************
*
* Brief :       Program entry.
*
* Param[in] :   None
*
*
* Param[out]:   None
*
* Return :
*
**************************************************************************************************************************************************/

void main()
{
    WDTCTL = WDTPW + WDTHOLD;                   // Stop watchdog

    // ROM RF13M module setup ** The following three lines are needed for proper RF stack operation
    DS = 1;                                     // ROM variable needs to be initialized here
    asm ( " CALL #0x5CDA ");                    // Call ROM function ( Initialize function pointers)
    asm ( " CALL #0x5CAC ");                    // Call ROM function ( Check part configuration)


    initISO15693(CLEAR_BLOCK_LOCKS);  // clear all block locks
    //initISO15693(0);                  // leave block locks as they are set in FRAM

    //JTAG is set to be disabled in this function call
    DeviceInit();

    while(1)
    {
        // Enter application code here...
        __bis_SR_register(LPM3_bits + GIE);

    }
}

/**************************************************************************************************************************************************
*  DeviceInit
***************************************************************************************************************************************************
*
* Brief : Initialize the clock system and other settings
*         Patchable function
*
* Param[in] :   parameters:  has these independent options
*                            INITIALIZE_DEVICE_CLOCK_SYSTEM - initializes the clock system
*                            POPULATE_INTERRUPT_VECTOR_IN_INITIALIZATION - populate the default interrupt vectors and recalculate their CRC
*
* Param[out]:  None
*
* Return  None
*
* Patchable :   Yes
**************************************************************************************************************************************************/
void DeviceInit(void)
{
//  P1SEL0 = 0xF0; //keep JTAG
//  P1SEL1 = 0xF0; //keep JTAG
    P1SEL0 = 0x00; //no JTAG
    P1SEL1 = 0x00; //no JTAG

    P1DIR &= ~0xEF;
    P1REN = 0;

    CCSCTL0 = CCSKEY;                        // Unlock CCS

    CCSCTL1 = 0;                             // do not half the clock speed
    CCSCTL4 = SELA_1 + SELM_0 + SELS_0;      // Select VLO for ACLK and select HFCLK/DCO for MCLK, and SMCLK
    CCSCTL5 = DIVA_2 + DIVM_1 + DIVS_1;      // Set the Dividers for ACLK (4), MCLK, and SMCLK to 1
    CCSCTL6 = XTOFF;                         // Turns of the crystal if it is not being used
    CCSCTL8 = ACLKREQEN + MCLKREQEN + SMCLKREQEN; //disable clocks if they are not being used

    CCSCTL0_H |= 0xFF;                       // Lock CCS

  return;
}



//#pragma vector = RFPMM_VECTOR
//__interrupt void RFPMM_ISR(void)
//{
//}
//
//#pragma vector = PORT1_VECTOR
//__interrupt void PORT1_ISR(void)
//{
//}
//
//#pragma vector = SD_ADC_VECTOR
//__interrupt void SD_ADC_ISR(void)
//{
//}
//
//#pragma vector = USCI_B0_VECTOR
//__interrupt void USCI_B0_ISR(void)
//{
//}
//#pragma CODE_SECTION(RF13M_ISR, ".fram_driver_code")  // comment this line for using ROM's RF13M ISR, uncomment next one, see .cmd file for details
#pragma CODE_SECTION(RF13M_ISR, ".rf13m_rom_isr")       // comment this line for creating a custom RF13M ISR that will exist in FRAM, bypassing ROM's, uncomment previous
#pragma vector = RF13M_VECTOR
__interrupt void RF13M_ISR(void)
{
    // Right now this vector is pointing to the ROMs firmware location that runs the RF stack. 
    // Entering code here will, without changing the CODE_SECTION lines
    // above, will cause an error.
    // Changing the code section above will cause the ROM RF stack to be bypassed.  New handler will need to be created.
}

//#pragma vector = WDT_VECTOR
//__interrupt void WDT_ISR(void)
//{
//}
//
//#pragma vector = TIMER0_A1_VECTOR
//__interrupt void TimerA1_ISR(void)
//{
//}
//
//#pragma vector = TIMER0_A0_VECTOR
//__interrupt void TimerA0_ISR(void)
//{
//}
//
//#pragma vector = UNMI_VECTOR
//__interrupt void UNMI_ISR(void)
//{
//}
//
//#pragma vector = SYSNMI_VECTOR
//__interrupt void SysNMI_ISR(void)
//{
//}

这是 NDEF.C 代码:

/*
 * NDEF.c
 *
 * RF430FRL152H NFC Only Example Project
 *
 * Copyright (C) 2014 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.
 *
*/

#include "types.h"
#include "NDEF.h"
#include "patch.h"
#include <string.h>

/* Firmware System Control Byte
 *
 *     Bit 0:   ISOBlockSize                0 - 4 byte,     1 - 8 byte
 *     Bit 1:   Page                        0 - page 1,     1 - page 0 (Effective only for 4-byte block mode)
 *     Bit 2:   ROMEUSCISupportEnabled      0 - disabled,   1 - enabled (Forced to 0 on RF430FRL153H)
 *     Bit 3-5: ReservedISO
 *     Bit 6:   NFCBridgeDisable            0 - enabled,    1 - disabled (see note below)
 *     Bit 7:   ROMSensorSupportEnable      0 - disabled,   1 - enabled (Forced to 0 on RF430FRL154H)
 *
 *     NFC bridge is recommended to be disabled in this project.  Unexpected behaviour can occur,
 *     trying to use it, due to the configuration being setup here.
 *
 *     If eUSCI host controller portion is needed along with the RF functionality, the default project
 *     must be used.  That is NFC cannot be supported in that application (because the I2C/SPI host controller
 *     control registers are in the same place that the NFC file needs to be).  However the rest of the FRAM
 *     memory can be used for storing and reading using ISO15693.
 */

//This project is based on the RF430FRL152H.  However it will work as well on the RF430FRL154H.
//However ROM_SENSOR_SUPPORT_DISABLED (or ROMSensorSupportEnable see above for both )must be set in the firmware system control register.  This is forced automatically on the RF430FRL154H.
//This setting is needed to disable the ROM which uses block 0... as virtual registers, however this memory is needed for NDEF purposes.
#define FIRMWARE_CONTROL_ADDRESS    0xF867
#pragma RETAIN(Firmware_System_Control_Byte);
#pragma location = FIRMWARE_CONTROL_ADDRESS
//This variable needs to be kept declared and as "volatile" for the BlockLockROM_Patched function to work properly.  Assignment can be changed however.
volatile const u08_t Firmware_System_Control_Byte = ROM_SENSOR_SUPPORT_DISABLED + EROM_EUSCI_SUPPORT_DISABLED + NFC_BRIDGE_DISABLED + FOUR_BYTE_BLOCK + FIRST_ISO_PAGE; //0x7F,     // this value sets the firmware system control register

// ROM variables - DO NOT CHANGE !!!
// Declared to protect from use by compiler
/********************************************/
#pragma RETAIN(DS)
#pragma location = 0x1C00
u08_t DS;
#pragma RETAIN(RF)
#pragma location = 0x1C6A
const u08_t RF;
#pragma RETAIN(NRX)
#pragma location = 0x1CA4 //rx
const u08_t NRX[34];
#pragma RETAIN(NTX)
#pragma location = 0x1CC6 //tx
const u08_t NTX[33];
#pragma RETAIN(EL)
#pragma location = 0x1CF2
const u08_t EL;
#pragma RETAIN(PF)
#pragma location = 0x1C0A
const u16_t PF[48];
/********************************************/

/*
 * This is an NDEF message: www.ti.com
 * This can be made longer and edited as necessary.  However it is limited to the first page (about 968 bytes),
 * the second page is mainly used for patch firmware, but can be read over NFC as well, with proper commands.
*/

#define NDEF_START_ADDRESS  0xF868
#pragma RETAIN(NFC_NDEF_Message);
#pragma location = NDEF_START_ADDRESS;                                                                  // the location of the address
const u08_t NFC_NDEF_Message[23] = {

        // Block 0
        0xE1,       // NDEF Magic Number
        0x40,       // Version Number, read/write access conditions
        0x79,  //0x7E,      // 1008 bytes / 8 = 126 blocks
        0x00,//0x04,//8 byte extended memory //0x00,        // does not support read multiple blocks (limited to only 3 blocks)

        // Block 1
        0x03,       // NDEF Message present
        0x0D,       // Length , 11 bytes-> payload of 7, pauload of 18 is 22 byte length
        0xD1,       // Record header
        0x01,       // type length

        // Block 2
        0x09,       // Payload length
        0x55,       // Record Type U (URI)
        0x01,       // URI header identifier
        0x7A,       // 'z'
        0x74,       // 't'

        // Block 3
        0x69,       // 'i'
        0x2E,       // '.'
        0x63,       // 'c'
        0x64,       // 'd'
        0x6F,       // 'o'

        // Block 4
        0x6D,       // 'm'
        0xFE,       // TLV terminator
        0x00,       // Empty don't care
        0x00        // Empty don't care
};

/**************************************************************************************************************************************************
*  initISO15693
***************************************************************************************************************************************************
*
* Brief : Initializes the RF Stack
*
* Param[in] :   parameter - the configuration to setup the ISO15693 (option to clear the lock blocks)
*
* Param[out]:   None
*
* Return        None
**************************************************************************************************************************************************/
void initISO15693(u16_t parameters )
{

  RF13MCTL |= RF13MTXEN + RF13MRXEN + RF13MRFTOEN;  // set up rx and tx functionality on RF13M module
  // enable interrupts  ** Do not change the following two lines, needed for proper RF stack operatoin
  RF13MINT |= RF13MRXIE + RX13MRFTOIE;              // enable interrupts on RX and on timeout and over and under flow checking

  if (parameters & CLEAR_BLOCK_LOCKS )
  {
    memset ((u08_t *) FRAM_LOCK_BLOCKS, 0xFF, FRAM_LOCK_BLOCK_AREA_SIZE);     //block is locked with a zero bit, clears FRAM and RAM lock blocks
  }

//  BlockLockAPI(3, LOCK_BLOCK);  //Test this API
//
//  BlockLockAPI(3, CHECK_LOCK);  //Test this API
}

/**************************************************************************************************************************************************
*  BlockLockAPI
***************************************************************************************************************************************************
*
* Brief : Locks a block either in FRAM or in RAM.
*
* Param[in] :   block - The block to lock.  In 4-byte mode this will lock two blocks and depends on the page selected.
*
* Param[out]:   None
*
* Return        None
**************************************************************************************************************************************************/
u16_t BlockLockAPI(u16_t block, u08_t checkLock)
{
    u16_t locked;

    locked = BlockLockROM_Patched(block, checkLock );
    return locked;
}

这里是 NDEF.h

/*
 * NDEF.h
 *
 * RF430FRL152H NFC Only Example Project
 *
 * Copyright (C) 2014 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.
 *
*/
#include <rf430frl152h.h>
#include "types.h"

#ifndef NDEF_H
#define NDEF_H

//*****************************FUNCTION PROTOTYPES********************************/
void initISO15693(u16_t parameters );
u16_t BlockLockAPI(u16_t block, u08_t checkLock);

extern u08_t DS;

#define CLEAR_BLOCK_LOCKS                               BIT3
#define FRAM_LOCK_BLOCK_AREA_SIZE                       38
#define FRAM_LOCK_BLOCKS                                0xF840  //Address of ISO15693 lock blocks


#define ROM_EUSCI_SUPPORT_ENABLED       BIT2
#define EROM_EUSCI_SUPPORT_DISABLED     0
#define ROM_SENSOR_SUPPORT_ENABLED      BIT7
#define ROM_SENSOR_SUPPORT_DISABLED     0
#define NFC_BRIDGE_DISABLED             BIT6
#define NFC_BRIDGE_ENABLED              0
#define EIGHT_BYTE_BLOCK                BIT0
#define FOUR_BYTE_BLOCK_MASK            BIT0
#define FOUR_BYTE_BLOCK                 0
#define FIRST_ISO_PAGE_MASK             BIT1
#define FIRST_ISO_PAGE                  BIT1
#define SECOND_ISO_PAGE                 0
#define FRAM_BLOCKS_8                   0xF3


#define CHECK_LOCK                  1
#define LOCK_BLOCK                  0
#define LOCKED_FLAG                 BIT0

#endif

这里是patch.h

/*
 * Patch.h
 *
 * RF430FRL152H NFC Only Example Project
 *
 * Copyright (C) 2014 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.
 *
*/
#include "types.h"
#ifndef PATCH_H
#define PATCH_H


//****Patch functions********************************************************************/
void GetSystemInfo_Patched();
void GetMultipleBlockSecurityStatus_Patched();
u16_t BlockLockROM_Patched(u16_t blockNumber , u08_t checkLock);

void userCustomCommand();

typedef void(*DriverFunction)(void);

//------------------------------------------------------------------------------
// Driver section
//------------------------------------------------------------------------------
extern volatile const u08_t Firmware_System_Control_Byte;

#define CRC_LENGTH_IN_BUFFER          2  // the CRC bytes take 2 bytes in the packet
#define DATA_IN_LENGTH                1  // only 1 byte of data in expected


#define DRIVER_TABLE_START              0xFFCE                  // starting address for driver table
#define DRIVER_TABLE_KEY                0xCECE                  // identifier indicating start and end of driver table
#define BLOCK_LOCK_ID                   0x2600                  // Block Lock Code for ROM
#define GET_SYSTEM_INFO_ID              0x002B                  // Get System Info ISO15693 command ID
#define GET_MUL_BLCK_SEC_STATUS_ID      0x002C                  // Get Multiple Block Security Status ISO15693 command ID
#define USER_CUSTOM_COMMAND_ID          0x00AA                  // user custom command, range from A0 - D0

#define NUMBER_OF_DRIVER_FUNCTIONS      4                       // the amount of patched functions
//------------------------------------------------------------------------------
#define CUSTOM_COMMAND         (DRIVER_TABLE_START-2)
#define CUSTOM_COMMAND_ADDR    (DRIVER_TABLE_START-4)

#define GET_SYSTEM_INFO_COMMAND (DRIVER_TABLE_START-6)                  // DIGITAL_SENSOR_DRIVER_ID, see below
#define GET_SYSTEM_INFO_ADDR    (DRIVER_TABLE_START-8)

#define GET_MULTIPLE_BLOCK_SECURITY_STATUS_COMMAND (DRIVER_TABLE_START-10)                      // INIT_DIGITAL_SENSOR_DRIVER_ID, see below
#define GET_MULTIPLE_BLOCK_SECURITY_STATUS_ADDR    (DRIVER_TABLE_START-12)

#define BLOCK_LOCK_ROM_COMMAND (DRIVER_TABLE_START-14)                      // INIT_DIGITAL_SENSOR_DRIVER_ID, see below
#define BLOCK_LOCK_ROM_ADDR    (DRIVER_TABLE_START-16)

#define DRIVER_TABLE_END  (DRIVER_TABLE_START-2-(NUMBER_OF_DRIVER_FUNCTIONS*4))

#endif

【问题讨论】:

  • CCS 是 IDE 而不是语言,没有“CCS 代码”之类的东西;它只是 C 代码。您使用的代码编辑器和构建系统无关紧要。
  • [nfc] 标签也无关紧要。修复了标签和标题。
  • 标题指的是“我的 C 代码”,但显然此代码是 TI Inc. 的版权。 (在这种情况下,您可能不应该发布它)。如果它是您的代码,您大概会知道它是如何工作的。标题中的问题似乎也与正文中的问题无关。

标签: c compilation linker


【解决方案1】:

您提出了两个截然不同且不相关的问题 - 通常最好单独发布问题。

关于NFC_NDEF_Message

以下代码:

#define NDEF_START_ADDRESS  0xF868
#pragma RETAIN(NFC_NDEF_Message);
#pragma location = NDEF_START_ADDRESS;                                                                  // the location of the address
const u08_t NFC_NDEF_Message[23] = {

意思:

NFC_NDEF_Message 定位到地址0xF868 并且不允许链接器移除数据对象,即使没有代码显式引用它。

要将0xF868 的数据更改为0xF87F,只需更改 NDEF.c 中的源即可。 #pragma 指令将确保 NFC_NDEF_Message 存储在该位置。

关于如何调用initISO15693()

initISO15693() 具有外部链接,并在 NDEF.h 中声明

预处理器#includes NDEF.h 编译器使用声明说

“这些符号存在于其他模块中,稍后可能由链接器解析”

编译器将未解析的链接占位符放在目标代码中。然后单独编译源 NDEFS.c,并在其目标代码中创建符号 initISO15693 等,引用实际的数据实例和代码。

然后,链接器将两个已编译的目标模块组合在一起(连同项目构建和库中的任何其他模块以及运行时启动代码)。在这种组合过程中,未解析的链接与其他模块和库中相应的具体实例匹配。

这也是您可以将自己的代码分解为单独编译的模块的方法。对于任何重要的应用程序,您都希望这样做。

查看 NDEFS.h 头文件或任何其他头文件,包括标准库头文件,以了解这些 声明 是如何生成的。头文件(通常)不包含库代码或数据对象,它们通常只包含声明或存在于其他地方的代码/数据,以供链接器解析。

构建可执行文件有(至少)三个阶段:

  1. 预处理:用包含的文件内容替换#include,用它们的#define'ed 文本替换宏,根据#if 删除代码等。
  2. 编译:将单独的预处理源模块转换为本机代码对象模块,并带有未解析的外部代码/数据链接。
  3. 链接:结合来自单个编译和库的对象模块,解析任何未解析的链接。

了解这些步骤(通常被使用 CCS 等 IDE 隐藏或掩盖)将帮助您更好地了解如何在出现问题时解决问题;例如,“未定义符号”是编译错误(您没有声明符号或包含必需的标头),而“未解析的符号”是链接器错误(您没有在构建中添加必需的目标模块或库 - 并且在turn 可能没有将源代码添加到您的项目中)。

【讨论】:

  • 感谢您的回复!我在原始帖子中添加了一些头文件。我看到了extern u08_t DS; 代码,但没有看到与 NFC_NDEF_Message 的直接连接。
  • 更新了答案。
猜你喜欢
  • 1970-01-01
  • 2019-11-12
  • 2011-02-23
  • 1970-01-01
  • 2018-05-30
  • 1970-01-01
  • 2018-05-27
  • 2012-03-29
  • 1970-01-01
相关资源
最近更新 更多