source: rtems/c/src/lib/libbsp/powerpc/gen5200/slicetimer/slicetimer.c @ caeaae26

5
Last change on this file since caeaae26 was caeaae26, checked in by Chris Johns <chrisj@…>, on 01/04/18 at 07:50:56

bsp/gen5200: Use public include path

Update #3254.

  • Property mode set to 100644
File size: 11.8 KB
Line 
1/*===============================================================*\
2| Project: RTEMS generic MPC5200 BSP                              |
3+-----------------------------------------------------------------+
4| Partially based on the code references which are named below.   |
5| Adaptions, modifications, enhancements and any recent parts of  |
6| the code are:                                                   |
7|                    Copyright (c) 2005                           |
8|                    Embedded Brains GmbH                         |
9|                    Obere Lagerstr. 30                           |
10|                    D-82178 Puchheim                             |
11|                    Germany                                      |
12|                    rtems@embedded-brains.de                     |
13+-----------------------------------------------------------------+
14| The license and distribution terms for this file may be         |
15| found in the file LICENSE in this distribution or at            |
16|                                                                 |
17| http://www.rtems.org/license/LICENSE.                           |
18|                                                                 |
19+-----------------------------------------------------------------+
20| this file contains functions to implement a slice timer         |
21\*===============================================================*/
22/***********************************************************************/
23/*                                                                     */
24/*   Module:       slicetimer.c                                        */
25/*   Date:         07/17/2003                                          */
26/*   Purpose:      RTEMS MPC5x00 slicetimer driver                     */
27/*                                                                     */
28/*---------------------------------------------------------------------*/
29/*                                                                     */
30/*   Description:  MPC5x00 slice timer routines for cyclic short time  */
31/*                 trigger                                             */
32/*                                                                     */
33/*---------------------------------------------------------------------*/
34/*                                                                     */
35/*   Code                                                              */
36/*   References:   Clock driver for PPC403                             */
37/*   Module:       clock.c                                             */
38/*   Project:      RTEMS 4.6.0pre1 / PPC403 BSP                        */
39/*   Version       1.16                                                */
40/*   Date:         2002/11/01                                          */
41/*   Author(s) / Copyright(s):                                         */
42/*                                                                     */
43/*   Author: Jay Monkman (jmonkman@frasca.com)                         */
44/*   Copyright (C) 1998 by Frasca International, Inc.                  */
45/*                                                                     */
46/*   Derived from c/src/lib/libcpu/ppc/ppc403/clock/clock.c:           */
47/*                                                                     */
48/*   Author: Andrew Bray <andy@i-cubed.co.uk>                          */
49/*                                                                     */
50/*   COPYRIGHT (c) 1995 by i-cubed ltd.                                */
51/*                                                                     */
52/*   To anyone who acknowledges that this file is provided "AS IS"     */
53/*   without any express or implied warranty:                          */
54/*      permission to use, copy, modify, and distribute this file      */
55/*      for any purpose is hereby granted without fee, provided that   */
56/*      the above copyright notice and this notice appears in all      */
57/*      copies, and that the name of i-cubed limited not be used in    */
58/*      advertising or publicity pertaining to distribution of the     */
59/*      software without specific, written prior permission.           */
60/*      i-cubed limited makes no representations about the suitability */
61/*      of this software for any purpose.                              */
62/*                                                                     */
63/*   Derived from c/src/lib/libcpu/hppa1.1/clock/clock.c:              */
64/*                                                                     */
65/*   Modifications for deriving timer clock from cpu system clock by   */
66/*              Thomas Doerfler <td@imd.m.isar.de>                     */
67/*   for these modifications:                                          */
68/*   COPYRIGHT (c) 1997 by IMD, Puchheim, Germany.                     */
69/*                                                                     */
70/*   COPYRIGHT (c) 1989-1999.                                          */
71/*   On-Line Applications Research Corporation (OAR).                  */
72/*                                                                     */
73/*   The license and distribution terms for this file may be           */
74/*   found in the file LICENSE in this distribution or at              */
75/*   http://www.rtems.org/license/LICENSE.                        */
76/*                                                                     */
77/*   Modifications for PPC405GP by Dennis Ehlin                        */
78/*---------------------------------------------------------------------*/
79/*                                                                     */
80/*   Partially based on the code references which are named above.     */
81/*   Adaptions, modifications, enhancements and any recent parts of    */
82/*   the code are under the right of                                   */
83/*                                                                     */
84/*         IPR Engineering, Dachauer Straße 38, D-80335 MÃŒnchen        */
85/*                        Copyright(C) 2003                            */
86/*                                                                     */
87/*---------------------------------------------------------------------*/
88/*                                                                     */
89/*   IPR Engineering makes no representation or warranties with        */
90/*   respect to the performance of this computer program, and          */
91/*   specifically disclaims any responsibility for any damages,        */
92/*   special or consequential, connected with the use of this program. */
93/*                                                                     */
94/*---------------------------------------------------------------------*/
95/*                                                                     */
96/*   Version history:  1.0                                             */
97/*                                                                     */
98/***********************************************************************/
99
100#include <bsp.h>
101#include <rtems/bspIo.h>
102#include <bsp/fatal.h>
103#include <bsp/irq.h>
104
105#include <rtems.h>
106#include <rtems/clockdrv.h>
107#include <rtems/libio.h>
108
109#include <bsp/irq.h>
110#include <bsp/mpc5200.h>
111#include <bsp/slicetimer.h>
112#include <stdio.h>
113
114uint32_t value0 = 0;
115uint32_t value1 = 0;
116
117/*
118 *  ISR Handlers
119 */
120void mpc5200_slt_isr(uint32_t slt_no)
121  {
122  uint32_t status;
123  struct mpc5200_slt *slt = (struct mpc5200_slt *)(&mpc5200.slt[slt_no]);
124
125  status = slt->tsr;
126
127  if(status & SLT_TSR_ST)
128    {
129
130    slt->tsr |= SLT_TSR_ST;
131
132    /*if(slt_no == SLT0)
133        slt0_user_defined_handler */
134
135    /*if(slt_no == SLT1)
136        slt1_user_defined_handler */
137
138    }
139
140  }
141
142
143rtems_isr mpc5200_slt0_isr(rtems_irq_hdl_param unused)
144  {
145
146  mpc5200_slt_isr(SLT0);
147
148  }
149
150
151rtems_isr mpc5200_slt1_isr(rtems_irq_hdl_param unused)
152  {
153
154  mpc5200_slt_isr(SLT1);
155
156  }
157
158
159/*
160 *  Initialize MPC5x00 slt
161 */
162void mpc5200_init_slt(uint32_t slt_no)
163  {
164  struct mpc5200_slt *slt = (struct mpc5200_slt *)(&mpc5200.slt[slt_no]);
165
166  slt->tsr    = SLT_TSR_ST;
167  slt->cntrl  = SLT_CNTRL_RW;
168
169  }
170
171
172/*
173 *  Set MPC5x00 slt counter
174 */
175void mpc5200_set_slt_count(uint32_t slt_no)
176  {
177  struct mpc5200_slt *slt = (struct mpc5200_slt *)(&mpc5200.slt[slt_no]);
178
179  if(slt_no == SLT0)
180    /* Calculate counter value 24 bit (must be greater than 255) => IPB_Clock=33MHz -> Int. every 7,75us - 508ms */
181    if((SLT_TSR_COUNT(SLT0_INT_FREQUENCY) > 0xFF) && (SLT_TSR_COUNT(SLT0_INT_FREQUENCY) < 0x1000000))
182      slt->tcr = SLT_TSR_COUNT(SLT0_INT_FREQUENCY);
183
184  if(slt_no == SLT1)
185    /* Calculate counter value 24 bit (must be greater than 255) => IPB_Clock=33MHz -> Int. every 7,75us - 508ms */
186    if((SLT_TSR_COUNT(SLT1_INT_FREQUENCY) > 0xFF) && (SLT_TSR_COUNT(SLT1_INT_FREQUENCY) < 0x1000000))
187      slt->tcr = SLT_TSR_COUNT(SLT1_INT_FREQUENCY);
188
189  }
190
191
192/*
193 *  Enable MPC5x00 slt interrupt
194 */
195void mpc5200_enable_slt_int(uint32_t slt_no)
196  {
197  struct mpc5200_slt *slt = (struct mpc5200_slt *)(&mpc5200.slt[slt_no]);
198
199  slt->cntrl  |= SLT_CNTRL_TIMEN | SLT_CNTRL_INTEN;
200
201  }
202
203
204/*
205 *  Disable MPC5x00 slt interrupt
206 */
207void mpc5200_disable_slt_int(uint32_t slt_no)
208  {
209  struct mpc5200_slt *slt = (struct mpc5200_slt *)(&mpc5200.slt[slt_no]);
210
211  slt->cntrl &= ~(SLT_CNTRL_TIMEN | SLT_CNTRL_INTEN);
212
213  }
214
215
216/*
217 *  Check MPC5x00 slt status
218 */
219uint32_t mpc5200_check_slt_status(uint32_t slt_no)
220  {
221  struct mpc5200_slt *slt = (struct mpc5200_slt *)(&mpc5200.slt[slt_no]);
222
223  if(((slt->cntrl) & (SLT_CNTRL_TIMEN | SLT_CNTRL_INTEN)) == (SLT_CNTRL_TIMEN | SLT_CNTRL_INTEN))
224    return 1;
225  else
226    return 0;
227
228  }
229
230/*
231 *  switch MPC5x00 slt on
232 */
233static void sltOn(const rtems_irq_connect_data* irq)
234  {
235  uint32_t slt_no = 0;
236
237  if((irq->name) == BSP_SIU_IRQ_SL_TIMER0)
238    slt_no = 0;
239
240  if((irq->name) == BSP_SIU_IRQ_SL_TIMER1)
241    slt_no = 1;
242
243  mpc5200_set_slt_count((uint32_t)slt_no);
244  mpc5200_enable_slt_int((uint32_t)slt_no);
245
246  }
247
248/*
249 *  switch MPC5x00 slt off
250 */
251static void sltOff(const rtems_irq_connect_data* irq)
252  {
253  uint32_t slt_no = 0;
254
255  if((irq->name) == BSP_SIU_IRQ_SL_TIMER0)
256    slt_no = 0;
257
258  if((irq->name) == BSP_SIU_IRQ_SL_TIMER1)
259    slt_no = 1;
260
261  mpc5200_disable_slt_int((uint32_t)slt_no);
262
263  }
264
265/*
266 *  get status of MPC5x00 slt
267 */
268static int sltIsOn(const rtems_irq_connect_data* irq)
269  {
270  uint32_t slt_no = 0;
271
272  if((irq->name) == BSP_SIU_IRQ_SL_TIMER0)
273    slt_no = 0;
274
275  if((irq->name) == BSP_SIU_IRQ_SL_TIMER1)
276    slt_no = 1;
277
278  if(mpc5200_check_slt_status(slt_no))
279    return 1;
280  else
281    return 0;
282  }
283
284/*
285 *  MPC5x00 slt0 irq connect data
286 */
287static rtems_irq_connect_data slt0_IrqData =
288  {
289  BSP_SIU_IRQ_SL_TIMER0,
290  mpc5200_slt0_isr,
291  (rtems_irq_hdl_param) NULL,
292  (rtems_irq_enable)sltOn,
293  (rtems_irq_disable)sltOff,
294  (rtems_irq_is_enabled)sltIsOn
295  };
296
297/*
298 *  MPC5x00 slt1 irq connect data
299 */
300static rtems_irq_connect_data slt1_IrqData =
301  {
302  BSP_SIU_IRQ_SL_TIMER1,
303  mpc5200_slt1_isr,
304  (rtems_irq_hdl_param) NULL,
305  (rtems_irq_enable)sltOn,
306  (rtems_irq_disable)sltOff,
307  (rtems_irq_is_enabled)sltIsOn
308  };
309
310/*
311 *  call MPC5x00 slt install routines
312 */
313void Install_slt(rtems_device_minor_number slt_no)
314  {
315
316  mpc5200_init_slt((uint32_t)slt_no);
317  mpc5200_set_slt_count((uint32_t)slt_no);
318
319  }
320
321/*
322 *  MPC5x00 slt device driver initialize
323 */
324rtems_device_driver slt_initialize
325  (
326  rtems_device_major_number major,
327  rtems_device_minor_number minor,
328  void *pargp
329  )
330  {
331
332  /* force minor according to definitions in bsp.h */
333  if(USE_SLICETIMER_0)
334    {
335
336    Install_slt(0);
337
338    if(!BSP_install_rtems_irq_handler(&slt0_IrqData))
339      {
340
341      printk("Unable to connect PSC Irq handler\n");
342      bsp_fatal(MPC5200_FATAL_SLICETIMER_0_IRQ_INSTALL);
343
344      }
345
346    }
347
348  if(USE_SLICETIMER_1)
349    {
350
351    Install_slt(1);
352
353    if(!BSP_install_rtems_irq_handler(&slt1_IrqData))
354      {
355
356      printk("Unable to connect PSC Irq handler\n");
357      bsp_fatal(MPC5200_FATAL_SLICETIMER_1_IRQ_INSTALL);
358
359      }
360
361    }
362
363  return RTEMS_SUCCESSFUL;
364
365  }
366
Note: See TracBrowser for help on using the repository browser.