Skip to content

Commit e9be716

Browse files
committed
minimal changes to cxip for latest libchan
1 parent 7fe7aab commit e9be716

File tree

4 files changed

+174
-196
lines changed

4 files changed

+174
-196
lines changed

cxip/cxip.c

Lines changed: 62 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ size_t xxx_buf_len = 0;
2727
bool serve(int listen_sock, struct chan_out *chan);
2828
void handle_client(int sock, struct chan_out *chan);
2929
void handle_message(int sock, struct chan_out *chan, uint8_t *msg, size_t msg_len);
30-
void test_and_send_status(int sock, struct chan_out *chan, uint8_t addr);
30+
void send_status(int sock, struct chan_out *chan, uint8_t addr, uint8_t device_status);
3131
void purge_status(struct chan_out *chan, uint8_t addr);
3232

3333
int main(int argc, char **argv)
@@ -81,21 +81,23 @@ int main(int argc, char **argv)
8181
return EXIT_FAILURE;
8282
}
8383

84+
chan_out_enable(&chan);
85+
8486
struct mock_cu mock_cu;
8587

8688
if (mock_cu_open(&mock_cu, 0x40001000, mem_fd) < 0) {
8789
perror("mock_cu_open");
8890
return EXIT_FAILURE;
8991
}
9092

91-
mock_cu_arrange(&mock_cu, false, false, 16);
93+
mock_cu_arrange(&mock_cu, false, false, false, 16);
9294

9395
if (!serve(listen_sock, &chan)) {
9496
return EXIT_FAILURE;
9597
}
9698

9799
mock_cu_close(&mock_cu);
98-
chan_out_close(&chan, true);
100+
chan_out_close(&chan);
99101

100102
close(listen_sock);
101103
close(mem_fd);
@@ -143,11 +145,13 @@ bool serve(int listen_sock, struct chan_out *chan)
143145
if (client_sock == -1) {
144146
client_sock = sock;
145147

146-
xxx_buf_len = 0; // Reset, for new client...
147-
purge_status(chan, ADDR);
148+
xxx_buf_len = 0; // Reset, for new client...
148149

149150
printf("CONNECTED\n");
150151

152+
chan_out_config(chan, ADDR /* TODO */, true);
153+
purge_status(chan, ADDR);
154+
151155
ev.events = EPOLLIN | EPOLLET | EPOLLRDHUP | EPOLLHUP;
152156
ev.data.fd = client_sock;
153157

@@ -156,6 +160,8 @@ purge_status(chan, ADDR);
156160
return false;
157161
}
158162

163+
printf("READY\n");
164+
159165
//test_and_send_status(client_sock, chan, ADDR /* TODO */);
160166
} else {
161167
printf("CONNECTION REJECTED\n");
@@ -171,6 +177,8 @@ purge_status(chan, ADDR);
171177
if (event.events & (EPOLLRDHUP | EPOLLHUP)) {
172178
assert(event.data.fd == client_sock);
173179

180+
chan_out_config(chan, ADDR /* TODO */, false);
181+
174182
epoll_ctl(epfd, EPOLL_CTL_DEL, client_sock, NULL);
175183

176184
close(client_sock);
@@ -181,12 +189,21 @@ purge_status(chan, ADDR);
181189
}
182190
}
183191

184-
// Check for request in.
192+
// Check for unsolicited status.
185193
if (client_sock != -1) {
186-
if (chan_out_request_in(chan)) {
187-
printf("REQUEST IN...\n");
194+
uint8_t device_status;
195+
196+
int result = chan_out_test(chan, ADDR /* TODO */, &device_status);
197+
198+
if (result < 0) {
199+
printf("chan_out_test error: %d\n", result);
200+
return false;
201+
}
202+
203+
if (result) {
204+
printf("Unsolicited status: 0x%.2x\n", device_status);
188205

189-
test_and_send_status(client_sock, chan, ADDR /* TODO */);
206+
send_status(client_sock, chan, ADDR /* TODO */, device_status);
190207
}
191208
}
192209
}
@@ -296,9 +313,9 @@ void handle_message(int sock, struct chan_out *chan, uint8_t *msg, size_t msg_le
296313

297314
printf("\taddr = %.2x, cmd = %.2x, flags = %.2x, count = %zu\n", addr, cmd, flags, count);
298315

299-
ssize_t result = chan_out_exec(chan, ADDR /* TODO */, cmd, data, count);
316+
uint8_t device_status;
300317

301-
uint8_t device_status = chan_out_device_status(chan);
318+
ssize_t result = chan_exec(chan, ADDR /* TODO */, cmd, 0, data, count, &device_status);
302319

303320
/*
304321
ssize_t result;
@@ -333,31 +350,31 @@ void handle_message(int sock, struct chan_out *chan, uint8_t *msg, size_t msg_le
333350
printf("\tresult = %zd, status = %.2x\n", result, device_status);
334351

335352
// special hack for DE...
336-
if ((device_status & CHAN_STATUS_CE) && !(device_status & CHAN_STATUS_DE)) {
337-
result = 0;
338-
339-
// wait for it via request in...
340-
printf("\tgot CE without DE, waiting for DE via request in...\n");
341-
342-
while (!chan_out_request_in(chan)) {
343-
usleep(100000); // 100ms
344-
}
345-
346-
int test_result = chan_out_test(chan, ADDR /* TODO */);
347-
348-
if (test_result < 0) {
349-
printf("\ttest result = %d\n", test_result);
350-
return;
351-
}
352-
353-
device_status |= chan_out_device_status(chan);
354-
355-
printf("\tupdated status = %.2x\n", device_status);
356-
357-
if (!(device_status & CHAN_STATUS_DE)) {
358-
printf("\tstill no DE...\n");
359-
}
360-
}
353+
//if ((device_status & CHAN_STATUS_CE) && !(device_status & CHAN_STATUS_DE)) {
354+
// result = 0;
355+
//
356+
// // wait for it via request in...
357+
// printf("\tgot CE without DE, waiting for DE via request in...\n");
358+
//
359+
// while (!chan_out_request_in(chan)) {
360+
// usleep(100000); // 100ms
361+
// }
362+
//
363+
// int test_result = chan_out_test(chan, ADDR /* TODO */);
364+
//
365+
// if (test_result < 0) {
366+
// printf("\ttest result = %d\n", test_result);
367+
// return;
368+
// }
369+
//
370+
// device_status |= chan_out_device_status(chan);
371+
//
372+
// printf("\tupdated status = %.2x\n", device_status);
373+
//
374+
// if (!(device_status & CHAN_STATUS_DE)) {
375+
// printf("\tstill no DE...\n");
376+
// }
377+
//}
361378

362379
buf[2] = 4; // EXEC RESPONSE
363380

@@ -388,21 +405,10 @@ void handle_message(int sock, struct chan_out *chan, uint8_t *msg, size_t msg_le
388405
}
389406
}
390407

391-
void test_and_send_status(int sock, struct chan_out *chan, uint8_t addr)
408+
void send_status(int sock, struct chan_out *chan, uint8_t addr, uint8_t device_status)
392409
{
393410
uint8_t buf[MSG_BUF_SIZE];
394411

395-
int result = chan_out_test(chan, addr);
396-
397-
if (result < 0) {
398-
printf("\tresult = %d\n", result);
399-
return;
400-
}
401-
402-
uint8_t device_status = chan_out_device_status(chan);
403-
404-
printf("\tstatus = %.2x\n", device_status);
405-
406412
buf[0] = 0;
407413
buf[1] = 3;
408414
buf[2] = 5; // STATUS
@@ -418,16 +424,21 @@ void purge_status(struct chan_out *chan, uint8_t addr)
418424
{
419425
// Very hacky... this is no way to do error recovery!
420426
while (true) {
421-
printf("TEST...\n");
427+
printf("PURGE...\n");
428+
429+
uint8_t status;
422430

423-
int result = chan_out_test(chan, addr);
431+
int result = chan_out_test(chan, addr, &status);
424432

425433
if (result < 0) {
426434
printf("\tresult = %d\n", result);
427435
return;
428436
}
429437

430-
uint8_t status = chan_out_device_status(chan);
438+
if (result == 0) {
439+
printf("\tno pending status\n");
440+
break;
441+
}
431442

432443
printf("\tstatus = 0x%.2x\n", status);
433444

cxip/hercules/cxip.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ static int cxip_init_handler(DEVBLK *dev, int argc, char **argv)
119119
struct sockaddr_in addr;
120120

121121
addr.sin_family = AF_INET;
122-
inet_pton(AF_INET, "192.168.1.132", &(addr.sin_addr));
122+
inet_pton(AF_INET, "10.83.5.62", &(addr.sin_addr));
123123
addr.sin_port = htons(3174);
124124

125125
if (connect(cxip->sock, (struct sockaddr *) &addr, sizeof(addr)) < 0) {

0 commit comments

Comments
 (0)