123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- /*******************************************************************************
- Class B Library implementation file
- Summary:
- This file contains the implementation for the
- the Class B Safety Software Library RAM Checkerboard Tests
- for PIC18 MCUs.
-
- *******************************************************************************/
- /*******************************************************************************
- FileName: SSL_CheckerBoardTest.c
- Processor: PIC18
- Compiler: Microchip MPLAB® C18 v3.41 or higher
- Copyright © 2008-2009 released Microchip Technology Inc. All rights reserved.
- Microchip licenses to you the right to use, modify, copy and distribute
- the accompanying software only when embedded on a Microchip microcontroller or
- digital signal controller that is integrated into your product or third party product.
-
- If the accompanying software required your consent to the terms of Microchip's
- click-wrap license agreement, then you should also refer to such license agreement
- for additional information regarding your rights and obligations.
- Your acceptance and/or use of this software constitutes your agreement to the terms
- and conditions of this notice and applicable click-wrap license, if any.
- You agree that you are solely responsible for testing the code and determining its suitability.
- Microchip has no obligation to modify, test, certify, or support the code.
- SOFTWARE AND DOCUMENTATION ARE PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND,
- EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF
- MERCHANTABILITY, TITLE, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
- IN NO EVENT SHALL MICROCHIP OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER
- CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR
- OTHER LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
- INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE OR
- CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST dataC, COST OF PROCUREMENT OF
- SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
- (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
- *******************************************************************************/
- #include "SSL_CheckerBoardTest.h"
- #pragma idata RAMFIX=0xE00
- int8_t* pRAM1_RAM = (int8_t *)RAM_StartAddress;
- int8_t* pRAM2_RAM = (int8_t *)RAM_StartAddress;
- int8_t BYTE_Low_RAM = 0x00;
- int8_t BYTE_High_RAM = 0x00;
- uint16_t CB_Counter_RAM = RAM_Length;
- #pragma idata STACKFIX=0x100
- int8_t* pRAM1_STACK = (int8_t *)STACK_StartAddress;
- int8_t* pRAM2_STACK = (int8_t *)STACK_StartAddress;
- int8_t BYTE_Low_STACK = 0x00;
- int8_t BYTE_High_STACK = 0x00;
- uint16_t CB_Counter_STACK = STACK_Length;
- /*
- /*******************************************************************************
- Function:
- int SSL_CheckerBoard( void )
- Summary:
- The RAM Checker Board test implements one of the functional tests
- H.2.19.6 as defined by the IEC 60730 standard.
-
- Description:
- This routine detects single bit Faults in the variable memory.
- This ensures that the bits in the tested RAM are not stuck at
- a value ‘0’ or ‘1’.
- The test writes the checkerboard pattern (0x55 followed by 0xAA)
- to adjacent memory locations starting at ramStartAddress.
- It performs the following steps:
- 1. The content of a 2 bytes memory chunk to be tested is saved in
- temporary CPU registers.
- 2. Writes the pattern 0x55 followed by 0xAA to adjacent memory locations
- filling up the 2 bytes memory chunk.
- 3. It reads the memory chunk adjacent locations and checks that the read-back values match
- the written pattern.
- If the values match set the success result and go to step 4.
- Else set the error result and go to step 6.
- 4. Writes the inverted pattern 0xAA followed by 0x55 to adjacent memory locations
- filling up the 2 bytes memory chunk.
- 5. It reads the memory chunk adjacent locations and checks that the read-back values match
- the written pattern.
- If the values match set the success result.
- Else set the error result.
- 6. The content of the tested 2 bytes memory chunk is restored from the
- temporary CPU registers.
- 7. If the result shows error the test is done and returns.
- 8. The address pointer is incremented to point to the next sequential 4 bytes memory chunk
- and the test is repeated from step 1 until all the number of requested memory locations
- is tested.
-
- Precondition:
- Global dataC
- ramStartAddress - start Address from which the checker Board test is to be performed
-
- ramStopAddresse - stop Address where the checker Board test is ending
-
-
- Returns:
- Result identifying the pass/fail status of the test:
- CB_TEST_PASS - The test passed. RAM area tested has not been detected to have stuck bits.
- CB_TEST_FAIL - The test failed. Some RAM area location has been detected to have stuck bits.
-
- Remarks:
- This is a non-destructive memory test. The content of the tested memory area is saved and restored.
- The test operates in 2 bytes long memory chunks at a time.
-
- The tested RAM area must not overlap the stack.
-
- The Start Address from which the Checker Board test is to be performed is
- PIC18 variant and application dependent. It is a run-time parameter.
-
- Refer to the AN1229 for details regarding
- *****************************************************************************/
- int16_t SSL_RAMtest_CheckerBoard( void )
- {
- pRAM2_RAM++;
- while(CB_Counter_RAM)
- {
- BYTE_Low_RAM = *pRAM1_RAM;
- BYTE_High_RAM = *pRAM2_RAM;
- *pRAM1_RAM = 0xAA;
- *pRAM2_RAM = 0x55;
-
- if(*pRAM1_RAM != 0xAA)
- return CB_TEST_FAIL;
- if(*pRAM2_RAM != 0x55)
- return CB_TEST_FAIL;
- *pRAM1_RAM = 0x55;
- *pRAM2_RAM = 0xAA;
-
- if(*pRAM1_RAM != 0x55)
- return CB_TEST_FAIL;
- if(*pRAM2_RAM != 0xAA)
- return CB_TEST_FAIL;
- *pRAM1_RAM = BYTE_Low_RAM;
- *pRAM2_RAM = BYTE_High_RAM;
- pRAM1_RAM++;
- pRAM2_RAM++;
- CB_Counter_RAM--;
- }
- return CB_TEST_PASS;
- }
- int16_t SSL_STACKtest_CheckerBoard( void )
- {
- pRAM2_STACK++;
- while(CB_Counter_STACK)
- {
- BYTE_Low_STACK = *pRAM1_STACK;
- BYTE_High_STACK = *pRAM2_STACK;
- *pRAM1_STACK = 0xAA;
- *pRAM2_STACK = 0x55;
- if(*pRAM1_STACK != 0xAA)
- return CB_TEST_FAIL;
- if(*pRAM2_STACK != 0x55)
- return CB_TEST_FAIL;
- *pRAM1_STACK = 0x55;
- *pRAM2_STACK = 0xAA;
- if(*pRAM1_STACK != 0x55)
- return CB_TEST_FAIL;
- if(*pRAM2_STACK != 0xAA)
- return CB_TEST_FAIL;
- *pRAM1_STACK = BYTE_Low_STACK;
- *pRAM2_STACK = BYTE_High_STACK;
- pRAM1_STACK++;
- pRAM2_STACK++;
- CB_Counter_STACK--;
- }
- return CB_TEST_PASS;
- }
|