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

This commit is contained in:
Joel Sherrill
2012-04-19 13:15:49 -05:00
parent 14010768ed
commit 029ced28e2

View File

@@ -8,38 +8,29 @@
* *
* The license and distribution terms for this file may be * The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at * found in the file LICENSE in this distribution or at
*
* http://www.rtems.com/license/LICENSE. * http://www.rtems.com/license/LICENSE.
* */
*
* $Id$
*/
#include <rtems.h> #include <rtems.h>
#include <bsp.h> #include <bsp.h>
#include <bsp/irq.h> #include <bsp/irq.h>
#include <lpc22xx.h> #include <lpc22xx.h>
#include <rtems/bspIo.h> /* for printk */ #include <rtems/bspIo.h> /* for printk */
/* this is defined in ../../../shared/clockdrv_shell.h */ void Clock_isr(rtems_irq_hdl_param arg);
rtems_isr Clock_isr(rtems_vector_number vector);
static void clock_isr_on(const rtems_irq_connect_data *unused); static void clock_isr_on(const rtems_irq_connect_data *unused);
static void clock_isr_off(const rtems_irq_connect_data *unused); static void clock_isr_off(const rtems_irq_connect_data *unused);
static int clock_isr_is_on(const rtems_irq_connect_data *irq); static int clock_isr_is_on(const rtems_irq_connect_data *irq);
/* Replace the first value with the clock's interrupt name. */ /* Replace the first value with the clock's interrupt name. */
rtems_irq_connect_data clock_isr_data = {LPC22xx_INTERRUPT_TIMER0, rtems_irq_connect_data clock_isr_data = {
(rtems_irq_hdl)Clock_isr, .name = LPC22xx_INTERRUPT_TIMER0,
NULL, .hdl = Clock_isr,
clock_isr_on, .handle = NULL,
clock_isr_off, .on = clock_isr_on,
clock_isr_is_on}; .off = clock_isr_off,
.isOn = clock_isr_is_on,
/* If you follow the code, this is never used, so any value };
* should work
*/
#define CLOCK_VECTOR 0
/* use the /shared/clockdrv_shell.h code template */ /* use the /shared/clockdrv_shell.h code template */
@@ -50,9 +41,10 @@ rtems_irq_connect_data clock_isr_data = {LPC22xx_INTERRUPT_TIMER0,
*/ */
#define Clock_driver_support_at_tick() \ #define Clock_driver_support_at_tick() \
do { \ do { \
if (!(T0IR & 0x01)) return; \ if (!(T0IR & 0x01)) \
return; \
T0IR = 0x01; \ T0IR = 0x01; \
VICVectAddr = 0x00;\ VICVectAddr = 0x00; \
} while(0) } while(0)
/** /**
@@ -64,7 +56,6 @@ rtems_irq_connect_data clock_isr_data = {LPC22xx_INTERRUPT_TIMER0,
BSP_install_rtems_irq_handler(&clock_isr_data); \ BSP_install_rtems_irq_handler(&clock_isr_data); \
} while(0) } while(0)
/** /**
* Initialize the hardware for the clock * Initialize the hardware for the clock
* - Set the frequency * - Set the frequency
@@ -75,22 +66,28 @@ rtems_irq_connect_data clock_isr_data = {LPC22xx_INTERRUPT_TIMER0,
* enable interrupts here. If you do so, the clock_isr_on(), * enable interrupts here. If you do so, the clock_isr_on(),
* clock_isr_off(), and clock_isr_is_on() functions can be * clock_isr_off(), and clock_isr_is_on() functions can be
* NOPs. * NOPs.
*/ *
* set timer to generate interrupt every
/* set timer to generate interrupt every rtems_configuration_get_microseconds_per_tick() * rtems_configuration_get_microseconds_per_tick()
* MR0/(LPC22xx_Fpclk/(PR0+1)) = 10/1000 = 0.01s * MR0/(LPC22xx_Fpclk/(PR0+1)) = 10/1000 = 0.01s
*/ */
#define Clock_driver_support_initialize_hardware() \ #define Clock_driver_support_initialize_hardware() \
do { \ do { \
T0TCR &= 0; /* disable and clear timer 0, set to */ \ /* disable and clear timer 0, set to */ \
T0PC = 0; /* TC is incrementet on every pclk.*/ \ T0TCR &= 0; \
T0MR0 = ((LPC22xx_Fpclk/1000* rtems_configuration_get_microseconds_per_tick()) / 1000); /* initialize the timer period and prescaler */ \ /* TC is incrementet on every pclk.*/ \
/*T0PR = (((LPC22xx_Fpclk / 1000) * rtems_configuration_get_microseconds_per_tick()) / 1000-1); \ */ \ T0PC = 0; \
T0MCR |= 0x03; /* generate interrupt when T0MR0 match T0TC and Reset Timer Count*/ \ /* initialize the timer period and prescaler */ \
T0EMR = 0; /*No external match*/ \ T0MR0 = ((LPC22xx_Fpclk/1000 * \
T0TCR = 1; /*enable timer0*/ \ rtems_configuration_get_microseconds_per_tick()) / 1000); \
T0IR|=0x01;/*enable interrupt, skyeye will check this*/\ /* generate interrupt when T0MR0 match T0TC and Reset Timer Count*/ \
T0MCR |= 0x03; \
/* No external match */ \
T0EMR = 0; \
/* enable timer0 */ \
T0TCR = 1; \
/* enable interrupt, skyeye will check this*/ \
T0IR |= 0x01; \
} while (0) } while (0)
/** /**
@@ -109,15 +106,16 @@ rtems_irq_connect_data clock_isr_data = {LPC22xx_INTERRUPT_TIMER0,
uint32_t bsp_clock_nanoseconds_since_last_tick(void) uint32_t bsp_clock_nanoseconds_since_last_tick(void)
{ {
uint32_t clicks; uint32_t clicks;
uint32_t microseconds;
clicks = T0TC; /*T0TC is the 32bit time counter 0*/ clicks = T0TC; /* T0TC is the 32bit time counter 0 */
return (uint32_t) (rtems_configuration_get_microseconds_per_tick() - clicks) * 1000; microseconds = (rtems_configuration_get_microseconds_per_tick() - clicks);
return microseconds * 1000;
} }
#define Clock_driver_nanoseconds_since_last_tick bsp_clock_nanoseconds_since_last_tick #define Clock_driver_nanoseconds_since_last_tick \
bsp_clock_nanoseconds_since_last_tick
/** /**
* Enables clock interrupt. * Enables clock interrupt.
@@ -127,7 +125,6 @@ uint32_t bsp_clock_nanoseconds_since_last_tick(void)
static void clock_isr_on(const rtems_irq_connect_data *unused) static void clock_isr_on(const rtems_irq_connect_data *unused)
{ {
T0IR&=0x01; T0IR&=0x01;
//return;
} }
/** /**
@@ -138,7 +135,6 @@ static void clock_isr_on(const rtems_irq_connect_data *unused)
static void clock_isr_off(const rtems_irq_connect_data *unused) static void clock_isr_off(const rtems_irq_connect_data *unused)
{ {
T0IR=0x00; T0IR=0x00;
//return;
} }
/** /**
@@ -149,10 +145,9 @@ static void clock_isr_off(const rtems_irq_connect_data *unused)
*/ */
static int clock_isr_is_on(const rtems_irq_connect_data *irq) static int clock_isr_is_on(const rtems_irq_connect_data *irq)
{ {
return T0IR & 0x01; /*MR0 mask*/ return T0IR & 0x01; /* MR0 mask */
} }
/* Make sure to include this, and only at the end of the file */ /* Make sure to include this, and only at the end of the file */
#include "../../../../libbsp/shared/clockdrv_shell.h" #include "../../../../libbsp/shared/clockdrv_shell.h"