Changeset eb94aaf in rtems


Ignore:
Timestamp:
10/17/22 20:44:00 (8 months ago)
Author:
Alex White <alex.white@…>
Branches:
master
Children:
cbac78a
Parents:
63b21ad5
git-author:
Alex White <alex.white@…> (10/17/22 20:44:00)
git-committer:
Joel Sherrill <joel@…> (02/06/23 20:29:24)
Message:

bsps/microblaze: Add device tree support to timer

Location:
bsps/microblaze/microblaze_fpga
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • bsps/microblaze/microblaze_fpga/clock/clock.c

    r63b21ad5 reb94aaf  
    3434 */
    3535
     36#include <bsp.h>
    3637#include <bsp/fatal.h>
    3738#include <bsp/timer.h>
     
    4243
    4344static rtems_timecounter_simple mblaze_tc;
     45static volatile Microblaze_Timer *mblaze_timer;
    4446
    4547static uint32_t microblaze_tc_get( rtems_timecounter_simple *tc )
    4648{
    47   volatile Microblaze_Timer *timer = _Microblaze_Timer;
    48   return timer->tcr0;
     49  return mblaze_timer->tcr0;
    4950}
    5051
    5152static bool microblaze_tc_is_pending( rtems_timecounter_simple *tc )
    5253{
    53   volatile Microblaze_Timer *timer = _Microblaze_Timer;
    54   return ( timer->tcsr0 & MICROBLAZE_TIMER_TCSR0_T0INT ) != 0;
     54  return ( mblaze_timer->tcsr0 & MICROBLAZE_TIMER_TCSR0_T0INT ) != 0;
    5555}
    5656
     
    6666static void microblaze_clock_initialize( void )
    6767{
    68   volatile Microblaze_Timer *timer = _Microblaze_Timer;
     68  mblaze_timer = (volatile Microblaze_Timer *) try_get_prop_from_device_tree(
     69    "xlnx,xps-timer-1.00.a",
     70    "reg",
     71    BSP_MICROBLAZE_FPGA_TIMER_BASE
     72  );
     73
    6974  /* Set load register to 0 */
    70   timer->tlr0 = 0;
     75  mblaze_timer->tlr0 = 0;
    7176  /* Reset the timer and interrupt */
    72   timer->tcsr0 = MICROBLAZE_TIMER_TCSR0_T0INT | MICROBLAZE_TIMER_TCSR0_LOAD0;
     77  mblaze_timer->tcsr0 = MICROBLAZE_TIMER_TCSR0_T0INT | MICROBLAZE_TIMER_TCSR0_LOAD0;
    7378  /* Release the reset */
    74   timer->tcsr0 = 0;
     79  mblaze_timer->tcsr0 = 0;
    7580  /*
    7681   * Enable interrupt, auto reload mode, external interrupt signal,
    7782   * and down counter
    7883   */
    79   timer->tcsr0 =  MICROBLAZE_TIMER_TCSR0_ARHT0 | MICROBLAZE_TIMER_TCSR0_ENIT0 |
     84  mblaze_timer->tcsr0 =  MICROBLAZE_TIMER_TCSR0_ARHT0 | MICROBLAZE_TIMER_TCSR0_ENIT0 |
    8085                  MICROBLAZE_TIMER_TCSR0_GENT0 | MICROBLAZE_TIMER_TCSR0_UDT0;
    8186
    8287  uint64_t us_per_tick = rtems_configuration_get_microseconds_per_tick();
    83   uint32_t counter_frequency_in_hz = BSP_MICROBLAZE_FPGA_TIMER_FREQUENCY;
     88  uint32_t counter_frequency_in_hz = try_get_prop_from_device_tree(
     89    "xlnx,xps-timer-1.00.a",
     90    "clock-frequency",
     91    BSP_MICROBLAZE_FPGA_TIMER_FREQUENCY
     92  );
    8493  uint32_t counter_ticks_per_clock_tick =
    8594    ( counter_frequency_in_hz * us_per_tick ) / 1000000;
    8695
    8796  /* Set a reset value for the timer counter */
    88   timer->tlr0 = counter_ticks_per_clock_tick;
    89   uint32_t control_status_reg = timer->tcsr0;
     97  mblaze_timer->tlr0 = counter_ticks_per_clock_tick;
     98  uint32_t control_status_reg = mblaze_timer->tcsr0;
    9099  /* Load the reset value into the counter register */
    91   timer->tcsr0 = MICROBLAZE_TIMER_TCSR0_LOAD0;
     100  mblaze_timer->tcsr0 = MICROBLAZE_TIMER_TCSR0_LOAD0;
    92101  /* Enable the timer */
    93   timer->tcsr0 = control_status_reg | MICROBLAZE_TIMER_TCSR0_ENT0;
     102  mblaze_timer->tcsr0 = control_status_reg | MICROBLAZE_TIMER_TCSR0_ENT0;
    94103
    95104  rtems_timecounter_simple_install(
     
    103112static void microblaze_clock_at_tick( rtems_timecounter_simple *tc )
    104113{
    105   volatile Microblaze_Timer *timer = _Microblaze_Timer;
    106   if ( ( timer->tcsr0 & MICROBLAZE_TIMER_TCSR0_T0INT ) == 0 ) {
     114  if ( ( mblaze_timer->tcsr0 & MICROBLAZE_TIMER_TCSR0_T0INT ) == 0 ) {
    107115    return;
    108116  }
    109117  /* Clear the interrupt */
    110   timer->tcsr0 |= MICROBLAZE_TIMER_TCSR0_T0INT;
     118  mblaze_timer->tcsr0 |= MICROBLAZE_TIMER_TCSR0_T0INT;
    111119}
    112120
     
    124132  rtems_status_code sc = RTEMS_SUCCESSFUL;
    125133
     134  uint32_t clock_irq_num = try_get_prop_from_device_tree(
     135    "xlnx,xps-timer-1.00.a",
     136    "interrupts",
     137    0
     138  );
     139
    126140  sc = rtems_interrupt_handler_install(
    127     0,
     141    clock_irq_num,
    128142    "Clock",
    129143    RTEMS_INTERRUPT_UNIQUE,
  • bsps/microblaze/microblaze_fpga/include/bsp/timer.h

    r63b21ad5 reb94aaf  
    6161} Microblaze_Timer;
    6262
    63 #define _Microblaze_Timer ((volatile Microblaze_Timer *) BSP_MICROBLAZE_FPGA_TIMER_BASE)
    64 
    6563#ifdef __cplusplus
    6664}
Note: See TracChangeset for help on using the changeset viewer.