int main(void) { int retval; retval = initializeSPI(20000000, // Default to 20MHz SPI_MODE_0, // SPI mode 0 0, // Default delay between transfers 8, // 8 bit words 0); // SPI device 0 if(retval) { fprintf(stderr, "Unable to initialize SPI.\n"); return -1; } // Print a progress bar (assume 80 columns) printf("----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----|\n"); // Create a set of 8 x 16 bit messages to cycle through // uint16_t txBuffer[8] = {0xDEAD, 0xBEEF, 0xBAAD, 0xF00D, // 0xDEAD, 0xBEEF, 0xBAAD, 0xF00D}; // In order to accurately test the time required to affect a tuning // We'll take Scotty at his word and assume that it'll take 126 sets of 16 bits // So, let's create an array this size, fill it with random data, and let it rip. uint16_t txBuffer[126]; for(int i = 0; i < 63; i++) { txBuffer[i * 2 + 0] = 0xAAAA; txBuffer[i * 2 + 1] = 0x5555; } // Do the inner test ten thousand times (10000 * 126 * 2 = 2.52 MB) for(int i = 0; i < 10000; i++) { // if(putSPIData(0, sizeof(txBuffer), txBuffer)) { // fprintf(stderr, "Error during SPI transfer!\n"); // return 1; // } if (putSPIData16(0, 126, txBuffer)) { fprintf(stderr, "Error during SPI transfer!\n"); return 1; } // Print a hash marker for the progress bar (assume 80 columns) if (i % 125 == 0) { printf("#"); fflush(stdout); } } printf("\n"); return 0; }
int main(void) { //Local Variables bool displayMode = true;//True if display mode, false if in data entry mode //Push buttons bool upPB = false; bool rightPB = false; bool downPB = false; bool leftPB = false; bool modePB = false; //Push buttons shift registers uint16_t shiftRegSW2 = 0xFFFF; uint16_t shiftRegSW3 = 0xFFFF; uint16_t shiftRegSW4 = 0xFFFF; uint16_t shiftRegSW5 = 0xFFFF; uint16_t shiftRegSW6 = 0xFFFF; //Initial display message uint8_t displayArray [SAVED_MSG_LEN_MAX] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; uint8_t inputArray [17] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; //Mark the indexcies of the array uint8_t endIndex = 19; uint8_t currIndex = 0; uint8_t inputIndex = 0; uint8_t tempIndex = 0; //Flag for overflwoing max char array length bool overflow = false; //Init color uint8_t color; //ADCval1 uint32_t ADCval1 = 0; uint32_t ADCval2 = 0; //Current string char myString[21] = "hello world"; char myChar; int8_t stringIndex=-1; // Initialize the PLLs so the the main CPU frequency is 80MHz PLL_Init(); //Configure Port C initPortC(); //Configure the SYSTICK timer 12.5uS ticks SYSTICKConfig(1000, true); //Configure Timer0 1mS ticks TIMER0Config(80000); //Configure watchdog with 1s reset WatchdogTIMERConfig(); // Initialize the GPIO Ports initializeGPIOPort(PORTA, &portA_config); initializeGPIOPort(PORTB, &portB_config); initializeGPIOPort(PORTC, &portC_config); initializeGPIOPort(PORTD, &portD_config); initializeGPIOPort(PORTE, &portE_config); initializeGPIOPort(PORTF, &portF_config); // Initialize SPI0 interface initializeSPI(SSI0, PHASE, POLARITY); //Init ADC ADCInit(); initializeDisplay(); // Set up the UARTS for 115200 8N1 InitializeUART(UART0); InitializeUART(UART2); InitializeUART(UART5); // Since PD7 is shared with the NMI, we need to clear the lock register and // set the commit register so that all the pins alternate functions can // be used. GPIO_PORTD_LOCK_R = 0x4C4F434B; GPIO_PORTD_CR_R = 0xFF; initializeGPIOPort(PORTD, &portD_config); EnableInterrupts(); //Get initial ADC values pwm = GetADCval(POT_RIGHT) / 40; ADCval2 = GetADCval(POT_LEFT) / 575; // Print out the current string uartTxPoll(UART0,"Hello World\n\r"); while(1) { if(checkADC){ pwm = GetADCval(POT_RIGHT) / 40; ADCval2 = GetADCval(POT_LEFT) / 600; checkADC = false; } //On systick interrupt display the current character and poll the buttons if (refreshLED){ if (displayMode){ displayLEDChar(displayArray[currIndex], ADCval2); } else{ displayLEDChar(inputArray[inputIndex], ADCval2); } refreshLED = false; } if (buttonPoll){ //Check if any buttons have been pushed //If so debounce them buttonPoll = false; //SW2 shiftRegSW2 = debounce(PORTA, SW2, shiftRegSW2); upPB = checkPB(shiftRegSW2); //SW3 shiftRegSW3 = debounce(PORTA, SW3, shiftRegSW3); rightPB = checkPB(shiftRegSW3); //SW4 shiftRegSW4 = debounce(PORTD, SW4, shiftRegSW4); downPB = checkPB(shiftRegSW4); //SW5 shiftRegSW5 = debounce(PORTD, SW5, shiftRegSW5); leftPB = checkPB(shiftRegSW5); //SW6 shiftRegSW6 = debounce(PORTF, SW6, shiftRegSW6); modePB = checkPB(shiftRegSW6); }//End polling //Display Mode if (displayMode){ //Check if right button is pressed if(rightPB){ //Clear the button press rightPB = false; //Display the next character in order in green color = GREEN_EN; if(currIndex == endIndex) currIndex = 0; else currIndex++; } //Check if left button is pressed else if(leftPB){ //Clear the button press leftPB = false; //Display the next character in reverse order in red color = RED_EN; if(currIndex == 0) currIndex = endIndex; else currIndex--; } //Check if mode button is pushed if(modePB){ //Clear the button press modePB = false; //change mode and reset parameters displayMode = false; inputIndex = 0; currIndex = 0; endIndex = 0; overflow = false; tempIndex = 0; displayArray[0] = 0; } } //Input Mode else{ //Check if right button is pressed if(rightPB || leftPB){ //Clear the button press rightPB = false; leftPB = false; //Save the current input character in the display array if //there is enough space if (tempIndex >= SAVED_MSG_LEN_MAX){ tempIndex= 0; overflow = true; } displayArray[tempIndex] = inputArray[inputIndex]; tempIndex++; } //Check if up button is pressed else if(upPB){ //Clear the button press upPB = false; //Display the next character in order in input array if(inputIndex == 15) inputIndex = 0; else inputIndex++; } //Check if down button is pressed else if(downPB){ //Clear the button press downPB = false; //Display the next character in reverse order input array if(inputIndex == 0) inputIndex = 15; else inputIndex--; } if(modePB){ //Clear the button press modePB = false; //change mode to display and reset parameters displayMode = true; color = GREEN_EN; if(overflow){ endIndex = SAVED_MSG_LEN_MAX - 1; } else if (tempIndex != 0) endIndex = tempIndex - 1; } } } }
int main(int argc,char** argv){ FILE* inputHex; int fileSize; int byteCount; int addr; int highLowToggle = LOW_BYTE; int ndx; uint16_t data; char hexData[128]; inputHex = fopen(argv[1],"r"); setATmega(ATMEGA_328P); initializeSPI(); if(programmingEnable() != 0x53){ printf("Programmer Out of Sync!!!\n"); return -1; } else { printf("In sync!\n"); } //printf("Erasing chip\n"); if(argv[2][0] == 'e'){ chipErase(); return 1; } //writeProgramMemoryByte(0,0xFF,LOW_BYTE); //chipErase(); usleep(25000); //printf("Fuse check: %hhX\n",readFuseBits()); //return 1; /*if(programmingEnable() != 0x53){ printf("Out of Sync!\n"); return -1; } else { printf("In sync!\n"); }*/ while(feof(inputHex) == 0){ fgets(hexData,128,inputHex); //printf("parsing %s\n",hexData); if(hexData[0] != ':'){ printf("Error in hex file!\n"); } byteCount = hexCharToInt(hexData[1]) << 4; byteCount |= hexCharToInt(hexData[2]); addr = hexCharToInt(hexData[3]) << 12; addr |= hexCharToInt(hexData[4]) << 8; addr |= hexCharToInt(hexData[5]) << 4; addr |= hexCharToInt(hexData[6]); addr /= 2; if(hexData[8] == '1'){ break; } else if(hexData[8] != '0'){ printf("Unsupported Hex file\n"); break; } ndx = 9; while(byteCount){ data = hexCharToInt(hexData[ndx]) << 4; ndx++; data |= hexCharToInt(hexData[ndx]); ndx++; data |= hexCharToInt(hexData[ndx]) << 12; ndx++; data |= hexCharToInt(hexData[ndx]) << 8; //printf("Writing byte %hX to address %hX\n",data,addr); writeProgramMemory(addr,data); usleep(4000); ndx++; addr++; byteCount -= 2; } } finishProgramming(); byteCount = 0; while(byteCount < 0x88){ printf("%X: %hX\n",byteCount,readProgramMemory(byteCount)); //printf("%X: %hhX %hhX\n",byteCount,readProgramMemoryByte(byteCount,HIGH_BYTE),readProgramMemoryByte(byteCount,LOW_BYTE)); byteCount++; } fclose(inputHex); }