コード例 #1
0
void vtHandleFatalError(int code,int line,char file[]) {
	static unsigned int delayCounter = 0;
	// There are lots of ways you can (and may want to) handle a fatal error
	// In this implementation, I suspend tasks and then flash the LEDs.  Note that the stop may not be
	//   immediate because this task has to be scheduled first for that to happen.  In fact, one task might
	//   call this while another tries to get into 
	taskENTER_CRITICAL();
	taskDISABLE_INTERRUPTS();
	/* LEDs on ports 1 and 2 to output (1). */
	// Note that all LED access is through the proper LPC library calls (or my own routines that call them)
	vtInitLED();
	for (;;) {
		// Silly delay loop, but we really don't have much choice here w/o interrupts and FreeRTOS...
		// This won't be okay to do *anywhere* else in your code
		for (delayCounter=0;delayCounter<10000000;delayCounter++) {
		}
		// Turn off half and on half
		vtLEDOn(0xAA);
		vtLEDOff(0x55);
		// Delay again
		for (delayCounter=0;delayCounter<10000000;delayCounter++) {
		}
		// Toggle
		vtLEDOff(0xAA);
		vtLEDOn(0x55);
		// Here is some dumb code to make sure that the three input parameters are not optimized away by the compiler
		if ((code < -55) && (line < -55) && (file == NULL)) {
			vtLEDOff(0x0); // We won't get here
		}
		// End of dumb code
	}
	// We will never get here
	taskEXIT_CRITICAL();
}
コード例 #2
0
int main()
{
	// Initialize system.
	init_syscalls();

	// Set up the LED ports.
	vtInitLED();

	// Set up hardware.
	setupHardware();

    // Buffer for events messages.
    char eventsMsg[QUEUE_BUF_LEN_LCD];

	// LCD task.
	startTaskLCD(&dataLCD, LCD_TASK_PRIORITY);
	startTimerLCD(&dataLCD);

    // Debug - initialize base.
    sendValueMsgLCD(&dataLCD, MSG_TYPE_LCD_EVENTS, QUEUE_BUF_LEN_LCD, "Initializing system", portMAX_DELAY);
    sendValueMsgLCD(&dataLCD, MSG_TYPE_LCD_EVENTS, QUEUE_BUF_LEN_LCD, "Initializing LEDs", portMAX_DELAY);
    sendValueMsgLCD(&dataLCD, MSG_TYPE_LCD_EVENTS, QUEUE_BUF_LEN_LCD, "Initializing hardware", portMAX_DELAY);

    sprintf(eventsMsg, "Starting %s", taskNameLCD);
    sendValueMsgLCD(&dataLCD, MSG_TYPE_LCD_EVENTS, QUEUE_BUF_LEN_LCD, eventsMsg, portMAX_DELAY);

    sprintf(eventsMsg, "Starting %s", timerNameLCD);
    sendValueMsgLCD(&dataLCD, MSG_TYPE_LCD_EVENTS, QUEUE_BUF_LEN_LCD, eventsMsg, portMAX_DELAY);
	
	// I2C task.
    sprintf(eventsMsg, "Starting %s", taskNameI2C);
    sendValueMsgLCD(&dataLCD, MSG_TYPE_LCD_EVENTS, QUEUE_BUF_LEN_LCD, eventsMsg, portMAX_DELAY);
	if(vtI2CInit(&vtI2C0, 0, MONITOR_TASK_PRIORITY, I2C_BITRATE) != vtI2CInitSuccess)
    {
        sprintf(eventsMsg, "Unable to create queue for %s", taskNameI2C);
        sendValueMsgLCD(&dataLCD, MSG_TYPE_LCD_EVENTS, QUEUE_BUF_LEN_LCD, eventsMsg, portMAX_DELAY);
		VT_HANDLE_FATAL_ERROR(0);
    }
        
    // Command task.
    sprintf(eventsMsg, "Starting %s", taskNameCommand);
    sendValueMsgLCD(&dataLCD, MSG_TYPE_LCD_EVENTS, QUEUE_BUF_LEN_LCD, eventsMsg, portMAX_DELAY);
	startTaskCommand(&dataCommand, COMMAND_TASK_PRIORITY, &vtI2C0, &dataLCD);
    sprintf(eventsMsg, "Starting %s", timerNameCommand);
    sendValueMsgLCD(&dataLCD, MSG_TYPE_LCD_EVENTS, QUEUE_BUF_LEN_LCD, eventsMsg, portMAX_DELAY);
	startTimerCommand(&dataCommand);

    // Locate task.
    sprintf(eventsMsg, "Starting %s", taskNameLocate);
    sendValueMsgLCD(&dataLCD, MSG_TYPE_LCD_EVENTS, QUEUE_BUF_LEN_LCD, eventsMsg, portMAX_DELAY);
	startTaskLocate(&dataLocate, SENSOR_TASK_PRIORITY, &dataLCD, &dataCommand);
    sprintf(eventsMsg, "Starting %s", timerNameLocate);
    sendValueMsgLCD(&dataLCD, MSG_TYPE_LCD_EVENTS, QUEUE_BUF_LEN_LCD, eventsMsg, portMAX_DELAY);
	startTimerLocate(&dataLocate);

	// Sensors task.
    sprintf(eventsMsg, "Starting %s", taskNameSensors);
    sendValueMsgLCD(&dataLCD, MSG_TYPE_LCD_EVENTS, QUEUE_BUF_LEN_LCD, eventsMsg, portMAX_DELAY);
	startTaskSensors(&dataSensors, SENSOR_TASK_PRIORITY, &vtI2C0, &dataLCD, &dataLocate);
    sprintf(eventsMsg, "Starting %s", timerNameSensors);
    sendValueMsgLCD(&dataLCD, MSG_TYPE_LCD_EVENTS, QUEUE_BUF_LEN_LCD, eventsMsg, portMAX_DELAY);
	startTimerSensors(&dataSensors);

    // Conductor task.
    sprintf(eventsMsg, "Starting %s", taskNameConductor);
    sendValueMsgLCD(&dataLCD, MSG_TYPE_LCD_EVENTS, QUEUE_BUF_LEN_LCD, eventsMsg, portMAX_DELAY);
	startTaskConductor(&dataConductor, CONDUCTOR_TASK_PRIORITY, &vtI2C0, &dataLCD, &dataSensors, &dataLocate);

	// Schedlar task.
    sprintf(eventsMsg, "Starting %s", taskNameScheduler);
    sendValueMsgLCD(&dataLCD, MSG_TYPE_LCD_EVENTS, QUEUE_BUF_LEN_LCD, eventsMsg, portMAX_DELAY);
	vTaskStartScheduler();
    
    // Shouldn't reach this part unless insufficient memory.
	for(;;);
}
コード例 #3
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

	// 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 );

	// MTJ: My LCD demonstration task
	#if USE_MTJ_LCD == 1
	vStartLCDTask( mainLCD_TASK_PRIORITY,&vtLCDdata);
	#endif

	// MTJ: My i2cTemp demonstration task
	#if USE_MTJ_V4Temp_Sensor == 1
	vtI2C0.devNum = 0;
	vtI2C0.taskPriority = mainI2CMONITOR_TASK_PRIORITY;
	// Initialize I2C0 
	int retVal;
	if ((retVal = vtI2CInit(&vtI2C0,100000)) != vtI2CInitSuccess) {
		VT_HANDLE_FATAL_ERROR(retVal);
	}
	tempSensorParams.dev = &vtI2C0;
	#if USE_MTJ_LCD == 1
	tempSensorParams.lcdData = &vtLCDdata;
	#else
	tempSensorParams.lcdData = NULL;
	#endif
	//vStarti2cTempTask(mainI2CTEMP_TASK_PRIORITY,&tempSensorParams);
	vStartSomeTask(mainI2CTEMP_TASK_PRIORITY, &tempSensorParams);
	#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...) writtenover
	//            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( ;; );
}
コード例 #4
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( ;; );
}
コード例 #5
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_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

	vStartLCDTask(&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.

	// 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);
	}

	// start up a "conductor" task that will move messages around
	vStartConductorTask(&conductorData,mainCONDUCTOR_TASK_PRIORITY,&vtI2C0,&i2cData,&motorControl,&irData,&speedData,&powerData,&vtLCDdata);

    // Start the I2C task
    starti2cTask(&i2cData,mainI2C_TASK_PRIORITY,&vtI2C0);
    // Start the Motor Control task
    vStartMotorControlTask(&motorControl,mainMOTOR_CONTROL_TASK_PRIORITY,&i2cData,&webData,&vtLCDdata);
    // Start the Navigation task
    vStartNavigationTask(&navData,mainNAVIGATION_TASK_PRIORITY,&motorControl,&vtLCDdata);
    // Start the IR Control task
    vStartIRTask(&irData,mainIR_CONTROL_TASK_PRIORITY,&navData);
    // Start the Speed Limit task
    vStartSpeedLimitTask(&speedData,mainSPEED_LIMIT_TASK_PRIORITY,&motorControl,&navData,&webData);

    startTimerFori2c(&i2cData);
    //startTimerForMotor(&motorControl);

    /* 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( ;; );
}