The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
AnnaBridge
Date:
Wed Feb 20 20:53:29 2019 +0000
Revision:
172:65be27845400
Parent:
171:3a7713b1edbc
mbed library release version 165

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Kojto 148:fd96258d940d 1 /*
Kojto 148:fd96258d940d 2 * Copyright(C) NXP Semiconductors, 2014
Kojto 148:fd96258d940d 3 * Copyright (c) 2016, Freescale Semiconductor, Inc.
Kojto 148:fd96258d940d 4 * All rights reserved.
Kojto 148:fd96258d940d 5 *
Kojto 148:fd96258d940d 6 * Redistribution and use in source and binary forms, with or without modification,
Kojto 148:fd96258d940d 7 * are permitted provided that the following conditions are met:
Kojto 148:fd96258d940d 8 *
Kojto 148:fd96258d940d 9 * o Redistributions of source code must retain the above copyright notice, this list
Kojto 148:fd96258d940d 10 * of conditions and the following disclaimer.
Kojto 148:fd96258d940d 11 *
Kojto 148:fd96258d940d 12 * o Redistributions in binary form must reproduce the above copyright notice, this
Kojto 148:fd96258d940d 13 * list of conditions and the following disclaimer in the documentation and/or
Kojto 148:fd96258d940d 14 * other materials provided with the distribution.
Kojto 148:fd96258d940d 15 *
Kojto 148:fd96258d940d 16 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
Kojto 148:fd96258d940d 17 * contributors may be used to endorse or promote products derived from this
Kojto 148:fd96258d940d 18 * software without specific prior written permission.
Kojto 148:fd96258d940d 19 *
Kojto 148:fd96258d940d 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
Kojto 148:fd96258d940d 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
Kojto 148:fd96258d940d 22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Kojto 148:fd96258d940d 23 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
Kojto 148:fd96258d940d 24 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
Kojto 148:fd96258d940d 25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
Kojto 148:fd96258d940d 26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
Kojto 148:fd96258d940d 27 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Kojto 148:fd96258d940d 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
Kojto 148:fd96258d940d 29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Kojto 148:fd96258d940d 30 */
Kojto 148:fd96258d940d 31
Kojto 148:fd96258d940d 32 #ifndef _FSL_MAILBOX_H_
Kojto 148:fd96258d940d 33 #define _FSL_MAILBOX_H_
Kojto 148:fd96258d940d 34
Kojto 148:fd96258d940d 35 #include "fsl_common.h"
Kojto 148:fd96258d940d 36
Kojto 148:fd96258d940d 37 /*!
Kojto 148:fd96258d940d 38 * @addtogroup mailbox
Kojto 148:fd96258d940d 39 * @{
Kojto 148:fd96258d940d 40 */
Kojto 148:fd96258d940d 41
Kojto 148:fd96258d940d 42 /*! @file */
Kojto 148:fd96258d940d 43
Kojto 148:fd96258d940d 44 /******************************************************************************
Kojto 148:fd96258d940d 45 * Definitions
Kojto 148:fd96258d940d 46 *****************************************************************************/
Kojto 148:fd96258d940d 47
Kojto 148:fd96258d940d 48 /*! @name Driver version */
Kojto 148:fd96258d940d 49 /*@{*/
Kojto 148:fd96258d940d 50 /*! @brief MAILBOX driver version 2.0.0. */
Kojto 148:fd96258d940d 51 #define FSL_MAILBOX_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
Kojto 148:fd96258d940d 52 /*@}*/
Kojto 148:fd96258d940d 53
Kojto 148:fd96258d940d 54 /*!
Kojto 148:fd96258d940d 55 * @brief CPU ID.
Kojto 148:fd96258d940d 56 */
Kojto 148:fd96258d940d 57 typedef enum _mailbox_cpu_id
Kojto 148:fd96258d940d 58 {
Kojto 148:fd96258d940d 59 kMAILBOX_CM0Plus = 0,
Kojto 148:fd96258d940d 60 kMAILBOX_CM4
Kojto 148:fd96258d940d 61 } mailbox_cpu_id_t;
Kojto 148:fd96258d940d 62
Kojto 148:fd96258d940d 63 /*******************************************************************************
Kojto 148:fd96258d940d 64 * API
Kojto 148:fd96258d940d 65 ******************************************************************************/
Kojto 148:fd96258d940d 66
Kojto 148:fd96258d940d 67 #ifdef __cplusplus
Kojto 148:fd96258d940d 68 extern "C" {
Kojto 148:fd96258d940d 69 #endif
Kojto 148:fd96258d940d 70
Kojto 148:fd96258d940d 71 /*!
Kojto 148:fd96258d940d 72 * @name MAILBOX initialization
Kojto 148:fd96258d940d 73 * @{
Kojto 148:fd96258d940d 74 */
Kojto 148:fd96258d940d 75
Kojto 148:fd96258d940d 76 /*!
Kojto 148:fd96258d940d 77 * @brief Initializes the MAILBOX module.
Kojto 148:fd96258d940d 78 *
Kojto 148:fd96258d940d 79 * This function enables the MAILBOX clock only.
Kojto 148:fd96258d940d 80 *
Kojto 148:fd96258d940d 81 * @param base MAILBOX peripheral base address.
Kojto 148:fd96258d940d 82 */
Kojto 148:fd96258d940d 83 static inline void MAILBOX_Init(MAILBOX_Type *base)
Kojto 148:fd96258d940d 84 {
Kojto 148:fd96258d940d 85 CLOCK_EnableClock(kCLOCK_Mailbox);
Kojto 148:fd96258d940d 86 }
Kojto 148:fd96258d940d 87
Kojto 148:fd96258d940d 88 /*!
Kojto 148:fd96258d940d 89 * @brief De-initializes the MAILBOX module.
Kojto 148:fd96258d940d 90 *
Kojto 148:fd96258d940d 91 * This function disables the MAILBOX clock only.
Kojto 148:fd96258d940d 92 *
Kojto 148:fd96258d940d 93 * @param base MAILBOX peripheral base address.
Kojto 148:fd96258d940d 94 */
Kojto 148:fd96258d940d 95 static inline void MAILBOX_Deinit(MAILBOX_Type *base)
Kojto 148:fd96258d940d 96 {
Kojto 148:fd96258d940d 97 CLOCK_DisableClock(kCLOCK_Mailbox);
Kojto 148:fd96258d940d 98 }
Kojto 148:fd96258d940d 99
Kojto 148:fd96258d940d 100 /* @} */
Kojto 148:fd96258d940d 101
Kojto 148:fd96258d940d 102 /*!
Kojto 148:fd96258d940d 103 * @brief Set data value in the mailbox based on the CPU ID.
Kojto 148:fd96258d940d 104 *
Kojto 148:fd96258d940d 105 * @param base MAILBOX peripheral base address.
Kojto 148:fd96258d940d 106 * @param cpu_id CPU id, kMAILBOX_CM0Plus is M0+ or kMAILBOX_CM4 is M4.
Kojto 148:fd96258d940d 107 * @param mboxData Data to send in the mailbox.
Kojto 148:fd96258d940d 108 *
Kojto 148:fd96258d940d 109 * @note Sets a data value to send via the MAILBOX to the other core.
Kojto 148:fd96258d940d 110 */
Kojto 148:fd96258d940d 111 static inline void MAILBOX_SetValue(MAILBOX_Type *base, mailbox_cpu_id_t cpu_id, uint32_t mboxData)
Kojto 148:fd96258d940d 112 {
Kojto 148:fd96258d940d 113 assert((cpu_id == kMAILBOX_CM0Plus) || (cpu_id == kMAILBOX_CM4));
Kojto 148:fd96258d940d 114 base->MBOXIRQ[cpu_id].IRQ = mboxData;
Kojto 148:fd96258d940d 115 }
Kojto 148:fd96258d940d 116
Kojto 148:fd96258d940d 117 /*!
Kojto 148:fd96258d940d 118 * @brief Get data in the mailbox based on the CPU ID.
Kojto 148:fd96258d940d 119 *
Kojto 148:fd96258d940d 120 * @param base MAILBOX peripheral base address.
Kojto 148:fd96258d940d 121 * @param cpu_id CPU id, kMAILBOX_CM0Plus is M0+ or kMAILBOX_CM4 is M4.
Kojto 148:fd96258d940d 122 *
Kojto 148:fd96258d940d 123 * @return Current mailbox data.
Kojto 148:fd96258d940d 124 */
Kojto 148:fd96258d940d 125 static inline uint32_t MAILBOX_GetValue(MAILBOX_Type *base, mailbox_cpu_id_t cpu_id)
Kojto 148:fd96258d940d 126 {
Kojto 148:fd96258d940d 127 assert((cpu_id == kMAILBOX_CM0Plus) || (cpu_id == kMAILBOX_CM4));
Kojto 148:fd96258d940d 128 return base->MBOXIRQ[cpu_id].IRQ;
Kojto 148:fd96258d940d 129 }
Kojto 148:fd96258d940d 130
Kojto 148:fd96258d940d 131 /*!
Kojto 148:fd96258d940d 132 * @brief Set data bits in the mailbox based on the CPU ID.
Kojto 148:fd96258d940d 133 *
Kojto 148:fd96258d940d 134 * @param base MAILBOX peripheral base address.
Kojto 148:fd96258d940d 135 * @param cpu_id CPU id, kMAILBOX_CM0Plus is M0+ or kMAILBOX_CM4 is M4.
Kojto 148:fd96258d940d 136 * @param mboxSetBits Data bits to set in the mailbox.
Kojto 148:fd96258d940d 137 *
Kojto 148:fd96258d940d 138 * @note Sets data bits to send via the MAILBOX to the other core. A value of 0 will
Kojto 148:fd96258d940d 139 * do nothing. Only sets bits selected with a 1 in it's bit position.
Kojto 148:fd96258d940d 140 */
Kojto 148:fd96258d940d 141 static inline void MAILBOX_SetValueBits(MAILBOX_Type *base, mailbox_cpu_id_t cpu_id, uint32_t mboxSetBits)
Kojto 148:fd96258d940d 142 {
Kojto 148:fd96258d940d 143 assert((cpu_id == kMAILBOX_CM0Plus) || (cpu_id == kMAILBOX_CM4));
Kojto 148:fd96258d940d 144 base->MBOXIRQ[cpu_id].IRQSET = mboxSetBits;
Kojto 148:fd96258d940d 145 }
Kojto 148:fd96258d940d 146
Kojto 148:fd96258d940d 147 /*!
Kojto 148:fd96258d940d 148 * @brief Clear data bits in the mailbox based on the CPU ID.
Kojto 148:fd96258d940d 149 *
Kojto 148:fd96258d940d 150 * @param base MAILBOX peripheral base address.
Kojto 148:fd96258d940d 151 * @param cpu_id CPU id, kMAILBOX_CM0Plus is M0+ or kMAILBOX_CM4 is M4.
Kojto 148:fd96258d940d 152 * @param mboxClrBits Data bits to clear in the mailbox.
Kojto 148:fd96258d940d 153 *
Kojto 148:fd96258d940d 154 * @note Clear data bits to send via the MAILBOX to the other core. A value of 0 will
Kojto 148:fd96258d940d 155 * do nothing. Only clears bits selected with a 1 in it's bit position.
Kojto 148:fd96258d940d 156 */
Kojto 148:fd96258d940d 157 static inline void MAILBOX_ClearValueBits(MAILBOX_Type *base, mailbox_cpu_id_t cpu_id, uint32_t mboxClrBits)
Kojto 148:fd96258d940d 158 {
Kojto 148:fd96258d940d 159 assert((cpu_id == kMAILBOX_CM0Plus) || (cpu_id == kMAILBOX_CM4));
Kojto 148:fd96258d940d 160 base->MBOXIRQ[cpu_id].IRQCLR = mboxClrBits;
Kojto 148:fd96258d940d 161 }
Kojto 148:fd96258d940d 162
Kojto 148:fd96258d940d 163 /*!
Kojto 148:fd96258d940d 164 * @brief Get MUTEX state and lock mutex
Kojto 148:fd96258d940d 165 *
Kojto 148:fd96258d940d 166 * @param base MAILBOX peripheral base address.
Kojto 148:fd96258d940d 167 *
Kojto 148:fd96258d940d 168 * @return See note
Kojto 148:fd96258d940d 169 *
Kojto 148:fd96258d940d 170 * @note Returns '1' if the mutex was taken or '0' if another resources has the
Kojto 148:fd96258d940d 171 * mutex locked. Once a mutex is taken, it can be returned with the MAILBOX_SetMutex()
Kojto 148:fd96258d940d 172 * function.
Kojto 148:fd96258d940d 173 */
Kojto 148:fd96258d940d 174 static inline uint32_t MAILBOX_GetMutex(MAILBOX_Type *base)
Kojto 148:fd96258d940d 175 {
Kojto 148:fd96258d940d 176 return (base->MUTEX & MAILBOX_MUTEX_EX_MASK);
Kojto 148:fd96258d940d 177 }
Kojto 148:fd96258d940d 178
Kojto 148:fd96258d940d 179 /*!
Kojto 148:fd96258d940d 180 * @brief Set MUTEX state
Kojto 148:fd96258d940d 181 *
Kojto 148:fd96258d940d 182 * @param base MAILBOX peripheral base address.
Kojto 148:fd96258d940d 183 *
Kojto 148:fd96258d940d 184 * @note Sets mutex state to '1' and allows other resources to get the mutex.
Kojto 148:fd96258d940d 185 */
Kojto 148:fd96258d940d 186 static inline void MAILBOX_SetMutex(MAILBOX_Type *base)
Kojto 148:fd96258d940d 187 {
Kojto 148:fd96258d940d 188 base->MUTEX = MAILBOX_MUTEX_EX_MASK;
Kojto 148:fd96258d940d 189 }
Kojto 148:fd96258d940d 190
Kojto 148:fd96258d940d 191 #if defined(__cplusplus)
Kojto 148:fd96258d940d 192 }
Kojto 148:fd96258d940d 193 #endif /*_cplusplus*/
Kojto 148:fd96258d940d 194 /*@}*/
Kojto 148:fd96258d940d 195
Kojto 148:fd96258d940d 196 #endif /* _FSL_MAILBOX_H_ */