]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_R4F_RZ_T_GCC_IAR_ARM/System/IAR/src/r_cpg.c
Modify RZ/T e2studio directory structure to accommodate an IAR project.
[freertos] / FreeRTOS / Demo / CORTEX_R4F_RZ_T_GCC_IAR_ARM / System / IAR / src / r_cpg.c
1 /*******************************************************************************\r
2 * DISCLAIMER\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
19 * following link:\r
20 * http://www.renesas.com/disclaimer\r
21 *\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
27 * Version      : 0.1\r
28 * Device       : R7S9100xx\r
29 * Abstract     : API for CPG function\r
30 * Tool-Chain   : IAR Embedded Workbench Ver.7.20\r
31 * OS           : not use\r
32 * H/W Platform : Renesas Starter Kit for RZ/T1(Preliminary)\r
33 * Description  : CPG setting API of RZ/T1\r
34 * Limitation   : none\r
35 *******************************************************************************/\r
36 /*******************************************************************************\r
37 * History      : DD.MM.YYYY Version  Description\r
38 *              :                     First Release\r
39 *******************************************************************************/\r
40 \r
41 /*******************************************************************************\r
42 Includes <System Includes> , "Project Includes"\r
43 *******************************************************************************/\r
44 #include <stdint.h>\r
45 #include <Renesas/ior7s910017.h>\r
46 #include "r_system.h"\r
47 #include "r_cpg.h"\r
48 #include "r_reset.h"\r
49 #include "r_icu_init.h"\r
50 \r
51 /*******************************************************************************\r
52 Macro definitions\r
53 *******************************************************************************/\r
54 #define CPG_WRITE_ENABLE (0x0000A501)\r
55 #define CPG_WRITE_DISABLE (0x0000A500)\r
56 \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
62 \r
63 #define CPG_CMT_REG_CLEAR (0x0000)\r
64 \r
65 /*******************************************************************************\r
66 Typedef definitions\r
67 *******************************************************************************/\r
68 \r
69 \r
70 /*******************************************************************************\r
71 Imported global variables and functions (from other files)\r
72 *******************************************************************************/\r
73 \r
74 \r
75 /*******************************************************************************\r
76 Exported global variables and functions (to be accessed by other files)\r
77 *******************************************************************************/\r
78 \r
79 \r
80 /*******************************************************************************\r
81 Private variables and functions\r
82 *******************************************************************************/\r
83 \r
84 \r
85 /*******************************************************************************\r
86 * Function Name : R_CPG_PLL_Wait\r
87 * Description   : Wait about 100us for PLL stabilization by using CMT0\r
88 * Arguments    : none\r
89 * Return Value : none\r
90 *******************************************************************************/\r
91 void R_CPG_PLL_Wait(void)\r
92 {\r
93 \r
94     /* Enables writing to the registers related to Reset and Low-Power function */\r
95     r_rst_write_enable();\r
96 \r
97     /* Release from the CMT0 module-stop state  */\r
98     MSTP(CMT0) = 0;\r
99 \r
100     /* Disables writing to the registers related to Reset and Low-Power function */\r
101     r_rst_write_disable();\r
102 \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
108 \r
109 \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
114 \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
118 \r
119     /* Start CMT0 count */\r
120     CMT.CMSTR0.BIT.STR0 = CPG_CMT0_START;\r
121 \r
122     /* Wait for 100us (IRQ21 is generated) */\r
123     while ( !(VIC.RAIS0.BIT.RAI21) )\r
124     {\r
125         /* Wait */\r
126     }\r
127 \r
128     /* Stop CMT0 count */\r
129     CMT.CMSTR0.BIT.STR0 = CPG_CMT0_STOP;\r
130 \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
136 \r
137     VIC.PIC0.BIT.PIC21 = ICU_PIC_EDGE_CLEAR;  // Clear interrupt detection edge\r
138 \r
139 \r
140     /* Disable IRQ interrupt (Set CPSR.I bit to 1) */\r
141     asm("cpsid i");\r
142     asm("isb");\r
143 \r
144     /* Enables writing to the registers related to Reset and Low-Power function */\r
145     r_rst_write_enable();\r
146 \r
147     /* Set CMT0 to module-stop state */\r
148     MSTP(CMT0) = 1;\r
149 \r
150     /* Disables writing to the registers related to Reset and Low-Power function */\r
151     r_rst_write_disable();\r
152 \r
153 \r
154 }\r
155 \r
156 /*******************************************************************************\r
157  End of function R_CPG_PLL_Wait\r
158 *******************************************************************************/\r
159 \r
160 /* End of File */\r
161 \r
162 \r