mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-04 18:03:20 +03:00
Move .C to .CPP in the code (#5696)
Use g++ to compile core files to get additional C++ checks on the code. Also move libb64 constants to PROGMEM, saving ~128 bytes of heap when used.
This commit is contained in:
parent
24fa59df4b
commit
f706c83b66
@ -27,6 +27,9 @@
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include "StackThunk.h"
|
||||
#include <ets_sys.h>
|
||||
|
||||
extern "C" {
|
||||
|
||||
uint32_t *stack_thunk_ptr = NULL;
|
||||
uint32_t *stack_thunk_top = NULL;
|
||||
@ -115,8 +118,10 @@ void stack_thunk_dump_stack()
|
||||
}
|
||||
ets_printf(">>>stack>>>\n");
|
||||
while (pos < stack_thunk_ptr) {
|
||||
ets_printf("%08x: %08x %08x %08x %08x\n", pos, pos[0], pos[1], pos[2], pos[3]);
|
||||
ets_printf("%08x: %08x %08x %08x %08x\n", (int32_t)pos, pos[0], pos[1], pos[2], pos[3]);
|
||||
pos += 4;
|
||||
}
|
||||
ets_printf("<<<stack<<<\n");
|
||||
}
|
||||
|
||||
};
|
@ -23,6 +23,7 @@
|
||||
#include <string.h>
|
||||
#include "ets_sys.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
#define CONT_STACKGUARD 0xfeefeffe
|
||||
|
||||
@ -80,3 +81,5 @@ void cont_repaint_stack(cont_t *cont)
|
||||
cont->stack[pos] = CONT_STACKGUARD;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
@ -23,7 +23,9 @@
|
||||
#include <stdbool.h>
|
||||
#include "eboot_command.h"
|
||||
|
||||
uint32_t crc_update(uint32_t crc, const uint8_t *data, size_t length)
|
||||
extern "C" {
|
||||
|
||||
static uint32_t crc_update(uint32_t crc, const uint8_t *data, size_t length)
|
||||
{
|
||||
uint32_t i;
|
||||
bool bit;
|
||||
@ -45,7 +47,7 @@ uint32_t crc_update(uint32_t crc, const uint8_t *data, size_t length)
|
||||
return crc;
|
||||
}
|
||||
|
||||
uint32_t eboot_command_calculate_crc32(const struct eboot_command* cmd)
|
||||
static uint32_t eboot_command_calculate_crc32(const struct eboot_command* cmd)
|
||||
{
|
||||
return crc_update(0xffffffff, (const uint8_t*) cmd,
|
||||
offsetof(struct eboot_command, crc32));
|
||||
@ -86,3 +88,4 @@ void eboot_command_clear()
|
||||
RTC_MEM[offsetof(struct eboot_command, crc32) / sizeof(uint32_t)] = 0;
|
||||
}
|
||||
|
||||
};
|
@ -25,6 +25,7 @@
|
||||
#include <stdbool.h>
|
||||
#include "flash_utils.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
int SPIEraseAreaEx(const uint32_t start, const uint32_t size)
|
||||
{
|
||||
@ -62,3 +63,4 @@ int SPIEraseAreaEx(const uint32_t start, const uint32_t size)
|
||||
return 0;
|
||||
}
|
||||
|
||||
};
|
@ -23,11 +23,11 @@
|
||||
#include "Arduino.h"
|
||||
#include "osapi.h"
|
||||
#include "ets_sys.h"
|
||||
|
||||
|
||||
#include "i2s_reg.h"
|
||||
#include "i2s.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
#define SLC_BUF_CNT (8) // Number of buffers in the I2S circular buffer
|
||||
#define SLC_BUF_LEN (64) // Length of one buffer, in 32-bit words.
|
||||
|
||||
@ -573,3 +573,5 @@ void i2s_end() {
|
||||
rx = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
@ -29,6 +29,8 @@
|
||||
#include <math.h>
|
||||
#include "stdlib_noniso.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
char* ltoa(long value, char* result, int base) {
|
||||
return itoa((int)value, result, base);
|
||||
}
|
||||
@ -109,3 +111,5 @@ char * dtostrf(double number, signed char width, unsigned char prec, char *s) {
|
||||
*out = 0;
|
||||
return s;
|
||||
}
|
||||
|
||||
};
|
@ -19,88 +19,90 @@
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include "c_types.h"
|
||||
#include "ets_sys.h"
|
||||
#include "spi_flash.h"
|
||||
#include "user_interface.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include "c_types.h"
|
||||
#include "ets_sys.h"
|
||||
#include "spi_flash.h"
|
||||
extern "C" {
|
||||
|
||||
static const uint8_t ICACHE_FLASH_ATTR phy_init_data[128] =
|
||||
{
|
||||
[0] = 5, // Reserved, do not change
|
||||
[1] = 8, // Reserved, do not change
|
||||
[2] = 4, // Reserved, do not change
|
||||
[3] = 2, // Reserved, do not change
|
||||
[4] = 5, // Reserved, do not change
|
||||
[5] = 5, // Reserved, do not change
|
||||
[6] = 5, // Reserved, do not change
|
||||
[7] = 2, // Reserved, do not change
|
||||
[8] = 5, // Reserved, do not change
|
||||
[9] = 0, // Reserved, do not change
|
||||
[10] = 4, // Reserved, do not change
|
||||
[11] = 5, // Reserved, do not change
|
||||
[12] = 5, // Reserved, do not change
|
||||
[13] = 4, // Reserved, do not change
|
||||
[14] = 5, // Reserved, do not change
|
||||
[15] = 5, // Reserved, do not change
|
||||
[16] = 4, // Reserved, do not change
|
||||
[17] = -2, // Reserved, do not change
|
||||
[18] = -3, // Reserved, do not change
|
||||
[19] = -1, // Reserved, do not change
|
||||
[20] = -16, // Reserved, do not change
|
||||
[21] = -16, // Reserved, do not change
|
||||
[22] = -16, // Reserved, do not change
|
||||
[23] = -32, // Reserved, do not change
|
||||
[24] = -32, // Reserved, do not change
|
||||
[25] = -32, // Reserved, do not change
|
||||
/*[0] =*/ 5, // Reserved, do not change
|
||||
/*[1] =*/ 8, // Reserved, do not change
|
||||
/*[2] =*/ 4, // Reserved, do not change
|
||||
/*[3] =*/ 2, // Reserved, do not change
|
||||
/*[4] =*/ 5, // Reserved, do not change
|
||||
/*[5] =*/ 5, // Reserved, do not change
|
||||
/*[6] =*/ 5, // Reserved, do not change
|
||||
/*[7] =*/ 2, // Reserved, do not change
|
||||
/*[8] =*/ 5, // Reserved, do not change
|
||||
/*[9] =*/ 0, // Reserved, do not change
|
||||
/*[10] =*/ 4, // Reserved, do not change
|
||||
/*[11] =*/ 5, // Reserved, do not change
|
||||
/*[12] =*/ 5, // Reserved, do not change
|
||||
/*[13] =*/ 4, // Reserved, do not change
|
||||
/*[14] =*/ 5, // Reserved, do not change
|
||||
/*[15] =*/ 5, // Reserved, do not change
|
||||
/*[16] =*/ 4, // Reserved, do not change
|
||||
/*[17] =*/ (uint8_t)-2, // Reserved, do not change
|
||||
/*[18] =*/ (uint8_t)-3, // Reserved, do not change
|
||||
/*[19] =*/ (uint8_t)-1, // Reserved, do not change
|
||||
/*[20] =*/ (uint8_t)-16, // Reserved, do not change
|
||||
/*[21] =*/ (uint8_t)-16, // Reserved, do not change
|
||||
/*[22] =*/ (uint8_t)-16, // Reserved, do not change
|
||||
/*[23] =*/ (uint8_t)-32, // Reserved, do not change
|
||||
/*[24] =*/ (uint8_t)-32, // Reserved, do not change
|
||||
/*[25] =*/ (uint8_t)-32, // Reserved, do not change
|
||||
|
||||
[26] = 225, // spur_freq_cfg, spur_freq=spur_freq_cfg/spur_freq_cfg_div
|
||||
[27] = 10, // spur_freq_cfg_div
|
||||
/*[26] =*/ 225, // spur_freq_cfg, spur_freq=spur_freq_cfg/spur_freq_cfg_div
|
||||
/*[27] =*/ 10, // spur_freq_cfg_div
|
||||
// each bit for 1 channel, 1 to select the spur_freq if in band, else 40
|
||||
[28] = 0xff, // spur_freq_en_h
|
||||
[29] = 0xff, // spur_freq_en_l
|
||||
/*[28] =*/ 0xff, // spur_freq_en_h
|
||||
/*[29] =*/ 0xff, // spur_freq_en_l
|
||||
|
||||
[30] = 0xf8, // Reserved, do not change
|
||||
[31] = 0, // Reserved, do not change
|
||||
[32] = 0xf8, // Reserved, do not change
|
||||
[33] = 0xf8, // Reserved, do not change
|
||||
/*[30] =*/ 0xf8, // Reserved, do not change
|
||||
/*[31] =*/ 0, // Reserved, do not change
|
||||
/*[32] =*/ 0xf8, // Reserved, do not change
|
||||
/*[33] =*/ 0xf8, // Reserved, do not change
|
||||
|
||||
[34] = 78, // target_power_qdb_0, target power is 78/4=19.5dbm
|
||||
[35] = 74, // target_power_qdb_1, target power is 74/4=18.5dbm
|
||||
[36] = 70, // target_power_qdb_2, target power is 70/4=17.5dbm
|
||||
[37] = 64, // target_power_qdb_3, target power is 64/4=16dbm
|
||||
[38] = 60, // target_power_qdb_4, target power is 60/4=15dbm
|
||||
[39] = 56, // target_power_qdb_5, target power is 56/4=14dbm
|
||||
/*[34] =*/ 78, // target_power_qdb_0, target power is 78/4=19.5dbm
|
||||
/*[35] =*/ 74, // target_power_qdb_1, target power is 74/4=18.5dbm
|
||||
/*[36] =*/ 70, // target_power_qdb_2, target power is 70/4=17.5dbm
|
||||
/*[37] =*/ 64, // target_power_qdb_3, target power is 64/4=16dbm
|
||||
/*[38] =*/ 60, // target_power_qdb_4, target power is 60/4=15dbm
|
||||
/*[39] =*/ 56, // target_power_qdb_5, target power is 56/4=14dbm
|
||||
|
||||
[40] = 0, // target_power_index_mcs0
|
||||
[41] = 0, // target_power_index_mcs1
|
||||
[42] = 1, // target_power_index_mcs2
|
||||
[43] = 1, // target_power_index_mcs3
|
||||
[44] = 2, // target_power_index_mcs4
|
||||
[45] = 3, // target_power_index_mcs5
|
||||
[46] = 4, // target_power_index_mcs6
|
||||
[47] = 5, // target_power_index_mcs7
|
||||
/*[40] =*/ 0, // target_power_index_mcs0
|
||||
/*[41] =*/ 0, // target_power_index_mcs1
|
||||
/*[42] =*/ 1, // target_power_index_mcs2
|
||||
/*[43] =*/ 1, // target_power_index_mcs3
|
||||
/*[44] =*/ 2, // target_power_index_mcs4
|
||||
/*[45] =*/ 3, // target_power_index_mcs5
|
||||
/*[46] =*/ 4, // target_power_index_mcs6
|
||||
/*[47] =*/ 5, // target_power_index_mcs7
|
||||
|
||||
// crystal_26m_en
|
||||
// 0: 40MHz
|
||||
// 1: 26MHz
|
||||
// 2: 24MHz
|
||||
#if F_CRYSTAL == 40000000
|
||||
[48] = 0,
|
||||
/*[48] =*/ 0,
|
||||
#else
|
||||
[48] = 1,
|
||||
/*[48] =*/ 1,
|
||||
#endif
|
||||
|
||||
|
||||
/*[49] =*/ 0,
|
||||
|
||||
// sdio_configure
|
||||
// 0: Auto by pin strapping
|
||||
// 1: SDIO dataoutput is at negative edges (SDIO V1.1)
|
||||
// 2: SDIO dataoutput is at positive edges (SDIO V2.0)
|
||||
[50] = 0,
|
||||
/*[50] =*/ 0,
|
||||
|
||||
// bt_configure
|
||||
// 0: None,no bluetooth
|
||||
@ -113,7 +115,7 @@ static const uint8_t ICACHE_FLASH_ATTR phy_init_data[128] =
|
||||
// MTMS -> BT_PRIORITY
|
||||
// MTCK -> BT_ACTIVE
|
||||
// U0RXD -> ANT_SEL_BT
|
||||
[51] = 0,
|
||||
/*[51] =*/ 0,
|
||||
|
||||
// bt_protocol
|
||||
// 0: WiFi-BT are not enabled. Antenna is for WiFi
|
||||
@ -122,16 +124,16 @@ static const uint8_t ICACHE_FLASH_ATTR phy_init_data[128] =
|
||||
// 3: WiFi-BT 3-wire are enabled, (when BT_ACTIVE = 0, BT_PRIORITY must be 0), independent ant
|
||||
// 4: WiFi-BT 2-wire are enabled, (only use BT_ACTIVE), share ant
|
||||
// 5: WiFi-BT 3-wire are enabled, (when BT_ACTIVE = 0, BT_PRIORITY must be 0), share ant
|
||||
[52] = 0,
|
||||
/*[52] =*/ 0,
|
||||
|
||||
// dual_ant_configure
|
||||
// 0: None
|
||||
// 1: dual_ant (antenna diversity for WiFi-only): GPIO0 + U0RXD
|
||||
// 2: T/R switch for External PA/LNA: GPIO0 is high and U0RXD is low during Tx
|
||||
// 3: T/R switch for External PA/LNA: GPIO0 is low and U0RXD is high during Tx
|
||||
[53] = 0,
|
||||
/*[53] =*/ 0,
|
||||
|
||||
[54] = 2, // Reserved, do not change
|
||||
/*[54] =*/ 2, // Reserved, do not change
|
||||
|
||||
// share_xtal
|
||||
// This option is to share crystal clock for BT
|
||||
@ -140,28 +142,53 @@ static const uint8_t ICACHE_FLASH_ATTR phy_init_data[128] =
|
||||
// 1: Forcely On
|
||||
// 2: Automatically On according to XPD_DCDC
|
||||
// 3: Automatically On according to GPIO2
|
||||
[55] = 0,
|
||||
/*[55] =*/ 0,
|
||||
|
||||
[64] = 225, // spur_freq_cfg_2, spur_freq_2=spur_freq_cfg_2/spur_freq_cfg_div_2
|
||||
[65] = 10, // spur_freq_cfg_div_2
|
||||
[66] = 0, // spur_freq_en_h_2
|
||||
[67] = 0, // spur_freq_en_l_2
|
||||
[68] = 0, // spur_freq_cfg_msb
|
||||
[69] = 0, // spur_freq_cfg_2_msb
|
||||
[70] = 0, // spur_freq_cfg_3_low
|
||||
[71] = 0, // spur_freq_cfg_3_high
|
||||
[72] = 0, // spur_freq_cfg_4_low
|
||||
[73] = 0, // spur_freq_cfg_4_high
|
||||
/*[56] =*/ 0,
|
||||
/*[57] =*/ 0,
|
||||
/*[58] =*/ 0,
|
||||
/*[59] =*/ 0,
|
||||
/*[60] =*/ 0,
|
||||
/*[61] =*/ 0,
|
||||
/*[62] =*/ 0,
|
||||
/*[63] =*/ 0,
|
||||
|
||||
[74] = 1, // Reserved, do not change
|
||||
[75] = 0x93, // Reserved, do not change
|
||||
[76] = 0x43, // Reserved, do not change
|
||||
[77] = 0x00, // Reserved, do not change
|
||||
/*[64] =*/ 225, // spur_freq_cfg_2, spur_freq_2=spur_freq_cfg_2/spur_freq_cfg_div_2
|
||||
/*[65] =*/ 10, // spur_freq_cfg_div_2
|
||||
/*[66] =*/ 0, // spur_freq_en_h_2
|
||||
/*[67] =*/ 0, // spur_freq_en_l_2
|
||||
/*[68] =*/ 0, // spur_freq_cfg_msb
|
||||
/*[69] =*/ 0, // spur_freq_cfg_2_msb
|
||||
/*[70] =*/ 0, // spur_freq_cfg_3_low
|
||||
/*[71] =*/ 0, // spur_freq_cfg_3_high
|
||||
/*[72] =*/ 0, // spur_freq_cfg_4_low
|
||||
/*[73] =*/ 0, // spur_freq_cfg_4_high
|
||||
|
||||
/*[74] =*/ 1, // Reserved, do not change
|
||||
/*[75] =*/ 0x93, // Reserved, do not change
|
||||
/*[76] =*/ 0x43, // Reserved, do not change
|
||||
/*[77] =*/ 0x00, // Reserved, do not change
|
||||
|
||||
/*[78] =*/ 0,
|
||||
/*[79] =*/ 0,
|
||||
/*[80] =*/ 0,
|
||||
/*[81] =*/ 0,
|
||||
/*[82] =*/ 0,
|
||||
/*[83] =*/ 0,
|
||||
/*[84] =*/ 0,
|
||||
/*[85] =*/ 0,
|
||||
/*[86] =*/ 0,
|
||||
/*[87] =*/ 0,
|
||||
/*[88] =*/ 0,
|
||||
/*[89] =*/ 0,
|
||||
/*[90] =*/ 0,
|
||||
/*[91] =*/ 0,
|
||||
/*[92] =*/ 0,
|
||||
|
||||
// low_power_en
|
||||
// 0: disable low power mode
|
||||
// 1: enable low power mode
|
||||
[93] = 0,
|
||||
/*[93] =*/ 0,
|
||||
|
||||
// lp_rf_stg10
|
||||
// the attenuation of RF gain stage 0 and 1,
|
||||
@ -173,7 +200,7 @@ static const uint8_t ICACHE_FLASH_ATTR phy_init_data[128] =
|
||||
// 0x8: -14db,
|
||||
// 0x4: -17.5,
|
||||
// 0x0: -23
|
||||
[94] = 0x00,
|
||||
/*[94] =*/ 0x00,
|
||||
|
||||
|
||||
// lp_bb_att_ext
|
||||
@ -188,20 +215,29 @@ static const uint8_t ICACHE_FLASH_ATTR phy_init_data[128] =
|
||||
// 7: -1.75db,
|
||||
// 8: -2db
|
||||
// max valve is 24(-6db)
|
||||
[95] = 0,
|
||||
/*[95] =*/ 0,
|
||||
|
||||
// pwr_ind_11b_en
|
||||
// 0: 11b power is same as mcs0 and 6m
|
||||
// 1: enable 11b power different with ofdm
|
||||
[96] = 0,
|
||||
/*[96] =*/ 0,
|
||||
|
||||
// pwr_ind_11b_0
|
||||
// 1m, 2m power index [0~5]
|
||||
[97] = 0,
|
||||
/*[97] =*/ 0,
|
||||
|
||||
// pwr_ind_11b_1
|
||||
// 5.5m, 11m power index [0~5]
|
||||
[98] = 0,
|
||||
/*[98] =*/ 0,
|
||||
|
||||
/*[99] =*/ 0,
|
||||
/*[100] =*/ 0,
|
||||
/*[101] =*/ 0,
|
||||
/*[102] =*/ 0,
|
||||
/*[103] =*/ 0,
|
||||
/*[104] =*/ 0,
|
||||
/*[105] =*/ 0,
|
||||
/*[106] =*/ 0,
|
||||
|
||||
// vdd33_const
|
||||
// the voltage of PA_VDD
|
||||
@ -220,10 +256,14 @@ static const uint8_t ICACHE_FLASH_ATTR phy_init_data[128] =
|
||||
// getVcc function (system_get_vdd33):
|
||||
// is only available when TOUT pin17 is suspended (floating), this function measure the power voltage of VDD3P3 pin 3 and 4
|
||||
// For this function the vdd33_const must be set to 255 (0xFF).
|
||||
[107] = 33,
|
||||
/*[107] =*/ 33,
|
||||
|
||||
// disable RF calibration for certain number of times
|
||||
[108] = 0,
|
||||
/*[108] =*/ 0,
|
||||
|
||||
/*[109] =*/ 0,
|
||||
/*[110] =*/ 0,
|
||||
/*[111] =*/ 0,
|
||||
|
||||
// freq_correct_en
|
||||
// bit[0]:0->do not correct frequency offset, 1->correct frequency offset.
|
||||
@ -234,20 +274,21 @@ static const uint8_t ICACHE_FLASH_ATTR phy_init_data[128] =
|
||||
// 3: auto measure frequency offset and correct it, bbpll is 160M, it only can correct + frequency offset.
|
||||
// 5: use 113 byte force_freq_offset to correct frequency offset, bbpll is 168M, it can correct + and - frequency offset.
|
||||
// 7: use 113 byte force_freq_offset to correct frequency offset, bbpll is 160M , it only can correct + frequency offset.
|
||||
[112] = 0,
|
||||
/*[112] =*/ 0,
|
||||
|
||||
// force_freq_offset
|
||||
// signed, unit is 8kHz
|
||||
[113] = 0,
|
||||
/*[113] =*/ 0,
|
||||
|
||||
// rf_cal_use_flash
|
||||
// 0: RF init no RF CAL, using all RF CAL data in flash, it takes about 2ms for RF init
|
||||
// 1: RF init only do TX power control CAL, others using RF CAL data in flash, it takes about 20ms for RF init
|
||||
// 2: RF init no RF CAL, using all RF CAL data in flash, it takes about 2ms for RF init (same as 0?!)
|
||||
// 3: RF init do all RF CAL, it takes about 200ms for RF init
|
||||
[114] = 1
|
||||
/*[114] =*/ 1
|
||||
};
|
||||
|
||||
|
||||
// These functions will be overriden from C++ code.
|
||||
// Unfortunately, we can't use extern "C" because Arduino preprocessor
|
||||
// doesn't generate forward declarations for extern "C" functions correctly,
|
||||
@ -260,6 +301,7 @@ static bool spoof_init_data = false;
|
||||
|
||||
extern int __real_spi_flash_read(uint32_t addr, uint32_t* dst, size_t size);
|
||||
extern int ICACHE_RAM_ATTR __wrap_spi_flash_read(uint32_t addr, uint32_t* dst, size_t size);
|
||||
extern int __get_adc_mode();
|
||||
|
||||
extern int ICACHE_RAM_ATTR __wrap_spi_flash_read(uint32_t addr, uint32_t* dst, size_t size)
|
||||
{
|
||||
@ -313,3 +355,5 @@ void user_rf_pre_init()
|
||||
|
||||
|
||||
void ICACHE_RAM_ATTR user_spi_flash_dio_to_qio_pre_init() {}
|
||||
|
||||
};
|
@ -22,6 +22,8 @@
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include "debug.h"
|
||||
#include "ets_sys.h"
|
||||
#include "user_interface.h"
|
||||
@ -31,6 +33,8 @@
|
||||
#include "gdb_hooks.h"
|
||||
#include "StackThunk.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
extern void __real_system_restart_local();
|
||||
|
||||
// These will be pointers to PROGMEM const strings
|
||||
@ -91,7 +95,8 @@ void __wrap_system_restart_local() {
|
||||
raise_exception();
|
||||
}
|
||||
|
||||
struct rst_info rst_info = {0};
|
||||
struct rst_info rst_info;
|
||||
memset(&rst_info, 0, sizeof(rst_info));
|
||||
system_rtc_mem_read(0, &rst_info, sizeof(rst_info));
|
||||
if (rst_info.reason != REASON_SOFT_WDT_RST &&
|
||||
rst_info.reason != REASON_EXCEPTION_RST &&
|
||||
@ -100,7 +105,8 @@ void __wrap_system_restart_local() {
|
||||
return;
|
||||
}
|
||||
|
||||
ets_install_putc1(&uart_write_char_d);
|
||||
// TODO: ets_install_putc1 definition is wrong in ets_sys.h, need cast
|
||||
ets_install_putc1((void *)&uart_write_char_d);
|
||||
|
||||
if (s_panic_line) {
|
||||
ets_printf_P(PSTR("\nPanic %S:%d %S"), s_panic_file, s_panic_line, s_panic_func);
|
||||
@ -175,7 +181,7 @@ void __wrap_system_restart_local() {
|
||||
|
||||
custom_crash_callback( &rst_info, sp_dump + offset, stack_end );
|
||||
|
||||
delayMicroseconds(10000);
|
||||
ets_delay_us(10000);
|
||||
__real_system_restart_local();
|
||||
}
|
||||
|
||||
@ -248,3 +254,4 @@ void __panic_func(const char* file, int line, const char* func) {
|
||||
raise_exception();
|
||||
}
|
||||
|
||||
};
|
@ -23,6 +23,8 @@
|
||||
#include "pins_arduino.h"
|
||||
#include "wiring_private.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
unsigned int preferred_si2c_clock = 100000;
|
||||
#include "twi_util.h"
|
||||
|
||||
@ -99,7 +101,7 @@ static void onSdaChange(void);
|
||||
static ETSEvent eventTaskQueue[EVENTTASK_QUEUE_SIZE];
|
||||
static void eventTask(ETSEvent *e);
|
||||
static ETSTimer timer;
|
||||
static void onTimer();
|
||||
static void onTimer(void *unused);
|
||||
|
||||
#define SDA_LOW() (GPES = (1 << twi_sda)) //Enable SDA (becomes output and since GPO is 0 for the pin, it will pull the line low)
|
||||
#define SDA_HIGH() (GPEC = (1 << twi_sda)) //Disable SDA (becomes input and since it has pullup it will go high)
|
||||
@ -179,6 +181,7 @@ static void ICACHE_RAM_ATTR twi_delay(unsigned char v){
|
||||
for (i = 0; i < v; i++) {
|
||||
reg = GPI;
|
||||
}
|
||||
(void)reg;
|
||||
#pragma GCC diagnostic pop
|
||||
}
|
||||
|
||||
@ -478,8 +481,9 @@ void ICACHE_RAM_ATTR twi_onTwipEvent(uint8_t status)
|
||||
}
|
||||
}
|
||||
|
||||
void ICACHE_RAM_ATTR onTimer()
|
||||
void ICACHE_RAM_ATTR onTimer(void *unused)
|
||||
{
|
||||
(void)unused;
|
||||
twi_releaseBus();
|
||||
twip_status = TW_BUS_ERROR;
|
||||
twi_onTwipEvent(twip_status);
|
||||
@ -781,3 +785,5 @@ void ICACHE_RAM_ATTR onSdaChange(void)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
@ -21,6 +21,8 @@
|
||||
|
||||
#include "Arduino.h" // using pinMode
|
||||
|
||||
extern "C" {
|
||||
|
||||
// definitions in esp8266_peri.h style
|
||||
#define GPSD ESP8266_REG(0x368) // GPIO_SIGMA_DELTA register @ 0x600000368
|
||||
#define GPSDT 0 // target, 8 bits
|
||||
@ -172,3 +174,5 @@ uint8_t ICACHE_FLASH_ATTR sigmaDeltaGetPrescaler(void)
|
||||
{
|
||||
return (uint8_t)((GPSD >> GPSDP) & 0xFF);
|
||||
}
|
||||
|
||||
};
|
@ -24,6 +24,8 @@
|
||||
#include "c_types.h"
|
||||
#include "ets_sys.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
// ------------------------------------------------------------------ -
|
||||
// timer 1
|
||||
|
||||
@ -101,3 +103,5 @@ void ICACHE_RAM_ATTR timer0_detachInterrupt() {
|
||||
timer0_user_cb = NULL;
|
||||
ETS_CCOMPARE0_DISABLE();
|
||||
}
|
||||
|
||||
};
|
@ -41,6 +41,8 @@
|
||||
#include "ets_sys.h"
|
||||
#include "core_esp8266_waveform.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
// Maximum delay between IRQs
|
||||
#define MAXIRQUS (10000)
|
||||
|
||||
@ -303,3 +305,5 @@ static ICACHE_RAM_ATTR void timer1Interrupt() {
|
||||
#endif
|
||||
TEIE |= TEIE1; // Edge int enable
|
||||
}
|
||||
|
||||
};
|
@ -25,6 +25,9 @@
|
||||
#include "user_interface.h"
|
||||
#include "cont.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
extern void ets_delay_us(uint32_t us);
|
||||
extern void esp_schedule();
|
||||
extern void esp_yield();
|
||||
|
||||
@ -210,3 +213,5 @@ void init() {
|
||||
os_timer_setfn(µs_overflow_timer, (os_timer_func_t*) µs_overflow_tick, 0);
|
||||
os_timer_arm(µs_overflow_timer, 60000, REPEAT);
|
||||
}
|
||||
|
||||
};
|
@ -24,7 +24,9 @@
|
||||
|
||||
#include "wiring_private.h"
|
||||
#include "pins_arduino.h"
|
||||
#include "user_interface.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
extern int __analogRead(uint8_t pin)
|
||||
{
|
||||
@ -36,3 +38,5 @@ extern int __analogRead(uint8_t pin)
|
||||
}
|
||||
|
||||
extern int analogRead(uint8_t pin) __attribute__ ((weak, alias("__analogRead")));
|
||||
|
||||
};
|
@ -24,8 +24,11 @@
|
||||
#include "c_types.h"
|
||||
#include "eagle_soc.h"
|
||||
#include "ets_sys.h"
|
||||
#include "user_interface.h"
|
||||
#include "core_esp8266_waveform.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
uint8_t esp8266_gpioToFn[16] = {0x34, 0x18, 0x38, 0x14, 0x3C, 0x40, 0x1C, 0x20, 0x24, 0x28, 0x2C, 0x30, 0x04, 0x08, 0x0C, 0x10};
|
||||
|
||||
extern void __pinMode(uint8_t pin, uint8_t mode) {
|
||||
@ -232,3 +235,4 @@ extern int digitalRead(uint8_t pin) __attribute__ ((weak, alias("__digitalRead")
|
||||
extern void attachInterrupt(uint8_t pin, voidFuncPtr handler, int mode) __attribute__ ((weak, alias("__attachInterrupt")));
|
||||
extern void detachInterrupt(uint8_t pin) __attribute__ ((weak, alias("__detachInterrupt")));
|
||||
|
||||
};
|
@ -22,6 +22,7 @@
|
||||
#include "wiring_private.h"
|
||||
#include "pins_arduino.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
extern uint32_t xthal_get_ccount();
|
||||
|
||||
@ -53,3 +54,5 @@ unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout)
|
||||
{
|
||||
return pulseIn(pin, state, timeout);
|
||||
}
|
||||
|
||||
};
|
@ -24,6 +24,7 @@
|
||||
#include <Arduino.h>
|
||||
#include "core_esp8266_waveform.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
static uint32_t analogMap = 0;
|
||||
static int32_t analogScale = PWMRANGE;
|
||||
@ -76,3 +77,5 @@ extern void __analogWrite(uint8_t pin, int val) {
|
||||
extern void analogWrite(uint8_t pin, int val) __attribute__((weak, alias("__analogWrite")));
|
||||
extern void analogWriteFreq(uint32_t freq) __attribute__((weak, alias("__analogWriteFreq")));
|
||||
extern void analogWriteRange(uint32_t range) __attribute__((weak, alias("__analogWriteRange")));
|
||||
|
||||
};
|
@ -26,6 +26,7 @@
|
||||
*/
|
||||
|
||||
#include "wiring_private.h"
|
||||
extern "C" {
|
||||
|
||||
uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder) {
|
||||
uint8_t value = 0;
|
||||
@ -55,3 +56,5 @@ void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val)
|
||||
digitalWrite(clockPin, LOW);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
@ -22,6 +22,7 @@
|
||||
#define ESP8266_PERI_H_INCLUDED
|
||||
|
||||
#include "c_types.h"
|
||||
#include "esp8266_undocumented.h"
|
||||
|
||||
#define ESP8266_REG(addr) *((volatile uint32_t *)(0x60000000+(addr)))
|
||||
#define ESP8266_DREG(addr) *((volatile uint32_t *)(0x3FF00000+(addr)))
|
||||
|
18
cores/esp8266/esp8266_undocumented.h
Normal file
18
cores/esp8266/esp8266_undocumented.h
Normal file
@ -0,0 +1,18 @@
|
||||
// ROM and blob calls without official headers available
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// ROM
|
||||
|
||||
extern void rom_i2c_writeReg_Mask(int, int, int, int, int, int);
|
||||
extern int rom_i2c_readReg_Mask(int, int, int, int, int);
|
||||
|
||||
extern int uart_baudrate_detect(int, int);
|
||||
|
||||
extern void ets_delay_us(uint32_t us);
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
@ -24,6 +24,7 @@
|
||||
/* gdb_init and gdb_do_break do not return anything, but since the return
|
||||
value is in register, it doesn't hurt to return a bool, so that the
|
||||
same stub can be used for gdb_present. */
|
||||
extern "C" {
|
||||
|
||||
static bool ICACHE_RAM_ATTR __gdb_no_op()
|
||||
{
|
||||
@ -40,3 +41,4 @@ void gdbstub_set_uart_isr_callback(void (*func)(void*, uint8_t), void* arg) __at
|
||||
void gdbstub_write_char(char c) __attribute__ ((weak, alias("__gdb_no_op")));
|
||||
void gdbstub_write(const char* buf, size_t size) __attribute__ ((weak, alias("__gdb_no_op")));
|
||||
|
||||
};
|
@ -8,6 +8,8 @@
|
||||
#include <c_types.h>
|
||||
#include <sys/reent.h>
|
||||
|
||||
extern "C" {
|
||||
|
||||
// Debugging helper, last allocation which returned NULL
|
||||
void *umm_last_fail_alloc_addr = NULL;
|
||||
int umm_last_fail_alloc_size = 0;
|
||||
@ -189,3 +191,5 @@ void system_show_malloc(void)
|
||||
{
|
||||
umm_info(NULL, 1);
|
||||
}
|
||||
|
||||
};
|
@ -5,15 +5,18 @@ This is part of the libb64 project, and has been placed in the public domain.
|
||||
For details, see http://sourceforge.net/projects/libb64
|
||||
*/
|
||||
|
||||
#include "cdecode.h"
|
||||
#include <pgmspace.h>
|
||||
#include <stdint.h>
|
||||
#include "cdecode.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
static int base64_decode_value_signed(int8_t value_in){
|
||||
static const int8_t decoding[] = {62,-1,-1,-1,63,52,53,54,55,56,57,58,59,60,61,-1,-1,-1,-2,-1,-1,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,-1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51};
|
||||
static const int8_t decoding[] PROGMEM = {62,-1,-1,-1,63,52,53,54,55,56,57,58,59,60,61,-1,-1,-1,-2,-1,-1,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,-1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51};
|
||||
static const int8_t decoding_size = sizeof(decoding);
|
||||
value_in -= 43;
|
||||
if (value_in < 0 || value_in > decoding_size) return -1;
|
||||
return decoding[(int)value_in];
|
||||
return pgm_read_byte( &decoding[(int)value_in] );
|
||||
}
|
||||
|
||||
void base64_init_decodestate(base64_decodestate* state_in){
|
||||
@ -97,3 +100,5 @@ int base64_decode_block(const char* code_in, const int length_in, char* plaintex
|
||||
int base64_decode_chars(const char* code_in, const int length_in, char* plaintext_out){
|
||||
return base64_decode_chars_signed((int8_t *) code_in, length_in, (int8_t *) plaintext_out);
|
||||
}
|
||||
|
||||
};
|
@ -5,8 +5,11 @@ This is part of the libb64 project, and has been placed in the public domain.
|
||||
For details, see http://sourceforge.net/projects/libb64
|
||||
*/
|
||||
|
||||
#include <pgmspace.h>
|
||||
#include "cencode.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
void base64_init_encodestate(base64_encodestate* state_in){
|
||||
state_in->step = step_A;
|
||||
state_in->result = 0;
|
||||
@ -21,9 +24,9 @@ void base64_init_encodestate_nonewlines(base64_encodestate* state_in){
|
||||
}
|
||||
|
||||
char base64_encode_value(char value_in){
|
||||
static const char* encoding = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
static const char encoding[] PROGMEM = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
if (value_in > 63) return '=';
|
||||
return encoding[(int)value_in];
|
||||
return pgm_read_byte( &encoding[(int)value_in] );
|
||||
}
|
||||
|
||||
int base64_encode_block(const char* plaintext_in, int length_in, char* code_out, base64_encodestate* state_in){
|
||||
@ -107,3 +110,5 @@ int base64_encode_chars(const char* plaintext_in, int length_in, char* code_out)
|
||||
int len = base64_encode_block(plaintext_in, length_in, code_out, &_state);
|
||||
return len + base64_encode_blockend((code_out + len), &_state);
|
||||
}
|
||||
|
||||
};
|
@ -45,6 +45,7 @@
|
||||
#include "user_interface.h"
|
||||
#include "debug.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
int ICACHE_RAM_ATTR _open_r (struct _reent* unused, const char *ptr, int mode) {
|
||||
(void)unused;
|
||||
@ -128,4 +129,6 @@ void _exit(int status) {
|
||||
int atexit(void (*func)()) {
|
||||
(void) func;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
@ -43,6 +43,8 @@
|
||||
#include <os_type.h>
|
||||
#include "coredecls.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
static void (*_settimeofday_cb)(void) = NULL;
|
||||
|
||||
void settimeofday_cb (void (*cb)(void))
|
||||
@ -55,6 +57,8 @@ void settimeofday_cb (void (*cb)(void))
|
||||
#include <pgmspace.h>
|
||||
|
||||
static const char stod14[] PROGMEM = "settimeofday() can't set time!\n";
|
||||
bool sntp_set_timezone(sint8 timezone);
|
||||
void sntp_set_daylight(int daylight);
|
||||
|
||||
int settimeofday(const struct timeval* tv, const struct timezone* tz)
|
||||
{
|
||||
@ -461,3 +465,5 @@ int settimeofday(const struct timeval* tv, const struct timezone* tz)
|
||||
}
|
||||
|
||||
#endif // lwip2 only
|
||||
|
||||
};
|
@ -10,6 +10,8 @@
|
||||
|
||||
#if SPIFFS_CACHE
|
||||
|
||||
extern "C" {
|
||||
|
||||
// returns cached page for give page index, or null if no such cached page
|
||||
static spiffs_cache_page *spiffs_cache_page_get(spiffs *fs, spiffs_page_ix pix) {
|
||||
spiffs_cache *cache = spiffs_get_cache(fs);
|
||||
@ -316,4 +318,5 @@ void spiffs_cache_init(spiffs *fs) {
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
#endif // SPIFFS_CACHE
|
@ -37,6 +37,8 @@
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
extern "C" {
|
||||
|
||||
//---------------------------------------
|
||||
// Look up consistency
|
||||
|
||||
@ -925,7 +927,7 @@ static s32_t spiffs_object_index_consistency_check_v(spiffs *fs, spiffs_obj_id o
|
||||
} else { // span index
|
||||
// objix page, see if header can be found
|
||||
int r = spiffs_object_index_search(fs, obj_id);
|
||||
u8_t delete = 0;
|
||||
u8_t _delete = 0;
|
||||
if (r == -1) {
|
||||
// not in temporary index, try finding it
|
||||
spiffs_page_ix objix_hdr_pix;
|
||||
@ -936,7 +938,7 @@ static s32_t spiffs_object_index_consistency_check_v(spiffs *fs, spiffs_obj_id o
|
||||
obj_table[*log_ix] = obj_id & ~SPIFFS_OBJ_ID_IX_FLAG;
|
||||
} else if (res == SPIFFS_ERR_NOT_FOUND) {
|
||||
// not found, register as unreachable
|
||||
delete = 1;
|
||||
_delete = 1;
|
||||
obj_table[*log_ix] = obj_id | SPIFFS_OBJ_ID_IX_FLAG;
|
||||
} else {
|
||||
SPIFFS_CHECK_RES(res);
|
||||
@ -949,11 +951,11 @@ static s32_t spiffs_object_index_consistency_check_v(spiffs *fs, spiffs_obj_id o
|
||||
// in temporary index, check reachable flag
|
||||
if ((obj_table[r] & SPIFFS_OBJ_ID_IX_FLAG)) {
|
||||
// registered as unreachable
|
||||
delete = 1;
|
||||
_delete = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (delete) {
|
||||
if (_delete) {
|
||||
SPIFFS_CHECK_DBG("IX: FIXUP: pix "_SPIPRIpg", obj id:"_SPIPRIid" spix:"_SPIPRIsp" is orphan index - deleting\n",
|
||||
cur_pix, obj_id, p_hdr.span_ix);
|
||||
CHECK_CB(fs, SPIFFS_CHECK_INDEX, SPIFFS_CHECK_DELETE_ORPHANED_INDEX, cur_pix, obj_id);
|
||||
@ -992,4 +994,6 @@ s32_t spiffs_object_index_consistency_check(spiffs *fs) {
|
||||
return res;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif // !SPIFFS_READ_ONLY
|
@ -3,6 +3,8 @@
|
||||
|
||||
#if !SPIFFS_READ_ONLY
|
||||
|
||||
extern "C" {
|
||||
|
||||
// Erases a logical block and updates the erase counter.
|
||||
// If cache is enabled, all pages that might be cached in this block
|
||||
// is dropped.
|
||||
@ -603,4 +605,6 @@ s32_t spiffs_gc_clean(spiffs *fs, spiffs_block_ix bix) {
|
||||
return res;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif // !SPIFFS_READ_ONLY
|
@ -8,6 +8,8 @@
|
||||
#include "spiffs.h"
|
||||
#include "spiffs_nucleus.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
#if SPIFFS_CACHE == 1
|
||||
static s32_t spiffs_fflush_cache(spiffs *fs, spiffs_file fh);
|
||||
#endif
|
||||
@ -1429,7 +1431,7 @@ s32_t SPIFFS_vis(spiffs *fs) {
|
||||
SPIFFS_CHECK_RES(res);
|
||||
|
||||
if (erase_count != (spiffs_obj_id)-1) {
|
||||
spiffs_printf("\tera_cnt: "_SPIPRIi"\n", erase_count);
|
||||
spiffs_printf("\tera_cnt: " _SPIPRIi "\n", erase_count);
|
||||
} else {
|
||||
spiffs_printf("\tera_cnt: N/A\n");
|
||||
}
|
||||
@ -1437,16 +1439,18 @@ s32_t SPIFFS_vis(spiffs *fs) {
|
||||
bix++;
|
||||
} // per block
|
||||
|
||||
spiffs_printf("era_cnt_max: "_SPIPRIi"\n", fs->max_erase_count);
|
||||
spiffs_printf("last_errno: "_SPIPRIi"\n", fs->err_code);
|
||||
spiffs_printf("blocks: "_SPIPRIi"\n", fs->block_count);
|
||||
spiffs_printf("free_blocks: "_SPIPRIi"\n", fs->free_blocks);
|
||||
spiffs_printf("page_alloc: "_SPIPRIi"\n", fs->stats_p_allocated);
|
||||
spiffs_printf("page_delet: "_SPIPRIi"\n", fs->stats_p_deleted);
|
||||
spiffs_printf("era_cnt_max: " _SPIPRIi "\n", fs->max_erase_count);
|
||||
spiffs_printf("last_errno: " _SPIPRIi "\n", fs->err_code);
|
||||
spiffs_printf("blocks: " _SPIPRIi "\n", fs->block_count);
|
||||
spiffs_printf("free_blocks: " _SPIPRIi "\n", fs->free_blocks);
|
||||
spiffs_printf("page_alloc: " _SPIPRIi "\n", fs->stats_p_allocated);
|
||||
spiffs_printf("page_delet: " _SPIPRIi "\n", fs->stats_p_deleted);
|
||||
SPIFFS_UNLOCK(fs);
|
||||
u32_t total, used;
|
||||
SPIFFS_info(fs, &total, &used);
|
||||
spiffs_printf("used: "_SPIPRIi" of "_SPIPRIi"\n", used, total);
|
||||
spiffs_printf("used: " _SPIPRIi " of " _SPIPRIi "\n", used, total);
|
||||
return res;
|
||||
}
|
||||
#endif
|
||||
|
||||
};
|
@ -1,6 +1,8 @@
|
||||
#include "spiffs.h"
|
||||
#include "spiffs_nucleus.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
static s32_t spiffs_page_data_check(spiffs *fs, spiffs_fd *fd, spiffs_page_ix pix, spiffs_span_ix spix) {
|
||||
s32_t res = SPIFFS_OK;
|
||||
if (pix == (spiffs_page_ix)-1) {
|
||||
@ -232,7 +234,7 @@ s32_t spiffs_erase_block(
|
||||
|
||||
// here we ignore res, just try erasing the block
|
||||
while (size > 0) {
|
||||
SPIFFS_DBG("erase "_SPIPRIad":"_SPIPRIi"\n", addr, SPIFFS_CFG_PHYS_ERASE_SZ(fs));
|
||||
SPIFFS_DBG("erase " _SPIPRIad ":" _SPIPRIi "\n", addr, SPIFFS_CFG_PHYS_ERASE_SZ(fs));
|
||||
SPIFFS_HAL_ERASE(fs, addr, SPIFFS_CFG_PHYS_ERASE_SZ(fs));
|
||||
|
||||
addr += SPIFFS_CFG_PHYS_ERASE_SZ(fs);
|
||||
@ -407,7 +409,7 @@ s32_t spiffs_obj_lu_scan(
|
||||
#if SPIFFS_USE_MAGIC
|
||||
if (unerased_bix != (spiffs_block_ix)-1) {
|
||||
// found one unerased block, remedy
|
||||
SPIFFS_DBG("mount: erase block "_SPIPRIbl"\n", bix);
|
||||
SPIFFS_DBG("mount: erase block " _SPIPRIbl "\n", bix);
|
||||
#if SPIFFS_READ_ONLY
|
||||
res = SPIFFS_ERR_RO_ABORTED_OPERATION;
|
||||
#else
|
||||
@ -645,7 +647,7 @@ static void spiffs_update_ix_map(spiffs *fs,
|
||||
}
|
||||
|
||||
map->map_buf[map_spix - map->start_spix] = objix_data_pix;
|
||||
SPIFFS_DBG("map "_SPIPRIid":"_SPIPRIsp" ("_SPIPRIsp"--"_SPIPRIsp") objix.spix:"_SPIPRIsp" to pix "_SPIPRIpg"\n",
|
||||
SPIFFS_DBG("map " _SPIPRIid ":" _SPIPRIsp " (" _SPIPRIsp "--" _SPIPRIsp ") objix.spix:" _SPIPRIsp " to pix " _SPIPRIpg "\n",
|
||||
fd->obj_id, map_spix - map->start_spix,
|
||||
map->start_spix, map->end_spix,
|
||||
objix->p_hdr.span_ix,
|
||||
@ -696,7 +698,7 @@ static s32_t spiffs_populate_ix_map_v(
|
||||
spiffs_update_ix_map(fs, state->fd, objix->p_hdr.span_ix, objix);
|
||||
|
||||
state->remaining_objix_pages_to_visit--;
|
||||
SPIFFS_DBG("map "_SPIPRIid" ("_SPIPRIsp"--"_SPIPRIsp") remaining objix pages "_SPIPRIi"\n",
|
||||
SPIFFS_DBG("map " _SPIPRIid " (" _SPIPRIsp "--" _SPIPRIsp ") remaining objix pages " _SPIPRIi "\n",
|
||||
state->fd->obj_id,
|
||||
state->fd->ix_map->start_spix, state->fd->ix_map->end_spix,
|
||||
state->remaining_objix_pages_to_visit);
|
||||
@ -924,7 +926,7 @@ s32_t spiffs_object_create(
|
||||
// find free entry
|
||||
res = spiffs_obj_lu_find_free(fs, fs->free_cursor_block_ix, fs->free_cursor_obj_lu_entry, &bix, &entry);
|
||||
SPIFFS_CHECK_RES(res);
|
||||
SPIFFS_DBG("create: found free page @ "_SPIPRIpg" bix:"_SPIPRIbl" entry:"_SPIPRIsp"\n", (spiffs_page_ix)SPIFFS_OBJ_LOOKUP_ENTRY_TO_PIX(fs, bix, entry), bix, entry);
|
||||
SPIFFS_DBG("create: found free page @ " _SPIPRIpg " bix:" _SPIPRIbl " entry:" _SPIPRIsp "\n", (spiffs_page_ix)SPIFFS_OBJ_LOOKUP_ENTRY_TO_PIX(fs, bix, entry), bix, entry);
|
||||
|
||||
// occupy page in object lookup
|
||||
res = _spiffs_wr(fs, SPIFFS_OP_T_OBJ_LU | SPIFFS_OP_C_UPDT,
|
||||
@ -1048,7 +1050,7 @@ void spiffs_cb_object_event(
|
||||
spiffs_obj_id obj_id = obj_id_raw & ~SPIFFS_OBJ_ID_IX_FLAG;
|
||||
u32_t i;
|
||||
spiffs_fd *fds = (spiffs_fd *)fs->fd_space;
|
||||
SPIFFS_DBG(" CALLBACK %s obj_id:"_SPIPRIid" spix:"_SPIPRIsp" npix:"_SPIPRIpg" nsz:"_SPIPRIi"\n", (const char *[]){"UPD", "NEW", "DEL", "MOV", "HUP","???"}[MIN(ev,5)],
|
||||
SPIFFS_DBG(" CALLBACK %s obj_id:" _SPIPRIid " spix:" _SPIPRIsp " npix:" _SPIPRIpg " nsz:" _SPIPRIi "\n", (const char *[]){"UPD", "NEW", "DEL", "MOV", "HUP","???"}[MIN(ev,5)],
|
||||
obj_id_raw, spix, new_pix, new_size);
|
||||
for (i = 0; i < fs->fd_count; i++) {
|
||||
spiffs_fd *cur_fd = &fds[i];
|
||||
@ -1061,7 +1063,7 @@ void spiffs_cb_object_event(
|
||||
#if SPIFFS_TEMPORAL_FD_CACHE
|
||||
if (cur_fd->score == 0) continue; // never used fd
|
||||
#endif
|
||||
SPIFFS_DBG(" callback: setting fd "_SPIPRIfd":"_SPIPRIid"(fdoffs:"_SPIPRIi" offs:"_SPIPRIi") objix_hdr_pix to "_SPIPRIpg", size:"_SPIPRIi"\n",
|
||||
SPIFFS_DBG(" callback: setting fd " _SPIPRIfd ":" _SPIPRIid "(fdoffs:" _SPIPRIi " offs:" _SPIPRIi ") objix_hdr_pix to " _SPIPRIpg ", size:" _SPIPRIi "\n",
|
||||
SPIFFS_FH_OFFS(fs, cur_fd->file_nbr), cur_fd->obj_id, cur_fd->fdoffset, cur_fd->offset, new_pix, new_size);
|
||||
cur_fd->objix_hdr_pix = new_pix;
|
||||
if (new_size != 0) {
|
||||
@ -1081,7 +1083,7 @@ void spiffs_cb_object_event(
|
||||
}
|
||||
#if SPIFFS_CACHE_WR
|
||||
if (cur_fd->cache_page && cur_fd->cache_page->offset > act_new_size+1) {
|
||||
SPIFFS_CACHE_DBG("CACHE_DROP: file trunced, dropping cache page "_SPIPRIi", no writeback\n", cur_fd->cache_page->ix);
|
||||
SPIFFS_CACHE_DBG("CACHE_DROP: file trunced, dropping cache page " _SPIPRIi ", no writeback\n", cur_fd->cache_page->ix);
|
||||
spiffs_cache_fd_release(fs, cur_fd->cache_page);
|
||||
}
|
||||
#endif
|
||||
@ -1090,18 +1092,18 @@ void spiffs_cb_object_event(
|
||||
// removing file
|
||||
#if SPIFFS_CACHE_WR
|
||||
if (cur_fd->file_nbr && cur_fd->cache_page) {
|
||||
SPIFFS_CACHE_DBG("CACHE_DROP: file deleted, dropping cache page "_SPIPRIi", no writeback\n", cur_fd->cache_page->ix);
|
||||
SPIFFS_CACHE_DBG("CACHE_DROP: file deleted, dropping cache page " _SPIPRIi ", no writeback\n", cur_fd->cache_page->ix);
|
||||
spiffs_cache_fd_release(fs, cur_fd->cache_page);
|
||||
}
|
||||
#endif
|
||||
SPIFFS_DBG(" callback: release fd "_SPIPRIfd":"_SPIPRIid" span:"_SPIPRIsp" objix_pix to "_SPIPRIpg"\n", SPIFFS_FH_OFFS(fs, cur_fd->file_nbr), cur_fd->obj_id, spix, new_pix);
|
||||
SPIFFS_DBG(" callback: release fd " _SPIPRIfd ":" _SPIPRIid " span:" _SPIPRIsp " objix_pix to " _SPIPRIpg "\n", SPIFFS_FH_OFFS(fs, cur_fd->file_nbr), cur_fd->obj_id, spix, new_pix);
|
||||
cur_fd->file_nbr = 0;
|
||||
cur_fd->obj_id = SPIFFS_OBJ_ID_DELETED;
|
||||
}
|
||||
} // object index header update
|
||||
if (cur_fd->cursor_objix_spix == spix) {
|
||||
if (ev != SPIFFS_EV_IX_DEL) {
|
||||
SPIFFS_DBG(" callback: setting fd "_SPIPRIfd":"_SPIPRIid" span:"_SPIPRIsp" objix_pix to "_SPIPRIpg"\n", SPIFFS_FH_OFFS(fs, cur_fd->file_nbr), cur_fd->obj_id, spix, new_pix);
|
||||
SPIFFS_DBG(" callback: setting fd " _SPIPRIfd ":" _SPIPRIid " span:" _SPIPRIsp " objix_pix to " _SPIPRIpg "\n", SPIFFS_FH_OFFS(fs, cur_fd->file_nbr), cur_fd->obj_id, spix, new_pix);
|
||||
cur_fd->cursor_objix_pix = new_pix;
|
||||
} else {
|
||||
cur_fd->cursor_objix_pix = 0;
|
||||
@ -1119,7 +1121,7 @@ void spiffs_cb_object_event(
|
||||
if (cur_fd->file_nbr == 0 ||
|
||||
cur_fd->ix_map == 0 ||
|
||||
(cur_fd->obj_id & ~SPIFFS_OBJ_ID_IX_FLAG) != obj_id) continue;
|
||||
SPIFFS_DBG(" callback: map ix update fd "_SPIPRIfd":"_SPIPRIid" span:"_SPIPRIsp"\n", SPIFFS_FH_OFFS(fs, cur_fd->file_nbr), cur_fd->obj_id, spix);
|
||||
SPIFFS_DBG(" callback: map ix update fd " _SPIPRIfd ":" _SPIPRIid " span:" _SPIPRIsp "\n", SPIFFS_FH_OFFS(fs, cur_fd->file_nbr), cur_fd->obj_id, spix);
|
||||
spiffs_update_ix_map(fs, cur_fd, spix, objix);
|
||||
}
|
||||
}
|
||||
@ -1138,7 +1140,7 @@ void spiffs_cb_object_event(
|
||||
} else if (ev == SPIFFS_EV_IX_DEL) {
|
||||
op = SPIFFS_CB_DELETED;
|
||||
} else {
|
||||
SPIFFS_DBG(" callback: WARNING unknown callback event "_SPIPRIi"\n", ev);
|
||||
SPIFFS_DBG(" callback: WARNING unknown callback event " _SPIPRIi "\n", ev);
|
||||
return; // bail out
|
||||
}
|
||||
fs->file_cb_f(fs, op, obj_id, new_pix);
|
||||
@ -1196,7 +1198,7 @@ s32_t spiffs_object_open_by_page(
|
||||
|
||||
SPIFFS_VALIDATE_OBJIX(oix_hdr.p_hdr, fd->obj_id, 0);
|
||||
|
||||
SPIFFS_DBG("open: fd "_SPIPRIfd" is obj id "_SPIPRIid"\n", SPIFFS_FH_OFFS(fs, fd->file_nbr), fd->obj_id);
|
||||
SPIFFS_DBG("open: fd " _SPIPRIfd " is obj id " _SPIPRIid "\n", SPIFFS_FH_OFFS(fs, fd->file_nbr), fd->obj_id);
|
||||
|
||||
return res;
|
||||
}
|
||||
@ -1209,7 +1211,7 @@ s32_t spiffs_object_append(spiffs_fd *fd, u32_t offset, u8_t *data, u32_t len) {
|
||||
s32_t res = SPIFFS_OK;
|
||||
u32_t written = 0;
|
||||
|
||||
SPIFFS_DBG("append: "_SPIPRIi" bytes @ offs "_SPIPRIi" of size "_SPIPRIi"\n", len, offset, fd->size);
|
||||
SPIFFS_DBG("append: " _SPIPRIi " bytes @ offs " _SPIPRIi " of size " _SPIPRIi "\n", len, offset, fd->size);
|
||||
|
||||
if (offset > fd->size) {
|
||||
SPIFFS_DBG("append: offset reversed to size\n");
|
||||
@ -1218,7 +1220,7 @@ s32_t spiffs_object_append(spiffs_fd *fd, u32_t offset, u8_t *data, u32_t len) {
|
||||
|
||||
res = spiffs_gc_check(fs, len + SPIFFS_DATA_PAGE_SIZE(fs)); // add an extra page of data worth for meta
|
||||
if (res != SPIFFS_OK) {
|
||||
SPIFFS_DBG("append: gc check fail "_SPIPRIi"\n", res);
|
||||
SPIFFS_DBG("append: gc check fail " _SPIPRIi "\n", res);
|
||||
}
|
||||
SPIFFS_CHECK_RES(res);
|
||||
|
||||
@ -1246,7 +1248,7 @@ s32_t spiffs_object_append(spiffs_fd *fd, u32_t offset, u8_t *data, u32_t len) {
|
||||
// within this clause we return directly if something fails, object index mess-up
|
||||
if (written > 0) {
|
||||
// store previous object index page, unless first pass
|
||||
SPIFFS_DBG("append: "_SPIPRIid" store objix "_SPIPRIpg":"_SPIPRIsp", written "_SPIPRIi"\n", fd->obj_id,
|
||||
SPIFFS_DBG("append: " _SPIPRIid " store objix " _SPIPRIpg ":" _SPIPRIsp ", written " _SPIPRIi "\n", fd->obj_id,
|
||||
cur_objix_pix, prev_objix_spix, written);
|
||||
if (prev_objix_spix == 0) {
|
||||
// this is an update to object index header page
|
||||
@ -1263,7 +1265,7 @@ s32_t spiffs_object_append(spiffs_fd *fd, u32_t offset, u8_t *data, u32_t len) {
|
||||
res = spiffs_object_update_index_hdr(fs, fd, fd->obj_id,
|
||||
fd->objix_hdr_pix, fs->work, 0, 0, offset+written, &new_objix_hdr_page);
|
||||
SPIFFS_CHECK_RES(res);
|
||||
SPIFFS_DBG("append: "_SPIPRIid" store new objix_hdr, "_SPIPRIpg":"_SPIPRIsp", written "_SPIPRIi"\n", fd->obj_id,
|
||||
SPIFFS_DBG("append: " _SPIPRIid " store new objix_hdr, " _SPIPRIpg ":" _SPIPRIsp ", written " _SPIPRIi "\n", fd->obj_id,
|
||||
new_objix_hdr_page, 0, written);
|
||||
}
|
||||
} else {
|
||||
@ -1280,7 +1282,7 @@ s32_t spiffs_object_append(spiffs_fd *fd, u32_t offset, u8_t *data, u32_t len) {
|
||||
res = spiffs_object_update_index_hdr(fs, fd, fd->obj_id,
|
||||
fd->objix_hdr_pix, 0, 0, 0, offset+written, &new_objix_hdr_page);
|
||||
SPIFFS_CHECK_RES(res);
|
||||
SPIFFS_DBG("append: "_SPIPRIid" store new size I "_SPIPRIi" in objix_hdr, "_SPIPRIpg":"_SPIPRIsp", written "_SPIPRIi"\n", fd->obj_id,
|
||||
SPIFFS_DBG("append: " _SPIPRIid " store new size I " _SPIPRIi " in objix_hdr, " _SPIPRIpg ":" _SPIPRIsp ", written " _SPIPRIi "\n", fd->obj_id,
|
||||
offset+written, new_objix_hdr_page, 0, written);
|
||||
}
|
||||
fd->size = offset+written;
|
||||
@ -1290,7 +1292,7 @@ s32_t spiffs_object_append(spiffs_fd *fd, u32_t offset, u8_t *data, u32_t len) {
|
||||
// create or load new object index page
|
||||
if (cur_objix_spix == 0) {
|
||||
// load object index header page, must always exist
|
||||
SPIFFS_DBG("append: "_SPIPRIid" load objixhdr page "_SPIPRIpg":"_SPIPRIsp"\n", fd->obj_id, cur_objix_pix, cur_objix_spix);
|
||||
SPIFFS_DBG("append: " _SPIPRIid " load objixhdr page " _SPIPRIpg ":" _SPIPRIsp "\n", fd->obj_id, cur_objix_pix, cur_objix_spix);
|
||||
res = _spiffs_rd(fs, SPIFFS_OP_T_OBJ_IX | SPIFFS_OP_C_READ,
|
||||
fd->file_nbr, SPIFFS_PAGE_TO_PADDR(fs, cur_objix_pix), SPIFFS_CFG_LOG_PAGE_SZ(fs), fs->work);
|
||||
SPIFFS_CHECK_RES(res);
|
||||
@ -1310,19 +1312,19 @@ s32_t spiffs_object_append(spiffs_fd *fd, u32_t offset, u8_t *data, u32_t len) {
|
||||
_SPIFFS_MEMCPY(fs->work, &p_hdr, sizeof(spiffs_page_header));
|
||||
spiffs_cb_object_event(fs, (spiffs_page_object_ix *)fs->work,
|
||||
SPIFFS_EV_IX_NEW, fd->obj_id, cur_objix_spix, cur_objix_pix, 0);
|
||||
SPIFFS_DBG("append: "_SPIPRIid" create objix page, "_SPIPRIpg":"_SPIPRIsp", written "_SPIPRIi"\n", fd->obj_id
|
||||
SPIFFS_DBG("append: " _SPIPRIid " create objix page, " _SPIPRIpg ":" _SPIPRIsp ", written " _SPIPRIi "\n", fd->obj_id
|
||||
, cur_objix_pix, cur_objix_spix, written);
|
||||
} else {
|
||||
// on first pass, we load existing object index page
|
||||
spiffs_page_ix pix;
|
||||
SPIFFS_DBG("append: "_SPIPRIid" find objix span_ix:"_SPIPRIsp"\n", fd->obj_id, cur_objix_spix);
|
||||
SPIFFS_DBG("append: " _SPIPRIid " find objix span_ix:" _SPIPRIsp "\n", fd->obj_id, cur_objix_spix);
|
||||
if (fd->cursor_objix_spix == cur_objix_spix) {
|
||||
pix = fd->cursor_objix_pix;
|
||||
} else {
|
||||
res = spiffs_obj_lu_find_id_and_span(fs, fd->obj_id | SPIFFS_OBJ_ID_IX_FLAG, cur_objix_spix, 0, &pix);
|
||||
SPIFFS_CHECK_RES(res);
|
||||
}
|
||||
SPIFFS_DBG("append: "_SPIPRIid" found object index at page "_SPIPRIpg" [fd size "_SPIPRIi"]\n", fd->obj_id, pix, fd->size);
|
||||
SPIFFS_DBG("append: " _SPIPRIid " found object index at page " _SPIPRIpg " [fd size " _SPIPRIi "]\n", fd->obj_id, pix, fd->size);
|
||||
res = _spiffs_rd(fs, SPIFFS_OP_T_OBJ_IX | SPIFFS_OP_C_READ,
|
||||
fd->file_nbr, SPIFFS_PAGE_TO_PADDR(fs, pix), SPIFFS_CFG_LOG_PAGE_SZ(fs), fs->work);
|
||||
SPIFFS_CHECK_RES(res);
|
||||
@ -1346,7 +1348,7 @@ s32_t spiffs_object_append(spiffs_fd *fd, u32_t offset, u8_t *data, u32_t len) {
|
||||
p_hdr.flags = 0xff & ~(SPIFFS_PH_FLAG_FINAL); // finalize immediately
|
||||
res = spiffs_page_allocate_data(fs, fd->obj_id & ~SPIFFS_OBJ_ID_IX_FLAG,
|
||||
&p_hdr, &data[written], to_write, page_offs, 1, &data_page);
|
||||
SPIFFS_DBG("append: "_SPIPRIid" store new data page, "_SPIPRIpg":"_SPIPRIsp" offset:"_SPIPRIi", len "_SPIPRIi", written "_SPIPRIi"\n", fd->obj_id,
|
||||
SPIFFS_DBG("append: " _SPIPRIid " store new data page, " _SPIPRIpg ":" _SPIPRIsp " offset:" _SPIPRIi ", len " _SPIPRIi ", written " _SPIPRIi "\n", fd->obj_id,
|
||||
data_page, data_spix, page_offs, to_write, written);
|
||||
} else {
|
||||
// append to existing page, fill out free data in existing page
|
||||
@ -1363,7 +1365,7 @@ s32_t spiffs_object_append(spiffs_fd *fd, u32_t offset, u8_t *data, u32_t len) {
|
||||
|
||||
res = _spiffs_wr(fs, SPIFFS_OP_T_OBJ_DA | SPIFFS_OP_C_UPDT,
|
||||
fd->file_nbr, SPIFFS_PAGE_TO_PADDR(fs, data_page) + sizeof(spiffs_page_header) + page_offs, to_write, &data[written]);
|
||||
SPIFFS_DBG("append: "_SPIPRIid" store to existing data page, "_SPIPRIpg":"_SPIPRIsp" offset:"_SPIPRIi", len "_SPIPRIi", written "_SPIPRIi"\n", fd->obj_id
|
||||
SPIFFS_DBG("append: " _SPIPRIid " store to existing data page, " _SPIPRIpg ":" _SPIPRIsp " offset:" _SPIPRIi ", len " _SPIPRIi ", written " _SPIPRIi "\n", fd->obj_id
|
||||
, data_page, data_spix, page_offs, to_write, written);
|
||||
}
|
||||
|
||||
@ -1373,13 +1375,13 @@ s32_t spiffs_object_append(spiffs_fd *fd, u32_t offset, u8_t *data, u32_t len) {
|
||||
if (cur_objix_spix == 0) {
|
||||
// update object index header page
|
||||
((spiffs_page_ix*)((u8_t *)objix_hdr + sizeof(spiffs_page_object_ix_header)))[data_spix] = data_page;
|
||||
SPIFFS_DBG("append: "_SPIPRIid" wrote page "_SPIPRIpg" to objix_hdr entry "_SPIPRIsp" in mem\n", fd->obj_id
|
||||
SPIFFS_DBG("append: " _SPIPRIid " wrote page " _SPIPRIpg " to objix_hdr entry " _SPIPRIsp " in mem\n", fd->obj_id
|
||||
, data_page, data_spix);
|
||||
objix_hdr->size = offset+written;
|
||||
} else {
|
||||
// update object index page
|
||||
((spiffs_page_ix*)((u8_t *)objix + sizeof(spiffs_page_object_ix)))[SPIFFS_OBJ_IX_ENTRY(fs, data_spix)] = data_page;
|
||||
SPIFFS_DBG("append: "_SPIPRIid" wrote page "_SPIPRIpg" to objix entry "_SPIPRIsp" in mem\n", fd->obj_id
|
||||
SPIFFS_DBG("append: " _SPIPRIid " wrote page " _SPIPRIpg " to objix entry " _SPIPRIsp " in mem\n", fd->obj_id
|
||||
, data_page, (spiffs_span_ix)SPIFFS_OBJ_IX_ENTRY(fs, data_spix));
|
||||
}
|
||||
|
||||
@ -1399,7 +1401,7 @@ s32_t spiffs_object_append(spiffs_fd *fd, u32_t offset, u8_t *data, u32_t len) {
|
||||
if (cur_objix_spix != 0) {
|
||||
// wrote beyond object index header page
|
||||
// write last modified object index page, unless object header index page
|
||||
SPIFFS_DBG("append: "_SPIPRIid" store objix page, "_SPIPRIpg":"_SPIPRIsp", written "_SPIPRIi"\n", fd->obj_id,
|
||||
SPIFFS_DBG("append: " _SPIPRIid " store objix page, " _SPIPRIpg ":" _SPIPRIsp ", written " _SPIPRIi"\n", fd->obj_id,
|
||||
cur_objix_pix, cur_objix_spix, written);
|
||||
|
||||
res2 = spiffs_page_index_check(fs, fd, cur_objix_pix, cur_objix_spix);
|
||||
@ -1414,7 +1416,7 @@ s32_t spiffs_object_append(spiffs_fd *fd, u32_t offset, u8_t *data, u32_t len) {
|
||||
// update size in object header index page
|
||||
res2 = spiffs_object_update_index_hdr(fs, fd, fd->obj_id,
|
||||
fd->objix_hdr_pix, 0, 0, 0, offset+written, &new_objix_hdr_page);
|
||||
SPIFFS_DBG("append: "_SPIPRIid" store new size II "_SPIPRIi" in objix_hdr, "_SPIPRIpg":"_SPIPRIsp", written "_SPIPRIi", res "_SPIPRIi"\n", fd->obj_id
|
||||
SPIFFS_DBG("append: " _SPIPRIid " store new size II " _SPIPRIi " in objix_hdr, " _SPIPRIpg ":" _SPIPRIsp ", written " _SPIPRIi ", res " _SPIPRIi "\n", fd->obj_id
|
||||
, offset+written, new_objix_hdr_page, 0, written, res2);
|
||||
SPIFFS_CHECK_RES(res2);
|
||||
} else {
|
||||
@ -1422,7 +1424,7 @@ s32_t spiffs_object_append(spiffs_fd *fd, u32_t offset, u8_t *data, u32_t len) {
|
||||
if (offset == 0) {
|
||||
// wrote to empty object - simply update size and write whole page
|
||||
objix_hdr->size = offset+written;
|
||||
SPIFFS_DBG("append: "_SPIPRIid" store fresh objix_hdr page, "_SPIPRIpg":"_SPIPRIsp", written "_SPIPRIi"\n", fd->obj_id
|
||||
SPIFFS_DBG("append: " _SPIPRIid " store fresh objix_hdr page, " _SPIPRIpg ":" _SPIPRIsp ", written " _SPIPRIi "\n", fd->obj_id
|
||||
, cur_objix_pix, cur_objix_spix, written);
|
||||
|
||||
res2 = spiffs_page_index_check(fs, fd, cur_objix_pix, cur_objix_spix);
|
||||
@ -1438,7 +1440,7 @@ s32_t spiffs_object_append(spiffs_fd *fd, u32_t offset, u8_t *data, u32_t len) {
|
||||
// modifying object index header page, update size and make new copy
|
||||
res2 = spiffs_object_update_index_hdr(fs, fd, fd->obj_id,
|
||||
fd->objix_hdr_pix, fs->work, 0, 0, offset+written, &new_objix_hdr_page);
|
||||
SPIFFS_DBG("append: "_SPIPRIid" store modified objix_hdr page, "_SPIPRIpg":"_SPIPRIsp", written "_SPIPRIi"\n", fd->obj_id
|
||||
SPIFFS_DBG("append: " _SPIPRIid " store modified objix_hdr page, " _SPIPRIpg ":" _SPIPRIsp ", written " _SPIPRIi "\n", fd->obj_id
|
||||
, new_objix_hdr_page, 0, written);
|
||||
SPIFFS_CHECK_RES(res2);
|
||||
}
|
||||
@ -1488,7 +1490,7 @@ s32_t spiffs_object_modify(spiffs_fd *fd, u32_t offset, u8_t *data, u32_t len) {
|
||||
// store previous object index header page
|
||||
res = spiffs_object_update_index_hdr(fs, fd, fd->obj_id,
|
||||
fd->objix_hdr_pix, fs->work, 0, 0, 0, &new_objix_hdr_pix);
|
||||
SPIFFS_DBG("modify: store modified objix_hdr page, "_SPIPRIpg":"_SPIPRIsp", written "_SPIPRIi"\n", new_objix_hdr_pix, 0, written);
|
||||
SPIFFS_DBG("modify: store modified objix_hdr page, " _SPIPRIpg ":" _SPIPRIsp ", written " _SPIPRIi "\n", new_objix_hdr_pix, 0, written);
|
||||
SPIFFS_CHECK_RES(res);
|
||||
} else {
|
||||
// store new version of previous object index page
|
||||
@ -1498,7 +1500,7 @@ s32_t spiffs_object_modify(spiffs_fd *fd, u32_t offset, u8_t *data, u32_t len) {
|
||||
SPIFFS_CHECK_RES(res);
|
||||
|
||||
res = spiffs_page_move(fs, fd->file_nbr, (u8_t*)objix, fd->obj_id, 0, cur_objix_pix, &new_objix_pix);
|
||||
SPIFFS_DBG("modify: store previous modified objix page, "_SPIPRIid":"_SPIPRIsp", written "_SPIPRIi"\n", new_objix_pix, objix->p_hdr.span_ix, written);
|
||||
SPIFFS_DBG("modify: store previous modified objix page, " _SPIPRIid ":" _SPIPRIsp ", written " _SPIPRIi "\n", new_objix_pix, objix->p_hdr.span_ix, written);
|
||||
SPIFFS_CHECK_RES(res);
|
||||
spiffs_cb_object_event(fs, (spiffs_page_object_ix *)objix,
|
||||
SPIFFS_EV_IX_UPD, fd->obj_id, objix->p_hdr.span_ix, new_objix_pix, 0);
|
||||
@ -1508,7 +1510,7 @@ s32_t spiffs_object_modify(spiffs_fd *fd, u32_t offset, u8_t *data, u32_t len) {
|
||||
// load next object index page
|
||||
if (cur_objix_spix == 0) {
|
||||
// load object index header page, must exist
|
||||
SPIFFS_DBG("modify: load objixhdr page "_SPIPRIpg":"_SPIPRIsp"\n", cur_objix_pix, cur_objix_spix);
|
||||
SPIFFS_DBG("modify: load objixhdr page " _SPIPRIpg ":" _SPIPRIsp "\n", cur_objix_pix, cur_objix_spix);
|
||||
res = _spiffs_rd(fs, SPIFFS_OP_T_OBJ_IX | SPIFFS_OP_C_READ,
|
||||
fd->file_nbr, SPIFFS_PAGE_TO_PADDR(fs, cur_objix_pix), SPIFFS_CFG_LOG_PAGE_SZ(fs), fs->work);
|
||||
SPIFFS_CHECK_RES(res);
|
||||
@ -1516,14 +1518,14 @@ s32_t spiffs_object_modify(spiffs_fd *fd, u32_t offset, u8_t *data, u32_t len) {
|
||||
} else {
|
||||
// load existing object index page on first pass
|
||||
spiffs_page_ix pix;
|
||||
SPIFFS_DBG("modify: find objix span_ix:"_SPIPRIsp"\n", cur_objix_spix);
|
||||
SPIFFS_DBG("modify: find objix span_ix:" _SPIPRIsp "\n", cur_objix_spix);
|
||||
if (fd->cursor_objix_spix == cur_objix_spix) {
|
||||
pix = fd->cursor_objix_pix;
|
||||
} else {
|
||||
res = spiffs_obj_lu_find_id_and_span(fs, fd->obj_id | SPIFFS_OBJ_ID_IX_FLAG, cur_objix_spix, 0, &pix);
|
||||
SPIFFS_CHECK_RES(res);
|
||||
}
|
||||
SPIFFS_DBG("modify: found object index at page "_SPIPRIpg"\n", pix);
|
||||
SPIFFS_DBG("modify: found object index at page " _SPIPRIpg "\n", pix);
|
||||
res = _spiffs_rd(fs, SPIFFS_OP_T_OBJ_IX | SPIFFS_OP_C_READ,
|
||||
fd->file_nbr, SPIFFS_PAGE_TO_PADDR(fs, pix), SPIFFS_CFG_LOG_PAGE_SZ(fs), fs->work);
|
||||
SPIFFS_CHECK_RES(res);
|
||||
@ -1554,7 +1556,7 @@ s32_t spiffs_object_modify(spiffs_fd *fd, u32_t offset, u8_t *data, u32_t len) {
|
||||
// a full page, allocate and write a new page of data
|
||||
res = spiffs_page_allocate_data(fs, fd->obj_id & ~SPIFFS_OBJ_ID_IX_FLAG,
|
||||
&p_hdr, &data[written], to_write, page_offs, 1, &data_pix);
|
||||
SPIFFS_DBG("modify: store new data page, "_SPIPRIpg":"_SPIPRIsp" offset:"_SPIPRIi", len "_SPIPRIi", written "_SPIPRIi"\n", data_pix, data_spix, page_offs, to_write, written);
|
||||
SPIFFS_DBG("modify: store new data page, " _SPIPRIpg ":" _SPIPRIsp " offset:" _SPIPRIi ", len " _SPIPRIi ", written " _SPIPRIi "\n", data_pix, data_spix, page_offs, to_write, written);
|
||||
} else {
|
||||
// write to existing page, allocate new and copy unmodified data
|
||||
|
||||
@ -1595,7 +1597,7 @@ s32_t spiffs_object_modify(spiffs_fd *fd, u32_t offset, u8_t *data, u32_t len) {
|
||||
(u8_t *)&p_hdr.flags);
|
||||
if (res != SPIFFS_OK) break;
|
||||
|
||||
SPIFFS_DBG("modify: store to existing data page, src:"_SPIPRIpg", dst:"_SPIPRIpg":"_SPIPRIsp" offset:"_SPIPRIi", len "_SPIPRIi", written "_SPIPRIi"\n", orig_data_pix, data_pix, data_spix, page_offs, to_write, written);
|
||||
SPIFFS_DBG("modify: store to existing data page, src:" _SPIPRIpg ", dst:" _SPIPRIpg ":" _SPIPRIsp " offset:" _SPIPRIi ", len " _SPIPRIi ", written " _SPIPRIi "\n", orig_data_pix, data_pix, data_spix, page_offs, to_write, written);
|
||||
}
|
||||
|
||||
// delete original data page
|
||||
@ -1605,11 +1607,11 @@ s32_t spiffs_object_modify(spiffs_fd *fd, u32_t offset, u8_t *data, u32_t len) {
|
||||
if (cur_objix_spix == 0) {
|
||||
// update object index header page
|
||||
((spiffs_page_ix*)((u8_t *)objix_hdr + sizeof(spiffs_page_object_ix_header)))[data_spix] = data_pix;
|
||||
SPIFFS_DBG("modify: wrote page "_SPIPRIpg" to objix_hdr entry "_SPIPRIsp" in mem\n", data_pix, data_spix);
|
||||
SPIFFS_DBG("modify: wrote page " _SPIPRIpg " to objix_hdr entry " _SPIPRIsp " in mem\n", data_pix, data_spix);
|
||||
} else {
|
||||
// update object index page
|
||||
((spiffs_page_ix*)((u8_t *)objix + sizeof(spiffs_page_object_ix)))[SPIFFS_OBJ_IX_ENTRY(fs, data_spix)] = data_pix;
|
||||
SPIFFS_DBG("modify: wrote page "_SPIPRIpg" to objix entry "_SPIPRIsp" in mem\n", data_pix, (spiffs_span_ix)SPIFFS_OBJ_IX_ENTRY(fs, data_spix));
|
||||
SPIFFS_DBG("modify: wrote page " _SPIPRIpg " to objix entry " _SPIPRIsp " in mem\n", data_pix, (spiffs_span_ix)SPIFFS_OBJ_IX_ENTRY(fs, data_spix));
|
||||
}
|
||||
|
||||
// update internals
|
||||
@ -1634,7 +1636,7 @@ s32_t spiffs_object_modify(spiffs_fd *fd, u32_t offset, u8_t *data, u32_t len) {
|
||||
SPIFFS_CHECK_RES(res2);
|
||||
|
||||
res2 = spiffs_page_move(fs, fd->file_nbr, (u8_t*)objix, fd->obj_id, 0, cur_objix_pix, &new_objix_pix);
|
||||
SPIFFS_DBG("modify: store modified objix page, "_SPIPRIpg":"_SPIPRIsp", written "_SPIPRIi"\n", new_objix_pix, cur_objix_spix, written);
|
||||
SPIFFS_DBG("modify: store modified objix page, " _SPIPRIpg ":" _SPIPRIsp ", written " _SPIPRIi "\n", new_objix_pix, cur_objix_spix, written);
|
||||
fd->cursor_objix_pix = new_objix_pix;
|
||||
fd->cursor_objix_spix = cur_objix_spix;
|
||||
SPIFFS_CHECK_RES(res2);
|
||||
@ -1645,7 +1647,7 @@ s32_t spiffs_object_modify(spiffs_fd *fd, u32_t offset, u8_t *data, u32_t len) {
|
||||
// wrote within object index header page
|
||||
res2 = spiffs_object_update_index_hdr(fs, fd, fd->obj_id,
|
||||
fd->objix_hdr_pix, fs->work, 0, 0, 0, &new_objix_hdr_pix);
|
||||
SPIFFS_DBG("modify: store modified objix_hdr page, "_SPIPRIpg":"_SPIPRIsp", written "_SPIPRIi"\n", new_objix_hdr_pix, 0, written);
|
||||
SPIFFS_DBG("modify: store modified objix_hdr page, " _SPIPRIpg ":" _SPIPRIsp ", written " _SPIPRIi "\n", new_objix_hdr_pix, 0, written);
|
||||
SPIFFS_CHECK_RES(res2);
|
||||
}
|
||||
|
||||
@ -1765,7 +1767,7 @@ s32_t spiffs_object_truncate(
|
||||
if (prev_objix_spix != cur_objix_spix) {
|
||||
if (prev_objix_spix != (spiffs_span_ix)-1) {
|
||||
// remove previous object index page
|
||||
SPIFFS_DBG("truncate: delete objix page "_SPIPRIpg":"_SPIPRIsp"\n", objix_pix, prev_objix_spix);
|
||||
SPIFFS_DBG("truncate: delete objix page " _SPIPRIpg ":" _SPIPRIsp "\n", objix_pix, prev_objix_spix);
|
||||
|
||||
res = spiffs_page_index_check(fs, fd, objix_pix, prev_objix_spix);
|
||||
SPIFFS_CHECK_RES(res);
|
||||
@ -1782,7 +1784,7 @@ s32_t spiffs_object_truncate(
|
||||
// Hence, take the risk - if aborted, a file check would free the lost pages and mend things
|
||||
// as the file is marked as fully deleted in the beginning.
|
||||
if (remove_full == 0) {
|
||||
SPIFFS_DBG("truncate: update objix hdr page "_SPIPRIpg":"_SPIPRIsp" to size "_SPIPRIi"\n", fd->objix_hdr_pix, prev_objix_spix, cur_size);
|
||||
SPIFFS_DBG("truncate: update objix hdr page " _SPIPRIpg ":" _SPIPRIsp " to size " _SPIPRIi "\n", fd->objix_hdr_pix, prev_objix_spix, cur_size);
|
||||
res = spiffs_object_update_index_hdr(fs, fd, fd->obj_id,
|
||||
fd->objix_hdr_pix, 0, 0, 0, cur_size, &new_objix_hdr_pix);
|
||||
SPIFFS_CHECK_RES(res);
|
||||
@ -1798,7 +1800,7 @@ s32_t spiffs_object_truncate(
|
||||
SPIFFS_CHECK_RES(res);
|
||||
}
|
||||
|
||||
SPIFFS_DBG("truncate: load objix page "_SPIPRIpg":"_SPIPRIsp" for data spix:"_SPIPRIsp"\n", objix_pix, cur_objix_spix, data_spix);
|
||||
SPIFFS_DBG("truncate: load objix page " _SPIPRIpg ":" _SPIPRIsp " for data spix:" _SPIPRIsp "\n", objix_pix, cur_objix_spix, data_spix);
|
||||
res = _spiffs_rd(fs, SPIFFS_OP_T_OBJ_IX | SPIFFS_OP_C_READ,
|
||||
fd->file_nbr, SPIFFS_PAGE_TO_PADDR(fs, objix_pix), SPIFFS_CFG_LOG_PAGE_SZ(fs), fs->work);
|
||||
SPIFFS_CHECK_RES(res);
|
||||
@ -1820,20 +1822,20 @@ s32_t spiffs_object_truncate(
|
||||
((spiffs_page_ix*)((u8_t *)objix + sizeof(spiffs_page_object_ix)))[SPIFFS_OBJ_IX_ENTRY(fs, data_spix)] = SPIFFS_OBJ_ID_FREE;
|
||||
}
|
||||
|
||||
SPIFFS_DBG("truncate: got data pix "_SPIPRIpg"\n", data_pix);
|
||||
SPIFFS_DBG("truncate: got data pix " _SPIPRIpg "\n", data_pix);
|
||||
|
||||
if (new_size == 0 || remove_full || cur_size - new_size >= SPIFFS_DATA_PAGE_SIZE(fs)) {
|
||||
// delete full data page
|
||||
res = spiffs_page_data_check(fs, fd, data_pix, data_spix);
|
||||
if (res != SPIFFS_ERR_DELETED && res != SPIFFS_OK && res != SPIFFS_ERR_INDEX_REF_FREE) {
|
||||
SPIFFS_DBG("truncate: err validating data pix "_SPIPRIi"\n", res);
|
||||
SPIFFS_DBG("truncate: err validating data pix " _SPIPRIi "\n", res);
|
||||
break;
|
||||
}
|
||||
|
||||
if (res == SPIFFS_OK) {
|
||||
res = spiffs_page_delete(fs, data_pix);
|
||||
if (res != SPIFFS_OK) {
|
||||
SPIFFS_DBG("truncate: err deleting data pix "_SPIPRIi"\n", res);
|
||||
SPIFFS_DBG("truncate: err deleting data pix " _SPIPRIi "\n", res);
|
||||
break;
|
||||
}
|
||||
} else if (res == SPIFFS_ERR_DELETED || res == SPIFFS_ERR_INDEX_REF_FREE) {
|
||||
@ -1848,13 +1850,13 @@ s32_t spiffs_object_truncate(
|
||||
}
|
||||
fd->size = cur_size;
|
||||
fd->offset = cur_size;
|
||||
SPIFFS_DBG("truncate: delete data page "_SPIPRIpg" for data spix:"_SPIPRIsp", cur_size:"_SPIPRIi"\n", data_pix, data_spix, cur_size);
|
||||
SPIFFS_DBG("truncate: delete data page " _SPIPRIpg " for data spix:" _SPIPRIsp ", cur_size:" _SPIPRIi "\n", data_pix, data_spix, cur_size);
|
||||
} else {
|
||||
// delete last page, partially
|
||||
spiffs_page_header p_hdr;
|
||||
spiffs_page_ix new_data_pix;
|
||||
u32_t bytes_to_remove = SPIFFS_DATA_PAGE_SIZE(fs) - (new_size % SPIFFS_DATA_PAGE_SIZE(fs));
|
||||
SPIFFS_DBG("truncate: delete "_SPIPRIi" bytes from data page "_SPIPRIpg" for data spix:"_SPIPRIsp", cur_size:"_SPIPRIi"\n", bytes_to_remove, data_pix, data_spix, cur_size);
|
||||
SPIFFS_DBG("truncate: delete " _SPIPRIi " bytes from data page " _SPIPRIpg " for data spix:" _SPIPRIsp ", cur_size:" _SPIPRIi "\n", bytes_to_remove, data_pix, data_spix, cur_size);
|
||||
|
||||
res = spiffs_page_data_check(fs, fd, data_pix, data_spix);
|
||||
if (res != SPIFFS_OK) break;
|
||||
@ -1886,11 +1888,11 @@ s32_t spiffs_object_truncate(
|
||||
if (cur_objix_spix == 0) {
|
||||
// update object index header page
|
||||
((spiffs_page_ix*)((u8_t *)objix_hdr + sizeof(spiffs_page_object_ix_header)))[data_spix] = new_data_pix;
|
||||
SPIFFS_DBG("truncate: wrote page "_SPIPRIpg" to objix_hdr entry "_SPIPRIsp" in mem\n", new_data_pix, (spiffs_span_ix)SPIFFS_OBJ_IX_ENTRY(fs, data_spix));
|
||||
SPIFFS_DBG("truncate: wrote page " _SPIPRIpg " to objix_hdr entry " _SPIPRIsp " in mem\n", new_data_pix, (spiffs_span_ix)SPIFFS_OBJ_IX_ENTRY(fs, data_spix));
|
||||
} else {
|
||||
// update object index page
|
||||
((spiffs_page_ix*)((u8_t *)objix + sizeof(spiffs_page_object_ix)))[SPIFFS_OBJ_IX_ENTRY(fs, data_spix)] = new_data_pix;
|
||||
SPIFFS_DBG("truncate: wrote page "_SPIPRIpg" to objix entry "_SPIPRIsp" in mem\n", new_data_pix, (spiffs_span_ix)SPIFFS_OBJ_IX_ENTRY(fs, data_spix));
|
||||
SPIFFS_DBG("truncate: wrote page " _SPIPRIpg " to objix entry " _SPIPRIsp " in mem\n", new_data_pix, (spiffs_span_ix)SPIFFS_OBJ_IX_ENTRY(fs, data_spix));
|
||||
}
|
||||
cur_size = new_size;
|
||||
fd->size = new_size;
|
||||
@ -1906,7 +1908,7 @@ s32_t spiffs_object_truncate(
|
||||
if (cur_size == 0) {
|
||||
if (remove_full) {
|
||||
// remove object altogether
|
||||
SPIFFS_DBG("truncate: remove object index header page "_SPIPRIpg"\n", objix_pix);
|
||||
SPIFFS_DBG("truncate: remove object index header page " _SPIPRIpg "\n", objix_pix);
|
||||
|
||||
res = spiffs_page_index_check(fs, fd, objix_pix, 0);
|
||||
SPIFFS_CHECK_RES(res);
|
||||
@ -1917,7 +1919,7 @@ s32_t spiffs_object_truncate(
|
||||
SPIFFS_EV_IX_DEL, fd->obj_id, 0, objix_pix, 0);
|
||||
} else {
|
||||
// make uninitialized object
|
||||
SPIFFS_DBG("truncate: reset objix_hdr page "_SPIPRIpg"\n", objix_pix);
|
||||
SPIFFS_DBG("truncate: reset objix_hdr page " _SPIPRIpg "\n", objix_pix);
|
||||
memset(fs->work + sizeof(spiffs_page_object_ix_header), 0xff,
|
||||
SPIFFS_CFG_LOG_PAGE_SZ(fs) - sizeof(spiffs_page_object_ix_header));
|
||||
res = spiffs_object_update_index_hdr(fs, fd, fd->obj_id,
|
||||
@ -1943,7 +1945,7 @@ s32_t spiffs_object_truncate(
|
||||
SPIFFS_CHECK_RES(res);
|
||||
spiffs_cb_object_event(fs, (spiffs_page_object_ix *)objix_hdr,
|
||||
SPIFFS_EV_IX_UPD, fd->obj_id, objix->p_hdr.span_ix, new_objix_pix, 0);
|
||||
SPIFFS_DBG("truncate: store modified objix page, "_SPIPRIpg":"_SPIPRIsp"\n", new_objix_pix, cur_objix_spix);
|
||||
SPIFFS_DBG("truncate: store modified objix page, " _SPIPRIpg ":" _SPIPRIsp "\n", new_objix_pix, cur_objix_spix);
|
||||
fd->cursor_objix_pix = new_objix_pix;
|
||||
fd->cursor_objix_spix = cur_objix_spix;
|
||||
fd->offset = cur_size;
|
||||
@ -1989,7 +1991,7 @@ s32_t spiffs_object_read(
|
||||
if (cur_objix_spix == 0) {
|
||||
objix_pix = fd->objix_hdr_pix;
|
||||
} else {
|
||||
SPIFFS_DBG("read: find objix "_SPIPRIid":"_SPIPRIsp"\n", fd->obj_id, cur_objix_spix);
|
||||
SPIFFS_DBG("read: find objix " _SPIPRIid ":" _SPIPRIsp "\n", fd->obj_id, cur_objix_spix);
|
||||
if (fd->cursor_objix_spix == cur_objix_spix) {
|
||||
objix_pix = fd->cursor_objix_pix;
|
||||
} else {
|
||||
@ -1997,7 +1999,7 @@ s32_t spiffs_object_read(
|
||||
SPIFFS_CHECK_RES(res);
|
||||
}
|
||||
}
|
||||
SPIFFS_DBG("read: load objix page "_SPIPRIpg":"_SPIPRIsp" for data spix:"_SPIPRIsp"\n", objix_pix, cur_objix_spix, data_spix);
|
||||
SPIFFS_DBG("read: load objix page " _SPIPRIpg ":" _SPIPRIsp " for data spix:" _SPIPRIsp "\n", objix_pix, cur_objix_spix, data_spix);
|
||||
res = _spiffs_rd(fs, SPIFFS_OP_T_OBJ_IX | SPIFFS_OP_C_READ,
|
||||
fd->file_nbr, SPIFFS_PAGE_TO_PADDR(fs, objix_pix), SPIFFS_CFG_LOG_PAGE_SZ(fs), fs->work);
|
||||
SPIFFS_CHECK_RES(res);
|
||||
@ -2026,7 +2028,7 @@ s32_t spiffs_object_read(
|
||||
len_to_read = MIN(len_to_read, SPIFFS_DATA_PAGE_SIZE(fs) - (cur_offset % SPIFFS_DATA_PAGE_SIZE(fs)));
|
||||
// remaining data in file
|
||||
len_to_read = MIN(len_to_read, fd->size);
|
||||
SPIFFS_DBG("read: offset:"_SPIPRIi" rd:"_SPIPRIi" data spix:"_SPIPRIsp" is data_pix:"_SPIPRIpg" addr:"_SPIPRIad"\n", cur_offset, len_to_read, data_spix, data_pix,
|
||||
SPIFFS_DBG("read: offset:" _SPIPRIi " rd:" _SPIPRIi " data spix:" _SPIPRIsp " is data_pix:" _SPIPRIpg " addr:" _SPIPRIad "\n", cur_offset, len_to_read, data_spix, data_pix,
|
||||
(u32_t)(SPIFFS_PAGE_TO_PADDR(fs, data_pix) + sizeof(spiffs_page_header) + (cur_offset % SPIFFS_DATA_PAGE_SIZE(fs))));
|
||||
if (len_to_read <= 0) {
|
||||
res = SPIFFS_ERR_END_OF_OBJECT;
|
||||
@ -2113,7 +2115,7 @@ static s32_t spiffs_obj_lu_find_free_obj_id_compact_v(spiffs *fs, spiffs_obj_id
|
||||
if (id >= state->min_obj_id && id <= state->max_obj_id) {
|
||||
u8_t *map = (u8_t *)fs->work;
|
||||
int ix = (id - state->min_obj_id) / state->compaction;
|
||||
//SPIFFS_DBG("free_obj_id: add ix "_SPIPRIi" for id "_SPIPRIid" min"_SPIPRIid" max"_SPIPRIid" comp:"_SPIPRIi"\n", ix, id, state->min_obj_id, state->max_obj_id, state->compaction);
|
||||
//SPIFFS_DBG("free_obj_id: add ix " _SPIPRIi " for id " _SPIPRIid " min" _SPIPRIid " max" _SPIPRIid " comp:" _SPIPRIi "\n", ix, id, state->min_obj_id, state->max_obj_id, state->compaction);
|
||||
map[ix]++;
|
||||
}
|
||||
}
|
||||
@ -2141,7 +2143,7 @@ s32_t spiffs_obj_lu_find_free_obj_id(spiffs *fs, spiffs_obj_id *obj_id, const u8
|
||||
if (state.max_obj_id - state.min_obj_id <= (spiffs_obj_id)SPIFFS_CFG_LOG_PAGE_SZ(fs)*8) {
|
||||
// possible to represent in bitmap
|
||||
u32_t i, j;
|
||||
SPIFFS_DBG("free_obj_id: BITM min:"_SPIPRIid" max:"_SPIPRIid"\n", state.min_obj_id, state.max_obj_id);
|
||||
SPIFFS_DBG("free_obj_id: BITM min:" _SPIPRIid " max:" _SPIPRIid "\n", state.min_obj_id, state.max_obj_id);
|
||||
|
||||
memset(fs->work, 0, SPIFFS_CFG_LOG_PAGE_SZ(fs));
|
||||
res = spiffs_obj_lu_find_entry_visitor(fs, 0, 0, 0, 0, spiffs_obj_lu_find_free_obj_id_bitmap_v,
|
||||
@ -2186,14 +2188,14 @@ s32_t spiffs_obj_lu_find_free_obj_id(spiffs *fs, spiffs_obj_id *obj_id, const u8
|
||||
return SPIFFS_ERR_FULL;
|
||||
}
|
||||
|
||||
SPIFFS_DBG("free_obj_id: COMP select index:"_SPIPRIi" min_count:"_SPIPRIi" min:"_SPIPRIid" max:"_SPIPRIid" compact:"_SPIPRIi"\n", min_i, min_count, state.min_obj_id, state.max_obj_id, state.compaction);
|
||||
SPIFFS_DBG("free_obj_id: COMP select index:" _SPIPRIi " min_count:" _SPIPRIi " min:" _SPIPRIid " max:" _SPIPRIid " compact:" _SPIPRIi "\n", min_i, min_count, state.min_obj_id, state.max_obj_id, state.compaction);
|
||||
|
||||
if (min_count == 0) {
|
||||
// no id in this range, skip compacting and use directly
|
||||
*obj_id = min_i * state.compaction + state.min_obj_id;
|
||||
return SPIFFS_OK;
|
||||
} else {
|
||||
SPIFFS_DBG("free_obj_id: COMP SEL chunk:"_SPIPRIi" min:"_SPIPRIid" -> "_SPIPRIid"\n", state.compaction, state.min_obj_id, state.min_obj_id + min_i * state.compaction);
|
||||
SPIFFS_DBG("free_obj_id: COMP SEL chunk:" _SPIPRIi " min:" _SPIPRIid " -> " _SPIPRIid "\n", state.compaction, state.min_obj_id, state.min_obj_id + min_i * state.compaction);
|
||||
state.min_obj_id += min_i * state.compaction;
|
||||
state.max_obj_id = state.min_obj_id + state.compaction;
|
||||
// decrease compaction
|
||||
@ -2206,7 +2208,7 @@ s32_t spiffs_obj_lu_find_free_obj_id(spiffs *fs, spiffs_obj_id *obj_id, const u8
|
||||
// in a work memory of log_page_size bytes, we may fit in log_page_size ids
|
||||
// todo what if compaction is > 255 - then we cannot fit it in a byte
|
||||
state.compaction = (state.max_obj_id-state.min_obj_id) / ((SPIFFS_CFG_LOG_PAGE_SZ(fs) / sizeof(u8_t)));
|
||||
SPIFFS_DBG("free_obj_id: COMP min:"_SPIPRIid" max:"_SPIPRIid" compact:"_SPIPRIi"\n", state.min_obj_id, state.max_obj_id, state.compaction);
|
||||
SPIFFS_DBG("free_obj_id: COMP min:" _SPIPRIid " max:" _SPIPRIid " compact:" _SPIPRIi "\n", state.min_obj_id, state.max_obj_id, state.compaction);
|
||||
|
||||
memset(fs->work, 0, SPIFFS_CFG_LOG_PAGE_SZ(fs));
|
||||
res = spiffs_obj_lu_find_entry_visitor(fs, 0, 0, 0, 0, spiffs_obj_lu_find_free_obj_id_compact_v, &state, 0, 0, 0);
|
||||
@ -2357,3 +2359,5 @@ void spiffs_fd_temporal_cache_rehash(
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
};
|
@ -110,6 +110,10 @@
|
||||
#ifndef SPIFFS_NUCLEUS_H_
|
||||
#define SPIFFS_NUCLEUS_H_
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define _SPIFFS_ERR_CHECK_FIRST (SPIFFS_ERR_INTERNAL - 1)
|
||||
#define SPIFFS_ERR_CHECK_OBJ_ID_MISM (SPIFFS_ERR_INTERNAL - 1)
|
||||
#define SPIFFS_ERR_CHECK_SPIX_MISM (SPIFFS_ERR_INTERNAL - 2)
|
||||
@ -839,4 +843,8 @@ s32_t spiffs_object_index_consistency_check(
|
||||
#endif
|
||||
#endif //_SPIFFS_TEST
|
||||
|
||||
#if defined(__cplusplus)
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif /* SPIFFS_NUCLEUS_H_ */
|
||||
|
@ -2,6 +2,8 @@
|
||||
#include <coredecls.h>
|
||||
#include <stdint.h>
|
||||
|
||||
extern "C" {
|
||||
|
||||
uint32_t sqrt32 (uint32_t n)
|
||||
{
|
||||
// http://www.codecodex.com/wiki/Calculate_an_integer_square_root#C
|
||||
@ -54,3 +56,5 @@ int main (void)
|
||||
|
||||
*
|
||||
*/
|
||||
|
||||
};
|
@ -22,6 +22,8 @@
|
||||
#include "sntp.h"
|
||||
#include "coredecls.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
#ifndef _TIMEVAL_DEFINED
|
||||
#define _TIMEVAL_DEFINED
|
||||
struct timeval {
|
||||
@ -33,6 +35,7 @@ struct timeval {
|
||||
extern char* sntp_asctime(const struct tm *t);
|
||||
extern struct tm* sntp_localtime(const time_t *clock);
|
||||
extern uint64_t micros64();
|
||||
extern void sntp_set_daylight(int daylight);
|
||||
|
||||
// time gap in seconds from 01.01.1900 (NTP time) to 01.01.1970 (UNIX time)
|
||||
#define DIFF1900TO1970 2208988800UL
|
||||
@ -101,3 +104,5 @@ int _gettimeofday_r(struct _reent* unused, struct timeval *tp, void *tzp)
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
};
|
@ -42,6 +42,7 @@
|
||||
*/
|
||||
#include "Arduino.h"
|
||||
#include <pgmspace.h>
|
||||
#include "../../libraries/GDBStub/src/GDBStub.h"
|
||||
#include "uart.h"
|
||||
#include "esp8266_peri.h"
|
||||
#include "user_interface.h"
|
||||
@ -70,8 +71,9 @@
|
||||
kept running to enable GDB to do commands.
|
||||
*/
|
||||
|
||||
static int s_uart_debug_nr = UART0;
|
||||
extern "C" {
|
||||
|
||||
static int s_uart_debug_nr = UART0;
|
||||
|
||||
struct uart_rx_buffer_
|
||||
{
|
||||
@ -974,3 +976,5 @@ uart_detect_baudrate(int uart_nr)
|
||||
|
||||
return default_rates[i];
|
||||
}
|
||||
|
||||
};
|
@ -499,6 +499,8 @@
|
||||
|
||||
#include "umm_malloc_cfg.h" /* user-dependent */
|
||||
|
||||
extern "C" {
|
||||
|
||||
// From UMM, the last caller of a malloc/realloc/calloc which failed:
|
||||
extern void *umm_last_fail_alloc_addr;
|
||||
extern int umm_last_fail_alloc_size;
|
||||
@ -905,7 +907,8 @@ static int check_poison_all_blocks(void) {
|
||||
*
|
||||
* `size_w_poison` is a size of the whole block, including a poison.
|
||||
*/
|
||||
static void *get_poisoned( unsigned char *ptr, size_t size_w_poison ) {
|
||||
static void *get_poisoned( void *vptr, size_t size_w_poison ) {
|
||||
unsigned char *ptr = (unsigned char *)vptr;
|
||||
if (size_w_poison != 0 && ptr != NULL) {
|
||||
|
||||
/* Put exact length of the user's chunk of memory */
|
||||
@ -930,7 +933,8 @@ static void *get_poisoned( unsigned char *ptr, size_t size_w_poison ) {
|
||||
*
|
||||
* Returns unpoisoned pointer, i.e. actual pointer to the allocated memory.
|
||||
*/
|
||||
static void *get_unpoisoned( unsigned char *ptr ) {
|
||||
static void *get_unpoisoned( void *vptr ) {
|
||||
unsigned char *ptr = (unsigned char *)vptr;
|
||||
if (ptr != NULL) {
|
||||
unsigned short int c;
|
||||
|
||||
@ -1775,4 +1779,6 @@ size_t ICACHE_FLASH_ATTR umm_block_size( void ) {
|
||||
return sizeof(umm_block);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
@ -56,17 +56,17 @@ CORE_CPP_FILES := $(addprefix $(CORE_PATH)/,\
|
||||
FS.cpp \
|
||||
spiffs_api.cpp \
|
||||
MD5Builder.cpp \
|
||||
core_esp8266_noniso.cpp \
|
||||
spiffs/spiffs_cache.cpp \
|
||||
spiffs/spiffs_check.cpp \
|
||||
spiffs/spiffs_gc.cpp \
|
||||
spiffs/spiffs_hydrogen.cpp \
|
||||
spiffs/spiffs_nucleus.cpp \
|
||||
libb64/cencode.cpp \
|
||||
Schedule.cpp \
|
||||
)
|
||||
|
||||
CORE_C_FILES := $(addprefix $(CORE_PATH)/,\
|
||||
core_esp8266_noniso.c \
|
||||
spiffs/spiffs_cache.c \
|
||||
spiffs/spiffs_check.c \
|
||||
spiffs/spiffs_gc.c \
|
||||
spiffs/spiffs_hydrogen.c \
|
||||
spiffs/spiffs_nucleus.c \
|
||||
libb64/cencode.c \
|
||||
)
|
||||
|
||||
MOCK_CPP_FILES_COMMON := $(addprefix common/,\
|
||||
|
Loading…
x
Reference in New Issue
Block a user