Changeset 029ced28 in rtems


Ignore:
Timestamp:
Apr 19, 2012, 6:15:49 PM (8 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.11, master
Children:
bb9cf58d
Parents:
1401076
Message:

lpc22xx shared: Clock driver clean up and ISR Handler Prototype Correction.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • c/src/lib/libcpu/arm/lpc22xx/clock/clockdrv.c

    r1401076 r029ced28  
    11/*
    22 *  LPC22XX/LPC21xx clock specific using the System Timer
    3  * Copyright (c) 2006 by Ray <rayx.cn@gmail.com>
     3 *  Copyright (c) 2006 by Ray <rayx.cn@gmail.com>
    44 *  Set the Time0 to generate click for RTEMS
    55 *
     
    99 *  The license and distribution terms for this file may be
    1010 *  found in the file LICENSE in this distribution or at
    11  *
    1211 *  http://www.rtems.com/license/LICENSE.
    13  *
    14  *
    15  *  $Id$
    16 */
     12 */
     13
    1714#include <rtems.h>
    1815#include <bsp.h>
     
    2118#include <rtems/bspIo.h>  /* for printk */
    2219
    23 /* this is defined in ../../../shared/clockdrv_shell.h */
    24 rtems_isr Clock_isr(rtems_vector_number vector);
     20void Clock_isr(rtems_irq_hdl_param arg);
    2521static void clock_isr_on(const rtems_irq_connect_data *unused);
    2622static void clock_isr_off(const rtems_irq_connect_data *unused);
     
    2824
    2925/* Replace the first value with the clock's interrupt name. */
    30 rtems_irq_connect_data clock_isr_data = {LPC22xx_INTERRUPT_TIMER0,
    31                                          (rtems_irq_hdl)Clock_isr,
    32                                          NULL,
    33                                          clock_isr_on,
    34                                          clock_isr_off,
    35                                          clock_isr_is_on};
    36 
    37 /* If you follow the code, this is never used, so any value
    38  * should work
    39  */
    40 #define CLOCK_VECTOR 0
    41 
    42 
     26rtems_irq_connect_data clock_isr_data = {
     27  .name   = LPC22xx_INTERRUPT_TIMER0,
     28  .hdl    = Clock_isr,
     29  .handle = NULL,
     30  .on     = clock_isr_on,
     31  .off    = clock_isr_off,
     32  .isOn   = clock_isr_is_on,
     33};
    4334
    4435/* use the /shared/clockdrv_shell.h code template */
     
    5041 */
    5142#define Clock_driver_support_at_tick() \
    52  do {                                                   \
    53           if (!(T0IR & 0x01)) return;   \
    54           T0IR = 0x01;                  \
    55           VICVectAddr = 0x00;\
     43 do {                                  \
     44   if (!(T0IR & 0x01))                 \
     45     return;                           \
     46   T0IR = 0x01;                        \
     47   VICVectAddr = 0x00;                 \
    5648 } while(0)
    5749
     
    6153#define Clock_driver_support_install_isr( _new, _old ) \
    6254  do {                                                 \
    63       (_old) = NULL;                                   \
    64       BSP_install_rtems_irq_handler(&clock_isr_data);  \
     55    (_old) = NULL;                                   \
     56    BSP_install_rtems_irq_handler(&clock_isr_data);  \
    6557  } while(0)
    66 
    6758
    6859/**
     
    7667 * clock_isr_off(), and clock_isr_is_on() functions can be
    7768 * NOPs.
     69 *
     70 * set timer to generate interrupt every
     71 * rtems_configuration_get_microseconds_per_tick()
     72 *     MR0/(LPC22xx_Fpclk/(PR0+1)) = 10/1000 = 0.01s
    7873 */
    79 
    80   /* set timer to generate interrupt every rtems_configuration_get_microseconds_per_tick()
    81    * MR0/(LPC22xx_Fpclk/(PR0+1)) = 10/1000 = 0.01s
    82    */
    83 
    8474#define Clock_driver_support_initialize_hardware() \
    8575  do { \
    86         T0TCR &= 0;      /* disable and clear timer 0, set to  */ \
    87         T0PC  = 0;            /* TC is incrementet on every pclk.*/ \
    88         T0MR0 = ((LPC22xx_Fpclk/1000* rtems_configuration_get_microseconds_per_tick()) / 1000); /* initialize the timer period and prescaler */  \
    89         /*T0PR = (((LPC22xx_Fpclk / 1000) * rtems_configuration_get_microseconds_per_tick()) / 1000-1); \ */ \
    90         T0MCR |= 0x03;            /* generate interrupt when T0MR0 match T0TC and Reset Timer Count*/ \
    91         T0EMR = 0;  /*No external match*/ \
    92         T0TCR = 1; /*enable timer0*/ \
    93         T0IR|=0x01;/*enable interrupt, skyeye will check this*/\
    94    } while (0)
     76    /* disable and clear timer 0, set to  */ \
     77    T0TCR &= 0;                              \
     78    /* TC is incrementet on every pclk.*/    \
     79    T0PC   = 0;                              \
     80    /* initialize the timer period and prescaler */  \
     81    T0MR0  = ((LPC22xx_Fpclk/1000 *          \
     82             rtems_configuration_get_microseconds_per_tick()) / 1000); \
     83    /* generate interrupt when T0MR0 match T0TC and Reset Timer Count*/ \
     84    T0MCR |= 0x03;          \
     85    /* No external match */ \
     86    T0EMR = 0;              \
     87    /* enable timer0 */     \
     88    T0TCR = 1;              \
     89    /* enable interrupt, skyeye will check this*/ \
     90    T0IR |= 0x01; \
     91  } while (0)
    9592
    9693/**
     
    10299#define Clock_driver_support_shutdown_hardware()                        \
    103100  do {                                                                  \
    104         /* Disable timer */ \
    105        T0TCR&=~0x02; \
    106         BSP_remove_rtems_irq_handler(&clock_isr_data);                  \
    107      } while (0)
     101    /* Disable timer */ \
     102    T0TCR&=~0x02; \
     103    BSP_remove_rtems_irq_handler(&clock_isr_data);                  \
     104  } while (0)
    108105
    109106uint32_t bsp_clock_nanoseconds_since_last_tick(void)
    110107{
    111         uint32_t clicks;
     108  uint32_t clicks;
     109  uint32_t microseconds;
    112110
    113         clicks = T0TC;  /*T0TC is the 32bit time counter 0*/
     111  clicks = T0TC;  /* T0TC is the 32bit time counter 0 */
    114112
    115         return (uint32_t) (rtems_configuration_get_microseconds_per_tick() - clicks) * 1000;
     113  microseconds = (rtems_configuration_get_microseconds_per_tick() - clicks);
     114  return microseconds * 1000;
    116115}
    117116
    118 #define Clock_driver_nanoseconds_since_last_tick bsp_clock_nanoseconds_since_last_tick
    119 
    120 
     117#define Clock_driver_nanoseconds_since_last_tick \
     118        bsp_clock_nanoseconds_since_last_tick
    121119
    122120/**
     
    127125static void clock_isr_on(const rtems_irq_connect_data *unused)
    128126{
    129         T0IR&=0x01;
    130         //return;
     127  T0IR&=0x01;
    131128}
    132129
     
    138135static void clock_isr_off(const rtems_irq_connect_data *unused)
    139136{
    140         T0IR=0x00;
    141         //return;
     137  T0IR=0x00;
    142138}
    143139
     
    150146static int clock_isr_is_on(const rtems_irq_connect_data *irq)
    151147{
    152     return T0IR & 0x01;  /*MR0 mask*/
     148  return T0IR & 0x01;  /* MR0 mask */
    153149}
    154 
    155150
    156151/* Make sure to include this, and only at the end of the file */
Note: See TracChangeset for help on using the changeset viewer.