| PDL for FM0+ Version1.0 Peripheral Driverl Library for FM0+

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

C:/pdl_v10/library/driver/lvd/lvd.c
Go to the documentation of this file.

    00001 /*******************************************************************************
    00002 * Copyright (C) 2013 Spansion LLC. All Rights Reserved.
    00003 *
    00004 * This software is owned and published by:
    00005 * Spansion LLC, 915 DeGuigne Dr. Sunnyvale, CA  94088-3453 ("Spansion").
    00006 *
    00007 * BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
    00008 * BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
    00009 *
    00010 * This software contains source code for use with Spansion
    00011 * components. This software is licensed by Spansion to be adapted only
    00012 * for use in systems utilizing Spansion components. Spansion shall not be
    00013 * responsible for misuse or illegal use of this software for devices not
    00014 * supported herein.  Spansion is providing this software "AS IS" and will
    00015 * not be responsible for issues arising from incorrect user implementation
    00016 * of the software.
    00017 *
    00018 * SPANSION MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
    00019 * REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
    00020 * ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
    00021 * WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
    00022 * WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
    00023 * WARRANTY OF NONINFRINGEMENT.
    00024 * SPANSION SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
    00025 * NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
    00026 * LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
    00027 * LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
    00028 * INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
    00029 * INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
    00030 * SAVINGS OR PROFITS,
    00031 * EVEN IF SPANSION HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
    00032 * YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
    00033 * INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
    00034 * FROM, THE SOFTWARE.
    00035 *
    00036 * This software may be replicated in part or whole for the licensed use,
    00037 * with the restriction that this Disclaimer and Copyright notice must be
    00038 * included with each copy of this software, whether used in part or whole,
    00039 * at all times.
    00040 */
    00041 /******************************************************************************/
    00052 /******************************************************************************/
    00053 /* Include files                                                              */
    00054 /******************************************************************************/
    00055 #include "lvd.h"
    00056
    00057 #if (defined(PDL_PERIPHERAL_LVD_ACTIVE))
    00058
    00064
    00065 /******************************************************************************/
    00066 /* Local pre-processor symbols/macros ('#define')                             */
    00067 /******************************************************************************/
    00068
    00069 /******************************************************************************/
    00070 /* Local type definitions ('typedef')                                         */
    00071 /******************************************************************************/
    00072
    00073 /******************************************************************************/
    00074 /* Local function prototypes ('static')                                       */
    00075 /******************************************************************************/
    00076
    00077 /******************************************************************************/
    00078 /* Local variable definitions ('static')                                      */
    00079 /******************************************************************************/
    00080 #if (PDL_INTERRUPT_ENABLE_LVD == PDL_ON)
    00081 static func_ptr_t  pfnLvdCallback;
    00082 #endif
    00083 /******************************************************************************/
    00084 /* Function implementation - global ('extern') and local ('static')           */
    00085 /******************************************************************************/
    00086 /* LVD enable timeout count */
    00087 #define LVD_TIMEOUT     (SystemCoreClock/10)
    00088
    00089 /* Unlock code for LVD_RLR */
    00090 #define LvdCtlUnlock    (0x1ACCE553)
    00091
    00092 #if (PDL_INTERRUPT_ENABLE_LVD == PDL_ON)
    00093
    00098 void LvdIrqHandler(void)
    00099 {
    00100     FM0P_LVD->LVD_CLR = 0x00;  /* Clear LVD interrupt (LVDCL (bit #7)) */
    00101
    00102     if (NULL != pfnLvdCallback)
    00103     {
    00104         pfnLvdCallback();
    00105     }
    00106 } /* LvdIrqHandler */
    00107
    00121 en_result_t Lvd_ConfigInt(func_ptr_t pfnCallback)
    00122 {
    00123     /* If callback function is set, interrupt is used. */
    00124     if (NULL != pfnCallback)
    00125     {
    00126         pfnLvdCallback = pfnCallback;
    00127
    00128         /* Init NVIC */
    00129         NVIC_ClearPendingIRQ(LVD_IRQn);
    00130         NVIC_EnableIRQ(LVD_IRQn);
    00131         NVIC_SetPriority(LVD_IRQn, PDL_IRQ_LEVEL_LVD);
    00132
    00133     }
    00134     else
    00135     {
    00136         pfnLvdCallback = NULL;
    00137
    00138         /* DeInit NVIC */
    00139         NVIC_ClearPendingIRQ(LVD_IRQn);
    00140         NVIC_DisableIRQ(LVD_IRQn);
    00141         NVIC_SetPriority(LVD_IRQn, PDL_DEFAULT_INTERRUPT_LEVEL);
    00142     }
    00143
    00144     return Ok;
    00145 }
    00146 #endif
    00147
    00166 en_result_t Lvd_SetIntDetectVoltage(en_lvd_int_volt_t enVolt)
    00167 {
    00168     FM0P_LVD->LVD_RLR = LvdCtlUnlock;/* unlock LVD_CTL */
    00169     switch (enVolt)
    00170     {
    00171         case LvdIntVoltage280:  /* Interrupt when voltage is vicinity of 2.80 volts */
    00172             FM0P_LVD->LVD_CTL_f.SVHI = 0x03u;
    00173             break;
    00174         case LvdIntVoltage300:  /* Interrupt when voltage is vicinity of 3.00 volts */
    00175             FM0P_LVD->LVD_CTL_f.SVHI = 0x04u;
    00176             break;
    00177         case LvdIntVoltage320:  /* Interrupt when voltage is vicinity of 3.20 volts */
    00178             FM0P_LVD->LVD_CTL_f.SVHI = 0x05u;
    00179             break;
    00180         case LvdIntVoltage360:  /* Interrupt when voltage is vicinity of 3.60 volts */
    00181             FM0P_LVD->LVD_CTL_f.SVHI = 0x06u;
    00182             break;
    00183         case LvdIntVoltage370:  /* Interrupt when voltage is vicinity of 3.70 volts */
    00184             FM0P_LVD->LVD_CTL_f.SVHI = 0x07u;
    00185             break;
    00186         case LvdIntVoltage400:  /* Interrupt when voltage is vicinity of 4.00 volts */
    00187             FM0P_LVD->LVD_CTL_f.SVHI = 0x08u;
    00188             break;
    00189         case LvdIntVoltage410:  /* Interrupt when voltage is vicinity of 4.10 volts */
    00190             FM0P_LVD->LVD_CTL_f.SVHI = 0x09u;
    00191             break;
    00192         case LvdIntVoltage420:  /* Interrupt when voltage is vicinity of 4.20 volts */
    00193             FM0P_LVD->LVD_CTL_f.SVHI = 0x0Au;
    00194             break;
    00195         default:
    00196             FM0P_LVD->LVD_RLR = 0;           /* lock LVD_CTL */
    00197             return  ErrorInvalidParameter;
    00198     }
    00199
    00200     FM0P_LVD->LVD_RLR = 0;           /* lock LVD_CTL */
    00201
    00202     return Ok;
    00203 }
    00204
    00226 en_result_t Lvd_SetResetDetectVoltage(en_lvd_reset_volt_t enVolt)
    00227 {
    00228     FM0P_LVD->LVD_RLR = LvdCtlUnlock;/* unlock LVD_CTL */
    00229     switch (enVolt)
    00230     {
    00231         case LvdResetVoltage245:  /* Interrupt when voltage is vicinity of 2.45 volts */
    00232             FM0P_LVD->LVD_CTL_f.SVHR = 0x00u;
    00233             break;
    00234         case LvdResetVoltage260:  /* Interrupt when voltage is vicinity of 2.60 volts */
    00235             FM0P_LVD->LVD_CTL_f.SVHR = 0x01u;
    00236             break;
    00237         case LvdResetVoltage270:  /* Interrupt when voltage is vicinity of 2.70 volts */
    00238             FM0P_LVD->LVD_CTL_f.SVHR = 0x02u;
    00239             break;
    00240         case LvdResetVoltage280:  /* Interrupt when voltage is vicinity of 2.80 volts */
    00241             FM0P_LVD->LVD_CTL_f.SVHR = 0x03u;
    00242             break;
    00243         case LvdResetVoltage300:  /* Interrupt when voltage is vicinity of 3.00 volts */
    00244             FM0P_LVD->LVD_CTL_f.SVHR = 0x04u;
    00245             break;
    00246         case LvdResetVoltage320:  /* Interrupt when voltage is vicinity of 3.20 volts */
    00247             FM0P_LVD->LVD_CTL_f.SVHR = 0x05u;
    00248             break;
    00249         case LvdResetVoltage360:  /* Interrupt when voltage is vicinity of 3.60 volts */
    00250             FM0P_LVD->LVD_CTL_f.SVHR = 0x06u;
    00251             break;
    00252         case LvdResetVoltage370:  /* Interrupt when voltage is vicinity of 3.70 volts */
    00253             FM0P_LVD->LVD_CTL_f.SVHR = 0x07u;
    00254             break;
    00255         case LvdResetVoltage400:  /* Interrupt when voltage is vicinity of 4.00 volts */
    00256             FM0P_LVD->LVD_CTL_f.SVHR = 0x08u;
    00257             break;
    00258         case LvdResetVoltage410:  /* Interrupt when voltage is vicinity of 4.10 volts */
    00259             FM0P_LVD->LVD_CTL_f.SVHR = 0x09u;
    00260             break;
    00261         case LvdResetVoltage420:  /* Interrupt when voltage is vicinity of 4.20 volts */
    00262             FM0P_LVD->LVD_CTL_f.SVHR = 0x0Au;
    00263             break;
    00264         default:
    00265             FM0P_LVD->LVD_RLR = 0;           /* lock LVD_CTL */
    00266             return  ErrorInvalidParameter;
    00267     }
    00268
    00269     FM0P_LVD->LVD_RLR = 0;           /* lock LVD_CTL */
    00270
    00271     return Ok;
    00272 }
    00273
    00286 en_result_t Lvd_EnableFunc(en_lvd_func_t enFunc)
    00287 {
    00288     uint32_t u32TimeOut = LVD_TIMEOUT;
    00289
    00290     FM0P_LVD->LVD_RLR = LvdCtlUnlock;/* unlock LVD_CTL */
    00291     switch(enFunc)
    00292     {
    00293         case LvdIntFunc:
    00294             FM0P_LVD->LVD_CTL_f.LVDIE = 1;
    00295             while(1)
    00296             {
    00297                 if(FM0P_LVD->LVD_STR2_f.LVDIRDY == 1)
    00298                 {
    00299                     break;
    00300                 }
    00301
    00302                 u32TimeOut--;
    00303
    00304                 if(u32TimeOut == 0)
    00305                 {
    00306                     return ErrorTimeout;
    00307                 }
    00308             }
    00309
    00310             break;
    00311         case LvdResetFunc:
    00312             FM0P_LVD->LVD_CTL_f.LVDRE = 1;
    00313             while(1)
    00314             {
    00315                 if(FM0P_LVD->LVD_STR2_f.LVDRRDY == 1)
    00316                 {
    00317                     break;
    00318                 }
    00319
    00320                 u32TimeOut--;
    00321
    00322                 if(u32TimeOut == 0)
    00323                 {
    00324                     return ErrorTimeout;
    00325                 }
    00326             }
    00327             break;
    00328         default:
    00329             FM0P_LVD->LVD_RLR = 0;           /* lock LVD_CTL */
    00330             return  ErrorInvalidParameter;
    00331     }
    00332
    00333     FM0P_LVD->LVD_RLR = 0;           /* lock LVD_CTL */
    00334
    00335     return Ok;
    00336 }
    00337
    00350 en_result_t Lvd_DisableFunc(en_lvd_func_t enFunc)
    00351 {
    00352     FM0P_LVD->LVD_RLR = LvdCtlUnlock;/* unlock LVD_CTL */
    00353     switch(enFunc)
    00354     {
    00355         case LvdIntFunc:
    00356             FM0P_LVD->LVD_CTL_f.LVDIE = 0;
    00357             break;
    00358         case LvdResetFunc:
    00359             FM0P_LVD->LVD_CTL_f.LVDRE = 0;
    00360             break;
    00361         default:
    00362             FM0P_LVD->LVD_RLR = 0;           /* lock LVD_CTL */
    00363             return  ErrorInvalidParameter;
    00364     }
    00365
    00366     FM0P_LVD->LVD_RLR = 0;           /* lock LVD_CTL */
    00367
    00368     return Ok;
    00369 }
    00370
    00379 boolean_t Lvd_GetIntStatus(void)
    00380 {
    00381     boolean_t bRetVal = FALSE;
    00382
    00383     /* Check the LVD interrupt status */
    00384     if (TRUE == FM0P_LVD->LVD_STR_f.LVDIR)
    00385     {
    00386         bRetVal = TRUE;
    00387     }
    00388
    00389     return (bRetVal);
    00390 } /* Lvd_GetIntOperationStatus */
    00391
    00397 void Lvd_ClearIntStatus(void)
    00398 {
    00399     FM0P_LVD->LVD_CLR = 0x00;  /* Clear LVD interrupt (LVDCL (bit #7)) */
    00400 } /* Lvd_ClearIntStatus */
    00401
    00402
    00404
    00405 #endif /* #if (defined(PDL_PERIPHERAL_LVD_ACTIVE)) */
    00406
    00407 /******************************************************************************/
    00408 /* EOF (not truncated)                                                        */
    00409 /******************************************************************************/