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

📄 10cab7d0b5c1001d10f4c581ea524f65

📁 基于FREERtos和LPC2468的程序。里面实现了串口通信
💻
📖 第 1 页 / 共 2 页
字号:
  EMC_DYN_RFSH = 0x00000002;
  for(i = 0; i < 0x40; i++);	/* wait 128 AHB clock cycles */
    
  /* set 28 x 16CCLKs=448CCLK=7us between SDRAM refresh cycles */
  EMC_DYN_RFSH = 28;
    
  /* To set mode register in SDRAM, enter mode by issue
  MODE command, after finishing, bailout and back to NORMAL mode. */    
  /* Mem clock enable, CLKOUT runs, send command: MODE */
  EMC_DYN_CTRL = 0x00000083;
  
  /* Set mode register in SDRAM */
  /* Mode regitster table for Micron's MT48LCxx */
  /* bit 9:   Programmed burst length(0)
     bit 8~7: Normal mode(0)
	 bit 6~4: CAS latency 3
	 bit 3:   Sequential(0)
	 bit 2~0: Burst length is 8
	 row position is 12 */
  dummy = *((volatile DWORD *)(SDRAM_BASE_ADDR | (0x33 << 12)));
  
  EMC_DYN_CTRL = 0x00000000;	  /* Send command: NORMAL */

  EMC_DYN_CFG0 |= 0x00080000;	  /* Enable buffer */
  delayMs(1);				  /* Use timer 1 */

/****************************************************************
   * Initialize EMC for CS2
   ****************************************************************/
 
  // Initialize EMC for CS2
  EMC_STA_CFG2 = 0x00000080;	/* 16 bit, byte lane state, BLSn[3:0] are low. */ 
//	EMC_STA_CFG2 = 0x00000080;  /* the bus of my Lcd is 8bit width	 */
//  EMC_STA_CFG2 = 0x00000000;		
  EMC_STA_WAITWEN2 = 0x2;		/* WE delay 2(n+1)CCLK */
  EMC_STA_WAITOEN2 = 0x4;		/* OE delay, 2(n)CCLK */
  EMC_STA_WAITRD2 = 0x10;		/* RD delay, 17(n+1)CCLK */ 
  EMC_STA_WAITPAGE2 = 0x1F;		/* Page mode read delay, 32CCLK(default) */
  EMC_STA_WAITWR2 = 0x8;		/* Write delay, 10(n+2)CCLK */
  EMC_STA_WAITTURN2 = 0x5;		/* Turn arounc delay, 5(n+1)CCLK */

  EMC_STA_EXT_WAIT = 0x0;		/* Extended wait time, 16CCLK */
  delayMs(1);				  /* Use timer 1 */
  return;

}
/******************************************************************************
** Function name:		ConfigurePLL
**
** Descriptions:		Configure PLL switching to main OSC instead of IRC
**						at power up and wake up from power down. 
**						This routine is used in TargetResetInit() and those
**						examples using power down and wake up such as
**						USB suspend to resume, ethernet WOL, and power management
**						example
** parameters:			None
** Returned value:		None
** 
******************************************************************************/
void xConfigurePLL ( void )
{
  unsigned int  MValue, NValue;

  if ( PLLSTAT & (1 << 25) )
  {
	PLLCON = 1;			/* Enable PLL, disconnected */
	PLLFEED = 0xaa;
	PLLFEED = 0x55;
  }

  PLLCON = 0;				/* Disable PLL, disconnected */
  PLLFEED = 0xaa;
  PLLFEED = 0x55;
    
  SCS |= 0x20;			/* Enable main OSC */
  while( !(SCS & 0x40) );	/* Wait until main OSC is usable */

  CLKSRCSEL = 0x1;		/* select main OSC, 12MHz, as the PLL clock source */

  PLLCFG = PLL_MValue | (PLL_NValue << 16);
  PLLFEED = 0xaa;
  PLLFEED = 0x55;
      
  PLLCON = 1;				/* Enable PLL, disconnected */
  PLLFEED = 0xaa;
  PLLFEED = 0x55;

  CCLKCFG = CCLKDivValue;	/* Set clock divider */
#if USE_USB
  USBCLKCFG = USBCLKDivValue;		/* usbclk = 288 MHz/6 = 48 MHz */
#endif

  while ( ((PLLSTAT & (1 << 26)) == 0) );	/* Check lock bit status */
    
  MValue = PLLSTAT & 0x00007FFF;
  NValue = (PLLSTAT & 0x00FF0000) >> 16;
  while ((MValue != PLL_MValue) && ( NValue != PLL_NValue) );

  PLLCON = 3;				/* enable and connect */
  PLLFEED = 0xaa;
  PLLFEED = 0x55;
  while ( ((PLLSTAT & (1 << 25)) == 0) );	/* Check connect bit status */
  return;
}

static void prvSetupHardware( void )
{
	//unsigned int Fdiv;
	
	#ifdef RUN_FROM_RAM
		/* Remap the interrupt vectors to RAM if we are are running from RAM. */
		SCB_MEMMAP = 2;
	#endif
	
	/* Configure the RS2332 pins.  All other pins remain at their default of 0. */
		PCB_PINSEL0 |= mainTX_ENABLE;
		PCB_PINSEL0 |= mainRX_ENABLE;
		
		
		  MEMMAP = 0x1;			/* remap to internal flash */
		  PCONP |= 0x80000000;		/* Turn On USB PCLK */
	  /* Configure PLL, switch from IRC to Main OSC */
		  xConfigurePLL();

	  /* Set system timers for each component */
		#if (Fpclk / (Fcclk / 4)) == 1
		  PCLKSEL0 = 0x00000000;	/* PCLK is 1/4 CCLK */
		  PCLKSEL1 = 0x00000000;
		#endif
		#if (Fpclk / (Fcclk / 4)) == 2
		  PCLKSEL0 = 0xAAAAAAAA;	/* PCLK is 1/2 CCLK */
		  PCLKSEL1 = 0xAAAAAAAA;	 
		#endif
		#if (Fpclk / (Fcclk / 4)) == 4
		  PCLKSEL0 = 0x55555555;	/* PCLK is the same as CCLK */
		  PCLKSEL1 = 0x55555555;	
		#endif
	  /* Set memory accelerater module*/
		  MAMCR = 0;
	  


	  /* Setup and turn on the MAM.  Three cycle access is used due to the fast
	  	PLL used.  It is possible faster overall performance could be obtained by
	  	tuning the MAM and PLL settings. */  
		#if Fcclk < 20000000
		  MAMTIM = 1;
		#else  
			#if Fcclk < 40000000
			  MAMTIM = 2;
			#else
			  MAMTIM = 3;
			#endif
		#endif
		  MAMCR = 2;
		 return;
}
/*-----------------------------------------------------------*/
void InitEMC(void)
{
	unsigned int Fdiv;
		PINSEL0 = 0x00000050;       /* RxD0 and TxD0 */

		U0LCR = 0x83;		/* 8 bits, no Parity, 1 Stop bit */
		Fdiv = ( Fpclk / 16 ) / 115200 ;	/*baud rate */
		U0DLM = Fdiv / 256;							
		U0DLL = Fdiv % 256;
		U0LCR = 0x03;		/* DLAB = 0 */
		U0FCR = 0x07;		/* Enable and reset TX and RX FIFO. */
	  
	/* initlialize external bus */
		SDRAMInit();
		IODIR0=LCD_FS;
		IOCLR0=LCD_FS; 
		IODIR1=0x00000004;
		IOSET1=0x00000004;
		return;
}
void prvToggleOnBoardLED( void )
{
	unsigned portLONG ulState;

	ulState = GPIO0_IOPIN;
	if( ulState & mainON_BOARD_LED_BIT )
	{
		GPIO_IOCLR = mainON_BOARD_LED_BIT;
	}
	else
	{
		GPIO_IOSET = mainON_BOARD_LED_BIT;
	}	
}
/*-----------------------------------------------------------*/

static portLONG prvCheckOtherTasksAreStillRunning( unsigned portLONG ulMemCheckTaskCount )
{
portLONG lReturn = ( portLONG ) pdPASS;

	/* Check all the demo tasks (other than the flash tasks) to ensure
	that they are all still running, and that none of them have detected
	an error. */

	/*
	if( xAreComTestTasksStillRunning() != pdTRUE )
	{
		lReturn = ( portLONG ) pdFAIL;
	}
	if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
		{
			lReturn = ( portLONG ) pdFAIL;
		}

	if( xArePollingQueuesStillRunning() != pdTRUE )
	{
		lReturn = ( portLONG ) pdFAIL;
	}

	if( xAreMathsTaskStillRunning() != pdTRUE )
	{
		lReturn = ( portLONG ) pdFAIL;
	}

	if( xAreSemaphoreTasksStillRunning() != pdTRUE )
	{
		lReturn = ( portLONG ) pdFAIL;
	}

	if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
	{
		lReturn = ( portLONG ) pdFAIL;
	}

	if( xAreBlockingQueuesStillRunning() != pdTRUE )
	{
		lReturn = ( portLONG ) pdFAIL;
	}
*/
	if( ulMemCheckTaskCount == mainCOUNT_INITIAL_VALUE )
	{
		/* The vMemCheckTask did not increment the counter - it must
		have failed. */
		lReturn = ( portLONG ) pdFAIL;
	}

	return lReturn;
}
/*-----------------------------------------------------------*/

static void vMemCheckTask( void *pvParameters )
{
	unsigned portLONG *pulMemCheckTaskRunningCounter;
	void *pvMem1, *pvMem2, *pvMem3;
	static portLONG lErrorOccurred = pdFALSE;

	/* This task is dynamically created then deleted during each cycle of the
	vErrorChecks task to check the operation of the memory allocator.  Each time
	the task is created memory is allocated for the stack and TCB.  Each time
	the task is deleted this memory is returned to the heap.  This task itself
	exercises the allocator by allocating and freeing blocks. 
	
	The task executes at the idle priority so does not require a delay. 
	
	pulMemCheckTaskRunningCounter is incremented each cycle to indicate to the
	vErrorChecks() task that this task is still executing without error. */

	pulMemCheckTaskRunningCounter = ( unsigned portLONG * ) pvParameters;

	for( ;; )
	{
		if( lErrorOccurred == pdFALSE )
		{
			/* We have never seen an error so increment the counter. */
			( *pulMemCheckTaskRunningCounter )++;
		}

		/* Allocate some memory - just to give the allocator some extra 
		exercise.  This has to be in a critical section to ensure the
		task does not get deleted while it has memory allocated. */
		vTaskSuspendAll();
		{
			pvMem1 = pvPortMalloc( mainMEM_CHECK_SIZE_1 );
			if( pvMem1 == NULL )
			{
				lErrorOccurred = pdTRUE;
			}
			else
			{
				memset( pvMem1, 0xaa, mainMEM_CHECK_SIZE_1 );
				vPortFree( pvMem1 );
			}
		}
		xTaskResumeAll();

		/* Again - with a different size block. */
		vTaskSuspendAll();
		{
			pvMem2 = pvPortMalloc( mainMEM_CHECK_SIZE_2 );
			if( pvMem2 == NULL )
			{
				lErrorOccurred = pdTRUE;
			}
			else
			{
				memset( pvMem2, 0xaa, mainMEM_CHECK_SIZE_2 );
				vPortFree( pvMem2 );
			}
		}
		xTaskResumeAll();

		/* Again - with a different size block. */
		vTaskSuspendAll();
		{
			pvMem3 = pvPortMalloc( mainMEM_CHECK_SIZE_3 );
			if( pvMem3 == NULL )
			{
				lErrorOccurred = pdTRUE;
			}
			else
			{
				memset( pvMem3, 0xaa, mainMEM_CHECK_SIZE_3 );
				vPortFree( pvMem3 );
			}
		}
		xTaskResumeAll();
	}
}
/*-----------------------------------------------------------*/
//extern void LCD_BackLight(int onoff);
extern struct CmdRcv CmdRcvIrq;
#define TICK_STACK_SIZE		configMINIMAL_STACK_SIZE
/*-----------------------------------------------------------*/
/*-----------------------------------------------------------
 * function : vStartTICKINCTasks and vTINCTask
 * specification : create a task to increasing the ticks which used 
 * 				in others functions 
 * parameters : uxPriority ,
 * ----------------------------------------------------------*/
static portTASK_FUNCTION_PROTO( vTINCTask, pvParameters );
void vStartTICKINCTasks( unsigned portBASE_TYPE uxPriority );
void vStartTICKINCTasks( unsigned portBASE_TYPE uxPriority )
{
	/* Create the task. */
	xTaskCreate( vTINCTask, ( signed portCHAR * ) "TICKINC", TICK_STACK_SIZE, NULL, uxPriority, ( xTaskHandle * ) NULL );
		
}
/*---------------------------------------------------------------------------
 * 
 * 一个计时函数,每10ms加1.
 * 
 * 
 * 
 * ----------------------------------------------------------------------------*/
extern struct KEYMODE m_KeyMode;

static portTASK_FUNCTION( vTINCTask, pvParameters )
{
	portTickType xkbdRate, xLastkbdTime;
	/* The parameters are not used. */
	( void ) pvParameters;
	xkbdRate = TICK_INC_RATE ;
	xkbdRate /= portTICK_RATE_MS;
	/* We need to initialise xLastkbdTime prior to the first call to vTaskDelayUntil(). */
	xLastkbdTime = xTaskGetTickCount();

	for(;;)
	{
		/* Delay for half the flash period then turn the LED on. 	*/
		vTaskDelayUntil( &xLastkbdTime, xkbdRate );
		/* Increasing every parameters    */
		if(CmdRcvIrq.time_flag>=1)		//增加串口超时控制标志
		{
			CmdRcvIrq.time_flag++;
			//SendByte('r');
		}
		if(m_KeyMode.timelag>0)
			m_KeyMode.timelag++;
	}
} 
/*
 * Starts all the other tasks, then starts the scheduler. 
 */
int main( void )
{
		
		/* Setup the hardware for use with the Olimex demo board. */
		prvSetupHardware();
		InitEMC();
		GUI_Initialize();
		
		
		//PutString(1,1,"北京",4);
		//
		//PutString(5,1,"北京立德金融设备有限责任公司",28);
		//vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
		xSerialPortInitMKD(115200);
		
		PutString(2,1,"Good afternoon,德海",19);
		PutString(5,1,"北京立德金融设备有限责任公司",28);
		//PutString(5,1,"北京立德金融设备有限责任公司",28);
		//GUI_PutString(1,8,"load mkd..");
		LCD_BackLight(0);
		vStartTICKINCTasks(mainTINC_TASK_PRIORITY);      //计时器任务
		vStartKBDTasks( mainKBD_TASK_PRIORITY );			//键值采集任务
		vStartPCKTasks( mainPCK_TASK_PRIORITY );		//命令处理任务
		vStartU0CHECKTasks(mainPCK_TASK_PRIORITY);		//串口检测任务,判断是否超时
		
		//DisplayFlag(2);
		/*Start the check task - which is defined in this file. */
		//xTaskCreate( vErrorChecks, ( signed portCHAR * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
		//xUARTSend(0,"Good afternoon",14);
		/* Now all the tasks have been started - start the scheduler.
		NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
		The processor MUST be in supervisor mode when vTaskStartScheduler is 
		called.  The demo applications included in the FreeRTOS.org download switch
		to supervisor mode prior to main being called.  If you are not using one of
		these demo application projects then ensure Supervisor mode is used here. */
		
		vTaskStartScheduler();
	
		/* Should never reach here! */

		
	return 0;
}
/*-----------------------------------------------------------*/

⌨️ 快捷键说明

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