static void initHardware(void) { #if defined (__USE_LPCOPEN) #if !defined(NO_BOARD_LIB) // Read clock settings and update SystemCoreClock variable SystemCoreClockUpdate(); // Set up and initialize all required blocks and // functions related to the board hardware Board_Init(); // Set the LED to the state of "Off" Board_LED_Set(0, false); #endif #endif adcInit(); dacInit(); }
// Sound routines void audioInit() { register Pio *pioptr ; dacInit() ; pioptr = PIOA ; #if defined(REVA) pioptr->PIO_CODR = 0x00010000L ; // Set bit A16 OFF pioptr->PIO_PER = 0x00010000L ; // Enable bit A16 (Stock buzzer) pioptr->PIO_OER = 0x00010000L ; // Set bit A16 as output #else pioptr->PIO_CODR = 0x02000000L ; // Set bit A25 OFF pioptr->PIO_PER = 0x02000000L ; // Enable bit A25 (Stock buzzer) pioptr->PIO_OER = 0x02000000L ; // Set bit A25 as output #endif }
int main(void) { halInit(); chSysInit(); initLed(); dacInit(); initAdc(); initRelay(); cpu_io_init(); while (TRUE) { cpu_io_process(); /* DacCfg dac; setLeds( 1 ); dac.dac1 = 0; dac.dac2 = 0; dacSet( &dac ); chThdSleepMilliseconds( 3000 ); setLeds( 2 ); dac.dac1 = 2047; dac.dac2 = 2047; dacSet( &dac ); chThdSleepMilliseconds( 3000 ); setLeds( 4 ); dac.dac1 = 3063; dac.dac2 = 3063; dacSet( &dac ); chThdSleepMilliseconds( 3000 ); setLeds( 4 ); dac.dac1 = 4095; dac.dac2 = 4095; dacSet( &dac ); chThdSleepMilliseconds( 3000 ); */ } return 0; }
/** * @brief HAL initialization. * @details This function invokes the low level initialization code then * initializes all the drivers enabled in the HAL. Finally the * board-specific initialization is performed by invoking * @p boardInit() (usually defined in @p board.c). * * @init */ void halInit(void) { /* Initializes the OS Abstraction Layer.*/ osalInit(); /* Platform low level initializations.*/ hal_lld_init(); #if (HAL_USE_PAL == TRUE) || defined(__DOXYGEN__) palInit(&pal_default_config); #endif #if (HAL_USE_ADC == TRUE) || defined(__DOXYGEN__) adcInit(); #endif #if (HAL_USE_CAN == TRUE) || defined(__DOXYGEN__) canInit(); #endif #if (HAL_USE_DAC == TRUE) || defined(__DOXYGEN__) dacInit(); #endif #if (HAL_USE_EXT == TRUE) || defined(__DOXYGEN__) extInit(); #endif #if (HAL_USE_GPT == TRUE) || defined(__DOXYGEN__) gptInit(); #endif #if (HAL_USE_I2C == TRUE) || defined(__DOXYGEN__) i2cInit(); #endif #if (HAL_USE_I2S == TRUE) || defined(__DOXYGEN__) i2sInit(); #endif #if (HAL_USE_ICU == TRUE) || defined(__DOXYGEN__) icuInit(); #endif #if (HAL_USE_MAC == TRUE) || defined(__DOXYGEN__) macInit(); #endif #if (HAL_USE_PWM == TRUE) || defined(__DOXYGEN__) pwmInit(); #endif #if (HAL_USE_SERIAL == TRUE) || defined(__DOXYGEN__) sdInit(); #endif #if (HAL_USE_SDC == TRUE) || defined(__DOXYGEN__) sdcInit(); #endif #if (HAL_USE_SPI == TRUE) || defined(__DOXYGEN__) spiInit(); #endif #if (HAL_USE_UART == TRUE) || defined(__DOXYGEN__) uartInit(); #endif #if (HAL_USE_USB == TRUE) || defined(__DOXYGEN__) usbInit(); #endif #if (HAL_USE_MMC_SPI == TRUE) || defined(__DOXYGEN__) mmcInit(); #endif #if (HAL_USE_SERIAL_USB == TRUE) || defined(__DOXYGEN__) sduInit(); #endif #if (HAL_USE_RTC == TRUE) || defined(__DOXYGEN__) rtcInit(); #endif #if (HAL_USE_WDG == TRUE) || defined(__DOXYGEN__) wdgInit(); #endif /* Community driver overlay initialization.*/ #if defined(HAL_USE_COMMUNITY) || defined(__DOXYGEN__) #if (HAL_USE_COMMUNITY == TRUE) || defined(__DOXYGEN__) halCommunityInit(); #endif #endif /* Board specific initialization.*/ boardInit(); /* * The ST driver is a special case, it is only initialized if the OSAL is * configured to require it. */ #if OSAL_ST_MODE != OSAL_ST_MODE_NONE stInit(); #endif }
// Sound routines void audioInit() { dacInit(); }
/****************** Thread main loop ***********************************/ msg_t analogue_thread(void *args) { (void)args; chRegSetThreadName("Analogue"); chBSemObjectInit(&bsAnalogueInst, true); chBSemObjectInit(&bsAnalogueFX, true); adcInit(); adcStart(&ADCD1, NULL); adcStart(&ADCD2, NULL); adcStartConversion(&ADCD1, &adc_con_group_1, (adcsample_t*)buffer1, INST_BUF_DEPTH); adcStartConversion(&ADCD2, &adc_con_group_2, (adcsample_t*)fx_samples, FX_BUF_DEPTH); dacInit(); dacStart(&DACD1, &dac_cfg); dacStartConversion(&DACD1, &dac_conv_grp, (dacsample_t*)buffer3, INST_BUF_DEPTH); // Enable DAC output buffer: DACD1.params->dac->CR |= DAC_CR_BOFF1; /* Start the GPT timers. They reload at after reaching 1 such that * TRGO frequency equals timer frequency. */ gptStart(&GPTD3, &gpt_inst_config); GPTD3.tim->CR2 |= STM32_TIM_CR2_MMS(2); gptStartContinuous(&GPTD3, 2); GPTD3.tim->DIER &= ~STM32_TIM_DIER_UIE; gptStart(&GPTD8, &gpt_fx_config); GPTD8.tim->CR2 |= STM32_TIM_CR2_MMS(2); gptStartContinuous(&GPTD8, 2); GPTD8.tim->DIER &= ~STM32_TIM_DIER_UIE; state = 1; // States: // 1 - ADC:buf1, DSP:buf2, DAC:buf3 // 2 - DSP:buf1, DAC:buf2, ADC:buf3 // 3 - DAC:buf1, ADC:buf2, DSP:buf3 /* Wait until the ADC callback boops the semaphore. */ volatile uint16_t *dsp_buf; while(true) { chSysLock(); chBSemWaitS(&bsAnalogueInst); chSysUnlock(); state += 1; switch(state) { case 1: dmaSetOtherMemory(ADCD1.dmastp, buffer1); dsp_buf = buffer2; dmaSetOtherMemory(DACD1.params->dma, buffer3); break; case 2: dmaSetOtherMemory(ADCD1.dmastp, buffer3); dsp_buf = buffer1; dmaSetOtherMemory(DACD1.params->dma, buffer2); break; case 3: dmaSetOtherMemory(ADCD1.dmastp, buffer2); dsp_buf = buffer3; dmaSetOtherMemory(DACD1.params->dma, buffer1); break; default: state = 1; dmaSetOtherMemory(ADCD1.dmastp, buffer1); dsp_buf = buffer2; dmaSetOtherMemory(DACD1.params->dma, buffer3); } dsp_stuff(dsp_buf); } }