eRPC API Reference  Rev. 1.12.0
NXP Semiconductors
erpc_mu_transport.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2017-2023 NXP
3  * All rights reserved.
4  *
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 
9 #ifndef _EMBEDDED_RPC__MU_TRANSPORT_H_
10 #define _EMBEDDED_RPC__MU_TRANSPORT_H_
11 
12 #include "erpc_config_internal.h"
13 #if !ERPC_THREADS_IS(NONE)
14 #include "erpc_threading.h"
15 #endif
16 #include "erpc_message_buffer.hpp"
17 #include "erpc_transport.hpp"
18 
19 extern "C" {
20 #include "fsl_device_registers.h"
21 #include "fsl_mu.h"
22 }
23 
30 // Definitions
33 #if ERPC_TRANSPORT_MU_USE_MCMGR
34 
36 #define MU_REG_COUNT (MU_RR_COUNT - 1U)
37 #define MU_LAST_REG_IDX 2
38 
39 #define MU_RX_Interrupt_Handler(x) MU_RX_Interrupt(x)
40 #define MU_RX_Interrupt(number) MU_Rx##number##FullFlagISR
41 #define MU_RxFullFlagISRCallback MU_RX_Interrupt_Handler(MU_LAST_REG_IDX)
42 
43 #define MU_TX_Interrupt_Handler(x) MU_TX_Interrupt(x)
44 #define MU_TX_Interrupt(number) MU_Tx##number##EmptyFlagISR
45 #define MU_TxEmptyFlagISRCallback MU_TX_Interrupt_Handler(MU_LAST_REG_IDX)
46 
47 #else
48 #define MU_REG_COUNT (MU_RR_COUNT)
49 #endif /* ERPC_TRANSPORT_MU_USE_MCMGR */
50 
51 #if (defined(MIMXRT1187_cm7_SERIES) || defined(MIMXRT1187_cm33_SERIES) || defined(MIMXRT1189_cm7_SERIES) || \
52  defined(MIMXRT1189_cm33_SERIES))
53 #define MU_TX_SHIFT (1UL << (MU_REG_COUNT - 1U))
54 #define MU_RX_SHIFT (1UL << (MU_REG_COUNT - 1U))
55 #define MU_RX_INTR_MASK (MU_RX_INTR(MU_RX_SHIFT))
56 #define MU_TX_INTR_MASK (MU_TX_INTR(MU_TX_SHIFT))
57 #define MU_IS_TX_EMPTY_FLAG_SET (0U != (transport->m_muBase->TCR & MU_TX_SHIFT))
58 #define MU_IS_RX_FULL_FLAG_SET (0U != (transport->m_muBase->RCR & MU_RX_SHIFT))
59 #define MU_SR_TX_MASK (1UL << (20U + (MU_REG_COUNT - 1U)))
60 #define MU_SR_RX_MASK (1UL << (24U + (MU_REG_COUNT - 1U)))
61 #else
62 #define MU_TX_SHIFT (1UL << (MU_CR_TIEn_SHIFT + MU_TR_COUNT - MU_REG_COUNT))
63 #define MU_RX_SHIFT (1UL << (MU_CR_RIEn_SHIFT + MU_RR_COUNT - MU_REG_COUNT))
64 #define MU_RX_INTR_MASK (MU_RX_SHIFT)
65 #define MU_TX_INTR_MASK (MU_TX_SHIFT)
66 #define MU_IS_TX_EMPTY_FLAG_SET (0U != (transport->m_muBase->CR & MU_TX_SHIFT))
67 #define MU_IS_RX_FULL_FLAG_SET (0U != (transport->m_muBase->CR & MU_RX_SHIFT))
68 #define MU_SR_TX_MASK (1UL << (MU_SR_TEn_SHIFT + MU_TR_COUNT - MU_REG_COUNT))
69 #define MU_SR_RX_MASK (1UL << (MU_SR_RFn_SHIFT + MU_RR_COUNT - MU_REG_COUNT))
70 #endif
71 // Classes
74 
75 namespace erpc {
94 class MUTransport : public Transport
95 {
96 public:
102  MUTransport(void);
103 
107  virtual ~MUTransport(void);
108 
119  virtual erpc_status_t init(MU_Type *muBase);
120 
130  virtual erpc_status_t receive(MessageBuffer *message) override;
131 
140  virtual erpc_status_t send(MessageBuffer *message) override;
141 
149  virtual bool hasMessage(void) override;
150 
151 #if ERPC_TRANSPORT_MU_USE_MCMGR
152 
160  static void mu_tx_empty_irq_callback(void);
168  static void mu_rx_full_irq_callback(void);
169 #else
170 
177  static void mu_irq_callback(void);
178 #endif /* ERPC_TRANSPORT_MU_USE_MCMGR */
179 
180 protected:
190  void rx_cb(void);
191 
198  void tx_cb(void);
199 
200  volatile bool m_newMessage;
202  volatile uint32_t m_rxMsgSize;
204  uint32_t m_rxCntBytes;
205  uint32_t *volatile m_rxBuffer;
206  volatile uint32_t m_txMsgSize;
208  uint32_t m_txCntBytes;
209  uint32_t *volatile m_txBuffer;
211 #if !ERPC_THREADS_IS(NONE)
217 #endif
218 
219  MU_Type *m_muBase;
220 };
221 
222 } // namespace erpc
223 
226 #endif // _EMBEDDED_RPC__MU_TRANSPORT_H_
Abstract interface for transport layer.
Definition: erpc_transport.hpp:36
volatile uint32_t m_rxMsgSize
Definition: erpc_mu_transport.hpp:202
virtual ~MUTransport(void)
Destructor of MU transport.
Definition: erpc_mu_transport.cpp:92
MUTransport(void)
Constructor of MU transport.
Definition: erpc_mu_transport.cpp:79
enum _erpc_status erpc_status_t
Type used for all status and error return values.
Definition: erpc_common.h:85
Semaphore m_txSemaphore
Definition: erpc_mu_transport.hpp:213
MU_Type * m_muBase
Definition: erpc_mu_transport.hpp:219
Semaphore m_rxSemaphore
Definition: erpc_mu_transport.hpp:212
Mutex m_sendLock
Definition: erpc_mu_transport.hpp:215
virtual erpc_status_t init(MU_Type *muBase)
Initialization of MU transport layer.
Definition: erpc_mu_transport.cpp:94
Represents a memory buffer containing a message.
Definition: erpc_message_buffer.hpp:37
uint32_t m_rxCntBytes
Definition: erpc_mu_transport.hpp:204
Definition: erpc_arbitrated_client_manager.hpp:25
uint32_t *volatile m_txBuffer
Definition: erpc_mu_transport.hpp:209
virtual erpc_status_t send(MessageBuffer *message) override
Function to send prepared message.
Definition: erpc_mu_transport.cpp:228
Transport that uses Messaging Unit (MU) for interprocessor messaging.
Definition: erpc_mu_transport.hpp:94
uint32_t *volatile m_rxBuffer
Definition: erpc_mu_transport.hpp:205
virtual erpc_status_t receive(MessageBuffer *message) override
Start receiving data and stores it to passed message buffer.
Definition: erpc_mu_transport.cpp:190
void tx_cb(void)
Function called from MU IRQ when the MU TX empty flag is asserted and the IRQ is enabled.
Definition: erpc_mu_transport.cpp:158
volatile uint32_t m_txMsgSize
Definition: erpc_mu_transport.hpp:206
Mutex m_receiveLock
Definition: erpc_mu_transport.hpp:216
volatile bool m_newMessage
Definition: erpc_mu_transport.hpp:200
uint32_t m_txCntBytes
Definition: erpc_mu_transport.hpp:208
static void mu_irq_callback(void)
Callback function called from MU IRQ.
Definition: erpc_mu_transport.cpp:58
Mutex.
Definition: erpc_threading.h:339
virtual bool hasMessage(void) override
Function to check if is new message to receive.
Definition: erpc_mu_transport.cpp:283
Simple semaphore class.
Definition: erpc_threading.h:442
void rx_cb(void)
Function called from MU IRQ when the MU RX full flag is asserted and the IRQ is enabled.
Definition: erpc_mu_transport.cpp:112