//--------------------------------------------------------------------------- static int fs_init(iop_device_t *driver) { if(!fs_inited) { fs_reset(); fs_inited = 1; } return 1; }
} TEST_END TEST(zero_sized_file_44) { fs_reset(); spiffs_file fd = SPIFFS_open(FS, "zero", SPIFFS_RDWR | SPIFFS_CREAT, 0); TEST_CHECK_GE(fd, 0); int res = SPIFFS_close(FS, fd); TEST_CHECK_GE(res, 0); fd = SPIFFS_open(FS, "zero", SPIFFS_RDWR, 0); TEST_CHECK_GE(fd, 0); u8_t buf[8]; res = SPIFFS_read(FS, fd, buf, 8); TEST_CHECK_LT(res, 0); TEST_CHECK_EQ(SPIFFS_errno(FS), SPIFFS_ERR_END_OF_OBJECT); res = SPIFFS_read(FS, fd, buf, 0); TEST_CHECK_GE(res, 0); res = SPIFFS_read(FS, fd, buf, 0); TEST_CHECK_GE(res, 0); buf[0] = 1; buf[1] = 2; res = SPIFFS_write(FS, fd, buf, 2); TEST_CHECK_EQ(res, 2); res = SPIFFS_lseek(FS, fd, 0, SPIFFS_SEEK_SET); TEST_CHECK_GE(res, 0); u8_t b; res = SPIFFS_read(FS, fd, &b, 1); TEST_CHECK_EQ(res, 1); TEST_CHECK_EQ(b, 1); res = SPIFFS_read(FS, fd, &b, 1); TEST_CHECK_EQ(res, 1); TEST_CHECK_EQ(b, 2); res = SPIFFS_read(FS, fd, buf, 8); TEST_CHECK_LT(res, 0); TEST_CHECK_EQ(SPIFFS_errno(FS), SPIFFS_ERR_END_OF_OBJECT); return TEST_RES_OK; } TEST_END
} TEST_END #if !SPIFFS_READ_ONLY TEST(truncate_48) { fs_reset(); u32_t len = SPIFFS_DATA_PAGE_SIZE(FS)/2; s32_t res = test_create_and_write_file("small", len, len); TEST_CHECK_GE(res, 0); spiffs_file fd = SPIFFS_open(FS, "small", SPIFFS_RDWR, 0); TEST_CHECK_GE(fd, 0); spiffs_fd *desc; #if SPIFFS_FILEHDL_OFFSET res = spiffs_fd_get(FS, fd - TEST_SPIFFS_FILEHDL_OFFSET, &desc); #else res = spiffs_fd_get(FS, fd, &desc); #endif TEST_CHECK_GE(res, 0); TEST_CHECK_EQ(desc->size, len); u32_t new_len = len/2; res = spiffs_object_truncate(desc, new_len, 0); TEST_CHECK_GE(res, 0); TEST_CHECK_EQ(desc->size, new_len); res = SPIFFS_close(FS, fd); TEST_CHECK_GE(res, 0); spiffs_stat s; res = SPIFFS_stat(FS, "small", &s); TEST_CHECK_GE(res, 0); TEST_CHECK_EQ(s.size, new_len); res = SPIFFS_remove(FS, "small"); TEST_CHECK_GE(res, 0); fd = SPIFFS_open(FS, "small", SPIFFS_RDWR, 0); TEST_CHECK_LT(fd, 0); TEST_CHECK_EQ(SPIFFS_errno(FS), SPIFFS_ERR_NOT_FOUND); return TEST_RES_OK; } TEST_END
void _setup() { fs_reset(); _setup_test_only(); }
/* Main function */ int main(void) { sc_time_t my_timer; int32_t value; dint(); #if USE_WATCHDOG init_watchdog(); #else WDTCTL = WDTCTL_INIT; //Init watchdog timer #endif init_ports(); init_clock(); sc_init_timer(); scandal_init(); config_read(); {volatile int i; for(i=0; i<100; i++) ; } /* Below here, we assume we have a config */ /* Send out the error that we've reset -- it's not fatal obviously, but we want to know when it happens, and it really is an error, since something that's solar powered should be fairly constantly powered */ scandal_do_user_err(UNSWMPPTNG_ERROR_WATCHDOG_RESET); /* Make sure our variables are set up properly */ tracker_status = 0; /* Initialise FPGA (or, our case, CPLD) stuff */ fpga_init(); /* Starts the ADC and control loop interrupt */ control_init(); /* Initialise the PV tracking mechanism */ pv_track_init(); eint(); my_timer = sc_get_timer(); while (1) { sc_time_t timeval; timeval = sc_get_timer(); handle_scandal(); /* pv_track sends data when it feels like it */ pv_track_send_data(); /* Periodically send out the values recorded by the ADC */ if(timeval >= my_timer + TELEMETRY_UPDATE_PERIOD){ my_timer = timeval; toggle_yellow_led(); #if USE_WATCHDOG kick_watchdog(); #endif mpptng_do_errors(); pv_track_send_telemetry(); /* We send the Input current and voltage from within the pvtrack module */ /* scandal_send_scaled_channel(TELEM_LOW, UNSWMPPTNG_IN_VOLTAGE, sample_adc(MEAS_VIN1)); scandal_send_scaled_channel(TELEM_LOW, UNSWMPPTNG_IN_CURRENT, sample_adc(MEAS_IIN1));*/ scandal_send_scaled_channel(TELEM_LOW, UNSWMPPTNG_OUT_VOLTAGE, sample_adc(MEAS_VOUT)); scandal_send_scaled_channel(TELEM_LOW, UNSWMPPTNG_HEATSINK_TEMP, sample_adc(MEAS_THEATSINK)); scandal_send_scaled_channel(TELEM_LOW, UNSWMPPTNG_15V, sample_adc(MEAS_15V)); scandal_send_channel(TELEM_LOW, UNSWMPPTNG_STATUS, tracker_status); /* Pre-scale for the temperature */ { int32_t degC = sample_adc(MEAS_TAMBIENT); degC = (((degC - 1615)*704*1000)/4095); scandal_send_scaled_channel(TELEM_LOW, UNSWMPPTNG_AMBIENT_TEMP, degC); } #if DEBUG >= 1 scandal_send_channel(TELEM_LOW, 134, output); scandal_send_channel(TELEM_LOW, 136, fpga_nFS()); #endif } /* If we're not tracking, check to see that our start-up criteria are satisfied, and then initialise the control loops and restart tracking */ if((tracker_status & STATUS_TRACKING) == 0){ /* Check the input voltage */ value = sample_adc(MEAS_VIN1); scandal_get_scaled_value(UNSWMPPTNG_IN_VOLTAGE, &value); if(value < config.min_vin) continue; /* Check the output voltage */ value = sample_adc(MEAS_VOUT); scandal_get_scaled_value(UNSWMPPTNG_OUT_VOLTAGE, &value); if(value > config.max_vout) continue; tracker_status |= STATUS_TRACKING; /* Initialise the tracking algorithm */ // pv_track_init(); /* Reset the FPGA */ fs_reset(); /* Initialise the control loop */ control_start(); /* Enable the FPGA */ fpga_enable(FPGA_ON); } } }
void _setup() { fs_reset(); fs_set_validate_flashing(1); test_init(test_on_stop); }
} TEST_END #endif TEST(eof_tell_72) { fs_reset(); s32_t res; spiffs_file fd = SPIFFS_open(FS, "file", SPIFFS_CREAT | SPIFFS_RDWR | SPIFFS_APPEND, 0); TEST_CHECK_GT(fd, 0); TEST_CHECK_EQ(SPIFFS_eof(FS, fd), 1); TEST_CHECK_EQ(SPIFFS_tell(FS, fd), 0); res = SPIFFS_write(FS, fd, "test", 4); TEST_CHECK_EQ(res, 4); TEST_CHECK_EQ(SPIFFS_eof(FS, fd), 1); TEST_CHECK_EQ(SPIFFS_tell(FS, fd), 4); res = SPIFFS_fflush(FS, fd); TEST_CHECK_EQ(res, SPIFFS_OK); TEST_CHECK_EQ(SPIFFS_eof(FS, fd), 1); TEST_CHECK_EQ(SPIFFS_tell(FS, fd), 4); res = SPIFFS_lseek(FS, fd, 2, SPIFFS_SEEK_SET); TEST_CHECK_EQ(res, 2); TEST_CHECK_EQ(SPIFFS_eof(FS, fd), 0); TEST_CHECK_EQ(SPIFFS_tell(FS, fd), 2); res = SPIFFS_write(FS, fd, "test", 4); TEST_CHECK_EQ(res, 4); TEST_CHECK_EQ(SPIFFS_eof(FS, fd), 1); TEST_CHECK_EQ(SPIFFS_tell(FS, fd), 8); res = SPIFFS_fflush(FS, fd); TEST_CHECK_EQ(res, SPIFFS_OK); TEST_CHECK_EQ(SPIFFS_eof(FS, fd), 1); TEST_CHECK_EQ(SPIFFS_tell(FS, fd), 8); res = SPIFFS_close(FS, fd); TEST_CHECK_EQ(res, SPIFFS_OK); TEST_CHECK_LT(SPIFFS_eof(FS, fd), SPIFFS_OK); TEST_CHECK_LT(SPIFFS_tell(FS, fd), SPIFFS_OK); fd = SPIFFS_open(FS, "file", SPIFFS_RDWR, 0); TEST_CHECK_GT(fd, 0); TEST_CHECK_EQ(SPIFFS_eof(FS, fd), 0); TEST_CHECK_EQ(SPIFFS_tell(FS, fd), 0); res = SPIFFS_lseek(FS, fd, 2, SPIFFS_SEEK_SET); TEST_CHECK_EQ(res, 2); TEST_CHECK_EQ(SPIFFS_eof(FS, fd), 0); TEST_CHECK_EQ(SPIFFS_tell(FS, fd), 2); res = SPIFFS_write(FS, fd, "test", 4); TEST_CHECK_EQ(res, 4); TEST_CHECK_EQ(SPIFFS_eof(FS, fd), 0); TEST_CHECK_EQ(SPIFFS_tell(FS, fd), 6); res = SPIFFS_fflush(FS, fd); TEST_CHECK_EQ(res, SPIFFS_OK); TEST_CHECK_EQ(SPIFFS_eof(FS, fd), 0); TEST_CHECK_EQ(SPIFFS_tell(FS, fd), 6); res = SPIFFS_lseek(FS, fd, 0, SPIFFS_SEEK_END); TEST_CHECK_EQ(res, 8); TEST_CHECK_EQ(SPIFFS_eof(FS, fd), 1); TEST_CHECK_EQ(SPIFFS_tell(FS, fd), 8); return TEST_RES_OK; } TEST_END
void _setup() { _fs_locks = 0; fs_reset(); _setup_test_only(); }