RTEMS: bsps/arm/atsam/include/libchip/include/afec.h File Reference

| RTEMS 5.4-rc2

Loading...
Searching...
No Matches
Macros | Functions
afec.h File Reference
`#include <assert.h>`
`#include <stdint.h>`

Go to the source code of this file.

## Macros
#define | AFEC_MR_SETTLING_Pos 20
#define | AFEC_MR_SETTLING_Msk (0x3u << AFEC_MR_SETTLING_Pos)
| (AFEC_MR) Trigger Selection
#define | AFEC_MR_SETTLING_AST3 (0x0u << 20)
| (AFEC_MR) ADC_SETTLING_AST3 3 periods of AFEClock
#define | AFEC_MR_SETTLING_AST5 (0x1u << 20)
| (AFEC_MR) ADC_SETTLING_AST5 5 periods of AFEClock
#define | AFEC_MR_SETTLING_AST9 (0x2u << 20)
| (AFEC_MR) ADC_SETTLING_AST9 9 periods of AFEClock
#define | AFEC_MR_SETTLING_AST17 (0x3u << 20)
| (AFEC_MR) ADC_SETTLING_AST17 17 periods of AFEClock
#define | AFEC_EMR_STM_Pos 25
#define | AFEC_EMR_STM_Msk (0x1u << AFEC_EMR_STM_Pos)
| (AFEC_EMR) Single Trigger Mode
#define | AFEC_EMR_STM_MULTI_TRIG (0x0u << 25)
| (AFEC_EMR) Single Trigger Mode: Multiple triggers are required to get an averaged result.
#define | AFEC_EMR_STM_SINGLE_TRIG (0x1u << 25)
| (AFEC_EMR) Single Trigger Mode: Only a Single Trigger is required to get an averaged value.
#define | AFEC_EMR_TAG_Pos 24
#define | AFEC_EMR_TAG_Msk (0x1u << AFEC_EMR_TAG_Pos)
| (AFEC_EMR) TAG of the AFEC_LDCR Register
#define | AFEC_EMR_TAG_CHNB_ZERO (0x0u << 24)
| (AFEC_EMR) TAG of the AFEC_LDCR Register: Sets CHNB to zero in AFEC_LDCR.
#define | AFEC_EMR_TAG_APPENDS (0x1u << 24)
| (AFEC_EMR) TAG of the AFEC_LDCR Register: Appends the channel number to the conversion result in AFEC_LDCR register.
#define | AFEC_EMR_CMPALL_Pos 9
#define | AFEC_EMR_CMPALL_Msk (0x1u << AFEC_EMR_TAG_Pos)
| (AFEC_EMR) Compare All Channels
#define | AFEC_EMR_CMPALL_ONE_CHANNEL_COMP (0x0u << 9)
| (AFEC_EMR) Compare All Channels: Only channel indicated in CMPSEL field is compared.
#define | AFEC_EMR_CMPALL_ALL_CHANNELS_COMP (0x1u << 9)
| (AFEC_EMR) Compare All Channels: All channels are compared.
#define | AFEC_ACR_PGA0_ON (0x1u << 2)
#define | AFEC_ACR_PGA1_ON (0x1u << 3)
#define | AFEC_GetModeReg(pAFEC) ((pAFEC)->AFEC_MR)
#define | AFEC_SetModeReg(pAFEC, mode) ((pAFEC)->AFEC_MR = mode)
#define | AFEC_GetExtModeReg(pAFEC) ((pAFEC)->AFEC_EMR)
#define | AFEC_SetExtModeReg(pAFEC, mode) ((pAFEC)->AFEC_EMR = mode)
#define | AFEC_StartConversion(pAFEC) ((pAFEC)->AFEC_CR = AFEC_CR_START)
#define | AFEC_EnableChannel(pAFEC, dwChannel)
#define | AFEC_DisableChannel(pAFEC, dwChannel)
#define | AFEC_EnableIt(pAFEC, dwMode)
#define | AFEC_DisableIt(pAFEC, dwMode)
#define | AFEC_SetChannelGain(pAFEC, dwMode)
#define | AFEC_EnableDataReadyIt(pAFEC) ((pAFEC)->AFEC_IER = AFEC_IER_DRDY)
#define | AFEC_GetStatus(pAFEC) ((pAFEC)->AFEC_ISR)
#define | AFEC_GetCompareMode(pAFEC) (((pAFEC)->AFEC_EMR)& (AFEC_EMR_CMPMODE_Msk))
#define | AFEC_GetChannelStatus(pAFEC) ((pAFEC)->AFEC_CHSR)
#define | AFEC_GetInterruptMaskStatus(pAFEC) ((pAFEC)->AFEC_IMR)
#define | AFEC_GetLastConvertedData(pAFEC) ((pAFEC)->AFEC_LCDR)

## Functions
void | AFEC_Initialize (Afec *pAFEC, uint32_t dwId)
| Initialize the AFE controller.
uint32_t | AFEC_SetClock (Afec *pAFEC, uint32_t dwPres, uint32_t dwMck)
| Set AFE clock.
void | AFEC_SetTiming (Afec *pAFEC, uint32_t dwStartup, uint32_t dwTracking, uint32_t dwSettling)
| Set AFE timing.
void | AFEC_SetTrigger (Afec *pAFEC, uint32_t dwTrgSel)
| Set AFE trigger.
void | AFEC_SetAnalogChange (Afec *pAFE, uint8_t bEnDis)
| Set analog change. IF enabled, it allows different analog settings for each channel, otherwise, DIFF0, GAIN0 and OFF0 are used for all channels.
void | AFEC_SetSleepMode (Afec *pAFEC, uint8_t bEnDis)
| Enable/Disable sleep mode.
void | AFEC_SetFastWakeup (Afec *pAFEC, uint8_t bEnDis)
| Enable/Disable fast wake up.
void | AFEC_SetSequenceMode (Afec *pAFEC, uint8_t bEnDis)
| Enable/Disable sequence mode.
void | AFEC_SetSequence (Afec *pAFEC, uint32_t dwSEQ1, uint32_t dwSEQ2)
| Set channel sequence.
void | AFEC_SetSequenceByList (Afec *pAFEC, uint8_t ucChList[], uint8_t ucNumCh)
| Set channel sequence by given channel list.
void | AFEC_SetTagEnable (Afec *pAFEC, uint8_t bEnDis)
| Set "TAG" mode, show channel number in last data or not.
void | AFEC_SetCompareChannel (Afec *pAFEC, uint32_t dwChannel)
| Set compare channel.
void | AFEC_SetCompareMode (Afec *pAFEC, uint32_t dwMode)
| Set compare mode.
void | AFEC_SetComparisonWindow (Afec *pAFEC, uint32_t dwHi_Lo)
| Set comparison window.
uint8_t | AFEC_CheckConfiguration (Afec *pAFEC, uint32_t dwMcK)
uint32_t | AFEC_GetConvertedData (Afec *pAFEC, uint32_t dwChannel)
| Return the Channel Converted Data.
void | AFEC_SetStartupTime (Afec *pAFEC, uint32_t dwUs)
void | AFEC_SetTrackingTime (Afec *pAFEC, uint32_t dwNs)
void | AFEC_SetAnalogOffset (Afec *pAFE, uint32_t dwChannel, uint32_t aoffset)
| Set analog offset to be used for channel CSEL.
void | AFEC_SetAnalogControl (Afec *pAFE, uint32_t control)
| Set analog offset to be used for channel CSEL.

## Detailed Description

# Purpose

Interface for configuration the Analog-to-Digital Converter (AFEC) peripheral.

# Usage

1. Configurate the pins for AFEC.
2. Initialize the AFEC with AFEC_Initialize().
3. Set AFEC clock and timing with AFEC_SetClock() and AFEC_SetTiming().
4. Select the active channel using AFEC_EnableChannel().
5. Start the conversion with AFEC_StartConversion().
6. Wait the end of the conversion by polling status with AFEC_GetStatus().
7. Finally, get the converted data using AFEC_GetConvertedData() or AFEC_GetLastConvertedData().

## Macro Definition Documentation

## ◆ AFEC_DisableChannel

#define AFEC_DisableChannel | ( |  | pAFEC,
|  |  | dwChannel
| ) |  |

Value:
{\
(pAFEC)->AFEC_CHDR = (1 << (dwChannel));\
}

## ◆ AFEC_DisableIt

#define AFEC_DisableIt | ( |  | pAFEC,
|  |  | dwMode
| ) |  |

Value:
{\
(pAFEC)->AFEC_IDR = (dwMode);\
}

## ◆ AFEC_EnableChannel

#define AFEC_EnableChannel | ( |  | pAFEC,
|  |  | dwChannel
| ) |  |

Value:
{\
(pAFEC)->AFEC_CHER = (1 << (dwChannel));\
}

## ◆ AFEC_EnableIt

#define AFEC_EnableIt | ( |  | pAFEC,
|  |  | dwMode
| ) |  |

Value:
{\
(pAFEC)->AFEC_IER = (dwMode);\
}

## ◆ AFEC_SetChannelGain

#define AFEC_SetChannelGain | ( |  | pAFEC,
|  |  | dwMode
| ) |  |

Value:
{\
(pAFEC)->AFEC_CGR = dwMode;\
}

## Function Documentation

## ◆ AFEC_GetConvertedData()

uint32_t AFEC_GetConvertedData | ( | Afec * | pAFE,
|  | uint32_t | dwChannel
| ) |  |

Return the Channel Converted Data.

Parameters

  pAFE | Pointer to an AFE instance.
  dwChannel | channel to get converted value

## ◆ AFEC_Initialize()

void AFEC_Initialize | ( | Afec * | pAFE,
|  | uint32_t | dwID
| ) |  |

Initialize the AFE controller.

Parameters

  pAFE | Pointer to an AFE instance.
  dwID | AFE Index

## ◆ AFEC_SetAnalogChange()

void AFEC_SetAnalogChange | ( | Afec * | pAFE,
|  | uint8_t | bEnDis
| ) |  |

Set analog change. IF enabled, it allows different analog settings for each channel, otherwise, DIFF0, GAIN0 and OFF0 are used for all channels.

Parameters

  pAFE | Pointer to an AFE instance.
  bEnDis | Enable/Disable.

## ◆ AFEC_SetAnalogControl()

void AFEC_SetAnalogControl | ( | Afec * | pAFE,
|  | uint32_t | control
| ) |  |

Set analog offset to be used for channel CSEL.

Parameters

  afec | Base address of the AFEC.
  control | Analog control value.

## ◆ AFEC_SetAnalogOffset()

void AFEC_SetAnalogOffset | ( | Afec * | pAFE,
|  | uint32_t | dwChannel,
|  | uint32_t | aoffset
| ) |  |

Set analog offset to be used for channel CSEL.

Parameters

  afec | Base address of the AFEC.
  dwChannel | AFEC channel number.
  aoffset | Analog offset value.

## ◆ AFEC_SetClock()

uint32_t AFEC_SetClock | ( | Afec * | pAFE,
|  | uint32_t | dwClk,
|  | uint32_t | dwMck
| ) |  |

Set AFE clock.

Parameters

  pAFE | Pointer to an AFE instance.
  dwPres | prescale value
  dwMck | Board MCK (Hz)

Returns
  AFE clock

## ◆ AFEC_SetCompareChannel()

void AFEC_SetCompareChannel | ( | Afec * | pAFE,
|  | uint32_t | dwChannel
| ) |  |

Set compare channel.

Parameters

  pAFE | Pointer to an AFE instance.
  dwChannel | channel number to be set,16 for all channels

## ◆ AFEC_SetCompareMode()

void AFEC_SetCompareMode | ( | Afec * | pAFE,
|  | uint32_t | dwMode
| ) |  |

Set compare mode.

Parameters

  pAFE | Pointer to an AFE instance.
  dwMode | compare mode

## ◆ AFEC_SetComparisonWindow()

void AFEC_SetComparisonWindow | ( | Afec * | pAFE,
|  | uint32_t | dwHi_Lo
| ) |  |

Set comparison window.

Parameters

  pAFE | Pointer to an AFE instance.
  dwHi_Lo | Comparison Window

## ◆ AFEC_SetFastWakeup()

void AFEC_SetFastWakeup | ( | Afec * | pAFE,
|  | uint8_t | bEnDis
| ) |  |

Enable/Disable fast wake up.

Parameters

  pAFE | Pointer to an AFE instance.
  bEnDis | Enable/Disable fast wake up in sleep mode.

## ◆ AFEC_SetSequence()

void AFEC_SetSequence | ( | Afec * | pAFE,
|  | uint32_t | dwSEQ1,
|  | uint32_t | dwSEQ2
| ) |  |

Set channel sequence.

Parameters

  pAFE | Pointer to an AFE instance.
  dwSEQ1 | Sequence 1 ~ 8 channel number.
  dwSEQ2 | Sequence 9 ~ 16 channel number.

## ◆ AFEC_SetSequenceByList()

void AFEC_SetSequenceByList | ( | Afec * | pAFE,
|  | uint8_t | ucChList[],
|  | uint8_t | ucNumCh
| ) |  |

Set channel sequence by given channel list.

Parameters

  pAFE | Pointer to an AFE instance.
  ucChList | Channel list.
  ucNumCh | Number of channels in list.

## ◆ AFEC_SetSequenceMode()

void AFEC_SetSequenceMode | ( | Afec * | pAFE,
|  | uint8_t | bEnDis
| ) |  |

Enable/Disable sequence mode.

Parameters

  pAFE | Pointer to an AFE instance.
  bEnDis | Enable/Disable sequence mode.

## ◆ AFEC_SetSleepMode()

void AFEC_SetSleepMode | ( | Afec * | pAFE,
|  | uint8_t | bEnDis
| ) |  |

Enable/Disable sleep mode.

Parameters

  pAFE | Pointer to an AFE instance.
  bEnDis | Enable/Disable sleep mode.

## ◆ AFEC_SetStartupTime()

void AFEC_SetStartupTime | ( | Afec * | pAFE,
|  | uint32_t | dwUs
| ) |  |

Sets the AFE startup time.

Parameters

  pAFE | Pointer to an AFE instance.
  dwUs | Startup time in uS.

## ◆ AFEC_SetTagEnable()

void AFEC_SetTagEnable | ( | Afec * | pAFE,
|  | uint8_t | bEnDis
| ) |  |

Set "TAG" mode, show channel number in last data or not.

Parameters

  pAFE | Pointer to an AFE instance.
  bEnDis | Enable/Disable TAG value.

## ◆ AFEC_SetTiming()

void AFEC_SetTiming | ( | Afec * | pAFE,
|  | uint32_t | dwStartup,
|  | uint32_t | dwTracking,
|  | uint32_t | dwSettling
| ) |  |

Set AFE timing.

Parameters

  pAFE | Pointer to an AFE instance.
  dwStartup | startup value
  dwTracking | tracking value
  dwSettling | settling value

## ◆ AFEC_SetTrackingTime()

void AFEC_SetTrackingTime | ( | Afec * | pAFE,
|  | uint32_t | dwNs
| ) |  |

Set AFE tracking time

Parameters

  pAFE | Pointer to an AFE instance.
  dwNs | Tracking time in nS.

## ◆ AFEC_SetTrigger()

void AFEC_SetTrigger | ( | Afec * | pAFE,
|  | uint32_t | dwTrgSel
| ) |  |

Set AFE trigger.

Parameters

  pAFE | Pointer to an AFE instance.
  dwTrgSel | Trigger selection