Skip to content

Commit 83bc7d5

Browse files
committed
Initial checkin of majority of design tree
1 parent bc6b686 commit 83bc7d5

31 files changed

+25996
-0
lines changed

README

1.95 KB
Binary file not shown.

application/application.c

+204
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
/*
2+
============================================================================
3+
Name : application.c
4+
Author : Daniel Bedard
5+
Version :
6+
Copyright : Your copyright notice
7+
Description : Hello World in C, Ansi-style
8+
============================================================================
9+
*/
10+
11+
#include <sys/termios.h>
12+
#include <stdio.h>
13+
#include <string.h>
14+
#include <fcntl.h>
15+
#include <stdlib.h>
16+
#include <unistd.h>
17+
#include <stdlib.h>
18+
#include <stdint.h>
19+
20+
#define VERSION_H 0
21+
#define VERSION_L 1
22+
#define OVF_FLAG 7
23+
#define TIME_FLAG 6
24+
#define DONE_FLAG 5
25+
26+
#define BAUDRATE B1000000
27+
#define V_FULLSCALE 26.52
28+
#define R_SENSE 0.00422 /* found empirically */
29+
#define I_FULLSCALE .10584
30+
31+
int g_serial_fd;
32+
FILE *g_serial_fp;
33+
struct termios g_oldtio, g_newtio;
34+
35+
int powermon_init();
36+
37+
void cleanup() {
38+
/* fprintf (stderr, "cleanup\n");*/
39+
powermon_init();
40+
tcflush(g_serial_fd, TCIFLUSH);
41+
tcsetattr(g_serial_fd, TCSANOW, &g_oldtio);
42+
close(g_serial_fd);
43+
}
44+
45+
int powermon_init() {
46+
char buffer[32];
47+
fprintf(g_serial_fp, "d\n");
48+
usleep(100000);
49+
fflush(g_serial_fp);
50+
usleep(100000);
51+
tcflush(g_serial_fd, TCIFLUSH);
52+
fprintf(g_serial_fp, "\n");
53+
fgets(buffer, sizeof(buffer), g_serial_fp);
54+
return strcmp(buffer, "OK\r\n");
55+
}
56+
57+
int powermon_set_mask(uint16_t mask) {
58+
char buffer[32];
59+
unsigned int length;
60+
unsigned int setval;
61+
length = sprintf(buffer, "m %u\n", mask);
62+
fwrite(buffer, 1, length, g_serial_fp);
63+
fgets(buffer, sizeof(buffer), g_serial_fp);
64+
sscanf(buffer, "M=%u\r", &setval);
65+
printf("Mask set to %u.\n", setval);
66+
fgets(buffer, sizeof(buffer), g_serial_fp);
67+
return strcmp(buffer, "OK\r\n");
68+
}
69+
70+
int powermon_set_samples(uint16_t interval, uint32_t num_samples) {
71+
char buffer[32];
72+
unsigned int length;
73+
unsigned int set_interval, set_num_samples;
74+
length = sprintf(buffer, "s %u %u\n", interval, num_samples);
75+
fwrite(buffer, 1, length, g_serial_fp);
76+
fgets(buffer, sizeof(buffer), g_serial_fp);
77+
sscanf(buffer, "S=%u,%u\r", &set_interval, &set_num_samples);
78+
printf("Sample interval set to %u. %u sample", set_interval,
79+
set_num_samples);
80+
if (set_num_samples != 1)
81+
printf("s");
82+
printf(" to be collected.\n");
83+
fgets(buffer, sizeof(buffer), g_serial_fp);
84+
return strcmp(buffer, "OK\r\n");
85+
}
86+
87+
int powermon_set_time(uint32_t now) {
88+
char buffer[32];
89+
unsigned int length;
90+
unsigned int setval;
91+
length = sprintf(buffer, "t %u\n", now);
92+
fwrite(buffer, 1, length, g_serial_fp);
93+
fgets(buffer, sizeof(buffer), g_serial_fp);
94+
sscanf(buffer, "T=%u\r", &setval);
95+
printf("Time set to %u.\n", setval);
96+
fgets(buffer, sizeof(buffer), g_serial_fp);
97+
return strcmp(buffer, "OK\r\n");
98+
}
99+
100+
int powermon_get_samples() {
101+
unsigned char buffer[4];
102+
unsigned int time; /* , reading; */
103+
uint16_t voltage, current;
104+
uint8_t flags, sensor;
105+
double v_double, i_double;
106+
fprintf(g_serial_fp, "e\n");
107+
for (;;) {
108+
fread(buffer, 1, 4, g_serial_fp);
109+
flags = buffer[0];
110+
/*reading = (((uint32_t)buffer[0] << 24) | ((uint32_t)buffer[1] << 16)
111+
| ((uint32_t)buffer[2] << 8) | ((uint32_t)buffer[3]));
112+
printf("bytes: %#x\n", reading);*/
113+
if (!(flags&(1<<TIME_FLAG)) && (flags&(1<<DONE_FLAG))) {
114+
break;
115+
}
116+
if(flags& (1 << OVF_FLAG)) {
117+
printf("*");
118+
}
119+
if (flags & (1 << TIME_FLAG)) {
120+
time = (((uint32_t)buffer[0] << 24) | ((uint32_t)buffer[1] << 16)
121+
| ((uint32_t)buffer[2] << 8) | ((uint32_t)buffer[3]))
122+
& 0x3FFFFFFF;
123+
printf("timestamp: %u\n", time);
124+
} else {
125+
sensor = (uint8_t)buffer[0] & 0x0F;
126+
voltage = ((uint16_t)buffer[1] << 4) | ((buffer[3] >> 4) & 0x0F);
127+
current = ((uint16_t)buffer[2] << 4) | (buffer[3] & 0x0F);
128+
v_double = (double)voltage / 4096 * V_FULLSCALE;
129+
i_double = (double)current / 4096 * I_FULLSCALE / R_SENSE;
130+
printf("sensor = %d, voltage = %fV, current = %fA\n", sensor, v_double, i_double);
131+
}
132+
}
133+
return 0;
134+
}
135+
136+
int configure_tty(const char *dev) {
137+
g_serial_fd = open(dev, O_RDWR | O_NOCTTY);
138+
if (g_serial_fd < 0) {
139+
perror(dev);
140+
return 1;
141+
}
142+
if ((g_serial_fp = fdopen(g_serial_fd, "r+")) == NULL) {
143+
perror("fdopen()");
144+
return 2;
145+
}
146+
tcgetattr(g_serial_fd, &g_oldtio); /* save current port settings */
147+
bzero(&g_newtio, sizeof (g_newtio));
148+
149+
/*
150+
CRTSCTS == hardware flow control
151+
CS8 = 8 bits
152+
CLOCAL = ignore modem control lines
153+
CREAD = enable receiver
154+
B38400 = baud rate
155+
*/
156+
g_newtio.c_iflag = IGNPAR;
157+
g_newtio.c_cflag = BAUDRATE | CS8 | CSTOPB | CLOCAL | CREAD;
158+
g_newtio.c_oflag = 0;
159+
160+
/* set input mode (non-canonical, no echo,...) */
161+
g_newtio.c_lflag = 0;
162+
163+
g_newtio.c_cc[VTIME] = 0; /* inter-character timer unused */
164+
g_newtio.c_cc[VMIN] = 1; /* blocking read until 1 char received */
165+
166+
tcflush(g_serial_fd, TCIFLUSH);
167+
tcsetattr(g_serial_fd, TCSANOW, &g_newtio);
168+
169+
return 0;
170+
}
171+
172+
int main(int argc, char **argv) {
173+
char dev[256];
174+
uint16_t sensor_mask;
175+
uint16_t sample_period;
176+
uint32_t num_samples = 0;
177+
if ((argc < 4) || (argc > 5)) {
178+
fprintf (stderr,
179+
"Usage:\n %s <port_dev> <mask> <sample_pd> [<num_samples>]\n\n",
180+
argv[0]);
181+
fprintf (stderr, "Example:\n%s /dev/ttyUSB1 1024 1 200\n", argv[0]);
182+
return 1;
183+
}
184+
strcpy (dev, argv[1]);
185+
sensor_mask = atoi(argv[2]);
186+
sample_period = atoi(argv[3]);
187+
if(argc == 5) {
188+
num_samples = atoi(argv[4]);
189+
}
190+
if (configure_tty(dev))
191+
exit(1);
192+
if (powermon_init())
193+
exit(1);
194+
if (powermon_set_mask(sensor_mask))
195+
exit(1);
196+
if (powermon_set_samples(sample_period, num_samples))
197+
exit(1);
198+
if (powermon_set_time(1))
199+
exit(1);
200+
powermon_get_samples();
201+
atexit(cleanup);
202+
return 0;
203+
204+
}

assembly/pm-bom.xlsx

14.4 KB
Binary file not shown.

assembly/pm-cablea.xlsx

14.3 KB
Binary file not shown.

assembly/pm-cableb.xlsx

15.6 KB
Binary file not shown.

assembly/pm-centroid.csv

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
Screaming Circuits SMD component position file.
2+
3+
Centroid Data for pc board: "drivebay pm.brd" as of: 8/4/2011 6:23:17 PM
4+
Measurements are in inches. Comma delimited
5+
Only surface mount components included
6+
7+
RefDes,Layer,LocationX,LocationY,Rotation
8+
C201,Top,0.670,3.670,90
9+
C202,Top,0.710,3.560,180
10+
C203,Top,1.020,3.320,180
11+
C204,Top,0.880,3.320,0
12+
C205,Top,1.340,3.470,90
13+
C206,Top,1.260,3.470,90
14+
J101,Top,0.190,2.840,270
15+
J102,Bottom,0.190,2.840,90
16+
J103,Top,0.190,1.960,270
17+
J104,Bottom,0.190,1.960,90
18+
J105,Top,0.190,0.780,270
19+
J106,Bottom,0.190,0.780,90
20+
J201,Top,0.160,3.560,0
21+
L201,Top,0.750,3.670,270
22+
R201,Top,1.940,3.570,0
23+
R202,Top,1.940,3.640,0
24+
R301,Top,1.300,2.250,0
25+
R303,Top,2.070,2.570,180
26+
R304,Top,2.070,2.520,0
27+
R305,Top,2.070,2.420,180
28+
R306,Top,2.070,2.470,0
29+
R307,Bottom,1.300,2.000,0
30+
R309,Bottom,2.070,2.170,0
31+
R310,Bottom,2.070,2.220,180
32+
R311,Bottom,2.070,2.330,0
33+
R312,Bottom,2.070,2.280,180
34+
R313,Top,1.300,1.750,0
35+
R315,Top,2.070,2.080,180
36+
R316,Top,2.070,2.030,0
37+
R317,Top,2.070,1.920,180
38+
R318,Top,2.070,1.970,0
39+
R319,Top,1.300,1.250,0
40+
R321,Top,2.070,1.580,180
41+
R322,Top,2.070,1.530,0
42+
R323,Top,2.070,1.430,180
43+
R324,Top,2.070,1.480,0
44+
R401,Bottom,1.300,1.000,0
45+
R403,Bottom,2.070,1.170,0
46+
R404,Bottom,2.070,1.220,180
47+
R405,Bottom,2.070,1.330,0
48+
R406,Bottom,2.070,1.280,180
49+
R407,Top,1.300,0.750,0
50+
R409,Top,2.070,1.090,180
51+
R410,Top,2.070,1.040,0
52+
R411,Top,2.070,0.930,180
53+
R412,Top,2.070,0.980,0
54+
R413,Bottom,1.300,0.500,0
55+
R415,Bottom,2.070,0.670,0
56+
R416,Bottom,2.070,0.720,180
57+
R417,Bottom,2.070,0.830,0
58+
R418,Bottom,2.070,0.780,180
59+
R419,Top,1.300,0.250,0
60+
R421,Top,2.070,0.590,180
61+
R422,Top,2.070,0.540,0
62+
R423,Top,2.070,0.430,180
63+
R424,Top,2.070,0.480,0
64+
U201,Top,1.010,3.560,180
65+
U202,Top,1.620,3.400,0
66+
U301,Top,1.330,2.500,0
67+
U302,Bottom,1.270,2.250,0
68+
U303,Top,1.330,2.000,0
69+
U304,Top,1.330,1.500,0
70+
U401,Bottom,1.270,1.250,0
71+
U402,Top,1.330,1.000,0
72+
U403,Bottom,1.270,0.750,0
73+
U404,Top,1.330,0.500,0
74+
X201,Top,1.300,3.200,270

assembly/pm-chassis.pdf

83.1 KB
Binary file not shown.

assembly/pm-compd.pdf

65.9 KB
Binary file not shown.

assembly/pm-compm.pdf

21.7 KB
Binary file not shown.

assembly/powermon fabrication.xlsx

12.6 KB
Binary file not shown.

assembly/powermon in chassis.easm

63.9 KB
Binary file not shown.

assembly/programming instructions

Whitespace-only changes.

0 commit comments

Comments
 (0)