Exemple #1
0
/**
 *  \brief SAM-BA Main loop.
 *  \return Unused (ANSI-C compatibility).
 */
int main(void)
{

	DEBUG_PIN_HIGH;

	/* Jump in application if condition is satisfied */
	check_start_application();

	/* We have determined we should stay in the monitor. */
	/* System initialization */
	system_init();

	/* UART is enabled in all cases */
	usart_open();

	DEBUG_PIN_LOW;
	/* Wait for a complete enum on usb or a '#' char on serial line */
	while (1) {
		/* Check if a '#' has been received */
		if (usart_sharp_received()) {
			sam_ba_monitor_init(SAM_BA_INTERFACE_USART);
			/* SAM-BA on UART loop */
			while(1) {
				sam_ba_monitor_run();
			}
		}
	}
}
Exemple #2
0
/**
 *  \brief SAMD21 SAM-BA Main loop.
 *  \return Unused (ANSI-C compatibility).
 */
int main(void)
{
#if SAM_BA_INTERFACE == SAM_BA_USBCDC_ONLY  ||  SAM_BA_INTERFACE == SAM_BA_BOTH_INTERFACES 
	P_USB_CDC pCdc;
#endif
	DEBUG_PIN_HIGH;

	/* Jump in application if condition is satisfied */
	check_start_application();

	/* We have determined we should stay in the monitor. */
	/* System initialization */
	system_init();
	cpu_irq_enable();

	#if SAM_BA_INTERFACE == SAM_BA_UART_ONLY  ||  SAM_BA_INTERFACE == SAM_BA_BOTH_INTERFACES
	/* UART is enabled in all cases */
	usart_open();
#endif

#if SAM_BA_INTERFACE == SAM_BA_USBCDC_ONLY  ||  SAM_BA_INTERFACE == SAM_BA_BOTH_INTERFACES
	pCdc = (P_USB_CDC)usb_init();
#endif
	DEBUG_PIN_LOW;

	// output on D13 (PA.17)
	LED_PORT.PINCFG[LED_PIN].reg &= ~ (uint8_t)(PORT_PINCFG_INEN);
	LED_PORT.DIRSET.reg = (uint32_t)(1 << LED_PIN);

	/* Wait for a complete enum on usb or a '#' char on serial line */
	while (1) {
   	        pulse_led(1); // while we're waiting, blink the D13 

#if SAM_BA_INTERFACE == SAM_BA_USBCDC_ONLY  ||  SAM_BA_INTERFACE == SAM_BA_BOTH_INTERFACES
		if (pCdc->IsConfigured(pCdc) != 0) {
			main_b_cdc_enable = true;
		}

		//Check if a USB enumeration has succeeded
		//And com port was opened
		if (main_b_cdc_enable) {
			sam_ba_monitor_init(SAM_BA_INTERFACE_USBCDC);
			//SAM-BA on USB loop
			while(1) {
				sam_ba_monitor_run();
			}
		}
#endif
#if SAM_BA_INTERFACE == SAM_BA_UART_ONLY  ||  SAM_BA_INTERFACE == SAM_BA_BOTH_INTERFACES
		/* Check if a '#' has been received */
		if (!main_b_cdc_enable && usart_sharp_received()) {
			sam_ba_monitor_init(SAM_BA_INTERFACE_USART);
			/* SAM-BA on UART loop */
			while(1) {
				sam_ba_monitor_run();
			}
		}
#endif
	}
}
/**
 *  \brief SAMD20 SAM-BA Main loop.
 *  \return Unused (ANSI-C compatibility).
 */
int main(void)
{
  
#if DEBUG_ENABLE
        /* Set BOOT_LED pin as output */
        PORT->Group[0].DIRSET.reg=(1u<<BOOT_LED);
#endif
	DEBUG_PIN_HIGH;
        
	/* Jump in application if condition is satisfied */
	check_start_application();
        
        /* Make OSC8M prescalar to zero rather divide by 8 */
        SYSCTRL->OSC8M.bit.PRESC = 0;

	/* UART is enabled in all cases */
	usart_open();

	/* Wait for a complete enum on usb or a '#' char on serial line */
	while (1) {
		/* Check if a '#' has been received */
		if (usart_sharp_received()) {
                        DEBUG_PIN_LOW;
			sam_ba_monitor_init(SAM_BA_INTERFACE_USART);
			/* SAM-BA on UART loop */
			while(1) {
				sam_ba_monitor_run();
			}
		}
	}
}
Exemple #4
0
int lambda_init(void)
{
	uint8_t i;

	for(i=0;i<128;i++)  O2Mem.Mem[i] = 0;
  
  sprintf(O2Mem.cur_value, "XXX");
  // USART �ffnen
  if((lambda_fd = usart_open( "/dev/ttyAMA0",115200)) == -1)
    return -1;
  
  // Einstellungen senden
  usart_puts(lambda_fd, NORMAL_MODE);
  usart_puts(lambda_fd, LOW_COMMUNICATION);
  usart_puts(lambda_fd, CSVTEXT_MODE);
  
  usart_flush(lambda_fd);
  
  is_Init = true;
}
Exemple #5
0
/**
 *  \brief SAMD21 WINO SAM-BA Main loop.
 *  \return Unused (ANSI-C compatibility).
 */
int main(void)
{
	/* Save the value of the boot key memory before it is overwritten */
	uint32_t bootKeyPtrVal = *bootKeyPtr;
	*bootKeyPtr = 0;
  
	P_USB_CDC pCdc;

	DEBUG_PIN_HIGH;

	volatile PortGroup *esp8266_port = (volatile PortGroup *)(&(PORT->Group[ESP8266_CH_PD_PIN / 32]));

	/* Enable the ouput on the ESP8266 power down Pin and drive it to low */
	esp8266_port->DIRSET.reg = ESP8266_CH_PD_PIN_MASK;
	esp8266_port->PINCFG[ESP8266_CH_PD_PIN & 0x1F].reg = PORT_PINCFG_INEN;
	esp8266_port->OUTCLR.reg = ESP8266_CH_PD_PIN_MASK;

	/* Enable the ouput on the LED Pin and drive it to high */
	PORT->Group[LED_PORT].DIRSET.reg = LED_PIN_MASK;
	LED_ON;

	/* System initialization */
	system_init();
	cpu_irq_enable();
	usart_open();
	pCdc = (P_USB_CDC)usb_init();
  
	DEBUG_USART_OPEN;
  
	/* Pointer to store application start address */
	uint32_t *data_ptr = (uint32_t *)0x20000000;
	
	/* Store the application start address @0x20000000 */
	*data_ptr = APP_START_ADDRESS;

	/* Jump in application if condition is satisfied */
	static uint32_t app_start_address;

	/* Load the Reset Handler address of the application */
	app_start_address = *(uint32_t *)(APP_START_ADDRESS + 4);
	
	int waiting = WAIT_SHORT;
	int elapsed;

	/* Test reset vector of application @APP_START_ADDRESS+4
	 * If *(APP_START+0x4) == 0xFFFFFFFF then set waiting
	 * Application erased condition
	 */
	if (app_start_address == 0xFFFFFFFF)
	{
		waiting = -1;
	}
	else if (bootKeyPtrVal == bootKey)
	{
		waiting = WAIT_LONG;
	}
  
	DEBUG_PIN_LOW;
  
	*bootKeyPtr = bootKey;
  
	/* Wait for a complete enum on usb or a '#' char on serial line.
	 * If there is no user application in the device's memory,
	 * this loop will not end, in the other case, it will wait until timeout.
	 */
	while (waiting)
	{
		if (pCdc->IsConfigured(pCdc))
		{
			sam_ba_monitor_init(SAM_BA_INTERFACE_USBCDC);
			main_b_cdc_enable = true;
			break;
		}
		
		if (usart_sharp_received())
		{
			sam_ba_monitor_init(SAM_BA_INTERFACE_USART);
			break;
		}
		
		if (PORT->Group[LED_PORT].OUT.reg == LED_PIN_MASK)
		{
			if (elapsed > 3000)
			{
				LED_OFF;
				elapsed = 0;
			}
		}
		else
		{
			if (elapsed > 30000)
			{
				LED_ON;
				elapsed = 0;
			}
		}
		
		if (waiting > 0)
			waiting--;
			
		elapsed++;
	}

	*bootKeyPtr = 0;
	while (waiting)
	{
		uint32_t tmp = do_sam_ba_monitor();

		if (PORT->Group[LED_PORT].OUT.reg == LED_PIN_MASK)
		{
			if (elapsed > (1 ? 5000 : 1))
			{
				LED_OFF;
				elapsed = 0;
			}
		}
		else
		{
			if (elapsed > (1 ? 50000 : 2))
			{
				LED_ON;
				elapsed = 0;
			}
		}
   
		if (waiting > 0)
		{
			/* If there is no activity, decrement timeout */
			/* Else set WAIT_SHORT timeout */
			if (tmp == 0)
				waiting--;
			else
				waiting = WAIT_SHORT;
		}
		
		elapsed++;
	}
	
	/* Reset LED pin */
	LED_OFF;
	PORT->Group[LED_PORT].DIRCLR.reg = LED_PIN_MASK;
  
	usart_close();
	usb_deinit();
	
	// reset clocks
	
	//SYSCTRL->OSC8M.reg = SYSCTRL_OSC8M_RESETVALUE;
	//SYSCTRL->OSC32K.reg = SYSCTRL_OSC32K_RESETVALUE;
	//SYSCTRL->XOSC32K.reg = SYSCTRL_XOSC32K_RESETVALUE;
	//SYSCTRL->DFLLCTRL.reg = SYSCTRL_DFLLCTRL_RESETVALUE;
	//SYSCTRL->DFLLMUL.reg = SYSCTRL_DFLLMUL_RESETVALUE;
	//SYSCTRL->DFLLVAL.reg = SYSCTRL_DFLLVAL_RESETVALUE;
	
	/* Jump to the application */
  
	/* Rebase the Stack Pointer */
	__set_MSP(*(uint32_t *) APP_START_ADDRESS);

	/* Rebase the vector table base address */
	SCB->VTOR = ((uint32_t) APP_START_ADDRESS & SCB_VTOR_TBLOFF_Msk);

	/* Jump to application Reset Handler in the application */
	asm("bx %0"::"r"(app_start_address));
}
Exemple #6
0
void init_sumo ( void )
{
    OSCCONbits.IRCF = 7;                // Set internal clock to 16 Mhz

    ANSELHbits.ANS11 = 0;               // Make RX digital

    // 115200,8,n,1: 138 - 64MHz
    // 19200,8,n,1: 832 - 64MHz; 207 - 16MHz
    // 9600,8,n,1: 129 - 20 MHz; 1249 - 48MHz; 1666 - 64MHz
    usart_open(USART_TX_INT_OFF &       // disable TX interrupt
               USART_RX_INT_ON &        // enable RX interrupt
               USART_BRGH_HIGH &        // Use High BRGH
               USART_CONT_RX &          // Receive continuous data
               USART_EIGHT_BIT &        // Use 8 bit
               USART_ASYNCH_MODE,       // Use Asynchronous mode
               207);                    // 19200 for 16 Mhz
    #if defined (__SDCC)
    stdout = STREAM_USART;              // Set stdout to serial stream
    #else
    baudUSART(BAUD_16_BIT_RATE &
              BAUD_IDLE_CLK_LOW &
              BAUD_WAKEUP_OFF &
              BAUD_AUTO_OFF & 0x48); // 16 bit BRG
    #endif

    #if defined (__SDCC)
    adc_open(ADC_CHN_0,                 // Set channel 0
             ADC_FOSC_16 | ADC_ACQT_8,  // Configure Acquisition frequency
             ADC_CFG_7A,                // Set the number of channels to use
             ADC_FRM_RJUST |            // Adjust result to the right
             ADC_INT_OFF |              // Disable interrupts
             ADC_VCFG_VDD_VSS |         // Configure reference voltages
             ADC_NVCFG_VSS |            // Negative reference to VSS
             ADC_PVCFG_VDD);            // Positive reference to VDD
    #else
    OpenADC(ADC_RIGHT_JUST & ADC_FOSC_16 & ADC_8_TAD,
            ADC_CH0 & ADC_INT_OFF,
            ADC_REF_VDD_VDD & ADC_REF_VDD_VSS,
            0b0000111111110000);
    #endif

    T0CONbits.T08BIT = 0;               // 16 bit mode
    T0CONbits.T0CS = 0;                 // Source is internal
    T0CONbits.PSA = 1;                  // Disable prescaler
    T0CONbits.T0PS = 7;                 // Prescaler to 1:256
    TMR0H = 0; TMR0L = 0;               // Reset Timer0 to 0x0000
    INTCONbits.TMR0IF = 0;              // Clear interrupt flag
    INTCONbits.TMR0IE = 1;              // Enable Interruption from timer0
    T0CONbits.TMR0ON = 1;               // Start timer0

    write_timer_0(Ticks4NextInterrupt);

    Servo.FL = 1;
    Servo.FR = 1;
    Servo.BL = 1;
    Servo.BR = 1;

    FL_SERVO_TRIS = 0;
    FR_SERVO_TRIS = 0;
    BL_SERVO_TRIS = 0;
    BR_SERVO_TRIS = 0;

    RCONbits.IPEN = 0;                  // Interruption Priority Disabled
    INTCONbits.PEIE = 1;                // Peripheral Interrupt Enabled
    INTCONbits.GIE = 1;                 // Global Interrupt Enable
}