Esempio n. 1
0
void flash_init(void)
{
  // Inicialização da FSL
  fsl_descr.fsl_flash_voltage_u08 = 0;  // full speed mode
  fsl_descr.fsl_frequency_u08 = 32;     // 32MHz
  // Modo da FSL = SCI - checagem de status interna
  fsl_descr.fsl_auto_status_check_u08 = 0x01;
  // Inicializa a FSL
  FSL_Init((__far fsl_descriptor_t*)&fsl_descr);
  FSL_Open(); // abre uma sessão FSL
  FSL_PrepareFunctions(); // inicializa funções básicas FSL
}
Esempio n. 2
0
/***********************************************************************************************************************
* Function Name: main
* Description  : This function implements main function.
* Arguments    : None
* Return Value : None
***********************************************************************************************************************/
void  main(void)
{
    /* Start user code. Do not edit comment generated here */
    
    uint16_t i, startBlockNum, endBlockNum;
    fsl_u08 fslStatus;
    
    // prepare the interrupt vector table and user code in ram 
    FSL_userCopyInterruptToRam();
    FSL_userCopyApplicationCodeToRam();
    
    // copy the relevant FSL API sections to ram
    FSL_CopySection();
    
    // prepare the descriptor for initializing the mode
    fslDescriptor.fsl_flash_voltage_u08 = 0x0;      // full speed mode
    fslDescriptor.fsl_frequency_u08 = 32;           // 32 MHz frequency, round up
    fslDescriptor.fsl_auto_status_check_u08 = 0x0;  // status check user mode

    // retrieve the flash block numbers for checking
    FSL_userGetFlashBlockRanges(&startBlockNum, &endBlockNum);
      
    // always do this sequence before using FSL
    fslStatus = FSL_Init(&fslDescriptor);
    FSL_Open();
    FSL_PrepareFunctions();
    FSL_PrepareExtFunctions();                      
    
    // get the flash status
    fslVersionString = FSL_GetVersionString();            
    fslStatus = FSL_GetSecurityFlags(&fslSecurityFlags);
    fslStatus = FSL_GetBootFlag(&fslBootFlag);
    fslStatus = FSL_GetSwapState(&fslSwapState);        
    fslStatus = FSL_GetFlashShieldWindow(&fslFlashShieldWindow);        
    
    // activate the interrupt table in ram
    FSL_ChangeInterruptTable((fsl_u16)&FSL_userIsrInRam);

    R_INTC0_Start();
    R_IT_Start();
    
    // repeat in a loop to demonstrate interrupt servicing in background
    while(1) {
    

      
      // toggle the led if requested
      if(keyPress) {
        
        keyPress = 0;
        P6_bit.no3 ^= 1U;

        fslStatus = eraseFromRam(startBlockNum, endBlockNum);
      
        FSL_RestoreInterruptTable();
      
        // prepare buffer data
        for(i=0;i<WORK_BUFFER_SIZE;i++) {
            workingBuffer[i] = i;
        }
      
        fslWriteStr.fsl_data_buffer_p_u08 = &workingBuffer[0];
        fslWriteStr.fsl_word_count_u08 = WORK_BUFFER_WDSIZE;
        fslWriteStr.fsl_destination_address_u32 = FSL_userGetFlashStartAddress();     
      
        FSL_ChangeInterruptTable((fsl_u16)&FSL_userIsrInRam);
      
        fslStatus = writeFromRam(NUM_DATA_BLOCKS, &fslWriteStr);

        fslStatus = verifyFromRam(startBlockNum, endBlockNum);
      
        FSL_RestoreInterruptTable();
        
        
      };            

           
    };  
    
    /* End user code. Do not edit comment generated here */
}
Esempio n. 3
0
/***********************************************************************************************************************
* Function Name: main
* Description  : This function implements main function.
* Arguments    : None
* Return Value : None
***********************************************************************************************************************/
void  main(void)
{
    /* Start user code. Do not edit comment generated here */
  
    uint16_t i, startBlockNum, endBlockNum;
    
    fslDescriptor.fsl_flash_voltage_u08 = 0x0;      // full speed mode
    fslDescriptor.fsl_frequency_u08 = 32;           // 32 MHz frequency, round up
    fslDescriptor.fsl_auto_status_check_u08 = 0x1;  // status check internal mode

    // retrieve the flash block numbers for checking
    FSL_userGetFlashBlockRanges(&startBlockNum, &endBlockNum);
      
    // always do this sequence first
    fslStatus = FSL_Init(&fslDescriptor);
    FSL_Open();
    FSL_PrepareFunctions();
    FSL_PrepareExtFunctions();         
               
    // prepare the interrupt vector table in ram before the timer starts
    FSL_userCopyInterruptToRam();
    
    // get the flash status
    fslVersionString = FSL_GetVersionString();            
    fslStatus = FSL_GetSecurityFlags(&fslSecurityFlags);
    fslStatus = FSL_GetBootFlag(&fslBootFlag);
    fslStatus = FSL_GetSwapState(&fslSwapState);        
    fslStatus = FSL_GetFlashShieldWindow(&fslFlashShieldWindow);        
    
    // activate the interrupt table in ram
    FSL_ChangeInterruptTable((fsl_u16)&FSL_userIsrInRam);

    R_INTC0_Start();
    R_IT_Start();
    
    // repeat in a loop to demonstrate interrupt servicing in background
    while(1) {
    
      // erase blocks
      for(i=startBlockNum;i<=endBlockNum;i++) {
        
        fslStatus = FSL_Erase(i);
        if(FSL_OK != fslStatus) while(1);
        
        fslStatus = FSL_BlankCheck(i);
        if(FSL_OK != fslStatus) while(1);       
      }
      
      FSL_RestoreInterruptTable();
      
      // prepare buffer data
      for(i=0;i<WORK_BUFFER_SIZE;i++) {
        workingBuffer[i] = i;
      }
      
      fslWriteStr.fsl_data_buffer_p_u08 = &workingBuffer[0];
      fslWriteStr.fsl_word_count_u08 = WORK_BUFFER_WDSIZE;
      fslWriteStr.fsl_destination_address_u32 = FSL_userGetFlashStartAddress();     
      
      FSL_ChangeInterruptTable((fsl_u16)&FSL_userIsrInRam);
      
      // write new data
      for(i=0;i<NUM_DATA_BLOCKS;i++) {
        
        fslStatus = FSL_Write(&fslWriteStr);
        if(FSL_OK != fslStatus) while(1);
        
        fslWriteStr.fsl_destination_address_u32 += WORK_BUFFER_SIZE;
      }
      
      // verify retention
      for(i=startBlockNum;i<=endBlockNum;i++) {
        
        fslStatus = FSL_IVerify(i);
        if(FSL_OK != fslStatus) while(1);    
      }
      
      FSL_RestoreInterruptTable();
      
      // toggle the led if requested
      if(keyPress) {
        keyPress = 0;
        P7_bit.no6 ^= 1U;
      };            

      FSL_ChangeInterruptTable((fsl_u16)&FSL_userIsrInRam);
      
    };  

    /* End user code. Do not edit comment generated here */
}