static long s3c64xx_pwm_ioctl(struct file *filep, unsigned int cmd, unsigned long arg) { /* Begin Commented Out printk (PWM_DEVICE_NAME"\tML: s3c64xx_pwm_ioctl: cmd (%d)\n", cmd); printk (KERN_ERR"\tML: s3c64xx_pwm_ioctl: cmd (%d)\n", cmd); End Commented Out */ /* * Basic checking of the command */ if (_IOC_TYPE(cmd) != PWM_MAGIC) return -ENOTTY ; if (_IOC_NR(cmd) > PWM_MAXCMD) return -ENOTTY ; switch (cmd) { case PWM_IOCTL_SET_FREQ: if (arg == 0) return -EINVAL; PWM_Set_Freq(arg); break; case PWM_IOCTL_STOP: case PWM_RESET: default: PWM_Stop(); break; } return 0; }
const void * PPMOUT_Cmds(enum ProtoCmds cmd) { switch(cmd) { case PROTOCMD_INIT: initialize(); return 0; case PROTOCMD_DEINIT: PWM_Stop(); return 0; case PROTOCMD_CHECK_AUTOBIND: return (void *)1L; case PROTOCMD_BIND: initialize(); return 0; case PROTOCMD_NUMCHAN: if (Model.proto_opts[CENTER_PW] != 0) { uint32_t chan = (Model.proto_opts[PERIOD_PW] - Model.proto_opts[NOTCH_PW]) / (Model.proto_opts[CENTER_PW] + Model.proto_opts[DELTA_PW] + Model.proto_opts[NOTCH_PW]); if (chan > NUM_OUT_CHANNELS) return (void *)(long)NUM_OUT_CHANNELS; return (void *)(long)chan; } return (void *)10L; case PROTOCMD_DEFAULT_NUMCHAN: return (void *)6L; case PROTOCMD_GETOPTIONS: if (Model.proto_opts[CENTER_PW] == 0) { Model.proto_opts[CENTER_PW] = 1100; Model.proto_opts[DELTA_PW] = 400; Model.proto_opts[NOTCH_PW] = 400; Model.proto_opts[PERIOD_PW] = 22500; } return ppm_opts; case PROTOCMD_TELEMETRYSTATE: return (void *)(long)PROTO_TELEM_UNSUPPORTED; default: break; } return 0; }
static int s3c64xx_pwm_open(struct inode *inode, struct file *file) { if (!down_trylock(&lock)) { // make sure that once we have the device, we're not doing anything yet. PWM_Stop(); return 0; } else return -EBUSY; }
int main() { CyGlobalIntEnable; /* Enable global interrupts. */ /* Place your initialization/startup code here (e.g. MyInst_Start()) */ for(;;) { PWM_Start(); CyDelay(500); PWM_Stop(); CyDelay(500); } }
/******************************************************************************* * Function Name: PWM_Sleep ******************************************************************************** * * Summary: * Stops the component operation and saves the user configuration. * * Parameters: * None * * Return: * None * *******************************************************************************/ void PWM_Sleep(void) { if(0u != (PWM_BLOCK_CONTROL_REG & PWM_MASK)) { PWM_backup.enableState = 1u; } else { PWM_backup.enableState = 0u; } PWM_Stop(); PWM_SaveConfig(); }
/** * @brief The main function for the charger. * @details This function is entered automatically at reset. There is no exit * from this function, it is declared as _int_ to avoid compiler warning. */ int main() { uint32_t i; FastVoltage = RawVoltage = RawCurrent = 0; PWM_Stop(); // Disable PWM output (set it low) ADC_Init(); // Initialize the A/D converters if (BUTTON1_PRESSED) // If button pressed at reset, calibrate only State = CALIBRATE; else // else wait for the START button State = WAIT4BUTTON; // // Wait at least 100 ms for the LCD to wake up // Assume that the loop takes 4 clocks, wait 125 ms // for (i = 0; i < (SystemCoreClock / 32); i++) { } LCD_Init(); // // Set up the System Tick // FLAG1_PORT->DIR |= FLAG1_Msk; FLAG1_PORT->DATA &= ~FLAG1_Msk; Ticks = 0; SysTick_Config((SystemCoreClock / TICKS_PER_SEC) - 1); // // Set up the I2C interface for the temperature sensor // I2CInit((uint32_t) I2CMASTER); for (;;) { if (0 == Ticks) { for (i = 0; i < BUFSIZE; i++) { I2CSlaveBuffer[i] = 0x00; } I2CWriteLength = 0; I2CReadLength = 2; I2CMasterBuffer[0] = LM75_ADDR | RD_BIT; I2CEngine(); Temperature = I2CSlaveBuffer[0]; // Wait until Ticks becomes non-zero to read the sensor again while (0 == Ticks) { } } } }
static long s3c64xx_pwm_ioctl(struct file *filep, unsigned int cmd, unsigned long arg) { switch (cmd) { case PWM_IOCTL_SET_FREQ: if (arg == 0) return -EINVAL; PWM_Set_Freq(arg); break; case PWM_IOCTL_STOP: default: PWM_Stop(); break; } return 0; }
static long s3c64xx_pwm_ioctl(struct file *filep, unsigned int cmd, unsigned long arg) { printk("%s\n", __FUNCTION__); #if 0 switch (cmd) { case PWM_IOCTL_SET_FREQ: if (arg == 0) return -EINVAL; PWM_Set_Freq(arg); break; case PWM_IOCTL_STOP: default: PWM_Stop(); break; } #endif return 0; }
/******************************************************************************* * Function Name: PWM_Sleep ******************************************************************************** * * Summary: * Disables block's operation and saves the user configuration. Should be called * just prior to entering sleep. * * Parameters: * void * * Return: * void * * Global variables: * PWM_backup.PWMEnableState: Is modified depending on the enable * state of the block before entering sleep mode. * *******************************************************************************/ void PWM_Sleep(void) { #if(PWM_UseControl) if(PWM_CTRL_ENABLE == (PWM_CONTROL & PWM_CTRL_ENABLE)) { /*Component is enabled */ PWM_backup.PWMEnableState = 1u; } else { /* Component is disabled */ PWM_backup.PWMEnableState = 0u; } #endif /* (PWM_UseControl) */ /* Stop component */ PWM_Stop(); /* Save registers configuration */ PWM_SaveConfig(); }
/** * function that will change the frequency of the SCT. * * this function will stop the SCT output, first, set the frequency, and startup the sct again * @param p_pwm the low level driver struct for the PWM that needs to be changed * @param frequency the wanted frequency in Hz (0 - MAX_FREQUENCY) * @return status_ok if succeeded (otherwise check status.h for details). */ status_t PWM_SetFrequency(pwm_t* p_pwm, uint32_t frequency) { status_t status = status_ok; uint8_t i; p_pwm->frequency = frequency; if(frequency <= MAX_FREQUENCY) { /* first stop the sct */ status = PWM_Stop(); /* then set the rate */ if(status == status_ok) { Chip_SCTPWM_SetRate(PWM_SCT, frequency); } /* set dutycycles */ /* then set the dutycycles */ for(i = 0; i < PWM_AMOUNTOFCHANNELS; i++) { if(status == status_ok) { if(p_pwm->usechannel[i]) { status = PWM_setdutycycle(p_pwm, i, p_pwm->dutycycle[i]); } } } /* If ok, start the pwm */ if(status == status_ok) { status = PWM_Start(); } } else { status = pwm_frequency; } return status; }
const void * PPMOUT_Cmds(enum ProtoCmds cmd) { switch(cmd) { case PROTOCMD_INIT: initialize(); return 0; case PROTOCMD_DEINIT: PWM_Stop(); return 0; case PROTOCMD_CHECK_AUTOBIND: return (void *)1L; case PROTOCMD_BIND: initialize(); return 0; case PROTOCMD_NUMCHAN: return (void *)((unsigned long)PPMOUT_MAX_CHANNELS); case PROTOCMD_DEFAULT_NUMCHAN: return (void *)6L; case PROTOCMD_GETOPTIONS: if (Model.proto_opts[CENTER_PW] == 0) { Model.proto_opts[CENTER_PW] = 1100; Model.proto_opts[DELTA_PW] = 400; Model.proto_opts[NOTCH_PW] = 400; Model.proto_opts[PERIOD_PW] = 22500; } return ppm_opts; case PROTOCMD_TELEMETRYSTATE: return (void *)(long)-1; default: break; } return 0; }
/****************************************************************************** ** Main Function main() ******************************************************************************/ int main (void) { unsigned long cycle = PWM_CYCLE, offset = 0; INIT_LEDS(); // initialize the GPIO's connected to LEDs turn_off_all_leds(); // Turnoff all LEDs init_VIC(); // Initialize Vectored interrupts if ( PWM_Init( 0 ) != TRUE ) { while( 1 ); /* fatal error */ } PWM_Set( cycle, offset ); PWM_Start(); while ( 1 ) { if ( match_counter != 0 ) { match_counter = 0; if( offset <= PWM_CYCLE ) { offset += PWM_OFFSET; } else { offset = 0; } PWM_Set( cycle, offset ); } } PWM_Stop() ; return 0; }
/*---------------------------------------------------------------------------------------------------------*/ int32_t main(void) { /* Unlock protected registers */ SYS_UnlockReg(); /* Init System, IP clock and multi-function I/O */ SYS_Init(); /* Lock protected registers */ SYS_LockReg(); /* Init UART0 for printf */ UART0_Init(); printf("+------------------------------------------------------------------------+\n"); printf("| PWM Driver Sample Code |\n"); printf("| |\n"); printf("+------------------------------------------------------------------------+\n"); printf(" This sample code will use PWMB channel 2 to capture\n the signal from PWMB channel 1.\n"); printf(" I/O configuration:\n"); printf(" PWM5(P2.5 PWMB channel 1) <--> PWM6(P2.6 PWMB channel 2)\n\n"); printf("Use PWMB Channel 2(P2.6) to capture the PWMB Channel 1(P2.5) Waveform\n"); while(1) { printf("Press any key to start PWM Capture Test\n"); getchar(); /*--------------------------------------------------------------------------------------*/ /* Set the PWMB Channel 1 as PWM output function. */ /*--------------------------------------------------------------------------------------*/ /* Assume PWM output frequency is 250Hz and duty ratio is 30%, user can calculate PWM settings by follows. duty ratio = (CMR+1)/(CNR+1) cycle time = CNR+1 High level = CMR+1 PWM clock source frequency = __HXT = 12000000 (CNR+1) = PWM clock source frequency/prescaler/clock source divider/PWM output frequency = 12000000/2/1/250 = 24000 (Note: CNR is 16 bits, so if calculated value is larger than 65536, user should increase prescale value.) CNR = 23999 duty ratio = 30% ==> (CMR+1)/(CNR+1) = 30% CMR = 7199 Prescale value is 1 : prescaler= 2 Clock divider is PWM_CSR_DIV1 : clock divider =1 */ /* set PWMB channel 1 output configuration */ PWM_ConfigOutputChannel(PWMB, PWM_CH1, 250, 30); /* Enable PWM Output path for PWMB channel 1 */ PWM_EnableOutput(PWMB, 0x2); /* Enable Timer for PWMB channel 1 */ PWM_Start(PWMB, 0x2); /*--------------------------------------------------------------------------------------*/ /* Set the PWMB channel 2 for capture function */ /*--------------------------------------------------------------------------------------*/ /* If input minimum frequency is 250Hz, user can calculate capture settings by follows. Capture clock source frequency = __HXT = 12000000 in the sample code. (CNR+1) = Capture clock source frequency/prescaler/clock source divider/minimum input frequency = 12000000/2/1/250 = 24000 (Note: CNR is 16 bits, so if calculated value is larger than 65536, user should increase prescale value.) CNR = 0xFFFF (Note: In capture mode, user should set CNR to 0xFFFF to increase capture frequency range.) */ /* set PWMB channel 2 capture configuration */ PWM_ConfigCaptureChannel(PWMB, PWM_CH2, 166, 0); /* Enable capture falling edge interrupt for PWMB channel 2 */ PWM_EnableCaptureInt(PWMB, PWM_CH2, PWM_CAPTURE_INT_FALLING_LATCH); /* Enable PWMB NVIC interrupt */ NVIC_EnableIRQ((IRQn_Type)(PWMB_IRQn)); /* Enable Timer for PWMB channel 2 */ PWM_Start(PWMB, 0x4); /* Enable Capture Function for PWMB channel 2 */ PWM_EnableCapture(PWMB, 0x4); /* Wait until PWMB channel 2 Timer start to count */ while(PWMB->PDR2 == 0); /* Capture the Input Waveform Data */ CalPeriodTime(PWMB, PWM_CH2); /*------------------------------------------------------------------------------------------------------*/ /* Stop PWMB channel 1 (Recommended procedure method 1) */ /* Set PWM Timer loaded value(CNR) as 0. When PWM internal counter(PDR) reaches to 0, disable PWM Timer */ /*------------------------------------------------------------------------------------------------------*/ /* Set PWMB channel 1 loaded value as 0 */ PWM_Stop(PWMB, 0x2); /* Wait until PWMB channel 1 Timer Stop */ while(PWMB->PDR1 != 0); /* Disable Timer for PWMB channel 1 */ PWM_ForceStop(PWMB, 0x2); /* Disable PWM Output path for PWMB channel 1 */ PWM_DisableOutput(PWMB, 0x2); /*------------------------------------------------------------------------------------------------------*/ /* Stop PWMB channel 2 (Recommended procedure method 1) */ /* Set PWM Timer loaded value(CNR) as 0. When PWM internal counter(PDR) reaches to 0, disable PWM Timer */ /*------------------------------------------------------------------------------------------------------*/ /* Disable PWMB NVIC */ NVIC_DisableIRQ((IRQn_Type)(PWMB_IRQn)); /* Set loaded value as 0 for PWMB channel 2 */ PWM_Stop(PWMB, 0x4); /* Wait until PWMB channel 2 current counter reach to 0 */ while(PWMB->PDR2 != 0); /* Disable Timer for PWMB channel 2 */ PWM_ForceStop(PWMB, 0x4); /* Disable Capture Function and Capture Input path for PWMB channel 2*/ PWM_DisableCapture(PWMB, 0x4); /* Clear Capture Interrupt flag for PWMB channel 2*/ PWM_ClearCaptureIntFlag(PWMB, PWM_CH2, PWM_CAPTURE_INT_FALLING_LATCH); } }
/******************************************************************************* * Function Name: StackEventHandler ******************************************************************************** * * Summary: * This is an event callback function to receive events from the BLE Component. * * Parameters: * uint8 event: Event from the CYBLE component * void* eventParams: A structure instance for corresponding event type. The * list of event structure is described in the component * datasheet. * * Return: * None * *******************************************************************************/ void StackEventHandler(uint32 event, void *eventParam) { char authFailReasonCode[3]; CYBLE_GAP_AUTH_FAILED_REASON_T *authFailReason; switch(event) { /* Mandatory events to be handled by Find Me Target design */ case CYBLE_EVT_STACK_ON: case CYBLE_EVT_GAP_DEVICE_DISCONNECTED: /* Start BLE advertisement for 30 seconds and update link * status on LEDs */ CyBle_GappStartAdvertisement(CYBLE_ADVERTISING_FAST); Advertising_LED_Write(LED_ON); PWM_WriteCompare(LED_NO_ALERT); break; case CYBLE_EVT_GAP_DEVICE_CONNECTED: UART_UartPutString("GAP Device Connected\r\n"); /* BLE link is established */ Advertising_LED_Write(LED_OFF); break; case CYBLE_EVT_TIMEOUT: if(*(uint8 *) eventParam == CYBLE_GAP_ADV_MODE_TO) { /* Advertisement event timed out, go to low power * mode (Hibernate mode) and wait for an external * user event to wake up the device again */ Advertising_LED_Write(LED_OFF); Hibernate_LED_Write(LED_ON); PWM_Stop(); Wakeup_SW_ClearInterrupt(); Wakeup_Interrupt_ClearPending(); Wakeup_Interrupt_Start(); CySysPmHibernate(); } break; /********************************************************** * GAP Events ***********************************************************/ case CYBLE_EVT_GAP_AUTH_REQ: UART_UartPutString("Authorization Requested\r\n"); break; case CYBLE_EVT_GAP_AUTH_COMPLETE: UART_UartPutString("Pairing is Successful!\r\n"); break; case CYBLE_EVT_GAP_AUTH_FAILED: authFailReason = ((CYBLE_GAP_AUTH_FAILED_REASON_T *)eventParam); UART_UartPutString("Authentication Failed with Reason Code: "); snprintf(authFailReasonCode, sizeof(authFailReasonCode), "%lu", (uint32)(*authFailReason)); UART_UartPutString(authFailReasonCode); UART_UartPutChar("\r\n"); break; /********************************************************** * GATT Events ***********************************************************/ case CYBLE_EVT_GATT_CONNECT_IND: UART_UartPutString("GATT Connection Indication\r\n"); /* Set OOB data after the connection indication but before the authorization * request is received. */ if(CyBle_GapSetOobData(cyBle_connHandle.bdHandle, CYBLE_GAP_OOB_ENABLE, securityKey, NULL, NULL) != CYBLE_ERROR_OK) { UART_UartPutString("Error in Setting OOB Data\r\n"); } else { UART_UartPutString("OOB Data is Set\r\n"); } break; default: break; } }
int main() { CyDelay(200); uint16 Counts=0; // ADC value (0 to 4095) right shifted by 6 which gives // us 0 to 63 to be used to simulate actual temperature uint16 TempSet = 2400; // Temperature set default value (left justified) 24 deg uint16 DisplayTemp = 0; // The combined sum of desired temp and actual temp uint16 bleTemp = 0; // Temperature sent to BLE module uint16 bleTempSet = 0; // Temperature set value sent to BLE module uint8 button0 = 0; // Declare CapSense button name button0 uint8 button1 = 0; // Declare CapSense button name button1 uint8 firstpress0 = 0; // Detects a transition of button1 from 0 to 1 uint8 firstpress1 = 0; // Detects a transition of button1 from 0 to 1 int buttonPrevious = 1; CyGlobalIntEnable; ADC_Start(); // Starts the ADC component ADC_StartConvert(); // The ADC conversion process begins LCD_Start(); // Start the LCD component CapSense_Start(); CapSense_ScanAllWidgets(); LCD_WritePixel(LCD_COLON, TRUE); ResetTimer_Start(); sendBootload_StartEx(StartBootload_ISR); BLEIOT_Start(); /* Initialize temperuature values out of range so that main loop update is triggered */ BLEIOT_updateTemperature(10000); BLEIOT_updatePot(100); for(;;) { /* Turn BLE on/off with button press */ if(buttonPrevious && (Button_Read() == 0)) { if(BLEIOT_remote.bleState == BLEIOT_BLEOFF) { BLEIOT_updateBleState(BLEIOT_BLEON); } else { BLEIOT_updateBleState(BLEIOT_BLEOFF); } } buttonPrevious = Button_Read(); /* Local Thermostat Operation */ /* ADC */ // Read the ADC, shift right by 6 (i.e. divide by 64) // and store result in Counts Counts = ADC_GetResult16(POT_CHAN); Counts = Counts >> 6; /* CapSense */ if (!CapSense_IsBusy()) { // Check Button states and store CapSense_ProcessAllWidgets(); if(CapSense_IsWidgetActive(CapSense_BUTTON0_WDGT_ID)) { button0 = 1; } else { button0 = 0; } if(CapSense_IsWidgetActive(CapSense_BUTTON1_WDGT_ID)) { button1 = 1; } else { button1 = 0; } // Light LEDs Based on Capsense buttons LED_CS0_Write(~button0); LED_CS1_Write(~button1); // Check for button touchdown transitions if (button0 == 1) { if(firstpress0 == 0) // Touchdown event { firstpress0 = 1; // Remember button0 was pressed TempSet = TempSet + 100; // Increment Temp by 1 deg } } else { firstpress0 = 0; // Button released } if (button1 == 1) { if(firstpress1 == 0) // Touchdown event { firstpress1 = 1; // Remember button0 was pressed TempSet = TempSet - 100; // Decrement Temp by 1 deg } } else { firstpress1 = 0; // Button released } CapSense_ScanAllWidgets(); // Start Next Scan } /* Warning LEDs and Buzzer */ if((Counts * 100) < TempSet) // Temperature Cold { LED_Blue_Write(LED_ON); // Blue On LED_Green_Write(LED_OFF); // Green Off LED_Red_Write(LED_OFF); // Red Off PWM_Stop(); // Buzzer Off } else if ((Counts * 100) <= (TempSet + 500)) // Temperature OK { LED_Blue_Write(LED_OFF); // Blue Off LED_Green_Write(LED_ON); // Green On LED_Red_Write(LED_OFF); // Red Off PWM_Stop();// Buzzer Off } else // Tempearture too high { LED_Blue_Write(LED_OFF); // Blue Off LED_Green_Write(LED_OFF); // Green Off LED_Red_Write(LED_ON); // Red On PWM_Start(); // Buzzer On } /* LCD Display */ DisplayTemp = TempSet + Counts; LCD_Write7SegNumber_0(DisplayTemp, POS, MODE); /* BLE operation - do only if BLE is not off */ if(BLEIOT_remote.bleState != BLEIOT_BLEOFF) { /* Send new temperature data to the BLE module */ if(bleTemp != Counts) { bleTemp = Counts; BLEIOT_updatePot(bleTemp); } if(bleTempSet != TempSet) { bleTempSet = TempSet; /* Scale set temperature down to whole number of degrees */ BLEIOT_updateTemperature(TempSet / 100); } /* Get new data from the BLE module */ /* LED0 is used for temperature changes */ if(BLEIOT_getDirtyFlags() & BLEIOT_FLAG_LED0) { /* Update local variable copy and clear dirty flag */ BLEIOT_updateLed0(BLEIOT_remote.led0); if(BLEIOT_local.led0 == UP) { TempSet = TempSet + 100; // Increment Temp by 1 deg } else if (BLEIOT_local.led0 == DOWN) { TempSet = TempSet - 100; // Decrement Temp by 1 deg } } } /* End of !BLEOFF state operations */ } /* End of superloop */ } /* End of main */
void Motor_Stop(void) { PWM_DisableOutput(PWM, 0x33); PWM_Stop(PWM, 0x33); printf("Motor_Stop \n"); }
void ApplicationEntryPoint() { #if defined(TEST_DAC) UINT32 FramesNum = g_LPC24XX_DAC_Driver.GetBufferFrameCapacity(); if (DAC_FRAME_BUFFERS_NUM!=FramesNum) { debug_printf( "Error, BufferFrameCapacity != DAC_FRAME_BUFFERS_NUM: %d != %d.\r\n", FramesNum, DAC_FRAME_BUFFERS_NUM ); } UINT32 nextInFrameOffset=0; UINT16 frameLength = MAX_DECODED_FRAME_SIZE/2; short* frameSignedStart = NULL; LPC24XX_VIC& VIC = LPC24XX::VIC(); /*debug_printf("VIC INTRSEL = 0x%08x\r\n", VIC.INTRSEL); VIC.INTRSEL |= 1 << LPC24XX_TIMER::getIntNo(LPC24XX_DAC::Timer); debug_printf("new VIC INTRSEL = 0x%08x\r\n", VIC.INTRSEL);*/ VIC.VECTPRIORITY[LPC24XX_TIMER::getIntNo(LPC24XX_DAC::Timer)] = 0; for(int i= 0; i< 32; i++) { debug_printf("PRIO INTR%02d = %d \r\n", i,VIC.VECTPRIORITY[i]); } debug_printf( "Init DAC, 8kHz output.\r\n" ); g_LPC24XX_DAC_Driver.Initialize(OUT_FREQ); debug_printf( "BUFFER PRE-FILL TEST.\r\n" ); debug_printf( "Adding frames to the DAC driver buffer: " ); debug_printf("total frames to be added = %d\r\n", TEST_SAMPLES_NUM/MAX_DECODED_FRAME_SIZE-CUTOUT); debug_printf("DAC frame buffers available = %d\r\n", DAC_FRAME_BUFFERS_NUM); if(DAC_FRAME_BUFFERS_NUM<(TEST_SAMPLES_NUM/MAX_DECODED_FRAME_SIZE-CUTOUT)) debug_printf("ONLY THE FIRST %d FRAMES OF THE SAMPLE WILL BE PLAYED.\r\n", DAC_FRAME_BUFFERS_NUM); while(nextInFrameOffset+(MAX_DECODED_FRAME_SIZE*CUTOUT) < TEST_SAMPLES_NUM) { //if(i%(1024*256)) continue; frameSignedStart = (short*)(bin_data+nextInFrameOffset); if(g_LPC24XX_DAC_Driver.AddFrame(frameSignedStart, frameLength)) { debug_printf( " done.\r\n" ); nextInFrameOffset+=MAX_DECODED_FRAME_SIZE; } else { debug_printf( "Buffer full, starting playout.\r\n"); break; } } resetDACISRTiming(); debug_printf( "DAC.On() in 2 seconds\r\n"); Events_WaitForEvents( 0, 2000 ); if(!hijackISRs()) return; if(g_LPC24XX_DAC_Driver.On()) { //debug_printf( "Done. 2sec wait.\r\n" ); don't output to avoid adding serial activity during the test } else { debug_printf( "FAILED.\r\n" ); } while(g_LPC24XX_DAC_Driver.GetBufferLevel()>0) { //debug_printf("Samples left: %d\r\n", g_LPC24XX_DAC_Driver.GetBufferLevel()); //debug_printf("Frames left: %d\r\n", g_LPC24XX_DAC_Driver.GetFramesLeft()); } //stop logging interrupts before starting to output again int finalIrqCount = irq_count; irq_count = 8192; Events_WaitForEvents( 0, 5000 ); if(!restoreISRs()) return; debug_printf("%d frames left.\r\n", g_LPC24XX_DAC_Driver.GetFramesLeft()); debug_printf("Final IRQ count = %u\r\n", finalIrqCount); debug_printf( "BUFFER PRE-FILL TEST OVER.\r\n"); displayRunTestResults(); debug_printf("CSV DATA OUTPUT FOLLOWS\r\n"); //csvRunTestResults(); debug_printf("\r\nPARALLEL BUFFER FILL TEST\r\n" ); Events_WaitForEvents( 0, 3000 ); debug_printf( "DAC.Off()\r\n"); if(g_LPC24XX_DAC_Driver.Off()) { debug_printf( "Done.\r\n" ); } else { debug_printf( "FAILED.\r\n" ); } debug_printf( "Uninit DAC\r\n"); g_LPC24XX_DAC_Driver.Uninitialize(); debug_printf( "Done.\r\n"); debug_printf( "Init DAC, 8kHz output.\r\n" ); g_LPC24XX_DAC_Driver.Initialize(OUT_FREQ); resetDACISRTiming(); debug_printf( "DAC.On() in 2 seconds\r\n"); Events_WaitForEvents( 0, 2000 ); if(g_LPC24XX_DAC_Driver.On()) { //debug_printf( "Done.\r\n" ); } else { debug_printf( "FAILED.\r\n" ); } debug_printf( "Adding frames to the DAC driver buffer: " ); nextInFrameOffset=0; debug_printf("total frames to be added = %d\r\n", TEST_SAMPLES_NUM/MAX_DECODED_FRAME_SIZE-CUTOUT); //FILL JUST ONCE while(nextInFrameOffset+(MAX_DECODED_FRAME_SIZE*CUTOUT) < TEST_SAMPLES_NUM) { //if(i%(1024*256)) continue; frameSignedStart = (short*)(bin_data+nextInFrameOffset); if(g_LPC24XX_DAC_Driver.AddFrame(frameSignedStart, frameLength)) { debug_printf( " done.\r\n" ); nextInFrameOffset+=MAX_DECODED_FRAME_SIZE; } else { //debug_printf( "FAIL.\r\n"); } } while(g_LPC24XX_DAC_Driver.GetBufferLevel()>0) { //debug_printf("Samples left: %d\r\n", g_LPC24XX_DAC_Driver.GetBufferLevel()); //debug_printf("Frames left: %d\r\n", g_LPC24XX_DAC_Driver.GetFramesLeft()); } Events_WaitForEvents( 0, 3000 ); displayRunTestResults(); debug_printf("CSV DATA OUTPUT FOLLOWS\r\n"); csvRunTestResults(); /*CONTINUOUS REFILL with samples while(true) { //if(i%(1024*256)) continue; frameSignedStart = (short*)(bin_data+nextInFrameOffset); if(g_LPC24XX_DAC_Driver.AddFrame(frameSignedStart, frameLength)) { //debug_printf( " done.\r\n" ); nextInFrameOffset+=MAX_DECODED_FRAME_SIZE; if(nextInFrameOffset+(MAX_DECODED_FRAME_SIZE*CUTOUT)>=TEST_SAMPLES_NUM) nextInFrameOffset = 0; } else { //debug_printf( "FAIL.\r\n"); } debug_printf("Samples left: %d\r\n", g_LPC24XX_DAC_Driver.GetBufferLevel()); debug_printf("Frames left: %d\r\n", g_LPC24XX_DAC_Driver.GetFramesLeft()); }*///end continuous refill debug_printf("%d frames left.\r\n", g_LPC24XX_DAC_Driver.GetFramesLeft()); debug_printf( "PARALLEL BUFFER FILL TEST OVER.\r\n\r\n" ); //Events_WaitForEvents( 0, 10000 ); debug_printf( "DAC.Off()\r\n"); if(g_LPC24XX_DAC_Driver.Off()) { debug_printf( "Done.\r\n" ); } else { debug_printf( "FAILED.\r\n" ); } debug_printf( "Uninit DAC()\r\n"); g_LPC24XX_DAC_Driver.Uninitialize(); debug_printf( "Done.\r\n"); #endif #if defined(TEST_JOYSTICK) extern LPC24XX_GPIO_Driver g_LPC24XX_GPIO_Driver; wait_joystick = true; for(UINT32 pin = LPC24XX_GPIO::c_P2_22; pin < LPC24XX_GPIO::c_P2_28; pin++) { if(pin == LPC24XX_GPIO::c_P2_24) continue; if(!g_LPC24XX_GPIO_Driver.EnableInputPin( pin, false, joystickISR, NULL, GPIO_INT_EDGE_HIGH, (GPIO_RESISTOR)2 )) { debug_printf("Cannot enable pin %u as INPUT pin.\r\n", pin); exit(1); } debug_printf("Enabled pin %u as INPUT pin.\r\n", pin); } while(wait_joystick) {}; #endif #if defined(TEST_SST39WF) while(1) { lcd_printf ( "Hello, world from the LCD!\r\n" ); hal_printf ( "Hello, world from the HAL!\r\n" ); debug_printf( "Hello, world from the debug intf!\r\n" ); if(BlockStorageList::GetNumDevices() != 1) { debug_printf( "%d Block Devices present!\r\n", BlockStorageList::GetNumDevices() ); break; } BlockStorageDevice* SST = BlockStorageList::GetFirstDevice(); if(SST == NULL) { debug_printf( "GetFirstDevice failed.\r\n" ); break; } const BlockDeviceInfo* SSTInfo = SST->GetDeviceInfo(); if(SSTInfo == NULL) { debug_printf( "GetDeviceInfo failed.\r\n" ); break; } debug_printf( "NumRegions in BSDevice: %d\r\n", SSTInfo->NumRegions); ByteAddress PhyAddress = (ByteAddress) 0xC0FFEEEE; SectorAddress SectAddress = 0xC0FFEEEE; UINT32 RangeIndex; UINT32 RegionIndex; const BlockRegionInfo *pBlockRegionInfo; SST->FindForBlockUsage( /*UINT32*/ BlockRange::BLOCKTYPE_DEPLOYMENT , PhyAddress , RegionIndex, RangeIndex ); if(PhyAddress == 0xC0FFEEEE) { debug_printf( "FindForBlockUsage failed.\r\n" ); break; } debug_printf( "Sector 0x%08x physical address: 0x%08x\r\n", SectAddress, PhyAddress); BYTE pSectorBuf[] = {0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF}; //ERASE before writing! if(!SST->IsBlockErased(PhyAddress, 0x1000)) { debug_printf( "Erasing block " ); if(!SST->EraseBlock(SectAddress)) { debug_printf( "failed.\r\n" ); break; } debug_printf( "successful.\r\n" ); } if(SST->Write(/*UINT32*/ PhyAddress, /*UINT32 NumOfBytes*/ 16, /*BYTE* */ pSectorBuf, /*SectorMetadata* */ FALSE)) debug_printf( "Correctly written 16 bytes to Sector 0x%08x\r\n", SectAddress); Events_WaitForEvents( 0, 2000 ); } #endif //TEST_SST39WF #if defined(TEST_PWM) PWM_Initialize(PWM_CHANNEL_0); // NOTE: on the EA_LPC2478 board the first pin we will return is the 11th pin on the left side from the top of the J1 connector GPIO_PIN pin = PWM_GetPinForChannel( PWM_CHANNEL_0 ); // from 90% to 2/3, to 50%, to 1/3 to 10% float dc[5] = { 0.9, 0.666, 0.5, 0.333, 0.1 }; UINT32 period1 = 1000; // 1Kxz for(UINT32 idx = 0; idx < 5; ++idx) { UINT32 duration1 = (UINT32)((float)period1 * dc[idx]); PWM_ApplyConfiguration( PWM_CHANNEL_0, pin, period1, duration1, FALSE); PWM_Start ( PWM_CHANNEL_0, pin ); // 2 secs, then change HAL_Time_Sleep_MicroSeconds_InterruptEnabled(1 * 1000 * 1000); //Events_WaitForEvents( 0, 2 * 1000); PWM_Stop ( PWM_CHANNEL_0, pin ); } // from 10Khz to 1Khz, 50% duty cycle for(UINT32 period = 10000; period >= 1000; period -= 1000) { UINT32 duration = period / 2; PWM_ApplyConfiguration( PWM_CHANNEL_0, pin, period, duration, FALSE); PWM_Start ( PWM_CHANNEL_0, pin ); // 2 secs, then change HAL_Time_Sleep_MicroSeconds_InterruptEnabled(1 * 1000 * 1000); //Events_WaitForEvents( 0, 2 * 1000); PWM_Stop ( PWM_CHANNEL_0, pin ); } PWM_Uninitialize(PWM_CHANNEL_0); #endif // TEST_PWM while(1) { lcd_printf ( "Hello, world!\r\n" ); hal_printf ( "Hello, world!\r\n" ); debug_printf( "Hello, world!\r\n" ); Events_WaitForEvents( 0, 1000 ); } }
/*---------------------------------------------------------------------------------------------------------*/ int32_t main(void) { /* Unlock protected registers */ SYS_UnlockReg(); /* Init System, IP clock and multi-function I/O */ SYS_Init(); /* Lock protected registers */ SYS_LockReg(); /* Init UART0 for printf */ UART0_Init(); printf("+------------------------------------------------------------------------+\n"); printf("| PWM Driver Sample Code |\n"); printf("| |\n"); printf("+------------------------------------------------------------------------+\n"); printf(" This sample code will use PWM0 channel 0 to capture\n the signal from PWM1 channel 0.\n"); printf(" I/O configuration:\n"); printf(" PWM0_CH0(PA.12 PWM0 channel 0) <--> PWM1_CH0(PA.2 PWM1 channel 0)\n\n"); printf("Use PWM0 Channel 0(PA.12) to capture the PWM1 Channel 0(PA.2) Waveform\n"); while(1) { printf("Press any key to start PWM Capture Test\n"); getchar(); /*--------------------------------------------------------------------------------------*/ /* Set the PWM1 Channel 0 as PWM output function. */ /*--------------------------------------------------------------------------------------*/ /* Assume PWM output frequency is 250Hz and duty ratio is 30%, user can calculate PWM settings by follows. duty ratio = (CMR+1)/(CNR+1) cycle time = CNR+1 High level = CMR+1 PWM clock source frequency = __HXT = 12000000 (CNR+1) = PWM clock source frequency/prescaler/clock source divider/PWM output frequency = 12000000/2/1/250 = 24000 (Note: CNR is 16 bits, so if calculated value is larger than 65536, user should increase prescale value.) CNR = 23999 duty ratio = 30% ==> (CMR+1)/(CNR+1) = 30% CMR = 7199 Prescale value is 1 : prescaler= 2 Clock divider is PWM_CSR_DIV1 : clock divider =1 */ /* set PWM1 channel 0 output configuration */ PWM_ConfigOutputChannel(PWM1, 0, 250, 30); /* Enable PWM Output path for PWM1 channel 0 */ PWM_EnableOutput(PWM1, PWM_CH_0_MASK); /* Enable Timer for PWM1 channel 0 */ PWM_Start(PWM1, PWM_CH_0_MASK); /*--------------------------------------------------------------------------------------*/ /* Set the PWM0 channel 0 for capture function */ /*--------------------------------------------------------------------------------------*/ /* If input minimum frequency is 250Hz, user can calculate capture settings by follows. Capture clock source frequency = __HXT = 12000000 in the sample code. (CNR+1) = Capture clock source frequency/prescaler/clock source divider/minimum input frequency = 12000000/2/1/250 = 24000 (Note: CNR is 16 bits, so if calculated value is larger than 65536, user should increase prescale value.) CNR = 0xFFFF (Note: In capture mode, user should set CNR to 0xFFFF to increase capture frequency range.) */ /* set PWM0 channel 0 capture configuration */ PWM_ConfigCaptureChannel(PWM0, 0, 166, 0); /* Enable capture falling edge interrupt for PWM0 channel 0 */ //PWM_EnableCaptureInt(PWM0, 0, PWM_CAPTURE_INT_FALLING_LATCH); /* Enable PWM0 NVIC interrupt */ //NVIC_EnableIRQ(PWM0_IRQn); /* Enable Timer for PWM0 channel 0 */ PWM_Start(PWM0, PWM_CH_0_MASK); /* Enable Capture Function for PWM0 channel 0 */ PWM_EnableCapture(PWM0, PWM_CH_0_MASK); /* Enable falling capture reload */ PWM0->CAPCTL |= PWM_CAPCTL_FCRLDEN0_Msk; /* Wait until PWM0 channel 0 Timer start to count */ while((PWM0->CNT[0]) == 0); /* Capture the Input Waveform Data */ CalPeriodTime(PWM0, 0); /*---------------------------------------------------------------------------------------------------------*/ /* Stop PWM1 channel 0 (Recommended procedure method 1) */ /* Set PWM Timer loaded value(Period) as 0. When PWM internal counter(CNT) reaches to 0, disable PWM Timer */ /*---------------------------------------------------------------------------------------------------------*/ /* Set PWM1 channel 0 loaded value as 0 */ PWM_Stop(PWM1, PWM_CH_0_MASK); /* Wait until PWM1 channel 0 Timer Stop */ while((PWM1->CNT[0] & PWM_CNT_CNT_Msk) != 0); /* Disable Timer for PWM1 channel 0 */ PWM_ForceStop(PWM1, PWM_CH_0_MASK); /* Disable PWM Output path for PWM1 channel 0 */ PWM_DisableOutput(PWM1, PWM_CH_0_MASK); /*---------------------------------------------------------------------------------------------------------*/ /* Stop PWM0 channel 0 (Recommended procedure method 1) */ /* Set PWM Timer loaded value(Period) as 0. When PWM internal counter(CNT) reaches to 0, disable PWM Timer */ /*---------------------------------------------------------------------------------------------------------*/ /* Disable PWM0 NVIC */ //NVIC_DisableIRQ(PWM0_IRQn); /* Set loaded value as 0 for PWM0 channel 0 */ PWM_Stop(PWM0, PWM_CH_0_MASK); /* Wait until PWM0 channel 0 current counter reach to 0 */ while((PWM0->CNT[0] & PWM_CNT_CNT_Msk) != 0); /* Disable Timer for PWM0 channel 0 */ PWM_ForceStop(PWM0, PWM_CH_0_MASK); /* Disable Capture Function and Capture Input path for PWM0 channel 0 */ PWM_DisableCapture(PWM0, PWM_CH_0_MASK); /* Clear Capture Interrupt flag for PWM0 channel 0 */ PWM_ClearCaptureIntFlag(PWM0, 0, PWM_CAPTURE_INT_FALLING_LATCH); } }