-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcharacter_driver.h
80 lines (70 loc) · 2.59 KB
/
character_driver.h
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
/*
* ten file: vchar_driver.h
* tac gia : [email protected]
* ngay tao: 9/12/2018
* mo ta : chua cac dinh nghia mo ta thiet bi gia lap vchar_dev.
* vchar_device la mot thiet bi nam tren RAM.
*/
#define REG_SIZE 1 //kich thuoc cua 1 thanh ghi la 1 byte (8 bits)
#define NUM_CTRL_REGS 1 //so thanh ghi dieu khien cua thiet bi
#define NUM_STS_REGS 5 //so thanh ghi trang thai cua thiet bi
#define NUM_DATA_REGS 256 //so thanh ghi du lieu cua thiet bi
#define NUM_DEV_REGS (NUM_CTRL_REGS + NUM_STS_REGS + NUM_DATA_REGS) //tong so thanh ghi cua thiet bi
/****************** Mo ta cac thanh ghi trang thai: START ******************/
/*
* cap thanh ghi [READ_COUNT_H_REG:READ_COUNT_L_REG]:
* - gia tri luc khoi tao: 0x0000
* - moi lan doc thanh cong tu cac thanh ghi du lieu, tang them 1 don vi
*/
#define READ_COUNT_H_REG 0
#define READ_COUNT_L_REG 1
/*
* cap thanh ghi [WRITE_COUNT_H_REG:WRITE_COUNT_L_REG]:
* - gia tri luc khoi tao: 0x0000
* - moi lan ghi thanh cong vao cac thanh ghi du lieu, tang them 1 don vi
*/
#define WRITE_COUNT_H_REG 2
#define WRITE_COUNT_L_REG 3
/*
* thanh ghi DEVICE_STATUS_REG:
* - gia tri luc khoi tao: 0x03
* - y nghia cua cac bit:
* bit0:
* 0: cho biet cac thanh ghi du lieu dang khong san sang de doc
* 1: cho biet cac thanh ghi du lieu da san sang cho viec doc
* bit1:
* 0: cho biet cac thanh ghi du lieu dang khong san sang de ghi
* 1: cho biet cac thanh ghi du lieu da san sang cho viec ghi
* bit2:
* 0: khi cac thanh ghi du lieu bi xoa, bit nay se duoc thiet lap bang 0
* 1: khi toan bo cac thanh ghi du lieu da bi ghi, bit nay se duoc thiet lap bang 1
* bit3~7: chua dung toi
*/
#define DEVICE_STATUS_REG 4
#define STS_READ_ACCESS_BIT (1 << 0)
#define STS_WRITE_ACCESS_BIT (1 << 1)
#define STS_DATAREGS_OVERFLOW_BIT (1 << 2)
#define READY 1
#define NOT_READY 0
#define OVERFLOW 1
#define NOT_OVERFLOW 0
/****************** Mo ta cac thanh ghi trang thai: END ******************/
/****************** Mo ta cac thanh ghi dieu khien: START ******************/
/*
* thanh ghi CONTROL_ACCESS_REG:
* - vai tro: chua cac bit dieu khien kha nang doc/ghi cac thanh ghi du lieu
* - gia tri luc khoi tao: 0x03
* - y nghia:
* bit0:
* 0: khong cho phep doc tu cac thanh ghi du lieu
* 1: cho phep doc tu cac thanh ghi du lieu
* bit1:
* 0: khong cho phep ghi vao cac thanh ghi du lieu
* 1: cho phep ghi vao cac thanh ghi du lieu
* bit2~7: chua dung toi
*/
#define CONTROL_ACCESS_REG 0
#define CTRL_READ_DATA_BIT (1 << 0)
#define CTRL_WRITE_DATA_BIT (1 << 1)
#define ENABLE 1
#define DISABLE 0