void ProcessCmd(char *cmd) { // cmd is one char, dest address 1 byte, data follows // we already know address is ours here switch(cmd[0]) { case 'W': // queue new work if( Status.WorkQC < MAX_WORK_COUNT-1 ) { WorkQue[ (WorkNow + Status.WorkQC) & WORKMASK ] = *(WORKTASK *)(cmd+2); if(Status.WorkQC++ == 0) { AsicPreCalc(&WorkQue[WorkNow]); AsicPushWork(); } } SendCmdReply(cmd, (char *)&Status, sizeof(Status)); break; case 'A': // abort work, reply with hash completion count Status.WorkQC = WorkNow = 0; WorkQue[ (WorkNow + Status.WorkQC++) & WORKMASK ] = *(WORKTASK *)(cmd+2); AsicPreCalc(&WorkQue[WorkNow]); AsicPushWork(); SendCmdReply(cmd, (char *)&Status, sizeof(Status)); break; case 'I': // return identity SendCmdReply(cmd, (char *)&ID, sizeof(ID)); break; case 'S': // return status SendCmdReply(cmd, (char *)&Status, sizeof(Status)); break; case 'C': // set config values if( cmd[2] != 0 ) { Cfg = *(WORKCFG *)(cmd+2); if(Cfg.HashClock < MIN_HASH_CLOCK) Cfg.HashClock = MIN_HASH_CLOCK; if(Cfg.HashClock > MAX_HASH_CLOCK) Cfg.HashClock = MAX_HASH_CLOCK; ClockCfg[0] = ((DWORD)Cfg.HashClock << 18) | 0x00000003; HashTime = 256-(TICK_FACTOR/Cfg.HashClock); PWM1DCH = Cfg.FanTarget; } SendCmdReply(cmd, (char *)&Cfg, sizeof(Cfg)); break; case 'E': // enable/disable work HASH_CLK_EN = (cmd[2] == '1'); Status.State = (cmd[2] == '1') ? 'R' : 'D'; SendCmdReply(cmd, (char *)&Status, sizeof(Status)); break; case 'Z': //I2CDetect(); SendCmdReply(cmd, (char *)&I2CState, sizeof(I2CState)); // case 'D': // detect asics // DetectAsics(); // SendCmdReply(cmd, (char *)&Status, sizeof(Status)); break; default: break; } LED_On(); }
void ProcessCmd(char *cmd) { // cmd is one char, dest address 1 byte, data follows // we already know address is ours here switch(cmd[0]) { case 'W': // queue new work if( Status.WorkQC < MAX_WORK_COUNT-1 ) { WorkQue[ (WorkNow + Status.WorkQC++) & WORKMASK ] = *(WORKTASK *)(cmd+2); if(Status.State == 'R') { AsicPreCalc(&WorkQue[WorkNow]); AsicPushWork(); } } SendCmdReply(cmd, (char *)&Status, sizeof(Status)); break; case 'A': // abort work, reply status has hash completed count Status.WorkQC = WorkNow = 0; Status.State = 'R'; SendCmdReply(cmd, (char *)&Status, sizeof(Status)); break; case 'I': // return identity SendCmdReply(cmd, (char *)&ID, sizeof(ID)); break; case 'S': // return status SendCmdReply(cmd, (char *)&Status, sizeof(Status)); break; case 'C': // set config values if( *(WORD *)&cmd[2] != 0 ) { Cfg = *(WORKCFG *)(cmd+2); if(Cfg.HashClock < MIN_HASH_CLOCK) Cfg.HashClock = MIN_HASH_CLOCK; if(Cfg.HashClock <= HALF_HASH_CLOCK && Cfg.HashClock >= MAX_HASH_CLOCK/2) Cfg.HashClock = MAX_HASH_CLOCK/2-1; if(Cfg.HashClock >= MAX_HASH_CLOCK) Cfg.HashClock = MAX_HASH_CLOCK-1; if(Cfg.HashClock <= HALF_HASH_CLOCK) ClockCfg[0] = (((DWORD)Cfg.HashClock*2) << 18) | CLOCK_HALF_CHG; else ClockCfg[0] = ((DWORD)Cfg.HashClock << 18) | CLOCK_LOW_CHG; HashTime = 256-((DWORD)TICK_FACTOR/Cfg.HashClock); PWM1DCH = Cfg.FanTarget; } SendCmdReply(cmd, (char *)&Cfg, sizeof(Cfg)); break; case 'E': // enable/disable work HASH_CLK_EN = (cmd[2] == '1'); Status.State = (cmd[2] == '1') ? 'R' : 'D'; SendCmdReply(cmd, (char *)&Status, sizeof(Status)); break; case 'D': SendCmdReply(cmd, (char *)&HashTime, sizeof(HashTime)); default: break; } LED_On(); }
int main(void) { InitializeSystem(); while(1) { #if defined(USB_INTERRUPT) //if(USB_BUS_SENSE && (USBGetDeviceState() == DETACHED_STATE)) //{ USBDeviceAttach(); //} #endif /*if(USBDeviceState < CONFIGURED_STATE) { if(!I2CState.Slave) InitI2CSlave(); } else if(!I2CState.Master) InitI2CMaster();*/ #if defined(USB_POLLING) // Check bus status and service USB interrupts. USBDeviceTasks(); // Interrupt or polling method. If using polling, must call // this function periodically. This function will take care // of processing and responding to SETUP transactions // (such as during the enumeration process when you first // plug in). USB hosts require that USB devices should accept // and process SETUP packets in a timely fashion. Therefore, // when using polling, this function should be called // regularly (such as once every 1.8ms or faster** [see // inline code comments in usb_device.c for explanation when // "or faster" applies]) In most cases, the USBDeviceTasks() // function does not take very long to execute (ex: <100 // instruction cycles) before it returns. #endif if(TMR0IF) WorkTick(); if(Status.State == 'P'){ AsicPushWork(); } ProcessIO(); }//end while }//end main