-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathsdram.hpp
96 lines (86 loc) · 3.47 KB
/
sdram.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#pragma once
//=====================================================================//
/*! @file
@brief RX600/RX700 グループ SDRAM 設定
@author 平松邦仁 ([email protected])
@copyright Copyright (C) 2017, 2024 Kunihito Hiramatsu @n
Released under the MIT license @n
https://github.com/hirakuni45/RX/blob/master/LICENSE
*/
//=====================================================================//
#include "RX600/system.hpp"
namespace utils {
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
/*!
@brief SDRAM 種別
*/
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
enum class sdram_type {
M128, ///< 128 Mbits (16 Mbytes)
M256, ///< 256 Mbits (32 Mbytes)
M512, ///< 512 Mbits (64 Mbytes)
};
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
/*!
@brief バス幅
*/
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
enum class sdram_width {
W16, ///< 16 bits
W32, ///< 32 bits
};
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
/*!
@brief SDRAM 制御クラス
@param[in] mtype メモリータイプ
@param[in] busw バス幅
*/
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
template <sdram_type mtype, sdram_width busw>
class sdram {
public:
void operator() ()
{
// SDRAM 初期化 128M/32bits bus
device::MPC::PFAOE0 = 0xff; // A8 to A15
device::MPC::PFBCR0 = device::MPC::PFBCR0.ADRLE.b(1) |
device::MPC::PFBCR0.DHE.b(1) |
device::MPC::PFBCR0.DH32E.b(1);
device::MPC::PFBCR1 = device::MPC::PFBCR1.MDSDE.b(1) |
device::MPC::PFBCR1.DQM1E.b(1) |
device::MPC::PFBCR1.SDCLKE.b(1);
device::SYSTEM::SYSCR0 = device::SYSTEM::SYSCR0.KEY.b(0x5A) |
device::SYSTEM::SYSCR0.ROME.b(1) |
device::SYSTEM::SYSCR0.EXBE.b(1);
while(device::SYSTEM::SYSCR0.EXBE() == 0) asm("nop");
device::BUS::SDIR = device::BUS::SDIR.ARFI.b(0) |
device::BUS::SDIR.ARFC.b(1) |
device::BUS::SDIR.PRC.b(0);
device::BUS::SDICR = device::BUS::SDICR.INIRQ.b(1); // 初期化シーケンス開始
while(device::BUS::SDSR() != 0) asm("nop");
// 動作許可、32ビットアクセス
device::BUS::SDCCR = device::BUS::SDCCR.BSIZE.b(1);
// Burst read and burst write, CAS latency: 3, Burst type: Sequential, Burst length: 1
device::BUS::SDMOD = 0b00000000110000;
// CAS latency: 3, Write recovery: 1, ROW prechage: 4, RAS latency: 3, RAS active: 4
device::BUS::SDTR = device::BUS::SDTR.CL.b(3) |
device::BUS::SDTR.RP.b(3) |
device::BUS::SDTR.RCD.b(2) |
device::BUS::SDTR.RAS.b(3);
// 128M/16 カラム9ビット、ロウ12ビット
device::BUS::SDADR = device::BUS::SDADR.MXC.b(1);
// Refresh cycle
device::BUS::SDRFCR = device::BUS::SDRFCR.RFC.b(2048) |
device::BUS::SDRFCR.REFW.b(7);
device::BUS::SDRFEN = device::BUS::SDRFEN.RFEN.b(1);
// SDRAM 動作開始
device::BUS::SDCCR.EXENB = 1;
}
};
typedef sdram<sdram_type::M128, sdram_width::W16> SDRAM_128M_16W;
typedef sdram<sdram_type::M128, sdram_width::W32> SDRAM_128M_32W;
typedef sdram<sdram_type::M256, sdram_width::W16> SDRAM_256M_16W;
typedef sdram<sdram_type::M256, sdram_width::W32> SDRAM_256M_32W;
typedef sdram<sdram_type::M512, sdram_width::W16> SDRAM_512M_16W;
typedef sdram<sdram_type::M512, sdram_width::W32> SDRAM_512M_32W;
}