Esempio n. 1
0
void bricklet_write_plugin_to_flash(const char *plugin,
	                                const uint8_t position,
	                                const uint8_t bricklet) {
	// Disable all irqs before plugin is written to flash.
	// While writing to flash there can't be any other access to the flash
	// (e.g. via interrupts).
	DISABLE_RESET_BUTTON();
	__disable_irq();

	// Unlock flash region
    FLASHD_Unlock(baddr[bricklet].plugin,
	              baddr[bricklet].plugin + BRICKLET_PLUGIN_MAX_SIZE,
				  0,
				  0);

    // Write plugin to flash
    uint16_t add = position*PLUGIN_CHUNK_SIZE;
    FLASHD_Write(baddr[bricklet].plugin + add, plugin, PLUGIN_CHUNK_SIZE);

    // Lock flash and enable irqs again
    FLASHD_Lock(baddr[bricklet].plugin,
                baddr[bricklet].plugin + BRICKLET_PLUGIN_MAX_SIZE,
				0,
				0);

    __enable_irq();
    ENABLE_RESET_BUTTON();
}
Esempio n. 2
0
void bricklet_write_asc_to_flash(const uint8_t bricklet) {
	// Disable all irqs before plugin is written to flash.
	// While writing to flash there can't be any other access to the flash
	// (e.g. via interrupts).
	DISABLE_RESET_BUTTON();
	__disable_irq();

	// Unlock flash region
	FLASHD_Unlock(baddr[bricklet].plugin,
				  baddr[bricklet].plugin + BRICKLET_PLUGIN_MAX_SIZE,
				  0,
				  0);

	// Write api address to flash
	int adr = (int)&ba;
	FLASHD_Write(baddr[bricklet].api, &adr, sizeof(int*));

	// Write settings address to flash
	adr = (int)&bs[bricklet];
	FLASHD_Write(baddr[bricklet].settings, &adr, sizeof(int*));

	// Write context address to flash
	adr = (int)&bc[bricklet];
	FLASHD_Write(baddr[bricklet].context, &adr, sizeof(int*));

	// Lock flash and enable irqs again
	FLASHD_Lock(baddr[bricklet].plugin,
				baddr[bricklet].plugin + BRICKLET_PLUGIN_MAX_SIZE,
				0,
				0);

	__enable_irq();
    ENABLE_RESET_BUTTON();
}
Esempio n. 3
0
bool read_calibration_from_bno055_and_save_to_flash(void) {
	if(sensor_data.calibration_status != 0xFF) {
		return false;
	}

	bmo_write_register(REG_OPR_MODE, 0b00000000); // Configuration Mode
	SLEEP_MS(19);
	IMUCalibration imu_calibration = {{0}};
	bmo_read_registers(REG_ACC_OFFSET_X_LSB, (uint8_t *)&imu_calibration, IMU_CALIBRATION_LENGTH);
	imu_calibration.password = IMU_CALIBRATION_PASSWORD;
	bmo_write_register(REG_OPR_MODE, 0b00001100); // Enable NDOF, see Table 3-5
	SLEEP_MS(7);

	logimui("Read calibration from BNO055 and save to flash:\n\r");
	logimui(" Mag Offset: %d %d %d\n\r", imu_calibration.mag_offset[0], imu_calibration.mag_offset[1], imu_calibration.mag_offset[2]);
	logimui(" Acc Offset: %d %d %d\n\r", imu_calibration.acc_offset[0], imu_calibration.acc_offset[1], imu_calibration.acc_offset[2]);
	logimui(" Gyr Offset: %d %d %d\n\r", imu_calibration.gyr_offset[0], imu_calibration.gyr_offset[1], imu_calibration.gyr_offset[2]);
	logimui(" Acc Radius: %d\n\r", imu_calibration.acc_radius);
	logimui(" Mag Radius: %d\n\r", imu_calibration.mag_radius);

	DISABLE_RESET_BUTTON();
	__disable_irq();

	// Unlock flash region
	if(FLASHD_Unlock(IMU_CALIBRATION_ADDRESS,
	                 END_OF_BRICKLET_MEMORY,
	                 NULL,
	                 NULL) != 0) {
		return false;
	}

	if(FLASHD_Write(IMU_CALIBRATION_ADDRESS,
	                &imu_calibration,
	                sizeof(IMUCalibration)) != 0) {
		return false;
	}

	if(FLASHD_Lock(IMU_CALIBRATION_ADDRESS,
	               END_OF_BRICKLET_MEMORY,
	               NULL,
			       NULL) != 0) {
		return false;
	}

	__enable_irq();
    ENABLE_RESET_BUTTON();

	return true;
}