|
|
1.1 root 1: //
2: // nono
1.1.1.3 root 3: // Copyright (C) 2020 nono project
4: // Licensed under nono-license.txt
1.1 root 5: //
6:
1.1.1.9 root 7: //
1.1.1.2 root 8: // MPU 共通部
1.1.1.9 root 9: //
1.1.1.2 root 10:
1.1 root 11: #include "mpu.h"
1.1.1.5 root 12: #include "config.h"
1.1.1.9 root 13: #include "scheduler.h"
1.1 root 14:
1.1.1.9 root 15: // グローバル参照用
16: MPUDevice *gMPU;
1.1 root 17:
18: // コンストラクタ
1.1.1.7 root 19: MPUDevice::MPUDevice(const std::string& objname_)
20: : inherited(objname_)
1.1 root 21: {
1.1.1.7 root 22: ClearAlias();
23: AddAlias("MPU");
1.1.1.9 root 24:
25: exec_event.Regist("MPU Execute");
1.1 root 26: }
27:
28: // デストラクタ
29: MPUDevice::~MPUDevice()
30: {
1.1.1.9 root 31: gMPU = NULL;
1.1 root 32: }
1.1.1.4 root 33:
1.1.1.5 root 34: bool
35: MPUDevice::Init()
36: {
1.1.1.9 root 37: gScheduler->ConnectMessage(MessageID::MPU_TRACE, this,
38: ToMessageCallback(&MPUDevice::TraceMessage));
39:
1.1.1.5 root 40: // MPU クロック
41: const ConfigItem& item = gConfig->Find("mpu-clock");
42: const std::string& val = item.AsString();
43: if (val.empty()) {
44: item.Err();
45: return false;
46: }
47: // 文字列を double に変換
48: char *end;
49: errno = 0;
50: double f = strtod(val.c_str(), &end);
51: if (end == val.c_str() || end[0] != '\0' || errno == ERANGE) {
52: item.Err();
53: return false;
54: }
55: // 設定の "mpu-clock" は MHz 単位だが、変数 clock_khz は kHz 単位。
56: clock_khz = (int)(f * 1000);
1.1.1.7 root 57: // 1MHz 未満はエラー。実際 10MHz 未満でもいい気がするけど
1.1.1.5 root 58: if (clock_khz < 1000) {
59: item.Err();
60: return false;
61: }
1.1.1.9 root 62: clock_nsec = 1000 * 1000 / clock_khz;
1.1.1.5 root 63:
64: return true;
65: }
1.1.1.8 root 66:
1.1.1.9 root 67: void
68: MPUDevice::PowerOff()
69: {
70: gScheduler->StopEvent(exec_event);
71: }
72:
73: // MPU トレース状態設定要求メッセージ
74: void
75: MPUDevice::TraceMessage(MessageID msgid, uint32 arg)
76: {
1.1.1.10! root 77: // リセット中は SetTrace しない
! 78: if (resetting) {
! 79: return;
! 80: }
! 81:
1.1.1.9 root 82: // デバッガから MPU のトレース状態を設定してくれと言われた
83: SetTrace((bool)arg);
84: }
85:
1.1.1.8 root 86: // Round Mode (モニタ表示用)
87: /*static*/ const char * const
88: MPUDevice::rmstr[4] = {
89: "Near",
90: "Zero",
91: "Minus",
92: "Plus",
93: };
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.