source: rtems/c/src/lib/libbsp/arm/tms570/clock/clock.c @ 4407ee6

4.115
Last change on this file since 4407ee6 was 4407ee6, checked in by Premysl Houdek <kom541000@…>, on 08/20/14 at 15:24:23

BSP for TMS570LS31x Hercules Development Kit from TI (TMS570LS3137)

Included variants:

tms570ls3137_hdk_intram - place code and data into internal SRAM
tms570ls3137_hdk_sdram - place code into external SDRAM and data to SRAM
tms570ls3137_hdk - variant prepared for stand-alone RTEMS aplication

stored and running directly from flash. Not working yet.

Chip initialization code not included in BSP.
External startup generated by TI's HalCoGen? was used for
testing and debugging.

More information about TMS570 BSP can be found at

http://www.rtems.org/wiki/index.php/Tms570

Patch version 2

  • most of the formatting suggestion applied.
  • BSP converted to use clock shell
  • console driver "set attributes" tested. Baudrate change working

Patch version 3

  • more formatting changes.
  • removed leftover defines and test functions

Todo:

refactor header files (name register fields)

  • Property mode set to 100644
File size: 4.0 KB
Line 
1/**
2 * @file clock.c
3 *
4 * @ingroup tms570
5 *
6 * @brief clock functions definitions.
7 */
8
9/*
10 * Copyright (c) 2014 Premysl Houdek <kom541000@gmail.com>
11 *
12 * Google Summer of Code 2014 at
13 * Czech Technical University in Prague
14 * Zikova 1903/4
15 * 166 36 Praha 6
16 * Czech Republic
17 *
18 * Based on LPC24xx and LPC1768 BSP
19 * by embedded brains GmbH and others
20 *
21 * The license and distribution terms for this file may be
22 * found in the file LICENSE in this distribution or at
23 * http://www.rtems.org/license/LICENSE.
24 */
25
26#include <stdlib.h>
27
28#include <rtems.h>
29#include <bsp.h>
30#include <bsp/irq.h>
31#include <bsp/tms570-rti.h>
32
33/**
34 *  holds HW counter value since last interrupt event
35 *  sets in tms570_clock_driver_support_at_tick
36 *  used in tms570_clock_driver_nanoseconds_since_last_tick
37 */
38static uint32_t tms570_rti_last_tick_fcr0;
39
40/**
41 *  @brief Initialize the HW peripheral for clock driver
42 *
43 *  Clock driver is implemented by RTI module
44 *
45 * @retval Void
46 */
47static void tms570_clock_driver_support_initialize_hardware( void )
48{
49
50  uint32_t microsec_per_tick = rtems_configuration_get_microseconds_per_tick();
51
52  /* Hardware specific initialize */
53  TMS570_RTI.RTIGCTRL = 0;
54  TMS570_RTI.RTICPUC0 = BSP_PLL_OUT_CLOCK /1000000 / 2; /* prescaler */
55  TMS570_RTI.RTITBCTRL = 2;
56  TMS570_RTI.RTICAPCTRL = 0;
57  TMS570_RTI.RTICOMPCTRL = 0;
58  /* set counter to zero */
59  TMS570_RTI.RTIUC0 = 0;
60  TMS570_RTI.RTIFRC0 = 0;
61  /* clear interrupts*/
62  TMS570_RTI.RTICLEARINTENA = 0x00070f0f;
63  TMS570_RTI.RTIINTFLAG = 0x0007000f;
64  /* set timer */
65  TMS570_RTI.RTICOMP0 = TMS570_RTI.RTIFRC0 + microsec_per_tick;
66  TMS570_RTI.RTICOMP0CLR = TMS570_RTI.RTICOMP0 + microsec_per_tick / 2;
67  TMS570_RTI.RTIUDCP0 = microsec_per_tick;
68  /* enable interupt */
69  TMS570_RTI.RTISETINTENA = 0x1;
70  /* enable timer */
71  TMS570_RTI.RTIGCTRL = 1;
72}
73
74/**
75 * @brief Clears interrupt source
76 *
77 * @retval Void
78 */
79static void tms570_clock_driver_support_at_tick( void )
80{
81  TMS570_RTI.RTIINTFLAG = 0x00000001;
82  tms570_rti_last_tick_fcr0 = TMS570_RTI.RTICOMP0 - TMS570_RTI.RTIUDCP0;
83  /* TMS570_RTI.RTICOMP0 += 1000; */
84}
85
86/**
87 * @brief registers RTI interrupt handler
88 *
89 * @param[in] Clock_isr new ISR handler
90 * @param[in] Old_ticker old ISR handler (unused and type broken)
91 *
92 * @retval Void
93 */
94static void tms570_clock_driver_support_install_isr(
95  rtems_isr_entry Clock_isr
96)
97{
98  rtems_status_code sc = RTEMS_SUCCESSFUL;
99
100  sc = rtems_interrupt_handler_install(
101    TMS570_IRQ_TIMER_0,
102    "Clock",
103    RTEMS_INTERRUPT_UNIQUE,
104    (rtems_interrupt_handler) Clock_isr,
105    NULL
106  );
107  if ( sc != RTEMS_SUCCESSFUL ) {
108    rtems_fatal_error_occurred(0xdeadbeef);
109  }
110}
111
112/**
113 * @brief disables RTI interrupt
114 *
115 * Called when closing clock driver
116 *
117 * @retval Void
118 */
119static void tms570_clock_driver_support_shutdown_hardware( void )
120{
121  /* turn off the timer interrupts */
122  TMS570_RTI.RTICLEARINTENA = 0x20000;
123}
124
125/**
126 * @brief returns the nanoseconds since last tick
127 *
128 * Return the nanoseconds since last tick
129 *
130 * @retval x nanoseconds
131 *
132 */
133static uint32_t tms570_clock_driver_nanoseconds_since_last_tick( void )
134{
135  uint32_t actual_fcr0 = TMS570_RTI.RTIFRC0;
136  uint32_t usec_since_tick;
137
138  usec_since_tick = actual_fcr0 - tms570_rti_last_tick_fcr0;
139
140  return usec_since_tick * 1000;
141}
142
143#define Clock_driver_support_initialize_hardware \
144                        tms570_clock_driver_support_initialize_hardware
145#define Clock_driver_support_at_tick \
146                        tms570_clock_driver_support_at_tick
147#define Clock_driver_support_initialize_hardware \
148                        tms570_clock_driver_support_initialize_hardware
149#define Clock_driver_support_shutdown_hardware \
150                        tms570_clock_driver_support_shutdown_hardware
151#define Clock_driver_nanoseconds_since_last_tick \
152                        tms570_clock_driver_nanoseconds_since_last_tick
153
154#define Clock_driver_support_install_isr(Clock_isr, Old_ticker ) \
155              tms570_clock_driver_support_install_isr( Clock_isr )
156
157void Clock_isr(void *arg); /* to supress warning */
158
159#include "../../../shared/clockdrv_shell.h"
Note: See TracBrowser for help on using the repository browser.