Пример #1
0
/** @brief General purpose Flash Erase function
  * @param flags : (u16) Flash erase method flags
  * @param DummyAddress : (u16) Address of Segment, Bank, or Mass to erase
  * @retval u8 : Logical OR'ed group of status flags as described in FlashStatus enum datatype
  * @ingroup CC430_lib
  *
  * Appropriate Flash controller Segments must be unlocked before use!
  */
u8 FLASH_Erase( u16 flags, u16* DummyAddress ) {
    u8 status;
    u8 wdtstate;
    
    /// 1. assure Flash Status is good before doing operations
    status = FLASH_GetStatus();
    if ( status == 0 ) {
        u16 saved_gie;
        
        /// 2. Temporarily Disable Watchdog & general interrupts
        SAVE_GIE(saved_gie);
        wdtstate = WDTAb->CTL_L & 0x80;
        STOP_WDT();
    
        /// 3. Setup Flash Controller and Erase Mode, note clearing of lock bits
        FLASH->CTL3 = FWKEY;
        FLASH->CTL1 = FLASH_FWKEY | flags;
    
        /// 4. Dummy Write to base address
        *DummyAddress = 0xFFFF;
        
        status = FLASH_CheckWrite();
        RESUME_WDT(wdtstate);
        REVERT_GIE(saved_gie);
    }
    
    return status;
}
Пример #2
0
u8 FLASH_ProgramBlock( u32* Address, u32* Data, u16 Length) {
    u8 status;
    u8 wdtstate;
    
    /// 1. assure Flash Status is good before doing operations
    status = FLASH_GetStatus();
    if ( status == 0 ) {
        u16 saved_gie;
        
        /// 2. Temporarily Disable Watchdog & general interrupts
        SAVE_GIE(saved_gie);
        wdtstate = WDTAb->CTL_L & 0x80;
        STOP_WDT();
    
        /// 3. Set Flash Controller for Long Block Access
        FLASH->CTL1 = FLASH_FWKEY | FLASH_CTL_BLKWRT | FLASH_CTL_WRT;
    
        /// 4. Write Long Block
        while ( Length > 0 ) {
            while (FLASH->CTL3 & BUSY);
            *Address = *Data;
            Length--;
            Data++;
            Address++;
        }
    
        status = FLASH_CheckWrite();
        RESUME_WDT(wdtstate);
        REVERT_GIE(saved_gie);
    }
    
    return status;
}
Пример #3
0
/**
  * @brief  Waits for a FLASH operation to complete.
  * @param  None
  * @retval FLASH Status: The returned value can be: FLASH_BUSY, FLASH_ERROR_PROGRAM,
  *                       FLASH_ERROR_WRP, FLASH_ERROR_OPERATION or FLASH_COMPLETE.
  */
FLASH_Status FLASH_WaitForLastOperation(void)
{ 
  __IO FLASH_Status status = FLASH_COMPLETE;
   
  /* Check for the FLASH Status */
  status = FLASH_GetStatus();

  /* Wait for the FLASH operation to complete by polling on BUSY flag to be reset.
     Even if the FLASH operation fails, the BUSY flag will be reset and an error
     flag will be set */
  while(status == FLASH_BUSY)
  {
    status = FLASH_GetStatus();
  }
  /* Return the operation status */
  return status;
}
Пример #4
0
/**
  * @brief  Waits for a Flash operation to complete or a TIMEOUT to occur.
  * @param  Timeout: FLASH progamming Timeout
  * @retval FLASH Status: The returned value can be: FLASH_ERROR_PG,
  *   FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
  */
FLASH_Status FLASH_WaitForLastOperation(uint32 Timeout)
{ 
	FLASH_Status status;

	/* Check for the Flash Status */
	status = FLASH_GetStatus();
	/* Wait for a Flash operation to complete or a TIMEOUT to occur */
	while ((status == FLASH_BUSY) && (Timeout != 0x00))
	{
		delay();
		status = FLASH_GetStatus();
		Timeout--;
	}
	if (Timeout == 0)
		status = FLASH_TIMEOUT;
	/* Return the operation status */
	return status;
}
Пример #5
0
/** @brief Checks and completes the write process
  * @param None
  * @retval u8 : Logical OR'ed group of status flags as described in FlashStatus enum datatype
  * @ingroup CC430_lib
  */
u8 FLASH_CheckWrite() {
    
    /// 1. Terminate Write
    FLASH->CTL1 = FWKEY;                            // Clear Erase bit
    FLASH->CTL3 = FWKEY+LOCK+LOCKA;
    
    /// 
    
    return FLASH_GetStatus();
}
Пример #6
0
int FLASH_WaitForLastOperation(unsigned int Timeout)
{ 
int status = FLASH_COMPLETE;
   
  	/* Check for the Flash Status */
  	status = FLASH_GetStatus();

  	/* Wait for a Flash operation to complete or a TIMEOUT to occur */
  	while((status == FLASH_BUSY) && (Timeout != 0x00))
  	{
    	FLASH_delay();
    	status = FLASH_GetStatus();
    	Timeout--;
  	}

  	if(Timeout == 0x00 )
  	{
    	status = FLASH_TIMEOUT;
  	}

  	/* Return the operation status */
  	return status;
}