HPM SDK
HPMicro Software Development Kit
hpm_mcan_soc.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023-2024 HPMicro
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 #ifndef HPM_MCAN_SOC_H
9 #define HPM_MCAN_SOC_H
10 
11 #include <stdint.h>
12 #include "hpm_mcan_regs.h"
13 #include "hpm_soc.h"
14 #include "hpm_soc_feature.h"
15 
16 #define MCAN_SOC_TSU_SRC_TWO_STAGES (1U)
17 
18 #define HPM_MCAN_EXT_TBSEL_NUM (4U)
19 #define HPM_MCAN_TBSEL_BASE (0xF02FF000UL)
20 #define HPM_MCAN_TBSEL (*(volatile uint32_t *)HPM_MCAN_TBSEL_BASE)
21 #define HPM_MCAN_TBSEL_BITWIDTH (6U)
22 #define HPM_MCAN_TBSEL_MASK ((1UL << HPM_MCAN_TBSEL_BITWIDTH) - 1UL)
23 #define HPM_MCAN_TBSEL0_SHIFT (8U)
24 
28 #define MCAN_MSG_BUF_SIZE_IN_WORDS (640U)
29 #define MCAN_IP_SLOT_SIZE (0x4000U)
30 
34 #define MCAN_TSU_EXT_TIMEBASE_SRC_MIN (0U)
35 #define MCAN_TSU_EXT_TIMEBASE_SRC_TBSEL_0 (MCAN_TSU_EXT_TIMEBASE_SRC_MIN)
36 #define MCAN_TSU_EXT_TIMEBASE_SRC_TBSEL_1 (1U)
37 #define MCAN_TSU_EXT_TIMEBASE_SRC_TBSEL_2 (2U)
38 #define MCAN_TSU_EXT_TIMEBASE_SRC_TBSEL_3 (3U)
39 #define MCAN_TSU_EXT_TIMEBASE_SRC_MAX (MCAN_TSU_EXT_TIMEBASE_SRC_TBSEL_3)
40 
44 #define MCAN_TSU_TBSEL_PTPC0 (0x20)
45 #define MCAN_TSU_TBSEL_MCAN0 (0x00)
46 #define MCAN_TSU_TBSEL_MCAN1 (0x01)
47 #define MCAN_TSU_TBSEL_MCAN2 (0x02)
48 #define MCAN_TSU_TBSEL_MCAN3 (0x03)
49 #define MCAN_TSU_TBSEL_MCAN4 (0x04)
50 #define MCAN_TSU_TBSEL_MCAN5 (0x05)
51 #define MCAN_TSU_TBSEL_MCAN6 (0x06)
52 #define MCAN_TSU_TBSEL_MCAN7 (0x07)
53 
54 ATTR_PLACE_AT(".ahb_sram") extern uint32_t mcan_soc_msg_buf[MCAN_MSG_BUF_SIZE_IN_WORDS * MCAN_SOC_MAX_COUNT];
55 
56 #ifdef __cpluspus
57 extern "C" {
58 #endif
59 
65 static inline void mcan_set_tsu_ext_timebase_src(MCAN_Type *ptr, uint8_t src)
66 {
67  if (src < HPM_MCAN_EXT_TBSEL_NUM) {
69  }
70 }
71 
79 static inline void mcan_set_tsu_tbsel_option(MCAN_Type *ptr, uint8_t ext_tbsel, uint8_t tbsel_option)
80 {
81  (void) ptr;
82  if (ext_tbsel < HPM_MCAN_EXT_TBSEL_NUM) {
83  uint32_t tbsel_shift = (ext_tbsel * HPM_MCAN_TBSEL_BITWIDTH) + HPM_MCAN_TBSEL0_SHIFT;
84  uint32_t tbsel_mask = HPM_MCAN_TBSEL_MASK << tbsel_shift;
85  HPM_MCAN_TBSEL = (HPM_MCAN_TBSEL & ~tbsel_mask) | (((uint32_t) tbsel_option << tbsel_shift) & tbsel_mask);
86  }
87 }
88 
93 static inline void mcan_enable_standby_pin(MCAN_Type *ptr)
94 {
96 }
97 
102 static inline void mcan_disable_standby_pin(MCAN_Type *ptr)
103 {
105 }
106 
112 static inline uint32_t mcan_get_ram_base(MCAN_Type *ptr)
113 {
114  (void) ptr;
115  return (uint32_t) &mcan_soc_msg_buf[0];
116 }
117 
123 static inline uint32_t mcan_get_ram_offset(MCAN_Type *ptr)
124 {
125  uint32_t index = ((uint32_t) ptr - HPM_MCAN0_BASE) / MCAN_IP_SLOT_SIZE;
126 
127  return (index * MCAN_MSG_BUF_SIZE_IN_WORDS * sizeof(uint32_t));
128 }
129 
135 static inline uint32_t mcan_get_ram_size(MCAN_Type *ptr)
136 {
137  (void) ptr;
138  return (MCAN_MSG_BUF_SIZE_IN_WORDS * sizeof(uint32_t));
139 }
140 
141 #ifdef __cpluspus
142 }
143 #endif
144 
145 #endif /* HPM_MCAN_SOC_H */
#define MCAN_SOC_MAX_COUNT
Definition: hpm_soc_feature.h:171
ATTR_PLACE_AT(".ahb_sram") extern uint32_t mcan_soc_msg_buf[(640U) *(4U)]
#define HPM_MCAN0_BASE
Definition: hpm_soc.h:220
#define MCAN_GLB_CTL_M_CAN_STBY_MASK
Definition: hpm_mcan_regs.h:2874
#define MCAN_GLB_CTL_TSU_TBIN_SEL_SET(x)
Definition: hpm_mcan_regs.h:2908
#define MCAN_GLB_CTL_TSU_TBIN_SEL_MASK
Definition: hpm_mcan_regs.h:2906
static uint32_t mcan_get_ram_offset(MCAN_Type *ptr)
Get the MCAN RAM offset in the dedicated/shared RAM for.
Definition: hpm_mcan_soc.h:123
static void mcan_set_tsu_tbsel_option(MCAN_Type *ptr, uint8_t ext_tbsel, uint8_t tbsel_option)
Set the Source for specified external timebase.
Definition: hpm_mcan_soc.h:79
#define HPM_MCAN_TBSEL_MASK
Definition: hpm_mcan_soc.h:22
#define HPM_MCAN_TBSEL
Definition: hpm_mcan_soc.h:20
#define HPM_MCAN_TBSEL_BITWIDTH
Definition: hpm_mcan_soc.h:21
#define MCAN_IP_SLOT_SIZE
Definition: hpm_mcan_soc.h:29
static void mcan_set_tsu_ext_timebase_src(MCAN_Type *ptr, uint8_t src)
Set External Timebase Source for MCAN TSU.
Definition: hpm_mcan_soc.h:65
static void mcan_disable_standby_pin(MCAN_Type *ptr)
Disable Standby pin for MCAN.
Definition: hpm_mcan_soc.h:102
#define MCAN_MSG_BUF_SIZE_IN_WORDS
MCAN MSG BUF base address (AHB_RAM)
Definition: hpm_mcan_soc.h:28
static void mcan_enable_standby_pin(MCAN_Type *ptr)
Enable Standby Pin for MCAN.
Definition: hpm_mcan_soc.h:93
#define HPM_MCAN_TBSEL0_SHIFT
Definition: hpm_mcan_soc.h:23
static uint32_t mcan_get_ram_base(MCAN_Type *ptr)
Get RAM base for MCAN.
Definition: hpm_mcan_soc.h:112
static uint32_t mcan_get_ram_size(MCAN_Type *ptr)
Get MCAN RAM size.
Definition: hpm_mcan_soc.h:135
#define HPM_MCAN_EXT_TBSEL_NUM
Definition: hpm_mcan_soc.h:18
Definition: hpm_mcan_regs.h:12
__RW uint32_t GLB_CTL
Definition: hpm_mcan_regs.h:74