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,7 +15,7 @@
#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;
@@ -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) {
// Is a control token so reset
} else {
// Not a control token so is data
/* Get buffer data from host - IAP OUT from host always into a single buffer */
xc_ptr p = iap_from_host_buffer + 4;
xc_ptr p0 = p;
int tail;
inuint(c_iap_from_host); // And discard
while (!testct(c_iap_from_host))
{
unsigned int datum = inuint(c_iap_from_host);
write_via_xc_ptr(p, datum);
p += 4;
}
tail = inct(c_iap_from_host);
datalength = p - p0;// - 4;
switch (tail)
{
case 10:
// the tail is 0 which means
datalength -= 6;
break;
case 11:
// the tail is 1 which means
datalength -= 5;
break;
case 12:
// the tail is 2 which means
datalength -= 4;
break;
case 13:
// the tail is 3 which means
datalength -= 3;
break;
default:
// // Case not handled before
// printstrln("Tail case not handled (tail, datalength)");
// printintln(tail);
// printintln(datalength);
break;
}
/* Get buffer data from host - IAP OUT from host always into a single buffer */ XUD_SetNotReady(ep_iap_from_host);
{
xc_ptr p = iap_from_host_buffer + 4; write_via_xc_ptr(iap_from_host_buffer, datalength);
xc_ptr p0 = p;
int tail; /* release the buffer */
while (!testct(c_iap_from_host)) SET_SHARED_GLOBAL(g_iap_from_host_flag, 1);
{
unsigned int datum = inuint(c_iap_from_host);
write_via_xc_ptr(p, datum);
p += 4;
}
tail = inct(c_iap_from_host);
datalength = p - p0;// - 4;
switch (tail)
{
case 10:
// the tail is 0 which means
datalength -= 6;
break;
case 11:
// the tail is 1 which means
datalength -= 5;
break;
case 12:
// the tail is 2 which means
datalength -= 4;
break;
case 13:
// the tail is 3 which means
datalength -= 3;
break;
default:
// // Case not handled before
// printstrln("Tail case not handled (tail, datalength)");
// printintln(tail);
// printintln(datalength);
break;
}
} }
XUD_SetNotReady(ep_iap_from_host);
write_via_xc_ptr(iap_from_host_buffer, datalength);
/* release the buffer */
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) {
// Is a control token so reset
} else {
inuint(c_iap_to_host); // And discard
// fill in the data
XUD_SetData_Inline(ep_iap_to_host, c_iap_to_host);
// fill in the data XUD_SetNotReady(ep_iap_to_host);
XUD_SetData_Inline(ep_iap_to_host, c_iap_to_host);
XUD_SetNotReady(ep_iap_to_host); // ack the decouple thread to say it has been sent to host
SET_SHARED_GLOBAL(g_iap_to_host_flag, 1);
// ack the decouple thread to say it has been sent to host
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) {
// Is a control token so reset
} else {
inuint(c_iap_to_host_int); // And discard
// fill in the data
XUD_SetData_Inline(ep_iap_to_host_int, c_iap_to_host_int);
// fill in the data XUD_SetNotReady(ep_iap_to_host_int);
XUD_SetData_Inline(ep_iap_to_host_int, c_iap_to_host_int); // Don't need to handle data here as always ZLP
}
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();
} }