-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpic32_dev_rtcc.c
More file actions
143 lines (126 loc) · 3.62 KB
/
pic32_dev_rtcc.c
File metadata and controls
143 lines (126 loc) · 3.62 KB
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
/*
* Interrupt controller for PIC32.
*
* Copyright (C) 2011 Serge Vakulenko <serge@vak.ru>
*
* This file is part of the virtualmips distribution.
* See LICENSE file for terms of the license.
*/
#define _GNU_SOURCE
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include "device.h"
#include "mips_memory.h"
#include "cpu.h"
#include "pic32.h"
#define RTCC_REG_SIZE 0x80
extern cpu_mips_t *current_cpu;
/*
* Perform an assign/clear/set/invert operation.
*/
static inline unsigned write_op (int a, int b, int op)
{
switch (op & 0xc) {
case 0x0: /* Assign */
a = b;
break;
case 0x4: /* Clear */
a &= ~b;
break;
case 0x8: /* Set */
a |= b;
break;
case 0xc: /* Invert */
a ^= b;
break;
}
return a;
}
void *dev_pic32_rtcc_access (cpu_mips_t *cpu, struct vdevice *dev,
m_uint32_t offset, u_int op_size, u_int op_type, m_reg_t *data,
m_uint8_t *has_set_value)
{
pic32_t *pic32 = dev->priv_data;
if (offset >= RTCC_REG_SIZE) {
*data = 0;
return NULL;
}
if (op_type == MTS_READ)
*data = 0;
switch (offset & 0x1f0) {
case PIC32_RTCCON & 0x1f0: /* RTC Control */
if (op_type == MTS_READ) {
*data = pic32->rtccon;
if (cpu->vm->debug_level > 2)
printf (" read RTCCON -> %08x\n", *data);
} else {
pic32->rtccon = write_op (pic32->rtccon, *data, offset);
if (cpu->vm->debug_level > 2)
printf (" RTCCON := %08x\n", pic32->rtccon);
}
break;
case PIC32_RTCALRM & 0x1f0: /* RTC alarm control */
if (op_type == MTS_READ) {
*data = 0;
} else {
//pic32->rtcalrm = write_op (pic32->rtcalrm, *data, offset);
}
break;
case PIC32_RTCTIME & 0x1f0: /* RTC time value */
if (op_type == MTS_READ) {
*data = 0;
} else {
//pic32->rtctime = write_op (pic32->rtctime, *data, offset);
}
break;
case PIC32_RTCDATE & 0x1f0: /* RTC date value */
if (op_type == MTS_READ) {
*data = 0;
} else {
//pic32->rtcdate = write_op (pic32->rtcdate, *data, offset);
}
break;
case PIC32_ALRMTIME & 0x1f0: /* Alarm time value */
if (op_type == MTS_READ) {
*data = 0;
} else {
//pic32->alrmtime = write_op (pic32->alrmtime, *data, offset);
}
break;
case PIC32_ALRMDATE & 0x1f0: /* Alarm date value */
if (op_type == MTS_READ) {
*data = 0;
} else {
//pic32->alrmdate = write_op (pic32->alrmdate, *data, offset);
}
break;
default:
ASSERT (0, "unknown rtcc offset %x\n", offset);
}
*has_set_value = TRUE;
return NULL;
}
void dev_pic32_rtcc_reset (cpu_mips_t *cpu, struct vdevice *dev)
{
pic32_t *pic32 = dev->priv_data;
pic32->rtccon = 0;
}
int dev_pic32_rtcc_init (vm_instance_t *vm, char *name, unsigned paddr)
{
pic32_t *pic32 = (pic32_t *) vm->hw_data;
pic32->rtcdev = dev_create (name);
if (! pic32->rtcdev)
return (-1);
pic32->rtcdev->priv_data = pic32;
pic32->rtcdev->phys_addr = paddr;
pic32->rtcdev->phys_len = RTCC_REG_SIZE;
pic32->rtcdev->handler = dev_pic32_rtcc_access;
pic32->rtcdev->reset_handler = dev_pic32_rtcc_reset;
pic32->rtcdev->flags = VDEVICE_FLAG_NO_MTS_MMAP;
vm_bind_device (vm, pic32->rtcdev);
return (0);
}