123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253 |
- /*******************************************************************************
- Class B Library Implementation Test File
- Summary:
- This file contains the test program for the
- the Class B Safety Software Library on PIC32MX MCUs.
-
- *******************************************************************************/
- /*******************************************************************************
- FileName: ClassB_main.c
- Processor: PIC32MX
- Compiler: Microchip MPLAB® C32 v1.04 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 Files
- *
- ********************************************************************/
- #include <stdlib.h>
- #include <P18F45K80.h>
- #include "SSL_CpuRegisterTest.h"
- #include "SSL_CheckerBoardTest.h"
- #include "SSL_ProgCounterTest.h"
- #include "SSL_MarchCMinusRamTest.h"
- #include "SSL_MarchBRamTest.h"
- #include "SSL_MarchCRamTest.h"
- #include "SSL_Flash_CRC.h"
- /*********************************************************************
- *
- * Pragmas
- *
- *********************************************************************/
- #pragma config XINST = OFF
- #pragma config FOSC = HS1
- #pragma config WDTEN = SWDTDIS //OFF // SWDTDIS
- #pragma config WDTPS = 256 // WD TimeOut 1024ms
- #pragma config SOSCSEL = DIG // Port C, Pin 0 & 1 => Digital
- #pragma config PLLCFG = ON
- /*********************************************************************
- *
- * Typdefs
- *
- *********************************************************************/
- volatile struct ClassB_Test_Flags {
- unsigned cpuRegister_TestResult : 1;
- unsigned programCounter_TestResult:1;
- unsigned checkerboardRam_TestResult:1;
- unsigned marchCRam_TestResult:1;
- unsigned marchCMinusRam_TestResult:1;
- unsigned marchCRamStack_TestResult:1;
- unsigned marchBRam_TestResult:1;
- unsigned flash_TestResult:1;
- unsigned clock_TestResult:1;
- unsigned clockLine_TestResult:1;
- } testFlag;
- /*+++++++ Main SSL Demo +++++++++++++++++++++++++++++++++++++++++++*/
- int main(void)
- {
- /* ini()? */
-
- /**********************************************************************************/
- /* CPU REGISTER TEST */
- /**********************************************************************************/
- if (SSL_PCtest()==CPU_REGISTER_TEST_PASS)
- {
- // the CPU registers don't have stuck bits
- testFlag.cpuRegister_TestResult = 1;
- }
- else
- {
- testFlag.cpuRegister_TestResult = 0;
- }
- /**********************************************************************************/
- /* PROGRAM COUNTER TEST */
- /* This requires a special linker script (elf32pic32mx.ld) to be added */
- /* as part of the project. See the description in SSL_PcTest.h */
- /**********************************************************************************/
- if (SSL_PCtest()==PC_TEST_PASS)
- {
- // the PC register does not have stuck bits
- testFlag.programCounter_TestResult = 1;
- }
- else
- {
- testFlag.programCounter_TestResult = 0;
- }
- /**********************************************************************************/
- /* RAM TESTS */
- /**********************************************************************************/
-
- /*************************/
- /* Checker Board RAM test*/
- /*************************/
- // We'll test 1KB chunk at the middle of the RAM
- // Note that this test is not destructive
- // It has to NOT overlap the stack space!
- if (SSL_RAMtest_CheckerBoard( )==CB_TEST_PASS)
- {
- // the test succeeded and we are confident that the RAM area can be used
- testFlag.checkerboardRam_TestResult = 1;
- }
- else
- {
- testFlag.checkerboardRam_TestResult = 0;
- }
- /****************************/
- /* March B Ram Test */
- /****************************/
- // Suppose we need to allocate and want to use a 1 KB chunk of memory
- // We'll test it using the Checker Board test before we use it
- // to make sure there is no problem with the chunk of RAM we selected.
- // Note that this test is destructive.
- // Note that the size of the RAM to test has to be multiple of 4.
-
- { // allocation succeeded and we can perform the test
- if (SSL_RAMtest_MarchB() ==MARCHB_TEST_PASS)
- {
- // the test succeeded and we can go ahead and use the allocated memory
- testFlag.marchBRam_TestResult = 1;
- }
- else
- {
- testFlag.marchBRam_TestResult = 0;
- }
-
- //free(ramTestStartAddress); // we're done with this memory block
- // return it to the heap
- }
- /*************************/
- /* MarchC RAM tests */
- /*************************/
- // We allocate and want to use a 2 KB chunk of memory
- // We'll test it using the March C and March C Minus tests before we use it
- // Note that the size of the RAM to test has to be multiple of 4.
- // This test is destructive too.
-
- if (SSL_RAMtest_MarchC() == MARCHC_TEST_PASS)
- {
- testFlag.marchCRam_TestResult = 1;
- }
- else
- {
- testFlag.marchCRam_TestResult = 0;
- }
- /**************************/
- /* MarchC Minus RAM test */
- /**************************/
- if (SSL_RAMtest_MarchCMinus() == MARCHC_TEST_PASS)
- {
- // if both tests succeeded we can go ahead and use the allocated memory
- testFlag.marchCMinusRam_TestResult = 1;
- }
- else
- {
- testFlag.marchCMinusRam_TestResult = 0;
- }
-
-
- /**********************************************************************************/
- /* FLASH CRC TEST */
- /**********************************************************************************/
- // This function can be called at startup to generate the Reference checksum.
- // The same function can be called periodically and the generated checksum can be
- // compared with the reference checksum.
- // If both are the same the "flash_TestResult" status bit can be set.
- unsigned int flashCrcRef, flashCrc; // reference and current CRC values
- unsigned int crcSeed=0xffff; // initial CRC register value
- // this is the recommended CRC seed
- // for checking properly long 0 streams.
- // calculate the CRC16 of the whole program flash (K0)
- char* flashStartAddress = (char*)0x9d000000; // fixed start K0 address on PIC32MX devices
- //char* flashEndAddress = flashStartAddress+BMXPFMSZ-1; // size of the flash on this device
- // the BMX register stores the Flash size for this part
- // first we calculate the reference Flash CRC value
- flashCrcRef = SSL_FLASHtest_CRC( );
- // at some time later we calculate again the CRC of the Flash
- flashCrc = SSL_FLASHtest_CRC( );
- // make sure that the periodic check is equal to the reference one
- if ( flashCrc==flashCrcRef)
- {
- testFlag.flash_TestResult=1;
- // we are confident that the data programmed in Flash
- // has not been altered in any way
- }
- else
- {
- testFlag.flash_TestResult=0;
- }
- }
|