[PATCH 3/3] Mailbox : Adding functionality to get clock rate

Mudit Jain muditjain18011995 at gmail.com
Sat Aug 20 13:25:09 UTC 2016


From: Mudit Jain <muditj at nvidia.com>

---
 c/src/lib/libbsp/arm/raspberrypi/include/vc.h      |  8 +++++++
 c/src/lib/libbsp/arm/raspberrypi/misc/vc.c         | 26 ++++++++++++++++++++++
 c/src/lib/libbsp/arm/raspberrypi/misc/vc_defines.h | 12 ++++++++++
 3 files changed, 46 insertions(+)

diff --git a/c/src/lib/libbsp/arm/raspberrypi/include/vc.h b/c/src/lib/libbsp/arm/raspberrypi/include/vc.h
index 74f7557..e863732 100644
--- a/c/src/lib/libbsp/arm/raspberrypi/include/vc.h
+++ b/c/src/lib/libbsp/arm/raspberrypi/include/vc.h
@@ -144,6 +144,14 @@ typedef struct {
 
 int bcm2835_mailbox_get_board_serial(
   bcm2835_get_board_serial_entries *_entries );
+
+typedef struct {
+  uint32_t clock_id;
+  uint32_t clock_rate;
+} bcm2835_get_clock_rate_entries;
+
+int bcm2835_mailbox_get_clock_rate(
+  bcm2835_get_clock_rate_entries *_entries );
 /** @} */
 
 #endif /* LIBBSP_ARM_RASPBERRYPI_VC_H */
diff --git a/c/src/lib/libbsp/arm/raspberrypi/misc/vc.c b/c/src/lib/libbsp/arm/raspberrypi/misc/vc.c
index c089b36..df92649 100644
--- a/c/src/lib/libbsp/arm/raspberrypi/misc/vc.c
+++ b/c/src/lib/libbsp/arm/raspberrypi/misc/vc.c
@@ -447,3 +447,29 @@ int bcm2835_mailbox_get_board_serial(
 
   return 0;
 }
+
+int bcm2835_mailbox_get_clock_rate(
+  bcm2835_get_clock_rate_entries *_entries )
+{
+  struct {
+    bcm2835_mbox_buf_hdr hdr;
+    bcm2835_mbox_tag_get_clock_rate get_clock_rate;
+    uint32_t end_tag;
+  } buffer BCM2835_MBOX_BUF_ALIGN_ATTRIBUTE;
+  BCM2835_MBOX_INIT_BUF( &buffer );
+  BCM2835_MBOX_INIT_TAG_NO_REQ( &buffer.get_clock_rate,
+    BCM2835_MAILBOX_TAG_GET_CLOCK_RATE );
+  buffer.get_clock_rate.body.req.clock_id = _entries->clock_id;
+  bcm2835_mailbox_buffer_flush_and_invalidate( &buffer, sizeof( &buffer ) );
+
+  if ( bcm2835_mailbox_send_read_buffer( &buffer ) )
+    return -1;
+
+  _entries->clock_id = buffer.get_clock_rate.body.resp.clock_id;
+  _entries->clock_rate = buffer.get_clock_rate.body.resp.clock_rate;
+
+  if ( !bcm2835_mailbox_buffer_suceeded( &buffer.hdr ) )
+    return -2;
+
+  return 0;
+}
diff --git a/c/src/lib/libbsp/arm/raspberrypi/misc/vc_defines.h b/c/src/lib/libbsp/arm/raspberrypi/misc/vc_defines.h
index e1a5a5b..48d1658 100644
--- a/c/src/lib/libbsp/arm/raspberrypi/misc/vc_defines.h
+++ b/c/src/lib/libbsp/arm/raspberrypi/misc/vc_defines.h
@@ -217,6 +217,18 @@ typedef struct {
 } bcm2835_mbox_tag_get_vc_memory;
 
 #define BCM2835_MAILBOX_TAG_GET_CLOCKS          0x00010007
+typedef struct {
+  bcm2835_mbox_tag_hdr tag_hdr;
+  union {
+    struct {
+      uint32_t clock_id;
+    } req;
+    struct {
+      uint32_t clock_id;
+      uint32_t clock_rate;
+    } resp;
+  } body;
+} bcm2835_mbox_tag_get_clock_rate;
 
 /* Config */
 #define BCM2835_MAILBOX_TAG_GET_CMD_LINE        0x00050001
-- 
1.9.1




More information about the devel mailing list