projects
/
fw
/
altos
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add new binaries to .gitignore
[fw/altos]
/
ao_usb.c
diff --git
a/ao_usb.c
b/ao_usb.c
index 3e9bb5b39c4ddb153a4fdc29e77646475b304333..c1520d750fc7e7c13c8790636f4da7e596df957e 100644
(file)
--- a/
ao_usb.c
+++ b/
ao_usb.c
@@
-32,10
+32,10
@@
struct ao_task __xdata ao_usb_task;
#define AO_USB_IN_SIZE 256
#define AO_USB_OUT_SIZE 128
#define AO_USB_IN_SIZE 256
#define AO_USB_OUT_SIZE 128
-static uint16_t ao_usb_in_bytes;
-static uint16_t ao_usb_out_bytes;
-static __
data uint8_t
ao_usb_iif;
-static __
data uint8_t
ao_usb_oif;
+static
__xdata
uint16_t ao_usb_in_bytes;
+static
__xdata
uint16_t ao_usb_out_bytes;
+static __
xdata uint8_t
ao_usb_iif;
+static __
xdata uint8_t
ao_usb_oif;
/* This interrupt is shared with port 2,
* so when we hook that up, fix this
/* This interrupt is shared with port 2,
* so when we hook that up, fix this
@@
-65,22
+65,22
@@
struct ao_usb_setup {
uint16_t value;
uint16_t index;
uint16_t length;
uint16_t value;
uint16_t index;
uint16_t length;
-} ao_usb_setup;
+}
__xdata
ao_usb_setup;
-__data uint8_t ao_usb_ep0_state;
-uint8_t * __data ao_usb_ep0_in_data;
-__data uint8_t ao_usb_ep0_in_len;
+__
x
data uint8_t ao_usb_ep0_state;
+uint8_t * __
x
data ao_usb_ep0_in_data;
+__
x
data uint8_t ao_usb_ep0_in_len;
__xdata uint8_t ao_usb_ep0_in_buf[2];
__xdata uint8_t ao_usb_ep0_in_buf[2];
-__data uint8_t ao_usb_ep0_out_len;
+__
x
data uint8_t ao_usb_ep0_out_len;
__xdata uint8_t *__data ao_usb_ep0_out_data;
__xdata uint8_t *__data ao_usb_ep0_out_data;
-__data uint8_t ao_usb_configuration;
+__
x
data uint8_t ao_usb_configuration;
/* Send an IN data packet */
static void
ao_usb_ep0_flush(void)
{
/* Send an IN data packet */
static void
ao_usb_ep0_flush(void)
{
- uint8_t this_len;
- uint8_t cs0;
+
__xdata
uint8_t this_len;
+
__xdata
uint8_t cs0;
USBINDEX = 0;
cs0 = USBCS0;
USBINDEX = 0;
cs0 = USBCS0;
@@
-102,7
+102,7
@@
ao_usb_ep0_flush(void)
USBCS0 = cs0;
}
USBCS0 = cs0;
}
-#define LE_WORD(x) ((x)&0xFF),((
x)>>8
)
+#define LE_WORD(x) ((x)&0xFF),((
uint8_t) (((uint16_t) (x))>>8)
)
/* CDC definitions */
#define CS_INTERFACE 0x24
/* CDC definitions */
#define CS_INTERFACE 0x24
@@
-120,7
+120,7
@@
struct ao_usb_line_coding {
uint8_t data_bits;
} ;
uint8_t data_bits;
} ;
-static struct ao_usb_line_coding ao_usb_line_coding = {115200, 0, 0, 8};
+
__xdata
static struct ao_usb_line_coding ao_usb_line_coding = {115200, 0, 0, 8};
/* USB descriptors in one giant block of bytes */
static const uint8_t ao_usb_descriptors [] =
/* USB descriptors in one giant block of bytes */
static const uint8_t ao_usb_descriptors [] =
@@
-241,7
+241,7
@@
static const uint8_t ao_usb_descriptors [] =
/* iSerial */
0x0e,
AO_USB_DESC_STRING,
/* iSerial */
0x0e,
AO_USB_DESC_STRING,
- '
t', 0, 'e', 0, 'l', 0, 'e', 0, '-
', 0, '0', 0,
+ '
0', 0, '0', 0, '0', 0, '0', 0, '0
', 0, '0', 0,
/* Terminating zero */
0
/* Terminating zero */
0
@@
-252,9
+252,9
@@
static const uint8_t ao_usb_descriptors [] =
static void
ao_usb_get_descriptor(uint16_t value)
{
static void
ao_usb_get_descriptor(uint16_t value)
{
- const uint8_t
*
descriptor;
- uint8_t type = value >> 8;
- uint8_t index = value;
+ const uint8_t
*__xdata
descriptor;
+
__xdata
uint8_t type = value >> 8;
+
__xdata
uint8_t index = value;
descriptor = ao_usb_descriptors;
while (descriptor[0] != 0) {
descriptor = ao_usb_descriptors;
while (descriptor[0] != 0) {
@@
-275,7
+275,7
@@
ao_usb_get_descriptor(uint16_t value)
static void
ao_usb_ep0_fill(void)
{
static void
ao_usb_ep0_fill(void)
{
- uint8_t len;
+
__xdata
uint8_t len;
USBINDEX = 0;
len = USBCNT0;
USBINDEX = 0;
len = USBCNT0;
@@
-303,19
+303,15
@@
ao_usb_set_address(uint8_t address)
static void
ao_usb_set_configuration(void)
{
static void
ao_usb_set_configuration(void)
{
- uint8_t size;
-
/* Set the IN max packet size, double buffered */
USBINDEX = AO_USB_IN_EP;
/* Set the IN max packet size, double buffered */
USBINDEX = AO_USB_IN_EP;
- size = AO_USB_IN_SIZE >> 3;
- USBMAXI = size;
-// USBCSIH |= USBCSIH_IN_DBL_BUF;
+ USBMAXI = AO_USB_IN_SIZE >> 3;
+ USBCSIH |= USBCSIH_IN_DBL_BUF;
/* Set the OUT max packet size, double buffered */
USBINDEX = AO_USB_OUT_EP;
/* Set the OUT max packet size, double buffered */
USBINDEX = AO_USB_OUT_EP;
- size = AO_USB_OUT_SIZE >> 3;
- USBMAXO = size;
-// USBCSOH = USBCSOH_OUT_DBL_BUF;
+ USBMAXO = AO_USB_OUT_SIZE >> 3;
+ USBCSOH = USBCSOH_OUT_DBL_BUF;
}
static void
}
static void
@@
-373,6
+369,7
@@
ao_usb_ep0_setup(void)
}
break;
case AO_USB_RECIP_INTERFACE:
}
break;
case AO_USB_RECIP_INTERFACE:
+ #pragma disable_warning 110
switch(ao_usb_setup.request) {
case AO_USB_REQ_GET_STATUS:
ao_usb_ep0_queue_byte(0);
switch(ao_usb_setup.request) {
case AO_USB_REQ_GET_STATUS:
ao_usb_ep0_queue_byte(0);
@@
-421,19
+418,17
@@
ao_usb_ep0_setup(void)
static void
ao_usb_ep0(void)
{
static void
ao_usb_ep0(void)
{
- uint8_t cs0;
+
__xdata
uint8_t cs0;
ao_usb_ep0_state = AO_USB_EP0_IDLE;
for (;;) {
ao_usb_ep0_state = AO_USB_EP0_IDLE;
for (;;) {
- ao_interrupt_disable();
- for (;;) {
+ __critical for (;;) {
if (ao_usb_iif & 1) {
ao_usb_iif &= ~1;
break;
}
ao_sleep(&ao_usb_task);
}
if (ao_usb_iif & 1) {
ao_usb_iif &= ~1;
break;
}
ao_sleep(&ao_usb_task);
}
- ao_interrupt_enable();
USBINDEX = 0;
cs0 = USBCS0;
if (cs0 & USBCS0_SETUP_END) {
USBINDEX = 0;
cs0 = USBCS0;
if (cs0 & USBCS0_SETUP_END) {
@@
-470,21
+465,18
@@
ao_usb_ep0(void)
}
void
}
void
-ao_usb_flush(void)
+ao_usb_flush(void)
__critical
{
{
- ao_interrupt_disable();
if (ao_usb_in_bytes) {
USBINDEX = AO_USB_IN_EP;
USBCSIL |= USBCSIL_INPKT_RDY;
ao_usb_in_bytes = 0;
}
if (ao_usb_in_bytes) {
USBINDEX = AO_USB_IN_EP;
USBCSIL |= USBCSIL_INPKT_RDY;
ao_usb_in_bytes = 0;
}
- ao_interrupt_enable();
}
void
}
void
-ao_usb_putchar(uint8_t c)
+ao_usb_putchar(uint8_t c)
__critical
{
{
- ao_interrupt_disable();
for (;;) {
USBINDEX = AO_USB_IN_EP;
if ((USBCSIL & USBCSIL_INPKT_RDY) == 0)
for (;;) {
USBINDEX = AO_USB_IN_EP;
if ((USBCSIL & USBCSIL_INPKT_RDY) == 0)
@@
-492,16
+484,17
@@
ao_usb_putchar(uint8_t c)
ao_sleep(&ao_usb_in_bytes);
}
USBFIFO[AO_USB_IN_EP << 1] = c;
ao_sleep(&ao_usb_in_bytes);
}
USBFIFO[AO_USB_IN_EP << 1] = c;
- if (++ao_usb_in_bytes == AO_USB_IN_SIZE)
- ao_usb_flush();
- ao_interrupt_enable();
+ if (++ao_usb_in_bytes == AO_USB_IN_SIZE) {
+ USBINDEX = AO_USB_IN_EP;
+ USBCSIL |= USBCSIL_INPKT_RDY;
+ ao_usb_in_bytes = 0;
+ }
}
uint8_t
}
uint8_t
-ao_usb_getchar(void)
+ao_usb_getchar(void)
__critical
{
{
- uint8_t c;
- ao_interrupt_disable();
+ __xdata uint8_t c;
while (ao_usb_out_bytes == 0) {
for (;;) {
USBINDEX = AO_USB_OUT_EP;
while (ao_usb_out_bytes == 0) {
for (;;) {
USBINDEX = AO_USB_OUT_EP;
@@
-517,7
+510,6
@@
ao_usb_getchar(void)
USBINDEX = AO_USB_OUT_EP;
USBCSOL &= ~USBCSOL_OUTPKT_RDY;
}
USBINDEX = AO_USB_OUT_EP;
USBCSOL &= ~USBCSOL_OUTPKT_RDY;
}
- ao_interrupt_enable();
return c;
}
return c;
}
@@
-546,5
+538,5
@@
ao_usb_init(void)
USBOIF = 0;
USBIIF = 0;
USBOIF = 0;
USBIIF = 0;
- ao_add_task(&ao_usb_task, ao_usb_ep0);
+ ao_add_task(&ao_usb_task, ao_usb_ep0
, "usb"
);
}
}