int main() { #if defined(PIC32_PINGUINO) || defined(PIC32_PINGUINO_OTG) TRISDbits.TRISD9=1; // because PORTB is shared with SDA on Olimex board TRISDbits.TRISD10=1; // because PORTB is shared with SCL on Olimex board #endif SystemConfig(80000000); // default clock frequency is 80Mhz // default peripheral freq. is 40MHz (cf. system.c) // All pins of PORTB as digital IOs #ifdef __32MX220F032D__ ANSELA = 0; ANSELB = 0; ANSELC = 0; #else AD1PCFG = 0xFFFF; #endif #ifdef __ANALOG__ analog_init(); #endif #ifdef __MILLIS__ millis_init(); #endif #ifdef __PWM__ PWM_init(); #endif #ifdef __USBCDC CDC_init(); #endif #ifdef __RTCC__ RTCC_init(); #endif setup(); while (1) { #ifdef __USBCDC CDCTxService(); #endif loop(); } return(0); }
int main() { // default peripheral freq. is CPUCoreFrequency / 2 (cf. system.c) #if defined(__32MX220F032D__)||defined(__32MX250F128B__)||defined(__32MX220F032B__) SystemConfig(40000000); // default clock frequency is 40Mhz #else SystemConfig(80000000); // default clock frequency is 80Mhz #endif IOsetSpecial(); IOsetDigital(); IOsetRemap(); #ifdef __ANALOG__ analog_init(); #endif #ifdef __MILLIS__ millis_init(); #endif #ifdef __PWM__ PWM_init(); #endif #ifdef __USBCDC CDC_init(); #endif #ifdef __RTCC__ RTCC_init(); #endif setup(); while (1) { #ifdef __USBCDC #if defined(__32MX220F032D__)||defined(__32MX250F128B__)||defined(__32MX220F032B__) USB_Service( ); #else CDCTxService(); #endif #endif loop(); } return(0); }
BOOL CDCUSBIsConnected(void) { if ( (U1OTGSTATbits.VBUSVD != 0) && (U1OTGSTATbits.SESVD != 0) ) { if (CDCUSBNotConnected == true) { CDC_init(); CDCUSBNotConnected = false; } return(true); } else { CDCUSBNotConnected = true; return (false); } }
// Application entry point called from bootloader v4.x void main(void) #endif { #if defined(__18f25k50) || defined(__18f45k50) || \ defined(__18f26j50) || defined(__18f46j50) || \ defined(__18f26j53) || defined(__18f46j53) || \ defined(__18f27j53) || defined(__18f47j53) u16 pll_startup_counter = 600; #endif /// ---------------------------------------------------------------- /// If we start from a Power-on reset, set NOT_POR bit to 1 /// ---------------------------------------------------------------- if (RCONbits.NOT_POR == 0) { RCON |= 0b10010011; // set all reset flag // enable priority levels on interrupts } /// ---------------------------------------------------------------- /// Disables all interrupt /// ---------------------------------------------------------------- //INTCONbits.GIEH = 0; // Disables all HP interrupts //INTCONbits.GIEL = 0; // Disables all LP interrupts /// ---------------------------------------------------------------- /// Perform a loop for some processors until their frequency is stable /// ---------------------------------------------------------------- #if defined(__18f2455) || defined(__18f4455) || \ defined(__18f2550) || defined(__18f4550) // If Internal Oscillator is used if (OSCCONbits.SCS > 0x01) // wait INTOSC frequency is stable (IOFS=1) while (!OSCCONbits.IOFS); // PLL is enabled by Config. Bits #elif defined(__18f25k50) || defined(__18f45k50) // If Internal Oscillator is used if (OSCCONbits.SCS > 0x01) // wait HFINTOSC frequency is stable (HFIOFS=1) while (!OSCCONbits.HFIOFS); // Enable the PLL and wait 2+ms until the PLL locks OSCCON2bits.PLLEN = 1; OSCTUNEbits.SPLLMULT = 1; // 1=3xPLL, 0=4xPLL while (pll_startup_counter--); #elif defined(__18f26j50) || defined(__18f46j50) // If Internal Oscillator is used // if (OSCCONbits.SCS > 0x02) // Seems there is no time to wait // Enable the PLL and wait 2+ms until the PLL locks OSCTUNEbits.PLLEN = 1; while (pll_startup_counter--); #elif defined(__18f26j53) || defined(__18f46j53) || \ defined(__18f27j53) || defined(__18f47j53) // If Internal Oscillator is used if (OSCCONbits.SCS > 0x02) // wait INTOSC frequency is stable (FLTS=1) while(!OSCCONbits.FLTS); // Enable the PLL and wait 2+ms until the PLL locks OSCTUNEbits.PLLEN = 1; while (pll_startup_counter--); #endif /// ---------------------------------------------------------------- /// I/O init /// ---------------------------------------------------------------- IO_init(); IO_digital(); #if defined(__18f26j50) || defined(__18f46j50) || \ defined(__18f26j53) || defined(__18f46j53) || \ defined(__18f27j53) || defined(__18f47j53) IO_remap(); #endif /// ---------------------------------------------------------------- /// Various Init. /// ---------------------------------------------------------------- #ifdef __USB__ usb_init(); #endif #ifdef __USBCDC CDC_init(); #endif #ifdef __USBBULK bulk_init(); #endif #if defined(ANALOGREFERENCE) || defined(ANALOGREAD) analog_init(); #endif #ifdef ANALOGWRITE analogwrite_init(); #endif #ifdef __MILLIS__ // Use Timer 0 millis_init(); #endif #ifdef SERVOSLIBRARY // Use Timer 1 servos_init(); #endif #ifdef __PS2KEYB__ keyboard_init() #endif //////////////////////////////////////////////////////////////////////// setup(); //////////////////////////////////////////////////////////////////////// #if defined(TMR0INT) || defined(TMR1INT) || \ defined(TMR2INT) || defined(TMR3INT) || \ defined(TMR4INT) || defined(TMR5INT) || \ defined(TMR6INT) || defined(TMR8INT) IntTimerStart(); // Enable all defined timers interrupts // at the same time #endif #ifdef ON_EVENT //IntInit(); INTCONbits.GIEH = 1; // Enable global HP interrupts INTCONbits.GIEL = 1; // Enable global LP interrupts #endif while (1) { //////////////////////////////////////////////////////////////////////// loop(); //////////////////////////////////////////////////////////////////////// } }
void pinguino_main(void) { #if defined(PIC18F26J50) // Enable the PLL and wait 2+ms until the PLL locks u16 pll_startup_counter = 600; OSCTUNEbits.PLLEN = 1; while(pll_startup_counter--); #endif PIE1 = 0; PIE2 = 0; IOsetSpecial(); IOsetDigital(); IOsetRemap(); #ifdef ON_EVENT // Enable General/Peripheral interrupts int_init(); // Disable all individual interrupts #endif #ifdef __USB__ PIE2bits.USBIE = 1; INTCONbits.PEIE = 1; INTCONbits.GIE = 1; #endif //setup(); //#ifdef ON_EVENT //int_start(); // Enable all defined timers interrupts //#endif #ifdef ANALOG analog_init(); #endif #ifdef __MILLIS__ // Use Timer 0 millis_init(); #endif #ifdef SERVOSLIBRARY servos_init(); #endif #ifdef __USBCDC CDC_init(); PIE2bits.USBIE = 1; INTCONbits.PEIE = 1; INTCONbits.GIE = 1; #endif #ifdef __USBBULK bulk_init(); PIE2bits.USBIE = 1; INTCONbits.PEIE = 1; INTCONbits.GIE = 1; #endif #ifdef __PS2KEYB__ keyboard_init() #endif #if defined(__SERIAL__) || defined(SERVOSLIBRARY) INTCONbits.PEIE = 1; INTCONbits.GIE = 1; #endif /* RB : millis.c/millis_init() did already the job #ifdef MILLIS INTCONbits.TMR0IE= 1; INTCONbits.GIE = 1; #endif */ setup(); #ifdef ON_EVENT int_start(); // Enable all defined timers interrupts #endif while (1) loop(); }
int main(void) { DBG_LED_ENA; DBG_1_ENA; DBG_1_OFF; DBG_2_ENA; DBG_2_OFF; DBG_3_ENA; DBG_3_OFF; debug_code_init(); CLK_init(); ADC0_init(); SR_EXP_Init(); #ifdef RGB_MATRIX_ENABLE i2c1_init(); #endif // RGB_MATRIX_ENABLE matrix_init(); USB2422_init(); DBGC(DC_MAIN_UDC_START_BEGIN); udc_start(); DBGC(DC_MAIN_UDC_START_COMPLETE); DBGC(DC_MAIN_CDC_INIT_BEGIN); CDC_init(); DBGC(DC_MAIN_CDC_INIT_COMPLETE); while (USB2422_Port_Detect_Init() == 0) {} DBG_LED_OFF; #ifdef RGB_MATRIX_ENABLE while (I2C3733_Init_Control() != 1) {} while (I2C3733_Init_Drivers() != 1) {} I2C_DMAC_LED_Init(); i2c_led_q_init(); for (uint8_t drvid = 0; drvid < ISSI3733_DRIVER_COUNT; drvid++) I2C_LED_Q_ONOFF(drvid); //Queue data #endif // RGB_MATRIX_ENABLE keyboard_setup(); keyboard_init(); host_set_driver(&arm_atsam_driver); #ifdef CONSOLE_ENABLE uint64_t next_print = 0; #endif //CONSOLE_ENABLE v_5v_avg = adc_get(ADC_5V); debug_code_disable(); while (1) { main_subtasks(); //Note these tasks will also be run while waiting for USB keyboard polling intervals if (g_usb_state == USB_FSMSTATUS_FSMSTATE_SUSPEND_Val || g_usb_state == USB_FSMSTATUS_FSMSTATE_SLEEP_Val) { if (suspend_wakeup_condition()) { udc_remotewakeup(); //Send remote wakeup signal wait_ms(50); } continue; } keyboard_task(); #ifdef CONSOLE_ENABLE if (timer_read64() > next_print) { next_print = timer_read64() + 250; //Add any debug information here that you want to see very often //dprintf("5v=%u 5vu=%u dlow=%u dhi=%u gca=%u gcd=%u\r\n", v_5v, v_5v_avg, v_5v_avg - V5_LOW, v_5v_avg - V5_HIGH, gcr_actual, gcr_desired); } #endif //CONSOLE_ENABLE } return 1; }