Ejemplo n.º 1
0
/************************************************************************
* NAME: fapp_mem_erase
*
* DESCRIPTION: 
************************************************************************/
static fnet_return_t fapp_mem_erase( void *addr, fnet_size_t n)
{
    fnet_return_t                   result = FNET_ERR;
    const struct fapp_mem_region    *region;
    
    if(fapp_mem_region_is_protected( (fnet_uint32_t)addr, n) == FNET_FALSE)
	{
    	/* Find memory region.*/
        region = fapp_mem_region_find( (fnet_uint32_t)addr, n);
        
        if(region)
        {
            if(region->erase)
            {
                region->erase(addr, n);
                result = FNET_OK;
            }
        }
	}
    return result;
}
Ejemplo n.º 2
0
/************************************************************************
* NAME: fapp_mem_erase
*
* DESCRIPTION: 
************************************************************************/
static int fapp_mem_erase( void *addr, unsigned n)
{
    int result = FNET_ERR;
    const struct fapp_mem_region *region;
    
    if(fapp_mem_region_is_protected( (unsigned long)addr, n) == 0)
	{
    	/* Find memory region.*/
        region = fapp_mem_region_find( (unsigned long)addr, n);
        
        if(region)
        {
            if(region->erase)
            {
                region->erase(addr, n);
                result = FNET_OK;
            }
        }
	}
    return result;
}
Ejemplo n.º 3
0
/************************************************************************
* NAME: fapp_mem_memcpy
*
* DESCRIPTION: 
************************************************************************/
fnet_return_t fapp_mem_memcpy (fnet_shell_desc_t desc, void *dest, const void *src, fnet_size_t n )
{
    fnet_size_t     i;
    const struct    fapp_mem_region *region;
	
	if(fapp_mem_region_is_protected( (fnet_uint32_t)dest, n) == FNET_FALSE)
	{
    	/* Find memory region.*/
        region = fapp_mem_region_find( (fnet_uint32_t)dest, n);
        
        if(region && (region->memcpy))
        {
        #if FAPP_CFG_CHECK_FLASH_BEFORE_WRITE
            if(region->erase)
            {
                /* Check if memory is erased.*/
                for(i=0u; i<n; i++)
                {
                    if(((fnet_uint8_t *)dest)[i] != 0xFFu)
                    {
                        fnet_shell_println(desc, FAPP_MEM_ERROR_NOTERASED);
                        goto FAIL;
                    }
                }
            }
        #endif
            
            /* Write. */
            region->memcpy(dest, src, n);
                
            /* Verify result. */
        #if 0 /* Old code.*/
            for(i=0; i<n; i++)
            {
                if(((volatile fnet_uint8_t *)dest)[i] !=((fnet_uint8_t *)src)[i])
                {
                    goto FAIL;   
                }
            }
        #else
            /* Workaround of the Flash cache issue discovered on K60.*/
            /* Delay.  fnet_timer_delay(1); is too big - 100ms.*/
            for(i=0u; i<100000000u; i++)
            {
                if(fnet_memcmp(dest, src, n) == 0)
                {
                    break;
                }
            }
            if(i==100000000u)
            {
                goto FAIL;
            }
        #endif

            return FNET_OK;
        }
	}

FAIL:	
    fnet_shell_println(desc, FAPP_MEM_ERROR_WRITEFAILED, n, dest);
    return FNET_ERR;
}