1 /*******************************************************************************
\r
3 * This software is supplied by Renesas Electronics Corporation and is only
\r
4 * intended for use with Renesas products. No other uses are authorized. This
\r
5 * software is owned by Renesas Electronics Corporation and is protected under
\r
6 * all applicable laws, including copyright laws.
\r
7 * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
\r
8 * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
\r
9 * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
\r
10 * AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
\r
11 * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
\r
12 * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
\r
13 * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
\r
14 * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
\r
15 * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
\r
16 * Renesas reserves the right, without notice, to make changes to this software
\r
17 * and to discontinue the availability of this software. By using this software,
\r
18 * you agree to the additional terms and conditions found by accessing the
\r
20 * http://www.renesas.com/disclaimer
\r
22 * Copyright (C) 2014 Renesas Electronics Corporation. All rights reserved.
\r
23 *******************************************************************************/
\r
24 /*******************************************************************************
\r
25 * System Name : RZ/T1 Init program
\r
26 * File Name : r_cpg.c
\r
28 * Device : R7S9100xx
\r
29 * Abstract : API for CPG function
\r
30 * Tool-Chain : IAR Embedded Workbench Ver.7.20
\r
32 * H/W Platform : Renesas Starter Kit for RZ/T1(Preliminary)
\r
33 * Description : CPG setting API of RZ/T1
\r
35 *******************************************************************************/
\r
36 /*******************************************************************************
\r
37 * History : DD.MM.YYYY Version Description
\r
39 *******************************************************************************/
\r
41 /*******************************************************************************
\r
42 Includes <System Includes> , "Project Includes"
\r
43 *******************************************************************************/
\r
45 #include <Renesas/ior7s910017.h>
\r
46 #include "r_system.h"
\r
48 #include "r_reset.h"
\r
49 #include "r_icu_init.h"
\r
51 /*******************************************************************************
\r
53 *******************************************************************************/
\r
54 #define CPG_WRITE_ENABLE (0x0000A501)
\r
55 #define CPG_WRITE_DISABLE (0x0000A500)
\r
57 #define CPG_CMT0_CLOCK_PCLKD_32 (1)
\r
58 #define CPG_CMT0_CMI0_ENABLE (1)
\r
59 #define CPG_CMT0_CONST_100_us (0xEA)
\r
60 #define CPG_CMT0_START (1)
\r
61 #define CPG_CMT0_STOP (0)
\r
63 #define CPG_CMT_REG_CLEAR (0x0000)
\r
65 /*******************************************************************************
\r
67 *******************************************************************************/
\r
70 /*******************************************************************************
\r
71 Imported global variables and functions (from other files)
\r
72 *******************************************************************************/
\r
75 /*******************************************************************************
\r
76 Exported global variables and functions (to be accessed by other files)
\r
77 *******************************************************************************/
\r
80 /*******************************************************************************
\r
81 Private variables and functions
\r
82 *******************************************************************************/
\r
85 /*******************************************************************************
\r
86 * Function Name : R_CPG_PLL_Wait
\r
87 * Description : Wait about 100us for PLL stabilization by using CMT0
\r
89 * Return Value : none
\r
90 *******************************************************************************/
\r
91 void R_CPG_PLL_Wait(void)
\r
94 /* Enables writing to the registers related to Reset and Low-Power function */
\r
95 r_rst_write_enable();
\r
97 /* Release from the CMT0 module-stop state */
\r
100 /* Disables writing to the registers related to Reset and Low-Power function */
\r
101 r_rst_write_disable();
\r
103 /* Set CMT0 to 100us interval operation */
\r
104 CMT0.CMCR.BIT.CKS = CPG_CMT0_CLOCK_PCLKD_32; // Count clock = PCLKD/32
\r
105 CMT0.CMCR.BIT.CMIE = CPG_CMT0_CMI0_ENABLE; // Enable CMI0 interrupt
\r
106 CMT0.CMCNT = CPG_CMT_REG_CLEAR; // Clear CMCNT counter
\r
107 CMT0.CMCOR = CPG_CMT0_CONST_100_us; // Set constant value for 100us
\r
110 /* Set IRQ21(CMI0) for polloing sequence */
\r
111 VIC.IEC0.BIT.IEC21 = ICU_IEC_MASK_SET; // Mask IRQ21 interrupt
\r
112 VIC.PLS0.BIT.PLS21 = ICU_TYPE_EDGE; // Set EDGE type interrupt
\r
113 VIC.PIC0.BIT.PIC21 = ICU_PIC_EDGE_CLEAR; // Clear interrupt detection edge
\r
115 /* Enable IRQ interrupt (Clear CPSR.I bit to 0) */
\r
116 asm("cpsie i"); // Clear CPSR.I bit to 0
\r
117 asm("isb"); // Ensuring Context-changing
\r
119 /* Start CMT0 count */
\r
120 CMT.CMSTR0.BIT.STR0 = CPG_CMT0_START;
\r
122 /* Wait for 100us (IRQ21 is generated) */
\r
123 while ( !(VIC.RAIS0.BIT.RAI21) )
\r
128 /* Stop CMT0 count */
\r
129 CMT.CMSTR0.BIT.STR0 = CPG_CMT0_STOP;
\r
131 /* Initialize CMT0 settings and clear interrupt detection edge */
\r
132 CMT0.CMCR.WORD = CPG_CMT_REG_CLEAR;
\r
133 CMT0.CMCNT = CPG_CMT_REG_CLEAR;
\r
134 CMT0.CMCOR = CPG_CMT_REG_CLEAR;
\r
135 CMT.CMSTR0.WORD = CPG_CMT_REG_CLEAR;
\r
137 VIC.PIC0.BIT.PIC21 = ICU_PIC_EDGE_CLEAR; // Clear interrupt detection edge
\r
140 /* Disable IRQ interrupt (Set CPSR.I bit to 1) */
\r
144 /* Enables writing to the registers related to Reset and Low-Power function */
\r
145 r_rst_write_enable();
\r
147 /* Set CMT0 to module-stop state */
\r
150 /* Disables writing to the registers related to Reset and Low-Power function */
\r
151 r_rst_write_disable();
\r
156 /*******************************************************************************
\r
157 End of function R_CPG_PLL_Wait
\r
158 *******************************************************************************/
\r