[rtems commit] bsp/lpc176x: Move source files to bsps

Sebastian Huber sebh at rtems.org
Wed Apr 25 12:35:10 UTC 2018


Module:    rtems
Branch:    master
Commit:    e945b049dc650ee2270740585a2c6d14bd925279
Changeset: http://git.rtems.org/rtems/commit/?id=e945b049dc650ee2270740585a2c6d14bd925279

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Wed Apr 25 10:43:38 2018 +0200

bsp/lpc176x: Move source files to bsps

This patch is a part of the BSP source reorganization.

Update #3285.

---

 bsps/arm/lpc176x/btimer/btimer.c                   | 388 +-------------------
 {c/src/lib/libbsp => bsps}/arm/lpc176x/can/can.c   |   0
 .../libbsp => bsps}/arm/lpc176x/gpio/lpc-gpio.c    |   0
 .../pwmout => bsps/arm/lpc176x/pwm}/pwmout.c       |   0
 .../lpc176x/adc => bsps/arm/lpc176x/start}/adc.c   |   0
 .../misc => bsps/arm/lpc176x/start}/bspidle.c      |   0
 .../misc => bsps/arm/lpc176x/start}/dma-copy.c     |   0
 .../lpc176x/misc => bsps/arm/lpc176x/start}/dma.c  |   0
 .../lpc176x/misc => bsps/arm/lpc176x/start}/io.c   |   0
 .../misc => bsps/arm/lpc176x/start}/restart.c      |   0
 .../arm/lpc176x/start}/system-clocks.c             |   0
 .../watchdog => bsps/arm/lpc176x/start}/watchdog.c |   0
 bsps/arm/lpc176x/timer/timer.c                     | 407 +++++++++++++++++++++
 c/src/lib/libbsp/arm/lpc176x/Makefile.am           |  26 +-
 .../arm/lpc176x/benchmark_timer/benchmark_timer.c  |  45 ---
 15 files changed, 433 insertions(+), 433 deletions(-)

diff --git a/bsps/arm/lpc176x/btimer/btimer.c b/bsps/arm/lpc176x/btimer/btimer.c
index 36c720b..359d890 100644
--- a/bsps/arm/lpc176x/btimer/btimer.c
+++ b/bsps/arm/lpc176x/btimer/btimer.c
@@ -1,9 +1,9 @@
 /**
- * @file timer.c
+ * @file timerbenchmark.c
  *
  * @ingroup lpc176x
  *
- * @brief Timer controller for the mbed lpc1768 board.
+ * @brief Timer benchmark functions for the lpc176x bsp.
  */
 
 /*
@@ -19,389 +19,27 @@
  * http://www.rtems.org/license/LICENSE.
  */
 
-#include <stdio.h>
-#include <rtems/status-checks.h>
+#include <rtems.h>
 #include <bsp.h>
-#include <bsp/irq.h>
-#include <bsp/io.h>
-#include <bsp/timer.h>
-
-/**
- * @brief Represents all the timers.
- */
-const lpc176x_timer timers[ LPC176X_TIMER_COUNT ] =
-{
-  {
-    .device = (lpc176x_timer_device *) LPC176X_TMR0_BASE_ADDR,
-    .module = LPC176X_MODULE_TIMER_0,
-    .pinselcap = LPC176X_TIMER0_CAPTURE_PORTS,
-    .pinselemat = LPC176X_TIMER0_EMATCH_PORTS,
-  },
-  {
-    .device = (lpc176x_timer_device *) LPC176X_TMR1_BASE_ADDR,
-    .module = LPC176X_MODULE_TIMER_1,
-    .pinselcap = LPC176X_TIMER1_CAPTURE_PORTS,
-    .pinselemat = LPC176X_TIMER1_EMATCH_PORTS,
-  },
-  {
-    .device = (lpc176x_timer_device *) LPC176X_TMR2_BASE_ADDR,
-    .module = LPC176X_MODULE_TIMER_2,
-    .pinselcap = LPC176X_TIMER2_CAPTURE_PORTS,
-    .pinselemat = LPC176X_TIMER2_EMATCH_PORTS,
-  },
-  {
-    .device = (lpc176x_timer_device *) LPC176X_TMR3_BASE_ADDR,
-    .module = LPC176X_MODULE_TIMER_3,
-    .pinselcap = LPC176X_TIMER3_CAPTURE_PORTS,
-    .pinselemat = LPC176X_TIMER3_EMATCH_PORTS,
-  }
-};
-
-/**
- * @brief Represents all the functions according to the timers.
- */
-lpc176x_timer_functions functions_vector[ LPC176X_TIMER_COUNT ] =
-{
-  {
-    .funct_vector = NULL
-  },
-  {
-    .funct_vector = NULL
-  },
-  {
-    .funct_vector = NULL
-  },
-  {
-    .funct_vector = NULL
-  }
-};
-
-/**
- * @brief Calls the corresponding interrupt function and pass the timer
- *        as parameter.
- *
- * @param  timer The specific device.
- * @param  interruptnumber Interrupt number.
- */
-static inline void lpc176x_call_desired_isr(
-  const lpc176x_timer_number number,
-  const lpc176x_isr_function interruptfunction
-)
-{
-  if ( ( *functions_vector[ number ].funct_vector )[ interruptfunction ] !=
-       NULL ) {
-    ( *functions_vector[ number ].funct_vector )[ interruptfunction ]( number );
-  }
-
-  /* else implies that the function vector points NULL. Also,
-     there is nothing to do. */
-}
-
-/**
- * @brief Gets true if the selected interrupt is pending
- *
- * @param number: the number of the timer.
- * @param interrupt: the interrupt we are checking for.
- * @return TRUE if the interrupt is pending.
- */
-static inline bool lpc176x_timer_interrupt_is_pending(
-  const lpc176x_timer_number tnumber,
-  const lpc176x_isr_function function
-)
-{
-  assert( ( tnumber < LPC176X_TIMER_COUNT )
-    && ( function < LPC176X_ISR_FUNCTIONS_COUNT ) );
-
-  return ( timers[ tnumber ].device->IR &
-           LPC176X_TIMER_INTERRUPT_SOURCE_BIT( function ) );
-}
-
-/**
- * @brief Resets interrupt status for the selected interrupt
- *
- * @param tnumber: the number of the timer
- * @param interrupt: the interrupt we are resetting
- */
-static inline void lpc176x_timer_reset_interrupt(
-  const lpc176x_timer_number tnumber,
-  const lpc176x_isr_function function
-)
-{
-  assert( ( tnumber < LPC176X_TIMER_COUNT )
-    && ( function < LPC176X_ISR_FUNCTIONS_COUNT ) );
-  timers[ tnumber ].device->IR =
-    LPC176X_TIMER_INTERRUPT_SOURCE_BIT( function );
-}
-
-inline rtems_status_code lpc176x_timer_reset(
-  const lpc176x_timer_number tnumber )
-{
-  rtems_status_code status_code = RTEMS_INVALID_NUMBER;
-
-  if ( tnumber < LPC176X_TIMER_COUNT ) {
-    timers[ tnumber ].device->TCR = LPC176X_TIMER_RESET;
-    status_code = RTEMS_SUCCESSFUL;
-  }
-
-  /* else implies that the timer number is invalid. Also,
-     an invalid number is returned. */
-
-  return status_code;
-}
-
-inline rtems_status_code lpc176x_timer_set_mode(
-  const lpc176x_timer_number tnumber,
-  const lpc176x_timer_mode   mode
-)
-{
-  rtems_status_code status_code = RTEMS_INVALID_NUMBER;
-
-  if ( tnumber < LPC176X_TIMER_COUNT ) {
-    timers[ tnumber ].device->CTCR = mode;
-    status_code = RTEMS_SUCCESSFUL;
-  }
-
-  /* else implies that the timer number is invalid. Also,
-     an invalid number is returned. */
-
-  return status_code;
-}
-
-inline rtems_status_code lpc176x_timer_start(
-  const lpc176x_timer_number tnumber )
-{
-  rtems_status_code status_code = RTEMS_INVALID_NUMBER;
-
-  if ( tnumber < LPC176X_TIMER_COUNT ) {
-    timers[ tnumber ].device->TCR = LPC176X_TIMER_START;
-    status_code = RTEMS_SUCCESSFUL;
-  }
-
-  /* else implies that the timer number is invalid. Also,
-     an invalid number is returned. */
-
-  return status_code;
-}
-
-inline rtems_status_code lpc176x_timer_is_started(
-  const lpc176x_timer_number tnumber,
-  bool                      *is_started
-)
-{
-  rtems_status_code status_code = RTEMS_INVALID_NUMBER;
-
-  if ( tnumber < LPC176X_TIMER_COUNT ) {
-    *is_started = ( timers[ tnumber ].device->TCR & LPC176X_TIMER_START ) ==
-                  LPC176X_TIMER_START;
-    status_code = RTEMS_SUCCESSFUL;
-  }
-
-  /* else implies that the timer number is invalid. Also,
-     an invalid number is returned. */
+#include <rtems/btimer.h>
 
-  return status_code;
-}
-
-inline rtems_status_code lpc176x_timer_set_resolution(
-  const lpc176x_timer_number tnumber,
-  const lpc176x_microseconds resolution
-)
-{
-  rtems_status_code status_code = RTEMS_INVALID_NUMBER;
-
-  if ( tnumber < LPC176X_TIMER_COUNT ) {
-    timers[ tnumber ].device->PR = ( LPC176X_CCLK /
-                                     LPC176X_TIMER_PRESCALER_DIVISOR ) *
-                                   resolution;
-    status_code = RTEMS_SUCCESSFUL;
-  }
-
-  /* else implies that the timer number is invalid. Also,
-     an invalid number is returned. */
-
-  return status_code;
-}
-
-rtems_status_code lpc176x_timer_match_config(
-  const lpc176x_timer_number   tnumber,
-  const lpc176x_match_port     match_port,
-  const lpc176x_match_function function,
-  const uint32_t               match_value
-)
-{
-  rtems_status_code status_code = RTEMS_INVALID_NUMBER;
-
-  if ( ( tnumber < LPC176X_TIMER_COUNT )
-       && ( match_port < LPC176X_EMATCH_PORTS_COUNT )
-       && ( function < LPC176X_TIMER_MATCH_FUNCTION_COUNT ) ) {
-    timers[ tnumber ].device->MCR =
-      LPC176X_SET_MCR( timers[ tnumber ].device->MCR,
-        match_port, function );
-    timers[ tnumber ].device->MR[ match_port ] = match_value;
-    status_code = RTEMS_SUCCESSFUL;
-  }
-
-  /* else implies that the timer number, or a match port or a function
-      is invalid. Also, an invalid number is returned. */
-
-  return status_code;
-}
-
-inline rtems_status_code lpc176x_timer_capture_config(
-  const lpc176x_timer_number     tnumber,
-  const lpc176x_capture_port     capture_port,
-  const lpc176x_capture_function function
-)
-{
-  rtems_status_code status_code = RTEMS_INVALID_NUMBER;
-
-  if ( ( tnumber < LPC176X_TIMER_COUNT )
-       && ( capture_port < LPC176X_CAPTURE_PORTS_COUNT )
-       && ( function < LPC176X_TIMER_CAPTURE_FUNCTION_COUNT ) ) {
-    timers[ tnumber ].device->CCR =
-      LPC176X_SET_CCR( timers[ tnumber ].device->CCR,
-        capture_port, function );
-    lpc176x_pin_select( timers[ tnumber ].pinselcap[ capture_port ],
-      LPC176X_PIN_FUNCTION_11 );
-  }
-
-  /* else implies that the timer number or the capture port is invalid. Also,
-     an invalid number is returned. */
-
-  return status_code;
-}
-
-inline rtems_status_code lpc176x_timer_external_match_config(
-  const lpc176x_timer_number       number,
-  const lpc176x_match_port         match_port,
-  const lpc176x_ext_match_function function
-)
-{
-  rtems_status_code status_code = RTEMS_INVALID_NUMBER;
-
-  if ( ( number < LPC176X_TIMER_COUNT )
-       && ( match_port < LPC176X_EMATCH_PORTS_COUNT ) ) {
-    timers[ number ].device->EMR =
-      LPC176X_SET_EMR( timers[ number ].device->EMR,
-        match_port, function );
-    lpc176x_pin_select( timers[ number ].pinselemat[ match_port ],
-      LPC176X_PIN_FUNCTION_11 );
-    status_code = RTEMS_SUCCESSFUL;
-  }
-
-  /* else implies that the timer number or the match port is invalid. Also,
-     an invalid number is returned. */
-
-  return status_code;
-}
-
-inline uint32_t lpc176x_timer_get_capvalue(
-  const lpc176x_timer_number number,
-  const lpc176x_capture_port capture_port
-)
-{
-  assert( ( number < LPC176X_TIMER_COUNT )
-    && ( capture_port < LPC176X_CAPTURE_PORTS_COUNT ) );
+#include <bsp/timer.h>
 
-  return timers[ number ].device->CR[ capture_port ];
-}
+static uint32_t benchmark_timer_base;
 
-inline uint32_t lpc176x_timer_get_timer_value(
-  const lpc176x_timer_number tnumber )
+void benchmark_timer_initialize( void )
 {
-  assert( tnumber < LPC176X_TIMER_COUNT );
-
-  return timers[ tnumber ].device->TC;
+  benchmark_timer_base = lpc176x_timer_get_timer_value( LPC176X_TIMER_1 );
 }
 
-inline rtems_status_code lpc176x_timer_set_timer_value(
-  const lpc176x_timer_number tnumber,
-  const uint32_t             timer_value
-)
+benchmark_timer_t benchmark_timer_read( void )
 {
-  rtems_status_code status_code = RTEMS_INVALID_NUMBER;
+  uint32_t delta = lpc176x_timer_get_timer_value( LPC176X_TIMER_1 ) -
+                   benchmark_timer_base;
 
-  if ( tnumber < LPC176X_TIMER_COUNT ) {
-    timers[ tnumber ].device->TC = timer_value;
-    status_code = RTEMS_SUCCESSFUL;
-  }
-
-  /* else implies that the timer number is invalid. Also,
-     an invalid number is returned. */
-
-  return status_code;
+  return delta;
 }
 
-void lpc176x_timer_isr( void *arg )
+void benchmark_timer_disable_subtracting_average_overhead( bool find_avg_ovhead )
 {
-  const lpc176x_timer_number tnumber = (lpc176x_timer_number) arg;
-
-  if ( tnumber < LPC176X_TIMER_COUNT ) {
-    lpc176x_isr_function i;
-
-    for ( i = 0; i < LPC176X_ISR_FUNCTIONS_COUNT; ++i ) {
-      if ( lpc176x_timer_interrupt_is_pending( tnumber, i ) ) {
-        lpc176x_call_desired_isr( tnumber, i );
-        lpc176x_timer_reset_interrupt( tnumber, i );
-      }
-
-      /* else implies that the current timer is not pending. Also,
-         there is nothing to do. */
-    }
-  }
-
-  /* else implies that the timer number is not valid. Also,
-     there is nothing to do. */
 }
-
-rtems_status_code lpc176x_timer_init( const lpc176x_timer_number tnumber )
-{
-  rtems_status_code status_code = RTEMS_INVALID_NUMBER;
-
-  if ( tnumber < LPC176X_TIMER_COUNT ) {
-    status_code = lpc176x_module_enable( timers[ tnumber ].module,
-      LPC176X_MODULE_PCLK_DEFAULT );
-    RTEMS_CHECK_SC( status_code, "Enabling the timer module." );
-
-    status_code = lpc176x_timer_reset( tnumber );
-    status_code = lpc176x_timer_set_mode( tnumber,
-      LPC176X_TIMER_MODE_TIMER );
-    status_code = lpc176x_timer_set_resolution( tnumber,
-      LPC176X_TIMER_DEFAULT_RESOLUTION );
-
-    timers[ tnumber ].device->MCR = LPC176X_TIMER_CLEAR_FUNCTION;
-    timers[ tnumber ].device->CCR = LPC176X_TIMER_CLEAR_FUNCTION;
-    timers[ tnumber ].device->EMR = LPC176X_TIMER_CLEAR_FUNCTION;
-  }
-
-  /* else implies that the timer number is not valid. Also,
-     an invalid number is returned. */
-
-  return status_code;
-}
-
-rtems_status_code lpc176x_timer_init_with_interrupt(
-  const lpc176x_timer_number            tnumber,
-  const lpc176x_isr_funct_vector *const vector
-)
-{
-  rtems_status_code status_code = RTEMS_INVALID_NUMBER;
-
-  char isrname[ LPC176X_ISR_NAME_STRING_SIZE ];
-
-  snprintf( isrname, LPC176X_ISR_NAME_STRING_SIZE, "TimerIsr%d", tnumber );
-
-  if ( tnumber < LPC176X_TIMER_COUNT && vector != NULL ) {
-    functions_vector[ tnumber ].funct_vector = vector;
-
-    status_code = lpc176x_timer_init( tnumber );
-    status_code = rtems_interrupt_handler_install(
-      LPC176X_TIMER_VECTOR_NUMBER( tnumber ),
-      isrname,
-      RTEMS_INTERRUPT_UNIQUE,
-      lpc176x_timer_isr,
-      (void *) tnumber );
-  }
-
-  return status_code;
-}
\ No newline at end of file
diff --git a/c/src/lib/libbsp/arm/lpc176x/can/can.c b/bsps/arm/lpc176x/can/can.c
similarity index 100%
rename from c/src/lib/libbsp/arm/lpc176x/can/can.c
rename to bsps/arm/lpc176x/can/can.c
diff --git a/c/src/lib/libbsp/arm/lpc176x/gpio/lpc-gpio.c b/bsps/arm/lpc176x/gpio/lpc-gpio.c
similarity index 100%
rename from c/src/lib/libbsp/arm/lpc176x/gpio/lpc-gpio.c
rename to bsps/arm/lpc176x/gpio/lpc-gpio.c
diff --git a/c/src/lib/libbsp/arm/lpc176x/pwmout/pwmout.c b/bsps/arm/lpc176x/pwm/pwmout.c
similarity index 100%
rename from c/src/lib/libbsp/arm/lpc176x/pwmout/pwmout.c
rename to bsps/arm/lpc176x/pwm/pwmout.c
diff --git a/c/src/lib/libbsp/arm/lpc176x/adc/adc.c b/bsps/arm/lpc176x/start/adc.c
similarity index 100%
rename from c/src/lib/libbsp/arm/lpc176x/adc/adc.c
rename to bsps/arm/lpc176x/start/adc.c
diff --git a/c/src/lib/libbsp/arm/lpc176x/misc/bspidle.c b/bsps/arm/lpc176x/start/bspidle.c
similarity index 100%
rename from c/src/lib/libbsp/arm/lpc176x/misc/bspidle.c
rename to bsps/arm/lpc176x/start/bspidle.c
diff --git a/c/src/lib/libbsp/arm/lpc176x/misc/dma-copy.c b/bsps/arm/lpc176x/start/dma-copy.c
similarity index 100%
rename from c/src/lib/libbsp/arm/lpc176x/misc/dma-copy.c
rename to bsps/arm/lpc176x/start/dma-copy.c
diff --git a/c/src/lib/libbsp/arm/lpc176x/misc/dma.c b/bsps/arm/lpc176x/start/dma.c
similarity index 100%
rename from c/src/lib/libbsp/arm/lpc176x/misc/dma.c
rename to bsps/arm/lpc176x/start/dma.c
diff --git a/c/src/lib/libbsp/arm/lpc176x/misc/io.c b/bsps/arm/lpc176x/start/io.c
similarity index 100%
rename from c/src/lib/libbsp/arm/lpc176x/misc/io.c
rename to bsps/arm/lpc176x/start/io.c
diff --git a/c/src/lib/libbsp/arm/lpc176x/misc/restart.c b/bsps/arm/lpc176x/start/restart.c
similarity index 100%
rename from c/src/lib/libbsp/arm/lpc176x/misc/restart.c
rename to bsps/arm/lpc176x/start/restart.c
diff --git a/c/src/lib/libbsp/arm/lpc176x/misc/system-clocks.c b/bsps/arm/lpc176x/start/system-clocks.c
similarity index 100%
rename from c/src/lib/libbsp/arm/lpc176x/misc/system-clocks.c
rename to bsps/arm/lpc176x/start/system-clocks.c
diff --git a/c/src/lib/libbsp/arm/lpc176x/watchdog/watchdog.c b/bsps/arm/lpc176x/start/watchdog.c
similarity index 100%
rename from c/src/lib/libbsp/arm/lpc176x/watchdog/watchdog.c
rename to bsps/arm/lpc176x/start/watchdog.c
diff --git a/bsps/arm/lpc176x/timer/timer.c b/bsps/arm/lpc176x/timer/timer.c
new file mode 100644
index 0000000..36c720b
--- /dev/null
+++ b/bsps/arm/lpc176x/timer/timer.c
@@ -0,0 +1,407 @@
+/**
+ * @file timer.c
+ *
+ * @ingroup lpc176x
+ *
+ * @brief Timer controller for the mbed lpc1768 board.
+ */
+
+/*
+ * Copyright (c) 2014 Taller Technologies.
+ *
+ * @author  Boretto Martin    (martin.boretto at tallertechnologies.com)
+ * @author  Diaz Marcos (marcos.diaz at tallertechnologies.com)
+ * @author  Lenarduzzi Federico  (federico.lenarduzzi at tallertechnologies.com)
+ * @author  Daniel Chicco  (daniel.chicco at tallertechnologies.com)
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE.
+ */
+
+#include <stdio.h>
+#include <rtems/status-checks.h>
+#include <bsp.h>
+#include <bsp/irq.h>
+#include <bsp/io.h>
+#include <bsp/timer.h>
+
+/**
+ * @brief Represents all the timers.
+ */
+const lpc176x_timer timers[ LPC176X_TIMER_COUNT ] =
+{
+  {
+    .device = (lpc176x_timer_device *) LPC176X_TMR0_BASE_ADDR,
+    .module = LPC176X_MODULE_TIMER_0,
+    .pinselcap = LPC176X_TIMER0_CAPTURE_PORTS,
+    .pinselemat = LPC176X_TIMER0_EMATCH_PORTS,
+  },
+  {
+    .device = (lpc176x_timer_device *) LPC176X_TMR1_BASE_ADDR,
+    .module = LPC176X_MODULE_TIMER_1,
+    .pinselcap = LPC176X_TIMER1_CAPTURE_PORTS,
+    .pinselemat = LPC176X_TIMER1_EMATCH_PORTS,
+  },
+  {
+    .device = (lpc176x_timer_device *) LPC176X_TMR2_BASE_ADDR,
+    .module = LPC176X_MODULE_TIMER_2,
+    .pinselcap = LPC176X_TIMER2_CAPTURE_PORTS,
+    .pinselemat = LPC176X_TIMER2_EMATCH_PORTS,
+  },
+  {
+    .device = (lpc176x_timer_device *) LPC176X_TMR3_BASE_ADDR,
+    .module = LPC176X_MODULE_TIMER_3,
+    .pinselcap = LPC176X_TIMER3_CAPTURE_PORTS,
+    .pinselemat = LPC176X_TIMER3_EMATCH_PORTS,
+  }
+};
+
+/**
+ * @brief Represents all the functions according to the timers.
+ */
+lpc176x_timer_functions functions_vector[ LPC176X_TIMER_COUNT ] =
+{
+  {
+    .funct_vector = NULL
+  },
+  {
+    .funct_vector = NULL
+  },
+  {
+    .funct_vector = NULL
+  },
+  {
+    .funct_vector = NULL
+  }
+};
+
+/**
+ * @brief Calls the corresponding interrupt function and pass the timer
+ *        as parameter.
+ *
+ * @param  timer The specific device.
+ * @param  interruptnumber Interrupt number.
+ */
+static inline void lpc176x_call_desired_isr(
+  const lpc176x_timer_number number,
+  const lpc176x_isr_function interruptfunction
+)
+{
+  if ( ( *functions_vector[ number ].funct_vector )[ interruptfunction ] !=
+       NULL ) {
+    ( *functions_vector[ number ].funct_vector )[ interruptfunction ]( number );
+  }
+
+  /* else implies that the function vector points NULL. Also,
+     there is nothing to do. */
+}
+
+/**
+ * @brief Gets true if the selected interrupt is pending
+ *
+ * @param number: the number of the timer.
+ * @param interrupt: the interrupt we are checking for.
+ * @return TRUE if the interrupt is pending.
+ */
+static inline bool lpc176x_timer_interrupt_is_pending(
+  const lpc176x_timer_number tnumber,
+  const lpc176x_isr_function function
+)
+{
+  assert( ( tnumber < LPC176X_TIMER_COUNT )
+    && ( function < LPC176X_ISR_FUNCTIONS_COUNT ) );
+
+  return ( timers[ tnumber ].device->IR &
+           LPC176X_TIMER_INTERRUPT_SOURCE_BIT( function ) );
+}
+
+/**
+ * @brief Resets interrupt status for the selected interrupt
+ *
+ * @param tnumber: the number of the timer
+ * @param interrupt: the interrupt we are resetting
+ */
+static inline void lpc176x_timer_reset_interrupt(
+  const lpc176x_timer_number tnumber,
+  const lpc176x_isr_function function
+)
+{
+  assert( ( tnumber < LPC176X_TIMER_COUNT )
+    && ( function < LPC176X_ISR_FUNCTIONS_COUNT ) );
+  timers[ tnumber ].device->IR =
+    LPC176X_TIMER_INTERRUPT_SOURCE_BIT( function );
+}
+
+inline rtems_status_code lpc176x_timer_reset(
+  const lpc176x_timer_number tnumber )
+{
+  rtems_status_code status_code = RTEMS_INVALID_NUMBER;
+
+  if ( tnumber < LPC176X_TIMER_COUNT ) {
+    timers[ tnumber ].device->TCR = LPC176X_TIMER_RESET;
+    status_code = RTEMS_SUCCESSFUL;
+  }
+
+  /* else implies that the timer number is invalid. Also,
+     an invalid number is returned. */
+
+  return status_code;
+}
+
+inline rtems_status_code lpc176x_timer_set_mode(
+  const lpc176x_timer_number tnumber,
+  const lpc176x_timer_mode   mode
+)
+{
+  rtems_status_code status_code = RTEMS_INVALID_NUMBER;
+
+  if ( tnumber < LPC176X_TIMER_COUNT ) {
+    timers[ tnumber ].device->CTCR = mode;
+    status_code = RTEMS_SUCCESSFUL;
+  }
+
+  /* else implies that the timer number is invalid. Also,
+     an invalid number is returned. */
+
+  return status_code;
+}
+
+inline rtems_status_code lpc176x_timer_start(
+  const lpc176x_timer_number tnumber )
+{
+  rtems_status_code status_code = RTEMS_INVALID_NUMBER;
+
+  if ( tnumber < LPC176X_TIMER_COUNT ) {
+    timers[ tnumber ].device->TCR = LPC176X_TIMER_START;
+    status_code = RTEMS_SUCCESSFUL;
+  }
+
+  /* else implies that the timer number is invalid. Also,
+     an invalid number is returned. */
+
+  return status_code;
+}
+
+inline rtems_status_code lpc176x_timer_is_started(
+  const lpc176x_timer_number tnumber,
+  bool                      *is_started
+)
+{
+  rtems_status_code status_code = RTEMS_INVALID_NUMBER;
+
+  if ( tnumber < LPC176X_TIMER_COUNT ) {
+    *is_started = ( timers[ tnumber ].device->TCR & LPC176X_TIMER_START ) ==
+                  LPC176X_TIMER_START;
+    status_code = RTEMS_SUCCESSFUL;
+  }
+
+  /* else implies that the timer number is invalid. Also,
+     an invalid number is returned. */
+
+  return status_code;
+}
+
+inline rtems_status_code lpc176x_timer_set_resolution(
+  const lpc176x_timer_number tnumber,
+  const lpc176x_microseconds resolution
+)
+{
+  rtems_status_code status_code = RTEMS_INVALID_NUMBER;
+
+  if ( tnumber < LPC176X_TIMER_COUNT ) {
+    timers[ tnumber ].device->PR = ( LPC176X_CCLK /
+                                     LPC176X_TIMER_PRESCALER_DIVISOR ) *
+                                   resolution;
+    status_code = RTEMS_SUCCESSFUL;
+  }
+
+  /* else implies that the timer number is invalid. Also,
+     an invalid number is returned. */
+
+  return status_code;
+}
+
+rtems_status_code lpc176x_timer_match_config(
+  const lpc176x_timer_number   tnumber,
+  const lpc176x_match_port     match_port,
+  const lpc176x_match_function function,
+  const uint32_t               match_value
+)
+{
+  rtems_status_code status_code = RTEMS_INVALID_NUMBER;
+
+  if ( ( tnumber < LPC176X_TIMER_COUNT )
+       && ( match_port < LPC176X_EMATCH_PORTS_COUNT )
+       && ( function < LPC176X_TIMER_MATCH_FUNCTION_COUNT ) ) {
+    timers[ tnumber ].device->MCR =
+      LPC176X_SET_MCR( timers[ tnumber ].device->MCR,
+        match_port, function );
+    timers[ tnumber ].device->MR[ match_port ] = match_value;
+    status_code = RTEMS_SUCCESSFUL;
+  }
+
+  /* else implies that the timer number, or a match port or a function
+      is invalid. Also, an invalid number is returned. */
+
+  return status_code;
+}
+
+inline rtems_status_code lpc176x_timer_capture_config(
+  const lpc176x_timer_number     tnumber,
+  const lpc176x_capture_port     capture_port,
+  const lpc176x_capture_function function
+)
+{
+  rtems_status_code status_code = RTEMS_INVALID_NUMBER;
+
+  if ( ( tnumber < LPC176X_TIMER_COUNT )
+       && ( capture_port < LPC176X_CAPTURE_PORTS_COUNT )
+       && ( function < LPC176X_TIMER_CAPTURE_FUNCTION_COUNT ) ) {
+    timers[ tnumber ].device->CCR =
+      LPC176X_SET_CCR( timers[ tnumber ].device->CCR,
+        capture_port, function );
+    lpc176x_pin_select( timers[ tnumber ].pinselcap[ capture_port ],
+      LPC176X_PIN_FUNCTION_11 );
+  }
+
+  /* else implies that the timer number or the capture port is invalid. Also,
+     an invalid number is returned. */
+
+  return status_code;
+}
+
+inline rtems_status_code lpc176x_timer_external_match_config(
+  const lpc176x_timer_number       number,
+  const lpc176x_match_port         match_port,
+  const lpc176x_ext_match_function function
+)
+{
+  rtems_status_code status_code = RTEMS_INVALID_NUMBER;
+
+  if ( ( number < LPC176X_TIMER_COUNT )
+       && ( match_port < LPC176X_EMATCH_PORTS_COUNT ) ) {
+    timers[ number ].device->EMR =
+      LPC176X_SET_EMR( timers[ number ].device->EMR,
+        match_port, function );
+    lpc176x_pin_select( timers[ number ].pinselemat[ match_port ],
+      LPC176X_PIN_FUNCTION_11 );
+    status_code = RTEMS_SUCCESSFUL;
+  }
+
+  /* else implies that the timer number or the match port is invalid. Also,
+     an invalid number is returned. */
+
+  return status_code;
+}
+
+inline uint32_t lpc176x_timer_get_capvalue(
+  const lpc176x_timer_number number,
+  const lpc176x_capture_port capture_port
+)
+{
+  assert( ( number < LPC176X_TIMER_COUNT )
+    && ( capture_port < LPC176X_CAPTURE_PORTS_COUNT ) );
+
+  return timers[ number ].device->CR[ capture_port ];
+}
+
+inline uint32_t lpc176x_timer_get_timer_value(
+  const lpc176x_timer_number tnumber )
+{
+  assert( tnumber < LPC176X_TIMER_COUNT );
+
+  return timers[ tnumber ].device->TC;
+}
+
+inline rtems_status_code lpc176x_timer_set_timer_value(
+  const lpc176x_timer_number tnumber,
+  const uint32_t             timer_value
+)
+{
+  rtems_status_code status_code = RTEMS_INVALID_NUMBER;
+
+  if ( tnumber < LPC176X_TIMER_COUNT ) {
+    timers[ tnumber ].device->TC = timer_value;
+    status_code = RTEMS_SUCCESSFUL;
+  }
+
+  /* else implies that the timer number is invalid. Also,
+     an invalid number is returned. */
+
+  return status_code;
+}
+
+void lpc176x_timer_isr( void *arg )
+{
+  const lpc176x_timer_number tnumber = (lpc176x_timer_number) arg;
+
+  if ( tnumber < LPC176X_TIMER_COUNT ) {
+    lpc176x_isr_function i;
+
+    for ( i = 0; i < LPC176X_ISR_FUNCTIONS_COUNT; ++i ) {
+      if ( lpc176x_timer_interrupt_is_pending( tnumber, i ) ) {
+        lpc176x_call_desired_isr( tnumber, i );
+        lpc176x_timer_reset_interrupt( tnumber, i );
+      }
+
+      /* else implies that the current timer is not pending. Also,
+         there is nothing to do. */
+    }
+  }
+
+  /* else implies that the timer number is not valid. Also,
+     there is nothing to do. */
+}
+
+rtems_status_code lpc176x_timer_init( const lpc176x_timer_number tnumber )
+{
+  rtems_status_code status_code = RTEMS_INVALID_NUMBER;
+
+  if ( tnumber < LPC176X_TIMER_COUNT ) {
+    status_code = lpc176x_module_enable( timers[ tnumber ].module,
+      LPC176X_MODULE_PCLK_DEFAULT );
+    RTEMS_CHECK_SC( status_code, "Enabling the timer module." );
+
+    status_code = lpc176x_timer_reset( tnumber );
+    status_code = lpc176x_timer_set_mode( tnumber,
+      LPC176X_TIMER_MODE_TIMER );
+    status_code = lpc176x_timer_set_resolution( tnumber,
+      LPC176X_TIMER_DEFAULT_RESOLUTION );
+
+    timers[ tnumber ].device->MCR = LPC176X_TIMER_CLEAR_FUNCTION;
+    timers[ tnumber ].device->CCR = LPC176X_TIMER_CLEAR_FUNCTION;
+    timers[ tnumber ].device->EMR = LPC176X_TIMER_CLEAR_FUNCTION;
+  }
+
+  /* else implies that the timer number is not valid. Also,
+     an invalid number is returned. */
+
+  return status_code;
+}
+
+rtems_status_code lpc176x_timer_init_with_interrupt(
+  const lpc176x_timer_number            tnumber,
+  const lpc176x_isr_funct_vector *const vector
+)
+{
+  rtems_status_code status_code = RTEMS_INVALID_NUMBER;
+
+  char isrname[ LPC176X_ISR_NAME_STRING_SIZE ];
+
+  snprintf( isrname, LPC176X_ISR_NAME_STRING_SIZE, "TimerIsr%d", tnumber );
+
+  if ( tnumber < LPC176X_TIMER_COUNT && vector != NULL ) {
+    functions_vector[ tnumber ].funct_vector = vector;
+
+    status_code = lpc176x_timer_init( tnumber );
+    status_code = rtems_interrupt_handler_install(
+      LPC176X_TIMER_VECTOR_NUMBER( tnumber ),
+      isrname,
+      RTEMS_INTERRUPT_UNIQUE,
+      lpc176x_timer_isr,
+      (void *) tnumber );
+  }
+
+  return status_code;
+}
\ No newline at end of file
diff --git a/c/src/lib/libbsp/arm/lpc176x/Makefile.am b/c/src/lib/libbsp/arm/lpc176x/Makefile.am
index c62474c..b443893 100644
--- a/c/src/lib/libbsp/arm/lpc176x/Makefile.am
+++ b/c/src/lib/libbsp/arm/lpc176x/Makefile.am
@@ -72,33 +72,33 @@ librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/dev/rtc/rtc-support.c
 librtemsbsp_a_SOURCES += ../../../../../../bsps/arm/lpc176x/rtc/rtc-config.c
 
 # GPIO
-librtemsbsp_a_SOURCES += gpio/lpc-gpio.c
+librtemsbsp_a_SOURCES += ../../../../../../bsps/arm/lpc176x/gpio/lpc-gpio.c
 
 # CAN
-librtemsbsp_a_SOURCES += can/can.c
+librtemsbsp_a_SOURCES += ../../../../../../bsps/arm/lpc176x/can/can.c
 
 # PWMOUT
-librtemsbsp_a_SOURCES += pwmout/pwmout.c
+librtemsbsp_a_SOURCES += ../../../../../../bsps/arm/lpc176x/pwm/pwmout.c
 
 # ADC
-librtemsbsp_a_SOURCES += adc/adc.c
+librtemsbsp_a_SOURCES += ../../../../../../bsps/arm/lpc176x/start/adc.c
 
 # Timer
-librtemsbsp_a_SOURCES += ../../../../../../bsps/arm/lpc176x/btimer/btimer.c
+librtemsbsp_a_SOURCES += ../../../../../../bsps/arm/lpc176x/timer/timer.c
 
 # Benchmark Timer
-librtemsbsp_a_SOURCES += benchmark_timer/benchmark_timer.c
+librtemsbsp_a_SOURCES += ../../../../../../bsps/arm/lpc176x/btimer/btimer.c
 
 # Misc
-librtemsbsp_a_SOURCES += misc/system-clocks.c
-librtemsbsp_a_SOURCES += misc/dma.c
-librtemsbsp_a_SOURCES += misc/dma-copy.c
-librtemsbsp_a_SOURCES += misc/bspidle.c
-librtemsbsp_a_SOURCES += misc/io.c
-librtemsbsp_a_SOURCES += misc/restart.c
+librtemsbsp_a_SOURCES += ../../../../../../bsps/arm/lpc176x/start/system-clocks.c
+librtemsbsp_a_SOURCES += ../../../../../../bsps/arm/lpc176x/start/dma.c
+librtemsbsp_a_SOURCES += ../../../../../../bsps/arm/lpc176x/start/dma-copy.c
+librtemsbsp_a_SOURCES += ../../../../../../bsps/arm/lpc176x/start/bspidle.c
+librtemsbsp_a_SOURCES += ../../../../../../bsps/arm/lpc176x/start/io.c
+librtemsbsp_a_SOURCES += ../../../../../../bsps/arm/lpc176x/start/restart.c
 
 # Watchdog
-librtemsbsp_a_SOURCES += watchdog/watchdog.c
+librtemsbsp_a_SOURCES += ../../../../../../bsps/arm/lpc176x/start/watchdog.c
 
 # Cache
 librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/cache/nocache.c
diff --git a/c/src/lib/libbsp/arm/lpc176x/benchmark_timer/benchmark_timer.c b/c/src/lib/libbsp/arm/lpc176x/benchmark_timer/benchmark_timer.c
deleted file mode 100644
index 359d890..0000000
--- a/c/src/lib/libbsp/arm/lpc176x/benchmark_timer/benchmark_timer.c
+++ /dev/null
@@ -1,45 +0,0 @@
-/**
- * @file timerbenchmark.c
- *
- * @ingroup lpc176x
- *
- * @brief Timer benchmark functions for the lpc176x bsp.
- */
-
-/*
- * Copyright (c) 2014 Taller Technologies.
- *
- * @author  Boretto Martin    (martin.boretto at tallertechnologies.com)
- * @author  Diaz Marcos (marcos.diaz at tallertechnologies.com)
- * @author  Lenarduzzi Federico  (federico.lenarduzzi at tallertechnologies.com)
- * @author  Daniel Chicco  (daniel.chicco at tallertechnologies.com)
- *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rtems.org/license/LICENSE.
- */
-
-#include <rtems.h>
-#include <bsp.h>
-#include <rtems/btimer.h>
-
-#include <bsp/timer.h>
-
-static uint32_t benchmark_timer_base;
-
-void benchmark_timer_initialize( void )
-{
-  benchmark_timer_base = lpc176x_timer_get_timer_value( LPC176X_TIMER_1 );
-}
-
-benchmark_timer_t benchmark_timer_read( void )
-{
-  uint32_t delta = lpc176x_timer_get_timer_value( LPC176X_TIMER_1 ) -
-                   benchmark_timer_base;
-
-  return delta;
-}
-
-void benchmark_timer_disable_subtracting_average_overhead( bool find_avg_ovhead )
-{
-}



More information about the vc mailing list