1 /*
2 * Copyright (c) 2015, Freescale Semiconductor, Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * o Redistributions of source code must retain the above copyright notice, this list
9 * of conditions and the following disclaimer.
10 *
11 * o Redistributions in binary form must reproduce the above copyright notice, this
12 * list of conditions and the following disclaimer in the documentation and/or
13 * other materials provided with the distribution.
14 *
15 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from this
17 * software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #include "mu_imx.h"
32
33 /*FUNCTION**********************************************************************
34 *
35 * Function Name : MU_TrySendMsg
36 * Description : Try to send message to the other core.
37 *
38 *END**************************************************************************/
MU_TrySendMsg(MU_Type * base,uint32_t regIndex,uint32_t msg)39 mu_status_t MU_TrySendMsg(MU_Type * base, uint32_t regIndex, uint32_t msg)
40 {
41 assert(regIndex < MU_TR_COUNT);
42
43 // TX register is empty.
44 if(MU_IsTxEmpty(base, regIndex))
45 {
46 base->TR[regIndex] = msg;
47 return kStatus_MU_Success;
48 }
49
50 return kStatus_MU_TxNotEmpty;
51 }
52
53 /*FUNCTION**********************************************************************
54 *
55 * Function Name : MU_SendMsg
56 * Description : Wait and send message to the other core.
57 *
58 *END**************************************************************************/
MU_SendMsg(MU_Type * base,uint32_t regIndex,uint32_t msg)59 void MU_SendMsg(MU_Type * base, uint32_t regIndex, uint32_t msg)
60 {
61 assert(regIndex < MU_TR_COUNT);
62 uint32_t mask = MU_SR_TE0_MASK >> regIndex;
63 // Wait TX register to be empty.
64 while (!(base->SR & mask)) { }
65 base->TR[regIndex] = msg;
66 }
67
68 /*FUNCTION**********************************************************************
69 *
70 * Function Name : MU_TryReceiveMsg
71 * Description : Try to receive message from the other core.
72 *
73 *END**************************************************************************/
MU_TryReceiveMsg(MU_Type * base,uint32_t regIndex,uint32_t * msg)74 mu_status_t MU_TryReceiveMsg(MU_Type * base, uint32_t regIndex, uint32_t *msg)
75 {
76 assert(regIndex < MU_RR_COUNT);
77
78 // RX register is full.
79 if(MU_IsRxFull(base, regIndex))
80 {
81 *msg = base->RR[regIndex];
82 return kStatus_MU_Success;
83 }
84
85 return kStatus_MU_RxNotFull;
86 }
87
88 /*FUNCTION**********************************************************************
89 *
90 * Function Name : MU_ReceiveMsg
91 * Description : Wait to receive message from the other core.
92 *
93 *END**************************************************************************/
MU_ReceiveMsg(MU_Type * base,uint32_t regIndex,uint32_t * msg)94 void MU_ReceiveMsg(MU_Type * base, uint32_t regIndex, uint32_t *msg)
95 {
96 assert(regIndex < MU_TR_COUNT);
97 uint32_t mask = MU_SR_RF0_MASK >> regIndex;
98
99 // Wait RX register to be full.
100 while (!(base->SR & mask)) { }
101 *msg = base->RR[regIndex];
102 }
103
104 /*FUNCTION**********************************************************************
105 *
106 * Function Name : MU_TriggerGeneralInt
107 * Description : Trigger general purpose interrupt to the other core.
108 *
109 *END**************************************************************************/
MU_TriggerGeneralInt(MU_Type * base,uint32_t index)110 mu_status_t MU_TriggerGeneralInt(MU_Type * base, uint32_t index)
111 {
112 // Previous interrupt has been accepted.
113 if (MU_IsGeneralIntAccepted(base, index))
114 {
115 // All interrupts have been accepted, trigger now.
116 base->CR = (base->CR & ~MU_CR_GIRn_MASK) // Clear GIRn
117 | (MU_CR_GIR0_MASK>>index); // Set GIRn
118 return kStatus_MU_Success;
119 }
120
121 return kStatus_MU_IntPending;
122 }
123
124 /*FUNCTION**********************************************************************
125 *
126 * Function Name : MU_TrySetFlags
127 * Description : Try to set some bits of the 3-bit flag.
128 *
129 *END**************************************************************************/
MU_TrySetFlags(MU_Type * base,uint32_t flags)130 mu_status_t MU_TrySetFlags(MU_Type * base, uint32_t flags)
131 {
132 if(MU_IsFlagPending(base))
133 {
134 return kStatus_MU_FlagPending;
135 }
136
137 base->CR = (base->CR & ~(MU_CR_GIRn_MASK | MU_CR_Fn_MASK)) | flags;
138 return kStatus_MU_Success;
139 }
140
141 /*FUNCTION**********************************************************************
142 *
143 * Function Name : MU_SetFlags
144 * Description : Block to set some bits of the 3-bit flag.
145 *
146 *END**************************************************************************/
MU_SetFlags(MU_Type * base,uint32_t flags)147 void MU_SetFlags(MU_Type * base, uint32_t flags)
148 {
149 while (MU_IsFlagPending(base)) { }
150 base->CR = (base->CR & ~(MU_CR_GIRn_MASK | MU_CR_Fn_MASK)) | flags;
151 }
152
153 /*******************************************************************************
154 * EOF
155 ******************************************************************************/
156