added toplevel makefile for xpd
This commit is contained in:
@@ -22,28 +22,28 @@ extern int DFU_reset_override;
|
||||
extern void DFUCustomFlashEnable();
|
||||
extern void DFUCustomFlashDisable();
|
||||
|
||||
void temp()
|
||||
void temp()
|
||||
{
|
||||
asm(".linkset DFU_reset_override, _edp.bss");
|
||||
asm(".globl DFU_reset_override");
|
||||
}
|
||||
|
||||
static int DFU_OpenFlash(chanend ?c_user_cmd)
|
||||
static int DFU_OpenFlash(chanend ?c_user_cmd)
|
||||
{
|
||||
if (!DFU_flash_connected)
|
||||
if (!DFU_flash_connected)
|
||||
{
|
||||
unsigned int cmd_data[16];
|
||||
DFUCustomFlashEnable();
|
||||
flash_cmd_init();
|
||||
DFU_flash_connected = 1;
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int DFU_CloseFlash(chanend ?c_user_cmd)
|
||||
static int DFU_CloseFlash(chanend ?c_user_cmd)
|
||||
{
|
||||
if (DFU_flash_connected)
|
||||
if (DFU_flash_connected)
|
||||
{
|
||||
unsigned int cmd_data[16];
|
||||
DFUCustomFlashDisable();
|
||||
@@ -53,9 +53,9 @@ static int DFU_CloseFlash(chanend ?c_user_cmd)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int DFU_Detach(unsigned int timeout, chanend ?c_user_cmd)
|
||||
static int DFU_Detach(unsigned int timeout, chanend ?c_user_cmd)
|
||||
{
|
||||
if (DFU_state == STATE_APP_IDLE)
|
||||
if (DFU_state == STATE_APP_IDLE)
|
||||
{
|
||||
|
||||
DFU_state = STATE_APP_DETACH;
|
||||
@@ -64,15 +64,15 @@ static int DFU_Detach(unsigned int timeout, chanend ?c_user_cmd)
|
||||
|
||||
// Setup DFU timeout value
|
||||
DFUResetTimeout = timeout * 100000;
|
||||
|
||||
|
||||
// Start DFU reset timer
|
||||
DFUTimer :> DFUTimerStart;
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
DFU_state = STATE_DFU_ERROR;
|
||||
}
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int DFU_Dnload(unsigned int request_len, unsigned int block_num, unsigned int request_data[16], chanend ?c_user_cmd)
|
||||
@@ -86,7 +86,7 @@ static int DFU_Dnload(unsigned int request_len, unsigned int block_num, unsigned
|
||||
|
||||
DFU_OpenFlash(c_user_cmd);
|
||||
|
||||
switch (DFU_state)
|
||||
switch (DFU_state)
|
||||
{
|
||||
case STATE_DFU_IDLE:
|
||||
case STATE_DFU_DOWNLOAD_IDLE:
|
||||
@@ -96,29 +96,29 @@ static int DFU_Dnload(unsigned int request_len, unsigned int block_num, unsigned
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((DFU_state == STATE_DFU_IDLE) && (request_len == 0))
|
||||
if ((DFU_state == STATE_DFU_IDLE) && (request_len == 0))
|
||||
{
|
||||
DFU_state = STATE_DFU_ERROR;
|
||||
return 0;
|
||||
}
|
||||
else if (DFU_state == STATE_DFU_IDLE)
|
||||
}
|
||||
else if (DFU_state == STATE_DFU_IDLE)
|
||||
{
|
||||
fromDfuIdle = 1;
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
fromDfuIdle = 0;
|
||||
}
|
||||
|
||||
if (request_len == 0)
|
||||
if (request_len == 0)
|
||||
{
|
||||
// Host signalling complete download
|
||||
int i = 0;
|
||||
unsigned int cmd_data[16];
|
||||
if (subPagesLeft)
|
||||
if (subPagesLeft)
|
||||
{
|
||||
unsigned int subPagePad[16] = {0};
|
||||
for (i = 0; i < subPagesLeft; i++)
|
||||
for (i = 0; i < subPagesLeft; i++)
|
||||
{
|
||||
flash_cmd_write_page_data((subPagePad, unsigned char[64]));
|
||||
}
|
||||
@@ -128,16 +128,16 @@ static int DFU_Dnload(unsigned int request_len, unsigned int block_num, unsigned
|
||||
flash_cmd_write_page((cmd_data, unsigned char[]));
|
||||
|
||||
DFU_state = STATE_DFU_MANIFEST_SYNC;
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned int i = 0;
|
||||
unsigned int flash_cmd = 0;
|
||||
unsigned int flash_page_index = 0;
|
||||
unsigned int cmd_data[16];
|
||||
|
||||
if (fromDfuIdle)
|
||||
{
|
||||
|
||||
if (fromDfuIdle)
|
||||
{
|
||||
unsigned s = 0;
|
||||
|
||||
// Erase flash on first block
|
||||
@@ -145,14 +145,14 @@ static int DFU_Dnload(unsigned int request_len, unsigned int block_num, unsigned
|
||||
}
|
||||
|
||||
// Program firmware, STATE_DFU_DOWNLOAD_BUSY not currently used
|
||||
if (!(block_num % 4))
|
||||
if (!(block_num % 4))
|
||||
{
|
||||
cmd_data[0] = !fromDfuIdle; // 0 for first page, 1 for other pages.
|
||||
flash_cmd_write_page((cmd_data, unsigned char[64]));
|
||||
subPagesLeft = 4;
|
||||
}
|
||||
|
||||
for (i = 0; i < 16; i++)
|
||||
|
||||
for (i = 0; i < 16; i++)
|
||||
{
|
||||
cmd_data[i] = request_data[i];
|
||||
}
|
||||
@@ -163,11 +163,11 @@ static int DFU_Dnload(unsigned int request_len, unsigned int block_num, unsigned
|
||||
DFU_state = STATE_DFU_DOWNLOAD_SYNC;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int DFU_Upload(unsigned int request_len, unsigned int block_num, unsigned int request_data[16], chanend ?c_user_cmd)
|
||||
static int DFU_Upload(unsigned int request_len, unsigned int block_num, unsigned int request_data[16], chanend ?c_user_cmd)
|
||||
{
|
||||
unsigned int cmd_data[16];
|
||||
unsigned int firstRead = 0;
|
||||
@@ -176,8 +176,8 @@ static int DFU_Upload(unsigned int request_len, unsigned int block_num, unsigned
|
||||
// Keep reading flash pages until read_page returns 1 (address out of range)
|
||||
// Return terminating upload packet at this point
|
||||
DFU_OpenFlash(c_user_cmd);
|
||||
|
||||
switch (DFU_state)
|
||||
|
||||
switch (DFU_state)
|
||||
{
|
||||
case STATE_DFU_IDLE:
|
||||
case STATE_DFU_UPLOAD_IDLE:
|
||||
@@ -187,18 +187,18 @@ static int DFU_Upload(unsigned int request_len, unsigned int block_num, unsigned
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((DFU_state == STATE_DFU_IDLE) && (request_len == 0))
|
||||
if ((DFU_state == STATE_DFU_IDLE) && (request_len == 0))
|
||||
{
|
||||
DFU_state = STATE_DFU_ERROR;
|
||||
return 0;
|
||||
}
|
||||
else if (DFU_state == STATE_DFU_IDLE)
|
||||
}
|
||||
else if (DFU_state == STATE_DFU_IDLE)
|
||||
{
|
||||
firstRead = 1;
|
||||
subPagesLeft = 0;
|
||||
}
|
||||
|
||||
if (!subPagesLeft)
|
||||
if (!subPagesLeft)
|
||||
{
|
||||
cmd_data[0] = !firstRead;
|
||||
|
||||
@@ -207,14 +207,14 @@ static int DFU_Upload(unsigned int request_len, unsigned int block_num, unsigned
|
||||
subPagesLeft = 4;
|
||||
|
||||
// If address out of range, terminate!
|
||||
if (cmd_data[0] == 1)
|
||||
if (cmd_data[0] == 1)
|
||||
{
|
||||
subPagesLeft = 0;
|
||||
// Back to idle state, upload complete
|
||||
DFU_state = STATE_DFU_IDLE;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Read page data
|
||||
flash_cmd_write_page_data((request_data, unsigned char[64]));
|
||||
@@ -223,16 +223,16 @@ static int DFU_Upload(unsigned int request_len, unsigned int block_num, unsigned
|
||||
|
||||
DFU_state = STATE_DFU_UPLOAD_IDLE;
|
||||
|
||||
return 64;
|
||||
return 64;
|
||||
}
|
||||
|
||||
static int DFU_GetStatus(unsigned int request_len, unsigned int request_data[16], chanend ?c_user_cmd)
|
||||
static int DFU_GetStatus(unsigned int request_len, unsigned int request_data[16], chanend ?c_user_cmd)
|
||||
{
|
||||
unsigned int timeout = 0;
|
||||
|
||||
request_data[0] = timeout << 8 | (unsigned char)DFU_status;
|
||||
|
||||
switch (DFU_state)
|
||||
|
||||
switch (DFU_state)
|
||||
{
|
||||
case STATE_DFU_MANIFEST:
|
||||
case STATE_DFU_MANIFEST_WAIT_RESET:
|
||||
@@ -255,28 +255,28 @@ static int DFU_GetStatus(unsigned int request_len, unsigned int request_data[16]
|
||||
|
||||
request_data[1] = DFU_state;
|
||||
|
||||
return 6;
|
||||
return 6;
|
||||
}
|
||||
|
||||
static int DFU_ClrStatus(void)
|
||||
static int DFU_ClrStatus(void)
|
||||
{
|
||||
if (DFU_state == STATE_DFU_ERROR)
|
||||
if (DFU_state == STATE_DFU_ERROR)
|
||||
{
|
||||
DFU_state = STATE_DFU_IDLE;
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
DFU_state = STATE_DFU_ERROR;
|
||||
}
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int DFU_GetState(unsigned int request_len, unsigned int request_data[16], chanend ?c_user_cmd)
|
||||
static int DFU_GetState(unsigned int request_len, unsigned int request_data[16], chanend ?c_user_cmd)
|
||||
{
|
||||
|
||||
request_data[0] = DFU_state;
|
||||
|
||||
switch (DFU_state)
|
||||
switch (DFU_state)
|
||||
{
|
||||
case STATE_DFU_DOWNLOAD_BUSY:
|
||||
case STATE_DFU_MANIFEST:
|
||||
@@ -287,22 +287,22 @@ static int DFU_GetState(unsigned int request_len, unsigned int request_data[16],
|
||||
break;
|
||||
}
|
||||
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int DFU_Abort(void)
|
||||
static int DFU_Abort(void)
|
||||
{
|
||||
DFU_state = STATE_DFU_IDLE;
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Tell the DFU state machine that a USB reset has occured
|
||||
int DFUReportResetState(chanend ?c_user_cmd)
|
||||
int DFUReportResetState(chanend ?c_user_cmd)
|
||||
{
|
||||
unsigned int inDFU = 0;
|
||||
unsigned int currentTime = 0;
|
||||
|
||||
if (DFU_reset_override == 0x11042011)
|
||||
if (DFU_reset_override == 0x11042011)
|
||||
{
|
||||
unsigned int cmd_data[16];
|
||||
inDFU = 1;
|
||||
@@ -310,19 +310,19 @@ int DFUReportResetState(chanend ?c_user_cmd)
|
||||
return inDFU;
|
||||
}
|
||||
|
||||
switch(DFU_state)
|
||||
switch(DFU_state)
|
||||
{
|
||||
case STATE_APP_DETACH:
|
||||
case STATE_DFU_IDLE:
|
||||
DFU_state = STATE_DFU_IDLE;
|
||||
|
||||
DFUTimer :> currentTime;
|
||||
if (currentTime - DFUTimerStart > DFUResetTimeout)
|
||||
if (currentTime - DFUTimerStart > DFUResetTimeout)
|
||||
{
|
||||
DFU_state = STATE_APP_IDLE;
|
||||
inDFU = 0;
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
inDFU = 1;
|
||||
}
|
||||
@@ -339,13 +339,13 @@ int DFUReportResetState(chanend ?c_user_cmd)
|
||||
inDFU = 0;
|
||||
DFU_state = STATE_APP_IDLE;
|
||||
break;
|
||||
default:
|
||||
default:
|
||||
DFU_state = STATE_DFU_ERROR;
|
||||
inDFU = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!inDFU)
|
||||
if (!inDFU)
|
||||
{
|
||||
DFU_CloseFlash(c_user_cmd);
|
||||
}
|
||||
@@ -363,7 +363,7 @@ static int XMOS_DFU_RevertFactory(chanend ?c_user_cmd)
|
||||
|
||||
DFUTimer :> s;
|
||||
DFUTimer when timerafter(s + 25000000) :> s; // Wait for flash erase
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -376,7 +376,7 @@ static int XMOS_DFU_SelectImage(unsigned int index, chanend ?c_user_cmd)
|
||||
|
||||
|
||||
static int XMOS_DFU_SaveState()
|
||||
{
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -391,16 +391,16 @@ int DFUDeviceRequests(XUD_ep ep0_out, XUD_ep &?ep0_in, USB_SetupPacket_t &sp, ch
|
||||
unsigned int data_buffer_len = 0;
|
||||
unsigned int data_buffer[17];
|
||||
unsigned int reset_device_after_ack = 0;
|
||||
|
||||
if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_H2D)
|
||||
{
|
||||
|
||||
if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_H2D)
|
||||
{
|
||||
// Host to device
|
||||
if (sp.wLength)
|
||||
if (sp.wLength)
|
||||
data_buffer_len = XUD_GetBuffer(ep0_out, (data_buffer, unsigned char[]));
|
||||
}
|
||||
|
||||
// Map Standard DFU commands onto device level firmware upgrade mechanism
|
||||
switch (sp.bRequest)
|
||||
switch (sp.bRequest)
|
||||
{
|
||||
case DFU_DETACH:
|
||||
return_data_len = DFU_Detach(sp.wValue, c_user_cmd);
|
||||
@@ -456,16 +456,16 @@ int DFUDeviceRequests(XUD_ep ep0_out, XUD_ep &?ep0_in, USB_SetupPacket_t &sp, ch
|
||||
break;
|
||||
}
|
||||
|
||||
if (sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_D2H && sp.wLength != 0)
|
||||
{
|
||||
if (sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_D2H && sp.wLength != 0)
|
||||
{
|
||||
// Device to host
|
||||
#ifdef ARCH_G
|
||||
XUD_DoGetRequest(ep0_out, 0, (data_buffer, unsigned char[]), return_data_len, return_data_len);
|
||||
#else
|
||||
XUD_DoGetRequest(ep0_out, ep0_in, (data_buffer, unsigned char[]), return_data_len, return_data_len);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef ARCH_G
|
||||
XUD_DoSetRequestStatus(ep0_out);
|
||||
@@ -475,11 +475,11 @@ int DFUDeviceRequests(XUD_ep ep0_out, XUD_ep &?ep0_in, USB_SetupPacket_t &sp, ch
|
||||
}
|
||||
|
||||
// If device reset requested, handle after command acknowledgement
|
||||
if (reset_device_after_ack)
|
||||
if (reset_device_after_ack)
|
||||
{
|
||||
if (user_reset)
|
||||
if (user_reset)
|
||||
{
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user