Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:39

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @ingroup RTEMSBSPsARMTMS570
0007  *
0008  * @brief This source file contains the HETx, HTUx, ADC, DMA and VIM module
0009  *   parity based protection support.
0010  *
0011  * Algorithms are based on Ti manuals and Ti HalCoGen generated
0012  * code.
0013  */
0014 
0015 /*
0016  * Copyright (C) 2016 Pavel Pisa <pisa@cmp.felk.cvut.cz>
0017  *
0018  * Czech Technical University in Prague
0019  * Zikova 1903/4
0020  * 166 36 Praha 6
0021  * Czech Republic
0022  *
0023  * Redistribution and use in source and binary forms, with or without
0024  * modification, are permitted provided that the following conditions
0025  * are met:
0026  * 1. Redistributions of source code must retain the above copyright
0027  *    notice, this list of conditions and the following disclaimer.
0028  * 2. Redistributions in binary form must reproduce the above copyright
0029  *    notice, this list of conditions and the following disclaimer in the
0030  *    documentation and/or other materials provided with the distribution.
0031  *
0032  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0033  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0034  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0035  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0036  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0037  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0038  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0039  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0040  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0041  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0042  * POSSIBILITY OF SUCH DAMAGE.
0043  */
0044 
0045 #include <stdint.h>
0046 #include <stddef.h>
0047 #include <bsp/tms570.h>
0048 #include <bsp/tms570_selftest.h>
0049 #include <bsp/tms570_selftest_parity.h>
0050 
0051 /**
0052  * @brief run test to check that parity protection works for modules with common setup structure.
0053  *
0054  * @param[in] desc module registers addresses end ESM channels descriptor
0055  *
0056  * @return Void, in the case of error invokes bsp_selftest_fail_notification()
0057  *
0058  * The descriptor provides address of the module registers and address
0059  * of internal RAM memory and corresponding parity area test access window.
0060  * This test function is usable for HETx, HTUx, ADC, DMA and VIM TMS570
0061  * peripherals.
0062  */
0063 void tms570_selftest_par_check_std( const tms570_selftest_par_desc_t *desc )
0064 {
0065   volatile uint32_t test_read_data;
0066   uint32_t          par_cr_bak = *desc->par_cr_reg;
0067   int               perr;
0068 
0069   /* Set TEST mode and enable parity checking */
0070   *desc->par_cr_reg = desc->par_cr_test | TMS570_SELFTEST_PAR_CR_KEY;
0071 
0072   /* flip parity bit */
0073   *desc->par_loc ^= desc->par_xor;
0074 
0075   /* Disable TEST mode */
0076   *desc->par_cr_reg = TMS570_SELFTEST_PAR_CR_KEY;
0077 
0078   /* read to cause parity error */
0079   test_read_data = *desc->ram_loc;
0080   (void) test_read_data;
0081 
0082   /* check if ESM channel is flagged */
0083   perr = tms570_esm_channel_sr_get( desc->esm_prim_grp, desc->esm_prim_chan );
0084 
0085   if ( desc->esm_sec_grp )
0086     perr |= tms570_esm_channel_sr_get( desc->esm_sec_grp, desc->esm_sec_chan );
0087 
0088   if ( !perr ) {
0089     /* RAM parity error was not flagged to ESM. */
0090     bsp_selftest_fail_notification( desc->fail_code );
0091   } else {
0092     /* If periperal has it own parity status register, clear it */
0093     if ( desc->par_st_reg != NULL )
0094       *desc->par_st_reg = desc->par_st_clear;
0095 
0096     /* clear ESM flag */
0097     tms570_esm_channel_sr_clear( desc->esm_prim_grp, desc->esm_prim_chan );
0098 
0099     if ( desc->esm_sec_grp )
0100       tms570_esm_channel_sr_clear( desc->esm_sec_grp, desc->esm_sec_chan );
0101 
0102     /* Set TEST mode and enable parity checking */
0103     *desc->par_cr_reg = desc->par_cr_test | TMS570_SELFTEST_PAR_CR_KEY;
0104 
0105     /* Revert back to correct data by flipping parity location */
0106     *desc->par_loc ^= desc->par_xor;
0107   }
0108 
0109   /* Restore Parity comtrol register */
0110   *desc->par_cr_reg = par_cr_bak;
0111 }