HPM SDK
HPMicro Software Development Kit
hpm_mbx_drv.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021 HPMicro
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 
9 #ifndef HPM_MBX_DRV_H
10 #define HPM_MBX_DRV_H
11 #include "hpm_common.h"
12 #include "hpm_mbx_regs.h"
13 
21 /*
22  * @brief Bus access responses
23  */
24 typedef enum {
28 
29 /*
30  * @brief MBX specific status
31  */
32 enum {
34 };
35 
36 #define MBX_CR_ALL_INTERRUPTS_MASK (MBX_CR_TFMAIE_MASK | MBX_CR_RFMAIE_MASK \
37  | MBX_CR_RFMFIE_MASK | MBX_CR_TWMEIE_MASK)
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
50 {
51  ptr->CR = (ptr->CR & ~(MBX_CR_BARCTL_MASK)) | MBX_CR_BARCTL_SET(resp);
52 }
53 
60 static inline void mbx_enable_intr(MBX_Type *ptr, uint32_t mask)
61 {
62  ptr->CR |= mask;
63 }
64 
71 static inline void mbx_disable_intr(MBX_Type *ptr, uint32_t mask)
72 {
73  ptr->CR &= ~mask;
74 }
75 
81 static inline void mbx_empty_txfifo(MBX_Type *ptr)
82 {
83  ptr->CR |= MBX_CR_TXRESET_MASK;
84 }
85 
91 static inline void mbx_init(MBX_Type *ptr)
92 {
93  mbx_empty_txfifo(ptr);
95 }
96 
105 static inline hpm_stat_t mbx_send_message(MBX_Type *ptr, uint32_t msg)
106 {
107  if (ptr->SR & MBX_SR_TWME_MASK) {
108  ptr->TXREG = msg;
109  return status_success;
110  }
112 }
113 
114 
123 static inline hpm_stat_t mbx_retrieve_message(MBX_Type *ptr, uint32_t *msg)
124 {
125  if (ptr->SR & MBX_SR_RWMV_MASK) {
126  *msg = ptr->RXREG;
127  return status_success;
128  }
130 }
131 
142 static inline hpm_stat_t mbx_send_fifo(MBX_Type *ptr, uint32_t *msg, uint32_t count)
143 {
144  uint32_t i;
145  hpm_stat_t status = status_success;
146  for (i = 0; i < 4; i++) {
147  if (ptr->SR & MBX_SR_TFMA_MASK) {
148  ptr->TXWRD[0] = MBX_TXWRD_TXFIFO_SET(*(msg + i));
149  count--;
150  if (!count) {
151  break;
152  }
153  } else {
154  status = status_mbx_not_available;
155  break;
156  }
157  }
158  return status;
159 }
160 
161 
162 
173 static inline hpm_stat_t mbx_retrieve_fifo(MBX_Type *ptr, uint32_t *msg, uint32_t count)
174 {
175  uint32_t i;
176  hpm_stat_t status = status_success;
177  for (i = 0; i < 4; i++) {
178  if (ptr->SR & MBX_SR_RFMA_MASK) {
179  *(msg + i) = (ptr->RXWRD[0] & MBX_RXWRD_RXFIFO_MASK) >> MBX_RXWRD_RXFIFO_SHIFT;
180  count--;
181  if (!count) {
182  break;
183  }
184  } else {
185  status = status_mbx_not_available;
186  break;
187  }
188  }
189  return status;
190 }
191 
192 #ifdef __cplusplus
193 }
194 #endif
198 #endif /* HPM_MBX_DRV_H */
#define MBX_TXWRD_TXFIFO_SET(x)
Definition: hpm_mbx_regs.h:322
#define MBX_RXWRD_RXFIFO_MASK
Definition: hpm_mbx_regs.h:333
#define MBX_SR_TWME_MASK
Definition: hpm_mbx_regs.h:276
#define MBX_SR_TFMA_MASK
Definition: hpm_mbx_regs.h:230
#define MBX_SR_RWMV_MASK
Definition: hpm_mbx_regs.h:287
#define MBX_RXWRD_RXFIFO_SHIFT
Definition: hpm_mbx_regs.h:334
#define MBX_SR_RFMA_MASK
Definition: hpm_mbx_regs.h:254
#define MBX_CR_BARCTL_SET(x)
Definition: hpm_mbx_regs.h:45
#define MBX_CR_BARCTL_MASK
Definition: hpm_mbx_regs.h:43
#define MBX_CR_TXRESET_MASK
Definition: hpm_mbx_regs.h:29
uint32_t hpm_stat_t
Definition: hpm_common.h:126
#define MAKE_STATUS(group, code)
Definition: hpm_common.h:135
@ status_success
Definition: hpm_common.h:180
@ status_group_mbx
Definition: hpm_common.h:152
static hpm_stat_t mbx_send_fifo(MBX_Type *ptr, uint32_t *msg, uint32_t count)
Send message to fifo.
Definition: hpm_mbx_drv.h:142
static void mbx_init(MBX_Type *ptr)
Initialization.
Definition: hpm_mbx_drv.h:91
static void mbx_enable_intr(MBX_Type *ptr, uint32_t mask)
Enable interrupt with mask.
Definition: hpm_mbx_drv.h:60
static void mbx_disable_intr(MBX_Type *ptr, uint32_t mask)
Disable interrupt with mask.
Definition: hpm_mbx_drv.h:71
static void mbx_empty_txfifo(MBX_Type *ptr)
Empty fifo.
Definition: hpm_mbx_drv.h:81
static hpm_stat_t mbx_retrieve_message(MBX_Type *ptr, uint32_t *msg)
Retrieve message.
Definition: hpm_mbx_drv.h:123
#define MBX_CR_ALL_INTERRUPTS_MASK
Definition: hpm_mbx_drv.h:36
static hpm_stat_t mbx_send_message(MBX_Type *ptr, uint32_t msg)
Send message.
Definition: hpm_mbx_drv.h:105
static void mbx_set_bus_access_response(MBX_Type *ptr, mbx_bus_access_resp_t resp)
Set bus access response.
Definition: hpm_mbx_drv.h:49
static hpm_stat_t mbx_retrieve_fifo(MBX_Type *ptr, uint32_t *msg, uint32_t count)
Retrieve data from fifo.
Definition: hpm_mbx_drv.h:173
mbx_bus_access_resp_t
Definition: hpm_mbx_drv.h:24
@ status_mbx_not_available
Definition: hpm_mbx_drv.h:33
@ generate_bus_error
Definition: hpm_mbx_drv.h:26
@ no_bus_error_no_wait
Definition: hpm_mbx_drv.h:25
Definition: hpm_mbx_regs.h:12
__W uint32_t TXREG
Definition: hpm_mbx_regs.h:15
__W uint32_t TXWRD[1]
Definition: hpm_mbx_regs.h:17
__RW uint32_t SR
Definition: hpm_mbx_regs.h:14
__R uint32_t RXWRD[1]
Definition: hpm_mbx_regs.h:19
__RW uint32_t CR
Definition: hpm_mbx_regs.h:13
__R uint32_t RXREG
Definition: hpm_mbx_regs.h:16