示例#1
0
void main_full( void )
{
TimerHandle_t xTimer = NULL;

	/* Start all the standard demo/test tasks.  These have not particular
	functionality, but do demonstrate how to use the FreeRTOS API, and test the
	kernel port. */
	vStartIntegerMathTasks( tskIDLE_PRIORITY );
	vStartDynamicPriorityTasks();
	vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
	vCreateBlockTimeTasks();
	vStartCountingSemaphoreTasks();
	vStartGenericQueueTasks( tskIDLE_PRIORITY );
	vStartRecursiveMutexTasks();
	vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
	vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
	vStartMathTasks( mainFLOP_TASK_PRIORITY );
	vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );

	/* Create the register test tasks, as described at the top of this file. */
	xTaskCreate( vRegTestTask1, "Reg1...", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
	xTaskCreate( vRegTestTask2, "Reg2...", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );


	/* Create the software timer that performs the 'check' functionality,
	as described at the top of this file. */
	xTimer = xTimerCreate( "CheckTimer",					/* A text name, purely to help debugging. */
							( mainCHECK_TIMER_PERIOD_MS ),	/* The timer period, in this case 3000ms (3s). */
							pdTRUE,							/* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */
							( void * ) 0,					/* The ID is not used, so can be set to anything. */
							prvCheckTimerCallback			/* The callback function that inspects the status of all the other tasks. */
						 );

	if( xTimer != NULL )
	{
		xTimerStart( xTimer, mainDONT_BLOCK );
	}

	/* Create the software timer that performs the 'LED spin' functionality,
	as described at the top of this file. */
	xTimer = xTimerCreate( "LEDTimer",					/* A text name, purely to help debugging. */
							( mainLED_TIMER_PERIOD_MS ),/* The timer period, in this case 75ms. */
							pdTRUE,						/* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */
							( void * ) 0,				/* The ID is not used, so can be set to anything. */
							prvLEDTimerCallback			/* The callback function that toggles the white LEDs. */
						 );

	if( xTimer != NULL )
	{
		xTimerStart( xTimer, mainDONT_BLOCK );
	}

	/* The set of tasks created by the following function call have to be
	created last as they keep account of the number of tasks they expect to see
	running. */
	vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );

	/* Start the scheduler. */
	vTaskStartScheduler();

	/* If all is well, the scheduler will now be running, and the following line
	will never be reached.  If the following line does execute, then there was
	insufficient FreeRTOS heap memory available for the idle and/or timer tasks
	to be created.  See the memory management section on the FreeRTOS web site
	for more details. */
	for( ;; );
}
示例#2
0
文件: main.c 项目: eeshanl/ee472
int main() {

  // Initializes all necessary hardware for the system.
  InitializeHardware();


  /**************************************/
  // These includes provided by FreeRTOS

  #if mainINCLUDE_WEB_SERVER != 0
  {
    /*
    Create the uIP task if running on a processor that includes a MAC and PHY.
    */

    if( SysCtlPeripheralPresent( SYSCTL_PERIPH_ETH ) )
    {
      xTaskCreate( vuIP_Task, ( signed portCHAR * ) "uIP", mainBASIC_WEB_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY - 1, NULL );
    }
  }
  #endif



  // These includes provided by FreeRTOS
  /**************************************/


  /* Our Tasks
   * NOTE: The xTaskCreate function is provided by FreeRTOS, we use them to create our tasks that we made.
   */

  /* Start the tasks */

  //creates the task for ADC sensors
  xTaskCreate(vTaskADC, "Task ADC", 100, NULL, 2, NULL);
  //creates the task that averages the ADC samples
  xTaskCreate(vTaskADCAverage, "Task Average", 100, NULL, 2, NULL);
  //creates the task that controls the motor via kepad/bluetooth
  xTaskCreate(vTaskControlMotor, "Task Control Motor", 100, NULL, 2, NULL); //3
  //creates the task that does the autonomous motion of the tank
  xTaskCreate(vAutoMotor, "Task Auto Motor", 100, NULL, 3, NULL); // 5
  //creates the task that controls the semi-autonomous mode for the tank
  xTaskCreate(vSemiMotor, "Task Semi-Motor", 100, NULL, 3, NULL); // 5
  //creates the task that controls the speaker
  xTaskCreate(vTaskSpeaker, "Task Control Motor", 100, NULL, 1, NULL);
  //creates the task the displays to the OLED Display
  xTaskCreate(vTaskDisplay, "Task OLED Display", 100, NULL, 3, NULL); // 4
  //creates the task that prints the distance from the distance sensors on the
  //OLED Display
  xTaskCreate(vPrintDistance, "Task Distance Please", 100, NULL, 2, NULL);
  // blinks LEDS
  xTaskCreate(vBlinkLED, "Blink", 100, NULL, 2, NULL);


  /**************************************/
  // These includes provided by FreeRTOS

  /*
  Configure the high frequency interrupt used to measure the interrupt
  jitter time.
  */

  vSetupHighFrequencyTimer();

  /*
  Start the scheduler.
  */

  vTaskStartScheduler();

  /* Will only get here if there was insufficient memory to create the idle task. */

  // These includes provided by FreeRTOS
  /**************************************/

  return 0;
}
/**
 * Program entry point 
 */
int main(void) {
    setupHardware();
 
    /* 
     * Start the tasks defined within this file/specific to this demo. 
     */
    xTaskCreate( vUserTask1, ( signed portCHAR * ) "Task1", USERTASK_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
    xTaskCreate( vUserTask2, ( signed portCHAR * ) "Task2", USERTASK_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
    xTaskCreate( working_task, ( signed portCHAR * ) "Task3", USERTASK_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
    xTaskCreate( vUserTask4, ( signed portCHAR * ) "Task4", USERTASK_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
    xTaskCreate( spi_task, ( signed portCHAR * ) "Task5", USERTASK_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
    xTaskCreate( protocol_task_runner, ( signed portCHAR * ) "Task6", USERTASK_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
    xTaskCreate( motor_task, ( signed portCHAR * ) "Task7", USERTASK_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
    xTaskCreate( uart0_receive_task_runner, ( signed portCHAR * ) "Task8", USERTASK_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
    xTaskCreate( regulation_task_runner, ( signed portCHAR * ) "Task8", USERTASK_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
    xTaskCreate( joystick_task_runner, ( signed portCHAR * ) "Joystick", USERTASK_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );

     
    /* 
     * Setup semaphores.
     */
    lcd_buffer_mutex = xSemaphoreCreateMutex();
    if ( lcd_buffer_mutex == NULL )
    {
        led_red_on();
        while(1);
    }
     
    lcd_keyboard_port_mutex = xSemaphoreCreateMutex();
    if ( lcd_keyboard_port_mutex == NULL )
    {
        led_red_on();
        while(1);
    }
     
    motor_one_speed_mutex = xSemaphoreCreateMutex();
    if ( motor_one_speed_mutex == NULL )
    {
        led_red_on();
        while(1);
    }
     
    motor_two_speed_mutex = xSemaphoreCreateMutex();
    if ( motor_two_speed_mutex == NULL )
    {
        led_red_on();
        while(1);
    }
     
    motor_one_direction_mutex = xSemaphoreCreateMutex();
    if ( motor_one_direction_mutex == NULL )
    {
        led_red_on();
        while(1);
    }
     
    motor_two_direction_mutex = xSemaphoreCreateMutex();
    if ( motor_two_direction_mutex == NULL )
    {
        led_red_on();
        while(1);
    }
     
    motor_one_position_mutex = xSemaphoreCreateMutex();
    if ( motor_one_position_mutex == NULL )
    {
        led_red_on();
        while(1);
    }
     
    motor_two_position_mutex = xSemaphoreCreateMutex();
    if ( motor_two_position_mutex == NULL )
    {
        led_red_on();
        while(1);
    }

	y_pos_mutex = xSemaphoreCreateMutex();
    if ( y_pos_mutex == NULL )
    {
        led_red_on();
        while(1);
    }

	x_pos_mutex = xSemaphoreCreateMutex();
    if ( x_pos_mutex == NULL )
    {
        led_red_on();
        while(1);
    }

	y_target_pos_mutex = xSemaphoreCreateMutex();
    if ( y_target_pos_mutex == NULL )
    {
        led_red_on();
        while(1);
    }

	x_target_pos_mutex = xSemaphoreCreateMutex();
    if ( x_target_pos_mutex == NULL )
    {
        led_red_on();
        while(1);
    }
     
    /* 
     * Setup queues.
     */
    motor_command_queue = xQueueCreate(16, sizeof( motor_command ) );
    if (motor_command_queue == NULL)
    {
        led_red_on();
        while(1);
    }
         
    motor_event_queue = xQueueCreate(16, sizeof( motor_event ) );
    if (motor_event_queue == NULL)
    {
        led_red_on();
        while(1);
    }
     
    spi_input_queue = xQueueCreate(16, sizeof( INT16U ) );
    if (spi_input_queue == NULL)
    {
        led_red_on();
        while(1);
    }
     
    spi_output_queue = xQueueCreate(16, sizeof( INT16U ) );
    if (spi_output_queue == NULL)
    {
        led_red_on();
        while(1);
    }
     
    ui_event_queue = xQueueCreate(16, sizeof( ui_event ) );
    if (ui_event_queue == NULL)
    {
        led_red_on();
        while(1);
    }
 
    uart_command_queue = xQueueCreate(16, sizeof( uart_command ) );
    if (uart_command_queue == NULL)
    {
        led_red_on();
        while(1);
    }
     
    /* 
     * Start the scheduler. 
     */
    vTaskStartScheduler();
 
    /* 
     * Will only get here if there was insufficient memory to create the idle task. 
     */
    return 1;
}
示例#4
0
int main(void)
{
	init();
	setup();
	/*while(1){
	compass.read();
	float heading = compass.heading();
	dprintf("%d",(int) heading);
	delay(1000);
	}*/
	
	
	//pinMode(12,OUTPUT);
	//pinMode(13,OUTPUT);
	TaskHandle_t t1,t2,t3,t4;

	/*while(1){
		//gyro
		gyro.read();
		//acc
		compass.read();
		//sonar
		unsigned int uS = sonar.ping(); // Send ping, get ping time in microseconds (uS).
		int sonar_reading = (int)sonar.convert_cm(uS);
		//baro
		float pressure = ps.readPressureMillibars();
		//dprintf("raw pressure is %d",(int) ((float)ps.readPressureRaw()/ 4096));
		float altitude = ps.pressureToAltitudeMeters(pressure);
		float temperature = ps.readTemperatureC();
		
		
		//ir
		sensorValue = analogRead(sensorIR);
		//inches = 4192.936 * pow(sensorValue,-0.935) - 3.937;
		cm = 10650.08 * pow(sensorValue,-0.935) - 10;
		
		char key = keypad.getKey();

		//print out the key that is pressed
		if (key != NO_KEY){
			dprintf("%c",key);
		}
	}*/
		
	
	//Create tasks
	//xTaskCreate(task1, "Task 1", STACK_DEPTH, NULL, 6, &t1);
	//xTaskCreate(task2, "Task 2", STACK_DEPTH, NULL, 5, &t2);
	//xTaskCreate(printArray, "Task Gyro", STACK_DEPTH,NULL,0,&t1);
	//xTaskCreate(task_sonar1,"task sornar",STACK_DEPTH,NULL,5,&t2);
	
	//xTaskCreate(task_ir,"Task Accelerometer", STACK_DEPTH, NULL,6,&t2);
	
	//xTaskCreate(task_poll_sensor,"Task_sensor",STACK_DEPTH,NULL,5,&t1);
	

	//xTaskCreate(task_accelerometer, "Task acc", STACK_DEPTH,NULL,5,&t1);
	//xTaskCreate(task_poll_sonar,"task_poll_sensor",STACK_DEPTH,NULL,6,&t2);
	//xTaskCreate(task_gyro, "Task gyro", STACK_DEPTH,NULL,7,&t3);
	//xTaskCreate(task_baro, "Task Gyro", STACK_DEPTH,NULL,8,&t4);
	//xTaskCreate(task_keypad, "Task acc", STACK_DEPTH,NULL,9,&t5);
	//xTaskCreate(task_comm,"task comm",STACK_DEPTH,NULL,6,&t6);
	//xTaskCreate(printArray,"task comm",STACK_DEPTH,NULL,7,&t6);
	
	//xTaskCreate(task_headingNdist, "Task_heading",256,NULL,5,&t1);
	xTaskCreate(task_poll_sonar,"task poll sensor", 256,NULL,7,&t2);
	//xTaskCreate(task_keypad,"task keypad",STACK_DEPTH,NULL,6,&t3);
	//xTaskCreate(task_comm,"task comm",STACK_DEPTH,NULL,5,&t4);
	//dprintf("%d size",uxTaskGetStackHighWaterMark(t1));
	//dprintf("%d",(int)&task_gyro);
	//dprintf("%d",(int)&task_keypad);
	//dprintf("%d_ar",(int)&printArray);
	
	//xTaskCreate(task_sensor_poll,"Task_sensor",STACK_DEPTH,NULL,5,&t1);
	
	vTaskStartScheduler();
}
//*****************************************************************************
//
// Initialize FreeRTOS and start the initial set of tasks.
//
//*****************************************************************************
int
main(void)
{
    //
    // Set the clocking to run at 50 MHz from the PLL.
    //
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |
                       SYSCTL_OSC_MAIN);

    //
    // Initialize the UART and configure it for 115,200, 8-N-1 operation.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    GPIOPinConfigure(GPIO_PB0_U1RX);
    GPIOPinConfigure(GPIO_PB1_U1TX);
    ROM_GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    UARTStdioInit(1);

    //
    // Print demo introduction.
    //
    //UARTprintf("\n\nWelcome to the Stellaris EK-LM4F120 FreeRTOS Demo!\n");

    //
    // Create a mutex to guard the UART.
    //
    //g_pUARTSemaphore = xSemaphoreCreateMutex();

//#######i2c test############
    /*
        unsigned long ulClockValue = ROM_SysCtlClockGet();
        unsigned char i2creturn,i2ctemp = 0;

        i2c0Init(ulClockValue);
        i2creturn = i2c0ReadReg((unsigned char)0x53, (unsigned char) 0x00, &i2ctemp);

        UARTprintf("\r\n\r\nI2C read value = %d, return value = %d", i2ctemp, i2creturn);

        while (1);

    */
//################
    /*
    unsigned long baseaddr0 = 0x40020000;
    unsigned long temp = 0;
    I2CSetup(baseaddr0, 100000);
    temp = I2CRegRead(baseaddr0, 0x53, 0x00);
    UARTprintf("\r\n\r\nI2C read value = %d\r\n", temp);
    while (1);

    */

    //
    // Create the LED task.



    //
    if(AccelerometerTaskInit() != 0)
    {

        while(1)
        {
        }
    }

    //
    // Create the switch task.
    //
    if(BluetoothTaskInit() != 0)
    {

        while(1)
        {
        }
    }

    //
    // Start the scheduler.  This should not return.
    //
    vTaskStartScheduler();

    //
    // In case the scheduler returns for some reason, print an error and loop
    // forever.
    //

    while(1)
    {
    }
}
示例#6
0
void main_full( void )
{
TimerHandle_t xCheckTimer = NULL;
/* The register test tasks are asm functions that don't use a stack.  The
stack allocated just has to be large enough to hold the task context, and
for the additional required for the stack overflow checking to work (if
configured). */
const size_t xRegTestStackSize = 25U;

	/* Create the standard demo tasks, including the interrupt nesting test
	tasks. */
	vStartInterruptQueueTasks();
	vCreateBlockTimeTasks();
	vStartCountingSemaphoreTasks();
	vStartRecursiveMutexTasks();

	/* Create the register test tasks as described at the top of this file.
	These are naked functions that don't use any stack.  A stack still has
	to be allocated to hold the task context. */
	xTaskCreate( 	vRegTest1Task,			/* Function that implements the task. */
					"Reg1", 				/* Text name of the task. */
					xRegTestStackSize,		/* Stack allocated to the task. */
					NULL, 					/* The task parameter is not used. */
					tskIDLE_PRIORITY, 		/* The priority to assign to the task. */
					NULL );					/* Don't receive a handle back, it is not needed. */

	xTaskCreate( 	vRegTest2Task,			/* Function that implements the task. */
					"Reg2", 				/* Text name of the task. */
					xRegTestStackSize,		/* Stack allocated to the task. */
					NULL, 					/* The task parameter is not used. */
					tskIDLE_PRIORITY, 		/* The priority to assign to the task. */
					NULL );					/* Don't receive a handle back, it is not needed. */

	/* Create the software timer that performs the 'check' functionality,
	as described at the top of this file. */
	xCheckTimer = xTimerCreate( "CheckTimer",					/* A text name, purely to help debugging. */
								( mainCHECK_TIMER_PERIOD_MS ),	/* The timer period, in this case 3000ms (3s). */
								pdTRUE,							/* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */
								( void * ) 0,					/* The ID is not used, so can be set to anything. */
								prvCheckTimerCallback			/* The callback function that inspects the status of all the other tasks. */
							  );

	/* If the software timer was created successfully, start it.  It won't
	actually start running until the scheduler starts.  A block time of
	zero is used in this call, although any value could be used as the block
	time will be ignored because the scheduler has not started yet. */
	if( xCheckTimer != NULL )
	{
		xTimerStart( xCheckTimer, mainDONT_BLOCK );
	}

	/* Start the kernel.  From here on, only tasks and interrupts will run. */
	vTaskStartScheduler();

	/* If all is well, the scheduler will now be running, and the following
	line will never be reached.  If the following line does execute, then there
	was	insufficient FreeRTOS heap memory available for the idle and/or timer
	tasks to be created.  See the memory management section on the FreeRTOS web
	site, or the FreeRTOS tutorial books for more details. */
	for( ;; );
}
示例#7
0
int main(int argc, char* argv[])
{
	uint32_t freq = HAL_RCC_GetSysClockFreq();
	uint32_t pclk1 = HAL_RCC_GetPCLK1Freq();
	uint32_t pclk2 = HAL_RCC_GetPCLK2Freq();

	(void) argc;
	(void) argv;

	relocate_interrupt_table();

	TimeStamp::init();
	colibri::UartTrace::init(115200 * 2);
	drone_state = new DroneState();

	printf("Starting main_task:, CPU freq: %lu, PCLK1 freq: %lu, PCLK2 freq: %lu\n", freq, pclk1, pclk2);

	/* Create tasks */
	xTaskCreate(
			main_task, /* Function pointer */
			"main_task", /* Task name - for debugging only*/
			4 * configMINIMAL_STACK_SIZE, /* Stack depth in words */
			(void*) NULL, /* Pointer to tasks arguments (parameter) */
			tskIDLE_PRIORITY + 3UL, /* Task priority*/
			&main_task_handle /* Task handle */
	);

	xTaskCreate(
			battery_task, /* Function pointer */
			"battery_task", /* Task name - for debugging only*/
			configMINIMAL_STACK_SIZE, /* Stack depth in words */
			(void*) NULL, /* Pointer to tasks arguments (parameter) */
			tskIDLE_PRIORITY + 1UL, /* Task priority*/
			&battery_task_handle /* Task handle */
	);

	xTaskCreate(
			gps_task, /* Function pointer */
			"gps_task", /* Task name - for debugging only*/
			configMINIMAL_STACK_SIZE, /* Stack depth in words */
			(void*) NULL, /* Pointer to tasks arguments (parameter) */
			tskIDLE_PRIORITY + 1UL, /* Task priority*/
			&gps_task_handle /* Task handle */
	);


#if ENABLE_UART_TASK
	xTaskCreate(
			uart_task, /* Function pointer */
			"uart_task", /* Task name - for debugging only*/
			configMINIMAL_STACK_SIZE, /* Stack depth in words */
			(void*) NULL, /* Pointer to tasks arguments (parameter) */
			tskIDLE_PRIORITY + 1UL, /* Task priority*/
			&uart_task_handle /* Task handle */
	);
#endif

	/*
	 * Disable the SysTick_IRQn and clean the priority
	 * and let the scheduler configure and enable it.
	 */
	NVIC_DisableIRQ(SysTick_IRQn);
	NVIC_SetPriority(SysTick_IRQn, 0);

	vTaskStartScheduler(); // this call will never return
}
示例#8
0
int main( void )
{
	/* MTJ: initialize syscalls -- *must* be first */
	// syscalls.c contains the files upon which the standard (and portable) C libraries rely 
	init_syscalls();

	// Set up the LED ports and turn them off
	vtInitLED();

	/* Configure the hardware for use by this demo. */
	prvSetupHardware();

	#if USE_FREERTOS_DEMO == 1
	/* Start the standard demo tasks.  These are just here to exercise the
	kernel port and provide examples of how the FreeRTOS API can be used. */
	vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
    vCreateBlockTimeTasks();
    vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
    vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
    vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY );
    vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
    vStartQueuePeekTasks();
    vStartRecursiveMutexTasks();
	vStartLEDFlashTasks( mainFLASH_TASK_PRIORITY );
	#endif

	#if USE_WEB_SERVER == 1
	// Not a standard demo -- but also not one of mine (MTJ)
	/* Create the uIP task.  The WEB server runs in this task. */
    xTaskCreate( vuIP_Task, ( signed char * ) "uIP", mainBASIC_WEB_STACK_SIZE, ( void * ) NULL, mainUIP_TASK_PRIORITY, NULL );
	#endif

	#if USE_MTJ_LCD == 1
	// MTJ: My LCD demonstration task
	StartLCDTask(&vtLCDdata,mainLCD_TASK_PRIORITY);
	// LCD Task creates a queue to receive messages -- what it does with those messages will depend on how the task is configured (see LCDtask.c)
	// Here we set up a timer that will send messages to the LCD task.  You don't have to have this timer for the LCD task, it is just showing
	//  how to use a timer and how to send messages from that timer.

	//Commented out by Matthew Ibarra 2/2/2013
	//startTimerForLCD(&vtLCDdata);
	#endif
	
	#if USE_MTJ_V4Temp_Sensor == 1
	// MTJ: My i2cTemp demonstration task
	// First, start up an I2C task and associate it with the I2C0 hardware on the ARM (there are 3 I2C devices, we need this one)
	// See vtI2C.h & vtI2C.c for more details on this task and the API to access the task
	// Initialize I2C0 for I2C0 at an I2C clock speed of 100KHz
	if (vtI2CInit(&vtI2C0,0,mainI2CMONITOR_TASK_PRIORITY,100000) != vtI2CInitSuccess) {
		VT_HANDLE_FATAL_ERROR(0);
	}
	// Now, start up the task that is going to handle the temperature sensor sampling (it will talk to the I2C task and LCD task using their APIs)
	#if USE_MTJ_LCD == 1
	vStarti2cTempTask(&tempSensorData,mainI2CTEMP_TASK_PRIORITY,&vtI2C0,&vtLCDdata);
	#else
	vStarti2cTempTask(&tempSensorData,mainI2CTEMP_TASK_PRIORITY,&vtI2C0,NULL);
	#endif
	// Here we set up a timer that will send messages to the Temperature sensing task.  The timer will determine how often the sensor is sampled
	startTimerForTemperature(&tempSensorData);
	// start up a "conductor" task that will move messages around
	vStartConductorTask(&conductorData,mainCONDUCTOR_TASK_PRIORITY,&vtI2C0,&tempSensorData);
	#endif

    /* Create the USB task. MTJ: This routine has been modified from the original example (which is not a FreeRTOS standard demo) */
	#if USE_MTJ_USE_USB == 1
	initUSB();  // MTJ: This is my routine used to make sure we can do printf() with USB
    xTaskCreate( vUSBTask, ( signed char * ) "USB", configMINIMAL_STACK_SIZE, ( void * ) NULL, mainUSB_TASK_PRIORITY, NULL );
	#endif
	
	/* Start the scheduler. */
	// IMPORTANT: Once you start the scheduler, any variables on the stack from main (local variables in main) can be (will be...) written over
	//            because the stack is used by the interrupt handler
	vTaskStartScheduler();

    /* Will only get here if there was insufficient memory to create the idle
    task.  The idle task is created within vTaskStartScheduler(). */
	for( ;; );
}
示例#9
0
文件: main.c 项目: AndreyMostovov/asf
int main(void)
{
	xTimerHandle xLEDTimer;

	/* Prepare the hardware to run this demo. */
	prvSetupHardware();

	/* Create the timer that toggles an LED to show that the system is running,
	and that the other tasks are behaving as expected. */
	xLEDTimer = xTimerCreate((const signed char * const) "LED timer",/* A text name, purely to help debugging. */
							mainSOFTWARE_TIMER_RATE,	/* The timer period. */
							pdTRUE,						/* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */
							NULL,						/* The timer does not use its ID, so the ID is just set to NULL. */
							prvLEDTimerCallback			/* The function that is called each time the timer expires. */
							);

	/* Sanity check the timer's creation, then start the timer.  The timer
	will not actually start until the FreeRTOS kernel is started. */
	configASSERT(xLEDTimer);
	xTimerStart(xLEDTimer, mainDONT_BLOCK);

	/* Create the example tasks as per the configuration settings.
	See the comments at the top of this file. */
	#if (defined confINCLUDE_UART_CLI)
	{
		create_uart_cli_task(BOARD_UART,
				mainUART_CLI_TASK_STACK_SIZE,
				mainUART_CLI_TASK_PRIORITY);
	}
	#endif /* confINCLUDE_USART_CLI */

	#if (defined confINCLUDE_USART_ECHO_TASKS)
	{
		create_usart_echo_test_tasks(BOARD_USART,
				mainUSART_ECHO_TASK_STACK_SIZE,
				mainUSART_ECHO_TASK_PRIORITY);
	}
	#endif /* confINCLUDE_USART_ECHO_TASKS */

	#if (defined confINCLUDE_USART_CLI)
	{
		create_usart_cli_task(BOARD_USART,
				mainUSART_CLI_TASK_STACK_SIZE,
				mainUSART_CLI_TASK_PRIORITY);
	}
	#endif /* confINCLUDE_USART_CLI */

	#if (defined confINCLUDE_CDC_CLI)
	{
		create_usb_cdc_cli_task(mainCDC_CLI_TASK_STACK_SIZE,
				mainCDC_CLI_TASK_PRIORITY);
	}
	#endif /* confINCLUDE_CDC_CLI */

	#if (defined confINCLUDE_SPI_FLASH_TASK)
	{
		create_spi_flash_test_task(BOARD_SPI,
				mainSPI_FLASH_TASK_STACK_SIZE,
				mainSPI_FLASH_TASK_PRIORITY,
				mainDEMONSTRATE_ASYNCHRONOUS_API);
	}
	#endif /* confINCLUDE_SPI_FLASH_TASK */

	#if (defined confINCLUDE_TWI_EEPROM_TASK)
	{
		create_twi_eeprom_test_task(BOARD_BASE_TWI_EEPROM,
				mainTWI_EEPROM_TASK_STACK_SIZE,
				mainTWI_EEPROM_TASK_PRIORITY,
				mainDEMONSTRATE_ASYNCHRONOUS_API);
	}
	#endif /* confINCLUDE_TWI_EEPROM_TASK */

	/* Start the RTOS scheduler. */
	vTaskStartScheduler();

	/* If all is well, the scheduler will now be running, and the following line
	will never be reached.  If the following line does execute, then there was
	insufficient FreeRTOS heap memory available for the idle and/or timer tasks
	to be created.  See the memory management section on the FreeRTOS web site
	for more details. */
	for (;;) {
	}
}
示例#10
0
/**
* @brief  Start the RTOS Kernel with executing the specified thread.
* @param  thread_def    thread definition referenced with \ref osThread.
* @param  argument      pointer that is passed to the thread function as start argument.
* @retval status code that indicates the execution status of the function
* @note   MUST REMAIN UNCHANGED: \b osKernelStart shall be consistent in every CMSIS-RTOS.
*/
osStatus osKernelStart (void)
{
  vTaskStartScheduler();
  
  return osOK;
}
示例#11
0
文件: main.c 项目: robopanda333/RTOS
int main(void) {
    /* Perform any hardware initialisation that may be necessary. */
    prvSetupHardware();
    //create queues
    xQueueHandle ql0 = xQueueCreate(5, 4);
    xQueueHandle ql1 = xQueueCreate(5, 4);
    xQueueHandle ql2 = xQueueCreate(5, 4);
    xQueueHandle quart = xQueueCreate(5, 50);

    xTaskParameter_t MCP1= {1, ql0, quart, NULL};
    xTaskParameter_t MCP2= {2, ql1, quart, NULL};
    xTaskParameter_t MCP3= {0, ql2, quart, NULL};
    xTaskParameter_t pUART= {0, NULL, quart, NULL};
    xTaskParameter_t LED0= {0, ql0, NULL, NULL};
    xTaskParameter_t LED1= {1, ql1, NULL, NULL};
    xTaskParameter_t LED2= {2, ql2, NULL, NULL};

    xTaskHandle next1;
    xTaskHandle next2;
    xTaskHandle next3;
    xTaskCreate(systemControlTask,
            "MCP 1",
            configMINIMAL_STACK_SIZE,
            (void*)&MCP1,
            1,
            &next3);

    xTaskCreate(systemControlTask,
            "MCP 2",
            configMINIMAL_STACK_SIZE,
            (void*)&MCP2,
            1,
            &next1);

    xTaskCreate(systemControlTask,
            "MCP 3",
            configMINIMAL_STACK_SIZE,
            (void*)&MCP3,
            1,
            &next2);

    xTaskCreate(myledblink,
            "LED 0",
            configMINIMAL_STACK_SIZE,
            (void *)&LED0,
            1,
            NULL);

    xTaskCreate(myledblink,
            "LED 1",
            configMINIMAL_STACK_SIZE,
            (void *)&LED1,
            1,
            NULL);

    xTaskCreate(myledblink,
            "LED 2",
            configMINIMAL_STACK_SIZE,
            (void *)&LED2,
            1,
            NULL);
    xTaskCreate(UARTTask,
            "UART",
            configMINIMAL_STACK_SIZE,
            (void *)&pUART,
            1,
            NULL);

    MCP1.next = next1;
    MCP2.next = next2;
    MCP3.next = next3;

    vTaskSuspend(next1);
    vTaskSuspend(next2);
    /* Start the scheduler so the tasks start executing.  This function should not return. */
    vTaskStartScheduler();
}
示例#12
0
文件: main.c 项目: ESLab/rtdl
int main()
{
	Elf32_Ehdr *simple_elfh = APPLICATION_ELF(simple);
	Elf32_Ehdr *writer_elfh = APPLICATION_ELF(writer);
	Elf32_Ehdr *reader_elfh = APPLICATION_ELF(reader);
	Elf32_Ehdr *rtuapp_elfh = APPLICATION_ELF(rtuappv1);

	Elf32_Ehdr *sys_elfh = SYSTEM_ELF;

	if (check_elf_magic(sys_elfh))
		INFO_MSG("System ELF magic checks out @ 0x%x\n", (u_int32_t)sys_elfh);
	else {
		ERROR_MSG("Wrong System ELF magic @ 0x%x\n", (u_int32_t)sys_elfh);	
		goto exit;
	}

	/*
	 * Registering tasks
	 */

	task_register_cons *simplec = task_register("simple", simple_elfh);
	task_register_cons *readerc = task_register("reader", reader_elfh);
	task_register_cons *writerc = task_register("writer", writer_elfh);
	task_register_cons *rtuappc = task_register("rtuapp", rtuapp_elfh);

	if (!task_alloc(simplec)) {
		ERROR_MSG("Could not alloc memory for task \"simple\"\n");
		goto exit;
	}
	if (!task_alloc(readerc)) {
		ERROR_MSG("Could not alloc memory for task \"reader\"\n");
		goto exit;
	}
	if (!task_alloc(writerc)) {
		ERROR_MSG("Could not alloc memory for task \"writer\"\n");
		goto exit;
	}
	if (!task_alloc(rtuappc)) {
		ERROR_MSG("Could not alloc memory for task \"rtuapp\"\n");
		goto exit;
	}

	/*
	 * Linking tasks
	 */

	if (!task_link(simplec)) {
		ERROR_MSG("Could not link \"simple\" task\n");
		goto exit;
	}
	if (!task_link(readerc)) {
		ERROR_MSG("Could not link \"reader\" task\n");
		goto exit;
	}
	if (!task_link(writerc)) {
		ERROR_MSG("Could not link \"writer\" task\n");
		goto exit;
	}
	if (!task_link(rtuappc)) {
		ERROR_MSG("Could not link \"rtuapp\" task\n");
		goto exit;
	}

	/*
	 * Starting tasks
	 */
	
	if (!task_start(simplec)) {
		ERROR_MSG("Could not start \"simple\" task\n");
		goto exit;
	}

	if (!task_start(readerc)) {
		ERROR_MSG("Could not start \"reader\" task\n");
		goto exit;
	}

	if (!task_start(writerc)) {
		ERROR_MSG("Could not start \"writer\" task\n");
		goto exit;
	}

	if (!task_start(rtuappc)) {
		ERROR_MSG("Could not start \"rtuapp\" task\n");
		goto exit;
	}

	/*
	 * Create migration task.
	 */

	if (!migrator_start()) {
		ERROR_MSG("Could not start migrator.\n");
		goto exit;
	}
	
	INFO_MSG("Starting scheduler\n");
	vTaskStartScheduler();

exit:
	INFO_MSG("Going into infinite loop...\n");
	while(1)
		;
}
示例#13
0
void osStartKernel(void)
{
   //Start the scheduler
   vTaskStartScheduler();
}
示例#14
0
int main( void )
{
	sysInit();

	/* USB Power dinyalakan supaya memory USB bisa dipakai */
	PCONP |= 0x80000000; 

	FIO0DIR = LED_UTAMA;
	FIO0CLR = LED_UTAMA;	
	
	FIO1DIR = 0xFFFFFFFF;

	#ifdef PAKAI_SERIAL_3
	/* PCONP enable UART3 */
	PCONP |= BIT(25);
	
	/* PCLK UART3, PCLK = CCLK */
	PCLKSEL1 &= ~(BIT(18) | BIT(19));
	PCLKSEL1 |= BIT(18);
	
	/* init TX3, RX3 */
	PINSEL1 &= ~(BIT(18) | BIT(19) | BIT(20) | BIT(21));
	PINSEL1 |= (BIT(18) | BIT(19));
	PINSEL1 |= (BIT(20) | BIT(21));
	PINSEL1 &= ~(BIT(16) | BIT(17));
	/* TXDE di highkan */
	FIO0DIR |= TXDE;
	//FIO0SET = TXDE;		// on	---> bisa kirim
	//FIO0SET &= ~TXDE;		// off	---> gak bisa kirim
	//FIO0CLR = TXDE;
	FIO0SET = TXDE;
	
	FIO0DIR |= RXDE;
	FIO0SET  = RXDE;
	#endif

	#ifdef PAKAI_SERIAL_2
	/* PCONP enable UART2 */
	PCONP |= BIT(24);
	
	/* PCLK UART2, PCLK = CCLK */
	PCLKSEL1 &= ~(BIT(16) | BIT(17));
	PCLKSEL1 |= BIT(16);
	
	/* init TX2, RX2 */
	PINSEL0 |= (BIT(20) | BIT(22));
	#endif

	/*	untuk cek blinking saat system boot */
#ifdef CEK_BLINK
	int t=0;
	while(t<5)
	{
		dele(1000000);
		FIO0CLR = LED_UTAMA;
		dele(1000000);
		FIO0SET = LED_UTAMA;
		t++;
	}
#endif

	xSerialPortInitMinimal( BAUD_RATE, configMINIMAL_STACK_SIZE  );
	#ifdef PAKAI_SERIAL_2
		serial2_init( BAUD_PM, (1 * configMINIMAL_STACK_SIZE) );
	#endif
	#ifdef PAKAI_SERIAL_3
		serial3_init( BAUD_PM, (1 * configMINIMAL_STACK_SIZE) );
	#endif

#ifdef PAKAI_ADC
	init_gpio_adc();
	init_gpio_mmc();
	init_spi_mmc(0);		// untuk adc dan mmc
#endif

#ifdef jalankan
	init_led_utama();
	start_ether();

//#if defined(PAKAI_PM) && defined(AMBIL_PM)
	init_task_pm();
//#endif
	init_shell();
	vTaskStartScheduler();

    /* Will only get here if there was insufficient memory to create the idle
    task. */
	return 0;
#endif
/*FUNCTION**********************************************************************
 *
 * Function Name : OSA_Start
 * Description   : This function is used to start RTOS scheduler.
 *
 *END**************************************************************************/
osa_status_t OSA_Start(void)
{
    vTaskStartScheduler();
    return kStatus_OSA_Success;
}
示例#16
0
void os_startScheduler(void)
{
    vTaskStartScheduler();
}
int main_full( void )
{
TimerHandle_t xTimer = NULL;

	/* Usage instructions on http://www.FreeRTOS.org/Atmel_SAM4E_RTOS_Demo.html */

	/* Initialise the LCD and output a bitmap.  The IP address will also be
	displayed on the LCD when it has been obtained. */
	vInitialiseLCD();

	/* If the file system is only going to be accessed from one task then
	F_FS_THREAD_AWARE can be set to 0 and the set of example files are created
	before the RTOS scheduler is started.  If the file system is going to be
	access from more than one task then F_FS_THREAD_AWARE must be set to 1 and
	the	set of sample files are created from the idle task hook function
	vApplicationIdleHook(). */
	#if( F_FS_THREAD_AWARE == 0 )
	{
		/* Initialise the drive and file system, then create a few example
		files.  The files can be viewed and accessed via the CLI.  View the
		documentation page for this demo (link at the top of this file) for more
		information. */
		vCreateAndVerifySampleFiles();
	}
	#endif

	/* Register example generic, file system related and UDP related CLI
	commands respectively.  Type 'help' into the command console to view a list
	of registered commands. */
	vRegisterSampleCLICommands();
	vRegisterFileSystemCLICommands();
	vRegisterUDPCLICommands();

	/* Initialise the network interface.  Tasks that use the network are
	created in the network event hook when the network is connected and ready
	for use.  The address values passed in here are used if ipconfigUSE_DHCP is
	set to 0, or if ipconfigUSE_DHCP is set to 1 but a DHCP server cannot be
	contacted.  The IP address actually used is displayed on the LCD (after DHCP
	has completed if DHCP is used). */
	FreeRTOS_IPInit( ucIPAddress, ucNetMask, ucGatewayAddress, ucDNSServerAddress, ucMACAddress );

	/* Create all the other standard demo tasks. */
	vStartLEDFlashTimers( mainNUM_FLASH_TIMER_LEDS );
	vCreateBlockTimeTasks();
	vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
	vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
	vStartQueuePeekTasks();
	vStartCountingSemaphoreTasks();
	vStartDynamicPriorityTasks();
	vStartQueueOverwriteTask( mainQUEUE_OVERWRITE_TASK_PRIORITY );
	vStartQueueSetTasks();
	vStartRecursiveMutexTasks();
	vStartEventGroupTasks();

	/* Create the software timer that performs the 'check' functionality, as
	described at the top of this file. */
	xTimer = xTimerCreate( 	"CheckTimer",					/* A text name, purely to help debugging. */
							( mainCHECK_TIMER_PERIOD_MS ),	/* The timer period, in this case 3000ms (3s). */
							pdTRUE,							/* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */
							( void * ) 0,					/* The ID is not used, so can be set to anything. */
							prvCheckTimerCallback );		/* The callback function that inspects the status of all the other tasks. */

	if( xTimer != NULL )
	{
		xTimerStart( xTimer, mainDONT_BLOCK );
	}

	/* Start the scheduler itself. */
	vTaskStartScheduler();

	/* If all is well, the scheduler will now be running, and the following line
	will never be reached.  If the following line does execute, then there was
	insufficient FreeRTOS heap memory available for the idle and/or timer tasks
	to be created.  See the memory management section on the FreeRTOS web site
	for more details. */
	for( ;; );
}
示例#18
0
/*****************************************************************************
 * c_entry: this is our main() function, called from boot_prot.S
 *
 * RETURNS: None
 */
__attribute__((regparm(0))) void c_entry (void)
{
	xTaskHandle xHandle;
	UINT8   	i=0,bFlag = 0;
    UINT16		port, baud = 0;
    NV_RW_Data	nvdata;
#ifdef INCLUDE_DEBUG_VGA
    char achBuffer[80];
#endif
    

#if 0 /* Not used, HAL no longer present */

	/*
	 * Register the local service provider now, as code will be using BIT
	 * services for PCI accesses.
	 */

	cctRegisterServiceProvider (cctServiceProvider);
#endif

	/*
	 * Key sub-system initialisation
	 */

	sysMmuInitialize ();				/* Initialise the local page table management */
	sysInitMalloc (K_HEAP, U_HEAP);		/* Initialise the heap management */

#ifdef INCLUDE_EXCEPTION_DEBUG
	dbgInstallExceptionHandlers();
#endif

#ifdef INCLUDE_DBGLOG	
	dbgLogInit();
#endif

	/*Initialise the mutexes so that we can start using the public functions*/
	for(i=0; i < MAX_CUTEBIT_MUTEX; i++)
	{
		globalMutexPool[i]=xSemaphoreCreateMutex();

		if( globalMutexPool[i] == NULL )
		{
			/*We should not get here, die...*/
			while(1);
		}
	}

	/*
	 * Search and parse BIOS_INFO and  EXTENDED_INFO structures
	 */
	board_service(SERVICE__BRD_GET_BIOS_INFO,     NULL, &dBiosInfo_addr);
	board_service(SERVICE__BRD_GET_EXTENDED_INFO, NULL, NULL);


	/*
	 * Open/close the debug channel and sign-on - we can't use vDebugWrite() this
	 * early, so make direct calls to sysDebug...
	 */
	if(bStartupDebugMode())
	{
		sysDebugWriteString ("\n[Debugging Enabled]\n");
		
		if(sysIsDebugopen())
		{
			if(board_service(SERVICE__BRD_GET_FORCE_DEBUG_OFF, NULL, NULL) == E__OK)
			{	
				sysDebugWriteString ("[Debugging Forced Off]\n");
				sysDebugClose();
			}
		}
	}
	else if( board_service(SERVICE__BRD_GET_FORCE_DEBUG_ON, NULL, NULL) == E__OK )
	{
		sysDebugWriteString ("[Debugging Forced On]\n");
		bForceStartupDebugMode();
		sysDebugOpen();
	}
	
	sysDebugFlush ();
	
#ifdef INCLUDE_DEBUG_VGA
	vgaDisplayInit();
	vgaSetCursor( CURSOR_OFF );
#endif

	sysDebugWriteString ("Starting HW Initialization\n");
	board_service(SERVICE__BRD_HARDWARE_INIT, NULL, NULL); /* board-specific H/W initialisation */

	if(board_service(SERVICE__BRD_GET_CONSOLE_PORT, NULL, &port) == E__OK)
	{
		baud = bGetBaudRate();
		//baud = 0; //hard coded by Rajan. Need to remove after debug
		sysSccInit (port, baud);
		
#ifdef INCLUDE_DEBUG_VGA
		sprintf( achBuffer, "Console open, port: 0x%x baud: %u\n", port, baud );
		vgaPutsXY( 0, startLine++, achBuffer );
		
#endif
	}

	if(board_service(SERVICE__BRD_GET_DEBUG_PORT, NULL, &port) == E__OK)
	{

//#ifdef commented by Rajan. Need to uncomment after debug
//#ifdef INCLUDE_DEBUG_PORT_INIT
			baud = bGetBaudRate();
            baud = 0; //hard coded by Rajan. Need to remove after debug
			sysSccInit (port, baud);
//#endif

#ifdef INCLUDE_DEBUG_VGA			
			sprintf( achBuffer, "Debug %s,   port: 0x%x baud: %u\n", 
						(sysIsDebugopen()? "open":"closed"), port, baud );
			vgaPutsXY( 0, startLine++, achBuffer );
#endif		
	}


#ifdef INCLUDE_MAIN_DEBUG
	{	
		UINT32 temp = 0;
		
		board_service(SERVICE__BRD_GET_MAX_DRAM_BELOW_4GB, NULL, &temp);
		DBLOG( "Max DRAM below 4GB: 0x%08x\n", temp );
	}
#endif

#if	defined(MAKE_CUTE) || defined (MAKE_BIT_CUTE)
	#if defined(VPX)
		vpxPreInit();
	#endif

	#if defined(CPCI)
		board_service(SERVICE__BRD_CHECK_CPCI_IS_SYSCON,NULL,&bFlag);
		cpciPreInit(bFlag);
	#endif

	board_service(SERVICE__BRD_CONFIGURE_VXS_NT_PORTS, NULL, NULL);
#endif

#if defined (SRIO)

	sysDebugWriteString ("Initializing: SRIO\n");
	
	for (i = 1 ; i < MAX_TSI721_DEVS; i++)
	{
	   srioPreInit (i);
	}

#endif

#ifndef CPCI
	if (!bFlag)
		vDelay(2000);// delay added, so pmc160 will show up!
#endif

	sysDebugWriteString ("Initializing: PCI\n");
	sysPciInitialize ();		/* (re)scan PCI and allocate resources */

	sysDebugWriteString ("Rajan--> Step1\n");


#if	defined(MAKE_CUTE) || defined (MAKE_BIT_CUTE)
	#if defined (VME) && defined (INCLUDE_LWIP_SMC)
		// pci bus enumeration must have been run
		InitialiseVMEDevice();
	#endif
#endif

	sysDebugWriteString ("Rajan--> Step2\n");


#ifdef INCLUDE_DEBUG_VGA
	vgaPutsXY( 0, startLine, "FreeRTOS starting....\n\n" );
	startLine += 2;
#endif

	board_service(SERVICE__BRD_POST_SCAN_INIT, NULL, NULL); // post scan H/W initialisations
	board_service(SERVICE__BRD_ENABLE_SMIC_LPC_IOWINDOW, NULL, NULL); /* board-specific smic Initialization */
	/*
	 * Having got this far, clear the load error that we've been holding in CMOS
	 */
	nvdata.dNvToken = NV__TEST_NUMBER;
	nvdata.dData    = 0;
	board_service(SERVICE__BRD_NV_WRITE, NULL, &nvdata);

	nvdata.dNvToken = NV__ERROR_CODE;
	nvdata.dData    = E__BOARD_HANG;
	board_service(SERVICE__BRD_NV_WRITE, NULL, &nvdata);

	
#ifdef INCLUDE_MAIN_DEBUG
	DBLOG( "CUTE/BIT Kernel heap: 0x%08x-0x%08x\n", (UINT32)K_HEAP, ((UINT32)K_HEAP + HEAP_SIZE - 1) );
	DBLOG( "CUTE/BIT User heap  : 0x%08x-0x%08x\n", (UINT32)U_HEAP, ((UINT32)U_HEAP + HEAP_SIZE - 1) );
	
	xPortGetFreeHeapSize();
#endif

	
	/* Initialise task data */
	vTaskDataInit( bCpuCount );
	
	/* Initialise PCI shared interrupt handling */
	pciIntInit();

#ifdef INCLUDE_MAIN_DEBUG	
	pciListDevs( 0 );
#endif
	
	/* Create and start the network */
	sysDebugWriteString ("Initializing: Network\n");
	networkInit();

#if defined(SRIO)
	sysDebugWriteString ("Initializing: TSI721\n");
	
	for (i = 1 ; i < MAX_TSI721_DEVS; i++)
	{
		tsi721_init(i);
	}

	rio_init_mports();
	
#endif

	// some boards may not reset the RTC cleanly
	board_service(SERVICE__BRD_INIT_RTC, NULL, NULL);

#ifdef INCLUDE_DEMO_TASKS
	
	randMutex = xSemaphoreCreateMutex();
	if (randMutex == NULL)
	{
		sysDebugWriteString ("Error - Failed to create rand mutex\n");
	}
	else
	{
		for (i = 0; i < bCpuConfigured; i++)
		{
			tParam[i].taskNum = i + 1;
			sprintf( tParam[i].taskName, "Demo%u", tParam[i].taskNum );
			xTaskCreate( i, vTaskCodePeriodic, tParam[i].taskName, mainDEMO_STACK_SIZE, 
						&tParam[i],	mainDEMO_TASK_PRIORITY, &xHandle );
		}
		
		tParam[i].taskNum = i + 1;
		sprintf( tParam[i].taskName, "BKGRD" );	
		xTaskCreate( 0, vTaskCodeBackground, tParam[i].taskName, mainDEMO_STACK_SIZE, 
						&tParam[i],	mainDEMO_TASK_PRIORITY+1, &xHandle );
	}						
#endif

	sysDebugWriteString ("Creating CUTE task\n");
	xTaskCreate( 0, startCuteBit, "CuteBitTask", mainCUTEBIT_TASK_STACKSIZE,
			NULL, mainCUTEBIT_TASK_PRIORITY, &xHandle );

#ifdef INCLUDE_MAIN_DEBUG
	sysDebugWriteString ("\n[Starting FreeRtos Scheduler]\n");
	sysDebugFlush ();
#endif


	sysInvalidateTLB();

	/* Start the FreeRTOS Scheduler, does not return */
	vTaskStartScheduler();

} /* c_entry () */
示例#19
0
int main(int argc, char *argv[])
{
    cmd_opts opts = { 0 };
    struct option long_options[] = {
        {"sub",     no_argument,        0, 's' },
        {"pub",     no_argument,        0, 'p' },
        {"url",     required_argument,  0, 'u' },
        {"thng",    required_argument,  0, 't' },
        {"key",     required_argument,  0, 'k' },
        {"prop",    required_argument,  0, 'n' },
        {"help",    no_argument,        0, 'h' },
        {0, 0, 0, 0}
    };

    int long_index = 0, opt;
    while ((opt = getopt_long(argc, argv,"spu:t:k:n:v:c:h", 
                    long_options, &long_index )) != -1) 
    {
        switch (opt) {
            case 's' : opts.sub = 1;
                       break;
            case 'p' : opts.pub = 1;
                       break;
            case 'u' : opts.url = optarg; 
                       break;
            case 't' : opts.thng = optarg;
                       break;
            case 'k' : opts.key = optarg;
                       break;
            case 'n' : opts.prop = optarg;
                       break;
            case 'h' : 
            default:
                       print_usage(); 
                       exit(EXIT_FAILURE);
        }
    }

    if (opts.sub && opts.pub) 
    {
        log("use --sub or --pub option, not both");
        exit(EXIT_FAILURE);
    }

    if (!opts.sub && !opts.pub) 
    {
        log("use --sub or --pub option");
        exit(EXIT_FAILURE);
    }

    if (!opts.url || !opts.key || !opts.thng || !opts.prop) 
    {
        print_usage();
        exit(EXIT_FAILURE);
    }

    struct sigaction action;
    action.sa_handler = sigint_handler;
    sigemptyset(&action.sa_mask);
    action.sa_flags = 0;
    sigaction(SIGINT, &action, NULL);

    platform_thread_create(&t, 5, "evrythng_task", evrythng_task, 8192, &opts);

    vTaskStartScheduler();

    return EXIT_SUCCESS;
}
示例#20
0
BT_ERROR BT_kStartScheduler() {
	vTaskStartScheduler();
	return BT_ERR_GENERIC;
}
示例#21
0
/** System startup function */
int main(void) {
	// Initialize basic system hardware
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
	enableVFP();
	delayTimer.init();

	// Initialize pulse led timer
	PulseLED::initTimer(pulseProps);

	// Initialize user button
	toggleButton.setPriority(8, 0);
	toggleButton.setPressedListener(userPressed, NULL);
	toggleButton.init();

	// Initialize GPS
	uartGPS.setPriority(5, 0);
	uartGPS.init();
	gps.init();

	// Initialize LEDs
	redLED.init();
	blueLED.init();
	greenLED.init();
	orangeLED.init();

	// Initialize pulse LEDs
	redPulseLED.init();
	greenPulseLED.init();

	// Initialize ZigBee
	mrf.setSPIPriority(0, 0);
	mrf.setRFPriority(1, 0);
	mrf.init();

	// Console initialization
	uartSerial.setPriority(15, 15);
	uartSerial.init();
	console.init();

	// Initialize stop-watch
	StopWatch::init(TIM1, RCC_APB2PeriphClockCmd, RCC_APB2Periph_TIM1, TIM1_UP_TIM10_IRQn);

	console.print(Info, "\n\n\n\n\n\n\n\n\n\n\n");
	console.print(Info, "# # # # # # # # # # # # # # # # # # # #\n");
	console.print(Info, " # # # # # # # # # # # # # # # # # # #\n");
	console.print(Info, "# # # # # # # # # # # # # # # # # # # #\n");
	console.print(Info, "\n>>> SYSTEM INIT <<<\n");

	console.print(Info, ">>> Waiting 3s for debugger to stop me...\n");
	delayTimer.mDelay(3000);
	console.print(Info, ">>> Starting system\n");

	// Get unique device id
	const uint32_t uniqId = *((uint32_t*) 0x1FFF7A10);
	console.print(Info, "\n\n>>>>> Unique system Id: %x <<<<<<\n\n\n", uniqId);

	// Initialize user defined CDEECO++ system
	cdeecoSetup(uniqId);

	// Start the scheduler.
	console.print(Info, ">>> Running scheduler\n");
	vTaskStartScheduler();

	// This should not be reached
	console.print(Error, ">>> End reached - THIS SHOULD NOT HAPPEN !!!!\n");
	assert_param(false);
}
示例#22
0
文件: main.c 项目: Mazetti/asf
//!
//! \fn     main
//! \brief  1) Initialize the microcontroller and the shared hardware resources
//!         of the board.
//!         2) Launch the Ctrl Panel modules.
//!         3) Start FreeRTOS.
//! \return Should never occur.
//! \note
//!
int main(void)
{
	// Disable the WDT.
	// wdt_disable();

	//**
	//** 1) Initialize the microcontroller and the shared hardware resources of the board.
	//**

	// switch to external oscillator 0
	pm_switch_to_osc0(&AVR32_PM, FOSC0, OSC0_STARTUP);

	// Init USB & MACB clock.
	prv_clk_gen_start();

	// initialize AT45DBX resources: GPIO, SPI and AT45DBX
	prv_at45dbx_resources_init();

#if SD_MMC_SPI_MEM == ENABLE
	prv_sd_mmc_resources_init();
#endif

	// Setup the LED's for output.
	LED_Off( LED0 ); LED_Off( LED1 ); LED_Off( LED2 ); LED_Off( LED3 );
	LED_Off( LED4 ); LED_Off( LED5 ); LED_Off( LED6 ); LED_Off( LED7 );
	// vParTestInitialise();

	// Init the memory module.
	if (false == ctrl_access_init()) {
		// TODO: Add msg on LCD.
		// gpio_clr_gpio_pin( 60 );
	while (1);
	}

	/* check if the AT45DBX mem is OK */
	while (CTRL_GOOD != mem_test_unit_ready( LUN_ID_AT45DBX_MEM )) {
		// TODO: Add msg on LCD.
		// gpio_clr_gpio_pin( 61 );
	}

	// Init the FAT navigation module.
	if (false == b_fsaccess_init()) {
		// TODO: Add msg on LCD.
		// gpio_clr_gpio_pin( 62 );
	while (true);
	}

	// Init the time module.
	v_cptime_Init();

	//**
	//** 2) Launch the Control Panel supervisor task that will in turn create all
	//** the necessary tasks.
	//**
	vSupervisor_Start( mainSUPERVISOR_TASK_PRIORITY );

	//**
	//** 3) Start FreeRTOS.
	//**
	// Use preemptive scheduler define configUSE_PREEMPTION as 1 in portmacro.h
	vTaskStartScheduler();

	/* Should never reach this point. */
	while (true);
}
int main(void)
{
	/* Configure the NVIC, LED outputs and button inputs. */
	prvSetupHardware();

	/* Create the queue. */
	xQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( unsigned long ) );

	if( xQueue != NULL )
	{
		/* Start the two application specific demo tasks, as described in the
		comments at the top of this	file. */
		xTaskCreate( prvQueueReceiveTask, "Rx", configMINIMAL_STACK_SIZE, NULL, mainQUEUE_RECEIVE_TASK_PRIORITY, NULL );
		xTaskCreate( prvQueueSendTask, "TX", configMINIMAL_STACK_SIZE, NULL, mainQUEUE_SEND_TASK_PRIORITY, NULL );

		/* Create the software timer that is responsible for turning off the LED
		if the button is not pushed within 5000ms, as described at the top of
		this file. */
		xLEDTimer = xTimerCreate( 	"LEDTimer", 				/* A text name, purely to help debugging. */
									( mainLED_TIMER_PERIOD_MS ),/* The timer period, in this case 5000ms (5s). */
									pdFALSE,					/* This is a one shot timer, so xAutoReload is set to pdFALSE. */
									( void * ) 0,				/* The ID is not used, so can be set to anything. */
									prvLEDTimerCallback			/* The callback function that switches the LED off. */
								);

		/* Create the software timer that performs the 'check' functionality,
		as described at the top of this file. */
		xCheckTimer = xTimerCreate( "CheckTimer",					/* A text name, purely to help debugging. */
									( mainCHECK_TIMER_PERIOD_MS ),	/* The timer period, in this case 3000ms (3s). */
									pdTRUE,							/* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */
									( void * ) 0,					/* The ID is not used, so can be set to anything. */
									prvCheckTimerCallback			/* The callback function that inspects the status of all the other tasks. */
								  );

		/* Create the software timer that performs the 'digit counting'
		functionality, as described at the top of this file. */
		xDigitCounterTimer = xTimerCreate( "DigitCounter",					/* A text name, purely to help debugging. */
									( mainDIGIT_COUNTER_TIMER_PERIOD_MS ),	/* The timer period, in this case 3000ms (3s). */
									pdTRUE,									/* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */
									( void * ) 0,							/* The ID is not used, so can be set to anything. */
									prvDigitCounterTimerCallback			/* The callback function that inspects the status of all the other tasks. */
								  );

		/* Create a lot of 'standard demo' tasks.  Over 40 tasks are created in
		this demo.  For a much simpler demo, select the 'blinky' build
		configuration. */
		vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
		vCreateBlockTimeTasks();
		vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
		vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
		vStartLEDFlashTasks( mainFLASH_TASK_PRIORITY );
		vStartQueuePeekTasks();
		vStartRecursiveMutexTasks();
		vStartTimerDemoTask( mainTIMER_TEST_PERIOD );
		vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
		vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
		vStartCountingSemaphoreTasks();
		vStartDynamicPriorityTasks();

		/* The suicide tasks must be created last, as they need to know how many
		tasks were running prior to their creation in order to ascertain whether
		or not the correct/expected number of tasks are running at any given
		time. */
		vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );

		/* Start the tasks and timer running. */
		vTaskStartScheduler();
	}

	/* If all is well, the scheduler will now be running, and the following line
	will never be reached.  If the following line does execute, then there was
	insufficient FreeRTOS heap memory available for the idle and/or timer tasks
	to be created.  See the memory management section on the FreeRTOS web site
	for more details. */
	for( ;; );
}
示例#24
0
int main(void)
{
  /* MCU Configuration----------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface
   * and the Systick. */
  board_Init();

  /* Init components */
    motor_init();
    motor_stop(motor_ch_all);
    motor_go_forward();

    pb_init();
    encoder_init();
  /* USER CODE BEGIN RTOS_MUTEX */
  /* USER CODE END RTOS_MUTEX */

  /* USER CODE BEGIN RTOS_SEMAPHORES */
  /* add semaphores, ... */
  muRange = xSemaphoreCreateMutex();
  /* USER CODE END RTOS_SEMAPHORES */

  /* USER CODE BEGIN RTOS_TIMERS */
  /* start timers, add new ones, ... */
  /* USER CODE END RTOS_TIMERS */

  /* Create the thread(s) */
  /* definition and creation of defaultTask */
  xTaskCreate(task_blinky,			        /* Pointer to the function that implements the task */
		  	  "Blinky",						/* Text name for the task. This is to facilitate debugging only. It is not used in the scheduler */
		  	  configMINIMAL_STACK_SIZE,		/* Stack depth in words */
		  	  NULL,							/* Pointer to a task parameters */
		  	  1,		                    /* The task priority */
		  	  &xBlinkyHandle);                        /* Pointer of its task handler, if you don't want to use, you can leave it NULL */

  /*
  xTaskCreate(vRangeFinderTask,
                  "Range",
                  configMINIMAL_STACK_SIZE+500,
                  NULL,
                  configMAX_PRIORITIES-1,
                  &xScanInputHandle);
*/
  /*
  xTaskCreate(vEncoderTask,
                  "Encoder",
                  configMINIMAL_STACK_SIZE+500,
                  NULL,
                  configMAX_PRIORITIES-1,
                  &xScanInputHandle);
                  */
  xTaskCreate(task_main,
                    "Main",
                    configMINIMAL_STACK_SIZE+2500,
                    NULL,
                    configMAX_PRIORITIES-1,
                    &xMainHandle);
  /* USER CODE BEGIN RTOS_QUEUES */
  /* definition and creation of xQueueUARTReceive */
  quUARTReceive = xQueueCreate(confUART_RECEIVE_QUEUE_LENGTH, /* length of queue */
                              sizeof(uint8_t)*confUART_RECEIVE_BUFFER_SIZE); /* size in byte of each item */
  /* USER CODE END RTOS_QUEUES */


  /* Start scheduler */
  vTaskStartScheduler();
  /* NOTE: We should never get here as control is now taken by the scheduler */
  while (1)
  {
  }
}
//*****************************************************************************
//							MAIN FUNCTION
//*****************************************************************************
void main()
{
  
  
    
#if defined(ewarm)
    IntVTableBaseSet((unsigned long)&__vector_table);
#endif

    //
    // Board Initialization
    //
    MCUInit();
    //
    
    
    // Enable the SYSTICK interrupt
    //
    IntEnable(FAULT_SYSTICK);
    
    sysTickInit();
    
    
    
	//
	// Start the SimpleLink Host
	//
    VStartSimpleLinkSpawnTask(SPAWN_TASK_PRIORITY);
	//
   // WlanStationMode(NULL);
      
  //  UART_PRINT("hellow i am in\n\r");
    
	// Start the WlanStationMode task
	//

    if(OSI_OK !=osi_TaskCreate( WlanStationMode,
    				(const signed char*)"WlanStationMode task",
    				2048, NULL, 3, NULL ))
      UART_PRINT("WlanStationMode failed\n\r");   
        
   if(OSI_OK != osi_TaskCreate( taskServer,
    				(const signed char*)"taskServer",
    				2048, NULL, 2, (OsiTaskHandle)&ServerTaskHandle ) )
     UART_PRINT("taskServer failed\n\r");
    
    if(OSI_OK != osi_TaskCreate( taskClient,
    				(const signed char*)"taskClient",
    				2048, NULL, 1, (OsiTaskHandle)&clientTaskHandle ))
      UART_PRINT("taskClient failed\n\r");
    
    
 /*   
    if(OSI_OK != osi_TaskCreate( taskTest1,
    				(const signed char*)"taskTest1",
    				2048, NULL, 1, NULL ))
      UART_PRINT("taskTest1 failed\n\r"); 
    
    if(OSI_OK != osi_TaskCreate( taskTest2,
    				(const signed char*)"taskTest2",
    				2048, NULL, 1, NULL ))
      UART_PRINT("taskTest1 failed\n\r"); 
*/       
    
	//
	// Start the task scheduler
	//
    //osi_start();
    vTaskStartScheduler();
}
示例#26
0
/*
 * Create the demo tasks then start the scheduler.
 */
int main_full( void )
{
TimerHandle_t xTimer = NULL;

	/* Create all the other standard demo tasks. */
	vStartLEDFlashTimers( mainNUM_FLASH_TIMER_LEDS );
	vCreateBlockTimeTasks();
	vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
	vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
	vStartQueuePeekTasks();
	vStartInterruptQueueTasks();
	vStartISRTriggeredTask();
	vStartCountingSemaphoreTasks();
	vStartDynamicPriorityTasks();
	vStartQueueOverwriteTask( mainQUEUE_OVERWRITE_TASK_PRIORITY );
	vStartQueueSetTasks();
	vStartRecursiveMutexTasks();
	vStartEventGroupTasks();
	vStartMathTasks( mainFLOP_TASK_PRIORITY );

	/* Create the tasks defined within this file. */
	xTaskCreate( prvRegTestTask1,			/* The function that implements the task. */
				"Reg1",						/* Text name for the task to assist debugger - not used by FreeRTOS itself. */
				configMINIMAL_STACK_SIZE,	/* The stack size to allocate for the task - specified in words not bytes. */
				NULL,						/* The parameter to pass into the task - not used in this case so set to NULL. */
				tskIDLE_PRIORITY,			/* The priority to assign to the task. */
				NULL );						/* Used to obtain a handle to the task being created - not used in this case so set to NULL. */

	xTaskCreate( prvRegTestTask2, "Reg2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );

	/* Create the software timer that performs the 'check' functionality, as
	described at the top of this file. */
	xTimer = xTimerCreate( 	"CheckTimer",/* A text name, purely to help debugging. */
							( mainCHECK_TIMER_PERIOD_MS ),		/* The timer period, in this case 3000ms (3s). */
							pdTRUE,								/* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */
							( void * ) 0,						/* The ID is not used, so can be set to anything. */
							prvCheckTimerCallback );			/* The callback function that inspects the status of all the other tasks. */

	if( xTimer != NULL )
	{
		xTimerStart( xTimer, mainDONT_BLOCK );
	}

	/* A software timer is also used to start the high frequency timer test.
	This is to ensure the test does not start before the kernel.  This time a
	one shot software timer is used. */
	xTimer = xTimerCreate( "HighHzTimerSetup", 1, pdFALSE, ( void * ) 0, prvSetupHighFrequencyTimerTest );
	if( xTimer != NULL )
	{
		xTimerStart( xTimer, mainDONT_BLOCK );
	}

	/* Finally start the scheduler. */
	vTaskStartScheduler();

	/* If all is well, the scheduler will now be running, and the following line
	will never be reached.  If the following line does execute, then there was
	insufficient FreeRTOS heap memory available for the idle and/or timer tasks
	to be created.  See the memory management section on the FreeRTOS web site
	for more details.  http://www.freertos.org/a00111.html */
	for( ;; );
}
示例#27
0
int main(void)
{
  xTaskHandle task1;
  xTaskHandle task2;
  xTaskHandle task3;

  cpu_init(DEFAULT_CPU_FREQ);

#ifdef CONSOLE_SERIAL
  serial_stdio(CONSOLE_PORT);
#endif

#ifdef CONSOLE_SEMIHOSTING
  semihosting_stdio(CONSOLE_PORT)
#endif

#ifdef CONSOLE_USB
  usb_serial_stdio(NULL);
  getch();
#endif

// Display version information

  printf("\033[H\033[2J%s FreeRTOS Test (" __DATE__ " " __TIME__ ")\n\n", MCUFAMILYNAME);
  puts(revision);
  printf("\nCPU Freq:%u Hz  Compiler:%s %s %s  FreeRTOS:%s\n\n", (unsigned int) SystemCoreClock,
    __COMPILER__, __VERSION__, __ABI__, tskKERNEL_VERSION_NUMBER);

// Create mutex to arbitrate console output

  console_lock = xSemaphoreCreateMutex();
  if (console_lock == NULL)
  {
    puts("ERROR: xSemaphoreCreateMutex() for console_lock failed!");
    fflush(stdout);
    assert(false);
  }

// Create a couple of tasks

  if (xTaskCreate(putsTaskFunction, (signed char *) "task1", 512, NULL, 1, &task1) != pdPASS)
  {
    puts("ERROR: xTaskCreate() for task1 failed!");
    fflush(stdout);
    assert(false);
  }

  if (xTaskCreate(putsTaskFunction, (signed char *) "task2", 512, NULL, 1, &task2) != pdPASS)
  {
    puts("ERROR: xTaskCreate() for task2 failed!");
    fflush(stdout);
    assert(false);
  }

  if (xTaskCreate(LEDTaskFunction, (signed char *) "task3", 256, NULL, 1, &task3) != pdPASS)
  {
    puts("ERROR: xTaskCreate() for task3 failed!");
    fflush(stdout);
    assert(false);
  }

  vTaskStartScheduler();
  assert(false);
}
示例#28
0
/**
 * Main is used to:
 * Initialize drivers
 * Create threads
 * Pass drivers structures to threads
 */
int main( void ) {
    /*
     * Enable internal 32 MHz ring oscillator and wait until it's
     * stable. Set the 32 MHz ring oscillator as the main clock source.
     */
    CLKSYS_Enable( OSC_RC32MEN_bm );
    CLKSYS_Prescalers_Config( CLK_PSADIV_1_gc, CLK_PSBCDIV_1_1_gc );
    do {} while ( CLKSYS_IsReady( OSC_RC32MRDY_bm ) == 0 );
    CLKSYS_Main_ClockSource_Select( CLK_SCLKSEL_RC32M_gc );

    //Enable watchdog timer, which will be reset by timer
    WDT_EnableAndSetTimeout( WDT_PER_1KCLK_gc );
    /*
     * Do all configuration and create all tasks and queues before scheduler is started.
     * It is possible to put initialization of peripherals like displays into task functions
     * (which will be executed after scheduler has started) if fast startup is needed.
     * Interrupts are not enabled until the call of vTaskStartScheduler();
     */
    // Enable the Round-Robin Scheduling scheme.Round-Robin scheme ensures that no low-level
    // interrupts are “starved”, as the priority changes continuously
    PMIC_EnableRoundRobin();

    //Create and start the timer, which will reset Watch Dog Timer
    xTimerStart(xTimerCreate((signed char*)"WDT",500, pdTRUE, 0, watchdogTimerCallback), 0);
    //---------Use USART on PORTC----------------------------
    Serial usartFTDI = Serial(&USARTE0, BAUD9600, 128, 10);

    // Initialize SPI slave on port D
    SpiSlave spiSlave = SpiSlave(&SPIC,false,SPI_MODE_1_gc,64);
    // Initialize SPI master on port C
    SpiMaster spiMaster = SpiMaster(&SPID, false, SPI_MODE_1_gc, false, SPI_PRESCALER_DIV4_gc);
    SpiDevice spiDevice = SpiDevice(&spiMaster, &PORTD, SPI_SS_bm);

    //---------Start LED task for testing purposes-----------
    ledRGB = LedGroup(3);
    ledRGB.add(&PORTF, 0x04,1 );//R
    ledRGB.add(&PORTF, 0x08,1 );//G
    ledRGB.add(&PORTF, 0x02,1 );//B
    ledRGB.set(BLUE);
    LedProcessorThread ledRGBEThread = LedProcessorThread(&ledRGB, GREEN, 500, "RGB", 64, configLOW_PRIORITY);

    LedGroup ledString = LedGroup(7);
    ledString.add(&PORTA, 0x02, 0);
    ledString.add(&PORTA, 0x04, 0);
    ledString.add(&PORTA, 0x08, 0);
    ledString.add(&PORTA, 0x10, 0);
    ledString.add(&PORTA, 0x20, 0);
    ledString.add(&PORTA, 0x40, 0);
    ledString.add(&PORTA, 0x80, 0);
    LedProcessorThread ledStringThread = LedProcessorThread(&ledString, "STR", 64, configLOW_PRIORITY);

    // ***** Start main Looper
    Looper looper = Looper(10, "LPR", 750, configNORMAL_PRIORITY);
    //XXX why it is not working if on the heap not on the stack?
    //ExampleHandler *exampleHandler = (ExampleHandler*) pvPortMalloc(sizeof(ExampleHandler));
    //*exampleHandler = ExampleHandler(looper, spiDevice, ledStringQueue, usartFTDI);
    ExampleHandler exampleHandler = ExampleHandler(&looper, &spiDevice, &ledStringThread, &usartFTDI);
    // ****** Register commands for the interpreter
    CommandInterpreter interpreter = CommandInterpreter();
    interpreter.registerCommand(Strings_SpiExampleCmd, Strings_SpiExampleCmdDesc, &exampleHandler, EVENT_RUN_SPI_TEST);
    interpreter.registerCommand(Strings_BlinkCmd, Strings_BlinkCmdDesc, &exampleHandler, EVENT_BLINK);
    CommandInterpreterThread cmdIntThreadFTDI = CommandInterpreterThread(&interpreter, 32, &usartFTDI, "I12", 128, configNORMAL_PRIORITY);

    PinChangeController pinChangeController = PinChangeController();
    pinChangeController.registerOnPinChangeListener(&exampleHandler, &PORTD, PIN2_bm, PORT_OPC_TOTEM_gc, PORT_ISC_RISING_gc);

    // ****** Start stand-alone tasks
    SpiSlaveThread spiSlaveThread = SpiSlaveThread(&spiSlave, &usartFTDI, "SLV", 128, configLOW_PRIORITY);

    /* Start scheduler. Creates idle task and returns if failed to create it.
     * vTaskStartScheduler never returns during normal operation. It is unlikely that XMEGA port will need to
     * dynamically create tasks or queues. To ensure stable work, create ALL tasks and ALL queues before
     * vTaskStartScheduler call.
     * Interrupts would be enabled by calling PMIC_EnableLowLevel();*/
    vTaskStartScheduler();

    /* Should never get here, stop execution and report error */
    while(true) ledRGB.set(PINK);
    return 0;
}
示例#29
0
int main(void)
{
xTimerHandle xExampleSoftwareTimer = NULL;

	/* Configure the system ready to run the demo.  The clock configuration
	can be done here if it was not done before main() was called. */
	prvSetupHardware();


	/* Create the queue used by the queue send and queue receive tasks.
	http://www.freertos.org/a00116.html */
	xQueue = xQueueCreate( 	mainQUEUE_LENGTH,		/* The number of items the queue can hold. */
							sizeof( uint32_t ) );	/* The size of each item the queue holds. */
	/* Add to the registry, for the benefit of kernel aware debugging. */
	vQueueAddToRegistry( xQueue, ( signed char * ) "MainQueue" );


	/* Create the semaphore used by the FreeRTOS tick hook function and the
	event semaphore task. */
	vSemaphoreCreateBinary( xEventSemaphore );
	/* Add to the registry, for the benefit of kernel aware debugging. */
	vQueueAddToRegistry( xEventSemaphore, ( signed char * ) "xEventSemaphore" );


	/* Create the queue receive task as described in the comments at the top
	of this	file.  http://www.freertos.org/a00125.html */
	xTaskCreate( 	prvQueueReceiveTask,			/* The function that implements the task. */
					( signed char * ) "Rx", 		/* Text name for the task, just to help debugging. */
					configMINIMAL_STACK_SIZE, 		/* The size (in words) of the stack that should be created for the task. */
					NULL, 							/* A parameter that can be passed into the task.  Not used in this simple demo. */
					mainQUEUE_RECEIVE_TASK_PRIORITY,/* The priority to assign to the task.  tskIDLE_PRIORITY (which is 0) is the lowest priority.  configMAX_PRIORITIES - 1 is the highest priority. */
					NULL );							/* Used to obtain a handle to the created task.  Not used in this simple demo, so set to NULL. */


	/* Create the queue send task in exactly the same way.  Again, this is
	described in the comments at the top of the file. */
	xTaskCreate( 	prvQueueSendTask,
					( signed char * ) "TX",
					configMINIMAL_STACK_SIZE,
					NULL,
					mainQUEUE_SEND_TASK_PRIORITY,
					NULL );


	/* Create the task that is synchronised with an interrupt using the
	xEventSemaphore semaphore. */
	xTaskCreate( 	prvEventSemaphoreTask,
					( signed char * ) "Sem",
					configMINIMAL_STACK_SIZE,
					NULL,
					mainEVENT_SEMAPHORE_TASK_PRIORITY,
					NULL );


	/* Create the software timer as described in the comments at the top of
	this file.  http://www.freertos.org/FreeRTOS-timers-xTimerCreate.html. */
	xExampleSoftwareTimer = xTimerCreate( 	( const signed char * ) "LEDTimer", /* A text name, purely to help debugging. */
								mainSOFTWARE_TIMER_PERIOD_MS,		/* The timer period, in this case 1000ms (1s). */
								pdTRUE,								/* This is a periodic timer, so xAutoReload is set to pdTRUE. */
								( void * ) 0,						/* The ID is not used, so can be set to anything. */
								vExampleTimerCallback				/* The callback function that switches the LED off. */
							);

	/* Start the created timer.  A block time of zero is used as the timer
	command queue cannot possibly be full here (this is the first timer to
	be created, and it is not yet running).
	http://www.freertos.org/FreeRTOS-timers-xTimerStart.html */
	xTimerStart( xExampleSoftwareTimer, 0 );

	/* Start the tasks and timer running. */
	vTaskStartScheduler();

	/* If all is well, the scheduler will now be running, and the following line
	will never be reached.  If the following line does execute, then there was
	insufficient FreeRTOS heap memory available for the idle and/or timer tasks
	to be created.  See the memory management section on the FreeRTOS web site
	for more details.  http://www.freertos.org/a00111.html */
	for( ;; );
}
示例#30
0
/*! \brief Main function. Execution starts here.
 *
 * \retval 42 Fatal error.
 */
int main(void)
{
  // Configure system clocks.
  if (pcl_configure_clocks(&pcl_freq_param) != PASS)
    return 42;

  // Initialize usart comm
  init_dbg_rs232(pcl_freq_param.pba_f);

#ifndef FREERTOS_USED
# if (defined __GNUC__)
  // Give the used CPU clock frequency to Newlib, so it can work properly.
  set_cpu_hz(pcl_freq_param.pba_f);
# endif
#endif

  // Initialize USB clock.
  pcl_configure_usb_clock();

  // Initialize USB task
  usb_task_init();

  // Display a welcome banner on USART
  printf("                                                       ......       ......     \r\n");
  printf("       IIIIII  IIIII        IIII   IIIIIIIIIII      IIIIIIIIIII. .IIIIIIIIII.  \r\n");
  printf("      IIIIIII   IIIII      IIIII  IIIIIIIIIIIII     IIIIIIIIIIII..IIIIIIIIIII. \r\n");
  printf("     IIIIIIIII  IIIII     IIIII   IIIII   IIIII     I.      IIIII.:.     IIIII \r\n");
  printf("     IIII IIIII  IIIII    IIII   IIIII    IIIII            .IIII.        IIIII \r\n");
  printf("    IIIII  IIII   IIII   IIIII  IIIIIIIIIIIIII         IIIIIIII          IIII. \r\n");
  printf("    IIII   IIIII  IIIII IIIII   IIIIIIIIIIIII          IIIIIIII.       .IIII:  \r\n");
  printf("   IIIII    IIIII  IIIIIIIII   IIIIIIIIIII                 .IIIII     IIIII.   \r\n");
  printf("  IIIIIIIIIIIIIII   IIIIIIII   IIIII IIIII                  .IIII   .IIII:     \r\n");
  printf("  IIIIIIIIIIIIIIII  IIIIIII   IIIII   IIII         II:.    .IIIII .IIIII.      \r\n");
  printf(" IIIII        IIIII  IIIIII  IIIII    IIIII        IIIIIIIIIIIII.IIIIIIIIIIIIII\r\n");
  printf(" IIIII        IIIII  IIIII   IIIII    IIIII        :IIIIIIIIII.  IIIIIIIIIIIIII\r\n");
  printf("                      III                                                      \r\n");
  printf("                       II                                                      \r\n");

#if USB_DEVICE_FEATURE == true
  // Initialize device CDC USB task
  device_cdc_task_init();
#endif
#if USB_HOST_FEATURE == true
  // Initialize host CDC USB task
  host_cdc_task_init();
#endif

#ifdef FREERTOS_USED
  // Start OS scheduler
  vTaskStartScheduler();
  portDBG_TRACE("FreeRTOS returned.");
  return 42;
#else
  // No OS here. Need to call each task in round-robin mode.
  while (true)
  {
    usb_task();
  #if USB_DEVICE_FEATURE == true
    device_cdc_task();
  #endif
  #if USB_HOST_FEATURE == true
    host_cdc_task();
  #endif
  }
#endif  // FREERTOS_USED
}