Refactor inuint_byref to testct_byref to support using status reporting. Works as before.

This commit is contained in:
Russell
2011-11-02 17:28:09 +00:00
parent 03957a411c
commit 2aef37576c
3 changed files with 91 additions and 69 deletions

View File

@@ -1,2 +1,17 @@
//#pragma select handler
#include <xs1.h>
/* TODO Currently complier does not support inline select functions, hense this is in a seperate file to ensure this is not the case */
#pragma select handler #pragma select handler
void testct_byref(chanend c, unsigned &isCt) ; inline void testct_byref(chanend c, unsigned &isCt)
{
if (testct(c))
{
isCt = 1;
}
else
{
isCt = 0;
}
}
//void testct_byref(chanend c, unsigned &isCt) ;

View File

@@ -2,7 +2,7 @@
/* TODO Currently complier does not support inline select functions, hense this is in a seperate file to ensure this is not the case */ /* TODO Currently complier does not support inline select functions, hense this is in a seperate file to ensure this is not the case */
#pragma select handler #pragma select handler
void testct_byref(chanend c, unsigned &isCt) void testct_byrefnot(chanend c, unsigned &isCt)
{ {
if (testct(c)) if (testct(c))
{ {

View File

@@ -15,8 +15,8 @@
#include "xc_ptr.h" #include "xc_ptr.h"
#include "clockcmds.h" #include "clockcmds.h"
#include "xud.h" #include "xud.h"
#include "testct_byref.h"
//typedef unsigned int XUD_ep; //typedef unsigned int XUD_ep;
//int XUD_GetData_NoReq(chanend c, xc_ptr buffer); //int XUD_GetData_NoReq(chanend c, xc_ptr buffer);
@@ -539,84 +539,92 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud
#endif #endif
#ifdef IAP #ifdef IAP
case inuint_byref(c_iap_from_host, tmp): case testct_byref(c_iap_from_host, tmp):
asm("#iap h->d"); asm("#iap h->d");
if (tmp) {
/* Get buffer data from host - IAP OUT from host always into a single buffer */ // Is a control token so reset
{ } else {
xc_ptr p = iap_from_host_buffer + 4; // Not a control token so is data
xc_ptr p0 = p; /* Get buffer data from host - IAP OUT from host always into a single buffer */
int tail; xc_ptr p = iap_from_host_buffer + 4;
while (!testct(c_iap_from_host)) xc_ptr p0 = p;
{ int tail;
unsigned int datum = inuint(c_iap_from_host); inuint(c_iap_from_host); // And discard
write_via_xc_ptr(p, datum); while (!testct(c_iap_from_host))
p += 4; {
} unsigned int datum = inuint(c_iap_from_host);
tail = inct(c_iap_from_host); write_via_xc_ptr(p, datum);
datalength = p - p0;// - 4; p += 4;
switch (tail) }
{ tail = inct(c_iap_from_host);
case 10: datalength = p - p0;// - 4;
// the tail is 0 which means switch (tail)
datalength -= 6; {
break; case 10:
case 11: // the tail is 0 which means
// the tail is 1 which means datalength -= 6;
datalength -= 5; break;
break; case 11:
case 12: // the tail is 1 which means
// the tail is 2 which means datalength -= 5;
datalength -= 4; break;
break; case 12:
case 13: // the tail is 2 which means
// the tail is 3 which means datalength -= 4;
datalength -= 3; break;
break; case 13:
default: // the tail is 3 which means
// // Case not handled before datalength -= 3;
// printstrln("Tail case not handled (tail, datalength)"); break;
// printintln(tail); default:
// printintln(datalength); // // Case not handled before
break; // printstrln("Tail case not handled (tail, datalength)");
} // printintln(tail);
} // printintln(datalength);
break;
}
XUD_SetNotReady(ep_iap_from_host); XUD_SetNotReady(ep_iap_from_host);
write_via_xc_ptr(iap_from_host_buffer, datalength); write_via_xc_ptr(iap_from_host_buffer, datalength);
/* release the buffer */ /* release the buffer */
SET_SHARED_GLOBAL(g_iap_from_host_flag, 1); SET_SHARED_GLOBAL(g_iap_from_host_flag, 1);
}
break; break;
/* IAP IN to host */ /* IAP IN to host */
case inuint_byref(c_iap_to_host, tmp): case testct_byref(c_iap_to_host, tmp):
asm("#iap d->h"); asm("#iap d->h");
if (tmp) {
// fill in the data // Is a control token so reset
XUD_SetData_Inline(ep_iap_to_host, c_iap_to_host); } else {
inuint(c_iap_to_host); // And discard
// fill in the data
XUD_SetData_Inline(ep_iap_to_host, c_iap_to_host);
XUD_SetNotReady(ep_iap_to_host); XUD_SetNotReady(ep_iap_to_host);
// ack the decouple thread to say it has been sent to host // ack the decouple thread to say it has been sent to host
SET_SHARED_GLOBAL(g_iap_to_host_flag, 1); SET_SHARED_GLOBAL(g_iap_to_host_flag, 1);
swap(iap_to_host_buffer, iap_to_host_waiting_buffer);
swap(iap_to_host_buffer, iap_to_host_waiting_buffer);
}
break; break;
/* IAP interrupt IN to host */ /* IAP interrupt IN to host */
case inuint_byref(c_iap_to_host_int, tmp): case testct_byref(c_iap_to_host_int, tmp):
asm("#iap interrupt d->h"); asm("#iap interrupt d->h");
if (tmp) {
// fill in the data // Is a control token so reset
XUD_SetData_Inline(ep_iap_to_host_int, c_iap_to_host_int); } else {
inuint(c_iap_to_host_int); // And discard
XUD_SetNotReady(ep_iap_to_host_int); // fill in the data
// Don't need to handle data here as always ZLP XUD_SetData_Inline(ep_iap_to_host_int, c_iap_to_host_int);
XUD_SetNotReady(ep_iap_to_host_int);
// Don't need to handle data here as always ZLP
}
break; break;
#endif #endif
} }
@@ -624,5 +632,4 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud
} }
set_thread_fast_mode_off(); set_thread_fast_mode_off();
} }