Пример #1
0
short eepromfs_format(char * sys_id)
{
   unsigned int16 i;

   //write memory struct values...
   for(i=0;i<sysDefaultValues_len;i++)
   {
      write_ext_eeprom(i,sysDefaultValues[i]);
   }

   //write system_id array...
   write_page_ext_eeprom(SYSTEM_ID_START_ADDR,sys_id,strlen(sys_id));

   //now, format blocks:

   //free block FORMAT:
   for(i=FREE_BLOCK_START;i<=FREE_BLOCK_END;i++)
   {
      write_ext_eeprom(i,0x00);
   }
   
   //index block FORMAT:
   for(i=INDEX_BLOCK_START;i<=INDEX_BLOCK_END;i++)
   {
      write_ext_eeprom(i,EEPROM_EMPTY_VALUE);     //indicate empty block
   }
   
   //data block should not need to be formated

   //success!
   return TRUE;
}
Пример #2
0
short eepromfs_setBlockIdentifiers(int8 blockNmr, struct blockIdentifiers * identIn)
{
   int8 aux81,aux82;
   int16 aux161,aux162,aux163;

   aux82=blockNmr;
   //get FREE BLOCK START ADDRESS
   aux161=eepromfs_getAddress(FREE_BLOCK_START_ADDR);

   while(aux82>7)
   {
      aux161++;
      aux82-=8;
   }

   //get 8 block info...
   aux81=read_ext_eeprom(aux161);

   if((*identIn).state) bit_set(aux81,aux82); else bit_clear(aux81,aux82);
   
   //write result...
   write_ext_eeprom(aux161,aux81);
   
   //get BLOCK SIZE
   aux162=eepromfs_getAddress(BLOCK_SIZE_ADDR);

   //calculate selected empty block address...
   aux163=eepromfs_getBlockAddress(blockNmr);                               //data block start address + (block size * empty block finded)                                      
   //add real block size...
   //aux163+=aux162-BLOCK_IDENTIFIER_SIZE;                                           //jump to identifiers zone
   write_page_ext_eeprom(aux163+aux162-BLOCK_IDENTIFIER_SIZE,&(*identIn).control,BLOCK_IDENTIFIER_SIZE);
   return TRUE;
}
Пример #3
0
//Creates a file. If files is out of bounds, already exists or no space aviable, returns with flag errors
short eepromfs_fileTouch(int8 fileNmr)
{
   int8 aux83;
   int16 aux161;
   struct blockIdentifiers blkIdent;

   eepromfs_flag_error=ERR_NO_ERRORS;
   
   //Check if file already exists...
   if(eepromfs_fileExists(fileNmr)) return FALSE;
   
   //Search for an empty block to store the file...
   aux83=eepromfs_findEmptyBlock(0);
   
   if(aux83==EEPROM_EMPTY_VALUE) return FALSE;
   
   //Now, write INDEX data
   //get INDEX BLOCK START ADDRESS
   aux161=eepromfs_getAddress(INDEX_BLOCK_START_ADDR);
   //add file number...
   aux161+=fileNmr;

   //write index data. now index points to block :)   
   write_ext_eeprom(aux161,aux83);

   blkIdent.state=1;
   blkIdent.control=0x00;
   blkIdent.control2=0x00;
   //write block state & control values...
   eepromfs_setBlockIdentifiers(aux83,&blkIdent);       //indicate that file haves 0 bytes & some other important stuff...

   //return with success...
   return TRUE;
}
Пример #4
0
void write16_ext_eeprom(int16 addr, int16 data) 
{ 
    int i; 
   
    for (i = 0; i < 2; i++)
    { 
        write_ext_eeprom(i + addr, *((int8*)&data + i) ) ; 
    } 
} 
Пример #5
0
void eeprom_test()
{ 
   int8 data; 
   int8 wrote; 
   int32 addr; 
   int16 errors = 0; 
         
   init_ext_eeprom(); 
         
   // Fill eeprom with random data. 
   printf("\n\r"); 
   printf("writing"); 
   
   // comment out for PIC16
   srand(0x55);
   
   for(addr = 0; addr < EEPROM_SIZE; addr++) 
      { 
       write_ext_eeprom(addr, (int8)rand()); 
       //comment out above and use line below for PIC16
       //write_ext_eeprom(addr, 0x88);
       if((int8)addr == 0) 
          putc('.'); 
      } 
   
   // Read the eeprom and check for errors. 
   printf("\n\r"); 
   printf("reading"); 
   
   // comment out for PIC16
   srand(0x55);
   
   for(addr = 0; addr < EEPROM_SIZE; addr++) 
      { 
       data = read_ext_eeprom(addr); 
       wrote = (int8)rand(); 
       //comment out above and use line below for PIC16
       //wrote = 0x88; 
       if(data != wrote) 
         { 
          printf("%lx: read %x, should be %x\n\r", addr, data, wrote); 
          errors++; 
          if(errors >= 10) 
             break; 
         } 
   
       if((int8)addr == 0) 
          putc('.'); 
      } 
   
   output_low(EEP_WP);
   
   printf("\n\r");
   printf("done\n\r"); 
}
Пример #6
0
//Deletes a file. If files is out of bounds or doesnt exists returns with flag errors
short eepromfs_fileRemove(int8 fileNmr)
{
   struct blockIdentifiers blkIdentSet,blkIdentGet;

   int8 aux83;
   int16 aux161;

   //Check that file number is valid & that it exists...
   if(!eepromfs_fileExists(fileNmr)) return FALSE;

   //we will first, go to file block info...
   aux161=eepromfs_getAddress(INDEX_BLOCK_START_ADDR);
   aux161+=fileNmr;

   //read first block number of file...
   aux83=read_ext_eeprom(aux161);

   //delete this file INDEX BLOCK info...
   write_ext_eeprom(aux161,EEPROM_EMPTY_VALUE);

   do{
      //get block info...
      eepromfs_getBlockIdentifiers(aux83,&blkIdentGet);
      //free this block!!!
      blkIdentSet.state=0;
      blkIdentSet.control=0;
      blkIdentSet.control2=0;
      eepromfs_setBlockIdentifiers(aux83,&blkIdentSet);
      //point to next block to erase...
      aux83=blkIdentGet.control2; 
      //if file continue in other block, continue deleting blocks...
   }while(bit_test(blkIdentGet.control,7));

   //Success!
   return TRUE;
}