void main(void) { SYSTEMConfig(SYS_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE); INTEnableSystemMultiVectoredInt(); ANSELA = 0x00000000; ANSELB = 0x00000000; initUART(); I2CModule * i2c = initI2C(); //testUART(); SID * sid = createSid(); SIDPlayer * sidPlayer = createSIDPlayer(sid); initSIDNet(sidPlayer,getI2CReceiveBuffer(i2c),getI2CTransmitBuffer(i2c)); writeStringUART(HELLO_MSG,strlen(HELLO_MSG)); while(1) { if(FIFOCount(getI2CReceiveBuffer(i2c)) >0) { // writeFIFO(getI2CTransmitBuffer(i2c),readFIFO(getI2CReceiveBuffer(i2c)) & 0xFF); processSidNetCommand(); } //play(); } }
BOOL processSidNetCommand (void) { if(SIDNetCmd.incomplete) { if(SIDNetCmd.dataLength > FIFORemaining(SIDNetCmd.cmdFifo)) { SIDNetCmd.incomplete = TRUE; return; } } else { if(FIFOCount(SIDNetCmd.cmdFifo) < 4) return; SIDNetCmd.cmd = readFIFO(SIDNetCmd.cmdFifo) & 0xFF; SIDNetCmd.sid = readFIFO(SIDNetCmd.cmdFifo) & 0xFF; SIDNetCmd.dataLength = ((readFIFO(SIDNetCmd.cmdFifo) & 0xFF) << 8) | (readFIFO(SIDNetCmd.cmdFifo) &0xFF); #ifdef DEBUG char buf[100]; sprintf(buf,"Cmd %d Sid %d DataLen %d\r\n\0",SIDNetCmd.cmd,SIDNetCmd.sid,SIDNetCmd.dataLength); writeStringUART(buf,strlen(buf)); #endif if(SIDNetCmd.dataLength > MAX_DATA) { #ifdef DEBUG char buf[100]; sprintf(buf,"Max data length %d exceeded %d \r\n\0",MAX_DATA,SIDNetCmd.dataLength); writeStringUART(buf,strlen(buf)); #endif while(1); } if(SIDNetCmd.dataLength > FIFORemaining(SIDNetCmd.cmdFifo)) { SIDNetCmd.incomplete = TRUE; return; } } SIDNetCmd.incomplete = FALSE; _copyCmdData(); _processSidNetCommand(); }
int main(int argc,char *argv[]) { int *g; int *new_g; int gsize; int count; int i; int j; int best_count; int best_i; void *f; char *key; /* * start with graph of size 8 */ gsize = 8; g = (int *)malloc(gsize*gsize*sizeof(int)); if(g == NULL) exit(1); /* * start out with all zeros */ memset(g,0,gsize*gsize*sizeof(int)); /* * make a fifo for the tabu list */ f = FIFOInitGraph(100000); if(f == NULL) exit(1); /* * while we do not have a publishable result */ while(gsize < 102) { /* * find out how we are doing */ count = CliqueCount(g,gsize); /* * if we have a counter example */ if(count == 0) { printf("Eureka! Counter-example found!\n"); PrintGraph(g,gsize); /* * make a new graph one size bigger */ new_g = (int *)malloc((gsize+1)*(gsize+1)*sizeof(int)); if(new_g == NULL) exit(1); /* * copy the old graph into the new graph leaving the * last row and last column alone */ CopyGraph(g,gsize,new_g,gsize+1); /* * zero out the last column and last row */ for(i=0; i < (gsize+1); i++) { new_g[i*(gsize+1) + gsize] = 0; // last column new_g[gsize*(gsize+1) + i] = 0; // last row } /* * throw away the old graph and make new one the * graph */ free(g); g = new_g; gsize = gsize+1; f = FIFOResetGraph(f); /* * keep going */ continue; } /* * otherwise, we need to consider flipping an edge * * let's speculative flip each edge, record the new count, * and unflip the edge. We'll then remember the best flip and * keep it next time around * * only need to work with upper triangle of matrix => * notice the indices */ best_count = 9999999; for(i=1; i <= gsize/2; i++) { /* * flip the edges corresponding to this distance */ Recolor(g,gsize,i); count = CliqueCount(g,gsize); /* * is it better and not already tabu? */ if((count < best_count) && !FIFOFindGraph(f,g,gsize)) { best_count = count; best_i = i; } /* * flip it back */ Recolor(g,gsize,i); } /* * keep the best flip we saw */ Recolor(g,gsize,best_i); printf("size: %d best_count: %d, best distance: %d, color: %d, size: %d\n", gsize, best_count, best_i, g[0*gsize+best_i], FIFOCount(f)); /* * add this edge to the fifo */ if(best_count != 0) FIFOInsertGraph(f,g,gsize); MakeGraphKey(g,gsize,&key); free(key); /* * rinse and repeat */ } FIFODeleteGraph(f); return(0); }
void _processSidNetCommand(void) { UINT8 responseBuffer[100]; int responseLength = 0,i; switch (SIDNetCmd.cmd) { case FLUSH: sidPlayerFlush(SIDNetCmd.sidPlayer); responseBuffer[responseLength++] = OK; break; case TRY_SET_SID_COUNT: responseBuffer[responseLength++] = OK; break; case MUTE: responseBuffer[responseLength++] = OK; break; case TRY_RESET: //resetFifo(playFifo); //playing = false; responseBuffer[responseLength++] = OK; break; case GET_VERSION: { responseBuffer[responseLength++] = VERSION; responseBuffer[responseLength++] = SID_NETWORK_PROTOCOL_VERSION; break; } case TRY_SET_SAMPLING: responseBuffer[responseLength++] = OK; break; case TRY_SET_CLOCKING: responseBuffer[responseLength++] = OK; break; case GET_CONFIG_COUNT: responseBuffer[responseLength++] = COUNT; responseBuffer[responseLength++] = 1; break; case GET_CONFIG_INFO: { responseBuffer[responseLength++] = INFO; responseBuffer[responseLength++] = 0; strcpy(&responseBuffer[0] + responseLength,SID_PI); responseLength += sizeof SID_PI; responseBuffer[responseLength++] = 0; break; } case SET_SID_POSITION: responseBuffer[responseLength++] = OK; break; case TRY_SET_SID_MODEL: responseBuffer[responseLength++] = OK; break; case TRY_WRITE: { if((FIFOCount(getSIDPlayerBuffer(SIDNetCmd.sidPlayer)) + SIDNetCmd.dataLength) > FIFOSize(getSIDPlayerBuffer(SIDNetCmd.sidPlayer))) { #ifdef DEBUG char buf[100]; sprintf(buf,"Player buffer full\r\n\0"); writeStringUART(buf,strlen(buf)); #endif responseBuffer[responseLength++] = BUSY; break; } for(i=0;i<SIDNetCmd.dataLength;i++) { if(writeFIFO(getSIDPlayerBuffer(SIDNetCmd.sidPlayer),SIDNetCmd.data[i]) < 0) { responseBuffer[responseLength++] = ERR; #ifdef DEBUG char buf[100]; sprintf(buf,"Cannot write to player buffer\r\n\0"); writeStringUART(buf,strlen(buf)); #endif break; } } responseBuffer[responseLength++] = OK; break; } default: responseBuffer[responseLength++] = OK; break; } for(i=0;i<responseLength;i++) { writeFIFO(SIDNetCmd.respFifo,responseBuffer[i]); } }