PDL for FM4  Version1.2
Peripheral Driverl Library for FM4
wc.c
Go to the documentation of this file.
1 /*******************************************************************************
2 * Copyright (C) 2013 Spansion LLC. All Rights Reserved.
3 *
4 * This software is owned and published by:
5 * Spansion LLC, 915 DeGuigne Dr. Sunnyvale, CA 94088-3453 ("Spansion").
6 *
7 * BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
8 * BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
9 *
10 * This software contains source code for use with Spansion
11 * components. This software is licensed by Spansion to be adapted only
12 * for use in systems utilizing Spansion components. Spansion shall not be
13 * responsible for misuse or illegal use of this software for devices not
14 * supported herein. Spansion is providing this software "AS IS" and will
15 * not be responsible for issues arising from incorrect user implementation
16 * of the software.
17 *
18 * SPANSION MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
19 * REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
20 * ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
21 * WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
22 * WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
23 * WARRANTY OF NONINFRINGEMENT.
24 * SPANSION SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
25 * NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
26 * LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
27 * LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
28 * INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
29 * INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
30 * SAVINGS OR PROFITS,
31 * EVEN IF SPANSION HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
32 * YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
33 * INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
34 * FROM, THE SOFTWARE.
35 *
36 * This software may be replicated in part or whole for the licensed use,
37 * with the restriction that this Disclaimer and Copyright notice must be
38 * included with each copy of this software, whether used in part or whole,
39 * at all times.
40 */
41 /******************************************************************************/
53 /******************************************************************************/
54 /* Include files */
55 /******************************************************************************/
56 #include "wc.h"
57 
58 #if (defined(PDL_PERIPHERAL_WC_ACTIVE))
59 
65 
66 /******************************************************************************/
67 /* Local pre-processor symbols/macros ('#define') */
68 /******************************************************************************/
69 #define WC_INSTANCE_COUNT (uint32_t)(sizeof(m_astcWcInstanceDataLut) / sizeof(m_astcWcInstanceDataLut[0]))
70 
71 /******************************************************************************/
72 /* Global variable definitions (declared in header file with 'extern') */
73 /******************************************************************************/
74 
77 {
78  #if (PDL_PERIPHERAL_ENABLE_WC0 == PDL_ON)
79  {
80  &WC0, // pstcInstance
81  NULL // stcInternData (not initialized yet)
82  },
83  #endif
84 };
85 
86 #if (PDL_INTERRUPT_ENABLE_WC0 == PDL_ON)
87 /******************************************************************************/
88 /* Local Functions */
89 /******************************************************************************/
97 static void Wc_InitNvic(volatile stc_wcn_t* pstcWc)
98 {
99  if (pstcWc == (stc_wcn_t*)(&WC0))
100  {
101  NVIC_ClearPendingIRQ(WC_IRQn);
102  NVIC_EnableIRQ(WC_IRQn);
103  NVIC_SetPriority(WC_IRQn, PDL_IRQ_LEVEL_CLK_WC0);
104  }
105 
106 }
107 
115 static void Wc_DeInitNvic(volatile stc_wcn_t* pstcWc)
116 {
117  if (pstcWc == (stc_wcn_t*)(&WC0))
118  {
119  NVIC_ClearPendingIRQ(WC_IRQn);
120  NVIC_DisableIRQ(WC_IRQn);
121  NVIC_SetPriority(WC_IRQn, PDL_IRQ_LEVEL_CLK_WC0);
122  }
123 }
137 void Wc_IrqHandler( volatile stc_wcn_t* pstcWc,
138  stc_wc_intern_data_t* pstcWcInternData)
139 {
140  if (PdlSet == Wc_GetIntFlag(pstcWc))
141  {
142  Wc_ClearIntFlag(pstcWc);
143  if (pstcWcInternData->pfnIntCallback != NULL)
144  {
145  pstcWcInternData->pfnIntCallback();
146  }
147  }
148 }
149 #endif
150 
161 {
162  uint32_t u32Instance;
163 
164  for (u32Instance = 0; u32Instance < WC_INSTANCE_COUNT; u32Instance++)
165  {
166  if (pstcWc == m_astcWcInstanceDataLut[u32Instance].pstcInstance)
167  {
168  return &m_astcWcInstanceDataLut[u32Instance].stcInternData;
169  }
170  }
171 
172  return NULL;
173 }
174 
189 en_result_t Wc_Pres_SelClk(volatile stc_wcn_t* pstcWc, stc_wc_pres_clk_t* pstcWcPresClk)
190 {
191  // Check for NULL pointers
192  if (NULL == pstcWc)
193  {
194  return ErrorInvalidParameter;
195  }
196  pstcWc->CLK_SEL_f.SEL_IN = pstcWcPresClk->enInputClk;
197  pstcWc->CLK_SEL_f.SEL_OUT = pstcWcPresClk->enOutputClk;
198  return Ok;
199 }
200 
215 {
216  // Check for NULL pointers
217  if (NULL == pstcWc)
218  {
219  return ErrorInvalidParameter;
220  }
221  pstcWc->CLK_EN_f.CLK_EN = 1;
222  return Ok;
223 }
224 
239 {
240  // Check for NULL pointers
241  if (NULL == pstcWc)
242  {
243  return ErrorInvalidParameter;
244  }
245  pstcWc->CLK_EN_f.CLK_EN = 0;
246  return Ok;
247 }
248 
262 {
263  return ((en_stat_flag_t)(pstcWc->CLK_EN_f.CLK_EN_R));
264 }
265 
280 en_result_t Wc_Init(volatile stc_wcn_t* pstcWc, stc_wc_config_t* pstcWcConfig)
281 {
282  // Pointer to internal data
283  stc_wc_intern_data_t* pstcWcInternData ;
284  // Check for NULL pointers
285  if ((NULL == pstcWc) || (NULL == pstcWcConfig))
286  {
287  return ErrorInvalidParameter;
288  }
289 
290  // Get pointer to internal data structure ...
291  pstcWcInternData = WcGetInternDataPtr( pstcWc );
292 
293  if(pstcWcInternData == NULL)
294  {
295  return ErrorInvalidParameter ;
296  }
297 
298  pstcWc->WCCR_f.CS0 = pstcWcConfig->enCntClk;
299  pstcWc->WCCR_f.CS1 = ((pstcWcConfig->enCntClk)>>1);
300  return Ok;
301 }
302 
303 
318 {
319  // Check for NULL pointers
320  if (NULL == pstcWc)
321  {
322  return ErrorInvalidParameter;
323  }
324  pstcWc->WCCR_f.WCEN = 1;
325  return Ok;
326 }
327 
342 {
343  // Check for NULL pointers
344  if (NULL == pstcWc)
345  {
346  return ErrorInvalidParameter;
347  }
348  pstcWc->WCCR_f.WCEN = 0;
349  return Ok;
350 }
351 
352 #if (PDL_INTERRUPT_ENABLE_WC0 == PDL_ON)
353 
367 en_result_t Wc_EnableInt(volatile stc_wcn_t* pstcWc, func_ptr_t pfnIntCallback)
368 {
369  stc_wc_intern_data_t* pstcWcInternData;
370  // check for non-null pointers
371  if (NULL == pstcWc)
372  {
373  return ErrorInvalidParameter;
374  }
375  pstcWc->WCCR_f.WCIE = 1;
376  // Get ptr to internal data struct ...
377  pstcWcInternData = WcGetInternDataPtr((stc_wcn_t*) pstcWc);
378  // ... and check
379  if (NULL == pstcWcInternData)
380  {
381  return ErrorInvalidParameter;
382  }
383  pstcWcInternData->pfnIntCallback = pfnIntCallback;
384  Wc_InitNvic(pstcWc);
385  return Ok;
386 }
387 
402 {
403  // check for non-null pointers
404  if (NULL == pstcWc)
405  {
406  return ErrorInvalidParameter;
407  }
408  pstcWc->WCCR_f.WCIE = 0;
409  Wc_DeInitNvic(pstcWc);
410  return Ok;
411 }
412 #endif
413 
427 en_result_t Wc_WriteReloadVal(volatile stc_wcn_t* pstcWc, uint8_t u8Val)
428 {
429  // check for non-null pointers
430  if (NULL == pstcWc)
431  {
432  return ErrorInvalidParameter;
433  }
434  pstcWc->WCRL = u8Val;
435  return Ok;
436 }
437 
451 uint8_t Wc_ReadCurCnt(volatile stc_wcn_t* pstcWc)
452 {
453  // check for non-null pointers
454  if (NULL == pstcWc)
455  {
456  return 0xFF;
457  }
458  return (pstcWc->WCRD);
459 }
460 
475 {
476  // check for non-null pointers
477  if (NULL == pstcWc)
478  {
479  return ErrorInvalidParameter;
480  }
481  pstcWc->WCCR_f.WCIF = 0;
482  return Ok;
483 }
484 
498 {
499  return ((en_int_flag_t)(pstcWc->WCCR_f.WCIF));
500 }
501 
515 {
516  return ((en_stat_flag_t)(pstcWc->WCCR_f.WCOP));
517 }
518 
520 
521 #endif // #if (defined(PDL_PERIPHERAL_WC_ACTIVE))
522 
523 /******************************************************************************/
524 /* EOF (not truncated) */
525 /******************************************************************************/
526