2010-02-19 18:19:00 +00:00
|
|
|
/*
|
2012-12-11 10:27:10 +00:00
|
|
|
* Licensed under ST Liberty SW License Agreement V2, (the "License");
|
|
|
|
* You may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at:
|
|
|
|
*
|
|
|
|
* http://www.st.com/software_license_agreement_liberty_v2
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2010-02-19 18:19:00 +00:00
|
|
|
|
|
|
|
/**
|
2012-12-11 10:27:10 +00:00
|
|
|
* @file SPC563Mxx/hal_lld.c
|
|
|
|
* @brief SPC563Mxx HAL subsystem low level driver source.
|
2010-02-19 18:19:00 +00:00
|
|
|
*
|
2010-10-26 17:39:29 +00:00
|
|
|
* @addtogroup HAL
|
2010-02-19 18:19:00 +00:00
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ch.h"
|
|
|
|
#include "hal.h"
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver exported variables. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver local variables. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver local functions. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver interrupt handlers. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver exported functions. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Low level HAL driver initialization.
|
2010-10-04 17:16:18 +00:00
|
|
|
*
|
|
|
|
* @notapi
|
2010-02-19 18:19:00 +00:00
|
|
|
*/
|
|
|
|
void hal_lld_init(void) {
|
|
|
|
extern void _vectors(void);
|
|
|
|
uint32_t n;
|
|
|
|
|
|
|
|
/* FLASH wait states and prefetching setup.*/
|
2012-12-11 14:17:39 +00:00
|
|
|
CFLASH0.BIUCR.R = SPC5_FLASH_BIUCR | SPC5_FLASH_WS;
|
2010-02-19 18:19:00 +00:00
|
|
|
CFLASH0.BIUCR2.R = 0;
|
|
|
|
CFLASH0.PFCR3.R = 0;
|
|
|
|
|
|
|
|
/* Optimal crossbar settings. The DMA priority is placed above the CPU
|
|
|
|
priority in order to not starve I/O activities while the CPU is
|
2012-03-26 09:13:37 +00:00
|
|
|
executing tight loops (FLASH and SRAM slave ports only).
|
2010-02-19 18:19:00 +00:00
|
|
|
The SRAM is parked on the load/store port, for some unknown reason it
|
|
|
|
is defaulted on the instructions port and this kills performance.*/
|
|
|
|
XBAR.SGPCR3.B.PARK = 4; /* RAM slave on load/store port.*/
|
|
|
|
XBAR.MPR0.R = 0x00030201; /* Flash slave port priorities:
|
|
|
|
eDMA (1): 0 (highest)
|
|
|
|
Core Instructions (0): 1
|
|
|
|
Undocumented (2): 2
|
|
|
|
Core Data (4): 3 */
|
|
|
|
XBAR.MPR3.R = 0x00030201; /* SRAM slave port priorities:
|
|
|
|
eDMA (1): 0 (highest)
|
|
|
|
Core Instructions (0): 1
|
|
|
|
Undocumented (2): 2
|
|
|
|
Core Data (4): 3 */
|
|
|
|
|
|
|
|
/* Downcounter timer initialized for system tick use, TB enabled for debug
|
|
|
|
and measurements.*/
|
2012-12-11 14:17:39 +00:00
|
|
|
n = SPC5_SYSCLK / CH_FREQUENCY;
|
2010-02-19 18:19:00 +00:00
|
|
|
asm volatile ("li %%r3, 0 \t\n"
|
|
|
|
"mtspr 284, %%r3 \t\n" /* Clear TBL register. */
|
|
|
|
"mtspr 285, %%r3 \t\n" /* Clear TBU register. */
|
|
|
|
"mtspr 22, %[n] \t\n" /* Init. DEC register. */
|
|
|
|
"mtspr 54, %[n] \t\n" /* Init. DECAR register.*/
|
|
|
|
"li %%r3, 0x4000 \t\n" /* TBEN bit. */
|
|
|
|
"mtspr 1008, %%r3 \t\n" /* HID0 register. */
|
|
|
|
"lis %%r3, 0x0440 \t\n" /* DIE ARE bits. */
|
|
|
|
"mtspr 340, %%r3" /* TCR register. */
|
|
|
|
: : [n] "r" (n) : "r3");
|
|
|
|
|
|
|
|
/* INTC initialization, software vector mode, 4 bytes vectors, starting
|
|
|
|
at priority 0.*/
|
|
|
|
INTC.MCR.R = 0;
|
|
|
|
INTC.CPR.R = 0;
|
|
|
|
INTC.IACKR.R = (uint32_t)_vectors;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief SPC563 clocks and PLL initialization.
|
|
|
|
* @note All the involved constants come from the file @p board.h and
|
|
|
|
* @p hal_lld.h
|
2010-10-04 17:16:18 +00:00
|
|
|
* @note This function must be invoked only after the system reset.
|
|
|
|
*
|
|
|
|
* @special
|
2010-02-19 18:19:00 +00:00
|
|
|
*/
|
2012-12-11 10:27:10 +00:00
|
|
|
void spc_clock_init(void) {
|
2010-02-19 18:19:00 +00:00
|
|
|
|
2012-12-11 14:17:39 +00:00
|
|
|
#if !SPC5_NO_INIT
|
2010-02-19 18:19:00 +00:00
|
|
|
/* PLL activation.*/
|
2012-12-17 13:02:41 +00:00
|
|
|
FMPLL.ESYNCR1.B.EMODE = 1; /* Enhanced mode on. */
|
2010-02-19 18:19:00 +00:00
|
|
|
FMPLL.ESYNCR1.B.CLKCFG &= 1; /* Bypass mode, PLL off.*/
|
2012-12-17 13:15:12 +00:00
|
|
|
#if !SPC5_CLK_BYPASS
|
2010-02-19 18:19:00 +00:00
|
|
|
FMPLL.ESYNCR1.B.CLKCFG |= 2; /* PLL on. */
|
2012-12-11 14:17:39 +00:00
|
|
|
FMPLL.ESYNCR1.B.EPREDIV = SPC5_CLK_PREDIV;
|
|
|
|
FMPLL.ESYNCR1.B.EMFD = SPC5_CLK_MFD;
|
|
|
|
FMPLL.ESYNCR2.B.ERFD = SPC5_CLK_RFD;
|
2010-02-19 18:19:00 +00:00
|
|
|
while (!FMPLL.SYNSR.B.LOCK)
|
|
|
|
;
|
|
|
|
FMPLL.ESYNCR1.B.CLKCFG |= 4; /* Clock from the PLL. */
|
2012-12-17 13:15:12 +00:00
|
|
|
#endif /* !SPC5_CLK_BYPASS */
|
2012-12-11 14:17:39 +00:00
|
|
|
#endif /* !SPC5_NO_INIT */
|
2010-02-19 18:19:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @} */
|