S32 SDK
pcc_hal.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
3  * Copyright 2016 NXP
4  * All rights reserved.
5  *
6  * THIS SOFTWARE IS PROVIDED BY NXP "AS IS" AND ANY EXPRESSED OR
7  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
8  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
9  * IN NO EVENT SHALL NXP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
10  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
11  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
12  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
13  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
14  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
15  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
16  * THE POSSIBILITY OF SUCH DAMAGE.
17  */
18 
30 #include "pcc_hal.h"
31 #include <stddef.h>
32 
33 /*******************************************************************************
34  * Definitions
35  ******************************************************************************/
36 
37 
44 
45 /*******************************************************************************
46  * Code
47  ******************************************************************************/
48 
49 /*FUNCTION*********************************************************************
50  *
51  * Function Name : PCC_HAL_SetPeripheralClockConfig
52  * Description : This function sets the peripheral clock configuration
53  *
54  * Implements PCC_HAL_SetPeripheralClockConfig_Activity
55  *END*************************************************************************/
57  const pcc_config_t* const config)
58 {
59  uint32_t i, clkGate;
60  const peripheral_clock_config_t *peripheral_clock_config;
61 
62  if ((config != NULL) && (config->peripheralClocks != NULL))
63  {
64  for (i = 0U; i < config->count; i++) {
65 
66  peripheral_clock_config = &config->peripheralClocks[i];
67 
68  /* Disable the peripheral clock */
69  base->PCCn[clockNameMappings[peripheral_clock_config->clockName]] &= (uint32_t)(~(PCC_PCCn_CGC_MASK));
70 
71  /* Clock gate value */
72  clkGate = (peripheral_clock_config->clkGate == true) ? 1UL : 0UL;
73 
74  /* Configure the peripheral clock source, the fractional clock divider and the clock gate */
75  base->PCCn[clockNameMappings[peripheral_clock_config->clockName]] = PCC_PCCn_PCS(peripheral_clock_config->clkSrc) |
76  PCC_PCCn_FRAC(peripheral_clock_config->frac) |
77  PCC_PCCn_PCD(peripheral_clock_config->divider) |
78  PCC_PCCn_CGC(clkGate);
79 
80  }
81  }
82 }
83 
84 
85 
86 /*******************************************************************************
87  * EOF
88  ******************************************************************************/
PCC peripheral instance clock configuration. Implements peripheral_clock_config_t_Class.
Definition: pcc_hal.h:157
#define PCC_PCCn_CGC_MASK
Definition: S32K144.h:8203
#define PCC_PCCn_PCD(x)
Definition: S32K144.h:8194
peripheral_clock_source_t clkSrc
Definition: pcc_hal.h:168
#define PCC_PCCn_FRAC(x)
Definition: S32K144.h:8198
peripheral_clock_config_t * peripheralClocks
Definition: pcc_hal.h:179
uint32_t count
Definition: pcc_hal.h:178
#define PCC_CLOCK_NAME_MAPPINGS
PCC clock name mappings Mappings between clock names and peripheral clock control indexes...
peripheral_clock_divider_t divider
Definition: pcc_hal.h:170
const uint16_t clockNameMappings[]
Clock name mappings Constant array storing the mappings between clock names and peripheral clock cont...
Definition: pcc_hal.c:43
clock_names_t clockName
Definition: pcc_hal.h:166
peripheral_clock_frac_t frac
Definition: pcc_hal.h:169
void PCC_HAL_SetPeripheralClockConfig(PCC_Type *const base, const pcc_config_t *const config)
Set the peripheral clock configuration.
Definition: pcc_hal.c:56
#define PCC_PCCn_PCS(x)
Definition: S32K144.h:8202
#define PCC_PCCn_CGC(x)
Definition: S32K144.h:8206
__IO uint32_t PCCn[PCC_PCCn_COUNT]
Definition: S32K144.h:8130
PCC configuration. Implements pcc_config_t_Class.
Definition: pcc_hal.h:176