[117] | 1 | /*
|
---|
| 2 | * TOPPERS ATK2
|
---|
| 3 | * Toyohashi Open Platform for Embedded Real-Time Systems
|
---|
| 4 | * Automotive Kernel Version 2
|
---|
| 5 | *
|
---|
| 6 | * Copyright (C) 2012-2014 by Center for Embedded Computing Systems
|
---|
| 7 | * Graduate School of Information Science, Nagoya Univ., JAPAN
|
---|
| 8 | *
|
---|
| 9 | * 上記著作権者は,以下の(1)〜(4)の条件を満たす場合に限り,本ソフトウェ
|
---|
| 10 | * ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改
|
---|
| 11 | * 変・再配布(以下,利用と呼ぶ)することを無償で許諾する.
|
---|
| 12 | * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
|
---|
| 13 | * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
|
---|
| 14 | * スコード中に含まれていること.
|
---|
| 15 | * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
|
---|
| 16 | * 用できる形で再配布する場合には,再配布に伴うドキュメント(利用
|
---|
| 17 | * 者マニュアルなど)に,上記の著作権表示,この利用条件および下記
|
---|
| 18 | * の無保証規定を掲載すること.
|
---|
| 19 | * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
|
---|
| 20 | * 用できない形で再配布する場合には,次のいずれかの条件を満たすこ
|
---|
| 21 | * と.
|
---|
| 22 | * (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
|
---|
| 23 | * 作権表示,この利用条件および下記の無保証規定を掲載すること.
|
---|
| 24 | * (b) 再配布の形態を,別に定める方法によって,TOPPERSプロジェクトに
|
---|
| 25 | * 報告すること.
|
---|
| 26 | * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
|
---|
| 27 | * 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
|
---|
| 28 | * また,本ソフトウェアのユーザまたはエンドユーザからのいかなる理
|
---|
| 29 | * 由に基づく請求からも,上記著作権者およびTOPPERSプロジェクトを
|
---|
| 30 | * 免責すること.
|
---|
| 31 | *
|
---|
| 32 | * 本ソフトウェアは,AUTOSAR(AUTomotive Open System ARchitecture)仕
|
---|
| 33 | * 様に基づいている.上記の許諾は,AUTOSARの知的財産権を許諾するもので
|
---|
| 34 | * はない.AUTOSARは,AUTOSAR仕様に基づいたソフトウェアを商用目的で利
|
---|
| 35 | * 用する者に対して,AUTOSARパートナーになることを求めている.
|
---|
| 36 | *
|
---|
| 37 | * 本ソフトウェアは,無保証で提供されているものである.上記著作権者お
|
---|
| 38 | * よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
|
---|
| 39 | * に対する適合性も含めて,いかなる保証も行わない.また,本ソフトウェ
|
---|
| 40 | * アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
|
---|
| 41 | * の責任を負わない.
|
---|
| 42 | *
|
---|
| 43 | * $Id: rh850_f1l.c 164 2015-06-03 01:22:29Z t_ishikawa $
|
---|
| 44 | */
|
---|
| 45 | #include "kernel_impl.h"
|
---|
| 46 | #include "rh850_f1l.h"
|
---|
| 47 | #include "Os.h"
|
---|
| 48 | #include "prc_sil.h"
|
---|
| 49 |
|
---|
| 50 | /*******************************************************************************************/
|
---|
| 51 | /* Outline : Write protected register */
|
---|
| 52 | /* Argument : Register address */
|
---|
| 53 | /* Register data */
|
---|
| 54 | /* Register No */
|
---|
| 55 | /* Return value : 0: write success / 1: write error */
|
---|
| 56 | /* Description : Write protected register */
|
---|
| 57 | /* */
|
---|
| 58 | /*******************************************************************************************/
|
---|
| 59 | static uint32
|
---|
| 60 | write_protected_reg(uint32 addr, uint32 data, uint8 regno)
|
---|
| 61 | {
|
---|
| 62 | uint8 wk;
|
---|
| 63 | const uint32 cmd_reg[19] = {
|
---|
| 64 | PROTCMD0, PROTCMD1, CLMA0PCMD, CLMA1PCMD, CLMA2PCMD, PROTCMDCLMA,
|
---|
| 65 | JPPCMD0, PPCMD0, PPCMD1, PPCMD2, PPCMD8,
|
---|
| 66 | PPCMD9, PPCMD10, PPCMD11, PPCMD12, PPCMD18, PPCMD20,
|
---|
| 67 | PROTCMDCVM, FLMDPCMD
|
---|
| 68 | };
|
---|
| 69 | const uint32 s_reg[19] = {
|
---|
| 70 | PROTCMD0, PROTCMD1, CLMA0PCMD, CLMA1PCMD, CLMA2PCMD, PROTCMDCLMA,
|
---|
| 71 | JPPCMD0, PPCMD0, PPCMD1, PPCMD2, PPCMD8,
|
---|
| 72 | PPCMD9, PPCMD10, PPCMD11, PPCMD12, PPCMD18, PPCMD20,
|
---|
| 73 | PROTCMDCVM, FLMDPCMD
|
---|
| 74 | };
|
---|
| 75 | SIL_PRE_LOC;
|
---|
| 76 |
|
---|
| 77 | if (regno > 19) {
|
---|
| 78 | return(UC_INVALIDPARAM);
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | SIL_LOC_INT();
|
---|
| 82 | sil_wrw_mem((void *) cmd_reg[regno], 0xA5);
|
---|
| 83 |
|
---|
| 84 | sil_wrw_mem((void *) addr, data);
|
---|
| 85 | sil_wrw_mem((void *) addr, ~data);
|
---|
| 86 | sil_wrw_mem((void *) addr, data);
|
---|
| 87 | SIL_UNL_INT();
|
---|
| 88 |
|
---|
| 89 | wk = sil_rew_mem((void *) s_reg[regno]);
|
---|
| 90 | wk &= 0x01;
|
---|
| 91 |
|
---|
| 92 | return((wk == 0) ? UC_SUCCESS : UC_PROTREGERROR);
|
---|
| 93 | } /* write_protected_reg */
|
---|
| 94 |
|
---|
| 95 |
|
---|
| 96 | /*******************************************************************************************/
|
---|
| 97 | /* Outline : Sub Oscillator enable */
|
---|
| 98 | /* Argument : - */
|
---|
| 99 | /* Return value : 0: successfly set / 1: set error */
|
---|
| 100 | /* Description : Sub Oscillator register setting */
|
---|
| 101 | /* */
|
---|
| 102 | /*******************************************************************************************/
|
---|
| 103 | uint32
|
---|
| 104 | EnableSubOSC(void)
|
---|
| 105 | {
|
---|
| 106 | /* stop SubOSC */
|
---|
| 107 | if (write_protected_reg(SOSCE, 0x00, PNO_CtrlProt0) != UC_SUCCESS) {
|
---|
| 108 | return(UC_ERROR);
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 | /* Wait inactive */
|
---|
| 112 | while (((sil_rew_mem((void *) SOSCS)) & CLK_S_CLKEN) != 0) {
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | /* start SubOSC */
|
---|
| 116 | if (write_protected_reg(SOSCE, 0x01, PNO_CtrlProt0) != UC_SUCCESS) return(UC_ERROR);
|
---|
| 117 |
|
---|
| 118 | /* Wait stabilization */
|
---|
| 119 | while (((sil_rew_mem((void *) SOSCS)) & CLK_S_CLKEN) == 0) {
|
---|
| 120 | }
|
---|
| 121 |
|
---|
| 122 | return(UC_SUCCESS);
|
---|
| 123 | } /* EnableSubOSC */
|
---|
| 124 |
|
---|
| 125 | /*******************************************************************************************/
|
---|
| 126 | /* Outline : Main Oscillator enable */
|
---|
| 127 | /* Argument : Main Cscillator frequency(Hz) */
|
---|
| 128 | /* Return value : 0: successfly set / 1: set error */
|
---|
| 129 | /* Description : Main Oscillator register setting */
|
---|
| 130 | /* */
|
---|
| 131 | /*******************************************************************************************/
|
---|
| 132 | uint32
|
---|
| 133 | EnableMainOSC(uint32 clk_in)
|
---|
| 134 | {
|
---|
| 135 | uint8 ampsel;
|
---|
| 136 |
|
---|
| 137 | /* stop MainOSC */
|
---|
| 138 | if (write_protected_reg(MOSCE, 0x02, PNO_CtrlProt0) != UC_SUCCESS) {
|
---|
| 139 | return(UC_ERROR);
|
---|
| 140 | }
|
---|
| 141 |
|
---|
| 142 | if (clk_in == CLK_MHz(8)) {
|
---|
| 143 | ampsel = 0x03;
|
---|
| 144 | }
|
---|
| 145 | else if (CLK_MHz(8) < clk_in && clk_in <= CLK_MHz(16)) {
|
---|
| 146 | ampsel = 0x02;
|
---|
| 147 | }
|
---|
| 148 | else if (CLK_MHz(16) < clk_in && clk_in <= CLK_MHz(20)) {
|
---|
| 149 | ampsel = 0x01;
|
---|
| 150 | }
|
---|
| 151 | else if (CLK_MHz(20) < clk_in && clk_in <= CLK_MHz(24)) {
|
---|
| 152 | ampsel = 0x00;
|
---|
| 153 | }
|
---|
| 154 | else {
|
---|
| 155 | return(UC_INVALIDPARAM);
|
---|
| 156 | }
|
---|
| 157 |
|
---|
| 158 | sil_wrw_mem((void *) MOSCC, 0x00 | ampsel); /* Normal stabilization time mode */
|
---|
| 159 | sil_wrw_mem((void *) MOSCST, 0x00FF); /* stabilization time -> Max */
|
---|
| 160 |
|
---|
| 161 |
|
---|
| 162 | /* Wait inactive */
|
---|
| 163 | while (((sil_rew_mem((void *) MOSCS)) & CLK_S_CLKEN) != 0) {
|
---|
| 164 | }
|
---|
| 165 |
|
---|
| 166 | /* MainOSC start */
|
---|
| 167 | if (write_protected_reg(MOSCE, 0x01, PNO_CtrlProt0) != UC_SUCCESS) {
|
---|
| 168 | return(UC_ERROR);
|
---|
| 169 | }
|
---|
| 170 |
|
---|
| 171 | /* Wait stabilization */
|
---|
| 172 | while (((sil_rew_mem((void *) MOSCS)) & CLK_S_CLKEN) == 0) {
|
---|
| 173 | }
|
---|
| 174 |
|
---|
| 175 | return(UC_SUCCESS);
|
---|
| 176 | } /* EnableMainOSC */
|
---|
| 177 |
|
---|
| 178 | /*******************************************************************************************/
|
---|
| 179 | /* Outline : PLL enable */
|
---|
| 180 | /* Argument : none */
|
---|
| 181 | /* Return value : 0: successfly set / 1: set error */
|
---|
| 182 | /* Description : PLL register setting */
|
---|
| 183 | /* */
|
---|
| 184 | /*******************************************************************************************/
|
---|
| 185 | uint32
|
---|
| 186 | EnablePLL(void)
|
---|
| 187 | {
|
---|
| 188 | /* stop PLL */
|
---|
| 189 | if (write_protected_reg(PLLE, 0x02, PNO_CtrlProt1) != UC_SUCCESS) {
|
---|
| 190 | return(UC_ERROR);
|
---|
| 191 | }
|
---|
| 192 |
|
---|
| 193 | sil_wrw_mem((void *) PLLC, (PLLC_OUTBSEL << 16) | ((PLLC_mr - 1) << 11) | ((PLLC_par >> 1) << 8) | (PLLC_nr - 1));
|
---|
| 194 |
|
---|
| 195 | /* start PLL */
|
---|
| 196 | if (write_protected_reg(PLLE, 0x01, PNO_CtrlProt1) != UC_SUCCESS) {
|
---|
| 197 | return(UC_ERROR);
|
---|
| 198 | }
|
---|
| 199 |
|
---|
| 200 | /* Wait stabilization */
|
---|
| 201 | while (((sil_rew_mem((void *) PLLS)) & CLK_S_CLKEN) == 0) {
|
---|
| 202 | }
|
---|
| 203 |
|
---|
| 204 | return(UC_SUCCESS);
|
---|
| 205 | } /* EnablePLL */
|
---|
| 206 |
|
---|
| 207 | /*******************************************************************************************/
|
---|
| 208 | /* Outline : Clock switcher setting */
|
---|
| 209 | /* Argument : Selector Control reginster address */
|
---|
| 210 | /* Selector Status reginster address */
|
---|
| 211 | /* Register No */
|
---|
| 212 | /* Select No */
|
---|
| 213 | /* Divider Control reginster address */
|
---|
| 214 | /* Divider Status reginster address */
|
---|
| 215 | /* divider */
|
---|
| 216 | /* Return value : 0: successfly set / 1: set error */
|
---|
| 217 | /* Description : Select clock source of CKSCLK_mn */
|
---|
| 218 | /* */
|
---|
| 219 | /*******************************************************************************************/
|
---|
| 220 | uint32
|
---|
| 221 | SetClockSelection(uint32 s_control, uint32 s_status, uint8 regno, uint16 sel,
|
---|
| 222 | uint32 d_control, uint32 d_status, uint8 divider)
|
---|
| 223 | {
|
---|
| 224 | /* Set Selector */
|
---|
| 225 | if (write_protected_reg(s_control, sel, regno) != UC_SUCCESS) {
|
---|
| 226 | return(UC_ERROR);
|
---|
| 227 | }
|
---|
| 228 |
|
---|
| 229 | /* Set Divider */
|
---|
| 230 | if (d_control != 0) {
|
---|
| 231 | if (write_protected_reg(d_control, divider, regno) != UC_SUCCESS) {
|
---|
| 232 | return(UC_ERROR);
|
---|
| 233 | }
|
---|
| 234 | }
|
---|
| 235 |
|
---|
| 236 | /* Wait untile enable */
|
---|
| 237 | while (sil_rew_mem((void *) s_control) != sil_rew_mem((void *) s_status)) {
|
---|
| 238 | }
|
---|
| 239 |
|
---|
| 240 | if (d_control != 0) {
|
---|
| 241 | while (sil_rew_mem((void *) d_control) != sil_rew_mem((void *) d_status)) {
|
---|
| 242 | }
|
---|
| 243 | }
|
---|
| 244 |
|
---|
| 245 | return(UC_SUCCESS);
|
---|
| 246 | }
|
---|