summaryrefslogtreecommitdiffstats
path: root/bsps/arm/raspberrypi/start/mailbox.c
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2018-04-25 10:36:01 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2018-04-25 11:02:24 +0200
commitfc1bdb839ef154cc90ff43edf3a5ea21b6b7f789 (patch)
tree0146bd743daf1c944529c303bf7121b7efd244eb /bsps/arm/raspberrypi/start/mailbox.c
parentbsp/smdk2410: Move smc.c to bsps (diff)
downloadrtems-fc1bdb839ef154cc90ff43edf3a5ea21b6b7f789.tar.bz2
bsp/raspberrypi: Move source files to bsps
This patch is a part of the BSP source reorganization. Update #3285.
Diffstat (limited to 'bsps/arm/raspberrypi/start/mailbox.c')
-rw-r--r--bsps/arm/raspberrypi/start/mailbox.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/bsps/arm/raspberrypi/start/mailbox.c b/bsps/arm/raspberrypi/start/mailbox.c
new file mode 100644
index 0000000000..8196781ee5
--- /dev/null
+++ b/bsps/arm/raspberrypi/start/mailbox.c
@@ -0,0 +1,63 @@
+/**
+ * @file
+ *
+ * @ingroup raspberrypi
+ *
+ * @brief mailbox support.
+ */
+/*
+ * Copyright (c) 2015 Yang Qiao
+ *
+ * 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 <stdint.h>
+#include <stdbool.h>
+#include <bsp.h>
+#include <bsp/raspberrypi.h>
+#include <bsp/mailbox.h>
+
+#define BCM2835_MBOX_DATA_MASK( data ) ( data & 0xFFFFFFF0U )
+#define BCM2835_MBOX_CHANNEL_MASK( data ) ( data & 0xFU )
+
+static inline bool bcm2835_mailbox_is_empty( void )
+{
+ return ( BCM2835_REG( BCM2835_MBOX_STATUS ) & BCM2835_MBOX_EMPTY );
+}
+
+static inline bool bcm2835_mailbox_is_full( void )
+{
+ return ( BCM2835_REG( BCM2835_MBOX_STATUS ) & BCM2835_MBOX_FULL );
+}
+
+unsigned int raspberrypi_mailbox_read( unsigned int channel )
+{
+ unsigned int raw;
+ unsigned int read_channel;
+
+ while ( 1 ) {
+ while ( bcm2835_mailbox_is_empty() ) ;
+
+ raw = BCM2835_REG( BCM2835_MBOX_READ );
+ read_channel = BCM2835_MBOX_CHANNEL_MASK( raw );
+
+ if ( read_channel == channel )
+ return BCM2835_MBOX_DATA_MASK( raw );
+ }
+}
+
+void raspberrypi_mailbox_write(
+ unsigned int channel,
+ unsigned int data
+)
+{
+ while ( bcm2835_mailbox_is_full() ) ;
+
+ BCM2835_REG( BCM2835_MBOX_WRITE ) =
+ BCM2835_MBOX_DATA_MASK( data ) |
+ BCM2835_MBOX_CHANNEL_MASK( channel );
+}