//*****************************************************************************
//
// Initializes the UART update interface.
//
//*****************************************************************************
void
UpdateUARTInit(void)
{
    //
    // Set the flash programming speed based on the processor speed.
    //
    FlashUsecSet(50);

    //
    // Enable the peripherals used by the UART.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);

    //
    // Configure the UART Tx and Rx pins for use by the UART.
    //
    GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    //
    // Configure and enable the UART for 115,200, 8-N-1 operation.
    //
    UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,
                        (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                         UART_CONFIG_PAR_NONE));
    UARTEnable(UART0_BASE);

    //
    // Enable the UART receive interrupts.
    //
    UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);
    IntEnable(INT_UART0);
}
Esempio n. 2
0
//*****************************************************************************
//
//! Initializes the flash parameter block.
//!
//! \param ulStart is the address of the flash memory to be used for storing
//! flash parameter blocks; this must be the start of an erase block in the
//! flash.
//! \param ulEnd is the address of the end of flash memory to be used for
//! storing flash parameter blocks; this must be the start of an erase block in
//! the flash (the first block that is NOT part of the flash memory to be
//! used), or the address of the first word after the flash array if the last
//! block of flash is to be used.
//! \param ulSize is the size of the parameter block when stored in flash;
//! this must be a power of two less than or equal to the flash erase block
//! size (typically 1024).
//!
//! This function initializes a fault-tolerant, persistent storage mechanism
//! for a parameter block for an application.  The last several erase blocks
//! of flash (as specified by \e ulStart and \e ulEnd are used for the
//! storage; more than one erase block is required in order to be
//! fault-tolerant.
//!
//! A parameter block is an array of bytes that contain the persistent
//! parameters for the application.  The only special requirement for the
//! parameter block is that the first byte is a sequence number (explained
//! in FlashPBSave()) and the second byte is a checksum used to validate the
//! correctness of the data (the checksum byte is the byte such that the sum of
//! all bytes in the parameter block is zero).
//!
//! The portion of flash for parameter block storage is split into N
//! equal-sized regions, where each region is the size of a parameter block
//! (\e ulSize).  Each region is scanned to find the most recent valid
//! parameter block.  The region that has a valid checksum and has the highest
//! sequence number (with special consideration given to wrapping back to zero)
//! is considered to be the current parameter block.
//!
//! In order to make this efficient and effective, three conditions must be
//! met.  The first is \e ulStart and \e ulEnd must be specified such that at
//! least two erase blocks of flash are dedicated to parameter block storage.
//! If not, fault tolerance can not be guaranteed since an erase of a single
//! block will leave a window where there are no valid parameter blocks in
//! flash.  The second condition is that the size (\e ulSize) of the parameter
//! block must be an integral divisor of the size of an erase block of flash.
//! If not, a parameter block will end up spanning between two erase blocks of
//! flash, making it more difficult to manage.  The final condition is that the
//! size of the flash dedicated to parameter blocks (\e ulEnd - \e ulStart)
//! divided by the parameter block size (\e ulSize) must be less than or equal
//! to 128.  If not, it will not be possible in all cases to determine which
//! parameter block is the most recent (specifically when dealing with the
//! sequence number wrapping back to zero).
//!
//! When the microcontroller is initially programmed, the flash blocks used for
//! parameter block storage are left in an erased state.
//!
//! This function must be called before any other flash parameter block
//! functions are called.
//!
//! \return None.
//
//*****************************************************************************
void
FlashPBInit(unsigned long ulStart, unsigned long ulEnd, unsigned long ulSize)
{
    unsigned char *pucOffset, *pucCurrent;
    unsigned char ucOne, ucTwo;

    //
    // Check the arguments.
    //
    ASSERT((ulStart % FLASH_ERASE_SIZE) == 0);
    ASSERT((ulEnd % FLASH_ERASE_SIZE) == 0);
    ASSERT((FLASH_ERASE_SIZE % ulSize) == 0);

    //
    // Set the number of clocks per microsecond to enable the flash controller
    // to properly program the flash.
    //
    FlashUsecSet(SysCtlClockGet() / 1000000);

    //
    // Save the characteristics of the flash memory to be used for storing
    // parameter blocks.
    //
    g_pucFlashPBStart = (unsigned char *)ulStart;
    g_pucFlashPBEnd = (unsigned char *)ulEnd;
    g_ulFlashPBSize = ulSize;

    //
    // Loop through the portion of flash memory used for storing parameter
    // blocks.
    //
    for(pucOffset = g_pucFlashPBStart, pucCurrent = 0;
        pucOffset < g_pucFlashPBEnd; pucOffset += g_ulFlashPBSize)
    {
        //
        // See if this is a valid parameter block (i.e. the checksum is
        // correct).
        //
        if(FlashPBIsValid(pucOffset))
        {
            //
            // See if a valid parameter block has been previously found.
            //
            if(pucCurrent != 0)
            {
                //
                // Get the sequence numbers for the current and new parameter
                // blocks.
                //
                ucOne = pucCurrent[0];
                ucTwo = pucOffset[0];

                //
                // See if the sequence number for the new parameter block is
                // greater than the current block.  The comparison isn't
                // straightforward since the one byte sequence number will wrap
                // after 256 parameter blocks.
                //
                if(((ucOne > ucTwo) && ((ucOne - ucTwo) < 128)) ||
                   ((ucTwo > ucOne) && ((ucTwo - ucOne) > 128)))
                {
                    //
                    // The new parameter block is older than the current
                    // parameter block, so skip the new parameter block and
                    // keep searching.
                    //
                    continue;
                }
            }

            //
            // The new parameter block is more recent than the current one, so
            // make it the new current parameter block.
            //
            pucCurrent = pucOffset;
        }
    }

    //
    // Save the address of the most recent parameter block found.  If no valid
    // parameter blocks were found, this will be a NULL pointer.
    //
    g_pucFlashPBCurrent = pucCurrent;
}
Esempio n. 3
0
//*****************************************************************************
//
//! Initializes the emulated EEPROM.
//!
//! This function initializes the EEPROM emulation area within the Flash. This
//! function must be called prior to using any of the other functions in the
//! API. It is expected that SysCtlClockSet() is called prior to calling this
//! function due to SysCtlClockGet() being used by this function.
//!
//! \param ulStart is the start address for the EEPROM region. This address
//! must be aligned on a 4K boundary.
//!
//! \param ulEnd is the end address for the EEPROM region.  This address is
//! not inclusive.  That is, it is the first address just after the EEPROM 
//! emulation region.  It must be aligned on a 4K boundary. It can be the first
//! location after the end of the Flash array if the last Flash page is used
//! for EEPROM emulation.
//!
//! \param ulSize is the size of each EEPROM page. This must be evenly
//! divisible into the total EEPROM emulation region.  The size must be
//! specified such to allow for at least two EEMPROM emulation pages.
//!
//! \return A value of 0 indicates that the initialization was successful.  A
//! non-zero value indicates a failure.
//
//*****************************************************************************
long
SoftEEPROMInit(unsigned long ulStart, unsigned long ulEnd,
               unsigned long ulSize)
{
    unsigned long ulActiveStatusCnt;
    unsigned char ucActivePgCnt;
    unsigned char* pucPageAddr;
    unsigned char* pucActivePg;
	tBoolean bFullPgFound;

    ASSERT(ulEnd > ulStart);
    ASSERT((ulStart % EEPROM_BOUNDARY) == 0);
    ASSERT((ulEnd % EEPROM_BOUNDARY) == 0);
    ASSERT((ulSize % FLASH_ERASE_SIZE) == 0);
    ASSERT(((ulEnd - ulStart) / ulSize) >= 2);
    
    //
    // Check that the EEPROM region is within the Flash.
    //
    if(ulEnd > SysCtlFlashSizeGet())
    {
        //
        // Return the proper error.
        //
        return(ERR_RANGE);   
    }

    //
    // Save the characteristics of the EEPROM Emulation area. Mask off the 
    // lower bits of the addresses to ensure that they are 4K aligned.
    //
    g_pucEEPROMStart = (unsigned char *)(ulStart & ~(EEPROM_BOUNDARY - 1));
    g_pucEEPROMEnd = (unsigned char *)(ulEnd & ~(EEPROM_BOUNDARY - 1));
    g_ulEEPROMPgSize = ulSize;

    //
    // Set the number of clocks per microsecond to enable the Flash controller
    // to properly program the Flash.
    //
    FlashUsecSet(SysCtlClockGet() / 1000000);

    //
    // Get the active page count.
    //
    ucActivePgCnt = GetActivePageCount();
    
    //
    // If there are no active pages, execute the following.  This will be true
    // for a fresh start and can also be true if a reset or power-down occurs
    // during a clear operation.
    //
    if(ucActivePgCnt == 0)
    {
        //
        // If there are not any used pages, then this is a fresh start.
        //
        if(GetUsedPageCount() == 0)
        {
            //
            // Erase the first page.
            //
            if(PageErase(g_pucEEPROMStart))
            {
                //
                // Return the proper error.
                //
                return(ERR_PG_ERASE);
            }

			//
			// The active status count will be 0.
			//
			ulActiveStatusCnt = 0;

            //
            // Mark the new page as active. Since this is a fresh start
            // start the counter at 0.
            //
            if(PageDataWrite(&ulActiveStatusCnt, g_pucEEPROMStart, 4))
            {
                //
                // Return the proper error.
                //
                return(ERR_PG_WRITE);
            }

            //
            // Save the active page pointer.
            //
            g_pucActivePage = g_pucEEPROMStart;
    
            //
            // Save the next available entry.
            //
            g_pucNextAvailEntry = g_pucEEPROMStart + 8;
        }
        
        //
        // Else, a reset must have occurred before a clear operation could
        // complete.  This is known since there are used pages but no active
        // pages.
        //
        else
        {
            //
            // Get the beginning address of the most recently used page.
            //
            pucPageAddr = GetMostRecentlyUsedPage();
            
            //
            // Get the active status counter for the most recently used
            // page.  Then add one to it for the next page.
            //
            ulActiveStatusCnt = *(unsigned long *)pucPageAddr + 1;
            
            //
            // Calculate the address of the page just after the most
            // recently used.
            //
            pucPageAddr = ((pucPageAddr + g_ulEEPROMPgSize) < g_pucEEPROMEnd) ?
                          (pucPageAddr + g_ulEEPROMPgSize) :
                          g_pucEEPROMStart;
            
            //
            // Erase this page.
            //
            if(PageErase(pucPageAddr))
            {
                //
                // Return the proper error.
                //
                return(ERR_PG_ERASE);
            }

            //
            // Mark this page as active.
            //
            if(PageDataWrite(&ulActiveStatusCnt, pucPageAddr, 4))
            {
                //
                // Return the proper error.
                //
                return(ERR_PG_WRITE);
            }

            //
            // Save the active page pointer.
            //
            g_pucActivePage = pucPageAddr;
    
            //
            // Save the next available entry.
            //
            g_pucNextAvailEntry = pucPageAddr + 8;
        }
    }
    
    //
    // Else, if there is 1 active page, execute the following.  This will be
    // true for a normal start where the EEPROM has been previously
    // initialized and can also be true if a reset or power-down occurs during
    // a clear operation.
    //
    else if(ucActivePgCnt == 1)
    {
        //
        // Loop through the pages.
        //	
        for(pucActivePg = g_pucEEPROMStart; pucActivePg < g_pucEEPROMEnd;
            pucActivePg += g_ulEEPROMPgSize)
        {
            //
            // Is this the active page?
            //
            if(PageIsActive(pucActivePg))
            {
                //
                // Break out of the loop.
                //
                break;
            }
        }
        
        //
        // Now calculate the address of the page before the active page.
        //
        pucPageAddr = (pucActivePg == g_pucEEPROMStart) ?
                      (g_pucEEPROMEnd - g_ulEEPROMPgSize) :
                      (pucActivePg - g_ulEEPROMPgSize);
                    
        //
        // Check to see if the page before has been used.
        //
        if(PageIsUsed(pucPageAddr))
        {
            //
            // Check to see that the used page counter is one less than the 
			// active page counter.
            //
            if(*(unsigned long*)pucPageAddr == 
			   (*(unsigned long*)pucActivePg - 1))
            {
                //
                // This is a normal start. Save the active page pointer.
                //
                g_pucActivePage = pucActivePg;
        
                //
                // Save the next available entry.
                //
                g_pucNextAvailEntry = GetNextAvailEntry();					
            }
            
            //
            // Else, a reset must have occurred during the page erase or
			// programming the the active status counter of a 
			// clear operation to leave the EEPROM in this state.
            //
            else
            {
                //
                // Erase the page that was marked active.  It is incorrectly
                // marked active due to the counter being off.
                //
                if(PageErase(pucActivePg))
                {
                    //
                    // Return the proper error.
                    //
                    return(ERR_PG_ERASE);
                }
                
                //
                // Get the active status counter for the most recently used
                // page.  Then add one to it for the next page.
                //
                ulActiveStatusCnt = *(unsigned long *)pucPageAddr + 1;
                
                //
                // Mark this page as active.
                //
                if(PageDataWrite(&ulActiveStatusCnt, pucActivePg, 4))
                {
                    //
                    // Return the proper error.
                    //
                    return(ERR_PG_WRITE);
                }
                
                //
                // Save the active page pointer.
                //
                g_pucActivePage = pucActivePg;
        
                //
                // Save the next available entry.
                //
                g_pucNextAvailEntry = pucActivePg + 8;
            }
        }
        
        //
        // Else, the page before the active one has not been used yet.
        //
        else
        {
            //
            // This is a normal start. Save the active page pointer.
            //
            g_pucActivePage = pucActivePg;
            
            //
            // Save the next available entry.
            //
            g_pucNextAvailEntry = GetNextAvailEntry();					
        }
    }

    //
    // Else, if there are 2 active pages, execute the following.  This should
    // only occur if a reset or power-down occurs during a page swap operation.
    // In this case, one of the active pages must be full or else PageSwap()
    // would not have been called.
    //
    else if(ucActivePgCnt == 2)
    {
		//
		// Initially set bFullPgFound to false;
		//
		bFullPgFound = false;

        //
        // Loop through the pages.
        //
        for(pucActivePg = g_pucEEPROMStart; pucActivePg < g_pucEEPROMEnd;
            pucActivePg += g_ulEEPROMPgSize)
        {
            //
            // Is this the active page?
            //
            if(PageIsActive(pucActivePg))
            {
                //
                // Is the page full?
                //
                if(*(unsigned long*)(pucActivePg + g_ulEEPROMPgSize - 4)
                   != 0xFFFFFFFF)
                {
                    //
					// Set the status to true
					//
					bFullPgFound = true;

					//
                    // Then the page is full.  Break out of the loop.
                    //
                    break;
                }
            }
        }
        
        //
		// Was a full page found?
		//
		if(bFullPgFound == true)
		{
			//
	        // Now, the full page is pointed to by pucActivePg.  Save this as
            // the active page.  PageSwap() will be called again on the next
            // write.
	        //
	        g_pucActivePage = pucActivePg;
	        
	        //
	        // Save the next available entry. It is the location just after
	        // the end of the page since the page is full.  This will cause
	        // PageSwap() to be called on the next write.
	        //
	        g_pucNextAvailEntry = pucActivePg + g_ulEEPROMPgSize;
		}
		
		//
		// Else, this is not an expected case.  Report the error.
		//
		else
		{
			//
            // Return the proper error.
            //
            return(ERR_TWO_ACTIVE_NO_FULL);	
		}
    }

    //
    // Else there are more than 2 active pages.  This should never happen.
    //
    else
    {
        //
        // Return the proper error.
        //
        return(ERR_ACTIVE_PG_CNT);
    }

    //
    // The EEPROM has been initialized.
    //
    g_bEEPROMInitialized = true;

    //
    // Return indicating that no error occurred.
    //
    return(0);
}
Esempio n. 4
0
main()
{
    SysCtlClockSet(SYSCTL_SYSDIV_2_5| SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_6MHZ);
    IntMasterEnable();
    Uart0Init(19200);
    Uart1Init(19200);
    DPRINTF(("Bat=%d  ,cha=%x ,Temp=%f \n",1,20,3.0));
//    ADCBAT_init();
//    Ssi0Init();   //AD7367
    //spi_ad7705Init();   //AD7705
    IoPortInit();	  //IO口初始化
//  I2CM_Init(); //Fm31256
    //TimerInit();
    PIN_JR_relay(ERelay_off);
    PIN_JRTG_relay(ERelay_off);
    PIN_JUNX_relay(ERelay_off);
    PIN_JUN_relay(ERelay_off);
    PIN_JUX_relay(ERelay_off);
    FlashUsecSet(49);
    AD7367_init();
    AD7705_init();
    //   PIN_JR_relay(ERsample_1M);
    /*
    {

      uint32 i;
      set.Debug=EDebug_sub;
      set.Fre=EFre_500;

      gainchange();
      Vac_read();
      for(i=0;i<500;i++)
           {

            Fourier_Samplestart(); ;
    		delay(0xf000*200);
           }
    }

    */
    /*
    	{
    		 uint32 i;
    	     set.Debug=EDebug_sub;
    	     set.Fre=EFre_000;
    		 V_read();
    		 for(i=0;i<50;i++)
    		 	{

    			  DPRINTF(("I=%x   \n",Read_ad7705_I(0x07,1)));
    		 	}

    		 for(i=0;i<50;i++)
    		 	{

    			  DPRINTF(("U=%x \n",Read_ad7705_U(0x07,1)));
    		 	}
             for(i=0;i<500;i++)
               {
                R_test();
    			delay(0xf000*200);
               }
        }
    */
    modifyK_js();
    rx_flag=0;
    while(1)
    {
        // uint8 option=0;

        if((rx_flag==rx_succeed))
        {

            Sendstc_ask();
            set.Work=0x0f&rx_data.mune.workcommand;
            set.Debug=0x0f&(rx_data.mune.workcommand>>4);
            set.Fre=rx_data.mune.Fre;
            set.Voltage=rx_data.mune.Voltage;
            rx_flag=0x00;

            switch(set.Work)
            {
            case EstartV_main:
                V_read();
                break;
            case  EstartTg_main://AC
                Fourier_Samplestart();
                PIN_JRTG_relay(ERelay_off);
                PIN_JUNX_relay(ERelay_off);
                PIN_JUN_relay(ERelay_off);
                PIN_JUX_relay(ERelay_off);
                break;
            case  EstartR_main://DC
                R_test();
                PIN_JRTG_relay(ERelay_off);
                break;
            case 	Emodifyin_main:
                modify_save();
                modifyK_js();
                //DPRINTF(("In \n"));
                break;
            case  Emodifyout_main	:
                delay(0x80000);
                modify_ToView();
                modifyK_js();
                //DPRINTF(("out \n"));
                break;
            case  EstartX_main  :
                Vacx_read();
                break;

            case ERelay_main:
                PIN_JRTG_relay(ERelay_on);
                PIN_JR_relay(ERsample_50);
                break;
            default :
                SysCtlReset();
                break;

            }
            if((rx_flag==rx_succeed))
            {
                if(set.Work==0x0f&rx_data.mune.workcommand)
                {
                    rx_flag=0;
                }
            }

        }
    }
Esempio n. 5
0
  main()
  {
     uint8 option=0;
     uint8 key;
  
    SysCtlClockSet(SYSCTL_SYSDIV_4| SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_6MHZ);
    Uart0Init(19200);
	Uart1Init(9600);
	Uart2Init(19200);
    IntMasterEnable();
    SysLinearTimer =0;
    IoPortInit();	  //IO口初始化
    I2C1Init() ;//Fm31256
   	TimerInit();
	xs6963_init();
	PIN_TDA7367stand_Write(ETDA7367work_no);
	FlashUsecSet(49);
	//T1Init_LM331();
    DPRINTF(("Bat=%d  ,cha=%d ,Temp=%d \n",1,2,3));
    Usb_Host_Init();  
    mainHandleinit();
	
    signPWM_init(50.0);
    PWM_sign_stop();
	/*LCD初始化*/
	start_mune();
	/* fm31256 eeprom 8 */
    readbyte_much(setsto_addr,settype_nub,set.byte );
 	/*修正系数*/
    modify_read();
	/**/
	Oiltempset.oilTwork=EOiltemp_Workon; 
	/*lm331初始化 温度测量使用*/
	T1Init_LM331();
	/*系统节拍*/
    SysLinearTimer=0;	
	while(SysLinearTimer<3*TIMER_FREQ)//后台参数设置
     {
       key=Keyset.keyEfficiency;
       if(key==key_modify)
    	 {
		   while(Keyset.keyEfficiency==key_modify); 
    	   option++;
		   if(option>=4)
	       	{
			   modify_read();//读取修正参数
			   TgC_read();
    	       modify();//修正
	   	    }
       	 }
    }	
   	modifyK_js();
    SysLinearTimer=0;
    rx_flag=0;
 	option=0;
mainset_go:
	  key=Keyset.keyEfficiency;
      mainset_mune();
      Reversepic(mainset_lin+option*mainset_high, mainset_column, mainset_high, 2*4);
	  while(1)
	  	{
	      while(key==Keyset.keyEfficiency)
		    {
		     if(SysLinearTimer>(3*TIMER_FREQ/4))  	   
              {
			    // Temp_account();
			  if(TRUE_z==Gandispose())//地线检测
			  	{
			  	  mainset_mune();
				  Reversepic(mainset_lin+option*mainset_high, mainset_column, mainset_high, 2*4);
			  	}
           	 
			   read_time();
			    {
				 uint8 byte[12];	
			   	 Clock_viewxs(byte)	;
			   	}
				 SysLinearTimer=0;
			 }
	  	   }
		   key=Keyset.keyEfficiency;
		  /*按键处理*/
           switch(key)
		   	{
               case key_no:
			   case key_back:
			   	        continue;
		       case key_down:
			   case key_up:
			   	      Reversepic(mainset_lin+option*mainset_high, mainset_column, mainset_high, 2*4);
			   	      option=keyoption_js(option, key,4,Emune_key);//
					  Reversepic(mainset_lin+option*mainset_high, mainset_column, mainset_high, 2*4);
                    /*  if(key==key_up)
                      	{
                         PWM_sign_acc(0.0, 0.0);
						 delay(0x80000);
                         PIN_DCAC_pwm(EDC_power);
                      	 PWM_sign_acc(0.0, 0.7);
                      	}
					  else
					  	{
					  	 PWM_sign_acc(0.0, 0.0);
						 delay(0x80000);
					   	 PIN_DCAC_pwm(EAC_power);
					  	 PWM_sign_acc(50.0, 0.8);
					  	}
					 */ 	
					  break;				
			   case key_ok:	
			   	      switch(option)
			   	      	{
			   	      	 
                          case ELan_main://语言
							    set.mune.Langue++;
							    set.mune.Langue&=0x01;
                                //ShowtextLine(mainset_lin+option*mainset_high, mainset_column+0x10,Lanset_p[set.mune.Langue]);	
								break;
					      case EOilset_main://油样设置
						  	    oidset();
							    break;
						  case EView_main://历史数据
						  	    Viewdata_Hander();
						  	   break;
						  case EClock_main://时钟设置
							   clockset_mune();
                               break;			   
			   	      	}					  
					    goto mainset_go ;
               case key_oil:                     			
			          Oilclear();//排油
					 break;
			   	     					  
		   	}
	  	}
}