-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
rx_protocol.hpp
200 lines (168 loc) · 5.77 KB
/
rx_protocol.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#pragma once
//=========================================================================//
/*! @file
@brief RX プログラミング・プロトコル・クラス
@author 平松邦仁 (hira@rvf-rc45.net)
@copyright Copyright (C) 2016, 2024 Kunihito Hiramatsu @n
Released under the MIT license @n
https://github.com/hirakuni45/RX/blob/master/LICENSE
*/
//=========================================================================//
#include <iostream>
#include <vector>
#include <string>
#include <boost/format.hpp>
namespace rx {
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
/*!
@brief RX プログラミング・プロトコル・クラス
*/
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
struct protocol {
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
/*!
@brief device 構造体
*/
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
struct device {
uint32_t code_;
std::string name_;
device() noexcept : code_(0), name_() { }
void info(const std::string& head = "") const noexcept
{
std::cout << head << (boost::format("Device ID: 0x%0X") % code_) << std::endl;
std::cout << head << (boost::format("Device Name: '%s'") % name_) << std::endl;
}
};
typedef std::vector<device> devices;
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
/*!
@brief device_type 構造体
*/
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
struct device_type {
uint8_t TYP[8];
uint32_t OSA;
uint32_t OSI;
uint32_t CPA;
uint32_t CPI;
device_type() noexcept : TYP{ 0 }, OSA(0), OSI(0), CPA(0), CPI(0) { }
void info(const std::string& head = "") const noexcept
{
std::cout << head << "Device Type TYP:";
for(int i = 0; i < 8; ++i) {
std::cout << boost::format(" %02X") % static_cast<uint32_t>(TYP[i]);
}
std::cout << std::endl;
std::cout << head << (boost::format("Device Type OSA: %d") % OSA) << std::endl;
std::cout << head << (boost::format("Device Type OSI: %d") % OSI) << std::endl;
std::cout << head << (boost::format("Device Type CPA: %d") % CPA) << std::endl;
std::cout << head << (boost::format("Device Type CPI: %d") % CPI) << std::endl;
}
};
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
/*!
@brief clock_mode 構造体
*/
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
struct clock_mode {
uint8_t type_;
clock_mode() noexcept : type_(0) { }
void info(const std::string& head = "") const noexcept
{
std::cout << head << (boost::format("Clock Mode: 0x%02X") % static_cast<int>(type_))
<< std::endl;
}
};
typedef std::vector<clock_mode> clock_modes;
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
/*!
@brief multiplier 構造体
*/
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
struct multiplier {
typedef std::vector<uint8_t> list;
list list_;
void info(const std::string& head = "") const {
std::cout << head << "Multiplier: ";
uint32_t i = 0;
for(auto v : list_) {
std::cout << static_cast<int>(v);
++i;
if(i < list_.size()) {
std::cout << ", ";
}
}
std::cout << std::endl;
}
};
typedef std::vector<multiplier> multipliers;
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
/*!
@brief frequency 構造体
*/
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
struct frequency {
uint16_t min_ = 0;
uint16_t max_ = 0;
void info(const std::string& head = "") const {
std::cout << head << "Frequency Min: "
<< (static_cast<float>(min_) / 100.0f) << " MHz, Max: "
<< (static_cast<float>(max_) / 100.0f) << " MHz"
<< std::endl;
}
};
typedef std::vector<frequency> frequencies;
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
/*!
@brief area 構造体
*/
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
struct area {
uint32_t org_ = 0;
uint32_t end_ = 0;
void info(const std::string& head = "") const {
std::cout << head << (boost::format("Area: %08X, %08X") % org_ % end_) << std::endl;
}
};
typedef std::vector<area> areas;
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
/*!
@brief block 構造体
*/
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
struct block {
uint32_t org_ = 0;
uint32_t size_ = 0;
uint32_t num_ = 0;
void info(const std::string& head = "") const {
std::cout << head << (boost::format("Block: %08X, %08X, %08X") % org_ % size_ % num_) << std::endl;
}
};
typedef std::vector<block> blocks;
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
/*!
@brief rx_t 構造体 @n
※ RX62x, RX63T 標準設定: 12.00MHz、8(96MHz)、4(48MHz)
*/
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
struct rx_t {
bool verbose_ = false;
std::string cpu_type_; ///< CPU タイプ
uint32_t master_ = 1200; ///< マスター・クロック(MHz 単位で、小数第2位、100倍)
uint32_t iclk_multi_ = 8; ///< インストラクション・マルチプライヤー設定
uint32_t pclk_multi_ = 4; ///< 周辺機器・マルチプライヤー設定
uint8_t id_[16] = { 0xff }; ///< ID
};
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
/*!
@brief erase_page ステート型
*/
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
enum class erase_state {
ERROR, ///< エラー
CHECK_OK, ///< 消去チェックが OK の場合
ERASE_OK, ///< ブロック消去が OK の場合
};
};
}