source: rtems/c/src/lib/libbsp/powerpc/mpc8260ads/startup/bspstart.c @ 74af8c0

Last change on this file since 74af8c0 was 74af8c0, checked in by Sebastian Huber <sebastian.huber@…>, on 04/02/12 at 09:32:11

bsps: More accurate PowerPC clock driver

The clock driver used previously the bsp_clicks_per_usec value. For a
33333333Hz time base frequency this leads to a relative error of one per
cent for example due to integer truncation.

  • Property mode set to 100644
File size: 5.4 KB
Line 
1/*  bsp_start()
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 *  The MPC860 specific stuff was written by Jay Monkman (jmonkman@frasca.com)
9 *
10 *  Modified for the MPC8260ADS board by Andy Dachs <a.dachs@sstl.co.uk>
11 *  Surrey Satellite Technology Limited, 2001
12 *  A 40MHz system clock is assumed.
13 *  The PON. RST.CONF. Dip switches (DS1) are
14 *  1 - Off
15 *  2 - On
16 *  3 - Off
17 *  4 - On
18 *  5 - Off
19 *  6 - Off
20 *  7 - Off
21 *  8 - Off
22 *  Dip switches on DS2 and DS3 are all set to ON
23 *  The LEDs on the board are used to signal panic and fatal_error
24 *  conditions.
25 *  The mmu is unused at this time.
26 *
27 *
28 *  COPYRIGHT (c) 1989-2007.
29 *  On-Line Applications Research Corporation (OAR).
30 *
31 *  The license and distribution terms for this file may be
32 *  found in the file LICENSE in this distribution or at
33 *  http://www.rtems.com/license/LICENSE.
34 *
35 *  $Id$
36 */
37
38#include <bsp.h>
39
40/*
41#include <mmu.h>
42*/
43
44#include <mpc8260.h>
45#include <rtems/score/thread.h>
46#include <rtems/powerpc/powerpc.h>
47
48#include <rtems/bspIo.h>
49#include <bsp/irq.h>
50#include <libcpu/cpuIdent.h>
51#include <libcpu/spr.h>
52
53#include <string.h>
54
55SPR_RW(SPRG1)
56
57/*
58 *  Driver configuration parameters
59 */
60uint32_t   bsp_clock_speed;
61uint32_t   bsp_time_base_frequency;
62uint32_t   bsp_clicks_per_usec;
63uint32_t   bsp_serial_per_sec;         /* Serial clocks per second */
64bool       bsp_serial_external_clock;
65bool       bsp_serial_xon_xoff;
66bool       bsp_serial_cts_rts;
67uint32_t   bsp_serial_rate;
68uint32_t   bsp_timer_average_overhead; /* Average overhead of timer in ticks */
69uint32_t   bsp_timer_least_valid;      /* Least valid number from timer      */
70bool       bsp_timer_internal_clock;   /* TRUE, when timer runs with CPU clk */
71
72void  _BSP_GPLED1_on(void);
73void  _BSP_GPLED0_on(void);
74void  cpu_init(void);
75
76extern char IntrStack_start [];
77extern char intrStack [];
78
79void BSP_panic(char *s)
80{
81  _BSP_GPLED1_on();
82  printk("%s PANIC %s\n",_RTEMS_version, s);
83  __asm__ __volatile ("sc");
84}
85
86void _BSP_Fatal_error(unsigned int v)
87{
88  _BSP_GPLED0_on();
89  _BSP_GPLED1_on();
90  printk("%s PANIC ERROR %x\n",_RTEMS_version, v);
91  __asm__ __volatile ("sc");
92}
93
94void _BSP_GPLED0_on(void)
95{
96  BCSR *csr;
97  csr = (BCSR *)(m8260.memc[1].br & 0xFFFF8000);
98  csr->bcsr0 &=  ~GP0_LED;              /* Turn on GP0 LED */
99}
100
101void _BSP_GPLED0_off(void)
102{
103  BCSR *csr;
104  csr = (BCSR *)(m8260.memc[1].br & 0xFFFF8000);
105  csr->bcsr0 |=  GP0_LED;               /* Turn off GP0 LED */
106}
107
108void _BSP_GPLED1_on(void)
109{
110  BCSR *csr;
111  csr = (BCSR *)(m8260.memc[1].br & 0xFFFF8000);
112  csr->bcsr0 &=  ~GP1_LED;              /* Turn on GP1 LED */
113}
114
115void _BSP_GPLED1_off(void)
116{
117  BCSR *csr;
118  csr = (BCSR *)(m8260.memc[1].br & 0xFFFF8000);
119  csr->bcsr0 |=  GP1_LED;               /* Turn off GP1 LED */
120}
121
122void _BSP_Uart1_enable(void)
123{
124  BCSR *csr;
125  csr = (BCSR *)(m8260.memc[1].br & 0xFFFF8000);
126  csr->bcsr1 &= ~UART1_E;               /* Enable Uart1 */
127}
128
129void _BSP_Uart1_disable(void)
130{
131  BCSR *csr;
132  csr = (BCSR *)(m8260.memc[1].br & 0xFFFF8000);
133  csr->bcsr1 |=  UART1_E;               /* Disable Uart1 */
134}
135
136void _BSP_Uart2_enable(void)
137{
138  BCSR *csr;
139  csr = (BCSR *)(m8260.memc[1].br & 0xFFFF8000);
140  csr->bcsr1 &= ~UART2_E;               /* Enable Uart2 */
141}
142
143void _BSP_Uart2_disable(void)
144{
145  BCSR *csr;
146  csr = (BCSR *)(m8260.memc[1].br & 0xFFFF8000);
147  csr->bcsr1 |=  UART2_E;               /* Disable Uart2 */
148
149}
150
151void bsp_start(void)
152{
153  rtems_status_code sc = RTEMS_SUCCESSFUL;
154  ppc_cpu_id_t myCpu;
155  ppc_cpu_revision_t myCpuRevision;
156
157  /* Set MPC8260ADS board LEDS and Uart enable lines */
158  _BSP_GPLED0_off();
159  _BSP_GPLED1_off();
160  _BSP_Uart1_enable();
161  _BSP_Uart2_enable();
162
163  /*
164   * Get CPU identification dynamically. Note that the get_ppc_cpu_type() function
165   * store the result in global variables so that it can be used latter...
166   */
167  myCpu         = get_ppc_cpu_type();
168  myCpuRevision = get_ppc_cpu_revision();
169
170  cpu_init();
171
172/*
173  mmu_init();
174*/
175
176  /* Initialize exception handler */
177  /* FIXME: Interrupt stack begin and size */
178  sc = ppc_exc_initialize(
179    PPC_INTERRUPT_DISABLE_MASK_DEFAULT,
180    (uintptr_t) IntrStack_start,
181    (uintptr_t) intrStack - (uintptr_t) IntrStack_start
182  );
183  if (sc != RTEMS_SUCCESSFUL) {
184    BSP_panic("cannot intitialize exceptions");
185  }
186
187  /* Initalize interrupt support */
188  sc = bsp_interrupt_initialize();
189  if (sc != RTEMS_SUCCESSFUL) {
190    BSP_panic("cannot intitialize interrupts");
191  }
192
193
194/*
195  mmu_init();
196*/
197
198  /*
199   * Enable instruction and data caches. Do not force writethrough mode.
200   */
201#if BSP_INSTRUCTION_CACHE_ENABLED
202  rtems_cache_enable_instruction();
203#endif
204#if BSP_DATA_CACHE_ENABLED
205  rtems_cache_enable_data();
206#endif
207
208  /*
209   *  initialize the device driver parameters
210   */
211  bsp_time_base_frequency    = 10000000;
212  bsp_clicks_per_usec        = 10;  /* for 40MHz extclk */
213  bsp_serial_per_sec         = 40000000;
214  bsp_serial_external_clock  = 0;
215  bsp_serial_xon_xoff        = 0;
216  bsp_serial_cts_rts         = 0;
217  bsp_serial_rate            = 9600;
218  bsp_timer_average_overhead = 3;
219  bsp_timer_least_valid    = 3;
220  bsp_clock_speed          = 40000000;
221
222#ifdef REV_0_2
223  /* set up some board specific registers */
224  m8260.siumcr &= 0xF3FFFFFF;           /* set TBEN ** BUG FIX ** */
225  m8260.siumcr |= 0x08000000;
226#endif
227
228  /* use BRG1 to generate 32kHz timebase */
229/*
230  m8260.brgc1 = M8260_BRG_EN + (uint32_t)(((uint16_t)((40016384)/(32768)) - 1) << 1) + 0;
231*/
232
233#ifdef SHOW_MORE_INIT_SETTINGS
234  printk("Exit from bspstart\n");
235#endif
236
237}
Note: See TracBrowser for help on using the repository browser.