Esempio n. 1
0
int Datalog::saveData(int a, int b, int c, int d){
	if(datapos >= 800) return 1;
	uint32_t data[5] = {(uint32_t)a, (uint32_t)b, (uint32_t)c, (uint32_t)d};
	R_FlashWrite(0x00100810+(0x00000010*datapos), (uint32_t)(data), 16);
	++ datapos;
	return 0;
}
/*---------------------------------------------------------------------------*
 * Routine:  Flash_Renesas_RX63N_Write
 *---------------------------------------------------------------------------*
 * Description:
 *      Write bytes into the Flash
 * Inputs:
 *      void *aW                    -- Workspace
 *      TUInt32 aOffset             -- Byte Offset into flash to write
 *      TUInt8 *aBuffer             -- Pointer to buffer of data
 *      TUInt32 aNumBytes           -- Number of bytes to write
 * Outputs:
 *      T_uezError                  -- Error code.  Returns
 *                                      UEZ_ERROR_BAD_ALIGNMENT if offset
 *                                      or number of bytes
 *                                      is not on word boundary.
 *---------------------------------------------------------------------------*/
T_uezError Flash_Renesas_RX63N_Write(
        void *aWorkspace,
        TUInt32 aOffset,
        TUInt8 *aBuffer,
        TUInt32 aNumBytes)
{
    T_Flash_Renesas_RX63N_Workspace *p = (T_Flash_Renesas_RX63N_Workspace *)aWorkspace;
    T_uezError error = UEZ_ERROR_NONE;
	TUInt8 padBuffer[256];
	TUInt8 ret = 0;
	TUInt8* flash_ptr = (TUInt8*)(p->iBaseAddr) + aOffset;
	// Let's do it
    UEZSemaphoreGrab(p->iSem, UEZ_TIMEOUT_INFINITE);
	
	memset(padBuffer, 0x00, 256);
	memcpy((void*)padBuffer, (void*)aBuffer, aNumBytes);
    while (1) {
    	/* Check if number of bytes is greater than 256 */
        if (aNumBytes > 256)
        {
            /* Number of bytes to write too high, set error flag to 1 */
            error = UEZ_ERROR_READ_WRITE_ERROR;
            break;
        }
        /* Check if number of bytes to write is a multiple of 8 */
        else if (aNumBytes % 8u)
        {
            /* Pad the data to write so it makes up to the nearest multiple of 8 */
            aNumBytes += 8u - (aNumBytes % 8u);
        }
	

    	// Passing the both the addresses, total offset and buffer(from where we want to write), as a value!!
    	error = (T_uezError)R_FlashWrite(((TUInt32)(p->iBaseAddr)+aOffset), (TUInt32)padBuffer,(TUInt16)aNumBytes ); //<<---- Check for error here
    
    	if(error) {
    		error = UEZ_ERROR_READ_WRITE_ERROR;
            break;
        }
	
    	ret = memcmp(aBuffer, flash_ptr, aNumBytes);
    	if(ret!=0) {
    		error = UEZ_ERROR_READ_WRITE_ERROR;
            break;
        }
        break;
    }
	UEZSemaphoreRelease(p->iSem);

    return error;
}
/******************************************************************************
* void write_data_flash(unsigned char * writeBuffer, unsigned short numBytes, unsigned long writeAddress)
*
* Writes data flash with contents of writeBuffer for size of numBytes to
* location writeAddress.  If contents are not fully verified, it locks.
*
******************************************************************************/
static void write_data_flash(unsigned char * writeBuffer, unsigned short numBytes, unsigned long writeAddress)
{
  unsigned char ret = 0;     // API error flag
  unsigned char pad_buffer[256];   // data padding array and loop counter
  unsigned short srcBytes = numBytes;  // we have to save off size to use for compare later

  /* Clear the contents of the flash write buffer array */
  memset(pad_buffer, 0x00, 256);

  /* Copy contents of the write buffer to the padding buffer */
  memcpy((char *)pad_buffer, (char *)writeBuffer, numBytes);

  /* Check if number of bytes is greater than 256 */
  if (numBytes > 256)
  {
    /* Number of bytes to write too high, set error flag to 1 */
    ret |= 1;
  }
  /* Check if number of bytes to write is a multiple of 8 */
  else if (numBytes % 8u)
  {
    /* Pad the data to write so it makes up to the nearest multiple of 8 */
    numBytes += 8u - (numBytes % 8u);
  }

  /* Halt in while loop when flash API errors detected */
  while (ret);

  /* Write contents of write buffer to data flash */
  ret |= R_FlashWrite(writeAddress,(uint32_t)pad_buffer,numBytes);

  /* Compare memory locations to verify written data */
  ret |= memcmp(writeBuffer, (unsigned char *)writeAddress, srcBytes);

  /* Halt in while loop when flash API errors detected */
  while (ret);
}
Esempio n. 4
0
/************************************************************************************
 * config_init() - called once on hard reset
 *
 * Performs one of 2 actions:
 *	(1) if persistence is set up or out-of-rev load RAM and NVM with settings.h defaults
 *	(2) if persistence is set up and at current config version use NVM data for config
 *
 *	You can assume the cfg struct has been zeroed by a hard reset.
 *	Do not clear it as the version and build numbers have already been set by tg_init()
 *
 * NOTE: Config assertions are handled from the controller
 */
void config_init()
{
	nvObj_t *nv = nv_reset_nv_list();
	char *P_str_axis[3] = {"x","y", "z"};
	config_init_assertions();

#ifdef __ARM
// ++++ The following code is offered until persistence is implemented.
// ++++ Then you can use the AVR code (or something like it)
	cfg.comm_mode = JSON_MODE;					// initial value until EEPROM is read
	_set_defa(nv);
#endif
#ifdef __AVR
	cm_set_units_mode(MILLIMETERS);				// must do inits in millimeter mode
	nv->index = 0;								// this will read the first record in NVM

	read_persistent_value(nv);
	if (nv->value != cs.fw_build) {				// case (1) NVM is not setup or not in revision
//	if (fp_NE(nv->value, cs.fw_build)) {
		_set_defa(nv);
	} else {									// case (2) NVM is setup and in revision
		rpt_print_loading_configs_message();
		for (nv->index=0; nv_index_is_single(nv->index); nv->index++) {
			if (GET_TABLE_BYTE(flags) & F_INITIALIZE) {
				strncpy_P(nv->token, cfgArray[nv->index].token, TOKEN_LEN);	// read the token from the array
				read_persistent_value(nv);
				nv_set(nv);
			}
		}
		sr_init_status_report();
	}
#endif
#ifdef __RX
// ++++ The following code is offered until persistence is implemented.
// ++++ Then you can use the AVR code (or something like it)
	cm_set_units_mode(MILLIMETERS);				// must do inits in millimeter mode
	nv->index = 0;								// this will read the first record in NVM

	spiffs_DIR sf_dir;
	struct spiffs_dirent e;
	struct spiffs_dirent *pe = &e;

	spiffs_file *fd = &uspiffs[0].f;
	spiffs *fs = &uspiffs[0].gSPIFFS;

	R_FlashDataAreaAccess(0xFFFF,0xFFFF);
	checkifParFlashed = (char *)(0x00100000);
	if (SPIFFS_opendir(fs, "/", &sf_dir) == NULL)
	{

	}
	pe = SPIFFS_readdir(&sf_dir, pe);
	*fd = SPIFFS_open(fs, "config.met", SPIFFS_RDWR | SPIFFS_DIRECT, 0);
	SPIFFS_close(fs, *fd);
	if (*fd == SPIFFS_ERR_NOT_FOUND && strcmp(checkifParFlashed,checkParPhrase)) {				// case (1) NVM is not setup or not in revision
		*fd = SPIFFS_open(fs, "config.met", SPIFFS_CREAT | SPIFFS_RDWR | SPIFFS_DIRECT, 0);
		SPIFFS_close(fs, *fd);
		R_FlashEraseRange(0x00100000,0x20);
		R_FlashWrite(0x00100000,(uint32_t)checkParPhrase, 0x20);
		_set_defa(nv);
	} else {									// case (2) NVM is setup and in revision
		rpt_print_loading_configs_message();
		for (nv->index=0; nv_index_is_single(nv->index); nv->index++) {
			if (GET_TABLE_BYTE(flags) & F_INITIALIZE) {
				strncpy_P(nv->token, cfgArray[nv->index].token, TOKEN_LEN);	// read the token from the array
				read_persistent_value(nv);
				nv_set(nv);


			}
		}
		sr_init_status_report();
	}
	z_step_pulse = (M1_TRAVEL_PER_REV*M1_STEP_ANGLE)/(360*M1_MICROSTEPS);
#endif
}
Esempio n. 5
0
int Datalog::saveMaze(Map &map, int n){
	R_FlashWrite(0x00100000+(96*n), (uint32_t)(map.column), 32);
	R_FlashWrite(0x00100020+(96*n), (uint32_t)(map.row), 32);
	R_FlashWrite(0x00100040+(96*n), (uint32_t)(map.reached), 32);
	return 0;
}