From bc0c0684257c7dfe3f92dc514b2d2970dd524e45 Mon Sep 17 00:00:00 2001 From: meri Date: Tue, 10 Apr 2007 17:39:51 +0000 Subject: added several new USB commands: remote reset, API version and read/write volatile flash environment git-svn-id: https://svn.openpcd.org:2342/trunk@295 6dc7ffe9-61d6-0310-9af1-9938baff3ed1 --- firmware/include/openpcd.h | 4 ++ firmware/src/os/usbcmd_generic.c | 97 ++++++++++++++++++++++++++++++++++++---- firmware/src/os/usbcmd_generic.h | 2 + 3 files changed, 94 insertions(+), 9 deletions(-) (limited to 'firmware') diff --git a/firmware/include/openpcd.h b/firmware/include/openpcd.h index 8c8b956..904b8ff 100644 --- a/firmware/include/openpcd.h +++ b/firmware/include/openpcd.h @@ -50,6 +50,10 @@ enum openpcd_cmd_class { #define OPENPCD_CMD_GET_VERSION (0x1|OPENPCD_CLS2CMD(OPENPCD_CMD_CLS_GENERIC)) #define OPENPCD_CMD_SET_LED (0x2|OPENPCD_CLS2CMD(OPENPCD_CMD_CLS_GENERIC)) #define OPENPCD_CMD_GET_SERIAL (0x3|OPENPCD_CLS2CMD(OPENPCD_CMD_CLS_GENERIC)) +#define OPENPCD_CMD_GET_API_VERSION (0x4|OPENPCD_CLS2CMD(OPENPCD_CMD_CLS_GENERIC)) +#define OPENPCD_CMD_GET_ENVIRONMENT (0x5|OPENPCD_CLS2CMD(OPENPCD_CMD_CLS_GENERIC)) +#define OPENPCD_CMD_SET_ENVIRONMENT (0x6|OPENPCD_CLS2CMD(OPENPCD_CMD_CLS_GENERIC)) +#define OPENPCD_CMD_RESET (0x7|OPENPCD_CLS2CMD(OPENPCD_CMD_CLS_GENERIC)) /* CMD_CLS_RC632 */ #define OPENPCD_CMD_WRITE_REG (0x1|OPENPCD_CLS2CMD(OPENPCD_CMD_CLS_RC632)) diff --git a/firmware/src/os/usbcmd_generic.c b/firmware/src/os/usbcmd_generic.c index c26daf7..77b992f 100644 --- a/firmware/src/os/usbcmd_generic.c +++ b/firmware/src/os/usbcmd_generic.c @@ -10,27 +10,98 @@ #include #include #include +#include +#include +#ifdef PCD +#include +#endif/*PCD*/ + +#define OPENPCD_API_VERSION (0x01) +#define CONFIG_AREA_ADDR ((void*)(AT91C_IFLASH + AT91C_IFLASH_SIZE - ENVIRONMENT_SIZE)) +#define CONFIG_AREA_WORDS ( AT91C_IFLASH_PAGE_SIZE/sizeof(u_int32_t) ) + +volatile u_int32_t config_stack[ CONFIG_AREA_WORDS ]; + +static int gen_setenv(const void* buffer,int len) +{ + volatile unsigned int i; + u_int32_t *dst; + + if( len >= sizeof(config_stack) ) + len=sizeof(config_stack); + + memcpy(&config_stack,buffer,len); + + /* retrieve current content to allow partial flashing */ + + /* flash changes */ + dst=(u_int32_t*)CONFIG_AREA_ADDR; + for(i=0;i= sizeof(config_stack) ) + len=sizeof(config_stack); + + memcpy(buffer,&config_stack,len); + + return len; +} static int gen_usb_rx(struct req_ctx *rctx) { struct openpcd_hdr *poh = (struct openpcd_hdr *) rctx->data; - struct openpcd_compile_version *ver = - (struct openpcd_compile_version *) poh->data; - int ret = 1; + struct openpcd_compile_version *ver = + (struct openpcd_compile_version *)poh->data; + u_int32_t len = rctx->tot_len-sizeof(*poh); - rctx->tot_len = sizeof(*poh); + /* initialize transmit length to header length */ + rctx->tot_len = sizeof(*poh); switch (poh->cmd) { + + case OPENPCD_CMD_GET_API_VERSION: + DEBUGP("CMD_GET_API_VERSION\n"); + poh->flags &= OPENPCD_FLAG_RESPOND; + poh->val = OPENPCD_API_VERSION; + break; + + case OPENPCD_CMD_GET_ENVIRONMENT: + poh->flags &= OPENPCD_FLAG_RESPOND; + poh->val = gen_getenv(&poh->data,poh->val); + rctx->tot_len += poh->val; + DEBUGP("CMD_GET_ENVIRONMENT(res_len=%u)\n", poh->val); + break; + + case OPENPCD_CMD_SET_ENVIRONMENT: + DEBUGP("CMD_SET_ENVIRONMENT (in_len=%u)\n", len); + gen_setenv(&poh->data,len); + break; + + case OPENPCD_CMD_RESET: + DEBUGP("CMD_RESET\n"); + AT91F_RSTSoftReset(AT91C_BASE_RSTC, AT91C_RSTC_PROCRST| + AT91C_RSTC_PERRST|AT91C_RSTC_EXTRST); + break; + case OPENPCD_CMD_GET_VERSION: - DEBUGP("GET_VERSION "); + DEBUGP("GET_VERSION\n"); + poh->flags |= OPENPCD_FLAG_RESPOND; memcpy(ver, &opcd_version, sizeof(*ver)); rctx->tot_len += sizeof(*ver); - poh->flags |= OPENPCD_FLAG_RESPOND; break; + case OPENPCD_CMD_SET_LED: - DEBUGP("SET LED(%u,%u) ", poh->reg, poh->val); + DEBUGP("SET LED(%u,%u)\n", poh->reg, poh->val); led_switch(poh->reg, poh->val); break; + case OPENPCD_CMD_GET_SERIAL: DEBUGP("GET SERIAL("); poh->flags |= OPENPCD_FLAG_RESPOND; @@ -41,14 +112,15 @@ static int gen_usb_rx(struct req_ctx *rctx) return USB_ERR(USB_ERR_CMD_NOT_IMPL); } - DEBUGP("%s) ", hexdump(poh->data, 4)); + DEBUGP("%s)\n", hexdump(poh->data, 4)); #else /* FIXME: where to get serial in PICC case */ return USB_ERR(USB_ERR_CMD_NOT_IMPL); #endif break; + default: - DEBUGP("UNKNOWN "); + DEBUGP("UNKNOWN\n"); return USB_ERR(USB_ERR_CMD_UNKNOWN); break; } @@ -60,6 +132,13 @@ static int gen_usb_rx(struct req_ctx *rctx) void usbcmd_gen_init(void) { + DEBUGP("Inititalizing usbcmd_gen_init\n"); + /* setup FLASH write support for environment storage */ + flash_init(); + + /* retrieve default data from flash */ + memcpy(&config_stack,CONFIG_AREA_ADDR,sizeof(config_stack)); + usb_hdlr_register(&gen_usb_rx, OPENPCD_CMD_CLS_GENERIC); } diff --git a/firmware/src/os/usbcmd_generic.h b/firmware/src/os/usbcmd_generic.h index 0a7b8b7..4dd0456 100644 --- a/firmware/src/os/usbcmd_generic.h +++ b/firmware/src/os/usbcmd_generic.h @@ -1,4 +1,6 @@ #ifndef _USBAPI_GENERIC_H #define _USBAPI_GENERIC_H extern void usbcmd_gen_init(void); +extern int gen_setenv(void* data,u_int32_t pos,u_int32_t length); +extern int gen_getenv(void* data,u_int32_t pos,u_int32_t length); #endif -- cgit v1.2.3