#include <Nordic\reg24lu1.h>#include <intrins.h>#include <stdbool.h>#include "config.h"#include "usb.h"Go to the source code of this file.
Defines | |
| #define | MIN(a, b) ((a) < (b) ? (a) : (b)) |
Functions | |
| void | usb_init (void) |
| void | usb_irq (void) |
Variables | |
| xdata volatile uint8_t out1buf[64] | _at_ |
| _Bool | packet_received |
Minimalistic USB code for the bootloader.
Definition in file usb.c.
| #define MIN | ( | a, | |
| b | |||
| ) | ((a) < (b) ? (a) : (b)) |
| void usb_init | ( | void | ) |
Definition at line 98 of file usb.c.
{
// Setup state information
usb_state = DEFAULT;
usb_bm_state = 0;
// Setconfig configuration information
usb_current_config = 0;
usb_current_alt_interface = 0;
// Disconnect from USB-bus since we are in this routine from a power on and not a soft reset:
usbcs |= 0x08;
delay_ms(50);
usbcs &= ~0x08;
usbien = 0x1d;
in_ien = 0x01;
in_irq = 0x1f;
out_ien = 0x01;
out_irq = 0x1f;
// Setup the USB RAM with some OK default values:
bout1addr = MAX_PACKET_SIZE_EP0/2;
bout2addr = MAX_PACKET_SIZE_EP0/2 + USB_EP1_SIZE/2;
bout3addr = MAX_PACKET_SIZE_EP0/2 + 2*USB_EP1_SIZE/2;
bout4addr = MAX_PACKET_SIZE_EP0/2 + 3*USB_EP1_SIZE/2;
bout5addr = MAX_PACKET_SIZE_EP0/2 + 4*USB_EP1_SIZE/2;
binstaddr = 0xc0;
bin1addr = MAX_PACKET_SIZE_EP0/2;
bin2addr = MAX_PACKET_SIZE_EP0/2 + USB_EP1_SIZE/2;
bin3addr = MAX_PACKET_SIZE_EP0/2 + 2*USB_EP1_SIZE/2;
bin4addr = MAX_PACKET_SIZE_EP0/2 + 3*USB_EP1_SIZE/2;
bin5addr = MAX_PACKET_SIZE_EP0/2 + 4*USB_EP1_SIZE/2;
// Set all endpoints to not valid (except EP0IN and EP0OUT)
inbulkval = 0x01;
outbulkval = 0x01;
inisoval = 0x00;
outisoval = 0x00;
in_ien |= 0x02;;
inbulkval |= 0x02;
out_ien |= 0x02;
outbulkval |= 0x02;
out1bc = 0xff;
}
| void usb_irq | ( | void | ) |
Definition at line 369 of file usb.c.
{
//
// Split case into an if and a switch to force Keil into not using a library function:
if (ivec == INT_USBRESET)
{
usbirq = 0x10;
usb_state = DEFAULT;
usb_current_config = 0;
usb_current_alt_interface = 0;
usb_bm_state = 0;
}
else
{
switch(ivec)
{
case INT_SUDAV:
usbirq = 0x01;
isr_sudav();
break;
case INT_SOF:
usbirq = 0x02;
break;
case INT_SUTOK:
usbirq = 0x04;
packetizer_data_ptr = NULL;
packetizer_data_size = 0;
packetizer_pkt_size = 0;
break;
case INT_SUSPEND:
usbirq = 0x08;
break;
case INT_EP0IN:
in_irq = 0x01;
packetizer_isr_ep0_in();
break;
case INT_EP0OUT:
out_irq = 0x01;
packetizer_data_size = 0;
// req.misc_data = out0buf;
USB_EP0_HSNAK();
break;
case INT_EP1IN:
// Clear interrupt
in_irq = 0x02;
in1cs = 0x02;
break;
case INT_EP1OUT:
// Clear interrupt
out_irq = 0x02;
packet_received = true;
out1bc = 0xff;
break;
default:
break;
}
}
}
1.7.2