summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libbsp/arm/tms570/hwinit/tms570_tcram_tests.c
blob: d0c7bbfff55ca6c2b62676efd7f091c7e5c8fa8b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/**
 * @file tms570_tcram_tests.c
 *
 * @ingroup tms570
 *
 * @brief TCRAM selftest function.
 */
/*
 * Copyright (c) 2016 Pavel Pisa <pisa@cmp.felk.cvut.cz>
 *
 * Czech Technical University in Prague
 * Zikova 1903/4
 * 166 36 Praha 6
 * Czech Republic
 *
 * The license and distribution terms for this file may be
 * found in the file LICENSE in this distribution or at
 * http://www.rtems.org/license/LICENSE.
 *
 * Algorithms are based on Ti manuals and Ti HalCoGen generated
 * code available under following copyright.
 */
/*
 * Copyright (C) 2009-2015 Texas Instruments Incorporated - www.ti.com
 *
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions
 *  are met:
 *
 *    Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 *    Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the
 *    distribution.
 *
 *    Neither the name of Texas Instruments Incorporated nor the names of
 *    its contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */

#include <stdint.h>
#include <bsp/tms570.h>
#include "tms570_selftest.h"
#include "tms570_hwinit.h"

#define tcramA1bitError (*(volatile uint32_t *)(0x08400000U))
#define tcramA2bitError (*(volatile uint32_t *)(0x08400010U))

#define tcramB1bitError (*(volatile uint32_t *)(0x08400008U))
#define tcramB2bitError (*(volatile uint32_t *)(0x08400018U))

#define tcramA1bit      (*(volatile uint64_t *)(0x08000000U))
#define tcramA2bit      (*(volatile uint64_t *)(0x08000010U))

#define tcramB1bit      (*(volatile uint64_t *)(0x08000008U))
#define tcramB2bit      (*(volatile uint64_t *)(0x08000018U))

/**
 * @brief Check TCRAM ECC error detection logic (HCG:checkRAMECC)
 *
 * This function checks TCRAM ECC error detection and correction logic.
 * The function does not return in case of TCRAM error.
 * It calls bsp_selftest_fail_notification() instead.
 *
 */
/* SourceId : SELFTEST_SourceId_034 */
/* DesignId : SELFTEST_DesignId_019 */
/* Requirements : HL_SR408 */
void  tms570_check_tcram_ecc( void )
{
  volatile uint64_t ramread;
  volatile uint32_t regread;
  uint32_t tcram1ErrStat, tcram2ErrStat = 0U;

  uint64_t tcramA1_bk = tcramA1bit;
  uint64_t tcramB1_bk = tcramB1bit;
  uint64_t tcramA2_bk = tcramA2bit;
  uint64_t tcramB2_bk = tcramB2bit;

  /* Clear RAMOCUUR before setting RAMTHRESHOLD register */
  TMS570_TCRAM1.RAMOCCUR = 0U;
  TMS570_TCRAM2.RAMOCCUR = 0U;

  /* Set Single-bit Error Threshold Count as 1 */
  TMS570_TCRAM1.RAMTHRESHOLD = 1U;
  TMS570_TCRAM2.RAMTHRESHOLD = 1U;

  /* Enable single bit error generation */
  TMS570_TCRAM1.RAMINTCTRL = 1U;
  TMS570_TCRAM2.RAMINTCTRL = 1U;

  /* Enable writes to ECC RAM, enable ECC error response */
  TMS570_TCRAM1.RAMCTRL = 0x0005010AU;
  TMS570_TCRAM2.RAMCTRL = 0x0005010AU;

  /* Force a single bit error in both the banks */
  _coreDisableRamEcc_();
  tcramA1bitError ^= 1U;
  tcramB1bitError ^= 1U;
  _coreEnableRamEcc_();

  /* Read the corrupted data to generate single bit error */
  ramread = tcramA1bit;
  ramread = tcramB1bit;
  (void)ramread;

  /* Check for error status */
  tcram1ErrStat = TMS570_TCRAM1.RAMERRSTATUS & 0x1U;
  tcram2ErrStat = TMS570_TCRAM2.RAMERRSTATUS & 0x1U;
  /*SAFETYMCUSW 139 S MR:13.7  <APPROVED> "LDRA Tool issue" */
  /*SAFETYMCUSW 139 S MR:13.7  <APPROVED> "LDRA Tool issue" */
  if ((tcram1ErrStat == 0U) || (tcram2ErrStat == 0U)) {
        /* TCRAM module does not reflect 1-bit error reported by CPU */
    bsp_selftest_fail_notification(CHECKRAMECC_FAIL1);
  } else {
    if (!tms570_esm_channel_sr_get(1, 26) || !tms570_esm_channel_sr_get(1, 28)) {
      /* TCRAM 1-bit error not flagged in ESM */
      bsp_selftest_fail_notification(CHECKRAMECC_FAIL2);
    } else {
      /* Clear single bit error flag in TCRAM module */
      TMS570_TCRAM1.RAMERRSTATUS = 0x1U;
      TMS570_TCRAM2.RAMERRSTATUS = 0x1U;

      /* Clear ESM status */
      tms570_esm_channel_sr_clear(1, 26);
      tms570_esm_channel_sr_clear(1, 28);
    }
  }

#if 0
  /*
   * This test sequence requires that data abort exception
   * handler checks for ECC test write enable in RAMCTR (bit 8)
   * and if the access abort is intended then it should clear
   * error status TCRAM status register and checks and clears
   * ESM group3 uncorrectable TCRAM error channels.
   *
   * More modifications in BSP and RTEMS ARM support are
   * required to make this code work.
   */

  /* Force a double bit error in both the banks */
  _coreDisableRamEcc_();
  tcramA2bitError ^= 3U;
  tcramB2bitError ^= 3U;
  _coreEnableRamEcc_();

  /* Read the corrupted data to generate double bit error */
  ramread = tcramA2bit;
  ramread = tcramB2bit;
  /* read from location with 2-bit ECC error this will cause a data abort to be generated */
  /* See HalCoGen support src/sys/asm/dabort.asm */
  /* _ARMV4_Exception_data_abort_default has to include solution for this special case for RTEMS */
#endif

  regread = TMS570_TCRAM1.RAMUERRADDR;
  regread = TMS570_TCRAM2.RAMUERRADDR;
  (void)regread;

  /* disable writes to ECC RAM */
  TMS570_TCRAM1.RAMCTRL = 0x0005000AU;
  TMS570_TCRAM2.RAMCTRL = 0x0005000AU;

  /* Compute correct ECC */
  tcramA1bit = tcramA1_bk;
  tcramB1bit = tcramB1_bk;
  tcramA2bit = tcramA2_bk;
  tcramB2bit = tcramB2_bk;
}