-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathiodefs.c
90 lines (68 loc) · 2.22 KB
/
iodefs.c
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
/*
* Implementation of common IO tasks
*
* iodefs.c
*
* Created on: Feb 25, 2012
* Author: aah9038
*/
#include "iodefs.h"
#include <sys/mman.h>
void setPin(uintptr_t port, char pin, char value){
sem_wait(& port_mutex);
char current=in8(port);
if(value){
out8(port, current | (1<<pin));
}else{
out8(port,current & ~(1<<pin));
}
sem_post(&port_mutex);
}
/* ******************************************************************
* Initiaize register handles
*****************************************************************/
int initialize_handles(){
sem_init(&port_mutex,0,1);
cnt_base = mmap_device_io( PORT_LENGTH, CNT_BASE );
if ( cnt_base == MAP_DEVICE_FAILED ) {
perror( "cnt_base map failed" ); return EXIT_FAILURE;
}
cnt_base_plus = mmap_device_io(PORT_LENGTH, CNT_BASE +1);
if ( cnt_base_plus == MAP_DEVICE_FAILED ) {
perror( "cnt_base_plus map failed" ); return EXIT_FAILURE;
}
cnt_input_chan = mmap_device_io(PORT_LENGTH, INPUT_CHAN);
if ( cnt_input_chan == MAP_DEVICE_FAILED ) {
perror( "cnt_input_chan map failed" ); return EXIT_FAILURE;
}
cnt_output_chan_high = mmap_device_io(PORT_LENGTH, OUTPUT_CHAN_HIGH);
if ( cnt_output_chan_high == MAP_DEVICE_FAILED ) {
perror( "cnt_input_chan map failed" ); return EXIT_FAILURE;
}
cnt_output_chan_low = mmap_device_io(PORT_LENGTH, OUTPUT_CHAN_LOW);
if ( cnt_output_chan_low == MAP_DEVICE_FAILED ) {
perror( "cnt_input_chan map failed" ); return EXIT_FAILURE;
}
cnt_input_rng = mmap_device_io(PORT_LENGTH, INPUT_RNG);
if ( cnt_input_rng == MAP_DEVICE_FAILED ) {
perror( "cnt_input_rng map failed" ); return EXIT_FAILURE;
}
cnt_ddr = mmap_device_io(PORT_LENGTH, DDR);
if ( cnt_ddr == MAP_DEVICE_FAILED ) {
perror( "cnt_ddr map failed" ); return EXIT_FAILURE;
}
cnt_port_a = mmap_device_io(PORT_LENGTH, PORT_A);
if ( cnt_port_a == MAP_DEVICE_FAILED ) {
perror( "cnt_port_a map failed" ); return EXIT_FAILURE;
}
cnt_port_b = mmap_device_io(PORT_LENGTH, PORT_B);
if ( cnt_port_b == MAP_DEVICE_FAILED ) {
perror( "cnt_port_b map failed" ); return EXIT_FAILURE;
}
sem_wait(& port_mutex);
//Set input range to +/- 10V
out8(cnt_input_rng, 0x00);
sem_post(& port_mutex);
//SEE PAGE 68 of Athena manual SECTION 13.4
return EXIT_SUCCESS;
}