Added support for WNC M14A2A Cellular LTE Data Module.

Dependencies:   WNC14A2AInterface

Dependents:   http-example-wnc http-example-wnc-modified

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers SPIRIT_Irq.c Source File

SPIRIT_Irq.c

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    SPIRIT_Irq.c
00004   * @author  VMA division - AMS
00005   * @version 3.2.2
00006   * @date    08-July-2015
00007   * @brief   Configuration and management of SPIRIT IRQs.
00008   * @details
00009   *
00010   * @attention
00011   *
00012   * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
00013   *
00014   * Redistribution and use in source and binary forms, with or without modification,
00015   * are permitted provided that the following conditions are met:
00016   *   1. Redistributions of source code must retain the above copyright notice,
00017   *      this list of conditions and the following disclaimer.
00018   *   2. Redistributions in binary form must reproduce the above copyright notice,
00019   *      this list of conditions and the following disclaimer in the documentation
00020   *      and/or other materials provided with the distribution.
00021   *   3. Neither the name of STMicroelectronics nor the names of its contributors
00022   *      may be used to endorse or promote products derived from this software
00023   *      without specific prior written permission.
00024   *
00025   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00026   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00028   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00029   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00030   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00031   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00032   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00033   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00034   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00035   *
00036   ******************************************************************************
00037   */
00038 
00039 /* Includes ------------------------------------------------------------------*/
00040 #include "SPIRIT_Irq.h"
00041 #include "MCU_Interface.h"
00042 
00043 
00044 
00045 /**
00046  * @addtogroup SPIRIT_Libraries
00047  * @{
00048  */
00049 
00050 
00051 /**
00052  * @addtogroup SPIRIT_Irq
00053  * @{
00054  */
00055 
00056 
00057 /**
00058  * @defgroup Irq_Private_TypesDefinitions       IRQ Private Types Definitions
00059  * @{
00060  */
00061 
00062 /**
00063  *@}
00064  */
00065 
00066 
00067 /**
00068  * @defgroup Irq_Private_Defines                IRQ Private Defines
00069  * @{
00070  */
00071 
00072 /**
00073  *@}
00074  */
00075 
00076 
00077 /**
00078  * @defgroup Irq_Private_Macros                 IRQ Private Macros
00079  * @{
00080  */
00081 
00082 /**
00083  *@}
00084  */
00085 
00086 
00087 /**
00088  * @defgroup Irq_Private_Variables              IRQ Private Variables
00089  * @{
00090  */
00091 
00092 
00093 /**
00094  *@}
00095  */
00096 
00097 
00098 /**
00099  * @defgroup Irq_Private_FunctionPrototypes     IRQ Private Function Prototypes
00100  * @{
00101  */
00102 
00103 /**
00104  *@}
00105  */
00106 
00107 
00108 /**
00109  * @defgroup Irq_Private_Functions              IRQ Private Functions
00110  * @{
00111  */
00112 
00113 
00114 /**
00115  * @brief  De initializate the SpiritIrqs structure setting all the bitfield to 0.
00116  *         Moreover, it sets the IRQ mask registers to 0x00000000, disabling all IRQs.
00117  * @param  pxIrqInit pointer to a variable of type @ref SpiritIrqs, in which all the
00118  *         bitfields will be settled to zero.
00119  * @retval None.
00120  */
00121 void SpiritIrqDeInit(SpiritIrqs* pxIrqInit)
00122 {
00123   uint8_t tempRegValue[4]={0x00,0x00,0x00,0x00};
00124 
00125   if(pxIrqInit!=NULL)
00126   {
00127     /* Sets the bitfields of passed structure to one */
00128     *(uint32_t*)pxIrqInit = 0x0;
00129   }
00130 
00131   /* Writes the IRQ_MASK registers */
00132   g_xStatus = SpiritSpiWriteRegisters(IRQ_MASK3_BASE, 4, tempRegValue);
00133 }
00134 
00135 
00136 /**
00137  * @brief  Enables all the IRQs according to the user defined pxIrqInit structure.
00138  * @param  pxIrqInit pointer to a variable of type @ref SpiritIrqs, through which the
00139  *         user enable specific IRQs. This parameter is a pointer to a SpiritIrqs.
00140  *         For example suppose to enable only the two IRQ Low Battery Level and Tx Data Sent:
00141  * @code
00142  * SpiritIrqs myIrqInit = {0};
00143  * myIrqInit.IRQ_LOW_BATT_LVL = 1;
00144  * myIrqInit.IRQ_TX_DATA_SENT = 1;
00145  * SpiritIrqInit(&myIrqInit);
00146  * @endcode
00147  * @retval None.
00148  */
00149 void SpiritIrqInit(SpiritIrqs* pxIrqInit)
00150 {
00151   /* Writes the IRQ_MASK registers */
00152   g_xStatus = SpiritSpiWriteRegisters(IRQ_MASK3_BASE, 4, (uint8_t*)pxIrqInit);
00153 
00154 }
00155 
00156 
00157 /**
00158  * @brief  Enables or disables a specific IRQ.
00159  * @param  xIrq IRQ to enable or disable.
00160  *         This parameter can be any value of @ref IrqList.
00161  * @param  xNewState new state for the IRQ.
00162  *         This parameter can be: S_ENABLE or S_DISABLE.
00163  * @retval None.
00164  */
00165 void SpiritIrq(IrqList xIrq, SpiritFunctionalState xNewState)
00166 {
00167   uint8_t tempRegValue[4];
00168   uint32_t tempValue = 0;
00169 
00170   /* Check the parameters */
00171   s_assert_param(IS_SPIRIT_IRQ_LIST(xIrq));
00172   s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xNewState));
00173 
00174   /* Reads the IRQ_MASK registers */
00175   g_xStatus = SpiritSpiReadRegisters(IRQ_MASK3_BASE, 4, tempRegValue);
00176 
00177   /* Build the IRQ mask word */
00178   for(uint8_t i=0; i<4; i++)
00179   {
00180     tempValue += ((uint32_t)tempRegValue[i])<<(8*(3-i));
00181   }
00182   
00183   /* Rebuild the new mask according to user request */
00184   if(xNewState == S_DISABLE)
00185   {
00186     tempValue &= (~xIrq);
00187   }
00188   else
00189   {
00190     tempValue |= (xIrq);
00191   }
00192 
00193   /* Build the array of bytes to write in the IRQ_MASK registers */
00194   for(uint8_t j=0; j<4; j++)
00195   {
00196     tempRegValue[j] = (uint8_t)(tempValue>>(8*(3-j)));
00197   }
00198   
00199   /* Writes the new IRQ mask in the corresponding registers */
00200   g_xStatus = SpiritSpiWriteRegisters(IRQ_MASK3_BASE, 4, tempRegValue);
00201 
00202 }
00203 
00204 
00205 /**
00206  * @brief  Fills a pointer to a structure of SpiritIrqs type reading the IRQ_MASK registers.
00207  * @param  pxIrqMask pointer to a variable of type @ref SpiritIrqs, through which the
00208  *         user can read which IRQs are enabled. All the bitfields equals to zero correspond
00209  *         to enabled IRQs, while all the bitfields equals to one correspond to disabled IRQs.
00210  *         This parameter is a pointer to a SpiritIrqs.
00211  *         For example suppose that the Power On Reset and RX Data ready are the only enabled IRQs.
00212  * @code
00213  * SpiritIrqs myIrqMask;
00214  * SpiritIrqGetStatus(&myIrqMask);
00215  * @endcode
00216  * Then
00217  * myIrqMask.IRQ_POR and myIrqMask.IRQ_RX_DATA_READY are equal to 0
00218  * while all the other bitfields are equal to one.
00219  * @retval None.
00220  */
00221 void SpiritIrqGetMask(SpiritIrqs* pxIrqMask)
00222 {
00223   /* Reads IRQ_MASK registers */
00224   g_xStatus = SpiritSpiReadRegisters(IRQ_MASK3_BASE, 4, (uint8_t*)pxIrqMask);
00225 }
00226 
00227 
00228 /**
00229  * @brief  Filla a pointer to a structure of SpiritIrqs type reading the IRQ_STATUS registers.
00230  * @param  pxIrqStatus pointer to a variable of type @ref SpiritIrqs, through which the
00231  *         user can read the status of all the IRQs. All the bitfields equals to one correspond
00232  *         to the raised interrupts. This parameter is a pointer to a SpiritIrqs.
00233  *         For example suppose that the XO settling timeout is raised as well as the Sync word
00234  *         detection.
00235  * @code
00236  * SpiritIrqs myIrqStatus;
00237  * SpiritIrqGetStatus(&myIrqStatus);
00238  * @endcode
00239  * Then
00240  * myIrqStatus.IRQ_XO_COUNT_EXPIRED and myIrqStatus.IRQ_VALID_SYNC are equals to 1
00241  * while all the other bitfields are equals to zero.
00242  * @retval None.
00243  */
00244 void SpiritIrqGetStatus(SpiritIrqs* pxIrqStatus)
00245 {
00246   /* Reads IRQ_STATUS registers */
00247   g_xStatus = SpiritSpiReadRegisters(IRQ_STATUS3_BASE, 4, (uint8_t*)pxIrqStatus);
00248 }
00249 
00250 
00251 /**
00252  * @brief  Clear the IRQ status registers.
00253  * @param  None.
00254  * @retval None.
00255  */
00256 void SpiritIrqClearStatus(void)
00257 {
00258   uint8_t tempRegValue[4];
00259 
00260   /* Reads the IRQ_STATUS registers clearing all the flags */
00261   g_xStatus = SpiritSpiReadRegisters(IRQ_STATUS3_BASE, 4, tempRegValue);
00262 
00263 }
00264 
00265 
00266 /**
00267  * @brief  Verifies if a specific IRQ has been generated.
00268  *         The call resets all the IRQ status, so it can't be used in case of multiple raising interrupts.
00269  * @param  xFlag IRQ flag to be checked.
00270  *         This parameter can be any value of @ref IrqList.
00271  * @retval SpiritBool S_TRUE or S_FALSE.
00272  */
00273 SpiritBool SpiritIrqCheckFlag(IrqList xFlag)
00274 {
00275   uint8_t tempRegValue[4];
00276   uint32_t tempValue = 0;
00277   SpiritBool flag;
00278 
00279   /* Check the parameters */
00280   s_assert_param(IS_SPIRIT_IRQ_LIST(xFlag));
00281 
00282   /* Reads registers and build the status word */
00283   g_xStatus = SpiritSpiReadRegisters(IRQ_STATUS3_BASE, 4, tempRegValue);
00284   for(uint8_t i=0; i<4; i++)
00285   {
00286     tempValue += ((uint32_t)tempRegValue[i])<<(8*(3-i));
00287   }
00288   
00289   if(tempValue & xFlag)
00290   {
00291     flag = S_TRUE;
00292   }
00293   else
00294   {
00295     flag = S_FALSE;
00296   }
00297 
00298   return flag;
00299 
00300 }
00301 
00302 
00303 /**
00304  *@}
00305  */
00306 
00307 
00308 /**
00309  *@}
00310  */
00311 
00312 
00313 /**
00314  *@}
00315  */
00316 
00317 
00318 
00319 
00320 /******************* (C) COPYRIGHT 2015 STMicroelectronics *****END OF FILE****/