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); }
static void init() { // OSCCAL = 71; clock_prescale_set(CPU_DIV); // power_twi_disable(); // power_usart0_disable(); // power_timer0_disable(); // power_timer1_disable(); // power_timer2_disable(); // power_adc_disable(); #if !UART_ENABLE power_usart0_disable(); #endif // Pull-up on unused pins pinPullup(D0, PULLUP_ENABLE); pinPullup(D1, PULLUP_ENABLE); pinPullup(D3, PULLUP_ENABLE); pinPullup(D4, PULLUP_ENABLE); pinPullup(B7, PULLUP_ENABLE); #if PIN_DEBUG != PIN_DEBUG_NONE pinMode(PIN_DEBUG_PIN, OUTPUT); #endif // Pin change interrupt on USB power sense pin PCICR |= _BV(PCIE0); PCMSK0 |= _BV(PCINT6); // Everything else uart_init(); spi_init(); i2c_init(); watchconfig_init(); led_init(); buzzer_init(); battery_init(); ds3231_init(); buttons_init(); millis_init(); pwrmgr_init(); time_init(); alarm_init(); oled_init(); }
void pinguino_main(void) { PIE1=0; PIE2=0; ADCON1=0x0F; #ifdef __USB__ PIE2bits.USBIE = 1; INTCON = 0xC0; #endif setup(); #ifdef ANALOG analog_init(); #endif #ifdef MILLIS millis_init(); #endif #ifdef SERVOSLIBRARY servos_init(); #endif #ifdef __USBCDC init_CDC(); PIE2bits.USBIE = 1; INTCON = 0xC0; #endif #ifdef __SERIAL__ INTCONbits.PEIE=1; INTCONbits.GIE=1; #endif #ifdef MILLIS INTCONbits.TMR0IE=1; INTCONbits.GIE=1; #endif #ifdef SERVOSLIBRARY INTCONbits.PEIE=1; INTCONbits.GIE=1; #endif while (1) { loop(); } }
int main() { // Initialize library millis_init(); // Port D 2 and 3 as outputs DDRD |= _BV(DDD2)|_BV(DDD3); // Enable interrupts sei(); // Variables for keeping time LEDs last changed millis_t lastChangeLed1 = 0; millis_t lastChangeLed2 = 0; while(1) { // Time now millis_t now = millis(); // Has it been 500ms since last change for LED1? if(now - lastChangeLed1 >= 500) { // Toggle LED PORTD ^= _BV(PORTD2); // Store time lastChangeLed1 = now; } // Has it been 700ms since last change for LED2? if(now - lastChangeLed2 >= 700) { // Toggle LED PORTD ^= _BV(PORTD3); // Store time lastChangeLed2 = now; } } }
void board_init(void) { /* This function is meant to contain board-specific initialization code * for, e.g., the I/O pins. The initialization can rely on application- * specific board configuration, found in conf_board.h. */ scif_start_rc120M(); scif_start_rc8M(); //enable brownout detection scif_bod50_enable_irq(); //4.something volts //set cpu divide by 2^(1+1) = 4 pm_set_clk_domain_div(AVR32_PM_CLK_GRP_CPU,1); //switch main clock source pm_set_mclk_source(PM_CLK_SRC_RC120M); //cpu frequency is now 30 MHz //set up pba, pbb, pbc. must be less than fcpu/4 //cpu is divide by 4 --> need divide by 16. 2^(3+1) = 16 pm_set_clk_domain_div(AVR32_PM_CLK_GRP_PBA,3); pm_set_clk_domain_div(AVR32_PM_CLK_GRP_PBB,3); pm_set_clk_domain_div(AVR32_PM_CLK_GRP_PBB,3); //120MHz / 16 = 7.5MHz //setup adc ADCInit(); //setup millis() millis_init(); //set up pwm PWMInit(); //setup usart USARTInit(); // CANInit(); }
// 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(); //////////////////////////////////////////////////////////////////////// } }
/*! \brief Main function. Execution starts here. */ int main(void) { board_init(); ui_init(); lithneProgrammer.setMainReset(true); lithneProgrammer.setXbeeReset(true); irq_initialize_vectors(); cpu_irq_enable(); sysclk_init(); delay_init(sysclk_get_cpu_hz()); millis_init(); // Start USB stack to authorize VBus monitoring udc_start(); lithneProgrammer.setMainReset(false); lithneProgrammer.setXbeeReset(false); // USART_COMM0 is a directly forwarded serial to the main processor, handled by interrupts. // The port is opened and interrupts are enabled on USB connect on port 0 // USART_COMM1 connects to the main processor for xbee rx/tx forwarding. // USART_XBEE connects to the xbee module // Messages outside the programming scope are forwarded between these ports in the main loop. // When USB port 1 in opened, the main processor is held in reset and USB port 1 is transparently coupled to the XBEE. // Only in that case the RXE interrupt is enabled. // open both COM ports for xbee forward with default settings uart_open(&USART_COMM1); uart_open(&USART_XBEE); usart_set_rx_interrupt_level(&USART_COMM1, USART_INT_LVL_HI); usart_set_rx_interrupt_level(&USART_XBEE, USART_INT_LVL_HI); lithneProgrammer.init(&USART_COMM0, &serialCo2MainSerial); // should not be necessary to pass 2 objects, but a quick hack to make it work near deadline Lithne.setSerial(serialCo2Xbee); while (true) { if(main_cdc_is_open(1)){ // XBEE is directly linked to USB. Skip Lithne forwarding/programming continue; } if (Lithne.available() ){ // Only process messages inside the programming scope if ( Lithne.getScope() == lithneProgrammingScope ){ lithneProgrammer.updateRemoteAddress(); } // The programming function receives all data packets containing the program to be written if ( Lithne.getFunction() == fProgramming ) { lithneProgrammer.processPacket(); } // Check-in Function else if (Lithne.getFunction() == fCheckingIn && !lithneProgrammer.busyProgramming()) { lithneProgrammer.processCheckin(); } // Node Name Functions - Empty messages are a request, Messages with content set the node name else if (Lithne.getFunction() == fNodeName && !lithneProgrammer.busyProgramming()) { lithneProgrammer.processNodeName(); } // LastUpload Functions - Empty messages are a request, Messages with content set the time of last upload else if (Lithne.getFunction() == fLastUpload && !lithneProgrammer.busyProgramming()) { lithneProgrammer.processLastUpload(); } // File Name Functions - Empty messages are a request, Messages with content set the file name else if (Lithne.getFunction() == fFileName && !lithneProgrammer.busyProgramming()) { lithneProgrammer.processFileName(); } // reset the main processor else if (Lithne.getFunction() == fResetMain && !lithneProgrammer.busyProgramming()) { lithneProgrammer.resetMain(); } // Kill the main processor for a longer period of time, or turn it back on again else if (Lithne.functionIs("killMain") && !lithneProgrammer.busyProgramming()) { lithneProgrammer.processKill(); } // If the message is not in the 'programming scope' this is a regular incoming Lithne message for the user (main proc) - Forward all bytes to main processor else { for(int i=0; i < Lithne.getXBeePacketSize(); i++) // send data in XBee packet straight through to the main processor { serialCo2MainXbee.write( Lithne.getXBeePacket()[i] ); } serialCo2MainXbee.flush(); } } // forward communication from main processor to xbee if ( !lithneProgrammer.busyProgramming() && serialCo2MainXbee.available() ) { uint8_t byte_to_pass_on = serialCo2MainXbee.read(); Lithne.sendBytePublic(byte_to_pass_on, false); while (serialCo2MainXbee.available()) { byte_to_pass_on = serialCo2MainXbee.read(); Lithne.sendBytePublic(byte_to_pass_on, true); } } lithneProgrammer.preventHangup(); } }
void setup(){ // cli(); // Turn all interrupts off! sei(); // Turn interrupts on. _delay_ms(4000); // Wait for startup! // SPI CS INIT - set all CS lines high! DDR_RFM_CS |= (1 << BIT_RFM_CS); // Set RFM12B CS to output PORT_RFM_CS |= (1 << BIT_RFM_CS); // Pull RFM12B CS high DDR_MEM_SS |= (1 << BIT_MEM_SS); // Set memory CS to output PORT_MEM_SS |= (1 << BIT_MEM_SS); // Pull memory CS high DDR_ETH_SS |= (1 << BIT_ETH_SS); // Set Ethernet CS to output PORT_ETH_SS |= (1 << BIT_ETH_SS); // Pull Ethernet CS high // SPI CS INIT - set all CS lines high! // SET ALL LED TO OUTPUT LED_433RECEIVE_DDR |= (1 << LED_433RECEIVE_BIT); // set output LED_433SEND_DDR |= (1 << LED_433SEND_BIT); // set output LED_868RECEIVE_DDR |= (1 << LED_868RECEIVE_BIT); // set output LED_868SEND_DDR |= (1 << LED_868SEND_BIT); // set output LED_DCF77_DDR |= (1 << LED_DCF77_BIT); // set output LED_LCD_DDR |= (1 << LED_LCD_BIT); // set output // SET ALL LED TO OUTPUT // TEST LEDS blinkAllLeds(true); _delay_ms(1000); blinkAllLeds(false); _delay_ms(500); blinkAllLeds(true); _delay_ms(1000); blinkAllLeds(false); // TEST LEDS /* Initialize UART */ uart_init(UART_BAUD_SELECT(UART_BAUD_RATE,F_CPU)); /* Initialize RFM12B*/ rf12_initialize(NODEID, RF12_868MHZ, NETWORKID); // see http://tools.jeelabs.org/rfm12b rf12_control(0xC040); // set low-battery level to 2.2V i.s.o. 3.1V // Initialize library millis_init(); LED_LCD_PORT |= (1 << LED_LCD_BIT); // set output /* GLCD_IO_PIN_A0_1(); GLCD_IO_PIN_RW_1(); GLCD_IO_PIN_E_1(); GLCD_IO_DATA_DIR_OUTPUT(); GLCD_IO_DATA_OUTPUT(0b11111111); */ //glcd.init(); //glcd.setFont(&proportional_font); //glcd.clearDisplay(); //uint8_t ret = glcd.drawPixel(GLCD_INDICATOR_2, 48, 2); //uart0_putc(ret); //glcd.drawLine(1, 1, 100,100, GLCD_COLOR_FILLED); glcd.init(); glcd.setFont(&proportional_font); glcd.clearDisplay(); log_s("ISA GATEWAY \n\r"); log_s("STARTUP OK! \n\r"); }
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(); }