/***************************************************************************/ /***************************************************************************/ /***************************************************************************/ /******* *******/ /******* U N I V E R S A L *******/ /******* *******/ /******* F U E L Q U A N T I T Y M E A S U R I N G S Y S T E M *******/ /******* *******/ /***************************************************************************/ /***************************************************************************/ /***************************************************************************/ /* */ /* Program Name : Universal Fuel Quantity Measuring System (UFQGS) */ /* Source File Name : bit.c */ /* CPC : Fault Isolation / NOVRAM / BIT */ /* Engineer : Sridhar Rokkam/ Rosanne Parnell / Katherine Monroe */ /* Criticality Level : Level C */ /* Contents : bit_ram_test */ /* bit_entire_rom_test */ /* bit_warmstart_indicator_test */ /* bit_probe_bit */ /* bit_processor_shutdown */ /* bit_delay */ /* Description : This CSC performs built in test. */ /* */ /* */ /* Contents of this document are propriety information, property of: */ /* PARKER HANNIFIN CORPORATION */ /* GULL ELECTRONIC SYSTEMS DIVISION */ /* SMITHTOWN, NEW YORK 11787 */ /* Any attempt to copy or use the contents of this document in any manner */ /* whatsoever without express written consent of the owner is prohibited. */ /***************************************************************************/ /***************************************************************************/ /***************************************************************************/ #pragma EJECT /***************************************************************************/ /* Revision History */ /***************************************************************************/ /* */ /* Date Rev Engineer Description */ /* ------ --- -------- ------------------------------------------------ */ /* */ /* 072595 A K MONROE PR 019 Remove BIT_STARTUP_WATCHDOG_TEST not */ /* being used. */ /* */ /* */ /***************************************************************************/ #pragma EJECT #pragma DEBUG #pragma LARGE #pragma NOAM #pragma OBJECTEXTEND #pragma SYMBOLS #define EXTRN extern /* declare all global variables external */ #define MAIN_FILE 0 //#pragma SRC #include "c:\c51\inc\reg51.h" #include "c:\c51\inc\absacc.h" #include "typedefs.h" #include "asicaddr.h" #include "defines.h" #include "globals.h" #include "prototyp.h" #include "fai.h" #pragma EJECT /*************************/ /* Module level literals */ /*************************/ #define ROM_SIZE 0x10000 /* 64k KM 3/23/95 */ #define CHECKSUM_SIZE 4 /* The last two bytes (FFFC & FFFD) */ /* Cannot use FFFE and FFFF in the LIFT chip */ #define ROM_BLOCK_SIZE 0x10 /* 16 bytes each pass */ #define ROM_BLOCKS (ROM_SIZE/ROM_BLOCK_SIZE) #define LAST_RAM_LOCATION 0x800 /* 2k of ram = 2048 bytes */ /**************************/ /* Module level variables */ /**************************/ static xdata uchar code *p_rom_ptr; /* maintained on external RAM */ static xdata uint bit_periodic_checksum; /* maintained on external RAM */ static xdata uint bit_rom_block_number; data uchar volatile xdata *p_ram_ptr; /* maintained on internal RAM */ /**********************************************/ /* Module level variables used at local level */ /**********************************************/ /* The following variables have been declared */ /* at the module level for sizing */ /* considerations. They are to be treated as */ /* local variables (i.e., they must be */ /* initialized by each unit which uses them). */ /**********************************************/ #pragma EJECT /***************************************************************************/ /* */ /* Unit Name : bit_processor_shutdown */ /* Description : This unit enters an infinite loop while strobing the */ /* watchdog timer to cause a system shutdown. */ /* Inputs : None */ /* Outputs : None */ /* */ /* Called by : bit_entire_rom_test */ /* bit_periodic_rom_test */ /* bit_cpu_test */ /* bit_ram_test */ /* */ /* Calls : None */ /* */ /***************************************************************************/ void bit_processor_shutdown (void) { xdata uchar wdog; /* watchdog timer */ EA=0; // disable interrupts XBYTE[PORT_A_ADDR ] |=SYSTEM_FAULT_ENABLE; // turn light on for (;;) { // do forever SYSTEM_SLEEP: wdog = XBYTE[WDS_ADDR]; // strobe the watchdog timer } } #pragma EJECT /***************************************************************************/ /* */ /* Unit Name : bit_entire_rom_test */ /* Description : This unit tests the ROM with a checksum test on the entire*/ /* block of ROM. */ /* Inputs : None */ /* Outputs : None */ /* */ /* Called by : main (background executive) */ /* Calls : fai_pass_fail_logger */ /* bit_processor_shutdown */ /* */ /***************************************************************************/ void bit_entire_rom_test (void) { /******************/ /* Local literals */ /******************/ /*******************/ /* Local variables */ /*******************/ xdata uint computed_checksum; /* maintained on external RAM */ /*************************************************/ /* TIMING: THIS TEST TAKES 236.084 MILLISECONDS */ /* TO COMPLETE IN ITS ENTIRETY (32k) */ /* 3/23/95 KM 472.16 FOR 64K */ /*************************************************/ /***********************************************/ /* Sum all the ROM bytes except for the stored */ /* checksum (last two bytes of ROM) */ /***********************************************/ computed_checksum = get_rom_checksum((ROM_SIZE-CHECKSUM_SIZE)); ROM_TEST_CHK: /************************************/ /* Add in the stored checksum value */ /************************************/ if (computed_checksum != CWORD[(ROM_SIZE-CHECKSUM_SIZE)/sizeof(uint)]) { fai_fault_logger(0,ROM_TEST_ID,FAIL); bit_processor_shutdown(); } } /* end bit_entire_rom_test */ #pragma EJECT /***************************************************************************/ /* */ /* Unit Name : reset_periodic_rom_test */ /* Description : This unit resets the variables for the ROM test. This test*/ /* needs to be called on warm starts. */ /* */ /* Inputs : None */ /* Outputs : None */ /* */ /* Called by : main (background executive) */ /* Calls : fai_pass_fail_logger */ /* */ /***************************************************************************/ void bit_reset_periodic_rom_test (void) { p_rom_ptr = 0; bit_periodic_checksum = 0; bit_rom_block_number = 0; } #pragma EJECT /***************************************************************************/ /* */ /* Unit Name : bit_periodic_rom_test */ /* Description : This unit tests 32 bytes on each pass */ /* */ /* Inputs : None */ /* Outputs : None */ /* */ /* Called by : main (background executive) */ /* Calls : fai_pass_fail_logger */ /* bit_processor_shutdown */ /* */ /***************************************************************************/ void bit_periodic_rom_test (void) { /******************/ /* Local literals */ /******************/ /*******************/ /* Local variables */ /*******************/ xdata uchar rom_slice; /*************************************************/ /* TIMING: THIS TEST TAKES 0.672 MILLISECONDS */ /* FOR EACH PASS OF 16 BYTES. */ /*************************************************/ bit_rom_block_number++; if (bit_rom_block_number == ROM_BLOCKS) rom_slice = ROM_BLOCK_SIZE - CHECKSUM_SIZE; else rom_slice = ROM_BLOCK_SIZE; while (rom_slice--) bit_periodic_checksum += *p_rom_ptr++; if (bit_rom_block_number == ROM_BLOCKS) { ROM_PERIODIC_CHK: if (bit_periodic_checksum != CWORD[(ROM_SIZE-CHECKSUM_SIZE)/sizeof(uint)]) { fai_fault_logger(0,ROM_TEST_ID,FAIL); bit_processor_shutdown(); } else fai_pass_fail_logger(ROM_TEST_ID,PASS); /* clean up for next go around */ bit_reset_periodic_rom_test(); } } /* end bit_periodic_rom_test */ #pragma EJECT /***************************************************************************/ /* */ /* Unit Name : bit_probe_bit */ /* Description : This unit */ /* Inputs : None */ /* Outputs : None */ /* */ /* Called by : main (background executive) */ /* Calls : None */ /* */ /***************************************************************************/ void bit_probe_bit (void) { /*****************************************/ /* Perform this task only when a full */ /* set of startup data has been acquired.*/ /* Use g_acq_startup_complete_flag */ /*****************************************/ } /* end bit_probe_bit */ #pragma EJECT /***************************************************************************/ /* */ /* Unit Name : bit_delay */ /* Description : This unit is used when a software delay is needed. */ /* This unit takes 1 millisecond to execute times the */ /* countdown number which is passed as a parameter. */ /* */ /* Inputs : time_to_wait (parameter) */ /* */ /* Outputs : None */ /* */ /* Called by : bit_startup_watchdog_test */ /* Calls : None */ /* */ /***************************************************************************/ void bit_delay (uint time_to_wait) { /*******************/ /* Local variables */ /*******************/ xdata uint delay; /* desired delay loop counter */ xdata uint wait_one_millisecond; /* 1 ms loop counter */ /******************/ /* Local literals */ /******************/ #define FACTOR_FOR_1_MS 166 /* the factor which causes the for loop */ /* to be one millisecond @20 Mhz */ for (delay=0; delay < time_to_wait; delay++) { BIT_MS_LOOP: wait_one_millisecond = FACTOR_FOR_1_MS; while (wait_one_millisecond) wait_one_millisecond--; } /* end for */ } /* end bit_delay */ #pragma EJECT /***************************************************************************/ /* */ /* Unit Name : bit_cpu_test */ /* Description : This unit tests the */ /* */ /***************************************************************************/ void bit_cpu_test (void) { /******************/ /* Local literals */ /******************/ #define FIRST_CPU_TEST_PATTERN 0x00 /* first pattern to use for testing */ #define SECOND_CPU_TEST_PATTERN 0x55 /* second pattern to use for testing */ /*******************/ /* Local variables */ /*******************/ bit error_found ; /* indicates when a CPU error is detected */ xdata uchar first_test_byte ; xdata uchar second_test_byte; error_found = FALSE; first_test_byte = 0xFF; /*******************************/ /* Clear Processor Status Word */ /*******************************/ PSW = 0; /**********************/ /* Test boolean logic */ /**********************/ BOOLEAN_TEST: if ((!(first_test_byte > FIRST_CPU_TEST_PATTERN)) || ((first_test_byte & FIRST_CPU_TEST_PATTERN) > 0) || ((first_test_byte | FIRST_CPU_TEST_PATTERN) != first_test_byte) || ((first_test_byte ^ SECOND_CPU_TEST_PATTERN) != 0xAA)) error_found = TRUE; /*************************/ /* Test arithmetic logic */ /*************************/ else { first_test_byte = 3; second_test_byte = 4; ARITHMETIC_TEST: if ((((first_test_byte * second_test_byte) +9) -4) != 17) error_found = TRUE; /****************************/ /* Program Status Word Test */ /****************************/ else { first_test_byte = 0xFF; first_test_byte += 0x80; OVERFLOW_TEST: /**********************/ /* Test overflow flag */ /**********************/ if ((!CY) || (!OV)) error_found = TRUE; /*******************/ /* Test carry flag */ /*******************/ else { CY = 0; first_test_byte = 0x80; CARRY_TEST1: first_test_byte <<= 1; if (!CY) error_found = TRUE; } /* end else (carry flag test) */ } /* end else (overflow flag test) */ } /* end else (arithmetic logic test) */ /*****************************************************************/ /* If a CPU failure is detected, the failure is reported to FAI, */ /* fault determination is called for fault processing, and the */ /* processor is shut down */ /*****************************************************************/ if (error_found) { fai_fault_logger(0,CPU_TEST_ID,FAIL); bit_processor_shutdown(); } /* end if */ } /* end bit_cpu_test */ #pragma EJECT /***************************************************************************/ /* */ /* Unit Name : bit_ram_test */ /* Description : This unit tests the 2K RAM with a read/write test on each */ /* RAM cell. This unit tests a portion of RAM each time it */ /* is called. */ /* */ /* Timing : This unit takes 0.609 msec for 8 bytes. */ /* */ /***************************************************************************/ void bit_ram_test (void) { /******************/ /* Local literals */ /******************/ #define RAM_BLOCK_SIZE 8 /* test 8 bytes of RAM */ #define FIRST_RAM_TEST_PATTERN 0x55 /* first pattern to use for testing */ #define SECOND_RAM_TEST_PATTERN 0xAA /* second pattern to use for testing */ /*******************/ /* Local variables */ /*******************/ bit error_found = FALSE; /* indicates when a RAM location failed */ data uchar save_ram_value; /* used to restore RAM contents */ data uchar ram_count = 0; /* indicates how many ram bytes have been tested */ xdata uchar initial_warm_start_value; /* contains the initial state of the wdt pattern */ /********************************************************************/ /* If a warm start occurs while this test is in progress, the CPCI */ /* will perform a cold start. Degrade the WDT pattern at the */ /* beginning of this test. At the completion of this test, restore */ /* the WDT (warm start) pattern to its initial state. */ /********************************************************************/ initial_warm_start_value = g_wdt_pattern[0]; // save initial state g_wdt_pattern[0] = 0; // degrade wdt pattern /********************************************/ /* Test RAM until a complete block has been */ /* tested or an error is found */ /********************************************/ while ((ram_count++ < RAM_BLOCK_SIZE) && (!error_found)) { /*****************************************************************/ /* Between the disable and enable of interrupts 16.8 Usec elapse */ /* Do not make any changes here - Data acq will be affected. */ /*****************************************************************/ EA = RESET; // disable 8031 interrupts save_ram_value = *p_ram_ptr; // save initial ram value *p_ram_ptr = FIRST_RAM_TEST_PATTERN; // set ram location to test pattern /*******************************************************/ /* If the test passes with the first pattern, test the */ /* second pattern */ /*******************************************************/ RAM_TEST1: if (*p_ram_ptr == FIRST_RAM_TEST_PATTERN) { *p_ram_ptr = SECOND_RAM_TEST_PATTERN; // set ram location to next test pattern /**********************************************************/ /* If the second pattern is not present after it has been */ /* written, set the error flag */ /**********************************************************/ if (*p_ram_ptr != SECOND_RAM_TEST_PATTERN) error_found = TRUE; } /* end FIRST RAM PATTERN */ /*********************************************************/ /* Otherwise, first pattern was not present after it was */ /* written; set the error flag */ /*********************************************************/ else error_found = TRUE; /****************************/ /* restore the ram contents */ /****************************/ *p_ram_ptr = save_ram_value; /**********************************************/ /* Enable interrupts after one byte is tested */ /**********************************************/ EA = SET; /***************************************************/ /* Update the ram pointer to the next ram location */ /* (rollover if at the last location) */ /***************************************************/ if (++p_ram_ptr == LAST_RAM_LOCATION) p_ram_ptr = 0; } /* end while */ /*****************************************************************/ /* If a RAM failure is detected, the failure is reported to FAI, */ /* fault determination is called for fault processing, and the */ /* processor is shut down */ /*****************************************************************/ if (error_found) { fai_fault_logger(0,RAM_TEST_ID,FAIL); bit_processor_shutdown(); } /* end if */ /************************************/ /* Restore WDT (warm start) pattern */ /************************************/ g_wdt_pattern[0] = initial_warm_start_value; } /* end bit_ram_test */