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

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

C:/pdl_v10/library/driver/csv/csv.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 "csv.h"
    00056
    00057 #if (defined(PDL_PERIPHERAL_CSV_ACTIVE))
    00058 /*---------------------------------------------------------------------------*/
    00059 /* local defines                                                             */
    00060 /*---------------------------------------------------------------------------*/
    00061 /*---------------------------------------------------------------------------*/
    00062 /* local datatypes                                                           */
    00063 /*---------------------------------------------------------------------------*/
    00064 /*---------------------------------------------------------------------------*/
    00065 /* local data                                                                */
    00066 /*---------------------------------------------------------------------------*/
    00067 #if (PDL_INTERRUPT_ENABLE_CSV == PDL_ON)
    00068
    00069 static fn_fcs_int_callback *m_pfnIntCallback = NULL;
    00070 #endif
    00071
    00072 /*---------------------------------------------------------------------------*/
    00073 /* local functions prototypes                                                */
    00074 /*---------------------------------------------------------------------------*/
    00075 /*---------------------------------------------------------------------------*/
    00076 /* global data                                                               */
    00077 /*---------------------------------------------------------------------------*/
    00078 /*---------------------------------------------------------------------------*/
    00079 /* global functions                                                          */
    00080 /*---------------------------------------------------------------------------*/
    00081
    00082 #if (PDL_INTERRUPT_ENABLE_CSV == PDL_ON)
    00083
    00088 void Csv_IrqHandler(void)
    00089 {
    00090     bFM0P_CRG_INT_CLR_FCSC = 1;
    00091     m_pfnIntCallback();
    00092 }
    00093
    00099 en_result_t Csv_EnableFcsInt(fn_fcs_int_callback* pfnIntCallback)
    00100 {
    00101     if(pfnIntCallback == NULL)
    00102     {
    00103         return ErrorInvalidParameter;
    00104     }
    00105
    00106     m_pfnIntCallback = pfnIntCallback;
    00107     bFM0P_CRG_INT_ENR_FCSE = 1;
    00108
    00109     NVIC_ClearPendingIRQ(CSV_IRQn);
    00110     NVIC_EnableIRQ(CSV_IRQn);
    00111     NVIC_SetPriority(CSV_IRQn, PDL_IRQ_LEVEL_CSV);
    00112
    00113     return Ok;
    00114 }
    00115
    00121 void Csv_DisableFcsInt(void)
    00122 {
    00123     bFM0P_CRG_INT_ENR_FCSE = 0;
    00124
    00125     NVIC_ClearPendingIRQ(CSV_IRQn);
    00126     NVIC_DisableIRQ(CSV_IRQn);
    00127     NVIC_SetPriority(CSV_IRQn, PDL_DEFAULT_INTERRUPT_LEVEL);
    00128
    00129 }
    00130 #endif
    00131
    00139 void Csv_EnableMainCsv(void)
    00140 {
    00141     bFM0P_CRG_CSV_CTL_MCSVE = 1;
    00142 }
    00143
    00149 void Csv_DisableMainCsv(void)
    00150 {
    00151     bFM0P_CRG_CSV_CTL_MCSVE = 0;
    00152 }
    00153
    00161 void Csv_EnableSubCsv(void)
    00162 {
    00163     bFM0P_CRG_CSV_CTL_SCSVE = 1;
    00164 }
    00165
    00171 void Csv_DisableSubCsv(void)
    00172 {
    00173     bFM0P_CRG_CSV_CTL_SCSVE = 0;
    00174 }
    00175
    00185 uint8_t Csv_GetCsvFailCause(stc_csv_status_t* pstcCsvStatus)
    00186 {
    00187     uint8_t u8Status;
    00188
    00189     u8Status = FM0P_CRG->CSV_STR;
    00190
    00191     if((u8Status & 0x01) == 0x01)
    00192     {
    00193         pstcCsvStatus->bCsvMainClockStatus = TRUE;
    00194     }
    00195     else
    00196     {
    00197         pstcCsvStatus->bCsvMainClockStatus = FALSE;
    00198     }
    00199
    00200     if((u8Status & 0x02) == 0x02)
    00201     {
    00202         pstcCsvStatus->bCsvSubClockStatus = TRUE;
    00203     }
    00204     else
    00205     {
    00206         pstcCsvStatus->bCsvSubClockStatus = FALSE;
    00207     }
    00208
    00209     return Ok;;
    00210 }
    00211
    00217 void Csv_EnableFcs(void)
    00218 {
    00219     bFM0P_CRG_CSV_CTL_FCSDE = 1;
    00220 }
    00221
    00227 void Csv_DisableFcs(void)
    00228 {
    00229     bFM0P_CRG_CSV_CTL_FCSDE = 0;
    00230 }
    00231
    00237 void Csv_EnableFcsReset(void)
    00238 {
    00239     bFM0P_CRG_CSV_CTL_FCSRE = 1;
    00240 }
    00241
    00242
    00248 void Csv_DisableFcsReset(void)
    00249 {
    00250     bFM0P_CRG_CSV_CTL_FCSRE = 0;
    00251 }
    00252
    00258 void Csv_ClrFcsIntFlag(void)
    00259 {
    00260     bFM0P_CRG_INT_CLR_FCSC = 1;
    00261 }
    00262
    00272 uint8_t Csv_GetFcsIntFlag(void)
    00273 {
    00274     return bFM0P_CRG_INT_STR_FCSI;
    00275 }
    00276
    00290 en_result_t Csv_SetFcsCrDiv(en_fcs_cr_div_t enDiv)
    00291 {
    00292     if ((enDiv != FcsCrDiv256) &&
    00293         (enDiv != FcsCrDiv512) &&
    00294         (enDiv != FcsCrDiv1024))
    00295     {
    00296         return ErrorInvalidParameter;
    00297     }
    00298
    00299     FM0P_CRG->CSV_CTL &= 0x0fffu;
    00300     FM0P_CRG->CSV_CTL |= (enDiv<<12u);
    00301
    00302     return Ok;
    00303 }
    00304
    00305
    00314 void Csv_SetFcsDetectRange(uint16_t u16LowerVal, uint16_t u16UpperVal)
    00315 {
    00316     FM0P_CRG->FCSWL_CTL = u16LowerVal;
    00317     FM0P_CRG->FCSWH_CTL = u16UpperVal;
    00318 }
    00319
    00327 uint16_t Csv_GetFcsDetectCount(void)
    00328 {
    00329     return FM0P_CRG->FCSWD_CTL;
    00330 }
    00331
    00332
    00333 #endif
    00334
    00335 /*****************************************************************************/
    00336 /* END OF FILE */