/* erase a sector dflash */ /* input: ru16_DflashAddress start address of the sector,which will be erase */ void bscomeep_EraseSector(uint16_t ru16_DflashAddress) { uint8_t lub_err = ERR_OK; /* FSTAT: ACCERR=1,FPVIOL=1 */ FSTAT = 48; /* Clear error flags */ FCCOBIX = 0; /* Clear index register */ FCCOBHI = 18; /* Erase D-Flash sector command */ FCCOBLO = 0; /* High address word */ FCCOBIX++; /* Shift index register */ FCCOB = ru16_DflashAddress+DFLASH_Write_OFFSET; /* Low address word aligned to word*/ FSTAT = 128; /* Clear flag command buffer empty */ //while (FSTAT_CCIF == 0); /* Wait to command complete */ //if (FSTAT_ACCERR || FSTAT_MGSTAT) /* Is access error or other error detected ? */ //{ // lub_err = ERR_NOTAVAIL; /* If yes then error */ //} /// else //misra C // /{ // } } /* write data to Dflash 8 byte */ void bscomeep_Write(uint16_t ru16_DflashAddress,uint16_t *ru16_Data,uint8_t Length) { /* FSTAT: ACCERR=1,FPVIOL=1 */ FSTAT = 48; /* Clear error flags */ FCCOBIX = 0; /* Clear index register */ FCCOBHI = 17; /* Program D-Flash command */ FCCOBLO = 0; /* High address word */ FCCOBIX++; /* Shift index register */ FCCOB = ru16_DflashAddress+DFLASH_Write_OFFSET; /* Low address word */ switch(Length) { case 2: FCCOBIX++; /* Shift index register */ FCCOB = *ru16_Data; /* Load new data */ FSTAT = 128; /* Clear flag command complete */ break; case 4: FCCOBIX++; /* Shift index register */ FCCOB = *ru16_Data; /* Load new data */ FCCOBIX++; /* Shift index register */ FCCOB = *(ru16_Data+1); /* Load new data */ FSTAT = 128; /* Clear flag command complete */ break; case 6: FCCOBIX++; /* Shift index register */ FCCOB = *ru16_Data; /* Load new data */ FCCOBIX++; /* Shift index register */ FCCOB = *(ru16_Data+1); /* Load new data */ FCCOBIX++; /* Shift index register */ FCCOB = *(ru16_Data+2); /* Load new data */ FSTAT = 128; /* Clear flag command complete */ break; case 8: FCCOBIX++; /* Shift index register */ FCCOB = *ru16_Data; /* Load new data */ FCCOBIX++; /* Shift index register */ FCCOB = *(ru16_Data+1); /* Load new data */ FCCOBIX++; /* Shift index register */ FCCOB = *(ru16_Data+2); /* Load new data */ FCCOBIX++; /* Shift index register */ FCCOB = *(ru16_Data+3); /* Load new data */ FSTAT = 128; /* Clear flag command complete */ break; default: break; } //if ((FSTAT_FPVIOL == 1) || (FSTAT_ACCERR == 1)) // { /* Is protection violation or acces error detected ? */ // return ERR_NOTAVAIL; /* If yes then error */ // } // while (!FSTAT_CCIF) {} /* Wait for command completition */ // if (FSTAT_MGSTAT) // { /* Was attempt to write data to the given address errorneous? */ // return ERR_VALUE; /* If yes then error */ // } /// return ERR_OK; }