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 CAN module parity based protection
0009  *   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 CAN modules RAM
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  */
0061 void tms570_selftest_par_check_can( const tms570_selftest_par_desc_t *desc )
0062 {
0063   volatile uint32_t       test_read_data;
0064   volatile tms570_dcan_t *can_regs = (volatile tms570_dcan_t *) desc->fnc_data;
0065   uint32_t                canctl_bak = can_regs->CTL;
0066   uint32_t                canctl_pmd;
0067   int                     perr;
0068 
0069   /* Set TEST mode and enable parity checking */
0070   /* Disable parity, init mode, TEST mode */
0071   canctl_pmd = TMS570_DCAN_CTL_PMD_SET( 0, 0x5 );
0072   can_regs->CTL = canctl_pmd | TMS570_DCAN_CTL_Test | TMS570_DCAN_CTL_Init;
0073 
0074   /* Enable RAM Direct Access mode */
0075   can_regs->TEST = TMS570_DCAN_TEST_RDA;
0076 
0077   /* flip parity bit */
0078   *desc->par_loc ^= desc->par_xor;
0079 
0080   /* Disable TEST mode */
0081   canctl_pmd = TMS570_DCAN_CTL_PMD_SET( 0, 0xA );
0082   can_regs->CTL = canctl_pmd | TMS570_DCAN_CTL_Test;
0083 
0084   /* read to cause parity error */
0085   test_read_data = *desc->ram_loc;
0086   (void) test_read_data;
0087 
0088   /* check if ESM channel is flagged */
0089   perr = tms570_esm_channel_sr_get( desc->esm_prim_grp, desc->esm_prim_chan );
0090 
0091   if ( !perr ) {
0092     /* RAM parity error was not flagged to ESM. */
0093     bsp_selftest_fail_notification( desc->fail_code );
0094   } else {
0095     /* clear ESM flag */
0096     tms570_esm_channel_sr_clear( desc->esm_prim_grp, desc->esm_prim_chan );
0097 
0098     /* Set TEST mode and enable parity checking */
0099     canctl_pmd = TMS570_DCAN_CTL_PMD_SET( 0, 0x5 );
0100     can_regs->CTL = canctl_pmd | TMS570_DCAN_CTL_Test | TMS570_DCAN_CTL_Init;
0101 
0102     /* Revert back to correct data by flipping parity location */
0103     *desc->par_loc ^= desc->par_xor;
0104   }
0105 
0106   /* Disable RAM Direct Access mode */
0107   can_regs->TEST = 0x00000000U;
0108 
0109   /* Restore CTL register */
0110   can_regs->CTL = canctl_bak;
0111 
0112   /* Read Error and Status register to clear Parity Error bit */
0113   test_read_data = can_regs->ES;
0114 }