source: rtems/bsps/bfin/bf537Stamp/start/bspstart.c @ 511dc4b

5
Last change on this file since 511dc4b was 9964895, checked in by Sebastian Huber <sebastian.huber@…>, on 04/20/18 at 08:35:35

bsps: Move startup files to bsps

Adjust build support files to new directory layout.

This patch is a part of the BSP source reorganization.

Update #3285.

  • Property mode set to 100644
File size: 8.2 KB
Line 
1/*  bspstart.c for bf537Stamp
2 *
3 *  This routine does the bulk of the system initialisation.
4 */
5
6/*
7 *  Copyright (c) 2006 by Atos Automacao Industrial Ltda.
8 *             written by Alain Schaefer <alain.schaefer@easc.ch>
9 *                    and Antonio Giovanini <antonio@atos.com.br>
10 *
11 *  The license and distribution terms for this file may be
12 *  found in the file LICENSE in this distribution or at
13 *  http://www.rtems.org/license/LICENSE.
14 */
15
16
17#include <bsp.h>
18#include <bsp/bootcard.h>
19#include <libcpu/bf537.h>
20#include <libcpu/ebiuRegs.h>
21#include <libcpu/gpioRegs.h>
22#include <libcpu/mmu.h>
23#include <libcpu/mmuRegs.h>
24#include <libcpu/interrupt.h>
25#include <rtems/sysinit.h>
26
27static bfin_mmu_config_t mmuRegions = {
28    /* instruction */
29    {
30        {(void *) 0x00000000, ICPLB_DATA_PAGE_SIZE_4MB | INSTR_CACHEABLE},
31        {(void *) 0x00400000, ICPLB_DATA_PAGE_SIZE_4MB | INSTR_CACHEABLE},
32        {(void *) 0x00800000, ICPLB_DATA_PAGE_SIZE_4MB | INSTR_CACHEABLE},
33        {(void *) 0x00c00000, ICPLB_DATA_PAGE_SIZE_4MB | INSTR_CACHEABLE},
34        {(void *) 0x01000000, ICPLB_DATA_PAGE_SIZE_4MB | INSTR_CACHEABLE},
35        {(void *) 0x01400000, ICPLB_DATA_PAGE_SIZE_4MB | INSTR_CACHEABLE},
36        {(void *) 0x01800000, ICPLB_DATA_PAGE_SIZE_4MB | INSTR_CACHEABLE},
37        {(void *) 0x01c00000, ICPLB_DATA_PAGE_SIZE_4MB | INSTR_CACHEABLE},
38        {(void *) 0x02000000, ICPLB_DATA_PAGE_SIZE_4MB | INSTR_CACHEABLE},
39        {(void *) 0x02400000, ICPLB_DATA_PAGE_SIZE_4MB | INSTR_CACHEABLE},
40        {(void *) 0x02800000, ICPLB_DATA_PAGE_SIZE_4MB | INSTR_CACHEABLE},
41        {(void *) 0x02c00000, ICPLB_DATA_PAGE_SIZE_4MB | INSTR_CACHEABLE},
42        {(void *) 0x03000000, ICPLB_DATA_PAGE_SIZE_4MB | INSTR_CACHEABLE},
43        {(void *) 0x20000000, ICPLB_DATA_PAGE_SIZE_4MB | INSTR_CACHEABLE},
44        {(void *) 0xff800000, ICPLB_DATA_PAGE_SIZE_4MB | INSTR_NOCACHE},
45        {(void *) 0xffc00000, ICPLB_DATA_PAGE_SIZE_4MB | INSTR_NOCACHE}
46    },
47    /* data */
48    {
49        {(void *) 0x00000000, DCPLB_DATA_PAGE_SIZE_4MB | DATA_WRITEBACK},
50        {(void *) 0x00400000, DCPLB_DATA_PAGE_SIZE_4MB | DATA_WRITEBACK},
51        {(void *) 0x00800000, DCPLB_DATA_PAGE_SIZE_4MB | DATA_WRITEBACK},
52        {(void *) 0x00c00000, DCPLB_DATA_PAGE_SIZE_4MB | DATA_WRITEBACK},
53        {(void *) 0x01000000, DCPLB_DATA_PAGE_SIZE_4MB | DATA_WRITEBACK},
54        {(void *) 0x01400000, DCPLB_DATA_PAGE_SIZE_4MB | DATA_WRITEBACK},
55        {(void *) 0x01800000, DCPLB_DATA_PAGE_SIZE_4MB | DATA_WRITEBACK},
56        {(void *) 0x01c00000, DCPLB_DATA_PAGE_SIZE_4MB | DATA_WRITEBACK},
57        {(void *) 0x02000000, DCPLB_DATA_PAGE_SIZE_4MB | DATA_WRITEBACK},
58        {(void *) 0x02400000, DCPLB_DATA_PAGE_SIZE_4MB | DATA_WRITEBACK},
59        {(void *) 0x02800000, DCPLB_DATA_PAGE_SIZE_4MB | DATA_WRITEBACK},
60        {(void *) 0x02c00000, DCPLB_DATA_PAGE_SIZE_4MB | DATA_WRITEBACK},
61        {(void *) 0x03000000, DCPLB_DATA_PAGE_SIZE_4MB | DATA_WRITEBACK},
62        {(void *) 0x20000000, DCPLB_DATA_PAGE_SIZE_4MB | DATA_WRITEBACK},
63        {(void *) 0xff800000, DCPLB_DATA_PAGE_SIZE_4MB | DATA_NOCACHE},
64        {(void *) 0xffc00000, DCPLB_DATA_PAGE_SIZE_4MB | DATA_NOCACHE}
65    }
66};
67
68static void initPLL(void);
69static void initEBIU(void);
70static void initGPIO(void);
71
72RTEMS_SYSINIT_ITEM(
73  bfin_interrupt_init,
74  RTEMS_SYSINIT_BSP_PRE_DRIVERS,
75  RTEMS_SYSINIT_ORDER_MIDDLE
76);
77
78void bsp_start(void)
79{
80  /* BSP Hardware Initialization*/
81
82  *(uint32_t volatile *) DMEM_CONTROL |= DMEM_CONTROL_PORT_PREF0;
83  *(uint32_t volatile *) DMEM_CONTROL &= ~DMEM_CONTROL_PORT_PREF1;
84  bfin_mmu_init(&mmuRegions);
85  rtems_cache_enable_instruction();
86  rtems_cache_enable_data();
87
88  Init_RTC();   /* Blackfin Real Time Clock initialization */
89
90  initPLL();   /* PLL initialization */
91  initEBIU();  /* EBIU initialization */
92  initGPIO();  /* GPIO initialization */
93}
94
95 /*
96  * initPLL
97  *
98  * Routine to initialize the PLL. The BF537 Stamp uses a 27 Mhz XTAL. BISON
99  * See "../bf537Stamp/include/bsp.h" for more information.
100  */
101
102static void initPLL(void) {
103
104#ifdef BISON
105  unsigned int n;
106
107  /* Configure PLL registers */
108  *((uint16_t*)PLL_LOCKCNT) = 0x1000;
109  *((uint16_t*)PLL_DIV) = PLL_CSEL|PLL_SSEL;
110  *((uint16_t*)PLL_CTL) = PLL_MSEL|PLL_DF;
111
112  /* Commands to set PLL values */
113  __asm__ ("cli r0;");
114  __asm__ ("idle;");
115  __asm__ ("sti r0;");
116
117  /* Delay for PLL stabilization */
118  for (n=0; n<200; n++) {}
119#endif
120
121}
122
123 /*
124  * initEBIU
125  *
126  * Configure extern memory
127  */
128
129static void initEBIU(void) {
130
131  /* by default the processor has priority over dma channels for access to
132     external memory.  this has been seen to result in dma unerruns on
133     ethernet transmit; it seems likely it could cause dma overruns on
134     ethernet receive as well.  setting the following bit gives the dma
135     channels priority over the cpu, fixing that problem.  unfortunately
136     we don't have finer grain control than that; all dma channels now
137     have priority over the cpu. */
138  *(uint16_t volatile *) EBIU_AMGCTL |= EBIU_AMGCTL_CDPRIO;
139
140#ifdef BISON
141  /* Configure FLASH */
142  *((uint32_t*)EBIU_AMBCTL0)  = 0x7bb07bb0L;
143  *((uint32_t*)EBIU_AMBCTL1)  = 0x7bb07bb0L;
144  *((uint16_t*)EBIU_AMGCTL)   = 0x000f;
145
146  /* Configure SDRAM
147  *((uint32_t*)EBIU_SDGCTL) = 0x0091998d;
148  *((uint16_t*)EBIU_SDBCTL) = 0x0013;
149  *((uint16_t*)EBIU_SDRRC)  = 0x0817;
150  */
151#endif
152}
153
154 /*
155  * initGPIO
156  *
157  * Enable LEDs port
158  */
159static void initGPIO(void) {
160#if (!BFIN_ON_SKYEYE)
161  *(uint16_t volatile *) PORT_MUX = 0;
162
163  /* port f bits 0, 1: uart0 tx, rx */
164  /*        bits 2 - 5: buttons */
165  /*        bits 6 - 11: leds */
166  *(uint16_t volatile *) PORTF_FER = 0x0003;
167  *(uint16_t volatile *) (PORTFIO_BASE_ADDRESS + PORTIO_OFFSET) = 0x0000;
168  *(uint16_t volatile *) (PORTFIO_BASE_ADDRESS + PORTIO_INEN_OFFSET) = 0x003c;
169  *(uint16_t volatile *) (PORTFIO_BASE_ADDRESS + PORTIO_POLAR_OFFSET) = 0x0000;
170  *(uint16_t volatile *) (PORTFIO_BASE_ADDRESS + PORTIO_EDGE_OFFSET) = 0x0000;
171  *(uint16_t volatile *) (PORTFIO_BASE_ADDRESS + PORTIO_BOTH_OFFSET) = 0x0000;
172  *(uint16_t volatile *) (PORTFIO_BASE_ADDRESS + PORTIO_MASKA_OFFSET) = 0x0000;
173  *(uint16_t volatile *) (PORTFIO_BASE_ADDRESS + PORTIO_MASKB_OFFSET) = 0x0000;
174  *(uint16_t volatile *) (PORTFIO_BASE_ADDRESS + PORTIO_DIR_OFFSET) = 0x0fc0;
175
176  *(uint16_t volatile *) PORTG_FER = 0x0000;
177  *(uint16_t volatile *) (PORTGIO_BASE_ADDRESS + PORTIO_OFFSET) = 0x0000;
178  *(uint16_t volatile *) (PORTGIO_BASE_ADDRESS + PORTIO_INEN_OFFSET) = 0x0000;
179  *(uint16_t volatile *) (PORTGIO_BASE_ADDRESS + PORTIO_POLAR_OFFSET) = 0x0000;
180  *(uint16_t volatile *) (PORTGIO_BASE_ADDRESS + PORTIO_EDGE_OFFSET) = 0x0000;
181  *(uint16_t volatile *) (PORTGIO_BASE_ADDRESS + PORTIO_BOTH_OFFSET) = 0x0000;
182  *(uint16_t volatile *) (PORTGIO_BASE_ADDRESS + PORTIO_MASKA_OFFSET) = 0x0000;
183  *(uint16_t volatile *) (PORTGIO_BASE_ADDRESS + PORTIO_MASKB_OFFSET) = 0x0000;
184  *(uint16_t volatile *) (PORTGIO_BASE_ADDRESS + PORTIO_DIR_OFFSET) = 0x0000;
185
186  /* port h bits 0 - 15: ethernet */
187  *(uint16_t volatile *) PORTH_FER = 0xffff;
188  *(uint16_t volatile *) (PORTHIO_BASE_ADDRESS + PORTIO_OFFSET) = 0x0000;
189  *(uint16_t volatile *) (PORTHIO_BASE_ADDRESS + PORTIO_INEN_OFFSET) = 0x0000;
190  *(uint16_t volatile *) (PORTHIO_BASE_ADDRESS + PORTIO_POLAR_OFFSET) = 0x0000;
191  *(uint16_t volatile *) (PORTHIO_BASE_ADDRESS + PORTIO_EDGE_OFFSET) = 0x0000;
192  *(uint16_t volatile *) (PORTHIO_BASE_ADDRESS + PORTIO_BOTH_OFFSET) = 0x0000;
193  *(uint16_t volatile *) (PORTHIO_BASE_ADDRESS + PORTIO_MASKA_OFFSET) = 0x0000;
194  *(uint16_t volatile *) (PORTHIO_BASE_ADDRESS + PORTIO_MASKB_OFFSET) = 0x0000;
195  *(uint16_t volatile *) (PORTHIO_BASE_ADDRESS + PORTIO_DIR_OFFSET) = 0x0000;
196#endif
197}
198
199/*
200 * Helper Function to use the EzKits LEDS.
201 * Can be used by the Application.
202 */
203void setLEDs(uint8_t value) {
204
205  *(uint16_t volatile *) (PORTFIO_BASE_ADDRESS + PORTIO_CLEAR_OFFSET) =
206      (uint16_t) (~value & 0x3f) << 6;
207  *(uint16_t volatile *) (PORTFIO_BASE_ADDRESS + PORTIO_SET_OFFSET) =
208      (uint16_t) (value & 0x3f) << 6;
209}
210
211/*
212 * Helper Function to use the EzKits LEDS
213 */
214uint8_t getLEDs(void) {
215  uint16_t r;
216
217  r = *(uint16_t volatile *) (PORTFIO_BASE_ADDRESS + PORTIO_OFFSET);
218  return (uint8_t) ((r >> 6) & 0x3f);
219}
220
221uint8_t getButtons(void) {
222  uint16_t r;
223
224  r = *(uint16_t volatile *) (PORTFIO_BASE_ADDRESS + PORTIO_OFFSET);
225
226  return (uint8_t) ((r >> 2) & 0x0f);
227}
228
229
Note: See TracBrowser for help on using the repository browser.