projects
/
fw
/
altos
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
altos/telelco-v3.0: Merge info into one screen
[fw/altos]
/
src
/
stm
/
ao_usb_stm.c
diff --git
a/src/stm/ao_usb_stm.c
b/src/stm/ao_usb_stm.c
index 27b82357843d3d278b815165b99ecfdc97555f2a..8b6d95d866c41fe8f7406a6a00007aab7feea2c3 100644
(file)
--- a/
src/stm/ao_usb_stm.c
+++ b/
src/stm/ao_usb_stm.c
@@
-3,7
+3,8
@@
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
@@
-117,7
+118,7
@@
static uint8_t ao_usb_in_pending;
* but not pulled to the shadow buffer.
*/
static uint8_t ao_usb_out_avail;
* but not pulled to the shadow buffer.
*/
static uint8_t ao_usb_out_avail;
-
static uint8_t
ao_usb_running;
+
uint8_t
ao_usb_running;
static uint8_t ao_usb_configuration;
#define AO_USB_EP0_GOT_RESET 1
static uint8_t ao_usb_configuration;
#define AO_USB_EP0_GOT_RESET 1
@@
-138,7
+139,7
@@
static inline uint32_t set_toggle(uint32_t current_value,
static inline uint32_t *ao_usb_packet_buffer_addr(uint16_t sram_addr)
{
static inline uint32_t *ao_usb_packet_buffer_addr(uint16_t sram_addr)
{
- return (uint32_t *) (
stm_usb_sram + 2 * sram_addr
);
+ return (uint32_t *) (
((void *) ((uint8_t *) stm_usb_sram + 2 * sram_addr))
);
}
static inline uint32_t ao_usb_epr_stat_rx(uint32_t epr) {
}
static inline uint32_t ao_usb_epr_stat_rx(uint32_t epr) {
@@
-173,7
+174,7
@@
static inline uint32_t ao_usb_epr_dtog_tx(uint32_t epr) {
* Set current device address and mark the
* interface as active
*/
* Set current device address and mark the
* interface as active
*/
-void
+
static
void
ao_usb_set_address(uint8_t address)
{
debug("ao_usb_set_address %02x\n", address);
ao_usb_set_address(uint8_t address)
{
debug("ao_usb_set_address %02x\n", address);
@@
-312,7
+313,7
@@
ao_usb_init_ep(uint8_t ep, uint32_t addr, uint32_t type, uint32_t stat_rx, uint3
static void
ao_usb_set_ep0(void)
{
static void
ao_usb_set_ep0(void)
{
-
int
e;
+
uint8_t
e;
ao_usb_sram_addr = 0;
ao_usb_sram_addr = 0;
@@
-349,6
+350,19
@@
ao_usb_set_ep0(void)
}
ao_usb_set_address(0);
}
ao_usb_set_address(0);
+
+ ao_usb_running = 0;
+
+ /* Reset our internal state
+ */
+
+ ao_usb_ep0_state = AO_USB_EP0_IDLE;
+
+ ao_usb_ep0_in_data = NULL;
+ ao_usb_ep0_in_len = 0;
+
+ ao_usb_ep0_out_data = 0;
+ ao_usb_ep0_out_len = 0;
}
static void
}
static void
@@
-393,7
+407,15
@@
ao_usb_set_configuration(void)
STM_USB_EPR_STAT_RX_DISABLED,
STM_USB_EPR_STAT_TX_NAK);
STM_USB_EPR_STAT_RX_DISABLED,
STM_USB_EPR_STAT_TX_NAK);
+ ao_usb_in_flushed = 0;
+ ao_usb_in_pending = 0;
+ ao_wakeup(&ao_usb_in_pending);
+
+ ao_usb_out_avail = 0;
+ ao_usb_configuration = 0;
+
ao_usb_running = 1;
ao_usb_running = 1;
+ ao_wakeup(&ao_usb_running);
}
static uint16_t control_count;
}
static uint16_t control_count;
@@
-424,18
+446,14
@@
ao_usb_write_short(uint16_t data, uint32_t *base, uint16_t offset)
}
static void
}
static void
-ao_usb_write(const uint8_t *src, uint32_t *base, uint16_t
offset, uint16_t
bytes)
+ao_usb_write(const uint8_t *src, uint32_t *base, uint16_t bytes)
{
{
+ uint16_t offset = 0;
if (!bytes)
return;
if (!bytes)
return;
- if (offset & 1) {
- debug_data (" %02x", src[0]);
- ao_usb_write_byte(*src++, base, offset++);
- bytes--;
- }
while (bytes >= 2) {
debug_data (" %02x %02x", src[0], src[1]);
while (bytes >= 2) {
debug_data (" %02x %02x", src[0], src[1]);
- ao_usb_write_short((
src[1] << 8) | src[0]
, base, offset);
+ ao_usb_write_short((
uint16_t) ((uint16_t) (src[1] << 8) | (uint16_t) src[0])
, base, offset);
offset += 2;
src += 2;
bytes -= 2;
offset += 2;
src += 2;
bytes -= 2;
@@
-459,7
+477,7
@@
ao_usb_read_byte(uint32_t *base, uint16_t offset)
static inline uint16_t
ao_usb_read_short(uint32_t *base, uint16_t offset)
{
static inline uint16_t
ao_usb_read_short(uint32_t *base, uint16_t offset)
{
- return
base[offset>>1]
;
+ return
(uint16_t) (base[offset>>1])
;
}
static void
}
static void
@@
-474,8
+492,8
@@
ao_usb_read(uint8_t *dst, uint32_t *base, uint16_t offset, uint16_t bytes)
}
while (bytes >= 2) {
uint16_t s = ao_usb_read_short(base, offset);
}
while (bytes >= 2) {
uint16_t s = ao_usb_read_short(base, offset);
- dst[0] = s;
- dst[1] =
s >> 8
;
+ dst[0] =
(uint8_t)
s;
+ dst[1] =
(uint8_t) (s >> 8)
;
debug_data (" %02x %02x", dst[0], dst[1]);
offset += 2;
dst += 2;
debug_data (" %02x %02x", dst[0], dst[1]);
offset += 2;
dst += 2;
@@
-509,7
+527,7
@@
ao_usb_ep0_flush(void)
ao_usb_ep0_in_len -= this_len;
debug_data ("Flush EP0 len %d:", this_len);
ao_usb_ep0_in_len -= this_len;
debug_data ("Flush EP0 len %d:", this_len);
- ao_usb_write(ao_usb_ep0_in_data, ao_usb_ep0_tx_buffer,
0,
this_len);
+ ao_usb_write(ao_usb_ep0_in_data, ao_usb_ep0_tx_buffer, this_len);
debug_data ("\n");
ao_usb_ep0_in_data += this_len;
debug_data ("\n");
ao_usb_ep0_in_data += this_len;
@@
-527,7
+545,7
@@
ao_usb_ep0_fill(void)
if (len > ao_usb_ep0_out_len)
len = ao_usb_ep0_out_len;
if (len > ao_usb_ep0_out_len)
len = ao_usb_ep0_out_len;
- ao_usb_ep0_out_len -= len;
+ ao_usb_ep0_out_len -=
(uint8_t)
len;
/* Pull all of the data out of the packet */
debug_data ("Fill EP0 len %d:", len);
/* Pull all of the data out of the packet */
debug_data ("Fill EP0 len %d:", len);
@@
-572,20
+590,20
@@
ao_usb_ep0_in_start(uint16_t max)
{
/* Don't send more than asked for */
if (ao_usb_ep0_in_len > max)
{
/* Don't send more than asked for */
if (ao_usb_ep0_in_len > max)
- ao_usb_ep0_in_len = max;
+ ao_usb_ep0_in_len =
(uint8_t)
max;
ao_usb_ep0_flush();
}
ao_usb_ep0_flush();
}
-st
atic st
ruct ao_usb_line_coding ao_usb_line_coding = {115200, 0, 0, 8};
+struct ao_usb_line_coding ao_usb_line_coding = {115200, 0, 0, 8};
/* Walk through the list of descriptors and find a match
*/
static void
/* Walk through the list of descriptors and find a match
*/
static void
-ao_usb_get_descriptor(uint16_t value)
+ao_usb_get_descriptor(uint16_t value
, uint16_t length
)
{
const uint8_t *descriptor;
{
const uint8_t *descriptor;
- uint8_t type =
value >> 8
;
- uint8_t index = value;
+ uint8_t type =
(uint8_t) (value >> 8)
;
+ uint8_t index =
(uint8_t)
value;
descriptor = ao_usb_descriptors;
while (descriptor[0] != 0) {
descriptor = ao_usb_descriptors;
while (descriptor[0] != 0) {
@@
-595,6
+613,8
@@
ao_usb_get_descriptor(uint16_t value)
len = descriptor[2];
else
len = descriptor[0];
len = descriptor[2];
else
len = descriptor[0];
+ if (len > length)
+ len = (uint8_t) length;
ao_usb_ep0_in_set(descriptor, len);
break;
}
ao_usb_ep0_in_set(descriptor, len);
break;
}
@@
-634,19
+654,19
@@
ao_usb_ep0_setup(void)
break;
case AO_USB_REQ_SET_ADDRESS:
debug ("set address %d\n", ao_usb_setup.value);
break;
case AO_USB_REQ_SET_ADDRESS:
debug ("set address %d\n", ao_usb_setup.value);
- ao_usb_address = ao_usb_setup.value;
+ ao_usb_address =
(uint8_t)
ao_usb_setup.value;
ao_usb_address_pending = 1;
break;
case AO_USB_REQ_GET_DESCRIPTOR:
debug ("get descriptor %d\n", ao_usb_setup.value);
ao_usb_address_pending = 1;
break;
case AO_USB_REQ_GET_DESCRIPTOR:
debug ("get descriptor %d\n", ao_usb_setup.value);
- ao_usb_get_descriptor(ao_usb_setup.value);
+ ao_usb_get_descriptor(ao_usb_setup.value
, ao_usb_setup.length
);
break;
case AO_USB_REQ_GET_CONFIGURATION:
debug ("get configuration %d\n", ao_usb_configuration);
ao_usb_ep0_in_queue_byte(ao_usb_configuration);
break;
case AO_USB_REQ_SET_CONFIGURATION:
break;
case AO_USB_REQ_GET_CONFIGURATION:
debug ("get configuration %d\n", ao_usb_configuration);
ao_usb_ep0_in_queue_byte(ao_usb_configuration);
break;
case AO_USB_REQ_SET_CONFIGURATION:
- ao_usb_configuration = ao_usb_setup.value;
+ ao_usb_configuration =
(uint8_t)
ao_usb_setup.value;
debug ("set configuration %d\n", ao_usb_configuration);
ao_usb_set_configuration();
break;
debug ("set configuration %d\n", ao_usb_configuration);
ao_usb_set_configuration();
break;
@@
-727,6
+747,9
@@
ao_usb_ep0_handle(uint8_t receive)
if (receive & AO_USB_EP0_GOT_TX_ACK) {
debug ("\tgot tx ack\n");
if (receive & AO_USB_EP0_GOT_TX_ACK) {
debug ("\tgot tx ack\n");
+#if HAS_FLIGHT && AO_USB_FORCE_IDLE
+ ao_flight_force_idle = 1;
+#endif
/* Wait until the IN packet is received from addr 0
* before assigning our local address
*/
/* Wait until the IN packet is received from addr 0
* before assigning our local address
*/
@@
-753,8
+776,8
@@
stm_usb_lp_isr(void)
epr_write = epr;
epr_write &= STM_USB_EPR_PRESERVE_MASK;
epr_write |= STM_USB_EPR_INVARIANT;
epr_write = epr;
epr_write &= STM_USB_EPR_PRESERVE_MASK;
epr_write |= STM_USB_EPR_INVARIANT;
- epr_write &= ~(1 << STM_USB_EPR_CTR_RX);
- epr_write &= ~(1 << STM_USB_EPR_CTR_TX);
+ epr_write &= ~(1
UL
<< STM_USB_EPR_CTR_RX);
+ epr_write &= ~(1
UL
<< STM_USB_EPR_CTR_TX);
stm_usb.epr[ep] = epr_write;
switch (ep) {
stm_usb.epr[ep] = epr_write;
switch (ep) {
@@
-799,17
+822,17
@@
stm_usb_lp_isr(void)
if (istr & (1 << STM_USB_ISTR_RESET)) {
++reset_count;
if (istr & (1 << STM_USB_ISTR_RESET)) {
++reset_count;
- stm_usb.istr &= ~(1 << STM_USB_ISTR_RESET);
+ stm_usb.istr &= ~(1
UL
<< STM_USB_ISTR_RESET);
ao_usb_ep0_receive |= AO_USB_EP0_GOT_RESET;
ao_usb_ep0_handle(ao_usb_ep0_receive);
}
}
void
ao_usb_ep0_receive |= AO_USB_EP0_GOT_RESET;
ao_usb_ep0_handle(ao_usb_ep0_receive);
}
}
void
-stm_usb_fs_wkup(void)
+stm_usb_fs_wkup
_isr
(void)
{
/* USB wakeup, just clear the bit for now */
{
/* USB wakeup, just clear the bit for now */
- stm_usb.istr &= ~(1 << STM_USB_ISTR_WKUP);
+ stm_usb.istr &= ~(1
UL
<< STM_USB_ISTR_WKUP);
}
/* Queue the current IN buffer for transmission */
}
/* Queue the current IN buffer for transmission */
@@
-823,7
+846,7
@@
_ao_usb_in_send(void)
ao_usb_in_pending = 1;
if (ao_usb_tx_count != AO_USB_IN_SIZE)
ao_usb_in_flushed = 1;
ao_usb_in_pending = 1;
if (ao_usb_tx_count != AO_USB_IN_SIZE)
ao_usb_in_flushed = 1;
- ao_usb_write(ao_usb_tx_buffer, ao_usb_in_tx_buffer,
0,
ao_usb_tx_count);
+ ao_usb_write(ao_usb_tx_buffer, ao_usb_in_tx_buffer, ao_usb_tx_count);
ao_usb_bdt[AO_USB_IN_EPR].single.count_tx = ao_usb_tx_count;
ao_usb_tx_count = 0;
_ao_usb_set_stat_tx(AO_USB_IN_EPR, STM_USB_EPR_STAT_TX_VALID);
ao_usb_bdt[AO_USB_IN_EPR].single.count_tx = ao_usb_tx_count;
ao_usb_tx_count = 0;
_ao_usb_set_stat_tx(AO_USB_IN_EPR, STM_USB_EPR_STAT_TX_VALID);
@@
-896,7
+919,7
@@
_ao_usb_out_recv(void)
_rx_dbg0("out_recv top");
ao_usb_out_avail = 0;
_rx_dbg0("out_recv top");
ao_usb_out_avail = 0;
- ao_usb_rx_count =
ao_usb_bdt[AO_USB_OUT_EPR].single.count_rx & STM_USB_BDT_COUNT_RX_COUNT_RX_MASK
;
+ ao_usb_rx_count =
(uint8_t) (ao_usb_bdt[AO_USB_OUT_EPR].single.count_rx & STM_USB_BDT_COUNT_RX_COUNT_RX_MASK)
;
_rx_dbg1("out_recv count", ao_usb_rx_count);
debug ("recv %d\n", ao_usb_rx_count);
_rx_dbg1("out_recv count", ao_usb_rx_count);
debug ("recv %d\n", ao_usb_rx_count);
@@
-909,7
+932,7
@@
_ao_usb_out_recv(void)
_ao_usb_set_stat_rx(AO_USB_OUT_EPR, STM_USB_EPR_STAT_RX_VALID);
}
_ao_usb_set_stat_rx(AO_USB_OUT_EPR, STM_USB_EPR_STAT_RX_VALID);
}
-int
+
static
int
_ao_usb_pollchar(void)
{
uint8_t c;
_ao_usb_pollchar(void)
{
uint8_t c;
@@
-944,9
+967,14
@@
ao_usb_getchar(void)
while ((c = _ao_usb_pollchar()) == AO_READ_AGAIN)
ao_sleep(AO_USB_OUT_SLEEP_ADDR);
ao_arch_release_interrupts();
while ((c = _ao_usb_pollchar()) == AO_READ_AGAIN)
ao_sleep(AO_USB_OUT_SLEEP_ADDR);
ao_arch_release_interrupts();
- return c;
+ return
(char)
c;
}
}
+#ifndef HAS_USB_DISABLE
+#define HAS_USB_DISABLE 1
+#endif
+
+#if HAS_USB_DISABLE
void
ao_usb_disable(void)
{
void
ao_usb_disable(void)
{
@@
-955,15
+983,16
@@
ao_usb_disable(void)
stm_usb.istr = 0;
/* Disable USB pull-up */
stm_usb.istr = 0;
/* Disable USB pull-up */
- stm_syscfg.pmc &= ~(1 << STM_SYSCFG_PMC_USB_PU);
+ stm_syscfg.pmc &= ~(1
UL
<< STM_SYSCFG_PMC_USB_PU);
/* Switch off the device */
stm_usb.cntr = (1 << STM_USB_CNTR_PDWN) | (1 << STM_USB_CNTR_FRES);
/* Disable the interface */
/* Switch off the device */
stm_usb.cntr = (1 << STM_USB_CNTR_PDWN) | (1 << STM_USB_CNTR_FRES);
/* Disable the interface */
- stm_rcc.apb1enr &= ~(1 << STM_RCC_APB1ENR_USBEN);
+ stm_rcc.apb1enr &= ~(1
UL
<< STM_RCC_APB1ENR_USBEN);
ao_arch_release_interrupts();
}
ao_arch_release_interrupts();
}
+#endif
void
ao_usb_enable(void)
void
ao_usb_enable(void)
@@
-974,7
+1003,7
@@
ao_usb_enable(void)
stm_rcc.apb2enr |= (1 << STM_RCC_APB2ENR_SYSCFGEN);
/* Disable USB pull-up */
stm_rcc.apb2enr |= (1 << STM_RCC_APB2ENR_SYSCFGEN);
/* Disable USB pull-up */
- stm_syscfg.pmc &= ~(1 << STM_SYSCFG_PMC_USB_PU);
+ stm_syscfg.pmc &= ~(1
UL
<< STM_SYSCFG_PMC_USB_PU);
/* Enable USB device */
stm_rcc.apb1enr |= (1 << STM_RCC_APB1ENR_USBEN);
/* Enable USB device */
stm_rcc.apb1enr |= (1 << STM_RCC_APB1ENR_USBEN);
@@
-988,7
+1017,7
@@
ao_usb_enable(void)
ao_arch_block_interrupts();
/* Route interrupts */
ao_arch_block_interrupts();
/* Route interrupts */
- stm_nvic_set_priority(STM_ISR_USB_LP_POS,
3
);
+ stm_nvic_set_priority(STM_ISR_USB_LP_POS,
AO_STM_NVIC_LOW_PRIORITY
);
stm_nvic_set_enable(STM_ISR_USB_LP_POS);
ao_usb_configuration = 0;
stm_nvic_set_enable(STM_ISR_USB_LP_POS);
ao_usb_configuration = 0;
@@
-1050,7
+1079,7
@@
ao_usb_irq(void)
control_count, out_count, in_count, int_count, reset_count);
}
control_count, out_count, in_count, int_count, reset_count);
}
-
__code
struct ao_cmds ao_usb_cmds[] = {
+
const
struct ao_cmds ao_usb_cmds[] = {
{ ao_usb_irq, "I\0Show USB interrupt counts" },
{ 0, NULL }
};
{ ao_usb_irq, "I\0Show USB interrupt counts" },
{ 0, NULL }
};
@@
-1082,7
+1111,7
@@
struct ao_usb_dbg {
int line;
char *msg;
uint32_t value;
int line;
char *msg;
uint32_t value;
- uint32_t pri
mask
;
+ uint32_t pri
val
;
#if TX_DBG
uint16_t in_count;
uint32_t in_epr;
#if TX_DBG
uint16_t in_count;
uint32_t in_epr;
@@
-1098,19
+1127,23
@@
struct ao_usb_dbg {
#endif
};
#endif
};
-#define NUM_USB_DBG 1
28
+#define NUM_USB_DBG 1
6
-static struct ao_usb_dbg dbg[
128
];
+static struct ao_usb_dbg dbg[
NUM_USB_DBG
];
static int dbg_i;
static void _dbg(int line, char *msg, uint32_t value)
{
static int dbg_i;
static void _dbg(int line, char *msg, uint32_t value)
{
- uint32_t pri
mask
;
+ uint32_t pri
val
;
dbg[dbg_i].line = line;
dbg[dbg_i].msg = msg;
dbg[dbg_i].value = value;
dbg[dbg_i].line = line;
dbg[dbg_i].msg = msg;
dbg[dbg_i].value = value;
- asm("mrs %0,primask" : "=&r" (primask));
- dbg[dbg_i].primask = primask;
+#if AO_NONMASK_INTERRUPT
+ asm("mrs %0,basepri" : "=&r" (prival));
+#else
+ asm("mrs %0,primask" : "=&r" (prival));
+#endif
+ dbg[dbg_i].prival = prival;
#if TX_DBG
dbg[dbg_i].in_count = in_count;
dbg[dbg_i].in_epr = stm_usb.epr[AO_USB_IN_EPR];
#if TX_DBG
dbg[dbg_i].in_count = in_count;
dbg[dbg_i].in_epr = stm_usb.epr[AO_USB_IN_EPR];