HPM SDK
HPMicro Software Development Kit
hpm_sdxc_soc_drv.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021-2023 HPMicro
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 #ifndef HPM_SDXC_SOC_DRV_H
9 #define HPM_SDXC_SOC_DRV_H
10 
11 #include "hpm_soc.h"
12 #include "hpm_sdxc_regs.h"
13 
14 #if defined(__cplusplus)
15 extern "C" {
16 #endif
17 
18 
22 static inline void sdxc_wait_card_active(SDXC_Type *base)
23 {
25 
27  }
28  /*
29  * Assume that the BUS clock is 200MHz, while in the identification state, the SD clock is 400KHz.
30  * - Reading the register costs about 5ns in best case, hence the loop should be (74 / 400KHz) * 1000000000 / 5
31  * - For robustness, use 50000 here
32  */
33  for (volatile uint32_t i = 0; i < 50000U; i++) {
34  (void) base->CAPABILITIES1;
35  }
36 }
37 
38 static inline void sdxc_enable_inverse_clock(SDXC_Type *base, bool enable)
39 {
40  volatile uint32_t *reg = (base == HPM_SDXC0) ? &HPM_CONCTL->CTRL4 : &HPM_CONCTL->CTRL5;
41  if (enable) {
42  *reg |= (1UL << 28);
43  } else {
44  *reg &= ~(1UL << 28);
45  }
46 }
47 
48 static inline bool sdxc_is_inverse_clock_enabled(SDXC_Type *base)
49 {
50  volatile uint32_t *reg = (base == HPM_SDXC0) ? &HPM_CONCTL->CTRL4 : &HPM_CONCTL->CTRL5;
51  return ((*reg) & (1UL << 28)) != 0U;
52 }
53 
54 static inline void sdxc_select_cardclk_delay_source(SDXC_Type *base, bool delay_from_pad)
55 {
56  (void) base;
57  (void) delay_from_pad;
58 }
59 
60 static inline void sdxc_set_cardclk_delay_chain(SDXC_Type *base, uint32_t delay_chain)
61 {
62  (void) base;
63  volatile uint32_t *reg = (base == HPM_SDXC0) ? &HPM_CONCTL->CTRL4 : &HPM_CONCTL->CTRL5;
66 }
67 
68 static inline void sdxc_set_data_strobe_delay(SDXC_Type *base, uint32_t num_delaycells)
69 {
70  (void) base;
71  volatile uint32_t *reg = (base == HPM_SDXC0) ? &HPM_CONCTL->CTRL4 : &HPM_CONCTL->CTRL5;
75 }
76 
77 
78 static inline uint32_t sdxc_get_default_strobe_delay(SDXC_Type *base)
79 {
80  (void) base;
81  return 0;
82 }
83 
84 static inline void sdxc_set_rxclk_delay_chain(SDXC_Type *base, uint32_t num_delaycells)
85 {
86  volatile uint32_t *reg = (base == HPM_SDXC0) ? &HPM_CONCTL->CTRL4 : &HPM_CONCTL->CTRL5;
89 
91 }
92 
93 static inline uint32_t sdxc_get_default_cardclk_delay_chain(SDXC_Type *base, uint32_t clock_freq)
94 {
95  (void) base;
96  uint32_t num_delaycells = 1;
97  if (clock_freq <= 52000000) {
98  num_delaycells = 13;
99  }
100  return num_delaycells;
101 }
102 
103 static inline bool sdxc_is_ddr50_supported(SDXC_Type *base)
104 {
105  (void) base;
106  return false;
107 }
108 
109 #if defined(__cplusplus)
110 }
111 #endif
112 
113 
114 #endif /* HPM_SDXC_SOC_DRV_H */
#define HPM_SDXC0
Definition: hpm_soc.h:431
static bool sdxc_is_ddr50_supported(SDXC_Type *base)
Definition: hpm_sdxc_soc_drv.h:103
static void sdxc_set_cardclk_delay_chain(SDXC_Type *base, uint32_t delay_chain)
Definition: hpm_sdxc_soc_drv.h:60
static void sdxc_enable_inverse_clock(SDXC_Type *base, bool enable)
Definition: hpm_sdxc_soc_drv.h:38
static void sdxc_set_data_strobe_delay(SDXC_Type *base, uint32_t num_delaycells)
Definition: hpm_sdxc_soc_drv.h:68
static uint32_t sdxc_get_default_strobe_delay(SDXC_Type *base)
Definition: hpm_sdxc_soc_drv.h:78
static uint32_t sdxc_get_default_cardclk_delay_chain(SDXC_Type *base, uint32_t clock_freq)
Definition: hpm_sdxc_soc_drv.h:93
static bool sdxc_is_inverse_clock_enabled(SDXC_Type *base)
Definition: hpm_sdxc_soc_drv.h:48
static void sdxc_set_rxclk_delay_chain(SDXC_Type *base, uint32_t num_delaycells)
Definition: hpm_sdxc_soc_drv.h:84
static void sdxc_wait_card_active(SDXC_Type *base)
Wait at least 74 clocks until card is ready to receive the first command.
Definition: hpm_sdxc_soc_drv.h:22
static void sdxc_select_cardclk_delay_source(SDXC_Type *base, bool delay_from_pad)
Definition: hpm_sdxc_soc_drv.h:54
#define HPM_CONCTL
Definition: hpm_soc.h:651
#define IS_HPM_BITMASK_SET(val, mask)
Definition: hpm_common.h:61
#define CONCTL_CTRL4_SDXC0_GPR_CCLK_RX_DLY_SW_SEL_MASK
Definition: hpm_conctl_regs.h:226
#define CONCTL_CTRL4_SDXC0_GPR_TUNING_CARD_CLK_SEL_SET(x)
Definition: hpm_conctl_regs.h:199
#define CONCTL_CTRL4_SDXC0_GPR_TUNING_CARD_CLK_SEL_MASK
Definition: hpm_conctl_regs.h:197
#define CONCTL_CTRL4_SDXC0_GPR_CCLK_RX_DLY_SW_FORCE_MASK
Definition: hpm_conctl_regs.h:236
#define CONCTL_CTRL4_SDXC0_GPR_TUNING_STROBE_SEL_MASK
Definition: hpm_conctl_regs.h:207
#define CONCTL_CTRL4_SDXC0_GPR_STROBE_IN_ENABLE_MASK
Definition: hpm_conctl_regs.h:217
#define CONCTL_CTRL4_SDXC0_GPR_CCLK_RX_DLY_SW_SEL_SET(x)
Definition: hpm_conctl_regs.h:228
#define CONCTL_CTRL4_SDXC0_GPR_TUNING_STROBE_SEL_SET(x)
Definition: hpm_conctl_regs.h:209
#define SDXC_SYS_CTRL_SD_CLK_EN_MASK
Definition: hpm_sdxc_regs.h:1087
Definition: hpm_sdxc_regs.h:12
__R uint32_t CAPABILITIES1
Definition: hpm_sdxc_regs.h:26
__RW uint32_t SYS_CTRL
Definition: hpm_sdxc_regs.h:21