// Write out the R-Type instruction void rtype_instruction(char *instruction, char *rs, char *rt, char *rd, int shamt, FILE *Out) { // Set the instruction bits char *opcode = "000000"; char *rdBin = "00000"; if (strcmp(rd, "00000") != 0) rdBin = register_address(rd); char *rsBin = "00000"; if (strcmp(rs, "00000") != 0) rsBin = register_address(rs); char *rtBin = "00000"; if (strcmp(rt, "00000") != 0) rtBin = register_address(rt); char *func = NULL; char shamtBin[6]; // Convert shamt to binary and put in shamtBin as a char* getBin(shamt, shamtBin, 5); size_t i; for (i = 0; rMap[i].name != NULL; i++) { if (strcmp(instruction, rMap[i].name) == 0) { func = rMap[i].function; } } if(RADIX == 16) { char buf[40]; sprintf(buf,"%s%s%s%s%s%s", opcode, rsBin, rtBin, rdBin, shamtBin, func); int hex = getDec(buf); // Print out the instruction to the file fprintf(Out, "%08X,\n",hex); } else { fprintf(Out, "%s%s%s%s%s%s,\n", opcode, rsBin, rtBin, rdBin, shamtBin, func); } }
void L6470::Dump(void) { #ifndef NDEBUG uint8_t reg; printf("Registers:\n"); printf("01:ABS_POS - Current position: %ld\n", getPos()); printf("02:EL_POS - Electrical position: %ld\n", getParam(L6470_PARAM_EL_POS)); printf("03:MARK - Mark position: %ld\n", getMark()); printf("04:SPEED - Current speed: %ld (raw)\n", getParam(L6470_PARAM_SPEED)); printf("05:ACC - Acceleration: %.2f steps/s2\n", getAcc()); printf("06:DEC - Deceleration: %.2f steps/s2\n", getDec()); printf("07:MAX_SPEED - Maximum speed: %.2f steps/s\n", getMaxSpeed()); printf("08:MIN_SPEED - Minimum speed: %.2f steps/s\n", getMinSpeed()); printf("09:KVAL_HOLD - Holding KVAL: %d\n", (int) getHoldKVAL()); printf("0A:KVAL_RUN - Constant speed KVAL: %d\n", (int) getRunKVAL()); printf("0B:KVAL_ACC - Acceleration starting KVAL: %d\n", (int) getAccKVAL()); printf("0C:KVAL_Dec - Deceleration starting KVAL: %d\n", (int) getDecKVAL()); printf("0D:INT_SPEED - Intersect speed: 0x%.4X (raw)\n", (unsigned int) getParam(L6470_PARAM_INT_SPD)); reg = getParam(L6470_PARAM_ST_SLP); printf("0E:ST_SLP - Start slope: %.3f\%% s/step (0x%.2X)\n", (float) 100 * SlpCalcValueReg(reg), reg); reg = getParam(L6470_PARAM_FN_SLP_ACC); printf("0F:FN_SLP_ACC - Acceleration final slope: %.3f\%% s/step (0x%.2X)\n", (float) 100 * SlpCalcValueReg(reg), reg); reg = getParam(L6470_PARAM_FN_SLP_DEC); printf("10:FN_SLP_DEC - Deceleration final slope: %.3f\%% s/step (0x%.2X)\n", (float) 100 * SlpCalcValueReg(reg), reg); reg = getParam(L6470_PARAM_K_THERM); printf("11:K_THERM - Thermal compensation factor: %.3f (0x%.2X)\n", KThermCalcValueReg(reg), reg); reg = getParam(L6470_PARAM_ADC_OUT); printf("12:ADC_OUT - ADC output: 0x%.2X\n", reg & 0x1F); reg = getOCThreshold(); printf("13:OCD_TH - OCD threshold: %d mA (0x%.2X)\n", OcdThCalcValueReg(reg), reg); reg = getParam(L6470_PARAM_STALL_TH); printf("14:STALL_TH - STALL threshold: %d mA (0x%.2X)\n", StallThCalcValueReg(reg & 0x7F), reg); printf("15:FS_SPD - Full-step speed: %.2f steps/s\n", getFullSpeed()); printf("16:STEP_MODE - Step mode: %d microsteps\n", 1 << getStepMode()); printf("17:ALARM_EN - Alarm enable: 0x%.2X\n", (unsigned int) getParam(L6470_PARAM_ALARM_EN)); printf("18:CONFIG - IC configuration: 0x%.4X\n", (unsigned int) getParam(L6470_PARAM_CONFIG)); #endif }
//uint8_t readCfgFile(DATE *adate,TIME *atime, uint8_t *filename_dat, uint8_t atomic) uint8_t readCfgFile(char *filename_dat) //, uint8_t atomic) { DIR *dir; uint32_t cluster, fileSize, firstSector; uint16_t k; uint8_t i,j,ld,lt; uint8_t filename[]= "CONFIG CFG"; uint8_t filename2[]="_CONFIG CFG"; dir = findFiles (GET_FILE, filename, filename); //, atomic); //get the file location if(dir == 0) return(0); cluster = (((uint32_t) dir->firstClusterHI) << 16) | dir->firstClusterLO; fileSize = dir->fileSize; ld = 0; lt = 0; while(1) { ClusterNumber = cluster; firstSector = getFirstSector (); for(j=0; j<SectorPerCluster; j++) { SD_readSingleBlock(firstSector + j); //, atomic); for(k=0; k<512; k++) { switch(buffer[k]) { case 'S': k++; if(buffer[k]=='T') { k++; Time.h = getDec((uint8_t*)buffer+k); //k +=2; Time.m = getDec((uint8_t*)buffer+k+2); //k +=2; Time.s = getDec((uint8_t*)buffer+k+4); } else if(buffer[k]=='D') { k++; Date.d = getDec(&buffer[k]); //k +=2; Date.m = getDec(&buffer[k+2]); //k +=2; Date.y = 20 + getDec(&buffer[k+4]); } else if(buffer[k]=='F') { k = k+2; for(i=0;i<8;i++) { if(buffer[k+i] < 0x21) //if any control code and space { filename_dat[i] = 0x00; break; } filename_dat[i] = buffer[k+i]; } filename_dat[i+1] = 0x00; // i = strlcpy(filename_dat,&(buffer[k]),9); k = k+i; } else if(buffer[k]=='I') { k +=2; for(i=0;i<13;i++) { if(buffer[k+i] < 0x20) //if any control code break; inset[i] = buffer[k+i]; } } break; case 'A': k++; if(buffer[k]=='D') { k++; ADate[ld].d = getDec((uint8_t*)buffer+k); //k +=2; ADate[ld].m = getDec((uint8_t*)buffer+k+2); //k +=2; ADate[ld].y = 20 + getDec((uint8_t*)buffer+k+4); ld++; } else if(buffer[k]=='T') { k++; ATime[lt].h = getDec((uint8_t*)buffer+k); //k +=2; ATime[lt].m = getDec((uint8_t*)buffer+k+2); //k +=2; ATime[lt].s = getDec((uint8_t*)buffer+k+4); lt++; } break; } if (k >= fileSize ) { findFiles(RENAME, filename, filename2); //, atomic); return(lt); } } } ClusterNumber = cluster; cluster = getSetNextCluster (GET); //, 0, atomic); if(cluster == 0) { //#if BIGAVR == 1 // printf_P(PSTR("ERR GETTING CLUSTERb\n")); //#endif //BIGAVR return(0); } } return(0); }
void itype_parse(char *token, char *tok_ptr, hash_table_t *hash_table, int32_t instruction_count, FILE *Out) { int i; // la is pseudo instruction for lui and ori // Convert to lui and ori and pass those instructions if (strcmp(token, "la") == 0) { // Parse the instruction - get register & immediate char *inst_ptr = tok_ptr; char *reg = NULL; // Create an array of char* that stores rd, rs and shamt char **reg_store; reg_store = (char**)malloc(2 * sizeof(char*)); if (reg_store == NULL) { fprintf(Out, "Out of memory\n"); exit(1); } for (i = 0; i < 2; i++) { reg_store[i] = (char*)malloc(20 * sizeof(char)); if (reg_store[i] == NULL) { fprintf(Out, "Out of memory\n"); exit(1); } } // Keeps a reference to which register has been parsed for storage int count = 0; while (1) { reg = parse_token(inst_ptr, " $,\n\t", &inst_ptr, NULL); if (reg == NULL || *reg == '#') { break; } strcpy(reg_store[count], reg); count++; free(reg); } // Interpret la instruction. // The register is at reg_store[0] and the variable is at reg_store[1] // Find address of label in hash table int *address = (int*)hash_find(hash_table, reg_store[1], strlen(reg_store[1])+1); // Convert address to binary in char* char addressBinary[33]; getBin(*address, addressBinary, 32); // Get upper and lower bits of address char upperBits[16]; char lowerBits[16]; for (i = 0; i < 32; i++) { if (i < 16) lowerBits[i] = addressBinary[i]; else upperBits[i-16] = addressBinary[i]; } // Call the lui instruction with: lui $reg, upperBits // Convert upperBits binary to int int immediate = getDec(upperBits); itype_instruction("lui", "00000", reg_store[0], immediate, Out); // Call the ori instruction with: ori $reg, $reg, lowerBits // Convert lowerBits binary to int immediate = getDec(lowerBits); itype_instruction("ori", reg_store[0], reg_store[0], immediate, Out); // Dealloc reg_store for (i = 0; i < 2; i++) { free(reg_store[i]); } free(reg_store); } // I-Type $rt, i($rs) else if (strcmp(token, "lw") == 0 || strcmp(token, "sw") == 0 || strcmp(token, "lb") == 0 || strcmp(token, "lbu") == 0 || strcmp(token, "lh") == 0 || strcmp(token, "lhu") == 0 || strcmp(token, "sb") == 0 || strcmp(token, "sh") == 0 ) { // Parse the instructio - rt, immediate and rs char *inst_ptr = tok_ptr; char *reg = NULL; // // Create an array of char* that stores rd, rs, rt respectively char **reg_store; reg_store =(char**) malloc(3 * sizeof(char*)); if (reg_store == NULL) { fprintf(Out, "Out of memory\n"); exit(1); } for (i = 0; i < 3; i++) { reg_store[i] =(char*) malloc(20 * sizeof(char)); if (reg_store[i] == NULL) { fprintf(Out, "Out of memory\n"); exit(1); } } // Keeps a reference to which register has been parsed for storage int count = 0; while (1) { reg = parse_token(inst_ptr, " $,\n\t()", &inst_ptr, NULL); if (reg == NULL || *reg == '#') { break; } strcpy(reg_store[count], reg); count++; free(reg); } // rt in position 0, immediate in position 1 and rs in position2 int immediate = atoi(reg_store[1]); itype_instruction(token, reg_store[2], reg_store[0], immediate, Out); // Dealloc reg_store for (i = 0; i < 3; i++) { free(reg_store[i]); } free(reg_store); } // I-Type rt, rs, im else if (strcmp(token, "andi") == 0 || strcmp( token, "ori") == 0 || strcmp(token, "xori") == 0 || strcmp(token, "sltiu") == 0 || strcmp(token, "slti") == 0 || strcmp(token, "addi") == 0 || strcmp(token, "addiu") == 0 ) { // Parse the instruction - rt, rs, immediate char *inst_ptr = tok_ptr; char *reg = NULL; // Create an array of char* that stores rt, rs char **reg_store; reg_store =(char**) malloc(3 * sizeof(char*)); if (reg_store == NULL) { fprintf(Out, "Out of memory\n"); exit(1); } for (i = 0; i < 3; i++) { reg_store[i] =(char*) malloc(20 * sizeof(char)); if (reg_store[i] == NULL) { fprintf(Out, "Out of memory\n"); exit(1); } } // Keeps a reference to which register has been parsed for storage int count = 0; while (1) { reg = parse_token(inst_ptr, " $,\n\t", &inst_ptr, NULL); if (reg == NULL || *reg == '#') { break; } strcpy(reg_store[count], reg); count++; free(reg); } // rt in position 0, rs in position 1 and immediate in position 2 int immediate = atoi(reg_store[2]); itype_instruction(token, reg_store[1], reg_store[0], immediate, Out); // Dealloc reg_store for ( i = 0; i < 3; i++) { free(reg_store[i]); } free(reg_store); } // I-Type $rt, immediate else if (strcmp(token, "lui") == 0) { // Parse the insturction, rt - immediate char *inst_ptr = tok_ptr; char *reg = NULL; // Create an array of char* that stores rs, rt char **reg_store; reg_store =(char**) malloc(2 * sizeof(char*)); if (reg_store == NULL) { fprintf(Out, "Out of memory\n"); exit(1); } for (i = 0; i < 2; i++) { reg_store[i] =(char*) malloc(20 * sizeof(char)); if (reg_store[i] == NULL) { fprintf(Out, "Out of memory\n"); exit(1); } } // Keeps a reference to which register has been parsed for storage int count = 0; while (1) { reg = parse_token(inst_ptr, " $,\n\t", &inst_ptr, NULL); if (reg == NULL || *reg == '#') { break; } strcpy(reg_store[count], reg); count++; free(reg); } // rt in position 0, immediate in position 1 int immediate = atoi(reg_store[1]); itype_instruction(token, "00000", reg_store[0], immediate, Out); // Dealloc reg_store for (i = 0; i < 2; i++) { free(reg_store[i]); } free(reg_store); } // I-Type $rs, $rt, label else if (strcmp(token, "beq") == 0 || strcmp(token, "bne") == 0) { // Parse the instruction - rs, rt char *inst_ptr = tok_ptr; char *reg = NULL; // Create an array of char* that stores rs, rt char **reg_store; reg_store =(char**) malloc(2 * sizeof(char*)); if (reg_store == NULL) { fprintf(Out, "Out of memory\n"); exit(1); } for (i = 0; i < 2; i++) { reg_store[i] =(char*) malloc(20 * sizeof(char)); if (reg_store[i] == NULL) { fprintf(Out, "Out of memory\n"); exit(1); } } // Keeps a reference to which register has been parsed for storage int count = 0; while (1) { reg = parse_token(inst_ptr, " $,\n\t", &inst_ptr, NULL); if (reg == NULL || *reg == '#') { break; } strcpy(reg_store[count], reg); count++; free(reg); if (count == 2) break; } reg = parse_token(inst_ptr, " $,\n\t", &inst_ptr, NULL); // Find hash address for a register and put in an immediate int *address =(int*) hash_find(hash_table, reg, strlen(reg)+1); // beq跳转地址有问题 int immediate = (*address - instruction_count) >> 2; // Send instruction to itype function itype_instruction(token, reg_store[0], reg_store[1], immediate, Out); // Dealloc reg_store for (i = 0; i < 2; i++) { free(reg_store[i]); } free(reg_store); }
//uint8_t readCfgFile(DATE *adate,TIME *atime, uint8_t *filename_dat, uint8_t atomic) uint8_t readCfgFile(uint8_t *filename_dat, uint8_t atomic) { DIR *dir; uint32_t cluster, fileSize, firstSector; uint16_t k; uint8_t i,j,ld,lt; uint8_t filename[]="CONFIG CFG"; uint8_t filename2[]="_CONFIG CFG"; TIME_t time; DATE_t date; dir = findFiles (GET_FILE, filename, filename, atomic); //get the file location if(dir == 0) return(0); cluster = (((uint32_t) dir->firstClusterHI) << 16) | dir->firstClusterLO; fileSize = dir->fileSize; ld = 0; lt = 0; while(1) { firstSector = getFirstSector (cluster); for(j=0; j<SectorPerCluster; j++) { SD_readSingleBlock(firstSector + j, atomic); for(k=0; k<512; k++) { switch(buffer[k]) { case 'S': k++; switch(buffer[k]) { case 'T': k++; time.h = getDec((uint8_t*)buffer+k); time.m = getDec((uint8_t*)buffer+k+2); time.s = getDec((uint8_t*)buffer+k+4); break; case 'D': k++; date.d = getDec(&buffer[k]); date.m = getDec(&buffer[k+2]); date.y = 20 + getDec(&buffer[k+4]); break; case 'F': k = k+2; for(i=0;i<13;i++) { if(buffer[k+i] < 0x20) //if any control code break; filename_dat[i] = buffer[k+i]; } k = k+i; break; case 'M': //mask definitions: M - mic only, S - SHT sensor only, T - DS1820 1-wire sensor, X - Mic+SHT, '-' - nothing k++; for(i=0;i<12;i++) { Mask.SHT = Mask.SHT<<1; Mask.MIC = Mask.MIC<<1; switch(buffer[k+i]) { // case 'X': //SHT mask generated from mic mask! // Mask.SHT |= 0x0001; case 'M': Mask.MIC |= 0x0001; break; // case 'S': // Mask.SHT |= 0x0001; // break; case 'T': Mask.DS |= 0x01; // any T will cause DS mask to be one... break; default: break; } } k = k+i; } break; case 'A': k++; if(buffer[k]=='D') { k++; ADate[ld].d = getDec((uint8_t*)buffer+k); //k +=2; ADate[ld].m = getDec((uint8_t*)buffer+k+2); //k +=2; ADate[ld].y = 20 + getDec((uint8_t*)buffer+k+4); ld++; } else if(buffer[k]=='T') { k++; ATime[lt].h = getDec((uint8_t*)buffer+k); //k +=2; ATime[lt].m = getDec((uint8_t*)buffer+k+2); //k +=2; ATime[lt].s = getDec((uint8_t*)buffer+k+4); lt++; } break; } if (k >= fileSize ) { findFiles(RENAME,filename, filename2, atomic); RTC_SetDateTime(&date, &time); //?? if(Mask.SHT) // { generate_mask_bm(); // } return(lt); } } } cluster = getSetNextCluster (cluster, GET, 0, atomic); if(cluster == 0) { #if RSCOM == 1 printf_P(PSTR("ERR GETTING CLUSTERb\n")); #endif //BIGAVR return(0); } } return(0); }