PDL for FM4  Version1.2
Peripheral Driverl Library for FM4
mft_adcmp.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 /******************************************************************************/
52 /******************************************************************************/
53 /* Include files */
54 /******************************************************************************/
55 #include "mft_adcmp.h"
56 
57 #if (defined(PDL_PERIPHERAL_MFT_ADCMP_ACTIVE))
58 
63 /******************************************************************************/
64 /* Global variable definitions (declared in header file with 'extern') */
65 /******************************************************************************/
66 
67 /******************************************************************************/
68 /* Local type definitions ('typedef') */
69 /******************************************************************************/
70 
71 /******************************************************************************/
72 /* Local function prototypes ('static') */
73 /******************************************************************************/
74 
75 /******************************************************************************/
76 /* Local variable definitions ('static') */
77 /******************************************************************************/
78 
79 /******************************************************************************/
80 /* Function implementation - global ('extern') and local ('static') */
81 /******************************************************************************/
82 
97  uint8_t u8Ch,
98  stc_mft_adcmp_config_t* pstcConfig)
99 {
100  stc_mft_adcmp_acfs10_field_t* stcACFS10 ;
101  stc_mft_adcmp_acfs32_field_t* stcACFS32 ;
102  stc_mft_adcmp_acfs54_field_t* stcACFS54 ;
103 
104  stc_mft_adcmp_acsc_field_t* stcACSCx ;
105  stc_mft_adcmp_acsd_field_t* stcACSDx ;
106 
107  if ((pstcMftAdcmp == NULL)||(pstcConfig == NULL)||(u8Ch > MFT_ADCMP_CH_MAX))
108  {
109  return ErrorInvalidParameter ;
110  }
111 
112  // Get actual address of register list of current channel
113  stcACFS10 = (stc_mft_adcmp_acfs10_field_t*)(&pstcMftAdcmp->ACFS10);
114  stcACFS32 = (stc_mft_adcmp_acfs32_field_t*)(&pstcMftAdcmp->ACFS32);
115  stcACFS54 = (stc_mft_adcmp_acfs54_field_t*)(&pstcMftAdcmp->ACFS54);
116 
117  stcACSCx = (stc_mft_adcmp_acsc_field_t*)((uint8_t*)(&pstcMftAdcmp->ACSC0) + 0x4*u8Ch);
118  stcACSDx = (stc_mft_adcmp_acsd_field_t*)((uint8_t*)(&pstcMftAdcmp->ACSD0) + 0x4*u8Ch);
119 
120  // Configure parameter
121  stcACSDx->DE = 0;
122  stcACSDx->PE = 0;
123  stcACSDx->UE = 0;
124  stcACSDx->ZE = 0;
125 
126  pstcMftAdcmp->ACSA &= 0x0000;
127 
128  // Select FRT channel : FRTx -> ADCMPx
129  switch(u8Ch)
130  {
131  case 0:
132  stcACFS10->FSA0 = pstcConfig->enFrt;
133  break;
134  case 1:
135  stcACFS10->FSA1 = pstcConfig->enFrt;
136  break;
137  case 2:
138  stcACFS32->FSA2 = pstcConfig->enFrt;
139  break;
140  case 3:
141  stcACFS32->FSA3 = pstcConfig->enFrt;
142  break;
143  case 4:
144  stcACFS54->FSA4 = pstcConfig->enFrt;
145  break;
146  case 5:
147  stcACFS54->FSA5 = pstcConfig->enFrt;
148  break;
149  default:
150  return ErrorInvalidParameter;
151  }
152 
153  // configure buffer function
154  if(pstcConfig->enBuf > AdcmpBufFrtZeroPeak)
155  {
156  return ErrorInvalidParameter;
157  }
158  stcACSCx->BUFE = pstcConfig->enBuf;
159 
160  // configure start trigger output channel number
161  if(pstcConfig->enTrigSel > AdcmpTrigAdc2Prio)
162  {
163  return ErrorInvalidParameter;
164  }
165  stcACSCx->ADSEL = pstcConfig->enTrigSel;
166 
167  // Select ADCMP running mode
168  if(pstcConfig->enMode > AdcmpOffsetMode)
169  {
170  return ErrorInvalidParameter;
171  }
172  stcACSDx->AMOD = pstcConfig->enMode;
173 
174  // select OCU OCCP register: OCCP(x)
175  if(pstcConfig->enOccpSel > AdcmpSelOccp1)
176  {
177  return ErrorInvalidParameter;
178  }
179  stcACSDx->OCUS = pstcConfig->enOccpSel;
180 
181  return Ok;
182 }
197  uint8_t u8Ch,
198  stc_mft_adcmp_func_t* pstcFunc)
199 {
200  stc_mft_adcmp_acsd_field_t* stcACSDx = { 0 };
201 
202  // Check for NULL pointer and channel parameter
203  if ((pstcMftAdcmp == NULL)||(pstcFunc == NULL)||(u8Ch > MFT_ADCMP_CH_MAX))
204  {
205  return ErrorInvalidParameter ;
206  }
207  // Get actual address of register list of current channel
208  stcACSDx = (stc_mft_adcmp_acsd_field_t*)((uint8_t*)(&pstcMftAdcmp->ACSD0) + 0x4*u8Ch);
209 
210  stcACSDx->PE = pstcFunc->bPeakEn;
211  stcACSDx->ZE = pstcFunc->bZeroEn;
212  stcACSDx->UE = pstcFunc->bUpEn;
213  stcACSDx->DE = pstcFunc->bDownEn;
214 
215  return Ok;
216 }
231  uint8_t u8Ch,
232  stc_mft_adcmp_func_t* pstcFunc)
233 {
234  stc_mft_adcmp_acsd_field_t* stcACSDx = { 0 };
235 
236  // Check for NULL pointer and channel parameter
237  if ((pstcMftAdcmp == NULL)||(pstcFunc == NULL)||(u8Ch > MFT_ADCMP_CH_MAX))
238  {
239  return ErrorInvalidParameter ;
240  }
241  // Get actual address of register list of current channel
242  stcACSDx = (stc_mft_adcmp_acsd_field_t*)((uint8_t*)(&pstcMftAdcmp->ACSD0) + 0x4*u8Ch);
243 
244  stcACSDx->PE = 0;
245  stcACSDx->UE = 0;
246  stcACSDx->ZE = 0;
247  stcACSDx->DE = 0;
248 
249  return Ok;
250 }
264 en_result_t Mft_Adcmp_WriteAcmp(volatile stc_mftn_adcmp_t *pstcMftAdcmp, uint8_t u8Ch,
265  uint16_t u16AcmpVal)
266 {
267  uint16_t* u16AdcmpAcpmReg = { 0 };
268 
269  // Check for NULL pointer and channel parameter
270  if ((pstcMftAdcmp == NULL)||(u8Ch > MFT_ADCMP_CH_MAX))
271  {
272  return ErrorInvalidParameter ;
273  }
274  u16AdcmpAcpmReg = (uint16_t*)((uint8_t*)(&pstcMftAdcmp->ACMP0) + 0x4*u8Ch);
275  *u16AdcmpAcpmReg = u16AcmpVal;
276 
277  return Ok;
278 }
290 uint16_t Mft_Adcmp_ReadAcmp(volatile stc_mftn_adcmp_t *pstcMftAdcmp, uint8_t u8Ch)
291 {
292  uint16_t* u16AdcmpAcpmReg ;
293 
294  // Check for NULL pointer and channel parameter
295  if ((pstcMftAdcmp == NULL)||(u8Ch > MFT_ADCMP_CH_MAX))
296  {
297  return ErrorInvalidParameter ;
298  }
299  u16AdcmpAcpmReg = (uint16_t*)((uint8_t*)(&pstcMftAdcmp->ACMP0) + 0x4*u8Ch);
300 
301  // return data value of ACMP register
302  return *u16AdcmpAcpmReg;
303 }
304 
321  uint8_t u8CoupleCh,
322  stc_mft_adcmp_fm3_config_t *pstcConfig)
323 {
324  stc_mft_adcmp_acsa_field_t* stcACSAx ;
325  stc_mft_adcmp_acsc_field_t* stcACSCx ;
326  stc_mft_adcmp_acfs10_field_t* stcACFS10 ;
327  stc_mft_adcmp_acfs32_field_t* stcACFS32;
328  stc_mft_adcmp_acfs54_field_t* stcACFS54 ;
329 
330  // Get actual address of register list of current channel
331  stcACSAx = (stc_mft_adcmp_acsa_field_t*)((uint16_t*)(&pstcMftAdcmp->ACSA));
332  stcACSCx = (stc_mft_adcmp_acsc_field_t*)((uint8_t*)(&pstcMftAdcmp->ACSC0) + 0x4*u8CoupleCh);
333  stcACFS10 = (stc_mft_adcmp_acfs10_field_t*)((uint16_t*)&pstcMftAdcmp->ACFS10);
334  stcACFS32 = (stc_mft_adcmp_acfs32_field_t*)((uint16_t*)&pstcMftAdcmp->ACFS32);
335  stcACFS54 = (stc_mft_adcmp_acfs54_field_t*)((uint16_t*)&pstcMftAdcmp->ACFS54);
336 
337  switch(u8CoupleCh)
338  {
339  case MFT_ADCMP_CH10:
340  stcACFS10->FSA0 = pstcConfig->enFrt;
341  stcACFS10->FSA1 = pstcConfig->enFrt;
342  break;
343  case MFT_ADCMP_CH32:
344  stcACFS32->FSA2 = pstcConfig->enFrt;
345  stcACFS32->FSA3 = pstcConfig->enFrt;
346  break;
347  case MFT_ADCMP_CH54:
348  stcACFS54->FSA4 = pstcConfig->enFrt;
349  stcACFS54->FSA5 = pstcConfig->enFrt;
350  break;
351  default:
352  return ErrorInvalidParameter;
353  }
354 
355  // configure buffer transfer type
356  if(pstcConfig->enBuf > AdcmpBufFrtZeroPeak)
357  {
358  return ErrorInvalidParameter;
359  }
360  stcACSCx->BUFE = pstcConfig->enBuf;
361 
362  // configure start trigger output channel number
363  if(pstcConfig->enTrigSel > AdcmpTrigAdc2Prio)
364  {
365  return ErrorInvalidParameter;
366  }
367  stcACSCx->ADSEL = pstcConfig->enTrigSel;
368 
369  // configure Adcmp Fm3 trig mode
370  switch(u8CoupleCh)
371  {
372  case MFT_ADCMP_CH10:
373  stcACSAx->CE10 = 0x00;
374  stcACSAx->SEL10 = pstcConfig->enMode;
375  break;
376  case MFT_ADCMP_CH32:
377  stcACSAx->CE32 = 0x00;
378  stcACSAx->SEL32 = pstcConfig->enMode;
379  break;
380  case MFT_ADCMP_CH54:
381  stcACSAx->CE54 = 0x00;
382  stcACSAx->SEL54 = pstcConfig->enMode;
383  break;
384  default:
385  return ErrorInvalidParameter;
386  }
387  return Ok;
388 }
402 en_result_t Mft_Adcmp_Fm3_EnableOperation(volatile stc_mftn_adcmp_t *pstcMftAdcmp, uint8_t u8CoupleCh)
403 {
404  stc_mft_adcmp_acsa_field_t* stcACSAx ;
405 
406  // Check for NULL pointer and channel parameter
407  if ((pstcMftAdcmp == NULL)||(u8CoupleCh > MFT_ADCMP_CPCH_MAX))
408  {
409  return ErrorInvalidParameter ;
410  }
411  // Get actual address of register list of current channel
412  stcACSAx = (stc_mft_adcmp_acsa_field_t*)(&pstcMftAdcmp->ACSA);
413  switch(u8CoupleCh)
414  {
415  case MFT_ADCMP_CH10:
416  stcACSAx->CE10 = 0x01;
417  break;
418  case MFT_ADCMP_CH32:
419  stcACSAx->CE32 = 0x01;
420  break;
421  case MFT_ADCMP_CH54:
422  stcACSAx->CE54 = 0x01;
423  break;
424  default:
425  return ErrorInvalidParameter;
426  }
427  return Ok;
428 }
442 en_result_t Mft_Adcmp_Fm3_DisableOperation(volatile stc_mftn_adcmp_t *pstcMftAdcmp, uint8_t u8CoupleCh)
443 {
444  stc_mft_adcmp_acsa_field_t* stcACSAx;
445 
446  // Check for NULL pointer and channel parameter
447  if ((pstcMftAdcmp == NULL)||(u8CoupleCh > MFT_ADCMP_CPCH_MAX))
448  {
449  return ErrorInvalidParameter ;
450  }
451  // Get actual address of register list of current channel
452  stcACSAx = (stc_mft_adcmp_acsa_field_t*)(&pstcMftAdcmp->ACSA);
453  switch(u8CoupleCh)
454  {
455  case MFT_ADCMP_CH10:
456  stcACSAx->CE10 = 0x00;
457  break;
458  case MFT_ADCMP_CH32:
459  stcACSAx->CE32 = 0x00;
460  break;
461  case MFT_ADCMP_CH54:
462  stcACSAx->CE54 = 0x00;
463  break;
464  default:
465  return ErrorInvalidParameter;
466  }
467  return Ok;
468 }
484 en_result_t Mft_Adcmp_Fm3_WriteAccp(volatile stc_mftn_adcmp_t *pstcMftAdcmp, uint8_t u8CoupleCh, uint16_t u16AccpVal)
485 {
486  uint16_t* u16AdcmpAcpmReg;
487 
488  // Check for NULL pointer and channel parameter
489  if ((pstcMftAdcmp == NULL)||(u8CoupleCh > MFT_ADCMP_CPCH_MAX))
490  {
491  return ErrorInvalidParameter ;
492  }
493  u16AdcmpAcpmReg = (uint16_t*)((uint8_t*)&pstcMftAdcmp->ACMP0 + 0x4*u8CoupleCh);
494  *u16AdcmpAcpmReg = u16AccpVal;
495 
496  return Ok;
497 }
511 uint16_t Mft_Adcmp_Fm3_ReadAccp(volatile stc_mftn_adcmp_t *pstcMftAdcmp, uint8_t u8CoupleCh)
512 {
513  uint16_t* u16AdcmpAcpmReg = { 0 };
514 
515  // Check for NULL pointer and channel parameter
516  if ((pstcMftAdcmp == NULL)||(u8CoupleCh > MFT_ADCMP_CPCH_MAX))
517  {
518  return ErrorInvalidParameter ;
519  }
520  u16AdcmpAcpmReg = (uint16_t*)((uint8_t*)&pstcMftAdcmp->ACMP0 + 0x4*u8CoupleCh);
521 
522  // return data value of ACMP register
523  return *u16AdcmpAcpmReg;
524 }
540 en_result_t Mft_Adcmp_Fm3_WriteAccpdn(volatile stc_mftn_adcmp_t *pstcMftAdcmp, uint8_t u8CoupleCh, uint16_t u16AccpdnVal)
541 {
542  uint16_t* u16AdcmpAcpmReg;
543 
544  // Check for NULL pointer and channel parameter
545  if ((pstcMftAdcmp == NULL)||(u8CoupleCh > MFT_ADCMP_CPCH_MAX))
546  {
547  return ErrorInvalidParameter ;
548  }
549  u16AdcmpAcpmReg = (uint16_t*)((uint8_t*)&pstcMftAdcmp->ACMP1 + 0x4*u8CoupleCh);
550  *u16AdcmpAcpmReg = u16AccpdnVal;
551 
552  return Ok;
553 }
567 uint16_t Mft_Adcmp_Fm3_ReadAccpdn(volatile stc_mftn_adcmp_t *pstcMftAdcmp, uint8_t u8CoupleCh)
568 {
569  uint16_t* u16AdcmpAcpmReg = { 0 };
570 
571  // Check for NULL pointer and channel parameter
572  if ((pstcMftAdcmp == NULL)||(u8CoupleCh > MFT_ADCMP_CPCH_MAX))
573  {
574  return ErrorInvalidParameter ;
575  }
576  u16AdcmpAcpmReg = ((uint16_t*)&pstcMftAdcmp->ACMP1 + 0x4*u8CoupleCh);
577 
578  // return data value of ACMP register
579  return *u16AdcmpAcpmReg;
580 }
581 
583 
584 #endif
585 
586 /******************************************************************************/
587 /* EOF (not truncated) */
588 /******************************************************************************/
589 
590