void MainTask(void) { USB_Init(); USB_EnableIAD(); _AddCDC(); _AddHID(); USB_Start(); BSP_SetLED(0); OS_CREATETASK(&_HIDTCB, "HIDTask", _HIDTask, 200, _aHIDStack); while (1) { char ac[64]; int NumBytesReceived; // // Wait for configuration // while ((USB_GetState() & (USB_STAT_CONFIGURED | USB_STAT_SUSPENDED)) != USB_STAT_CONFIGURED) { BSP_ToggleLED(0); USB_OS_Delay(50); } BSP_SetLED(0); NumBytesReceived = USB_CDC_Receive(&ac[0], sizeof(ac)); if (NumBytesReceived > 0) { USB_CDC_Write(&ac[0], NumBytesReceived); } } }
void MainTask(void) { USB_Init(); _AddBULK(); USB_Start(); OS_CREATETASK(&_StatusTCB0, "Status Task", _StatusTask, 50, _aStatusStack); OS_CREATETASK(&_USBTCB0, "USB Task", _USBTask, 150, _aUSBStack); OS_Terminate(OS_pCurrentTask); }
/******************************************************************************* * Function Name: USB_CyBtldrCommStart ****************************************************************************//** * * This function performs all required initialization for the USBFS component, * waits on enumeration, and enables communication. * * \sideeffect * This function starts the USB with 3V or 5V operation. * * \reentrant * No. * *******************************************************************************/ void USB_CyBtldrCommStart(void) { /* Enable Global Interrupts. Interrupts are mandatory for USBFS component operation. */ CyGlobalIntEnable; /* Start USBFS Operation: device 0 and with 5V or 3V operation depend on Voltage Configuration in DWR. */ USB_Start(0u, USB_DWR_POWER_OPERATION); /* USB component started, the correct enumeration will be checked in the first Read operation. */ USB_started = 1u; }
int main(void) { laser_off(); bootloaderSwitcher(); init_serial_number(); USB_Start(); RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE); setupJP5(); setupJP6(); setupLeds(); init_watchdog(); setup_interlock(); //debug: flas the light on boot, to watch for watchdog resets setCoilLed(1); initialize_led_override(); if (LED_OVERRIDES_EN){ play_long_spin(); //Spin the led's while we load the rest of this stuff } initialize_pwm(); initialize_dripper(); setCornerLed(0); setInLed(0); setCoilLed(0); setUSBLed(0); SysTick_Config(SystemCoreClock / 2000); //48MHz/2000 gives us 2000 ticks per second (2KHz) int last_drip_count = g_dripcount; while(1) { serialio_feed(); updateADC(); if (move_count!=0){ g_twig_coils=0; g_key_coil_gate=0; } if (g_dripcount != last_drip_count) { last_drip_count = g_dripcount; send_updated_drip_count(); } if ((tick % 500) == 0) { send_printer_status(); } } }
void MainTask(void) { USB_Init(); _AddMSD(); USB_Start(); while (1) { while ((USB_GetState() & (USB_STAT_CONFIGURED | USB_STAT_SUSPENDED)) != USB_STAT_CONFIGURED) { BSP_ToggleLED(0); USB_OS_Delay(50); } BSP_SetLED(0); USB_MSD_Task(); } }
void usb_init(void) { /* Start USB operation with 5-V operation. */ USB_Start(0u, USB_5V_OPERATION); /* Wait for device to enumerate */ while (0u == USB_GetConfiguration()) { wait_ms(100); } host_set_driver(psoc_driver()); // Start listening! USB_EnableOutEP(INBOX_EP); }
/********************************************************************* * * _USBTask */ static void _USBTask(void) { _AddMSD(); USB_Start(); while(1) { // // Wait for configuration // while ((USB_GetState() & (USB_STAT_CONFIGURED | USB_STAT_SUSPENDED)) != USB_STAT_CONFIGURED) { BSP_ToggleLED(0); USB_OS_Delay(50); } BSP_SetLED(0); FS_Unmount(""); USB_MSD_Task(); // Task, does only return when device is non-configured mode FS_Mount(""); } }
void main(void) { // Initialize Pull Up/Down ressistors //Port_0_Data_SHADE = 0x80; // Enable distance input pull-up P0.7 //PRT0DR = Port_0_Data_SHADE; Port_2_Data_SHADE = 0x04; // Enable pull-down resistor on LED P2.2 PRT2DR = Port_2_Data_SHADE; Port_3_Data_SHADE = 0x20; // Enable pull-up on button bit P3.5 PRT3DR = Port_3_Data_SHADE; Port_4_Data_SHADE = 0x44; // Enable pull-down LED P4.2, P4.6 PRT4DR = Port_4_Data_SHADE; Timer8_WritePeriod(50); // 12MHz/15/16/50 = 1KHz => 1ms main timer interrupt Timer8_WriteCompareValue(0); Timer8_EnableInt(); Timer8_Start(); PRS8_WritePolynomial(0x78); // load the PRS polynomial PRS8_WriteSeed(0xFF); // load the PRS seed PRS8_Start(); // start the PRS8 RED_Start(); GREEN_Start(); BLUE_Start(); PWM8_WritePeriod(100); // set period to eight clocks PWM8_WritePulseWidth(0); // set pulse width to generate a % duty cycle PWM8_EnableInt(); // ensure interrupt is enabled PWM8_Start(); // start PWM //DAC_CR &= ~0x80; // turn off SplitMUX bit 7 (P0[7] on right, others on left) PGA_Start(PGA_HIGHPOWER); // Start PGA ADCINC_Start(ADCINC_HIGHPOWER); // Start ADC ADCINC_GetSamples(1); // initiate the first sample M8C_EnableGInt; // Global interrupt enable ReadFlash(); // read on/off times and LED dutycyle from FLASH if(!(RamFlashBlock.Dummy == 0x55)) { SetFlashDefaults(); // clear flash first time } LedPowerTog = 1; // flag change LedPower = RamFlashBlock.PowerState; RedDutyMax = RamFlashBlock.RedDuty; BlueDutyMax = RamFlashBlock.BlueDuty; GreenDutyMax = RamFlashBlock.GreenDuty; the_state = RamFlashBlock.the_state; ledChangeRate = RamFlashBlock.ledChangeRate; Events.press = 0; Events.hold = 0; Events.release = 0; MenuFsm(&Events, &the_state); // initlaize the state machine USB_Start(0, USB_3V_OPERATION); // Start USB //while (!USB_bGetConfiguration()); // Wait to be enumerated USB_INT_REG |= USB_INT_SOF_MASK; USB_EnableOutEP(1); // Post a buffer to wait for a command while(1) // cycle the puck here { MeasureTemperature(); // sample input temperature sensor voltage ThermalProtection(); // decrease LED power if temperature rises above limit ButtonStates(); // button driver CommunicateUSB(); // USB driver LedStates(); // LED Cadence state machine DelayedSaveFlash(); // Save power state and RGB dutycycle 10 seconds after last button event } }
void main() { /* Place your initialization/startup code here (e.g. MyInst_Start()) */ CyGlobalIntEnable; /* Uncomment this line to enable global interrupts. */ init(); // Start usb operation with 3V //Wait for device to enumerate USB_Start(0u,USB_3V_OPERATION); while(!USB_bGetConfiguration()); //Enumeration i done, enable out endpoint for recieve data from host USB_EnableOutEP(2); ADC_StartConvert(); while(1) { //wait for data while(USB_bGetEPState(2) !=USB_OUT_BUFFER_FULL); //read received bytes count length = USB_wGetEPCount(2); //turn on LED LED_Write(~LED_Read()); //unload the out buffer USB_ReadOutEP(2, &buffer[0], length); // check for in buffer is empty while(USB_bGetEPState(1) != USB_IN_BUFFER_EMPTY); // Turn off LED // load the in buffer USB_LoadInEP(1, &buffer[0], length); while(USB_bGetEPState(1) != USB_IN_BUFFER_EMPTY); USB_LoadInEP(1, &buffer[1], length); } for(;;) { } /* while(!USB_bGetConfiguration()); //Enumeration i done, enable out endpoint for recieve data from host USB_EnableOutEP(2); while(1) { //wait for data while(USB_bGetEPState(2) !=USB_OUT_BUFFER_FULL); //read received bytes count length = USB_wGetEPCount(2); //turn on LED LED_Write(~LED_Read()); //unload the out buffer USB_ReadOutEP(2, &buffer[0], length); // check for in buffer is empty while(USB_bGetEPState(1) != USB_IN_BUFFER_EMPTY); // Turn off LED // load the in buffer USB_LoadInEP(1, &buffer[0], length); }*/ /* if( ADC_IsEndConversion(ADC_WAIT_FOR_RESULT)) { //LCD_ClearDisplay(); //LCD_PrintNumber(ADC_GetResult16()); //CyDelay(250); Pin_1_Write(~Pin_1_Read()); //buffer[count]=ADC_GetResult8(); buffer[count]=count; ++count; USB_LoadInEP(1,&buffer[0],1); if (count==64) { // load the in buffer *? //USB_LoadInEP(1, &buffer[0], 64); count=0; } } */ }