void PWMC1_InterruptOnFault(void) { if (getRegBits(PWM_FSTS, (0x01 << 0x00))) { setRegBits(PWM_FSTS, (0x01 << 0x00)); /* Reset interrupt request flag */ PWMC1_OnFault0(); /* Invoke user event */ } }
/** * This method reads a byte from the SPI bus * @param Chr is the read byte * @return ERR_OK always ***************************************************************************/ byte SPI1_RecvChar(byte *Chr) { int i=0; byte ToRead=0; *Chr=0; //SCLK setRegBits(GPIO_E_DR,0x10); wait(4); for(i=7;i>=0;i--) { //SCLK clrRegBits(GPIO_E_DR,0x10); wait(4); ToRead= getRegBits(GPIO_E_DR,0x40); wait(1); *Chr |=(ToRead & 1)<<i; //SCLK setRegBits(GPIO_E_DR,0x10); wait(4); } wait(4); //SCLK setRegBits(GPIO_E_DR,0x10); }
/***************************************************************************** * void main(void) * * Main application. * * In: n/a * * Out: n/a *****************************************************************************/ void main(void) { UInt16 state; char *temp_ptr; extern word _vba; uint8_t sw0, sw1; INTC_VBA = ((word)&_vba) >> (21-INTC_VBA_BITS); /* Set Vector Base Address */ /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/ PE_low_level_init(); /*** End of Processor Expert internal initialization. ***/ /*StartDelay = pmem_read((unsigned int *)BOOT_START_DELAY_PLACE) & 0x00FF; if(!StartDelay) bootExit(); else bootTimerInit();*/ /* Write your code here */ GPIO_A_PER &= ~GPIO_A_PER_PE0_MASK; // set to GPIO mode GPIO_A_PER &= ~GPIO_A_PER_PE1_MASK; GPIO_A_DDR |= GPIO_A_DDR_DD0_MASK; // set as output GPIO_A_DDR |= GPIO_A_DDR_DD1_MASK; GPIO_A_DR &= ~GPIO_A_DR_D0_MASK; // set low GPIO_A_DR &= ~GPIO_A_DR_D1_MASK; Cpu_Delay100US(5000); // power-up delay // Initialize R0,R1,M01, and N for circular buffer (including shadows) asm { swap shadows ;// Switch to shadow registers moveu.w #(RX_DATA_SIZE-1),M01 ;// Set buffer size moveu.w #rx_data,R0 ;// Set starting address moveu.w #QSCI_STAT,R1 ;// Use R1 for SCI status register moveu.w #0,N ;// N is unused swap shadows ;// Switch back to normal registers } // with DEFCON 17, we used a timer to keep the badge in bootloader mode on power up for 10 seconds // for DEFCON 18, the bootloader mode is only enabled if both buttons are held down on power up // otherwise it jumps directly to the user application. no timer necessary, so that code is commented out // check buttons GPIO_C_PUR |= GPIO_C_PUR_PU0_MASK; // enable pull-up GPIO_C_PUR |= GPIO_C_PUR_PU1_MASK; GPIO_C_DDR &= ~GPIO_C_DDR_DD0_MASK; // set as input GPIO_C_DDR &= ~GPIO_C_DDR_DD1_MASK; GPIO_C_PER &= ~GPIO_C_PER_PE0_MASK; // set to GPIO mode GPIO_C_PER &= ~GPIO_C_PER_PE1_MASK; Cpu_Delay100US(1000); // setup delay #define SW0_PIN_MASK ((byte)1) /* Pin mask */ #define SW1_PIN_MASK ((byte)2) /* Pin mask */ sw0 = !((bool)(getRegBits(GPIO_C_RAWDATA,SW0_PIN_MASK))); sw1 = !((bool)(getRegBits(GPIO_C_RAWDATA,SW1_PIN_MASK))); if (sw0 || sw1) // one or more buttons has been pressed { Cpu_Delay100US(1000); // give the user time to press both buttons (also serves as 100mS debounce) sw0 = !((bool)(getRegBits(GPIO_C_RAWDATA,SW0_PIN_MASK))); sw1 = !((bool)(getRegBits(GPIO_C_RAWDATA,SW1_PIN_MASK))); } if (sw0 && sw1) // if both buttons have been pressed, enter bootloader { // Turn on LEDs so the user knows we're here GPIO_A_DR |= GPIO_A_DR_D0_MASK; // set high GPIO_A_DR |= GPIO_A_DR_D1_MASK; // Initialize globals mem_init(rx_data, NULL, RX_DATA_SIZE); data_out = data_in = rx_data; state = INITIAL_STATE; temp_ptr = rx_data; // Disable protection setReg(FM_PROT,BOOT_PROT_VALUE); // Output banner sci_tx(&StrCopyright[0]); // Now it is safe to enable interrupts Cpu_EnableInt(); do { // State: Initial State if (state == INITIAL_STATE) { status = 0; sci_tx(&StrWaitingSrec[0]); sci_tx_char(XON); state = WAIT_FOR_S; } if (data_in != temp_ptr) { //Timer_Disable(); // State: Wait for Header "S" if (state == WAIT_FOR_S) { temp_ptr = data_out; if (get_char(&temp_ptr) == 'S') { state = WAIT_FOR_0; } else { get_char(&data_out); } } // State: Wait for Header "0" else if (state == WAIT_FOR_0) { if (get_char(&temp_ptr) == '0') { state = WAIT_FOR_EOL; } else { get_char(&data_out); state = WAIT_FOR_S; } } // State: Wait for EOL else if (state == WAIT_FOR_EOL) { if (get_char(&temp_ptr) == '\r') { if (!(status & TX_XOFF)) { sci_tx_char(XOFF); status |= TX_XOFF; } srec_decode(); temp_ptr = data_out; } } } else { if (status & TX_XOFF) { sci_tx_char(XON); status &= ~TX_XOFF; } } // State: Error if (status & DOWNLOAD_ERROR) { sci_tx(StrErr); sci_tx(int_to_string(status)); state = INITIAL_STATE; sci_tx(StrNewLine); } //bootTimerCheck(); } while (status != DOWNLOAD_OK); sci_tx(StrNewLine); sci_tx(&StrLoaded[0]); } bootExit(); }