|
| 1 | +/* |
| 2 | + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +// The LL layer for ESP32-P4 LP Mailbox register operations |
| 8 | + |
| 9 | +#pragma once |
| 10 | + |
| 11 | +#include <stdlib.h> |
| 12 | +#include <stdbool.h> |
| 13 | +#include "soc/soc.h" |
| 14 | +#include "soc/lp_mailbox_struct.h" |
| 15 | +#include "soc/lp_mailbox_reg.h" |
| 16 | +#include "hal/misc.h" |
| 17 | +#include "esp_attr.h" |
| 18 | + |
| 19 | +#define LP_MAILBOX_LL_MSG_COUNT 16U |
| 20 | + |
| 21 | +#ifdef __cplusplus |
| 22 | +extern "C" { |
| 23 | +#endif |
| 24 | + |
| 25 | + |
| 26 | +/** |
| 27 | + * @brief Get a message (32-bit value) from the LP mailbox. |
| 28 | + * |
| 29 | + * @param dev Pointer to the LP mailbox device structure. |
| 30 | + * @param index Index of the message to retrieve (must be less than LP_MAILBOX_LL_MSG_COUNT). |
| 31 | + * |
| 32 | + * @return The 32-bit message value at the specified index, or 0 if the index is out of range. |
| 33 | + */ |
| 34 | +FORCE_INLINE_ATTR uint32_t lp_mailbox_ll_get_message(lp_mb_dev_t *dev, int index) |
| 35 | +{ |
| 36 | + if (index < LP_MAILBOX_LL_MSG_COUNT) { |
| 37 | + return (&dev->message_0.val)[index]; |
| 38 | + } |
| 39 | + return 0; |
| 40 | +} |
| 41 | + |
| 42 | +/** |
| 43 | + * @brief Set a message in the LP mailbox. |
| 44 | + * |
| 45 | + * @note Writing a message in the mailbox will set the corresponding message's intr_raw bit for |
| 46 | + * both the LP and HP registers, regardless of the writer! |
| 47 | + * |
| 48 | + * @param dev Pointer to the LP mailbox device structure. |
| 49 | + * @param index Index of the message to set (must be less than LP_MAILBOX_LL_MSG_COUNT). |
| 50 | + * @param val Message (32-bit value) to write to the specified message index. |
| 51 | + */ |
| 52 | +FORCE_INLINE_ATTR void lp_mailbox_ll_set_message(lp_mb_dev_t *dev, int index, uint32_t val) |
| 53 | +{ |
| 54 | + if (index < LP_MAILBOX_LL_MSG_COUNT) { |
| 55 | + (&dev->message_0.val)[index] = val; |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +/** |
| 60 | + * @brief Get the raw status of the LP core interrupt register. |
| 61 | + * |
| 62 | + * @param dev Pointer to the LP mailbox device structure. |
| 63 | + * |
| 64 | + * @return Raw interrupt status value. |
| 65 | + */ |
| 66 | +FORCE_INLINE_ATTR uint32_t lp_mailbox_ll_get_lp_intr_raw(lp_mb_dev_t *dev) |
| 67 | +{ |
| 68 | + return dev->lp_int_raw.val; |
| 69 | +} |
| 70 | + |
| 71 | +/** |
| 72 | + * @brief Clear LP core interrupt register bits. |
| 73 | + * |
| 74 | + * @param dev Pointer to the LP mailbox device structure. |
| 75 | + * @param mask Bitmask of interrupts to clear, bit `i` represents message `i`. |
| 76 | + */ |
| 77 | +FORCE_INLINE_ATTR void lp_mailbox_ll_lp_intr_clear(lp_mb_dev_t *dev, uint32_t mask) |
| 78 | +{ |
| 79 | + dev->lp_int_clr.val = mask; |
| 80 | +} |
| 81 | + |
| 82 | +/** |
| 83 | + * @brief Get the LP core interrupt register status. |
| 84 | + * |
| 85 | + * @param dev Pointer to the LP mailbox device structure. |
| 86 | + * |
| 87 | + * @return Interrupt status value. |
| 88 | + */ |
| 89 | +FORCE_INLINE_ATTR uint32_t lp_mailbox_ll_lp_intr_status(lp_mb_dev_t *dev) |
| 90 | +{ |
| 91 | + return dev->lp_int_st.val; |
| 92 | +} |
| 93 | + |
| 94 | +/** |
| 95 | + * @brief Enable mailbox interrupts by mask for the LP core. |
| 96 | + * |
| 97 | + * @param dev Pointer to the LP mailbox device structure. |
| 98 | + * @param mask Bitmask of interrupts to enable, bit `i` represents message `i`. |
| 99 | + * |
| 100 | + * @return Updated interrupt enable register value. |
| 101 | + */ |
| 102 | +FORCE_INLINE_ATTR uint32_t lp_mailbox_ll_lp_intr_enable_mask(lp_mb_dev_t *dev, uint32_t mask) |
| 103 | +{ |
| 104 | + dev->lp_int_ena.val |= mask; |
| 105 | + return dev->lp_int_ena.val; |
| 106 | +} |
| 107 | + |
| 108 | +/** |
| 109 | + * @brief Disable LP core mailbox interrupts by mask. |
| 110 | + * |
| 111 | + * @param dev Pointer to the LP mailbox device structure. |
| 112 | + * @param mask Bitmask of interrupts to disable, bit `i` represents message `i`. |
| 113 | + * |
| 114 | + * @return Updated interrupt enable register value. |
| 115 | + */ |
| 116 | + |
| 117 | +FORCE_INLINE_ATTR uint32_t lp_mailbox_ll_lp_intr_disable_mask(lp_mb_dev_t *dev, uint32_t mask) |
| 118 | +{ |
| 119 | + dev->lp_int_ena.val &= ~mask; |
| 120 | + return dev->lp_int_ena.val; |
| 121 | +} |
| 122 | + |
| 123 | +/** |
| 124 | + * @brief Get the raw status of the HP core interrupt register. |
| 125 | + * |
| 126 | + * @param dev Pointer to the LP mailbox device structure. |
| 127 | + * |
| 128 | + * @return Raw interrupt status value. |
| 129 | + */ |
| 130 | +FORCE_INLINE_ATTR uint32_t lp_mailbox_ll_get_hp_intr_raw(lp_mb_dev_t *dev) |
| 131 | +{ |
| 132 | + return dev->hp_int_raw.val; |
| 133 | +} |
| 134 | + |
| 135 | +/** |
| 136 | + * @brief Clear HP core interrupt register bits. |
| 137 | + * |
| 138 | + * @param dev Pointer to the LP mailbox device structure. |
| 139 | + * @param mask Bitmask of interrupts to clear, bit `i` represents message `i`. |
| 140 | + */ |
| 141 | +FORCE_INLINE_ATTR void lp_mailbox_ll_hp_intr_clear(lp_mb_dev_t *dev, uint32_t mask) |
| 142 | +{ |
| 143 | + dev->hp_int_clr.val = mask; |
| 144 | +} |
| 145 | + |
| 146 | +/** |
| 147 | + * @brief Get the HP core interrupt register status. |
| 148 | + * |
| 149 | + * @param dev Pointer to the LP mailbox device structure. |
| 150 | + * |
| 151 | + * @return Interrupt status value. |
| 152 | + */ |
| 153 | +FORCE_INLINE_ATTR uint32_t lp_mailbox_ll_hp_intr_status(lp_mb_dev_t *dev) |
| 154 | +{ |
| 155 | + return dev->hp_int_st.val; |
| 156 | +} |
| 157 | + |
| 158 | +/** |
| 159 | + * @brief Enable mailbox interrupts by mask for the HP core. |
| 160 | + * |
| 161 | + * @param dev Pointer to the LP mailbox device structure. |
| 162 | + * @param mask Bitmask of interrupts to enable, bit `i` represents message `i`. |
| 163 | + * |
| 164 | + * @return Updated interrupt enable register value. |
| 165 | + */ |
| 166 | +FORCE_INLINE_ATTR uint32_t lp_mailbox_ll_hp_intr_enable_mask(lp_mb_dev_t *dev, uint32_t mask) |
| 167 | +{ |
| 168 | + dev->hp_int_ena.val |= mask; |
| 169 | + return dev->hp_int_ena.val; |
| 170 | +} |
| 171 | + |
| 172 | +/** |
| 173 | + * @brief Disable HP core mailbox interrupts by mask. |
| 174 | + * |
| 175 | + * @param dev Pointer to the LP mailbox device structure. |
| 176 | + * @param mask Bitmask of interrupts to disable, bit `i` represents message `i`. |
| 177 | + * |
| 178 | + * @return Updated interrupt enable register value. |
| 179 | + */ |
| 180 | +FORCE_INLINE_ATTR uint32_t lp_mailbox_ll_hp_intr_disable_mask(lp_mb_dev_t *dev, uint32_t mask) |
| 181 | +{ |
| 182 | + dev->hp_int_ena.val &= ~mask; |
| 183 | + return dev->hp_int_ena.val; |
| 184 | +} |
| 185 | + |
| 186 | +#ifdef __cplusplus |
| 187 | +} |
| 188 | +#endif |
0 commit comments