c - RAM 测试逐步通过,但在运行时失败

标签 c testing embedded ram pic

我正在做的项目需要在程序运行前测试一个dsPIC30F芯片的数据存储器。由于行业要求,我们不能使用 C 必须提供的任何预定义库。也就是说,这是我测试 RAM 的方法:

Step 1 - Write the word 0xAAAA to a specific location in memory (defined by a LoopIndex added to the START_OF_RAM address)

Step 2 - increment LoopIndex

Step 3 - Repeat Steps 1-2 until LoopIndex + START_OF_RAM >= END_OF_RAM

Step 4 - Reset LoopIndex = 0

Step 5 - Read memory at LoopIndex+START_OF_RAM

Step 6 - If memory = 0xAAAA, continue, else throw RAM_FAULT_HANDLER

Step 7 - increment LoopIndex

Step 8 - Repeat Step 5 - 7 until LoopIndex + START_OF_RAM >= END_OF_RAM

现在,奇怪的是我可以单步执行代码,没问题。只要我的小指可以按 F8,它就会慢慢地遍历每个内存地址,但是当我尝试在第 4 步设置断点时,它会无缘无故地抛出一个随机的通用中断处理程序。我想过可能是因为我使用的for()可能超过了END_OF_RAM,但是我已经改变了条件的界限,它仍然不喜欢运行。

任何见解都会有所帮助。

void PerformRAMTest()
{

    // Locals
    uint32_t LoopIndex = 0;
    uint16_t *AddressUnderTest;
    uint32_t RAMvar = 0;
    uint16_t i = 0;

    // Loop through RAM and write the first pattern (0xAA) - from the beginning to the first RESERVED block
    for(LoopIndex = 0x0000; LoopIndex < C_RAM_END_ADDRESS; LoopIndex+= 2)
    {

        AddressUnderTest = (uint32_t*)(C_RAM_START_ADDRESS + LoopIndex);

        *AddressUnderTest = 0xAAAA;


    }// end for

    for(LoopIndex = 0x0000; LoopIndex < C_RAM_END_ADDRESS; LoopIndex += 2)
    {
        AddressUnderTest = (uint32_t*)(C_RAM_START_ADDRESS + LoopIndex);

        if(*AddressUnderTest != 0xAAAA)
            {
                // If what was read does not equal what was written, log the
                // RAM fault in NVM and call the RAMFaultHandler()
                RAMFaultHandler();
            }// end if
    }

    // Loop through RAM and write then verify the second pattern (0x55)
    // - from the beginning to the first RESERVED block
//    for(LoopIndex = C_RAM_START_ADDRESS; LoopIndex < C_RAM_END_ADDRESS; LoopIndex++)
//    {
//        AddressUnderTest = (uint32_t*)(C_RAM_START_ADDRESS + LoopIndex);
//        *AddressUnderTest = 0x5555;
//        if(*AddressUnderTest != 0x5555)
//        {
//            // If what was read does not equal what was written, log the
//            // RAM fault in NVM and call the RAMFaultHandler()
//            RAMFaultHandler();
//        }
//    }

}// end PerformRAMTest

你可以看到第二遍测试写入了0x55。这是给我的原始实现,但它从未奏效(至少就调试/运行而言;这种写入方法遇到了相同的随机中断,然后在继续之前立即读取相同的地址)

更新:在几次 Clean&Builds 之后,代码现在将运行直到它到达堆栈指针 (WREG15),跳过,然后出错。这是相关代码的新示例:

if(AddressUnderTest >= &SPLIMIT && AddressUnderTest <= SPLIMIT)
    {
        // if true, set the Loop Index to point to the end of the stack
        LoopIndex = (uint16_t)SPLIMIT;
    }
    else if(AddressUnderTest == &SPLIMIT) // checkint to see if AddressUnderTest points directly to the stack [This works while the previous >= &SPLIMIT does not. It will increment into the stack, update, THEN say "oops, I just hit the stack" and error out.]
    {
        LoopIndex = &SPLIMIT;
    }
    else
    {
        *AddressUnderTest = 0xAAAA;
    }

最佳答案

我想你真的想要(C_RAM_START_ADDRESS + LoopIndex) < C_RAM_END_ADDRESS作为你的循环条件。当前,您正在从 C_RAM_START_ADDRESS 循环至 C_RAM_START_ADDRESS + C_RAM_END_ADDRESS我假设是在写入 RAM 末尾之后。

您还应该真正将重复的代码分解为一个单独的函数,该函数将测试模式作为参数 (DRY)。

关于c - RAM 测试逐步通过,但在运行时失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17156106/

相关文章:

交叉编译可执行文件无法解析符号 pthread_create

c - 在 c 中实现 tar 命令

testing - 我可以使用 watin 接受来自 excel 工作表的输入吗

c++ - 使用继承或编码不同的 USART 变体

c - 字符数组的状态

testing - 为 Grails 单元测试使用不同的结构

testing - 缺少 else 的分支覆盖

c - 这两个表达之间有区别吗?

c - STM32 ADC DMA。 MCU何时得知ADC结束?

c - 使用多个进程时 MPI Bcast 附近的段错误