projects
/
fw
/
altos
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge ccdbg and altos sources into one giant repository
[fw/altos]
/
lib
/
cc-usb.c
diff --git
a/lib/cc-usb.c
b/lib/cc-usb.c
index 09b06bb54054b2e71c2e5c8c7b4ea8b175fce2f0..dc764c24e99f79fd326226cbb8f795063ab58340 100644
(file)
--- a/
lib/cc-usb.c
+++ b/
lib/cc-usb.c
@@
-31,7
+31,11
@@
#define CC_NUM_READ 16
#define CC_NUM_READ 16
-#define CC_BUF 1024
+/*
+ * AltOS has different buffer sizes for in/out packets
+ */
+#define CC_IN_BUF 256
+#define CC_OUT_BUF 64
#define DEFAULT_TTY "/dev/ttyACM0"
struct cc_read {
#define DEFAULT_TTY "/dev/ttyACM0"
struct cc_read {
@@
-41,9
+45,9
@@
struct cc_read {
struct cc_usb {
int fd;
struct cc_usb {
int fd;
- uint8_t in_buf[CC_BUF];
+ uint8_t in_buf[CC_
IN_
BUF];
int in_count;
int in_count;
- uint8_t out_buf[CC_BUF];
+ uint8_t out_buf[CC_
OUT_
BUF];
int out_count;
struct cc_read read_buf[CC_NUM_READ];
int read_count;
int out_count;
struct cc_read read_buf[CC_NUM_READ];
int read_count;
@@
-73,14
+77,14
@@
cc_handle_in(struct cc_usb *cc)
uint8_t h, l;
int in_pos;
int read_pos;
uint8_t h, l;
int in_pos;
int read_pos;
-
+
in_pos = 0;
read_pos = 0;
while (read_pos < cc->read_count && in_pos < cc->in_count) {
/*
* Skip to next hex character
*/
in_pos = 0;
read_pos = 0;
while (read_pos < cc->read_count && in_pos < cc->in_count) {
/*
* Skip to next hex character
*/
- while (in_pos < cc->in_count &&
+ while (in_pos < cc->in_count &&
cc_hex_nibble(cc->in_buf[in_pos]) == NOT_HEX)
in_pos++;
/*
cc_hex_nibble(cc->in_buf[in_pos]) == NOT_HEX)
in_pos++;
/*
@@
-105,7
+109,7
@@
cc_handle_in(struct cc_usb *cc)
if (--cc->read_buf[read_pos].len <= 0)
read_pos++;
}
if (--cc->read_buf[read_pos].len <= 0)
read_pos++;
}
-
+
/* Move remaining bytes to the start of the input buffer */
if (in_pos) {
memmove(cc->in_buf, cc->in_buf + in_pos,
/* Move remaining bytes to the start of the input buffer */
if (in_pos) {
memmove(cc->in_buf, cc->in_buf + in_pos,
@@
-167,7
+171,7
@@
cc_usb_sync(struct cc_usb *cc)
else
timeout = 0;
fds.events = 0;
else
timeout = 0;
fds.events = 0;
- if (cc->in_count < CC_BUF)
+ if (cc->in_count < CC_
IN_
BUF)
fds.events |= POLLIN;
if (cc->out_count)
fds.events |= POLLOUT;
fds.events |= POLLIN;
if (cc->out_count)
fds.events |= POLLOUT;
@@
-180,12
+184,13
@@
cc_usb_sync(struct cc_usb *cc)
}
if (fds.revents & POLLIN) {
ret = read(cc->fd, cc->in_buf + cc->in_count,
}
if (fds.revents & POLLIN) {
ret = read(cc->fd, cc->in_buf + cc->in_count,
- CC_BUF - cc->in_count);
+ CC_
IN_
BUF - cc->in_count);
if (ret > 0) {
cc_usb_dbg(24, cc->in_buf + cc->in_count, ret);
cc->in_count += ret;
cc_handle_in(cc);
if (ret > 0) {
cc_usb_dbg(24, cc->in_buf + cc->in_count, ret);
cc->in_count += ret;
cc_handle_in(cc);
- }
+ } else if (ret < 0)
+ perror("read");
}
if (fds.revents & POLLOUT) {
ret = write(cc->fd, cc->out_buf,
}
if (fds.revents & POLLOUT) {
ret = write(cc->fd, cc->out_buf,
@@
-196,7
+201,8
@@
cc_usb_sync(struct cc_usb *cc)
cc->out_buf + ret,
cc->out_count - ret);
cc->out_count -= ret;
cc->out_buf + ret,
cc->out_count - ret);
cc->out_count -= ret;
- }
+ } else if (ret < 0)
+ perror("write");
}
}
}
}
}
}
@@
-207,7
+213,7
@@
cc_usb_printf(struct cc_usb *cc, char *format, ...)
char buf[1024], *b;
va_list ap;
int ret, this_time;
char buf[1024], *b;
va_list ap;
int ret, this_time;
-
+
/* sprintf to a local buffer */
va_start(ap, format);
ret = vsnprintf(buf, sizeof(buf), format, ap);
/* sprintf to a local buffer */
va_start(ap, format);
ret = vsnprintf(buf, sizeof(buf), format, ap);
@@
-221,13
+227,13
@@
cc_usb_printf(struct cc_usb *cc, char *format, ...)
b = buf;
while (ret > 0) {
this_time = ret;
b = buf;
while (ret > 0) {
this_time = ret;
- if (this_time > CC_BUF - cc->out_count)
- this_time = CC_BUF - cc->out_count;
+ if (this_time > CC_
OUT_
BUF - cc->out_count)
+ this_time = CC_
OUT_
BUF - cc->out_count;
memcpy(cc->out_buf + cc->out_count, b, this_time);
cc->out_count += this_time;
ret -= this_time;
b += this_time;
memcpy(cc->out_buf + cc->out_count, b, this_time);
cc->out_count += this_time;
ret -= this_time;
b += this_time;
- while (cc->out_count >= CC_BUF)
+ while (cc->out_count >= CC_
OUT_
BUF)
cc_usb_sync(cc);
}
}
cc_usb_sync(cc);
}
}
@@
-237,7
+243,7
@@
cc_usb_send_bytes(struct cc_usb *cc, uint8_t *bytes, int len)
{
int this_len;
int ret = len;
{
int this_len;
int ret = len;
-
+
while (len) {
this_len = len;
if (this_len > 8)
while (len) {
this_len = len;
if (this_len > 8)
@@
-317,13
+323,11
@@
cc_usb_reset(struct cc_usb *cc)
static struct termios save_termios;
struct cc_usb *
static struct termios save_termios;
struct cc_usb *
-cc_usb_open(
void
)
+cc_usb_open(
char *tty
)
{
struct cc_usb *cc;
{
struct cc_usb *cc;
- char *tty;
struct termios termios;
struct termios termios;
-
- tty = getenv("CCDBG_TTY");
+
if (!tty)
tty = DEFAULT_TTY;
cc = calloc (sizeof (struct cc_usb), 1);
if (!tty)
tty = DEFAULT_TTY;
cc = calloc (sizeof (struct cc_usb), 1);
@@
-353,4
+357,3
@@
cc_usb_close(struct cc_usb *cc)
close (cc->fd);
free (cc);
}
close (cc->fd);
free (cc);
}
-