Esempio n. 1
0
File: log.c Progetto: 12019/SOSSE
void log_add( iu8 tag, iu8 *data, iu8 len )
{
	bool save=log_enable;

	if( !log_enable || dst<LOG_START ) return;

	log_enable=FALSE;
	hal_eeprom_write( dst++, &tag, 1 );
	hal_eeprom_write( dst++, &len, 1 );
	hal_eeprom_write( dst, data, len );
	dst+=len;
	hal_eeprom_write( LOG_START, (iu8 *) &dst, 2 );
	log_enable=save;
}
Esempio n. 2
0
bool fstream_write( S_FSTREAM *fs, iu8 *src, iu8 len )
{
	if( !( fstream_test( fs, len ) &&
		hal_eeprom_write( fs->start+fs->pos, src, len ) ) ) return FALSE;
	fs->pos+=len;
	return TRUE;
}
Esempio n. 3
0
extern hal_result_t ap_privateData_init(void)
{
    const eEsharinfoPartable_t *ptab;
    hal_result_t res;
    ap_private_datastruct_t privdata;

    //sharinfo_applic_partiontable_get(&ptab);
	ee_sharedstorage_partiontable_get(&ptab);

    res = hal_eeprom_read(hal_eeprom_emulatedflash, ptab->strg_priv_application.addr, 
                              sizeof(ap_private_datastruct_t), (void*)&privdata);
    if(hal_res_OK != res)
    {
        return(res);    
    }

    //check if data is valid
    if(!s_ap_privatedata_isValid(&privdata))
    { 
        res = hal_eeprom_write(hal_eeprom_emulatedflash, ptab->strg_priv_application.addr, 
                              sizeof(ap_private_datastruct_t), (void*)&privateData_default);
        if(hal_res_OK != res)
        {
            return(res);    
        }
    }
    return(hal_res_OK);
}
Esempio n. 4
0
extern eEresult_t ee_privatestorage_set(const void* data)
{
    eEresult_t res = ee_res_NOK_generic;
    hal_result_t halres = hal_res_NOK_generic;
    uint16_t tmp16 = 0;
    
    // controls upon initialisation. if not initted yet, then we return error
    if(0 == s_ee_privatestorage_internals.config.size)
    {
        return(ee_res_NOK_generic);
    }
    
    if((NULL != data) && (data != s_ee_privatestorage_internals.dataplussig_ramfor))
    {
        memcpy(s_ee_privatestorage_internals.dataplussig_ramfor, data, s_ee_privatestorage_internals.config.size);
    }
    
    // now compute its signature and set it ..
    tmp16 = s_ee_privatestorage_compute_signature();
    s_ee_privatestorage_set_signature(tmp16);
    
    // now i write in eeprom
    halres = hal_eeprom_write(hal_eeprom_emulatedflash, s_ee_privatestorage_internals.eeprom_address, 
                              s_ee_privatestorage_internals.dataplussig_sizeof, s_ee_privatestorage_internals.dataplussig_ramfor);

    if(hal_res_OK != halres)
    {
        return(ee_res_NOK_generic);    
    }
        
    return(ee_res_OK);  
}
Esempio n. 5
0
extern hal_result_t ap_privateData_set(ap_private_datastruct_t *privdata)
{
    const eEsharinfoPartable_t *ptab;

    if(NULL == privdata)
    {
        return(hal_res_NOK_generic);
    }
    //sharinfo_applic_partiontable_get(&ptab);
	ee_sharedstorage_partiontable_get(&ptab);

    return( hal_eeprom_write(hal_eeprom_emulatedflash, ptab->strg_priv_application.addr, 
                             sizeof(ap_private_datastruct_t), (void*)privdata) );

}
Esempio n. 6
0
void cmd_write( void )
{
	iu8 b, i;

	if( t0_testP3( 0x00 ) ) {
		sw_set( SW_WRONG_LEN );
		return;
	}

	/* TODO: check for eeprom range */

	/* Receive */
	for( i=0; i<header[4]; i++ ) {
		/* ~ACK */
		t0_sendCAck();

		/* Data */
		b = hal_io_recByteT0();

		if( !hal_eeprom_write( ((iu16)header[2]<<8)+header[3]+i, &b, 1 ) ) return;
	}

	sw_set( SW_OK );
}
Esempio n. 7
0
File: log.c Progetto: 12019/SOSSE
void log_init( void )
{
	dst=LOG_START+2;
	hal_eeprom_write( LOG_START, (iu8 *) &dst, 2 );
	log_enable=FALSE;
}
Esempio n. 8
0
extern eEresult_t ee_privatestorage_init(ee_privatestorage_cfg_t* cfg, void** pdata)
{
    eEresult_t res = ee_res_NOK_generic;
    const eEsharinfoPartable_t *ptab;
    hal_result_t halres = hal_res_NOK_generic;
    uint16_t tmp16 = 0;

    // some controls upon validity of the params
    if((NULL == cfg) || (0 == cfg->size))
    {
        return(ee_res_NOK_generic);
    }
    
    // controls upon a previous call, so that we dont call it twice
    if(0 != s_ee_privatestorage_internals.config.size)
    {
        return(ee_res_NOK_generic);
    }
    
    
    if(NULL != pdata)
    {
        *pdata = NULL;
    }   
 
    // ok, params are ok. and it is first call. let's go on
    
    memcpy(&s_ee_privatestorage_internals.config, cfg, sizeof(ee_privatestorage_cfg_t));    
    ee_sharedstorage_partiontable_get(&ptab);   
    s_ee_privatestorage_internals.eeprom_address        = ptab->strg_priv_application.addr;   
    // for data i use 4-bytes alignment
    tmp16 = (s_ee_privatestorage_internals.config.size + 3)/4;
    tmp16 *= 4;
    s_ee_privatestorage_internals.dataplussig_sigoff    = tmp16; 
    s_ee_privatestorage_internals.dataplussig_sizeof    = s_ee_privatestorage_internals.dataplussig_sigoff + 4;  // add 4 bytes for the sig at the end.
    s_ee_privatestorage_internals.tmpsigvalue           = 0;   
    
    s_ee_privatestorage_internals.dataplussig_ramfor    = calloc(s_ee_privatestorage_internals.dataplussig_sizeof, 1);
    
    if(NULL == s_ee_privatestorage_internals.dataplussig_ramfor)
    {
        return(ee_res_NOK_generic);
    }
    
    // read data plus sig
    halres = hal_eeprom_read(hal_eeprom_emulatedflash, s_ee_privatestorage_internals.eeprom_address, 
                             s_ee_privatestorage_internals.dataplussig_sizeof, s_ee_privatestorage_internals.dataplussig_ramfor);
    if(hal_res_OK != halres)
    {
        return(ee_res_NOK_generic);    
    }
    
    // check if data is valid
    if(ee_false == s_ee_privatestorage_isvalid())
    { 
        // reset data
        if(NULL != s_ee_privatestorage_internals.config.defval)
        {
            memcpy(s_ee_privatestorage_internals.dataplussig_ramfor, s_ee_privatestorage_internals.config.defval, s_ee_privatestorage_internals.config.size);
        }
        else
        {
            memset(s_ee_privatestorage_internals.dataplussig_ramfor, 0, s_ee_privatestorage_internals.config.size);            
        }
        
        // now compute the signature and set it
        tmp16 = s_ee_privatestorage_compute_signature();
        s_ee_privatestorage_set_signature(tmp16);

        
        // now i write in eeprom
        halres = hal_eeprom_write(hal_eeprom_emulatedflash, s_ee_privatestorage_internals.eeprom_address, 
                                  s_ee_privatestorage_internals.dataplussig_sizeof, s_ee_privatestorage_internals.dataplussig_ramfor);
                                  
        if(hal_res_OK != res)
        {
            return(ee_res_NOK_generic);    
        }
    }
    
    if(NULL != pdata)
    {
        *pdata = s_ee_privatestorage_internals.dataplussig_ramfor;
    }
    
    return(ee_res_OK);    
}