hwstub: add delay functions, and plain binary/sb file generation

Change-Id: Idbedb9277b355edcd93975ec5a268428c7b89633
This commit is contained in:
Amaury Pouly 2013-09-10 23:07:40 +02:00
parent acf3af4ae3
commit 3b6d2ac28a
5 changed files with 37 additions and 4 deletions

View file

@ -14,9 +14,10 @@ OBJ=$(SRC:.c=.o)
OBJ:=$(OBJ:.S=.o)
OBJ_EXCEPT_CRT0=$(filter-out $(BUILD_DIR)/crt0.o,$(OBJ))
EXEC_ELF=$(BUILD_DIR)/hwstub.elf
EXEC_BIN=$(BUILD_DIR)/hwstub.bin
DEPS=$(foreach obj,$(OBJ),$(obj).d)
EXEC=$(EXEC_ELF)
EXEC+=$(EXEC_ELF) $(EXEC_BIN)
SILENT?=@
PRINTS=$(SILENT)$(call info,$(1))
@ -44,6 +45,10 @@ $(TMP_LDS): $(LINKER_FILE)
$(EXEC_ELF): $(OBJ) $(TMP_LDS)
$(call PRINTS,LD $(@F))
$(SILENT)$(LD) $(LDFLAGS) -o $@ $(OBJ_EXCEPT_CRT0)
$(EXEC_BIN): $(EXEC_ELF)
$(call PRINTS,OC $(@F))
$(SILENT)$(OC) -O binary $< $@
clean:
$(SILENT)rm -rf $(OBJ) $(DEPS) $(EXEC) $(TMP_LDS) $(TMP_MAP)

View file

@ -5,10 +5,16 @@ CC=arm-elf-eabi-gcc
LD=arm-elf-eabi-gcc
AS=arm-elf-eabi-gcc
OC=arm-elf-eabi-objcopy
SBTOELF=$(CURDIR)/../../../imxtools/sbtools/elftosb
DEFINES=
INCLUDES=-I$(CURDIR)
GCCOPTS=-mcpu=arm926ej-s
BUILD_DIR=$(CURDIR)/build/
ROOT_DIR=$(CURDIR)/..
include ../hwstub.make
EXEC=$(BUILD_DIR)/hwstub.sb
include ../hwstub.make
$(BUILD_DIR)/hwstub.sb: $(EXEC_BIN)
$(call PRINTS,SBTOELF $(@F))
$(SILENT)$(SBTOELF) -z -c hwstub.db -o $@ $<

View file

@ -273,3 +273,18 @@ void target_exit(void)
return;
}
}
void target_udelay(int us)
{
uint32_t cur = HW_DIGCTL_MICROSECONDS;
uint32_t end = cur + us;
if(cur < end)
while(HW_DIGCTL_MICROSECONDS < end) {}
else
while(HW_DIGCTL_MICROSECONDS >= cur) {}
}
void target_mdelay(int ms)
{
return target_udelay(ms * 1000);
}

View file

@ -31,5 +31,9 @@ void target_exit(void);
int target_get_info(int info, void **buffer);
/* set atexit action or return -1 on error */
int target_atexit(int action);
/* Wait a very short time (us<=1000) */
void target_udelay(int us);
/* Wait for a short time (ms <= 1000) */
void target_mdelay(int ms);
#endif /* __TARGET_H__ */

View file

@ -23,6 +23,7 @@
#include "usb_drv.h"
#include "config.h"
#include "memory.h"
#include "target.h"
#define MAX_PKT_SIZE 1024
#define MAX_PKT_SIZE_EP0 64
@ -323,9 +324,11 @@ void usb_drv_init(void)
/* we don't know if USB was connected or not. In USB recovery mode it will
* but in other cases it might not be. In doubt, disconnect */
REG_USBCMD &= ~USBCMD_RUN;
/* wait a short time for the host to realise */
target_mdelay(50);
/* reset the controller */
REG_USBCMD |= USBCMD_CTRL_RESET;
while (REG_USBCMD & USBCMD_CTRL_RESET);
while(REG_USBCMD & USBCMD_CTRL_RESET);
/* put it in device mode */
REG_USBMODE = USBMODE_CTRL_MODE_DEVICE;
/* reset address */