int main(void) { SetupHardware(); /* Create a regular character stream for the interface so that it can be used with the stdio.h functions */ CDC_Device_CreateStream(&VirtualSerial_CDC_Interface, &USBSerialStream); GlobalInterruptEnable(); while(1) { DebounceUpdate(); EncoderUpdate(); LedUpdate(); SendSerial(); /* Must throw away unused bytes from the host, or it will lock up while waiting for the device */ CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface); CDC_Device_USBTask(&VirtualSerial_CDC_Interface); HID_Device_USBTask(&Mouse_HID_Interface); HID_Device_USBTask(&Keyboard_HID_Interface); USB_USBTask(); } }
void SystemInitialize(void) { cli(); #if defined(USE_MU) // Setting for Receive Data CtrlDataInitialize(); // RCReceive.c // Initialize for MU MuInitialize(); // Mu.c #endif #if defined(USE_ENCODER) // Initialize for Encoder EncoderInitialize(); // Encoder.c #endif #if defined(USE_SWITCH) // Initialize for Switch SwitchInitialize(); // Switch.c #endif #if defined(USE_DIP_SWITCH) DipSwitchInitialize(); // Switch.c #endif #if defined(USE_SENSOR) SensorInitialize(); #endif #if defined(USE_AIR) // Initialize for Air Actuator AirInitialize(); // Air.c AirUpdate(); // Air.c #endif #if defined(USE_BUZZER) // Initialize for Buzzer Actuator BuzzerInitialize(); // Buzzer.c BuzzerUpdate(); // Buzzer.c #endif #if defined(USE_LED) // Initialize for LED LedInitialize(); // Led.c LedUpdate(); // Led.c #endif #if defined(USE_MOTOR) // Initialize for Motor Actuator MotorInitialize(); // Motor.c MotorUpdate(); // Motor.c #endif #if defined(USE_SERVO) // Initialize for Servo Motor Actuator ServoInitialize(); // Servo.c ServoUpdate(); // Servo.c #endif #if defined(USE_SAFETY) // Initialize for Safety Function SafetyInitialize[SAFETY_TIMER_NO](); // Safety.c #endif #if defined(USE_HUB) #if defined(USE_RS485) RS485Initialize(12); #endif #endif #if defined(WDT_RESET) WDTInitialize(); #endif // Initialize Process Job ProcessJobInitialize(); // Process.c }
/*---------------------------------------------------------------------------------------------------------------------- Function: LedInitialize Description: Initialization of LED system paramters and visual LED check. Requires: - G_u32SystemTime1ms ticking - All LEDs already initialized to LED_NORMAL_MODE mode ON Promises: - All LEDs in LED_NORMAL_MODE mode with OFF */ void LedInitialize(void) { u32 u32Timer; // u8* pu8Parser; u32 u32Buzzer1Frequency = 4000; u32 u32Buzzer2Frequency = 500; u32 u32StepSize = (u32Buzzer1Frequency - u32Buzzer2Frequency) / 20; static u8 au8LedStartupMsg[] = "LED functions ready\n\r"; #if MPGL2 /* Test code for checking LEDs */ #if 0 LedOn(RED0); LedOn(RED1); LedOn(RED2); LedOn(RED3); LedOn(BLUE0); LedOn(BLUE1); LedOn(BLUE2); LedOn(BLUE3); LedOn(GREEN0); LedOn(GREEN1); LedOn(GREEN2); LedOn(GREEN3); #endif #endif /* MPGL2 */ /* Turn all LEDs on full, then fade them out over a few seconds */ for(u8 i = 20; i > 0; i--) { #if STARTUP_SOUND /* Configure Buzzers to provide some audio during start up */ PWMAudioSetFrequency(BUZZER1, u32Buzzer1Frequency); PWMAudioOn(BUZZER1); #ifdef MPGL1 PWMAudioSetFrequency(BUZZER2, u32Buzzer2Frequency); PWMAudioOn(BUZZER2); #endif /* MPGL1 */ #endif /* STARTUP_SOUND */ /* Spend 40ms in each level of intensity */ for(u16 j = 40; j > 0; j--) { u32Timer = G_u32SystemTime1ms; while( !IsTimeUp(&u32Timer, 1) ); LedUpdate(); } /* Pause for a bit on the first iteration to show the LEDs on for little while */ if(i == 20) { while( !IsTimeUp(&u32Timer, 1500) ); } /* Set the LED intensity for the next iteration */ for(u8 j = 0; j < TOTAL_LEDS; j++) { Leds_asLedArray[j].eRate = (LedRateType)(i - 1); } /* Set the buzzer frequency for the next iteration */ u32Buzzer1Frequency -= u32StepSize; u32Buzzer2Frequency += u32StepSize; } /* Final update to set last state, hold for a short period */ LedUpdate(); while( !IsTimeUp(&u32Timer, 200) ); #if STARTUP_SOUND /* Turn off the buzzers */ PWMAudioOff(BUZZER1); #ifdef MPGL1 PWMAudioOff(BUZZER2); #endif /* MPGL1 */ #endif /* STARTUP_SOUND */ /* Exit with Leds off, NORMAL mode, and the backlight on (white) */ for(u8 i = 0; i < TOTAL_LEDS; i++) { Leds_asLedArray[0].eMode = LED_NORMAL_MODE; } #ifdef MPGL1 LedOn(LCD_RED); LedOn(LCD_GREEN); LedOn(LCD_BLUE); #endif #ifdef MPGL2 LedOn(LCD_BL); #endif /* Final setup and report that LED system is ready */ G_u32ApplicationFlags |= _APPLICATION_FLAGS_LED; DebugPrintf(au8LedStartupMsg); } /* end LedInitialize() */
void main(void) { G_u32SystemFlags |= _SYSTEM_INITIALIZING; /* Low level initialization */ WatchDogSetup(); /* During development, set to not reset processor if timeout */ ClockSetup(); GpioSetup(); InterruptSetup(); SysTickSetup(); /* Driver initialization */ MessagingInitialize(); UartInitialize(); DebugInitialize(); /* Debug messages through DebugPrintf() are available from here */ SspInitialize(); TWIInitialize(); LcdInitialize(); LedInitialize(); ButtonInitialize(); CapTouchInitialize(); AntInitialize(); /* Application initialization */ UserAppInitialize(); /* Exit initialization */ SystemStatusReport(); G_u32SystemFlags &= ~_SYSTEM_INITIALIZING; /* Super loop */ while(1) { WATCHDOG_BONE(); /* Drivers */ LedUpdate(); ButtonRunActiveState(); UartRunActiveState(); SspRunActiveState(); TWIRunActiveState(); CapTouchRunActiveState(); /* This function violates 1ms loop timing every 25ms */ MessagingRunActiveState(); DebugRunActiveState(); LcdRunActiveState(); AntRunActiveState(); /* Applications */ UserAppRunActiveState(); /* System sleep*/ HEARTBEAT_OFF(); SystemSleep(); HEARTBEAT_ON(); } /* end while(1) main super loop */ } /* end main() */