]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/blob - rpp/src/sys/pom_vect_remap.c
Change license to MIT
[pes-rpp/rpp-lib.git] / rpp / src / sys / pom_vect_remap.c
1 /* Copyright (C) 2013 Czech Technical University in Prague
2  *
3  * Authors:
4  *     - Pavel Pisa
5  *     - Michal Horn
6  *
7  * Permission is hereby granted, free of charge, to any person
8  * obtaining a copy of this software and associated documentation
9  * files (the "Software"), to deal in the Software without
10  * restriction, including without limitation the rights to use,
11  * copy, modify, merge, publish, distribute, sublicense, and/or sell
12  * copies of the Software, and to permit persons to whom the
13  * Software is furnished to do so, subject to the following
14  * conditions:
15  *
16  * The above copyright notice and this permission notice shall be
17  * included in all copies or substantial portions of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
21  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
23  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26  * OTHER DEALINGS IN THE SOFTWARE.
27  *
28  * File : pom_vect_remap.c
29  * Abstract:
30  *     Setup of parameter overlay module which remaps SRAM areal
31  *     over exception vectors at start of the Flash which enables
32  *     to redirect them to application load into SDRAM, SRAM
33  *     or placed after bootblock in the Flash
34  *
35  * References:
36  *     RPP API documentation.
37  */
38
39 #include <stdint.h>
40 #include <sys/ti_drv_pom.h>
41
42 #define POM_REGIONS 32
43 #define POM_SIZE_DISABLED 0
44 #define POM_REGADDRMASK    ((1<<23)-1)
45 #define POM_GLBCTRL_ENABLE 0x000000a0a
46 #define ARM_MAX_EXCEPTIONS 8
47
48 #pragma DATA_ALIGN(pom_vector_overlay, 64)
49 uint32_t pom_vector_overlay[2*ARM_MAX_EXCEPTIONS];
50 /*
51    0    b   _c_int00
52    1    b   undefEntry
53    2    b   vPortYieldProcessor
54    3    b   prefetchEntry
55    4    b   _dabort
56    5    b   reservedEntry
57    6    ldr pc,[pc,#-0x1b0]
58    7    ldr pc,[pc,#-0x1b0]
59  */
60
61 extern void _dabort(void);
62 extern void vPortYieldProcessor(void);
63
64 void pom_set_cpu_exception_handler(int cpu_exception, uint32_t target_addr)
65 {
66
67         /* e59ff018        ldr     pc, [pc, #24] */
68         pom_vector_overlay[cpu_exception] = 0xe59ff000+(ARM_MAX_EXCEPTIONS*4-8);
69         pom_vector_overlay[cpu_exception+ARM_MAX_EXCEPTIONS] = target_addr;
70 }
71
72 /**
73  * @brief remaps vector table
74  *
75  * transfer the rtems start vector table to address 0x0
76  *
77  * @retval Void
78  */
79 void pom_vectors_remap(void)
80 {
81         int i;
82         uint32_t vec_overlay_start = (uint32_t)pom_vector_overlay;
83
84         pomREG->POMGLBCTRL_UL = 0;
85
86         memcpy(pom_vector_overlay, (void *)(volatile void *)0x0, 64);
87         pom_set_cpu_exception_handler(2, (uint32_t)vPortYieldProcessor);
88         pom_set_cpu_exception_handler(4, (uint32_t)_dabort);
89         /* ldr pc,[pc,#-0x1b0] */
90         pom_vector_overlay[6] = 0xe51ff1b0;
91         /* ldr pc,[pc,#-0x1b0] */
92         pom_vector_overlay[7] = 0xe51ff1b0;
93
94
95         for ( i = 0; i < POM_REGIONS; ++i ) {
96                 pomREG->POMRGNCONF_ST[i].POMREGSIZE_UL = POM_SIZE_DISABLED;
97         }
98
99         pomREG->POMRGNCONF_ST[0].POMPROGSTART_UL = 0x0 & POM_REGADDRMASK;
100         pomREG->POMRGNCONF_ST[0].POMOVLSTART_UL = vec_overlay_start & POM_REGADDRMASK;
101         pomREG->POMRGNCONF_ST[0].POMREGSIZE_UL = SIZE_64BYTES;
102
103         pomREG->POMGLBCTRL_UL = POM_GLBCTRL_ENABLE |
104                                                         (vec_overlay_start & ~POM_REGADDRMASK);
105 }