summaryrefslogtreecommitdiffstats
path: root/bsps/arm/rtl22xx
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2018-04-20 12:08:42 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2018-04-20 13:52:19 +0200
commite0dd8a5ad830798bc8082b03b8c42c32fb9660e0 (patch)
treed147bfc4d670fcdfbd2e2d2e75eb209f92e07df1 /bsps/arm/rtl22xx
parentbsps: Move startup files to bsps (diff)
downloadrtems-e0dd8a5ad830798bc8082b03b8c42c32fb9660e0.tar.bz2
bsps: Move benchmark timer to bsps
This patch is a part of the BSP source reorganization. Update #3285.
Diffstat (limited to 'bsps/arm/rtl22xx')
-rw-r--r--bsps/arm/rtl22xx/btimer/btimer.c65
-rw-r--r--bsps/arm/rtl22xx/btimer/lpc_timer.h48
2 files changed, 113 insertions, 0 deletions
diff --git a/bsps/arm/rtl22xx/btimer/btimer.c b/bsps/arm/rtl22xx/btimer/btimer.c
new file mode 100644
index 0000000000..ad73aeda3c
--- /dev/null
+++ b/bsps/arm/rtl22xx/btimer/btimer.c
@@ -0,0 +1,65 @@
+/**
+ * @file
+ * @brief RTL22xx board Timer driver
+ *
+ * This uses Timer1 for timing measurments.
+ */
+
+/*
+ * By Ray Xu <rayx.cn@gmail.com>, modify form Mc9328mxl RTEMS DSP
+ *
+ * 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 <bsp.h>
+#include <rtems.h>
+#include <rtems/btimer.h>
+#include <lpc22xx.h>
+#include "lpc_timer.h"
+
+uint32_t g_start;
+uint32_t g_freq;
+
+bool benchmark_timer_find_average_overhead;
+
+
+/*
+ * Set up Timer 1
+ */
+void benchmark_timer_initialize( void )
+{
+ g_freq = LPC22xx_Fpclk / 1000;
+}
+
+/*
+ * The following controls the behavior of benchmark_timer_read().
+ *
+ * AVG_OVEREHAD is the overhead for starting and stopping the timer. It
+ * is usually deducted from the number returned.
+ *
+ * LEAST_VALID is the lowest number this routine should trust. Numbers
+ * below this are "noise" and zero is returned.
+ */
+
+#define AVG_OVERHEAD 0 /* It typically takes X.X microseconds */
+ /* (Y countdowns) to start/stop the timer. */
+ /* This value is in microseconds. */
+#define LEAST_VALID 1 /* Don't trust a clicks value lower than this */
+
+benchmark_timer_t benchmark_timer_read( void )
+{
+ return (T0TC/(LPC22xx_Fpclk/1000000));
+ /*
+ * Total is calculated by taking into account the number of timer overflow
+ * interrupts since the timer was initialized and clicks since the last
+ * interrupts.
+ */
+}
+
+void benchmark_timer_disable_subtracting_average_overhead(bool find_flag)
+{
+ benchmark_timer_find_average_overhead = find_flag;
+}
+
diff --git a/bsps/arm/rtl22xx/btimer/lpc_timer.h b/bsps/arm/rtl22xx/btimer/lpc_timer.h
new file mode 100644
index 0000000000..364812ddb8
--- /dev/null
+++ b/bsps/arm/rtl22xx/btimer/lpc_timer.h
@@ -0,0 +1,48 @@
+#ifndef __LPC_TIMER_H
+#define __LPC_TIMER_H
+
+/*************************************************************************
+ *
+ * File name : Timer.h
+ *
+ **************************************************************************/
+
+/* Timer Control register bit descriptions */
+#define TCR_ENABLE_BIT 0
+#define TCR_RESET_BIT 1
+
+// The channel name which is used in matching, in fact they represent
+// corresponding Match Register
+#define CH_MAXNUM 4
+#define CH0 0
+#define CH1 1
+#define CH2 2
+#define CH3 3
+
+// The channel name which is used in capturing, in fact they represent
+// corresponding Capture Register
+#define CPCH_MAXNUM 4
+#define CPCH0 0
+#define CPCH1 1
+#define CPCH2 2
+#define CPCH3 3
+
+//The actions when matching
+#define TimerAction_Interrupt 0x1
+#define TimerAction_ResetTimer 0x2
+#define TimerAction_StopTimer 0x4
+
+//Interrupt source type
+#define TIMERMR0Int 0x01
+#define TIMERMR1Int 0x02
+#define TIMERMR2Int 0x04
+#define TIMERMR3Int 0x08
+#define TIMERCR0Int 0x10
+#define TIMERCR1Int 0x20
+#define TIMERCR2Int 0x40
+#define TIMERCR3Int 0x80
+
+#define TIMERALLInt 0xFF
+
+#endif //__LPC_Timer_H
+