Actually try to use USB-serial code. "make APP=tester TYPE=serial"

This commit is contained in:
Stefan `Sec` Zehl 2011-07-27 15:41:18 +02:00
parent 250ea3213f
commit 63ff0de8b2
9 changed files with 142 additions and 7 deletions

View File

@ -67,7 +67,10 @@ OBJS += $(LOBJ)
endif endif
ifeq "$(APP)" "tester" ifeq "$(APP)" "tester"
TSRCS = $(wildcard $(APP)/*.c) ifndef TYPE
TYPE=$(APP)
endif
TSRCS = $(wildcard $(TYPE)/*.c)
TOBJS = $(foreach mod,$(TSRCS),$(subst .c,.o,$(mod))) TOBJS = $(foreach mod,$(TSRCS),$(subst .c,.o,$(mod)))
TWRAP=tester.gen TWRAP=tester.gen
@ -90,7 +93,7 @@ $(LIBFILE): $(OBJS) $(WRAPOBJ)
$(CC) $(CFLAGS) -o $@ $< $(CC) $(CFLAGS) -o $@ $<
clean: clean:
rm -f $(OBJS) $(WRAPOBJ) $(WRAPSRC) $(LIBFILE) *.o tester/*.o rm -f $(OBJS) $(WRAPOBJ) $(WRAPSRC) $(LIBFILE) *.o */*.o
%.c: %.c:
@echo @echo

View File

@ -0,0 +1 @@
../tester/config.c

View File

@ -0,0 +1,116 @@
#include <sysinit.h>
#include "basic/basic.h"
#include "lcd/lcd.h"
#include "lcd/print.h"
#include "funk/nrf24l01p.h"
#include "core/usbcdc/usb.h"
#include "core/usbcdc/usbcore.h"
#include "core/usbcdc/usbhw.h"
#include "core/usbcdc/cdcuser.h"
#include "core/usbcdc/cdc_buf.h"
#include <string.h>
#if CFG_USBMSC
#error "MSC is defined
#endif
#if !CFG_USBCDC
#error "CDC is not defined
#endif
/**************************************************************************/
volatile unsigned int lastTick;
int puts(const char * str)
{
// There must be at least 1ms between USB frames (of up to 64 bytes)
// This buffers all data and writes it out from the buffer one frame
// and one millisecond at a time
if (USB_Configuration)
{
while(*str)
cdcBufferWrite(*str++);
// Check if we can flush the buffer now or if we need to wait
unsigned int currentTick = systickGetTicks();
if (currentTick != lastTick)
{
uint8_t frame[64];
uint32_t bytesRead = 0;
while (cdcBufferDataPending())
{
// Read up to 64 bytes as long as possible
bytesRead = cdcBufferReadLen(frame, 64);
USB_WriteEP (CDC_DEP_IN, frame, bytesRead);
systickDelay(1);
}
lastTick = currentTick;
}
}
return 0;
}
void f_ser(void) {
//lastTick = systickGetTicks(); // Used to control output/printf timing
CDC_Init(); // Initialise VCOM
USB_Init(); // USB Initialization
lcdPrintln("preconnect");
USB_Connect(TRUE); // USB Connect
lcdPrintln("postconnect");
// Wait until USB is configured or timeout occurs
uint32_t usbTimeout = 0;
// while ( usbTimeout < CFG_USBCDC_INITTIMEOUT / 10 ) {
// if (USB_Configuration) break;
// delayms(10); // Wait 10ms
// usbTimeout++;
// }
lcdPrintln("fini");
};
void f_disconnect(void) {
USB_Connect(FALSE);
};
#define LEN 10
void f_sread(){
uint8_t buf[LEN+1];
int l=LEN;
lcdPrint("Bytes:");
CDC_OutBufAvailChar (&l);
lcdPrintInt(l);
lcdNl();
lcdPrint("read:");
CDC_RdOutBuf (buf, &l);
lcdPrintInt(l);
lcdNl();
buf[l]=0;
lcdPrintln(buf);
};
void f_echo(){
uint8_t buf[2] = {0,0};
int l;
while(1){
CDC_OutBufAvailChar(&l);
if( l ){
l = 1;
CDC_RdOutBuf (buf, &l);
puts(buf);
}
//puts("hello world\r\n");
//delayms(1);
}
};
void f_say(){
puts("hello world\r\n");
};

View File

@ -0,0 +1 @@
../tester/util.c

View File

@ -0,0 +1 @@
../tester/uuid.c

View File

@ -76,10 +76,16 @@ void EnableWatchdog(uint32_t ms){
void ISPandReset(void){ void ISPandReset(void){
#if CFG_USBMSC #if CFG_USBMSC
if(usbMSCenabled){ if(usbMSCenabled&USB_MSC_ENABLEFLAG){
usbMSCOff(); usbMSCOff();
delayms(500); delayms(500);
}; };
#endif
#if CFG_USBCDC
if(usbMSCenabled&USB_CDC_ENABLEFLAG){
USB_Connect(FALSE);
delayms(500);
};
#endif #endif
EnableWatchdog(1000*5); EnableWatchdog(1000*5);
ReinvokeISP(); ReinvokeISP();

View File

@ -85,7 +85,7 @@ void usbMSCInit(void) {
(*rom)->pUSBD->init(&DeviceInfo); /* USB Initialization */ (*rom)->pUSBD->init(&DeviceInfo); /* USB Initialization */
(*rom)->pUSBD->connect(true); /* USB Connect */ (*rom)->pUSBD->connect(true); /* USB Connect */
usbMSCenabled=1; usbMSCenabled|=USB_MSC_ENABLEFLAG;
} }
#if CFG_USBMSC #if CFG_USBMSC
@ -96,6 +96,6 @@ void USB_IRQHandler() {
void usbMSCOff(void) { void usbMSCOff(void) {
(*rom)->pUSBD->connect(false); /* USB Disconnect */ (*rom)->pUSBD->connect(false); /* USB Disconnect */
usbMSCenabled=0; usbMSCenabled&=~USB_MSC_ENABLEFLAG;
} }

View File

@ -39,6 +39,8 @@
#include "projectconfig.h" #include "projectconfig.h"
#define USB_MSC_ENABLEFLAG (1<<0)
#define USB_CDC_ENABLEFLAG (1<<1)
extern char usbMSCenabled; extern char usbMSCenabled;
void usbMSCWrite(uint32_t offset, uint8_t src[], uint32_t length); void usbMSCWrite(uint32_t offset, uint8_t src[], uint32_t length);
void usbMSCRead(uint32_t offset, uint8_t dst[], uint32_t length); void usbMSCRead(uint32_t offset, uint8_t dst[], uint32_t length);

View File

@ -27,6 +27,7 @@
#include "usbcore.h" #include "usbcore.h"
#include "usbuser.h" #include "usbuser.h"
#include "usb/usbmsc.h"
/* /*
* USB and IO Clock configuration only. * USB and IO Clock configuration only.
@ -63,8 +64,8 @@ void USBIOClkConfig( void )
SCB_USBCLKSEL = SCB_USBCLKSEL_SOURCE_USBPLLOUT; SCB_USBCLKSEL = SCB_USBCLKSEL_SOURCE_USBPLLOUT;
// Set USB pin functions // Set USB pin functions
IOCON_PIO0_1 &= ~IOCON_PIO0_1_FUNC_MASK; // IOCON_PIO0_1 &= ~IOCON_PIO0_1_FUNC_MASK;
IOCON_PIO0_1 |= IOCON_PIO0_1_FUNC_CLKOUT; // CLK OUT // IOCON_PIO0_1 |= IOCON_PIO0_1_FUNC_CLKOUT; // CLK OUT
IOCON_PIO0_3 &= ~IOCON_PIO0_3_FUNC_MASK; IOCON_PIO0_3 &= ~IOCON_PIO0_3_FUNC_MASK;
IOCON_PIO0_3 |= IOCON_PIO0_3_FUNC_USB_VBUS; // VBus IOCON_PIO0_3 |= IOCON_PIO0_3_FUNC_USB_VBUS; // VBus
IOCON_PIO0_6 &= ~IOCON_PIO0_6_FUNC_MASK; IOCON_PIO0_6 &= ~IOCON_PIO0_6_FUNC_MASK;
@ -205,6 +206,10 @@ void USB_Init (void)
void USB_Connect (uint32_t con) void USB_Connect (uint32_t con)
{ {
if(con)
usbMSCenabled|=USB_CDC_ENABLEFLAG;
else
usbMSCenabled&=~USB_CDC_ENABLEFLAG;
WrCmdDat(CMD_SET_DEV_STAT, DAT_WR_BYTE(con ? DEV_CON : 0)); WrCmdDat(CMD_SET_DEV_STAT, DAT_WR_BYTE(con ? DEV_CON : 0));
} }