This is an automated email from the ASF dual-hosted git repository.

andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
     new 52d5c4954 hw/mcu/cmac: Add chip variant detection on startup
52d5c4954 is described below

commit 52d5c49545730902bbf98c2dcdaccce61eed72fa
Author: Andrzej Kaczmarek <andrzej.kaczma...@codecoup.pl>
AuthorDate: Tue Jun 20 13:25:47 2023 +0200

    hw/mcu/cmac: Add chip variant detection on startup
    
    This adds chip variant dedection early during startup. Previously this
    was done during RF initialization, but since CHIP_ID1 register resides
    in PD_SYS it could happen that domain was powered down already due to
    M33 going to sleep.
    
    Reading on boot is safe since M33 starts CMAC and then waits for shm to
    initialize so PD_SYS is always available at CMAC startup.
---
 hw/mcu/dialog/cmac/include/mcu/mcu.h | 10 ++++++++++
 hw/mcu/dialog/cmac/src/system_cmac.c | 28 ++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+)

diff --git a/hw/mcu/dialog/cmac/include/mcu/mcu.h 
b/hw/mcu/dialog/cmac/include/mcu/mcu.h
index 28aecd221..5313b9889 100644
--- a/hw/mcu/dialog/cmac/include/mcu/mcu.h
+++ b/hw/mcu/dialog/cmac/include/mcu/mcu.h
@@ -31,6 +31,16 @@ extern "C" {
 #define MCU_MEM_SYSRAM_START_ADDRESS    (0x20000000)
 #define MCU_MEM_SYSRAM_END_ADDRESS      (0x20080000)
 
+#define MCU_CHIP_VARIANT_TSMC           1
+#define MCU_CHIP_VARIANT_GF             2
+
+static inline uint8_t
+mcu_chip_variant_get(void)
+{
+    extern uint8_t g_mcu_chip_variant;
+    return g_mcu_chip_variant;
+}
+
 /* Map diagnostic signal to diagnostic port (output) */
 #define MCU_DIAG_MAP(_port, _word, _evt)                                \
     CMAC->CM_DIAG_PORT ## _port ## _REG =                               \
diff --git a/hw/mcu/dialog/cmac/src/system_cmac.c 
b/hw/mcu/dialog/cmac/src/system_cmac.c
index ec83c963c..8a695dc8f 100644
--- a/hw/mcu/dialog/cmac/src/system_cmac.c
+++ b/hw/mcu/dialog/cmac/src/system_cmac.c
@@ -28,6 +28,16 @@
 #include <ipc_cmac/diag.h>
 #include "CMAC.h"
 
+uint8_t g_mcu_chip_variant;
+
+static inline uint32_t
+get_reg32_bits(uint32_t addr, uint32_t mask)
+{
+    volatile uint32_t *reg = (volatile uint32_t *)addr;
+
+    return (*reg & mask) >> __builtin_ctz(mask);
+}
+
 static inline void
 set_reg32_bits(uint32_t addr, uint32_t mask, uint32_t val)
 {
@@ -36,6 +46,22 @@ set_reg32_bits(uint32_t addr, uint32_t mask, uint32_t val)
     *reg = (*reg & (~mask)) | (val << __builtin_ctz(mask));
 }
 
+static void
+read_chip_variant(void)
+{
+    switch (get_reg32_bits(0x50040200, 0xff)) {
+    default:
+        /* use TSMC as default chip variant and hope it will work for unknown
+         * chips */
+    case '2':
+        g_mcu_chip_variant = MCU_CHIP_VARIANT_TSMC;
+        break;
+    case '3':
+        g_mcu_chip_variant = MCU_CHIP_VARIANT_GF;
+        break;
+    }
+}
+
 void
 SystemInit(void)
 {
@@ -48,6 +74,8 @@ SystemInit(void)
     for (int i = 0; i < 1000000; i++);
 #endif
 
+    read_chip_variant();
+
     CMAC->CM_CTRL_REG &= ~CMAC_CM_CTRL_REG_CM_BS_RESET_N_Msk;
     CMAC->CM_CTRL_REG |= CMAC_CM_CTRL_REG_CM_BS_RESET_N_Msk;
 

Reply via email to