uint8 bu_start(CB_LIST *buffer) { uint8 result = BU_BAD_ARGUMENT; if (buffer != NULL) { if (_buffer == NULL) { _buffer = buffer; isr_1_StartEx(bu_interrupt); isr_1_ClearPending(); /* * This delay gives the button pins time to go high. */ CyDelay(10); result = BU_SUCCESS; } else { result = BU_FAILURE; } } return result; }
int main() { // Enable global interrupts CyGlobalIntEnable; // Enable bootloader button // (need to clear pending interrupt first) isr_1_ClearPending(); isr_1_StartEx(isr_bootloader); // Enable analog multiplexer (chooses thermocouple input) AMux_1_Start(); // Enable op-amp (amplifies thermocouple signal) Opamp_1_Start(); // Enable ADC (reads amplified signal) ADC_SAR_Seq_1_Start(); ADC_SAR_Seq_1_StartConvert(); // Enable serial transmission UART_1_Start(); // To avoid a flash on power-on, the relay pin is configured as a // high impedance input initially // Because some guy on the internet says so: // http://www.cypress.com/forum/psoc-4-architecture/low-initial-drive-state-pwm-components Pin_Relays_Write(1); // HIGH to turn PNP transistor OFF Pin_Relays_SetDriveMode(Pin_Relays_DM_STRONG); for(;;) { // Read thermocouples and send over serial // Note that externally (and over serial communication), // 0 is T1, 1 is T2, and 2 is T3 SendTemperature(0, ADC_OFFSET_0, OPAMP_GAIN_FACTOR_0); SendTemperature(1, ADC_OFFSET_1, OPAMP_GAIN_FACTOR_1); SendTemperature(2, ADC_OFFSET_2, OPAMP_GAIN_FACTOR_2); // Newline for easier debugging UART_1_UartPutString("\r\n"); // Wait a bit, processing serial command input in between delays uint8 i; for (i = 0; i < 5; i++) { ReadSerialInput(); CyDelay(100); } // Safety feature: Ensure that the relays do not stay on for more than // ~30 seconds without communication from the serial control program if (relayState) { if (++relayOnCycles >= 60) { UART_1_UartPutString("R=0 (inactivity)\r\n"); SetRelays(0); } } else { relayOnCycles = 0; } } }
/*main*/ void main(void) { /*Preliminary parts not important*/ LCD_Char_1_Start(); ADC_DelSig_1_Start(); ADC_DelSig_1_StartConvert(); Configure_DMA(); isr_1_StartEx(Buffer_complete); isr_2_StartEx(LPF_buffer_complete); ADC_DelSig_1_SetCoherency(ADC_DelSig_1_COHER_MID); Filter_SetDalign(Filter_STAGEA_DALIGN,Filter_ENABLED); Filter_SetDalign(Filter_HOLDA_DALIGN,Filter_ENABLED); Filter_SetCoherency(Filter_STAGEA_COHER,Filter_KEY_MID); Filter_SetCoherency(Filter_HOLDA_COHER,Filter_KEY_MID); Filter_SetCoherency(Filter_CHANNEL_A,Filter_KEY_MID); Filter_SetDalign(Filter_STAGEB_DALIGN,Filter_ENABLED); Filter_SetDalign(Filter_HOLDB_DALIGN,Filter_ENABLED); Filter_SetCoherency(Filter_STAGEB_COHER,Filter_KEY_MID); Filter_SetCoherency(Filter_HOLDB_COHER,Filter_KEY_MID); Filter_SetCoherency(Filter_CHANNEL_B,Filter_KEY_MID); CyGlobalIntEnable; Filter_Start(); /*Writes ADC values to ADC_samples array*/ while(1){ if (isr_BC_flag==1){ arm_cfft_q15(&arm_cfft_sR_q15_len256, Buffer_samples, 0, 1); arm_cmplx_mag_q15(Buffer_samples, magoutput, fftlength); CyDmaChEnable(DMA_2_Chan, 1); isr_BC_flag=0; isr_1_ClearPending(); } } }