1 | /** |
---|
2 | * @file tms570_selftest_par_can.c |
---|
3 | * |
---|
4 | * @ingroup tms570 |
---|
5 | * |
---|
6 | * @brief Test CAN module parity based protection logic to work. |
---|
7 | */ |
---|
8 | /* |
---|
9 | * Copyright (c) 2016 Pavel Pisa <pisa@cmp.felk.cvut.cz> |
---|
10 | * |
---|
11 | * Czech Technical University in Prague |
---|
12 | * Zikova 1903/4 |
---|
13 | * 166 36 Praha 6 |
---|
14 | * Czech Republic |
---|
15 | * |
---|
16 | * The license and distribution terms for this file may be |
---|
17 | * found in the file LICENSE in this distribution or at |
---|
18 | * http://www.rtems.org/license/LICENSE. |
---|
19 | * |
---|
20 | * Algorithms are based on Ti manuals and Ti HalCoGen generated |
---|
21 | * code. |
---|
22 | */ |
---|
23 | |
---|
24 | #include <stdint.h> |
---|
25 | #include <stddef.h> |
---|
26 | #include <bsp/tms570.h> |
---|
27 | #include "tms570_selftest.h" |
---|
28 | #include "tms570_selftest_parity.h" |
---|
29 | |
---|
30 | /** |
---|
31 | * @brief run test to check that parity protection works for CAN modules RAM |
---|
32 | * |
---|
33 | * @param[in] desc module registers addresses end ESM channels descriptor |
---|
34 | * |
---|
35 | * @return Void, in the case of error invokes bsp_selftest_fail_notification() |
---|
36 | * |
---|
37 | * The descriptor provides address of the module registers and address |
---|
38 | * of internal RAM memory and corresponding parity area test access window. |
---|
39 | */ |
---|
40 | void tms570_selftest_par_check_can( const tms570_selftest_par_desc_t *desc ) |
---|
41 | { |
---|
42 | volatile uint32_t test_read_data; |
---|
43 | volatile tms570_dcan_t *can_regs = (volatile tms570_dcan_t *) desc->fnc_data; |
---|
44 | uint32_t canctl_bak = can_regs->CTL; |
---|
45 | uint32_t canctl_pmd; |
---|
46 | int perr; |
---|
47 | |
---|
48 | /* Set TEST mode and enable parity checking */ |
---|
49 | /* Disable parity, init mode, TEST mode */ |
---|
50 | canctl_pmd = TMS570_DCAN_CTL_PMD_SET( 0, 0x5 ); |
---|
51 | can_regs->CTL = canctl_pmd | TMS570_DCAN_CTL_Test | TMS570_DCAN_CTL_Init; |
---|
52 | |
---|
53 | /* Enable RAM Direct Access mode */ |
---|
54 | can_regs->TEST = TMS570_DCAN_TEST_RDA; |
---|
55 | |
---|
56 | /* flip parity bit */ |
---|
57 | *desc->par_loc ^= desc->par_xor; |
---|
58 | |
---|
59 | /* Disable TEST mode */ |
---|
60 | canctl_pmd = TMS570_DCAN_CTL_PMD_SET( 0, 0xA ); |
---|
61 | can_regs->CTL = canctl_pmd | TMS570_DCAN_CTL_Test; |
---|
62 | |
---|
63 | /* read to cause parity error */ |
---|
64 | test_read_data = *desc->ram_loc; |
---|
65 | (void) test_read_data; |
---|
66 | |
---|
67 | /* check if ESM channel is flagged */ |
---|
68 | perr = tms570_esm_channel_sr_get( desc->esm_prim_grp, desc->esm_prim_chan ); |
---|
69 | |
---|
70 | if ( !perr ) { |
---|
71 | /* RAM parity error was not flagged to ESM. */ |
---|
72 | bsp_selftest_fail_notification( desc->fail_code ); |
---|
73 | } else { |
---|
74 | /* clear ESM flag */ |
---|
75 | tms570_esm_channel_sr_clear( desc->esm_prim_grp, desc->esm_prim_chan ); |
---|
76 | |
---|
77 | /* Set TEST mode and enable parity checking */ |
---|
78 | canctl_pmd = TMS570_DCAN_CTL_PMD_SET( 0, 0x5 ); |
---|
79 | can_regs->CTL = canctl_pmd | TMS570_DCAN_CTL_Test | TMS570_DCAN_CTL_Init; |
---|
80 | |
---|
81 | /* Revert back to correct data by flipping parity location */ |
---|
82 | *desc->par_loc ^= desc->par_xor; |
---|
83 | } |
---|
84 | |
---|
85 | /* Disable RAM Direct Access mode */ |
---|
86 | can_regs->TEST = 0x00000000U; |
---|
87 | |
---|
88 | /* Restore CTL register */ |
---|
89 | can_regs->CTL = canctl_bak; |
---|
90 | |
---|
91 | /* Read Error and Status register to clear Parity Error bit */ |
---|
92 | test_read_data = can_regs->ES; |
---|
93 | } |
---|