refactor usb read and write
This commit is contained in:
parent
8b10ccc7de
commit
4a0461987b
@ -8,7 +8,7 @@ AVRDUDE = avrdude -c usbasp -p $(DEVICE)
|
|||||||
|
|
||||||
CFLAGS = -Iusbdrv -I. -DDEBUG_LEVEL=0
|
CFLAGS = -Iusbdrv -I. -DDEBUG_LEVEL=0
|
||||||
#-std=gnu99
|
#-std=gnu99
|
||||||
OBJECTS = usbdrv/usbdrv.o usbdrv/usbdrvasm.o usbdrv/oddebug.o main.o uart.o fifo.o sram.o crc.o debug.o
|
OBJECTS = usbdrv/usbdrv.o usbdrv/usbdrvasm.o usbdrv/oddebug.o main.o usb_bulk.o uart.o fifo.o sram.o crc.o debug.o
|
||||||
COMPILE = avr-gcc -Wall -Os -DF_CPU=$(F_CPU) $(CFLAGS) -mmcu=$(DEVICE)
|
COMPILE = avr-gcc -Wall -Os -DF_CPU=$(F_CPU) $(CFLAGS) -mmcu=$(DEVICE)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -14,7 +14,7 @@
|
|||||||
#include "sram.h"
|
#include "sram.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "crc.h"
|
#include "crc.h"
|
||||||
|
#include "usb_bulk.h"
|
||||||
|
|
||||||
extern FILE uart_stdout;
|
extern FILE uart_stdout;
|
||||||
|
|
||||||
@ -32,8 +32,6 @@ uint8_t data_buffer[4];
|
|||||||
uint32_t addr;
|
uint32_t addr;
|
||||||
uint16_t crc = 0;
|
uint16_t crc = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
usbMsgLen_t usbFunctionSetup(uchar data[8])
|
usbMsgLen_t usbFunctionSetup(uchar data[8])
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -117,44 +115,6 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint8_t usbFunctionWrite(uint8_t * data, uint8_t len)
|
|
||||||
{
|
|
||||||
if (len > rx_remaining) {
|
|
||||||
printf("usbFunctionWrite more data than expected remain: %i len: %i\n",
|
|
||||||
rx_remaining, len);
|
|
||||||
len = rx_remaining;
|
|
||||||
}
|
|
||||||
if (req_state == REQ_UPLOAD) {
|
|
||||||
|
|
||||||
rx_remaining -= len;
|
|
||||||
#if DEBUG_USB_RAW
|
|
||||||
printf("usbFunctionWrite addr: 0x%08lx len: %i rx_remaining=%i\n",
|
|
||||||
req_addr, len, rx_remaining);
|
|
||||||
#endif
|
|
||||||
cli();
|
|
||||||
sram_copy(req_addr, data, len);
|
|
||||||
sei();
|
|
||||||
req_addr += len;
|
|
||||||
}
|
|
||||||
return len;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t usbFunctionRead(uint8_t * data, uint8_t len)
|
|
||||||
{
|
|
||||||
uint8_t i;
|
|
||||||
if (len > tx_remaining)
|
|
||||||
len = tx_remaining;
|
|
||||||
tx_remaining -= len;
|
|
||||||
#if DEBUG_USB_RAW
|
|
||||||
printf("usbFunctionRead len=%i tx_remaining=%i \n", len, tx_remaining);
|
|
||||||
#endif
|
|
||||||
for (i = 0; i < len; i++) {
|
|
||||||
*data = tx_buffer[len];
|
|
||||||
data++;
|
|
||||||
}
|
|
||||||
return len;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* -------------------------------------------------------------------------
|
* -------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|||||||
66
avr/usbload/usb_bulk.c
Normal file
66
avr/usbload/usb_bulk.c
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include <avr/pgmspace.h> /* required by usbdrv.h */
|
||||||
|
#include <avr/interrupt.h> /* for sei() */
|
||||||
|
#include <util/delay.h> /* for _delay_ms() */
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "usbdrv.h"
|
||||||
|
#include "oddebug.h" /* This is also an example for using debug
|
||||||
|
* macros */
|
||||||
|
#include "config.h"
|
||||||
|
#include "requests.h" /* The custom request numbers we use */
|
||||||
|
#include "uart.h"
|
||||||
|
#include "sram.h"
|
||||||
|
#include "debug.h"
|
||||||
|
#include "crc.h"
|
||||||
|
#include "usb_bulk.h"
|
||||||
|
|
||||||
|
extern uint8_t read_buffer[BUFFER_SIZE];
|
||||||
|
extern uint32_t req_addr;
|
||||||
|
extern uint32_t req_size;
|
||||||
|
extern uint8_t req_bank;
|
||||||
|
extern uint32_t req_bank_size;
|
||||||
|
extern uint8_t req_state;
|
||||||
|
extern uint8_t rx_remaining;
|
||||||
|
extern uint8_t tx_remaining;
|
||||||
|
extern uint8_t tx_buffer[32];
|
||||||
|
|
||||||
|
uint8_t usbFunctionWrite(uint8_t * data, uint8_t len)
|
||||||
|
{
|
||||||
|
if (len > rx_remaining) {
|
||||||
|
printf("usbFunctionWrite more data than expected remain: %i len: %i\n",
|
||||||
|
rx_remaining, len);
|
||||||
|
len = rx_remaining;
|
||||||
|
}
|
||||||
|
if (req_state == REQ_UPLOAD) {
|
||||||
|
|
||||||
|
rx_remaining -= len;
|
||||||
|
#if DEBUG_USB_RAW
|
||||||
|
printf("usbFunctionWrite addr: 0x%08lx len: %i rx_remaining=%i\n",
|
||||||
|
req_addr, len, rx_remaining);
|
||||||
|
#endif
|
||||||
|
cli();
|
||||||
|
sram_copy(req_addr, data, len);
|
||||||
|
sei();
|
||||||
|
req_addr += len;
|
||||||
|
}
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t usbFunctionRead(uint8_t * data, uint8_t len)
|
||||||
|
{
|
||||||
|
uint8_t i;
|
||||||
|
if (len > tx_remaining)
|
||||||
|
len = tx_remaining;
|
||||||
|
tx_remaining -= len;
|
||||||
|
#if DEBUG_USB_RAW
|
||||||
|
printf("usbFunctionRead len=%i tx_remaining=%i \n", len, tx_remaining);
|
||||||
|
#endif
|
||||||
|
for (i = 0; i < len; i++) {
|
||||||
|
*data = tx_buffer[len];
|
||||||
|
data++;
|
||||||
|
}
|
||||||
|
return len;
|
||||||
|
}
|
||||||
3
avr/usbload/usb_bulk.h
Normal file
3
avr/usbload/usb_bulk.h
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
|
||||||
|
uint8_t usbFunctionWrite(uint8_t * data, uint8_t len);
|
||||||
|
uint8_t usbFunctionRead(uint8_t * data, uint8_t len);
|
||||||
Loading…
x
Reference in New Issue
Block a user