/** Main program entry point. This routine configures the hardware required by the application, then
 *  starts the scheduler to run the application tasks.
 */
int main(void)
{
	/* Disable watchdog if enabled by bootloader/fuses */
	MCUSR &= ~(1 << WDRF);
	wdt_disable();

	/* Disable clock division */
	clock_prescale_set(clock_div_1);
	
	/* Hardware Initialization */
	SerialStream_Init(9600, false);
	LEDs_Init();
	
	/* Indicate USB not ready */
	UpdateStatus(Status_USBNotReady);
	
	/* Initialize Scheduler so that it can be used */
	Scheduler_Init();

	/* Initialize USB Subsystem */
	USB_Init();

	/* Start-up message */
	puts_P(PSTR(ESC_RESET ESC_BG_WHITE ESC_INVERSE_ON ESC_ERASE_DISPLAY
	       "Mouse Host Demo running.\r\n" ESC_INVERSE_OFF));
		   
	/* Scheduling - routine never returns, so put this last in the main function */
	Scheduler_Start();
}
Beispiel #2
0
int main(void)
{
	SysTick_init();
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);	
	uart_init(115200);
	
	Struct_Init();
	Pid_Init();
	
	MotoPwm_Init();
	
	OLED_Init();
	Key_Init();
	
	I2cMaster_Init();
  mpu_dmp_init();	
	GPIO_Config();
	
	Filter_Init();
	
//	NRF_Usart_Pin_Init();//无线初始化
//	NRF_Read_Live_Init();//无线在线传输	
//  ReadData_Init();
	
	Scheduler_Init();
	
  while(1)
	{
		Scheduler_Loop();
	}
}
Beispiel #3
0
/** Main program entry point. This routine configures the hardware required by the application, then
 *  starts the scheduler to run the application tasks.
 */
int main(void)
{
	/* Disable watchdog if enabled by bootloader/fuses */
	MCUSR &= ~(1 << WDRF);
	wdt_disable();

	/* Disable Clock Division */
	SetSystemClockPrescaler(0);

	/* Hardware Initialization */
	LEDs_Init();
	Dataflash_Init(SPI_SPEED_FCPU_DIV_2);

	/* Clear Dataflash sector protections, if enabled */
	DataflashManager_ResetDataflashProtections();
	
	/* Indicate USB not ready */
	UpdateStatus(Status_USBNotReady);
	
	/* Initialize Scheduler so that it can be used */
	Scheduler_Init();

	/* Initialize USB Subsystem */
	USB_Init();

	/* Scheduling - routine never returns, so put this last in the main function */
	Scheduler_Start();
}
Beispiel #4
0
/** Main program entry point. This routine configures the hardware required by the application, then
 *  starts the scheduler to run the application tasks.
 */
int main(void)
{
	/* Disable watchdog if enabled by bootloader/fuses */
	MCUSR &= ~(1 << WDRF);
	wdt_disable();

	/* Disable clock division */
	clock_prescale_set(clock_div_1);

	/* Hardware Initialization */
	Joystick_Init();
	LEDs_Init();
	Buttons_Init();
	
	/* Millisecond timer initialization, with output compare interrupt enabled for the idle timing */
	OCR0A  = 0x7D;
	TCCR0A = (1 << WGM01);
	TCCR0B = ((1 << CS01) | (1 << CS00));
	TIMSK0 = (1 << OCIE0A);

	/* Indicate USB not ready */
	UpdateStatus(Status_USBNotReady);
	
	/* Initialize Scheduler so that it can be used */
	Scheduler_Init();

	/* Initialize USB Subsystem */
	USB_Init();

	/* Scheduling - routine never returns, so put this last in the main function */
	Scheduler_Start();
}
Beispiel #5
0
int main(void)
{
	uint8_t IOReg = 0;

	/* initialize the board for general non-usb development */
	init_gmd();


	// SPI Mode0 slave with CKDIV = /4 and enable SPI transfer complete interrupt
	// set PB3(MISO) as output, PB0(^SS), PB1(SCK), PB2(MOSI)  as input, and rest as input
	DDRB = (0 << PB0) | (0 << PB1) | (0 << PB2) | (1 << PB3) | (1 << PB4) | (1 << PB5) | (1 << PB6) | (1 << PB7);
	SPCR = ((1 << SPE) | (1 << SPIE) | (0 << MSTR) | (0 << CPOL) | (0 << CPHA));
	SPSR = 0;
	IOReg = SPSR; //need to read to initiliaze
	IOReg = SPDR; //need to read to initiliaze
	SPDR = 0x00; // send 0 over SPI so that the SPI interrupt starts being used
	sei(); // enable interrupts


	/* set PortD as output and start Timer1 */
	DDRD = 0xFF;
	PORTD = 0x00;
	TCCR1A = 0; //start the timer
	//TCCR1B = (1 << CS10); // no Timer1 prescaling, use CLK
	TCCR1B = (1 << CS12); // prescale Timer1 by CLK/256


	/* initialize the scheduler */
	Scheduler_Init();
	Scheduler_Start(); // MCU runs indefinitely, work is done in TASK(MainTask) and interrupts
}
Beispiel #6
0
/** Main program entry point. This routine configures the hardware required by the application, then
 *  starts the scheduler to run the application tasks.
 */
int main(void)
{
	/* Disable watchdog if enabled by bootloader/fuses */
	MCUSR &= ~(1 << WDRF);
	wdt_disable();

	/* Disable clock division */
	clock_prescale_set(clock_div_1);

	/* Hardware Initialization */
	Joystick_Init();
	LEDs_Init();
	Buttons_Init();
	
	/* Indicate USB not ready */
	UpdateStatus(Status_USBNotReady);
	
	/* Initialize Scheduler so that it can be used */
	Scheduler_Init();

	/* Initialize USB Subsystem */
	USB_Init();

	/* Scheduling - routine never returns, so put this last in the main function */
	Scheduler_Start();
}
Beispiel #7
0
/**
 * @brief Setup the RTOS and create main() as the first SYSTEM level task.
 *
 * Point of entry from the C runtime crt0.S.
 */
void OS_Init()
{
    /* Set up the clocks */

    TCCR1B |= (_BV(CS11));
	TCCR5A = 0; // timer5 in normal mode.
	TCCR5B |= (_BV(CS51));

#ifdef SLOW_CLOCK
    kernel_slow_clock();
#endif

    /*
     * Initialize dead pool to contain all but last task descriptor.
     *
     * DEAD == 0, already set in .init4
     */
	initialize_dead_pool_queue();

	/* Create idle "task" */
    kernel_request_create_args.f = (voidfuncvoid_ptr)idle;
    kernel_request_create_args.level = NULL;
    kernel_create_task();

    /* Create "main" task as SYSTEM level. */
    kernel_request_create_args.f = (voidfuncvoid_ptr)r_main;
    kernel_request_create_args.level = SYSTEM;
    kernel_create_task();

    /* First time through. Select "main" task to run first. */
    cur_task = task_desc;
    cur_task->state = RUNNING;
    dequeue(&system_queue);

    /* Set up Timer 1 Output Compare interrupt,the TICK clock. */
    TIMSK1 |= _BV(OCIE1A);
	volatile uint32_t time = TCNT1;
	volatile uint32_t tickstest = TICK_CYCLES;
	volatile uint32_t test = time + tickstest;
	OCR1A = test;
    OCR1A = TCNT1 + TICK_CYCLES;
    /* Clear flag. */
    TIFR1 = _BV(OCF1A);
	
	
	/* Set up the periodic task scheduler */
	Scheduler_Init();
	
    /*
     * The main loop of the RTOS kernel.
     */
    kernel_main_loop();
}
Beispiel #8
0
/**
 * The main function.
 *
 * \return This function does never return.
 *****************************************************************************/
int main(void)
{
    hw_init();
    i2c_init();
    spi_init();
    cbf_init(&rx_buf);
    cbf_init(&tx_buf);

    // Indicate USB not ready
    UpdateStatus(Status_USBNotReady);

    // Initialize Scheduler so that it can be used
    Scheduler_Init();

    // Initialize USB Subsystem
    USB_Init();

    // Scheduling - routine never returns, so put this last in the main function
    Scheduler_Start();
}
Beispiel #9
0
/** Main program entry point. This routine configures the hardware required by the application, then
 *  starts the scheduler to run the USB management task.
 */
int main(void)
{
  /* After reset start bootloader? */
  if ((AVR_IS_WDT_RESET()) && (boot_key == DFU_BOOT_KEY_VAL))
    {
      boot_key = 0;
      Bootloader();
    }

  /* Disable watchdog if enabled by bootloader/fuses */
  MCUSR &= ~(1 << WDRF);
  wdt_disable();

  /* Disable clock division */
  clock_prescale_set(clock_div_1);

  /* Hardware Initialization */
  LEDs_Init();

  /* Indicate USB not ready */
  UpdateStatus(Status_USBNotReady);

  /* Initialize Scheduler so that it can be used */
  Scheduler_Init();

  /* Initialize USB Subsystem */
  USB_Init();

  /* Initialize I/O lines */
  //IO_Init();

  /* Initialize Timers */
  Timer_Init();

  /* Initialize Motors */
  Motor_Init();

  /* Scheduling - routine never returns, so put this last in the main function */
  Scheduler_Start();
}
Beispiel #10
0
int main(void)
{
    /* Disable watchdog if enabled by bootloader/fuses */
    MCUSR &= ~(1 << WDRF);
    wdt_disable();

    /* Disable clock division */
    clock_prescale_set(clock_div_1);

    /* Hardware Initialization */

    DDRB = 0xFF;
    DDRD = 0xFF;
    DDRC = 0xF0;

    /* Initialize Scheduler so that it can be used */
    Scheduler_Init();

    /* Initialize USB Subsystem */
    USB_Init();

    /* Scheduling - routine never returns, so put this last in the main function */
    Scheduler_Start();
}
Beispiel #11
0
/*******************************************************************************//**
 * @implements InitComponents
 **********************************************************************************/
RESULT InitComponents(void)
{
	// init guard
	if(Guard_Init()==FAIL)
		return FAIL;
	
	// init utils
	if(Utils_Init()==FAIL)
		return FAIL;
	
	// init MCU
	if(MCU_Init()==FAIL)
		return FAIL;
	
	// init scheduler
	if(Scheduler_Init()==FAIL)
		return FAIL;
	
	// init power management system
	#ifdef USE_PWR
	if(PWR_Init()==FAIL)
		return FAIL;
	#endif
	
	// init timers
	#ifdef USE_TIMERS
	if(Timers_Init()==FAIL)
		return FAIL;
	#endif
	
	// init LEDs
	#ifdef USE_LEDS
	if(LEDs_Init()==FAIL)
		return FAIL;
	#endif
	
	// init buttons
	#ifdef USE_BUTTONS
	if(Buttons_Init()==FAIL)
		return FAIL;
	#endif
	
	// init UART
	#ifdef USE_UART
	if(UART_Init()==FAIL)
		return FAIL;
	#endif
	
	// init SPI
	#ifdef USE_SPI
	if(SPI_Init()==FAIL)
		return FAIL;
	#endif
	
	// init TWI
	#ifdef USE_TWI
	if(TWI_Init()==FAIL)
		return FAIL;
	#endif
	
	// init OWI
	#ifdef USE_OWI
	if(OWI_Init()==FAIL)
		return FAIL;
	#endif
	
	// init other components
	if(InitOther()==FAIL)
		return FAIL;
	
	// init sensors
	#ifdef USE_SENSORS
	if(Sensors_Init()==FAIL)
		return FAIL;
	#endif
	
	// init NWK
	#ifdef USE_NWK
	if(NWKLayer_Init()==FAIL)
		return FAIL;
	#endif
	
	// return success
	return SUCCESS;
}
Beispiel #12
0
int32_t main(void)
{
	uint32_t u32Index;
	uint8_t mac_def[6];
	uip_ipaddr_t ipaddr;
	struct timer periodic_timer, arp_timer;
	volatile int32_t ax88796c_isr;
	
	Board_Init();
	Uart4_Init();
	_delay_init();
	// Setup scheduler and tasks
	Scheduler_Init();
	Scheduler_AddTask(Task_SetLEDs, 0, 100);
	Scheduler_AddTask(Task_ProcessSwitches, 0, 50);
	Scheduler_AddTask(Task_Adconverter, 500, 100);
	Scheduler_AddTask(Task_SerialTerminalOutput, 0, 1000);

	Scheduler_Start();

	// Configure uIP
	timer_set(&periodic_timer, CLOCK_SECOND / 2);
	timer_set(&arp_timer, CLOCK_SECOND * 10);
	
	mac_def[0] = UIP_ETHADDR0;
	mac_def[1] = UIP_ETHADDR1;
	mac_def[2] = UIP_ETHADDR2;
	mac_def[3] = UIP_ETHADDR3;
	mac_def[4] = UIP_ETHADDR4;
	mac_def[5] = UIP_ETHADDR5;
	
	ax88796c_init(mac_def);
	uip_init();

	init_uip_clock_time();
	
	uip_ipaddr(ipaddr, UIP_IPADDR0,UIP_IPADDR1,UIP_IPADDR2,UIP_IPADDR3);
	uip_sethostaddr(ipaddr);
	
	uip_ipaddr(ipaddr, UIP_DRIPADDR0,UIP_DRIPADDR1,UIP_DRIPADDR2,UIP_DRIPADDR3);
	uip_setdraddr(ipaddr);
	
	uip_ipaddr(ipaddr, UIP_NETMASK0,UIP_NETMASK1,UIP_NETMASK2,UIP_NETMASK3);
	uip_setnetmask(ipaddr);
	
	httpd_init();
	
	/* hello_world_init(); */
    /* telnetd_init(); */
	
	/*{
		dhcpc_init(&mac_def, 6);
	}*/
  
	/*
	uip_ipaddr(ipaddr, 127,0,0,1);
	smtp_configure("localhost", ipaddr);
	SMTP_SEND("*****@*****.**", "", "*****@*****.**", 
		"Testing SMTP from uIP", 
		"Test message sent by uIP\r\n");
	*/

	/*
    webclient_init();
    resolv_init();
    uip_ipaddr(ipaddr, 168,95,1,1);
    resolv_conf(ipaddr);
    resolv_query("www.sics.se");
	*/
	
	while(1){
		Scheduler_DispatchTasks();
		
		ax88796c_isr = ax88796c_check_int();
		if(ax88796c_isr & ISR_LINK){
			if(!ax88796c_check_media()){
				printf ("Link down.\n");
			}else{
				uint16_t bmcr;
				bmcr = ax88796c_mdio_read(PHY_ID, MII_BMCR);
				printf("Link up, %sMbps, %s-duplex\n",(bmcr & BMCR_SPEED100) ? "100" : "10", \
				(bmcr & BMCR_FULLDPLX) ? "full" : "half");
				
			}
		}
		if(ax88796c_isr & ISR_RXPCT){
			uip_len = ax88796c_packet_receive(uip_buf);
		}else{
			uip_len = 0;
		}
		ax88796c_clear_int(ax88796c_isr);
		
		if(uip_len > 0) {
			if(UipBuf->type == htons(UIP_ETHTYPE_IP)) {
				uip_arp_ipin();
				uip_input();
				/* If the above function invocation resulted in data that
				should be sent out on the network, the global variable
				uip_len is set to a value > 0. */
				if(uip_len > 0) {
					uip_arp_out();
					ax88796c_packet_send(uip_buf,uip_len);
				}
			} else if(UipBuf->type == htons(UIP_ETHTYPE_ARP)) {
				uip_arp_arpin();
				/* If the above function invocation resulted in data that
				should be sent out on the network, the global variable
				uip_len is set to a value > 0. */
				if(uip_len > 0) {
					ax88796c_packet_send(uip_buf,uip_len);
				}
			}

		} else if(timer_expired(&periodic_timer)) {
			timer_reset(&periodic_timer);
			for(u32Index = 0; u32Index < UIP_CONNS; u32Index++) {
				uip_periodic(u32Index);
				/* If the above function invocation resulted in data that
				should be sent out on the network, the global variable
				uip_len is set to a value > 0. */
				if(uip_len > 0) {
					uip_arp_out();
					ax88796c_packet_send(uip_buf,uip_len);
				}
			}

#if UIP_UDP
			for(u32Index = 0; u32Index < UIP_UDP_CONNS; u32Index++) {
				uip_udp_periodic(u32Index);
				/* If the above function invocation resulted in data that
				should be sent out on the network, the global variable
				uip_len is set to a value > 0. */
				if(uip_len > 0) {
					uip_arp_out();
					ax88796c_packet_send(uip_buf,uip_len);
				}
			}
#endif /* UIP_UDP */

			/* Call the ARP timer function every 10 seconds. */
			if(timer_expired(&arp_timer)) {
				timer_reset(&arp_timer);
				uip_arp_timer();
			}
		}
	}
}