/***************************************************************************//** * @brief * Initialize board and LCD controller * * @details * This function is called during initialization and when exited from AEM mode ******************************************************************************/ static void _InitController(void) { /* Initialize EBI banks (Board Controller, external PSRAM, ..) */ DVK_init(DVK_Init_EBI); /* If first word of user data page is non-zero, enable eA Profiler trace */ TRACE_ProfilerSetup(); /* Configure for 32MHz HFXO operation of core clock */ CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFXO); /* on Giant & Leopard we have to reduce core clock when * talking with slow TFT controller */ CMU_ClockDivSet(cmuClock_CORE, cmuClkDiv_2); CMU_ClockEnable( cmuClock_GPIO, true); CMU_ClockEnable( cmuClock_ADC0, true); LCD_InitializeLCD(); }
/**************************************************************************//** * @brief Main function *****************************************************************************/ int main(void) { int i = 0; uint16_t temp_humid_sensor; float rel_humidity, dew_point; char buffer_humid[10]; // char buffer_voltage[10]; // char light_level[10]; /* Chip errata */ CHIP_Init(); /* If first word of user data page is non-zero, enable eA Profiler trace */ TRACE_ProfilerSetup(); /* Setup SysTick Timer for 1 msec interrupts */ if (SysTick_Config(CMU_ClockFreqGet(cmuClock_CORE) / 1000)) while (1) ; /* Disable usart0 clock, it is enabled by default in gecko series mcu's. */ CMU_ClockEnable(cmuClock_USART0, false); /* Infinite blink loop with main state machine */ state = RESET; while (1) { // state machine switch(state){ case RESET: // RESET state check for vital HW functions if(1){ // todo all checks i = 0; state = INIT; } else state = RESET; break; case INIT: // INIT state initialize all necessary peripherials if(1){ i = i + 1; /* Enable clocks. */ CMU_ClockEnable(cmuClock_GPIO, true); CMU_ClockEnable(cmuClock_I2C0, true); /* Configure PB9, PB10 pin interrupt on falling edge do not enable yet. */ GPIO_PinModeSet(gpioPortB, 9, gpioModeInput, 0); GPIO_PinModeSet(gpioPortB, 10, gpioModeInput, 0); GPIO_IntConfig(gpioPortB, 9, false, true, true); GPIO_IntConfig(gpioPortB, 10, false, true, true); HumiditySensorInit(); LED_Init(); /* Initialize LED driver */ LED_Set(0); /* Enable LCD without voltage boost */ SegmentLCD_Init(false); /* Init LCD driver */ SegmentLCD_Write("ST: INIT"); Delay(500); SegmentLCD_Number(i); Delay(500); state = IDLE; } else state = INIT; break; case IDLE: if(1){ i = i + 1; SegmentLCD_Write("ST: IDLE"); Delay(500); SegmentLCD_Number(i); Delay(500); // while idle check humidity and temp paramters rel_humidity = ReadHumiditySensor(); dew_point = getDewPoint(); /* Get temperature from humidity sensor, notice that both pressure sensor and */ /* humidity sensor has built in temperature sensors, since dewpoint and pressure */ /* is dependent on the temperature close to the sensor it gives the most accurate */ /* results to use the built in temperature sensor in each device. */ temp_humid_sensor = getTemperatureHumidSensor(); state = RX_STATE; } else state = IDLE; break; case RX_STATE : if(1){ i = i + 1; SegmentLCD_Write("ST: Rx"); Delay(500); SegmentLCD_Number(i); Delay(500); SegmentLCD_Symbol(LCD_SYMBOL_ANT, 1); state = TX_STATE; } else state = RX_STATE; break; case TX_STATE: if(1){ i = i + 1; SegmentLCD_Write("ST: TX"); Delay(500); SegmentLCD_Number(i); Delay(500); SegmentLCD_Symbol(LCD_SYMBOL_ANT, 1); state = ERROR; } else state = TX_STATE; break; case ERROR: if(1){ i = i + 1; SegmentLCD_Write("ST: ERR"); Delay(500); SegmentLCD_Number(i); Delay(500); state = IDLE; } else state = ERROR; break; } LED_Toggle(0); LED_Toggle(1); Delay(1000); } }
int main(void) { /* Local variables */ int32_t measurement,_i,_j,_error; // Note that the chip resets to using the HFRCO at 14MHz /* Chip errata */ CHIP_Init(); /* If first word of user data page is non-zero, enable eA Profiler trace */ TRACE_ProfilerSetup(); /* Initialise core functionality */ CMU_init(); GPIO_init(); /* Set up the homodynde detection system */ channel = 0; for (_i=0;_i<2;_i++) { channels[_i].local_osc.local_osc = osc_lut; channels[_i].local_osc.phase_limit = 4; channels[_i].local_osc.phase_offset = 0; channels[_i].filter.order = FILTER_ORDER; for (_j=0;_j<FILTER_ORDER;_j++) { channels[_i].filter.alphas[_j] = rpom.filter_alphas[_j]; channels[_i].filter.types[_j] = rpom.filter_types[_j]; } ppgd_init(&delineator[_i],rpom.pd_thresh[0],rpom.pd_thresh[1]); } // Make channel 0 orthogonal to channel 1 (pi/2 offset) channels[1].local_osc.phase_offset = 1; hd_reset(&channels[0],0); hd_reset(&channels[1],0); /* Manually initialise the FIFOs */ tx_fifo.depth = 0; tx_fifo.pRead = 0; tx_fifo.pWrite = 0; rx_fifo.depth = 0; rx_fifo.pRead = 0; rx_fifo.pWrite = 0; /* Create a message */ message_t sample_message, *rx_message; sample_message.header.id = 0x00; sample_message.header.type = 0x00; sample_message.header.length = 0; sample_message.header.check = 0; /* Set up functional peripheral interfaces */ USART1_uart_init(); iDAC_init(); xDAC_init(); iDAC_write(0); iADC_init(); // DAC_A uint8_t dac_command = (3 << 3); xDAC_write(dac_command, XDAC_RST, true); // DAC_B dac_command = (3 << 3) | (1 << 0); xDAC_write(dac_command, XDAC_RST, true); /* Set up low frequency timer for sampling */ LFTIMER_init(); /* Set up high accuracy timer for precision timing procedures */ HFTIMER_init(); /* Infinite main loop */ while (1) { /* Process any characters received on the UART */ if (message_parser(&rx_fifo,&rx_message)) { uint8_t order; switch(rx_message->header.type) { case 0x00: // System state if (rx_message->payload[0]==0) enter_reset_state(); else rpom.mode = rx_message->payload[0]; break; case 0x01: // LED brightnesses rpom.led_current[0] = (rx_message->payload[0]<<8) + rx_message->payload[1]; rpom.led_current[1] = (rx_message->payload[2]<<8) + rx_message->payload[3]; break; case 0x02: // Filter adaptor coefficients /* Calculate the filter order */ order = (rx_message->header.length - sizeof(rx_message->header))>>2; for (_i=0;_i<order;_i++) { /* Extract the adaptor coefficients */ rpom.filter_alphas[_i] = (rx_message->payload[(_i<<1)]<<8) + rx_message->payload[(_i<<1)+1]; /* Reload the internal adaptor coefficients */ for (_j=0;_j<2;_j++) { channels[_i].filter.alphas[_j] = rpom.filter_alphas[_j]; } } break; case 0x03: // Filter adaptor types /* Calculate the filter order */ order = (rx_message->header.length - sizeof(rx_message->header))>>2; for (_i=0;_i<order;_i++) { /* Extract the adaptor types */ rpom.filter_types[_i] = rx_message->payload[_i]; /* Reload the internal adaptor types */ for (_j=0;_j<2;_j++) { channels[_i].filter.types[_j] = rpom.filter_types[_j]; } } break; case 0x04: // Quadrature delineation thresholds /* Calculate the filter order */ for (_i=0;_i<4;_i++) { /* Extract the adaptor types - big endian */ _j = _i<<2; /* Extract the thresholds */ rpom.pd_thresh[_i] = rx_message->payload[_j]<<24 + rx_message->payload[_j+1]<<16 + rx_message->payload[_j+2]<<8 + rx_message->payload[_j+3]; /* Copy the thresholds into the delineator */ delineator[_i>>1].delineator.delta[_i&0x01] = rpom.pd_thresh[_i]; } break; default: break; } } /* Process any waiting ADC values */ for (_i=0;_i<2;_i++) { if (channels[_i].adc_waiting) { /* DC current rejection ? */ if (rpom.mode&(1<<1)) { /* Perform DC current rejection */ channels[_i].adc_hold -= MID_RANGE; /* Implement any required gain */ dcr_integration[_i] += (channels[_i].adc_hold+(1<<2))>>3; /* Bound the integration to limits of the external DAC */ if (dcr_integration[_i]>XDAC_LIMIT) { dcr_integration[_i] = XDAC_LIMIT; } else if (dcr_integration[_i]<0) { dcr_integration[_i] = 0; } } /* Homodyne? */ if (rpom.mode&(1<<2)) { /* Perform homodyne detection on raw ADC value */ // Includes intrinsic gain of 64 measurement = hd_adc_process(&channels[_i])<<6; } else { /* Send the raw DAC value if homodyne not requested */ channels[_i].adc_waiting = false; measurement = channels[_i].adc_hold<<16; } /* Delineate? */ if (rpom.mode&(1<<3)) { ppgd_write(&delineator[_i], measurement); } else { /* Transmit raw data if not delineating */ sample_message.payload[(_i<<1)] = (uint8_t)(measurement>>24); sample_message.payload[(_i<<1)+1] = (uint8_t)((measurement>>16)&0x00FF); /* If all channels complete then transmit the packet */ if (_i==1) { sample_message.header.length = sizeof(sample_message.header) + 4; tx_message(&tx_fifo, &sample_message); } } } }