![]() |
PDL for FM0+
Version1.0
Peripheral Driverl Library for FM0+
|
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 /******************************************************************************/ 00055 /******************************************************************************/ 00056 /* Include files */ 00057 /******************************************************************************/ 00058 #include "exint.h" 00059 00065 00066 /******************************************************************************/ 00067 /* Local pre-processor symbols/macros ('#define') */ 00068 /******************************************************************************/ 00069 00070 /******************************************************************************/ 00071 /* Global variable definitions (declared in header file with 'extern') */ 00072 /******************************************************************************/ 00073 #if (defined(PDL_PERIPHERAL_NMI_ACTIVE)) 00074 func_ptr_t pfnNMICallback; 00075 #endif 00076 00077 #if (defined(PDL_PERIPHERAL_EXINT_ACTIVE)) 00078 00079 func_ptr_t apfnExintCallback[EXINT_CHANNEL_NUM] = 00080 { 00081 NULL, 00082 NULL, 00083 NULL, 00084 NULL, 00085 NULL, 00086 NULL, 00087 NULL, 00088 NULL, 00089 }; 00090 00091 /******************************************************************************/ 00092 /* Local type definitions ('typedef') */ 00093 /******************************************************************************/ 00094 00095 /******************************************************************************/ 00096 /* Local function prototypes ('static') */ 00097 /******************************************************************************/ 00098 00099 /******************************************************************************/ 00100 /* Local variable definitions ('static') */ 00101 /******************************************************************************/ 00102 00103 /******************************************************************************/ 00104 /* Function implementation - global ('extern') and local ('static') */ 00105 /******************************************************************************/ 00106 00113 void Exint_IrqHandler(uint8_t u8Channel) 00114 { 00115 FM0P_EXTI->EICL &= (0xFFFFFFFFu ^ (1u << u8Channel)); 00116 00117 if (0 != apfnExintCallback[u8Channel]) 00118 { 00119 apfnExintCallback[u8Channel](); 00120 } 00121 00122 } // Exint_IrqHandler 00123 00133 en_result_t Exint_Enable(uint8_t u8Ch, func_ptr_t pfnIntCb) 00134 { 00135 if((u8Ch > EXINT_MAX_CH_INDEX) || (pfnIntCb == NULL)) 00136 { 00137 return ErrorInvalidParameter; 00138 } 00139 00140 FM0P_EXTI->EICL &= ~(1ul << u8Ch); /* Clear interrupt flag */ 00141 FM0P_EXTI->ENIR |= (1ul<< u8Ch); /* Enable interrupt */ 00142 00143 apfnExintCallback[u8Ch] = pfnIntCb; 00144 00145 if(u8Ch <= 7u) 00146 { 00147 NVIC_ClearPendingIRQ(EXINT0_7_IRQn); 00148 NVIC_EnableIRQ(EXINT0_7_IRQn); 00149 NVIC_SetPriority(EXINT0_7_IRQn, PDL_IRQ_LEVEL_EXINT0_7); 00150 } 00151 else 00152 { 00153 NVIC_ClearPendingIRQ(EXINT8_31_IRQn); 00154 NVIC_EnableIRQ(EXINT8_31_IRQn); 00155 NVIC_SetPriority(EXINT0_7_IRQn, PDL_IRQ_LEVEL_EXINT0_7); 00156 } 00157 00158 return Ok; 00159 } 00160 00172 en_result_t Exint_Disable(uint8_t u8Ch) 00173 { 00174 if(u8Ch > EXINT_MAX_CH_INDEX) 00175 { 00176 return ErrorInvalidParameter; 00177 } 00178 00179 FM0P_EXTI->ENIR &= ~(1ul<<u8Ch); 00180 00181 apfnExintCallback[u8Ch] = NULL; 00182 00183 if((FM0P_EXTI->ENIR & 0x000000FFu) == 0x00000000u) 00184 { 00185 NVIC_ClearPendingIRQ(EXINT0_7_IRQn); 00186 NVIC_DisableIRQ(EXINT0_7_IRQn); 00187 NVIC_SetPriority(EXINT0_7_IRQn, PDL_DEFAULT_INTERRUPT_LEVEL); 00188 } 00189 00190 if((FM0P_EXTI->ENIR & 0xFFFFFF00u) == 0x00000000u) 00191 { 00192 NVIC_ClearPendingIRQ(EXINT8_31_IRQn); 00193 NVIC_DisableIRQ(EXINT8_31_IRQn); 00194 NVIC_SetPriority(EXINT8_31_IRQn, PDL_DEFAULT_INTERRUPT_LEVEL); 00195 } 00196 00197 return Ok; 00198 } 00199 00217 en_result_t Exint_SetIntDetectMode(uint8_t u8Ch, en_exint_level_t enLevel) 00218 { 00219 if(u8Ch > EXINT_MAX_CH_INDEX) 00220 { 00221 return ErrorInvalidParameter; 00222 } 00223 00224 switch (enLevel) 00225 { 00226 case ExIntLowLevel: 00227 case ExIntHighLevel: 00228 case ExIntRisingEdge: 00229 case ExIntFallingEdge: 00230 FM0P_EXTI->ELVR &= ~(3ul<<(2*u8Ch)); 00231 FM0P_EXTI->ELVR |= ((uint8_t)enLevel<<(2*u8Ch)); 00232 break; 00233 default: 00234 return ErrorInvalidParameter; 00235 } 00236 00237 return Ok; 00238 } 00239 00253 en_exint_level_t Exint_GetIntDetectMode(uint8_t u8Ch) 00254 { 00255 uint8_t u8Level; 00256 u8Level = (FM0P_EXTI->ELVR & (3ul<<(2*u8Ch))) >> (2*u8Ch); 00257 return (en_exint_level_t)u8Level; 00258 } 00259 00260 #endif // #if (defined(PDL_PERIPHERAL_EXINT_ACTIVE)) 00261 00262 #if (defined(PDL_PERIPHERAL_NMI_ACTIVE)) 00263 00271 void Nmi_IrqHandler(void) 00272 { 00273 if ((FM0P_EXTI->NMIRR & 0x01) == 0x01) 00274 { 00275 FM0P_EXTI->NMICL = 0; 00276 00277 if (0 != pfnNMICallback) 00278 { 00279 pfnNMICallback(); 00280 } 00281 } 00282 } 00283 00284 00296 en_result_t Exint_Nmi_SetIntCallback(func_ptr_t pfnIntCb) 00297 { 00298 if(pfnIntCb == NULL) 00299 { 00300 return ErrorInvalidParameter; 00301 } 00302 pfnNMICallback = pfnIntCb; 00303 return Ok; 00304 } 00305 00307 00308 #endif 00309 00310 /******************************************************************************/ 00311 /* EOF (not truncated) */ 00312 /******************************************************************************/ 00313 00314