source: rtems/c/src/lib/libbsp/bfin/bf537Stamp/startup/bspstart.c @ 321cce4

4.104.11
Last change on this file since 321cce4 was 321cce4, checked in by Joel Sherrill <joel.sherrill@…>, on Sep 25, 2008 at 8:07:25 PM

2008-09-25 Allan Hessenflow <allanh@…>

  • include/bsp.h, startup/bspstart.c:
  • Property mode set to 100644
File size: 5.3 KB
Line 
1/*  bspstart.c for bf537Stamp
2 *
3 *  This routine starts the application.  It includes application,
4 *  board, and monitor specific initialization and configuration.
5 *  The generic CPU dependent initialization has been performed
6 *  before this routine is invoked.
7 * 
8 *  Copyright (c) 2006 by Atos Automacao Industrial Ltda.
9 *             written by Alain Schaefer <alain.schaefer@easc.ch>
10 *                    and Antonio Giovanini <antonio@atos.com.br>
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.com/license/LICENSE.
15 *
16 *  $Id$
17 */
18
19
20#include <bsp.h>
21#include <libcpu/bf537.h>
22#include <libcpu/gpioRegs.h>
23#include <libcpu/mmu.h>
24#include <libcpu/interrupt.h>
25
26
27#if 0
28static bfin_mmu_region_t mmuRegions[] = {
29};
30#endif
31
32void Init_RTC(void);
33
34static void initPLL(void);
35static void initEBIU(void);
36static void initGPIO(void);
37
38/*
39 *  BSP pretasking hook.
40 */
41void bsp_pretasking_hook(void)
42{
43  bfin_interrupt_init();
44}
45
46/*
47 *  bsp_start
48 *
49 *  This routine does the bulk of the BSP initialization.
50 */
51void bsp_start(void)
52{
53  /* BSP Hardware Initialization*/
54
55  /*bfin_mmu_init(sizeof(mmuRegions) / sizeof(mmuRegions[0]), mmuRegions);*/
56
57  Init_RTC();   /* Blackfin Real Time Clock initialization */
58
59  initPLL();   /* PLL initialization */
60  initEBIU();  /* EBIU initialization */
61  initGPIO();  /* GPIO initialization */
62}
63
64 /*
65  * initPLL
66  *
67  * Routine to initialize the PLL. The BF537 Stamp uses a 27 Mhz XTAL. BISON
68  * See "../bf537Stamp/include/bsp.h" for more information.
69  */
70
71static void initPLL(void) {
72 
73#ifdef BISON
74  unsigned int n;
75 
76  /* Configure PLL registers */
77  *((uint16_t*)PLL_LOCKCNT) = 0x1000;
78  *((uint16_t*)PLL_DIV) = PLL_CSEL|PLL_SSEL;
79  *((uint16_t*)PLL_CTL) = PLL_MSEL|PLL_DF;
80
81  /* Commands to set PLL values */
82  asm("cli r0;");
83  asm("idle;");
84  asm("sti r0;");
85 
86  /* Delay for PLL stabilization */
87  for (n=0; n<200; n++) {} 
88#endif
89 
90}
91
92 /*
93  * initEBIU
94  *
95  * Configure extern memory
96  */
97
98static void initEBIU(void) {
99#ifdef BISON
100  /* Configure FLASH */
101  *((uint32_t*)EBIU_AMBCTL0)  = 0x7bb07bb0L;
102  *((uint32_t*)EBIU_AMBCTL1)  = 0x7bb07bb0L;
103  *((uint16_t*)EBIU_AMGCTL)   = 0x000f;
104 
105  /* Configure SDRAM
106  *((uint32_t*)EBIU_SDGCTL) = 0x0091998d;
107  *((uint16_t*)EBIU_SDBCTL) = 0x0013;
108  *((uint16_t*)EBIU_SDRRC)  = 0x0817;
109  */
110#endif
111}
112
113 /*
114  * initGPIO
115  *
116  * Enable LEDs port
117  */
118static void initGPIO(void) {
119#if (!BFIN_ON_SKYEYE)
120  *(uint16_t volatile *) PORT_MUX = 0;
121
122  /* port f bits 0, 1: uart0 tx, rx */
123  /*        bits 2 - 5: buttons */
124  /*        bits 6 - 11: leds */
125  *(uint16_t volatile *) PORTF_FER = 0x0003;
126  *(uint16_t volatile *) (PORTFIO_BASE_ADDRESS + PORTIO_OFFSET) = 0x0000;
127  *(uint16_t volatile *) (PORTFIO_BASE_ADDRESS + PORTIO_INEN_OFFSET) = 0x003c;
128  *(uint16_t volatile *) (PORTFIO_BASE_ADDRESS + PORTIO_POLAR_OFFSET) = 0x0000;
129  *(uint16_t volatile *) (PORTFIO_BASE_ADDRESS + PORTIO_EDGE_OFFSET) = 0x0000;
130  *(uint16_t volatile *) (PORTFIO_BASE_ADDRESS + PORTIO_BOTH_OFFSET) = 0x0000;
131  *(uint16_t volatile *) (PORTFIO_BASE_ADDRESS + PORTIO_MASKA_OFFSET) = 0x0000;
132  *(uint16_t volatile *) (PORTFIO_BASE_ADDRESS + PORTIO_MASKB_OFFSET) = 0x0000;
133  *(uint16_t volatile *) (PORTFIO_BASE_ADDRESS + PORTIO_DIR_OFFSET) = 0x0fc0;
134
135  *(uint16_t volatile *) PORTG_FER = 0x0000;
136  *(uint16_t volatile *) (PORTGIO_BASE_ADDRESS + PORTIO_OFFSET) = 0x0000;
137  *(uint16_t volatile *) (PORTGIO_BASE_ADDRESS + PORTIO_INEN_OFFSET) = 0x0000;
138  *(uint16_t volatile *) (PORTGIO_BASE_ADDRESS + PORTIO_POLAR_OFFSET) = 0x0000;
139  *(uint16_t volatile *) (PORTGIO_BASE_ADDRESS + PORTIO_EDGE_OFFSET) = 0x0000;
140  *(uint16_t volatile *) (PORTGIO_BASE_ADDRESS + PORTIO_BOTH_OFFSET) = 0x0000;
141  *(uint16_t volatile *) (PORTGIO_BASE_ADDRESS + PORTIO_MASKA_OFFSET) = 0x0000;
142  *(uint16_t volatile *) (PORTGIO_BASE_ADDRESS + PORTIO_MASKB_OFFSET) = 0x0000;
143  *(uint16_t volatile *) (PORTGIO_BASE_ADDRESS + PORTIO_DIR_OFFSET) = 0x0000;
144
145  /* port h bits 0 - 15: ethernet */
146  *(uint16_t volatile *) PORTH_FER = 0xffff;
147  *(uint16_t volatile *) (PORTHIO_BASE_ADDRESS + PORTIO_OFFSET) = 0x0000;
148  *(uint16_t volatile *) (PORTHIO_BASE_ADDRESS + PORTIO_INEN_OFFSET) = 0x0000;
149  *(uint16_t volatile *) (PORTHIO_BASE_ADDRESS + PORTIO_POLAR_OFFSET) = 0x0000;
150  *(uint16_t volatile *) (PORTHIO_BASE_ADDRESS + PORTIO_EDGE_OFFSET) = 0x0000;
151  *(uint16_t volatile *) (PORTHIO_BASE_ADDRESS + PORTIO_BOTH_OFFSET) = 0x0000;
152  *(uint16_t volatile *) (PORTHIO_BASE_ADDRESS + PORTIO_MASKA_OFFSET) = 0x0000;
153  *(uint16_t volatile *) (PORTHIO_BASE_ADDRESS + PORTIO_MASKB_OFFSET) = 0x0000;
154  *(uint16_t volatile *) (PORTHIO_BASE_ADDRESS + PORTIO_DIR_OFFSET) = 0x0000;
155#endif
156}
157
158/*
159 * Helper Function to use the EzKits LEDS.
160 * Can be used by the Application.
161 */
162void setLEDs(uint8_t value) {
163
164  *(uint16_t volatile *) (PORTFIO_BASE_ADDRESS + PORTIO_CLEAR_OFFSET) =
165      (uint16_t) (~value & 0x3f) << 6;
166  *(uint16_t volatile *) (PORTFIO_BASE_ADDRESS + PORTIO_SET_OFFSET) =
167      (uint16_t) (value & 0x3f) << 6;
168}
169
170/*
171 * Helper Function to use the EzKits LEDS
172 */
173uint8_t getLEDs(void) {
174  uint16_t r;
175
176  r = *(uint16_t volatile *) (PORTFIO_BASE_ADDRESS + PORTIO_OFFSET);
177  return (uint8_t) ((r >> 6) & 0x3f);
178}
179
180uint8_t getButtons(void) {
181  uint16_t r;
182
183  r = *(uint16_t volatile *) (PORTFIO_BASE_ADDRESS + PORTIO_OFFSET);
184
185  return (uint8_t) ((r >> 2) & 0x0f);
186}
187
188
Note: See TracBrowser for help on using the repository browser.