⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 FreeRTOS操作系统源码V3.2
💻 C
📖 第 1 页 / 共 2 页
字号:
	/* Ensure the clock is stable. */
	for( usWait = 0; usWait < usWaitTime; usWait++ );

	/* Setup the clock source for the PLL. */
	PLL0CN &= ~mainPLL_USES_INTERNAL_OSC;

	/* Change the read timing for the flash ready for the fast clock. */
	SFRPAGE = LEGACY_PAGE;
	FLSCL |= mainFLASH_READ_TIMING;

	/* Turn on the PLL power. */
	SFRPAGE = CONFIG_PAGE;
	PLL0CN |= mainPLL_POWER_ON;

	/* Don't predivide the clock. */
	PLL0DIV = mainPLL_NO_PREDIVIDE;

	/* Set filter for fastest clock. */
	PLL0FLT = mainPLL_FILTER;
	PLL0MUL = mainPLL_MULTIPLICATION;

	/* Ensure the clock is stable. */
	for( usWait = 0; usWait < usWaitTime; usWait++ );

	/* Enable the PLL and wait for it to lock. */
	PLL0CN |= mainENABLE_PLL;
	for( usWait = 0; usWait < usWaitTime; usWait++ )
	{
		if( PLL0CN & mainPLL_LOCKED )
		{
			break;
		}
	}

	/* Select the PLL as the clock source. */
	CLKSEL |= mainSELECT_PLL_AS_SOURCE;

	/* Return the SFR back to its original value. */
	SFRPAGE = ucOriginalSFRPage;
}
/*-----------------------------------------------------------*/

static void prvToggleOnBoardLED( void )
{
	/* If the on board LED is on, turn it off and visa versa. */
	if( P1 & ucLED_BIT )
	{
		P1 &= ~ucLED_BIT;
	}
	else
	{
		P1 |= ucLED_BIT;
	}
}
/*-----------------------------------------------------------*/

/*
 * See the documentation at the top of this file. 
 */
static void vErrorChecks( void *pvParameters )
{
portBASE_TYPE xErrorHasOccurred = pdFALSE;
	
	/* Just to prevent compiler warnings. */
	( void ) pvParameters;
	
	/* Cycle for ever, delaying then checking all the other tasks are still
	operating without error.   The delay period depends on whether an error
	has ever been detected. */
	for( ;; )
	{
		if( xLatchedError == pdFALSE )
		{		
			/* No errors have been detected so delay for a longer period.  The
			on board LED will get toggled every mainNO_ERROR_FLASH_PERIOD ms. */
			vTaskDelay( mainNO_ERROR_FLASH_PERIOD );
		}
		else
		{
			/* We have at some time recognised an error in one of the demo
			application tasks, delay for a shorter period.  The on board LED
			will get toggled every mainERROR_FLASH_PERIOD ms. */
			vTaskDelay( mainERROR_FLASH_PERIOD );
		}

		
		
		/* Check the demo application tasks for errors. */

		if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
		{
			xErrorHasOccurred = pdTRUE;
		}

		if( xArePollingQueuesStillRunning() != pdTRUE )
		{
			xErrorHasOccurred = pdTRUE;
		}

		if( xAreComTestTasksStillRunning() != pdTRUE )
		{
			xErrorHasOccurred = pdTRUE;
		}

		if( xAreSemaphoreTasksStillRunning() != pdTRUE )
		{
			xErrorHasOccurred = pdTRUE;
		}

		/* If an error has occurred, latch it to cause the LED flash rate to 
		increase. */
		if( xErrorHasOccurred == pdTRUE )
		{
			xLatchedError = pdTRUE;
		}

		/* Toggle the LED to indicate the completion of a check cycle.  The
		frequency of check cycles is dependent on whether or not we have 
		latched an error. */
		prvToggleOnBoardLED();
	}
}
/*-----------------------------------------------------------*/

/*
 * See the documentation at the top of this file.  Also see the standard FLOP
 * demo task documentation for the rationale of these tasks.
 */
static void vFLOPCheck1( void *pvParameters )
{
volatile portFLOAT fVal1, fVal2, fResult;

	( void ) pvParameters;

	for( ;; )
	{
		fVal1 = ( portFLOAT ) -1234.5678;
		fVal2 = ( portFLOAT ) 2345.6789;

		fResult = fVal1 + fVal2;
		if( ( fResult > ( portFLOAT )  1111.15 ) || ( fResult < ( portFLOAT ) 1111.05 ) )
		{
			mainLATCH_ERROR();
		}

		fResult = fVal1 / fVal2;
		if( ( fResult > ( portFLOAT ) -0.51 ) || ( fResult < ( portFLOAT ) -0.53 ) )
		{
			mainLATCH_ERROR();
		}
	}
}
/*-----------------------------------------------------------*/

/*
 * See the documentation at the top of this file.
 */
static void vFLOPCheck2( void *pvParameters )
{
volatile portFLOAT fVal1, fVal2, fResult;

	( void ) pvParameters;

	for( ;; )
	{
		fVal1 = ( portFLOAT ) -12340.5678;
		fVal2 = ( portFLOAT ) 23450.6789;

		fResult = fVal1 + fVal2;
		if( ( fResult > ( portFLOAT ) 11110.15 ) || ( fResult < ( portFLOAT ) 11110.05 ) )
		{
			mainLATCH_ERROR();
		}

		fResult = fVal1 / -fVal2;
		if( ( fResult > ( portFLOAT ) 0.53 ) || ( fResult < ( portFLOAT ) 0.51 ) )
		{
			mainLATCH_ERROR();
		}
	}
}
/*-----------------------------------------------------------*/

/*
 * See the documentation at the top of this file. 
 */
static void vRegisterCheck( void *pvParameters )
{
	( void ) pvParameters;

	for( ;; )
	{
		if( SP != configSTACK_START )
		{
			mainLATCH_ERROR();
		}

		_asm
			MOV ACC, ar0
		_endasm;

		if( ACC != 0 )
		{
			mainLATCH_ERROR();
		}

		_asm
			MOV ACC, ar1
		_endasm;

		if( ACC != 1 )
		{
			mainLATCH_ERROR();
		}
		_asm
			MOV ACC, ar2
		_endasm;

		if( ACC != 2 )
		{
			mainLATCH_ERROR();
		}
		_asm
			MOV ACC, ar3
		_endasm;

		if( ACC != 3 )
		{
			mainLATCH_ERROR();
		}
		_asm
			MOV ACC, ar4
		_endasm;

		if( ACC != 4 )
		{
			mainLATCH_ERROR();
		}
		_asm
			MOV ACC, ar5
		_endasm;

		if( ACC != 5 )
		{
			mainLATCH_ERROR();
		}
		_asm
			MOV ACC, ar6
		_endasm;

		if( ACC != 6 )
		{
			mainLATCH_ERROR();
		}
		_asm
			MOV ACC, ar7
		_endasm;

		if( ACC != 7 )
		{
			mainLATCH_ERROR();
		}

		if( DPL != 0xcd )
		{
			mainLATCH_ERROR();
		}

		if( DPH != 0xab )
		{
			mainLATCH_ERROR();
		}

		if( B != 0x01 )
		{
			mainLATCH_ERROR();
		}			
	}
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -