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

📄 main.c

📁 超好的嵌入式操作系统学习代码
💻 C
📖 第 1 页 / 共 2 页
字号:
	vSetupTimer();
	
	/* Start the scheduler. */
	vTaskStartScheduler();

    /* Will only get here if there was insufficient memory to create the idle
    task. */
	return 0;
}
/*-----------------------------------------------------------*/

void prvSetupHardware( void )
{
    /* If running on Rev A2 silicon, turn the LDO voltage up to 2.75V.  This is
    a workaround to allow the PLL to operate reliably. */
    if( DEVICE_IS_REVA2 )
    {
        SysCtlLDOSet( SYSCTL_LDO_2_75V );
    }
	
	/* Set the clocking to run from the PLL at 50 MHz */
	SysCtlClockSet( SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ );
	
	/* 	Enable Port F for Ethernet LEDs
		LED0        Bit 3   Output
		LED1        Bit 2   Output */
	SysCtlPeripheralEnable( SYSCTL_PERIPH_GPIOF );
	GPIODirModeSet( GPIO_PORTF_BASE, (GPIO_PIN_2 | GPIO_PIN_3), GPIO_DIR_MODE_HW );
	GPIOPadConfigSet( GPIO_PORTF_BASE, (GPIO_PIN_2 | GPIO_PIN_3 ), GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD );	
	
	vParTestInitialise();
}
/*-----------------------------------------------------------*/

void vApplicationTickHook( void )
{
static xOLEDMessage xMessage = { "PASS" };
static unsigned portLONG ulTicksSinceLastDisplay = 0;

	/* Called from every tick interrupt.  Have enough ticks passed to make it
	time to perform our health status check again? */
	ulTicksSinceLastDisplay++;
	if( ulTicksSinceLastDisplay >= mainCHECK_DELAY )
	{
		ulTicksSinceLastDisplay = 0;
		
		/* Has an error been found in any task? */
		if( xAreGenericQueueTasksStillRunning() != pdTRUE )
		{
			xMessage.pcMessage = "ERROR IN GEN Q";
		}
		else if( xAreQueuePeekTasksStillRunning() != pdTRUE )
		{
			xMessage.pcMessage = "ERROR IN PEEK Q";
		}
		else if( xAreBlockingQueuesStillRunning() != pdTRUE )
		{
			xMessage.pcMessage = "ERROR IN BLOCK Q";
		}
		else if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
		{
			xMessage.pcMessage = "ERROR IN BLOCK TIME";
		}
	    else if( xAreSemaphoreTasksStillRunning() != pdTRUE )
	    {
	        xMessage.pcMessage = "ERROR IN SEMAPHORE";
	    }
	    else if( xArePollingQueuesStillRunning() != pdTRUE )
	    {
	        xMessage.pcMessage = "ERROR IN POLL Q";
	    }
	    else if( xIsCreateTaskStillRunning() != pdTRUE )
	    {
	        xMessage.pcMessage = "ERROR IN CREATE";
	    }
	    else if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
	    {
	        xMessage.pcMessage = "ERROR IN MATH";
	    }
		else if( ulIdleError != pdFALSE )
		{
			xMessage.pcMessage = "ERROR IN HOOK";
		}

		/* Send the message to the OLED gatekeeper for display. */
		xQueueSendFromISR( xOLEDQueue, &xMessage, pdFALSE );
	}
}
/*-----------------------------------------------------------*/

void vOLEDTask( void *pvParameters )
{
xOLEDMessage xMessage;
unsigned portLONG ulY, ulMaxY;
static portCHAR cMessage[ mainMAX_MSG_LEN ];
extern unsigned portLONG ulMaxJitter;

/* Functions to access the OLED.  The one used depends on the dev kit
being used. */
void ( *vOLEDInit )( unsigned portLONG );
void ( *vOLEDStringDraw )( const portCHAR *, unsigned portLONG, unsigned portLONG, unsigned portCHAR );
void ( *vOLEDImageDraw )( const unsigned portCHAR *, unsigned portLONG, unsigned portLONG, unsigned portLONG, unsigned portLONG );
void ( *vOLEDClear )( void );

	/* Map the OLED access functions to the driver functions that are appropriate
	for the evaluation kit being used. */	
	switch( HWREG( SYSCTL_DID1 ) & SYSCTL_DID1_PRTNO_MASK )
	{
		case SYSCTL_DID1_PRTNO_6965	:	 
		case SYSCTL_DID1_PRTNO_2965	:	vOLEDInit = OSRAM128x64x4Init;
										vOLEDStringDraw = OSRAM128x64x4StringDraw;
										vOLEDImageDraw = OSRAM128x64x4ImageDraw;
										vOLEDClear = OSRAM128x64x4Clear;
										ulMaxY = mainMAX_ROWS_64;
										break;
										
		default						:	vOLEDInit = RIT128x96x4Init;
										vOLEDStringDraw = RIT128x96x4StringDraw;
										vOLEDImageDraw = RIT128x96x4ImageDraw;
										vOLEDClear = RIT128x96x4Clear;
										ulMaxY = mainMAX_ROWS_96;										
										break;
	}

	ulY = ulMaxY;
	
	/* Initialise the OLED and display a startup message. */
	vOLEDInit( ulSSI_FREQUENCY );	
	vOLEDStringDraw( " POWERED BY FreeRTOS", 0, 0, mainFULL_SCALE );
	vOLEDImageDraw( pucImage, 0, mainCHARACTER_HEIGHT + 1, bmpBITMAP_WIDTH, bmpBITMAP_HEIGHT );
	
	for( ;; )
	{
		/* Wait for a message to arrive that requires displaying. */
		xQueueReceive( xOLEDQueue, &xMessage, portMAX_DELAY );
	
		/* Write the message on the next available row. */
		ulY += mainCHARACTER_HEIGHT;
		if( ulY >= ulMaxY )
		{
			ulY = mainCHARACTER_HEIGHT;
			vOLEDClear();
			vOLEDStringDraw( pcWelcomeMessage, 0, 0, mainFULL_SCALE );			
		}

		/* Display the message along with the maximum jitter time from the 
		high priority time test. */
		sprintf( cMessage, "%s [%uns]", xMessage.pcMessage, ulMaxJitter * mainNS_PER_CLOCK );
		vOLEDStringDraw( cMessage, 0, ulY, mainFULL_SCALE );
	}
}
/*-----------------------------------------------------------*/

void vApplicationIdleHook( void )
{
	/* This is just a sanity check function to test the port is
	functioning correctly.  It can be removed from real applications.
	
	Fill the general purpose registers with known values. */
	__asm volatile( "    mov r11, #10		\n"
					"    add r0, r11, #1	\n"
					"    add r1, r11, #2	\n"
		            "    add r2, r11, #3	\n"
		            "    add r3, r11, #4	\n"
		            "    add r4, r11, #5	\n"
		            "    add r5, r11, #6	\n"
		            "    add r6, r11, #7	\n"
		            "    add r7, r11, #8	\n"
		            "    add r8, r11, #9	\n"
		            "    add r9, r11, #10	\n"
		            "    add r10, r11, #11	\n"
		            "    add r12, r11, #12" );
	
	/* Check the values are as expected.  A context switch might
	have occurred since setting the register values. */
	__asm volatile( "    cmp r11, #10			\n"
		            "    bne set_error_flag		\n"
		            "    cmp r0, #11			\n"
		            "    bne set_error_flag		\n"
		            "    cmp r1, #12			\n"
		            "    bne set_error_flag		\n"
		            "    cmp r2, #13			\n"
		            "    bne set_error_flag		\n"
		            "    cmp r3, #14			\n"
		            "    bne set_error_flag		\n"
		            "    cmp r4, #15			\n"
		            "    bne set_error_flag		\n"
		            "    cmp r5, #16			\n"
		            "    bne set_error_flag		\n"
		            "    cmp r6, #17			\n"
		            "    bne set_error_flag		\n"
		            "    cmp r7, #18			\n"
		            "    bne set_error_flag		\n"
		            "    cmp r8, #19			\n"
		            "    bne set_error_flag		\n"
		            "    cmp r9, #20			\n"
		            "    bne set_error_flag		\n"
		            "    cmp r10, #21			\n"
		            "    bne set_error_flag		\n"
		            "    cmp r12, #22			\n"
		            "    bne set_error_flag		\n"
					"	 bx r14 				\n"
					" 							\n"	/* If an error is detected in the */					
					"set_error_flag:			\n" /* value of a register then the error */
					"	ldr r1, ulIdleErrorConst\n" /* variable will be set to true.  This */
					"	mov r0, #1				\n" /* will cause	an error message to be */
					"	str r0, [r1]			\n" /* written to the OLED. */
					"	bx r14 					\n"
					"							\n"
					"	.align 2				\n"			
					"ulIdleErrorConst: .word ulIdleError" );
}



⌨️ 快捷键说明

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