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

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

C:/pdl_v10/library/driver/wdg/hwwdg.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 "hwwdg.h"
    00056
    00057 #if (defined(PDL_PERIPHERAL_WDG_ACTIVE))
    00058
    00064
    00065 #if (PDL_PERIPHERAL_ENABLE_HWWDG == PDL_ON)
    00066 /******************************************************************************/
    00067 /* Local pre-processor symbols/macros ('#define')                             */
    00068 /******************************************************************************/
    00069 /* for WDG_CTL */
    00070 #define HWWDG_CTL_INTEN     (0x01u)
    00071 #define HWWDG_CTL_RESEN     (0x02u)
    00072
    00073 /* for checking magic word (Hwwdg_DeInit) */
    00074 #define HWWDG_MAGIC_WORD_CHK1       (0x38D1AE5Cu)
    00075 #define HWWDG_MAGIC_WORD_CHK2       (0x7624D1BCu)
    00076 #define HWWDG_MAGIC_WORD_CHK_RESULT (0xFFFFFFFFu)
    00077
    00078 /******************************************************************************/
    00079 /* Global variable definitions (declared in header file with 'extern')        */
    00080 /******************************************************************************/
    00081 static func_ptr_t pfnHwwdgCallback;
    00082
    00083 /******************************************************************************/
    00084 /* Local type definitions ('typedef')                                         */
    00085 /******************************************************************************/
    00086
    00087 /******************************************************************************/
    00088 /* Local function prototypes ('static')                                       */
    00089 /******************************************************************************/
    00090
    00091 /******************************************************************************/
    00092 /* Local variable definitions ('static')                                      */
    00093 /******************************************************************************/
    00094
    00095 /******************************************************************************/
    00096 /* Function implementation - global ('extern') and local ('static')           */
    00097 /******************************************************************************/
    00098
    00103 void HwwdgIrqHandler(void)
    00104 {
    00105     /* Check hardware interrupt status */
    00106     if (TRUE == FM0P_HWWDT->WDG_RIS_f.RIS)
    00107     {
    00108         if (NULL != pfnHwwdgCallback)
    00109         {
    00110             pfnHwwdgCallback();
    00111         }
    00112     }
    00113 } /* HwwdgIrqHandler */
    00114
    00127 en_result_t Hwwdg_Init(stc_hwwdg_config_t* pstcConfig)
    00128 {
    00129     en_result_t enResult;
    00130     uint8_t     u8WdogControl = 0;      /* Preset register */
    00131
    00132     enResult = ErrorInvalidParameter;
    00133     /* Check for NULL Pointer */
    00134     if (NULL != pstcConfig)
    00135     {
    00136         /* Release Lock */
    00137         FM0P_HWWDT->WDG_LCK = HWWDG_REG_UNLOCK_1;
    00138         FM0P_HWWDT->WDG_LDR = pstcConfig->u32LoadValue;
    00139
    00140         if (TRUE == pstcConfig->bResetEnable)
    00141         {
    00142             /* RESEN bit */
    00143             u8WdogControl |= HWWDG_CTL_RESEN;
    00144         }
    00145
    00146         /* HW Watchdog Control Register unlock sequence */
    00147         FM0P_HWWDT->WDG_LCK = HWWDG_REG_UNLOCK_1;
    00148         FM0P_HWWDT->WDG_LCK = HWWDG_REG_UNLOCK_2;
    00149
    00150         /* Setup HW-Watchdog and start */
    00151         FM0P_HWWDT->WDG_CTL = u8WdogControl;
    00152
    00153         /* Initialize callback to NULL */
    00154         pfnHwwdgCallback = NULL;
    00155
    00156         NVIC_ClearPendingIRQ(NMI_IRQn);
    00157         NVIC_EnableIRQ(NMI_IRQn);
    00158         NVIC_SetPriority(NMI_IRQn, PDL_IRQ_LEVEL_HWWDG);
    00159
    00160         enResult = Ok;
    00161     }
    00162
    00163     return (enResult);
    00164 } /* Hwwdg_Init */
    00165
    00182 en_result_t Hwwdg_DeInit(uint32_t u32MagicWord1,
    00183                          uint32_t u32MagicWord2
    00184                         )
    00185 {
    00186     en_result_t enResult;
    00187
    00188     enResult = ErrorInvalidParameter;
    00189
    00190     /* Inverted magic word check is done to avoid "plain text magic word" in ROM. */
    00191     if ((HWWDG_MAGIC_WORD_CHK_RESULT == (u32MagicWord1 ^ HWWDG_MAGIC_WORD_CHK1)) &&
    00192         (HWWDG_MAGIC_WORD_CHK_RESULT == (u32MagicWord2 ^ HWWDG_MAGIC_WORD_CHK2))
    00193        )
    00194     {
    00195         /* Disable NVIC */
    00196         NVIC_ClearPendingIRQ(NMI_IRQn);
    00197         NVIC_DisableIRQ(NMI_IRQn);
    00198         NVIC_SetPriority(NMI_IRQn, PDL_DEFAULT_INTERRUPT_LEVEL);
    00199
    00200         /* HW Watchdog Control Register unlock sequence */
    00201         FM0P_HWWDT->WDG_LCK = HWWDG_REG_UNLOCK_1;
    00202         FM0P_HWWDT->WDG_LCK = HWWDG_REG_UNLOCK_2;
    00203
    00204         /* HW Watchdog stop */
    00205         FM0P_HWWDT->WDG_CTL = 0;
    00206
    00207         /* Initialize callback to NULL */
    00208         pfnHwwdgCallback = NULL;
    00209
    00210         enResult = Ok;
    00211     }
    00212
    00213     return (enResult);
    00214 } /* Hwwdg_DeInit */
    00215
    00226 en_result_t Hwwdg_Start(func_ptr_t pfnHwwdgCb)
    00227 {
    00228     en_result_t enResult;
    00229
    00230     /* If hardware watchdog is active, error is returned. */
    00231     if (TRUE == FM0P_HWWDT->WDG_CTL_f.INTEN)
    00232     {
    00233         enResult = ErrorOperationInProgress;
    00234     }
    00235     else
    00236     {
    00237         /* Set callback pointer to global variable for HW-Wdg-ISR */
    00238         pfnHwwdgCallback = pfnHwwdgCb;
    00239
    00240         /* HW Watchdog Control Register unlock sequence */
    00241         FM0P_HWWDT->WDG_LCK = HWWDG_REG_UNLOCK_1;
    00242         FM0P_HWWDT->WDG_LCK = HWWDG_REG_UNLOCK_2;
    00243
    00244         /* Enable interrupt and count */
    00245         FM0P_HWWDT->WDG_CTL_f.INTEN = TRUE;
    00246
    00247         enResult = Ok;
    00248     }
    00249
    00250     return (enResult);
    00251 } /* Hwwdg_Start */
    00252
    00258 void Hwwdg_Stop(void)
    00259 {
    00260     if (TRUE == FM0P_HWWDT->WDG_CTL_f.INTEN)
    00261     {
    00262         /* HW Watchdog Control Register unlock sequence */
    00263         FM0P_HWWDT->WDG_LCK = HWWDG_REG_UNLOCK_1;
    00264         FM0P_HWWDT->WDG_LCK = HWWDG_REG_UNLOCK_2;
    00265
    00266         /* Disable interrupt and count */
    00267         FM0P_HWWDT->WDG_CTL_f.INTEN = FALSE;
    00268     }
    00269 } /* Hwwdg_Stop */
    00270
    00278 void Hwwdg_WriteWdgLoad(uint32_t u32LoadValue)
    00279 {
    00280     FM0P_HWWDT->WDG_LCK = HWWDG_REG_UNLOCK_1;    /* Release Lock */
    00281     FM0P_HWWDT->WDG_LDR = u32LoadValue;          /* Write load value */
    00282 } /* Hwwdg_WriteWdgLoad */
    00283
    00291 uint32_t Hwwdg_ReadWdgValue(void)
    00292 {
    00293     return (FM0P_HWWDT->WDG_VLR);
    00294 } /* Hwwdg_ReadWdgValue */
    00295
    00308 void Hwwdg_Feed(uint8_t u8ClearPattern1,
    00309                 uint8_t u8ClearPattern2
    00310                )
    00311 {
    00312     FM0P_HWWDT->WDG_LCK = HWWDG_REG_UNLOCK_1;    /* Release Lock */
    00313     FM0P_HWWDT->WDG_ICL = u8ClearPattern1;       /* Clear possible interrupt and reload value, step 1 */
    00314     FM0P_HWWDT->WDG_ICL = u8ClearPattern2;       /* Clear possible interrupt and reload value, step 2 */
    00315 } /* Hwwdg_Feed */
    00316
    00322 void Hwwdg_EnableDbgBrkWdgCtl(void)
    00323 {
    00324     stc_crg_dbwdt_ctl_field_t stcDBWDT_CTL;
    00325
    00326     stcDBWDT_CTL         = FM0P_CRG->DBWDT_CTL_f;
    00327     stcDBWDT_CTL.DPHWBE  = TRUE;
    00328     FM0P_CRG->DBWDT_CTL_f = stcDBWDT_CTL;
    00329 } /* Hwwdt_EnableDbgBrkWdtCtl */
    00330
    00336 void Hwwdg_DisableDbgBrkWdgCtl(void)
    00337 {
    00338     stc_crg_dbwdt_ctl_field_t stcDBWDT_CTL;
    00339
    00340     stcDBWDT_CTL         = FM0P_CRG->DBWDT_CTL_f;
    00341     stcDBWDT_CTL.DPHWBE  = FALSE;
    00342     FM0P_CRG->DBWDT_CTL_f = stcDBWDT_CTL;
    00343 } /* Hwwdt_DisableDbgBrkWdtCtl */
    00344
    00345 #endif /* #if (PDL_PERIPHERAL_ENABLE_HWWDG == PDL_ON) */
    00346
    00348
    00349 #endif /* #if (defined(PDL_PERIPHERAL_WDG_ACTIVE)) */
    00350
    00351 /******************************************************************************/
    00352 /* EOF (not truncated)                                                        */
    00353 /******************************************************************************/