/*FUNCTION*------------------------------------------------------------------- * * Function Name : mcf_52xx_flash_init * Returned Value : * Comments : * Erase a flash memory block * *END*----------------------------------------------------------------------*/ bool mcf52xx_flash_init ( /* [IN] File pointer */ IO_FLASHX_STRUCT_PTR dev_ptr ) { MCF52XX_FLASH_INTERNAL_STRUCT_PTR dev_spec_ptr; #ifdef PSP_HAS_DUAL_FLASH uint8_t array; #endif //PSP_HAS_DUAL_FLASH VMCF52XX_CFM_STRUCT_PTR cfm_ptr; dev_spec_ptr = _mem_alloc(sizeof(MCF52XX_FLASH_INTERNAL_STRUCT)); #if MQX_CHECK_FOR_MEMORY_ALLOCATION_ERRORS /* test for correct memory allocation */ if( dev_spec_ptr == NULL) { return FALSE; } #endif //MQX_CHECK_FOR_MEMORY_ALLOCATION_ERRORS /* get the pointer to cfm registers structure */ cfm_ptr = _bsp_get_cfm_address(); dev_spec_ptr->cfm_ptr = (volatile char *)cfm_ptr; dev_ptr->DEVICE_SPECIFIC_DATA = dev_spec_ptr; /* save pointer to function in ram */ dev_spec_ptr->flash_execute_code_ptr = mcf52xx_init_ram_function(); /* set correct clocking for CFM module */ _mcf52xx_set_cfmclkd(); return TRUE; }
/*FUNCTION*------------------------------------------------------------------- * * Function Name : mcf_51xx_flash_array2_init * Returned Value : * Comments : * Init flash - store the FSTAT register * *END*----------------------------------------------------------------------*/ boolean mcf_51xx_flash_array2_init( IO_FLASHX_STRUCT_PTR flash_ptr ) { VMCF51XX_FTSR_STRUCT_PTR ftsr_ptr; INTERNAL_51XX_STRUCT dev_spec_struct; INTERNAL_51XX_STRUCT_PTR dev_spec_ptr; dev_spec_ptr = _mem_alloc(sizeof(dev_spec_struct)); /* test for correct memory allocation */ if( dev_spec_ptr == NULL){ return FALSE; } /* get the pointer to cfm registers structure */ /* RTC_CFG_DATA[CFG0] = 0 : FSTR1 => 0x00000000 - see Flash Array Base Address table */ ftsr_ptr = ( _mcf51_get_rtc_cfg_state() == 1 ) ? _bsp_get_cfm_address( MEMORY_ARRAY_1 ) : _bsp_get_cfm_address( MEMORY_ARRAY_2 ); dev_spec_ptr->ftsr_ptr = (vuchar_ptr)ftsr_ptr; flash_ptr->DEVICE_SPECIFIC_DATA = dev_spec_ptr; /* save pointer to function in ram - this is the default settings */ dev_spec_ptr->flash_execute_code_ptr = mcf51xx_init_ram_function(); return TRUE; }
/*FUNCTION*------------------------------------------------------------------- * * Function Name : _mcf51xx_set_cfmclkd_ext * Returned Value : none * Comments : * Set the CFMCLKD register. * *END*----------------------------------------------------------------------*/ void _mcf51xx_set_cfmclkd_ext( uchar mem_array ){ #define PRDIV8_LIMIT_FREQ 12800000L // limit freq. for using PRDIV8_PRSC #define FLASH_FREQ 200000L // 190 kHz program frequency #define PRDIV8_PRSC 8 // prescaller 8 VMCF51XX_FTSR_STRUCT_PTR ftsr_ptr; ftsr_ptr = _bsp_get_cfm_address( mem_array ); if(BSP_BUS_CLOCK > PRDIV8_LIMIT_FREQ) { ftsr_ptr->FCDIV = MCF51XX_FTSR_FCDIV_PRDIV8 | MCF51XX_FTSR_FCDIV_FDIV((BSP_BUS_CLOCK+PRDIV8_PRSC*FLASH_FREQ-1) / (PRDIV8_PRSC * FLASH_FREQ) -1); } else { ftsr_ptr->FCDIV = MCF51XX_FTSR_FCDIV_FDIV((BSP_BUS_CLOCK+FLASH_FREQ-1) / FLASH_FREQ -1); } }
/*FUNCTION*------------------------------------------------------------------- * * Function Name : _mcf52xx_set_cfmclkd * Returned Value : none * Comments : * Set the CFMCLKD register. * *END*----------------------------------------------------------------------*/ void _mcf52xx_set_cfmclkd() { #define PRDIV8_LIMIT_FREQ 12800000L // limit freq. for using PRDIV8_PRSC #define FLASH_FREQ 200000L // 200 kHz program frequency #define PRDIV8_PRSC 8 // prescaller 8 VMCF52XX_CFM_STRUCT_PTR cfm_ptr; cfm_ptr = _bsp_get_cfm_address(); if(BSP_BUS_CLOCK > PRDIV8_LIMIT_FREQ) { cfm_ptr->CFMCLKD = MCF52XX_CFM_CFMCLKD_PRDIV8 | MCF52XX_CFM_CFMCLKD_DIV((BSP_BUS_CLOCK+PRDIV8_PRSC*FLASH_FREQ-1) / (PRDIV8_PRSC * FLASH_FREQ) -1); } else { cfm_ptr->CFMCLKD = MCF52XX_CFM_CFMCLKD_DIV((BSP_BUS_CLOCK+FLASH_FREQ-1) / FLASH_FREQ -1); } }
/*FUNCTION*------------------------------------------------------------------- * * Function Name : mcf_51xx_flash_init * Returned Value : * Comments : * Init flash - store the FSTAT register * *END*----------------------------------------------------------------------*/ boolean mcf_51xx_flash_init( IO_FLASHX_STRUCT_PTR flash_ptr ) { VMCF51XX_FTSR_STRUCT_PTR ftsr_ptr; INTERNAL_51XX_STRUCT dev_spec_struct; INTERNAL_51XX_STRUCT_PTR dev_spec_ptr; dev_spec_ptr = _mem_alloc(sizeof(dev_spec_struct)); /* test for correct memory allocation */ if( dev_spec_ptr == NULL){ return FALSE; } /* get the pointer to cfm registers structure */ ftsr_ptr = _bsp_get_cfm_address( MEMORY_ARRAY_STD ); dev_spec_ptr->ftsr_ptr = (vuchar_ptr)ftsr_ptr; flash_ptr->DEVICE_SPECIFIC_DATA = dev_spec_ptr; /* save pointer to function in ram - this is the default settings */ dev_spec_ptr->flash_execute_code_ptr = mcf51xx_init_ram_function(); return TRUE; }