Unverified Commit 310faf7f authored by Terry Ellison's avatar Terry Ellison Committed by GitHub
Browse files

Merge pull request #2886 from nodemcu/dev

Next master drop
parents 68c425c0 a08e74d9
/* uri.c -- helper functions for URI treatment /* uri.c -- helper functions for URI treatment
*/ */
#include "c_stdio.h" #include <stdio.h>
#include "c_stdlib.h" #include <stdlib.h>
#include "c_string.h" #include <string.h>
#include "c_ctype.h" #include <ctype.h>
#include "coap.h" #include "coap.h"
#include "uri.h" #include "uri.h"
...@@ -43,7 +43,7 @@ int coap_split_uri(unsigned char *str_var, size_t len, coap_uri_t *uri) { ...@@ -43,7 +43,7 @@ int coap_split_uri(unsigned char *str_var, size_t len, coap_uri_t *uri) {
if (!str_var || !uri) if (!str_var || !uri)
return -1; return -1;
c_memset(uri, 0, sizeof(coap_uri_t)); memset(uri, 0, sizeof(coap_uri_t));
uri->port = COAP_DEFAULT_PORT; uri->port = COAP_DEFAULT_PORT;
/* search for scheme */ /* search for scheme */
...@@ -394,16 +394,16 @@ int coap_split_query(coap_rw_buffer_t *scratch, coap_packet_t *pkt, const unsign ...@@ -394,16 +394,16 @@ int coap_split_query(coap_rw_buffer_t *scratch, coap_packet_t *pkt, const unsign
coap_uri_t * coap_new_uri(const unsigned char *uri, unsigned int length) { coap_uri_t * coap_new_uri(const unsigned char *uri, unsigned int length) {
unsigned char *result; unsigned char *result;
result = (unsigned char *)c_malloc(length + 1 + sizeof(coap_uri_t)); result = (unsigned char *)malloc(length + 1 + sizeof(coap_uri_t));
if (!result) if (!result)
return NULL; return NULL;
c_memcpy(URI_DATA(result), uri, length); memcpy(URI_DATA(result), uri, length);
URI_DATA(result)[length] = '\0'; /* make it zero-terminated */ URI_DATA(result)[length] = '\0'; /* make it zero-terminated */
if (coap_split_uri(URI_DATA(result), length, (coap_uri_t *)result) < 0) { if (coap_split_uri(URI_DATA(result), length, (coap_uri_t *)result) < 0) {
c_free(result); free(result);
return NULL; return NULL;
} }
return (coap_uri_t *)result; return (coap_uri_t *)result;
......
...@@ -38,10 +38,6 @@ STD_CFLAGS=-std=gnu11 -Wimplicit ...@@ -38,10 +38,6 @@ STD_CFLAGS=-std=gnu11 -Wimplicit
# Required for each makefile to inherit from the parent # Required for each makefile to inherit from the parent
# #
INCLUDES := $(INCLUDES) -I $(PDIR)include
INCLUDES += -I ./
INCLUDES += -I ../libc
INCLUDES += -I ../platform
PDIR := ../$(PDIR) PDIR := ../$(PDIR)
sinclude $(PDIR)Makefile sinclude $(PDIR)Makefile
...@@ -34,7 +34,8 @@ ...@@ -34,7 +34,8 @@
#include "osapi.h" #include "osapi.h"
#include "mem.h" #include "mem.h"
#include <string.h> #include <string.h>
#include <c_errno.h> #include <strings.h>
#include <errno.h>
#ifdef MD2_ENABLE #ifdef MD2_ENABLE
#include "ssl/ssl_crypto.h" #include "ssl/ssl_crypto.h"
......
#ifndef _CRYPTO_DIGESTS_H_ #ifndef _CRYPTO_DIGESTS_H_
#define _CRYPTO_DIGESTS_H_ #define _CRYPTO_DIGESTS_H_
#include <c_types.h> #include <stdint.h>
#include <stddef.h>
typedef void (*create_ctx_fn)(void *ctx); typedef void (*create_ctx_fn)(void *ctx);
typedef void (*update_ctx_fn)(void *ctx, const uint8_t *msg, int len); typedef void (*update_ctx_fn)(void *ctx, const uint8_t *msg, int len);
typedef void (*finalize_ctx_fn)(uint8_t *digest, void *ctx); typedef void (*finalize_ctx_fn)(uint8_t *digest, void *ctx);
typedef sint32_t ( *read_fn )(int fd, void *ptr, size_t len); typedef int32_t ( *read_fn )(int fd, void *ptr, size_t len);
/** /**
* Description of a message digest mechanism. * Description of a message digest mechanism.
......
...@@ -33,7 +33,8 @@ ...@@ -33,7 +33,8 @@
#include "mech.h" #include "mech.h"
#include "sdk-aes.h" #include "sdk-aes.h"
#include "c_string.h" #include <string.h>
#include <strings.h>
/* ----- AES ---------------------------------------------------------- */ /* ----- AES ---------------------------------------------------------- */
...@@ -58,7 +59,7 @@ static bool do_aes (crypto_op_t *co, bool with_cbc) ...@@ -58,7 +59,7 @@ static bool do_aes (crypto_op_t *co, bool with_cbc)
char iv[AES_BLOCKSIZE] = { 0 }; char iv[AES_BLOCKSIZE] = { 0 };
if (with_cbc && co->ivlen) if (with_cbc && co->ivlen)
c_memcpy (iv, co->iv, co->ivlen < AES_BLOCKSIZE ? co->ivlen : AES_BLOCKSIZE); memcpy (iv, co->iv, co->ivlen < AES_BLOCKSIZE ? co->ivlen : AES_BLOCKSIZE);
const char *src = co->data; const char *src = co->data;
char *dst = co->out; char *dst = co->out;
...@@ -68,7 +69,7 @@ static bool do_aes (crypto_op_t *co, bool with_cbc) ...@@ -68,7 +69,7 @@ static bool do_aes (crypto_op_t *co, bool with_cbc)
{ {
char block[AES_BLOCKSIZE] = { 0 }; char block[AES_BLOCKSIZE] = { 0 };
size_t n = left > AES_BLOCKSIZE ? AES_BLOCKSIZE : left; size_t n = left > AES_BLOCKSIZE ? AES_BLOCKSIZE : left;
c_memcpy (block, src, n); memcpy (block, src, n);
if (with_cbc && co->op == OP_ENCRYPT) if (with_cbc && co->op == OP_ENCRYPT)
{ {
......
#ifndef _MECH_H_ #ifndef _MECH_H_
#define _MECH_H_ #define _MECH_H_
#include "c_types.h" #include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
typedef struct typedef struct
{ {
......
#ifndef __SHA2_H__ #ifndef __SHA2_H__
#define __SHA2_H__ #define __SHA2_H__
#include <c_types.h> #include <stdint.h>
#include <stddef.h>
/************************************************************************** /**************************************************************************
* SHA256/384/512 declarations * SHA256/384/512 declarations
......
...@@ -37,13 +37,6 @@ endif ...@@ -37,13 +37,6 @@ endif
# Required for each makefile to inherit from the parent # Required for each makefile to inherit from the parent
# #
INCLUDES := $(INCLUDES) -I $(PDIR)include
INCLUDES += -I ./
INCLUDES += -I ./include
INCLUDES += -I ../include
INCLUDES += -I ../../include
INCLUDES += -I ../libc
INCLUDES += -I ../platform
PDIR := ../$(PDIR) PDIR := ../$(PDIR)
sinclude $(PDIR)Makefile sinclude $(PDIR)Makefile
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
#include "user_interface.h" #include "user_interface.h"
#include "platform.h" #include "platform.h"
#include "c_stdio.h" #include <stdio.h>
#include "dht.h" #include "dht.h"
#ifndef LOW #ifndef LOW
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
// #else // #else
// #include <Arduino.h> // #include <Arduino.h>
// #endif // #endif
#include "c_types.h" #include <stdint.h>
#define DHT_LIB_VERSION "0.1.14" #define DHT_LIB_VERSION "0.1.14"
...@@ -67,4 +67,4 @@ double dht_getTemperature(void); ...@@ -67,4 +67,4 @@ double dht_getTemperature(void);
#endif #endif
// //
// END OF FILE // END OF FILE
// //
\ No newline at end of file
...@@ -38,9 +38,6 @@ STD_CFLAGS=-std=gnu11 -Wimplicit ...@@ -38,9 +38,6 @@ STD_CFLAGS=-std=gnu11 -Wimplicit
# Required for each makefile to inherit from the parent # Required for each makefile to inherit from the parent
# #
INCLUDES := $(INCLUDES) -I $(PDIR)include
INCLUDES += -I ./
INCLUDES += -I ../platform
PDIR := ../$(PDIR) PDIR := ../$(PDIR)
sinclude $(PDIR)Makefile sinclude $(PDIR)Makefile
This diff is collapsed.
/*
* Software PWM using soft-interrupt timer1.
* Supports higher frequencies compared to Espressif provided one.
*
* Nikolay Fiykov
*/
#include <stddef.h>
#include <stdint.h>
#include "mem.h"
#include "pin_map.h"
#include "platform.h"
#include "hw_timer.h"
#include "driver/pwm2.h"
#define PWM2_TMR_MAGIC_80MHZ 16
#define PWM2_TMR_MAGIC_160MHZ 32
// module vars, lazy initialized, allocated only if pwm2 is being used
static pwm2_module_data_t *moduleData = NULL;
//############################
// tools
static bool isPinSetup(const pwm2_module_data_t *data, const uint8_t pin) {
return data->setupData.pin[pin].pulseResolutions > 0;
}
static uint32_t getCPUTicksPerSec() {
return system_get_cpu_freq() * 1000000;
}
static uint8_t getCpuTimerTicksDivisor() {
return system_get_cpu_freq() == 80 ? PWM2_TMR_MAGIC_80MHZ : PWM2_TMR_MAGIC_160MHZ;
}
static uint32_t findGCD(uint32_t n1, uint32_t n2) {
uint32_t n3;
while (n2 != 0) {
n3 = n1;
n1 = n2;
n2 = n3 % n2;
}
return n1;
}
static uint32_t findGreatesCommonDividerForTimerTicks(uint32_t newTimerTicks, uint32_t oldTimerTicks) {
return oldTimerTicks == 0 ? newTimerTicks : findGCD(newTimerTicks, oldTimerTicks);
}
static uint16_t findAllEnabledGpioMask(pwm2_module_data_t *moduleData) {
uint16_t enableGpioMask = 0;
for (int i = 1; i < GPIO_PIN_NUM; i++) {
if (moduleData->setupData.pin[i].pulseResolutions > 0) {
enableGpioMask |= moduleData->interruptData.pin[i].gpioMask;
}
}
return enableGpioMask;
}
static uint32_t findCommonCPUTicksDivisor(pwm2_module_data_t *moduleData) {
uint32_t gcdCPUTicks = 0;
for (int i = 1; i < GPIO_PIN_NUM; i++) {
if (moduleData->setupData.pin[i].pulseResolutions > 0) {
gcdCPUTicks = findGreatesCommonDividerForTimerTicks(moduleData->setupData.pin[i].resolutionCPUTicks, gcdCPUTicks);
}
}
return gcdCPUTicks;
}
static uint32_t cpuToTimerTicks(uint32_t cpuTicks) {
return cpuTicks / getCpuTimerTicksDivisor();
}
static void updatePinResolutionToInterruptsMultiplier(pwm2_pin_setup_t *sPin, uint32_t timerCPUTicks) {
sPin->resolutionInterruptCounterMultiplier = sPin->resolutionCPUTicks / timerCPUTicks;
}
static void updatePinPulseToInterruptsCounter(pwm2_pin_interrupt_t *iPin, pwm2_pin_setup_t *sPin) {
iPin->pulseInterruptCcounter = (sPin->pulseResolutions + 1) * sPin->resolutionInterruptCounterMultiplier;
}
static uint8_t getDutyAdjustment(const uint32_t duty, const uint32_t pulse) {
if (duty == 0) {
return 0;
} else if (duty == pulse) {
return 2;
} else {
return 1;
}
}
static void updatePinOffCounter(pwm2_pin_interrupt_t *iPin, pwm2_pin_setup_t *sPin) {
iPin->offInterruptCounter = (sPin->duty + getDutyAdjustment(sPin->duty, sPin->pulseResolutions)) * sPin->resolutionInterruptCounterMultiplier;
}
static void reCalculateCommonToAllPinsData(pwm2_module_data_t *moduleData) {
moduleData->interruptData.enabledGpioMask = findAllEnabledGpioMask(moduleData);
moduleData->setupData.interruptTimerCPUTicks = findCommonCPUTicksDivisor(moduleData);
moduleData->setupData.interruptTimerTicks = cpuToTimerTicks(moduleData->setupData.interruptTimerCPUTicks);
for (int i = 1; i < GPIO_PIN_NUM; i++) {
if (isPinSetup(moduleData, i)) {
updatePinResolutionToInterruptsMultiplier(&moduleData->setupData.pin[i], moduleData->setupData.interruptTimerCPUTicks);
updatePinPulseToInterruptsCounter(&moduleData->interruptData.pin[i], &moduleData->setupData.pin[i]);
updatePinOffCounter(&moduleData->interruptData.pin[i], &moduleData->setupData.pin[i]);
}
}
}
static uint64_t enduserFreqToCPUTicks(const uint64_t divisableFreq, const uint64_t freqDivisor, const uint64_t resolution) {
return (getCPUTicksPerSec() / (freqDivisor * resolution)) * divisableFreq;
}
static uint16_t getPinGpioMask(uint8_t pin) {
return 1 << GPIO_ID_PIN(pin_num[pin]);
}
static void set_duty(pwm2_module_data_t *moduleData, const uint8_t pin, const uint32_t duty) {
pwm2_pin_setup_t *sPin = &moduleData->setupData.pin[pin];
pwm2_pin_interrupt_t *iPin = &moduleData->interruptData.pin[pin];
sPin->duty = duty;
updatePinOffCounter(iPin, sPin);
}
static void configureAllPinsAsGpioOutput(pwm2_module_data_t *moduleData) {
for (int i = 1; i < GPIO_PIN_NUM; i++) {
if (isPinSetup(moduleData, i)) {
PIN_FUNC_SELECT(pin_mux[i], pin_func[i]); // set pin as gpio
PIN_PULLUP_EN(pin_mux[i]); // set pin pullup on
}
}
}
static void resetPinCounters(pwm2_module_data_t *moduleData) {
for (int i = 1; i < GPIO_PIN_NUM; i++) {
if (isPinSetup(moduleData, i)) {
moduleData->interruptData.pin[i].currentInterruptCounter = 0;
}
}
}
//############################
// interrupt handler related
static inline void computeIsPinOn(pwm2_pin_interrupt_t *pin, uint16_t *maskOn) {
if (pin->currentInterruptCounter == pin->pulseInterruptCcounter) {
pin->currentInterruptCounter = 1;
} else {
pin->currentInterruptCounter++;
}
// ets_printf("curr=%u on=%u\n", pin->currentInterruptCounter, (pin->currentInterruptCounter < pin->offInterruptCounter));
if (pin->currentInterruptCounter < pin->offInterruptCounter) {
*maskOn |= pin->gpioMask;
}
}
static inline bool isPinSetup2(const pwm2_interrupt_handler_data_t *data, const uint8_t pin) {
return data->pin[pin].gpioMask > 0;
}
static inline uint16_t findAllPinOns(pwm2_interrupt_handler_data_t *data) {
uint16_t maskOn = 0;
for (int i = 1; i < GPIO_PIN_NUM; i++) {
if (isPinSetup2(data, i)) {
computeIsPinOn(&data->pin[i], &maskOn);
}
}
return maskOn;
}
static inline void setGpioPins(const uint16_t enabledGpioMask, const register uint16_t maskOn) {
GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, maskOn);
const register uint16_t maskOff = ~maskOn & enabledGpioMask;
GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, maskOff);
}
static void ICACHE_RAM_ATTR timerInterruptHandler(os_param_t arg) {
pwm2_interrupt_handler_data_t *data = (pwm2_interrupt_handler_data_t *)arg;
setGpioPins(data->enabledGpioMask, findAllPinOns(data));
}
//############################
// driver's public API
void pwm2_init() {
moduleData = os_malloc(sizeof(pwm2_module_data_t));
memset(moduleData, 0, sizeof(*moduleData));
}
pwm2_module_data_t *pwm2_get_module_data() {
return moduleData;
}
bool pwm2_is_pin_setup(const uint8_t pin) {
return isPinSetup(moduleData, pin);
}
void pwm2_setup_pin(
const uint8_t pin,
const uint32_t divisableFreq,
const uint32_t freqDivisor,
const uint32_t resolution,
const uint32_t initDuty
)
{
moduleData->setupData.pin[pin].pulseResolutions = resolution;
moduleData->setupData.pin[pin].divisableFrequency = divisableFreq;
moduleData->setupData.pin[pin].frequencyDivisor = freqDivisor;
moduleData->setupData.pin[pin].resolutionCPUTicks = enduserFreqToCPUTicks(divisableFreq, freqDivisor, resolution);
moduleData->interruptData.pin[pin].gpioMask = getPinGpioMask(pin);
reCalculateCommonToAllPinsData(moduleData);
set_duty(moduleData, pin, initDuty);
}
void pwm2_release_pin(const uint8_t pin) {
moduleData->setupData.pin[pin].pulseResolutions = 0;
moduleData->interruptData.pin[pin].gpioMask = 0;
}
void pwm2_stop() {
if (!moduleData->setupData.isStarted) {
return;
}
platform_hw_timer_close_exclusive();
GPIO_REG_WRITE(GPIO_ENABLE_W1TC_ADDRESS, moduleData->interruptData.enabledGpioMask); // clear pins of being gpio output
moduleData->setupData.isStarted = false;
}
bool pwm2_start() {
if (moduleData->setupData.isStarted) {
return true;
}
if (!platform_hw_timer_init_exclusive(FRC1_SOURCE, TRUE, timerInterruptHandler, (os_param_t)&moduleData->interruptData, (void (*)(void))NULL)) {
return false;
}
configureAllPinsAsGpioOutput(moduleData);
resetPinCounters(moduleData);
GPIO_REG_WRITE(GPIO_ENABLE_W1TS_ADDRESS, moduleData->interruptData.enabledGpioMask); // set pins as gpio output
moduleData->setupData.isStarted = true;
platform_hw_timer_arm_ticks_exclusive(moduleData->setupData.interruptTimerTicks);
return true;
}
bool pwm2_is_started() {
return moduleData->setupData.isStarted;
}
void pwm2_set_duty(const uint8_t pin, const uint32_t duty) {
set_duty(moduleData, pin, duty);
}
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#include "os_type.h" #include "os_type.h"
#include "osapi.h" #include "osapi.h"
#include "driver/uart.h" #include "driver/uart.h"
#include "c_types.h" #include <stdint.h>
LOCAL os_timer_t readline_timer; LOCAL os_timer_t readline_timer;
......
...@@ -11,9 +11,9 @@ ...@@ -11,9 +11,9 @@
*/ */
#include "platform.h" #include "platform.h"
#include "c_types.h" #include <stdint.h>
#include "../libc/c_stdlib.h" #include <stdlib.h>
#include "../libc/c_stdio.h" #include <stdio.h>
#include "driver/rotary.h" #include "driver/rotary.h"
#include "user_interface.h" #include "user_interface.h"
#include "task/task.h" #include "task/task.h"
...@@ -87,7 +87,7 @@ int rotary_close(uint32_t channel) ...@@ -87,7 +87,7 @@ int rotary_close(uint32_t channel)
rotary_clear_pin(d->phase_b_pin); rotary_clear_pin(d->phase_b_pin);
rotary_clear_pin(d->press_pin); rotary_clear_pin(d->press_pin);
c_free(d); free(d);
set_gpio_bits(); set_gpio_bits();
...@@ -207,7 +207,7 @@ int rotary_setup(uint32_t channel, int phase_a, int phase_b, int press, task_han ...@@ -207,7 +207,7 @@ int rotary_setup(uint32_t channel, int phase_a, int phase_b, int press, task_han
} }
} }
DATA *d = (DATA *) c_zalloc(sizeof(DATA)); DATA *d = (DATA *) calloc(1, sizeof(DATA));
if (!d) { if (!d) {
return -1; return -1;
} }
......
...@@ -14,9 +14,10 @@ ...@@ -14,9 +14,10 @@
*/ */
#include "platform.h" #include "platform.h"
#include "c_types.h" #include <stdint.h>
#include "../libc/c_stdlib.h" #include <stddef.h>
#include "../libc/c_stdio.h" #include <stdlib.h>
#include <stdio.h>
#include "driver/switec.h" #include "driver/switec.h"
#include "ets_sys.h" #include "ets_sys.h"
#include "os_type.h" #include "os_type.h"
...@@ -101,7 +102,7 @@ int switec_close(uint32_t channel) ...@@ -101,7 +102,7 @@ int switec_close(uint32_t channel)
gpio_output_set(0, 0, 0, d->mask); gpio_output_set(0, 0, 0, d->mask);
data[channel] = NULL; data[channel] = NULL;
c_free(d); free(d);
// See if there are any other channels active // See if there are any other channels active
for (channel = 0; channel < sizeof(data)/sizeof(data[0]); channel++) { for (channel = 0; channel < sizeof(data)/sizeof(data[0]); channel++) {
...@@ -259,7 +260,7 @@ int switec_setup(uint32_t channel, int *pin, int max_deg_per_sec, task_handle_t ...@@ -259,7 +260,7 @@ int switec_setup(uint32_t channel, int *pin, int max_deg_per_sec, task_handle_t
} }
} }
DATA *d = (DATA *) c_zalloc(sizeof(DATA)); DATA *d = (DATA *) calloc(1, sizeof(DATA));
if (!d) { if (!d) {
return -1; return -1;
} }
...@@ -269,7 +270,7 @@ int switec_setup(uint32_t channel, int *pin, int max_deg_per_sec, task_handle_t ...@@ -269,7 +270,7 @@ int switec_setup(uint32_t channel, int *pin, int max_deg_per_sec, task_handle_t
// no autoreload // no autoreload
if (!platform_hw_timer_init(TIMER_OWNER, FRC1_SOURCE, FALSE)) { if (!platform_hw_timer_init(TIMER_OWNER, FRC1_SOURCE, FALSE)) {
// Failed to get the timer // Failed to get the timer
c_free(d); free(d);
return -1; return -1;
} }
} }
...@@ -299,12 +300,12 @@ int switec_setup(uint32_t channel, int *pin, int max_deg_per_sec, task_handle_t ...@@ -299,12 +300,12 @@ int switec_setup(uint32_t channel, int *pin, int max_deg_per_sec, task_handle_t
#ifdef SWITEC_DEBUG #ifdef SWITEC_DEBUG
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
c_printf("pin[%d]=%d\n", i, pin[i]); printf("pin[%d]=%d\n", i, pin[i]);
} }
c_printf("Mask=0x%x\n", d->mask); printf("Mask=0x%x\n", d->mask);
for (i = 0; i < N_STATES; i++) { for (i = 0; i < N_STATES; i++) {
c_printf("pinstate[%d]=0x%x\n", i, d->pinstate[i]); printf("pinstate[%d]=0x%x\n", i, d->pinstate[i]);
} }
#endif #endif
......
...@@ -37,8 +37,6 @@ endif ...@@ -37,8 +37,6 @@ endif
# Required for each makefile to inherit from the parent # Required for each makefile to inherit from the parent
# #
INCLUDES += -I $(PDIR)include
INCLUDES += -I ./
INCLUDES += -I ../../include/ets INCLUDES += -I ../../include/ets
PDIR := ../$(PDIR) PDIR := ../$(PDIR)
sinclude $(PDIR)Makefile sinclude $(PDIR)Makefile
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#include "gdbstub.h" #include "gdbstub.h"
#include "ets_sys.h" #include "ets_sys.h"
#include "eagle_soc.h" #include "eagle_soc.h"
#include "c_types.h"
#include "gpio.h" #include "gpio.h"
#include "xtensa/corebits.h" #include "xtensa/corebits.h"
#include "driver/uart.h" #include "driver/uart.h"
...@@ -659,11 +658,22 @@ static void ATTR_GDBFN gdb_semihost_putchar1(char c) { ...@@ -659,11 +658,22 @@ static void ATTR_GDBFN gdb_semihost_putchar1(char c) {
} }
#if !GDBSTUB_FREERTOS #if !GDBSTUB_FREERTOS
//The OS-less SDK uses the Xtensa HAL to handle exceptions. We can use those functions to catch any /* The non-OS SDK uses the Xtensa HAL to handle exceptions, and the SDK now establishes exception
//fatal exceptions and invoke the debugger when this happens. * handlers for EXCCAUSE errors: ILLEGAL, INSTR_ERROR, LOAD_STORE_ERROR, PRIVILEGED, UNALIGNED,
* LOAD_PROHIBITED and STORE_PROHIBITED. These handlers are established in SDK/app_main.c.
* LOAD_STORE_ERROR is handled by SDK/user_exceptions.o:load_non_32_wide_handler() which is a
* fork of our version. The remaining are handled by a static function at
* SDK:app+main.c:offset 0x0348.
*
* Our SDK 2 load_non_32_wide_handler chained into the gdb stub handler if the error was anything
* other than a L8UI, L16SI or L16UI at a flash mapped address. However in this current
* implementation, we have left the Espressif handler in place and handle the other errors with
* the debugger. This means that the debugger will not capture other load store errors. I
* might revise this.
*/
static void ATTR_GDBINIT install_exceptions() { static void ATTR_GDBINIT install_exceptions() {
int i; int i;
int exno[]={EXCCAUSE_ILLEGAL, EXCCAUSE_SYSCALL, EXCCAUSE_INSTR_ERROR, EXCCAUSE_LOAD_STORE_ERROR, const int exno[]={EXCCAUSE_ILLEGAL, EXCCAUSE_SYSCALL, EXCCAUSE_INSTR_ERROR, /* EXCCAUSE_LOAD_STORE_ERROR, */
EXCCAUSE_DIVIDE_BY_ZERO, EXCCAUSE_UNALIGNED, EXCCAUSE_INSTR_DATA_ERROR, EXCCAUSE_LOAD_STORE_DATA_ERROR, EXCCAUSE_DIVIDE_BY_ZERO, EXCCAUSE_UNALIGNED, EXCCAUSE_INSTR_DATA_ERROR, EXCCAUSE_LOAD_STORE_DATA_ERROR,
EXCCAUSE_INSTR_ADDR_ERROR, EXCCAUSE_LOAD_STORE_ADDR_ERROR, EXCCAUSE_INSTR_PROHIBITED, EXCCAUSE_INSTR_ADDR_ERROR, EXCCAUSE_LOAD_STORE_ADDR_ERROR, EXCCAUSE_INSTR_PROHIBITED,
EXCCAUSE_LOAD_PROHIBITED, EXCCAUSE_STORE_PROHIBITED}; EXCCAUSE_LOAD_PROHIBITED, EXCCAUSE_STORE_PROHIBITED};
......
...@@ -42,11 +42,6 @@ STD_CFLAGS=-std=gnu11 -Wimplicit -imacros $(FATFS_INC_DIR)fatfs_prefix_lib.h ...@@ -42,11 +42,6 @@ STD_CFLAGS=-std=gnu11 -Wimplicit -imacros $(FATFS_INC_DIR)fatfs_prefix_lib.h
# Required for each makefile to inherit from the parent # Required for each makefile to inherit from the parent
# #
INCLUDES := $(INCLUDES) -I $(PDIR)include
INCLUDES += -I ./
INCLUDES += -I ../platform
INCLUDES += -I ../libc
INCLUDES += -I ../lua
PDIR := ../$(PDIR) PDIR := ../$(PDIR)
sinclude $(PDIR)Makefile sinclude $(PDIR)Makefile
#include <c_stdlib.h> #include <stdlib.h>
#include <c_string.h> #include <string.h>
#include <stdbool.h>
#include "vfs_int.h" #include "vfs_int.h"
...@@ -12,37 +13,37 @@ static FRESULT last_result = FR_OK; ...@@ -12,37 +13,37 @@ static FRESULT last_result = FR_OK;
static const char* const volstr[FF_VOLUMES] = {FF_VOLUME_STRS}; static const char* const volstr[FF_VOLUMES] = {FF_VOLUME_STRS};
static int is_current_drive = FALSE; static int is_current_drive = false;
// forward declarations // forward declarations
static sint32_t myfatfs_close( const struct vfs_file *fd ); static int32_t myfatfs_close( const struct vfs_file *fd );
static sint32_t myfatfs_read( const struct vfs_file *fd, void *ptr, size_t len ); static int32_t myfatfs_read( const struct vfs_file *fd, void *ptr, size_t len );
static sint32_t myfatfs_write( const struct vfs_file *fd, const void *ptr, size_t len ); static int32_t myfatfs_write( const struct vfs_file *fd, const void *ptr, size_t len );
static sint32_t myfatfs_lseek( const struct vfs_file *fd, sint32_t off, int whence ); static int32_t myfatfs_lseek( const struct vfs_file *fd, int32_t off, int whence );
static sint32_t myfatfs_eof( const struct vfs_file *fd ); static int32_t myfatfs_eof( const struct vfs_file *fd );
static sint32_t myfatfs_tell( const struct vfs_file *fd ); static int32_t myfatfs_tell( const struct vfs_file *fd );
static sint32_t myfatfs_flush( const struct vfs_file *fd ); static int32_t myfatfs_flush( const struct vfs_file *fd );
static uint32_t myfatfs_fsize( const struct vfs_file *fd ); static uint32_t myfatfs_fsize( const struct vfs_file *fd );
static sint32_t myfatfs_ferrno( const struct vfs_file *fd ); static int32_t myfatfs_ferrno( const struct vfs_file *fd );
static sint32_t myfatfs_closedir( const struct vfs_dir *dd ); static int32_t myfatfs_closedir( const struct vfs_dir *dd );
static sint32_t myfatfs_readdir( const struct vfs_dir *dd, struct vfs_stat *buf ); static int32_t myfatfs_readdir( const struct vfs_dir *dd, struct vfs_stat *buf );
static vfs_vol *myfatfs_mount( const char *name, int num ); static vfs_vol *myfatfs_mount( const char *name, int num );
static vfs_file *myfatfs_open( const char *name, const char *mode ); static vfs_file *myfatfs_open( const char *name, const char *mode );
static vfs_dir *myfatfs_opendir( const char *name ); static vfs_dir *myfatfs_opendir( const char *name );
static sint32_t myfatfs_stat( const char *name, struct vfs_stat *buf ); static int32_t myfatfs_stat( const char *name, struct vfs_stat *buf );
static sint32_t myfatfs_remove( const char *name ); static int32_t myfatfs_remove( const char *name );
static sint32_t myfatfs_rename( const char *oldname, const char *newname ); static int32_t myfatfs_rename( const char *oldname, const char *newname );
static sint32_t myfatfs_mkdir( const char *name ); static int32_t myfatfs_mkdir( const char *name );
static sint32_t myfatfs_fsinfo( uint32_t *total, uint32_t *used ); static int32_t myfatfs_fsinfo( uint32_t *total, uint32_t *used );
static sint32_t myfatfs_chdrive( const char *name ); static int32_t myfatfs_chdrive( const char *name );
static sint32_t myfatfs_chdir( const char *name ); static int32_t myfatfs_chdir( const char *name );
static sint32_t myfatfs_errno( void ); static int32_t myfatfs_errno( void );
static void myfatfs_clearerr( void ); static void myfatfs_clearerr( void );
static sint32_t myfatfs_umount( const struct vfs_vol *vol ); static int32_t myfatfs_umount( const struct vfs_vol *vol );
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
...@@ -112,12 +113,12 @@ struct myvfs_dir { ...@@ -112,12 +113,12 @@ struct myvfs_dir {
// //
void *ff_memalloc( UINT size ) void *ff_memalloc( UINT size )
{ {
return c_malloc( size ); return malloc( size );
} }
void ff_memfree( void *mblock ) void ff_memfree( void *mblock )
{ {
c_free( mblock ); free( mblock );
} }
// TODO // TODO
...@@ -153,14 +154,14 @@ DWORD get_fattime( void ) ...@@ -153,14 +154,14 @@ DWORD get_fattime( void )
const struct myvfs_vol *myvol = (const struct myvfs_vol *)descr; \ const struct myvfs_vol *myvol = (const struct myvfs_vol *)descr; \
FATFS *fs = (FATFS *)&(myvol->fs); FATFS *fs = (FATFS *)&(myvol->fs);
static sint32_t myfatfs_umount( const struct vfs_vol *vol ) static int32_t myfatfs_umount( const struct vfs_vol *vol )
{ {
GET_FATFS_FS(vol); GET_FATFS_FS(vol);
last_result = f_mount( NULL, myvol->ldrname, 0 ); last_result = f_mount( NULL, myvol->ldrname, 0 );
c_free( myvol->ldrname ); free( myvol->ldrname );
c_free( (void *)vol ); free( (void *)vol );
return last_result == FR_OK ? VFS_RES_OK : VFS_RES_ERR; return last_result == FR_OK ? VFS_RES_OK : VFS_RES_ERR;
} }
...@@ -173,19 +174,19 @@ static sint32_t myfatfs_umount( const struct vfs_vol *vol ) ...@@ -173,19 +174,19 @@ static sint32_t myfatfs_umount( const struct vfs_vol *vol )
const struct myvfs_file *myfd = (const struct myvfs_file *)descr; \ const struct myvfs_file *myfd = (const struct myvfs_file *)descr; \
FIL *fp = (FIL *)&(myfd->fp); FIL *fp = (FIL *)&(myfd->fp);
static sint32_t myfatfs_close( const struct vfs_file *fd ) static int32_t myfatfs_close( const struct vfs_file *fd )
{ {
GET_FIL_FP(fd) GET_FIL_FP(fd)
last_result = f_close( fp ); last_result = f_close( fp );
// free descriptor memory // free descriptor memory
c_free( (void *)fd ); free( (void *)fd );
return last_result == FR_OK ? VFS_RES_OK : VFS_RES_ERR; return last_result == FR_OK ? VFS_RES_OK : VFS_RES_ERR;
} }
static sint32_t myfatfs_read( const struct vfs_file *fd, void *ptr, size_t len ) static int32_t myfatfs_read( const struct vfs_file *fd, void *ptr, size_t len )
{ {
GET_FIL_FP(fd); GET_FIL_FP(fd);
UINT act_read; UINT act_read;
...@@ -195,7 +196,7 @@ static sint32_t myfatfs_read( const struct vfs_file *fd, void *ptr, size_t len ) ...@@ -195,7 +196,7 @@ static sint32_t myfatfs_read( const struct vfs_file *fd, void *ptr, size_t len )
return last_result == FR_OK ? act_read : VFS_RES_ERR; return last_result == FR_OK ? act_read : VFS_RES_ERR;
} }
static sint32_t myfatfs_write( const struct vfs_file *fd, const void *ptr, size_t len ) static int32_t myfatfs_write( const struct vfs_file *fd, const void *ptr, size_t len )
{ {
GET_FIL_FP(fd); GET_FIL_FP(fd);
UINT act_written; UINT act_written;
...@@ -205,7 +206,7 @@ static sint32_t myfatfs_write( const struct vfs_file *fd, const void *ptr, size_ ...@@ -205,7 +206,7 @@ static sint32_t myfatfs_write( const struct vfs_file *fd, const void *ptr, size_
return last_result == FR_OK ? act_written : VFS_RES_ERR; return last_result == FR_OK ? act_written : VFS_RES_ERR;
} }
static sint32_t myfatfs_lseek( const struct vfs_file *fd, sint32_t off, int whence ) static int32_t myfatfs_lseek( const struct vfs_file *fd, int32_t off, int whence )
{ {
GET_FIL_FP(fd); GET_FIL_FP(fd);
FSIZE_t new_pos; FSIZE_t new_pos;
...@@ -231,7 +232,7 @@ static sint32_t myfatfs_lseek( const struct vfs_file *fd, sint32_t off, int when ...@@ -231,7 +232,7 @@ static sint32_t myfatfs_lseek( const struct vfs_file *fd, sint32_t off, int when
return last_result == FR_OK ? new_pos : VFS_RES_ERR; return last_result == FR_OK ? new_pos : VFS_RES_ERR;
} }
static sint32_t myfatfs_eof( const struct vfs_file *fd ) static int32_t myfatfs_eof( const struct vfs_file *fd )
{ {
GET_FIL_FP(fd); GET_FIL_FP(fd);
...@@ -240,7 +241,7 @@ static sint32_t myfatfs_eof( const struct vfs_file *fd ) ...@@ -240,7 +241,7 @@ static sint32_t myfatfs_eof( const struct vfs_file *fd )
return f_eof( fp ); return f_eof( fp );
} }
static sint32_t myfatfs_tell( const struct vfs_file *fd ) static int32_t myfatfs_tell( const struct vfs_file *fd )
{ {
GET_FIL_FP(fd); GET_FIL_FP(fd);
...@@ -249,7 +250,7 @@ static sint32_t myfatfs_tell( const struct vfs_file *fd ) ...@@ -249,7 +250,7 @@ static sint32_t myfatfs_tell( const struct vfs_file *fd )
return f_tell( fp ); return f_tell( fp );
} }
static sint32_t myfatfs_flush( const struct vfs_file *fd ) static int32_t myfatfs_flush( const struct vfs_file *fd )
{ {
GET_FIL_FP(fd); GET_FIL_FP(fd);
...@@ -267,7 +268,7 @@ static uint32_t myfatfs_fsize( const struct vfs_file *fd ) ...@@ -267,7 +268,7 @@ static uint32_t myfatfs_fsize( const struct vfs_file *fd )
return f_size( fp ); return f_size( fp );
} }
static sint32_t myfatfs_ferrno( const struct vfs_file *fd ) static int32_t myfatfs_ferrno( const struct vfs_file *fd )
{ {
return -last_result; return -last_result;
} }
...@@ -280,24 +281,24 @@ static sint32_t myfatfs_ferrno( const struct vfs_file *fd ) ...@@ -280,24 +281,24 @@ static sint32_t myfatfs_ferrno( const struct vfs_file *fd )
const struct myvfs_dir *mydd = (const struct myvfs_dir *)descr; \ const struct myvfs_dir *mydd = (const struct myvfs_dir *)descr; \
DIR *dp = (DIR *)&(mydd->dp); DIR *dp = (DIR *)&(mydd->dp);
static sint32_t myfatfs_closedir( const struct vfs_dir *dd ) static int32_t myfatfs_closedir( const struct vfs_dir *dd )
{ {
GET_DIR_DP(dd); GET_DIR_DP(dd);
last_result = f_closedir( dp ); last_result = f_closedir( dp );
// free descriptor memory // free descriptor memory
c_free( (void *)dd ); free( (void *)dd );
return last_result == FR_OK ? VFS_RES_OK : VFS_RES_ERR; return last_result == FR_OK ? VFS_RES_OK : VFS_RES_ERR;
} }
static void myfatfs_fill_stat( const FILINFO *fno, struct vfs_stat *buf ) static void myfatfs_fill_stat( const FILINFO *fno, struct vfs_stat *buf )
{ {
c_memset( buf, 0, sizeof( struct vfs_stat ) ); memset( buf, 0, sizeof( struct vfs_stat ) );
// fill in supported stat entries // fill in supported stat entries
c_strncpy( buf->name, fno->fname, FS_OBJ_NAME_LEN+1 ); strncpy( buf->name, fno->fname, FS_OBJ_NAME_LEN+1 );
buf->name[FS_OBJ_NAME_LEN] = '\0'; buf->name[FS_OBJ_NAME_LEN] = '\0';
buf->size = fno->fsize; buf->size = fno->fsize;
buf->is_dir = fno->fattrib & AM_DIR ? 1 : 0; buf->is_dir = fno->fattrib & AM_DIR ? 1 : 0;
...@@ -316,7 +317,7 @@ static void myfatfs_fill_stat( const FILINFO *fno, struct vfs_stat *buf ) ...@@ -316,7 +317,7 @@ static void myfatfs_fill_stat( const FILINFO *fno, struct vfs_stat *buf )
buf->tm_valid = 1; buf->tm_valid = 1;
} }
static sint32_t myfatfs_readdir( const struct vfs_dir *dd, struct vfs_stat *buf ) static int32_t myfatfs_readdir( const struct vfs_dir *dd, struct vfs_stat *buf )
{ {
GET_DIR_DP(dd); GET_DIR_DP(dd);
FILINFO fno; FILINFO fno;
...@@ -340,19 +341,19 @@ static sint32_t myfatfs_readdir( const struct vfs_dir *dd, struct vfs_stat *buf ...@@ -340,19 +341,19 @@ static sint32_t myfatfs_readdir( const struct vfs_dir *dd, struct vfs_stat *buf
static vfs_vol *myfatfs_mount( const char *name, int num ) static vfs_vol *myfatfs_mount( const char *name, int num )
{ {
struct myvfs_vol *vol; struct myvfs_vol *vol;
const size_t len = c_strlen( name ); const size_t len = strlen( name );
// num argument specifies the physical driver = SS/CS pin number for this sd card // num argument specifies the physical driver = SS/CS pin number for this sd card
if (num >= 0) { if (num >= 0) {
for (int i = 0; i < NUM_LOGICAL_DRIVES; i++) { for (int i = 0; i < NUM_LOGICAL_DRIVES; i++) {
if (0 == c_strncmp( name, volstr[i], c_strlen( volstr[i] ) )) { if (0 == strncmp( name, volstr[i], strlen( volstr[i] ) )) {
VolToPart[i].pd = num; VolToPart[i].pd = num;
} }
} }
} }
if (vol = c_malloc( sizeof( struct myvfs_vol ) )) { if (vol = malloc( sizeof( struct myvfs_vol ) )) {
if (vol->ldrname = c_strdup( name )) { if (vol->ldrname = strdup( name )) {
if (FR_OK == (last_result = f_mount( &(vol->fs), name, 1 ))) { if (FR_OK == (last_result = f_mount( &(vol->fs), name, 1 ))) {
vol->vfs_vol.fs_type = VFS_FS_FATFS; vol->vfs_vol.fs_type = VFS_FS_FATFS;
vol->vfs_vol.fns = &myfatfs_vol_fns; vol->vfs_vol.fns = &myfatfs_vol_fns;
...@@ -362,29 +363,29 @@ static vfs_vol *myfatfs_mount( const char *name, int num ) ...@@ -362,29 +363,29 @@ static vfs_vol *myfatfs_mount( const char *name, int num )
} }
if (vol) { if (vol) {
if (vol->ldrname) c_free( vol->ldrname ); if (vol->ldrname) free( vol->ldrname );
c_free( vol ); free( vol );
} }
return NULL; return NULL;
} }
static BYTE myfatfs_mode2flag( const char *mode ) static BYTE myfatfs_mode2flag( const char *mode )
{ {
if (c_strlen( mode ) == 1) { if (strlen( mode ) == 1) {
if(c_strcmp( mode, "w" ) == 0) if(strcmp( mode, "w" ) == 0)
return FA_WRITE | FA_CREATE_ALWAYS; return FA_WRITE | FA_CREATE_ALWAYS;
else if (c_strcmp( mode, "r" ) == 0) else if (strcmp( mode, "r" ) == 0)
return FA_READ | FA_OPEN_EXISTING; return FA_READ | FA_OPEN_EXISTING;
else if (c_strcmp( mode, "a" ) == 0) else if (strcmp( mode, "a" ) == 0)
return FA_WRITE | FA_OPEN_ALWAYS; return FA_WRITE | FA_OPEN_ALWAYS;
else else
return FA_READ | FA_OPEN_EXISTING; return FA_READ | FA_OPEN_EXISTING;
} else if (c_strlen( mode ) == 2) { } else if (strlen( mode ) == 2) {
if (c_strcmp( mode, "r+" ) == 0) if (strcmp( mode, "r+" ) == 0)
return FA_READ | FA_WRITE | FA_OPEN_EXISTING; return FA_READ | FA_WRITE | FA_OPEN_EXISTING;
else if (c_strcmp( mode, "w+" ) == 0) else if (strcmp( mode, "w+" ) == 0)
return FA_READ | FA_WRITE | FA_CREATE_ALWAYS; return FA_READ | FA_WRITE | FA_CREATE_ALWAYS;
else if (c_strcmp( mode, "a+" ) ==0 ) else if (strcmp( mode, "a+" ) ==0 )
return FA_READ | FA_WRITE | FA_OPEN_ALWAYS; return FA_READ | FA_WRITE | FA_OPEN_ALWAYS;
else else
return FA_READ | FA_OPEN_EXISTING; return FA_READ | FA_OPEN_EXISTING;
...@@ -398,7 +399,7 @@ static vfs_file *myfatfs_open( const char *name, const char *mode ) ...@@ -398,7 +399,7 @@ static vfs_file *myfatfs_open( const char *name, const char *mode )
struct myvfs_file *fd; struct myvfs_file *fd;
const BYTE flags = myfatfs_mode2flag( mode ); const BYTE flags = myfatfs_mode2flag( mode );
if (fd = c_malloc( sizeof( struct myvfs_file ) )) { if (fd = malloc( sizeof( struct myvfs_file ) )) {
if (FR_OK == (last_result = f_open( &(fd->fp), name, flags ))) { if (FR_OK == (last_result = f_open( &(fd->fp), name, flags ))) {
// skip to end of file for append mode // skip to end of file for append mode
if (flags & FA_OPEN_ALWAYS) if (flags & FA_OPEN_ALWAYS)
...@@ -408,7 +409,7 @@ static vfs_file *myfatfs_open( const char *name, const char *mode ) ...@@ -408,7 +409,7 @@ static vfs_file *myfatfs_open( const char *name, const char *mode )
fd->vfs_file.fns = &myfatfs_file_fns; fd->vfs_file.fns = &myfatfs_file_fns;
return (vfs_file *)fd; return (vfs_file *)fd;
} else { } else {
c_free( fd ); free( fd );
} }
} }
...@@ -419,20 +420,20 @@ static vfs_dir *myfatfs_opendir( const char *name ) ...@@ -419,20 +420,20 @@ static vfs_dir *myfatfs_opendir( const char *name )
{ {
struct myvfs_dir *dd; struct myvfs_dir *dd;
if (dd = c_malloc( sizeof( struct myvfs_dir ) )) { if (dd = malloc( sizeof( struct myvfs_dir ) )) {
if (FR_OK == (last_result = f_opendir( &(dd->dp), name ))) { if (FR_OK == (last_result = f_opendir( &(dd->dp), name ))) {
dd->vfs_dir.fs_type = VFS_FS_FATFS; dd->vfs_dir.fs_type = VFS_FS_FATFS;
dd->vfs_dir.fns = &myfatfs_dir_fns; dd->vfs_dir.fns = &myfatfs_dir_fns;
return (vfs_dir *)dd; return (vfs_dir *)dd;
} else { } else {
c_free( dd ); free( dd );
} }
} }
return NULL; return NULL;
} }
static sint32_t myfatfs_stat( const char *name, struct vfs_stat *buf ) static int32_t myfatfs_stat( const char *name, struct vfs_stat *buf )
{ {
FILINFO fno; FILINFO fno;
...@@ -445,28 +446,28 @@ static sint32_t myfatfs_stat( const char *name, struct vfs_stat *buf ) ...@@ -445,28 +446,28 @@ static sint32_t myfatfs_stat( const char *name, struct vfs_stat *buf )
} }
} }
static sint32_t myfatfs_remove( const char *name ) static int32_t myfatfs_remove( const char *name )
{ {
last_result = f_unlink( name ); last_result = f_unlink( name );
return last_result == FR_OK ? VFS_RES_OK : VFS_RES_ERR; return last_result == FR_OK ? VFS_RES_OK : VFS_RES_ERR;
} }
static sint32_t myfatfs_rename( const char *oldname, const char *newname ) static int32_t myfatfs_rename( const char *oldname, const char *newname )
{ {
last_result = f_rename( oldname, newname ); last_result = f_rename( oldname, newname );
return last_result == FR_OK ? VFS_RES_OK : VFS_RES_ERR; return last_result == FR_OK ? VFS_RES_OK : VFS_RES_ERR;
} }
static sint32_t myfatfs_mkdir( const char *name ) static int32_t myfatfs_mkdir( const char *name )
{ {
last_result = f_mkdir( name ); last_result = f_mkdir( name );
return last_result == FR_OK ? VFS_RES_OK : VFS_RES_ERR; return last_result == FR_OK ? VFS_RES_OK : VFS_RES_ERR;
} }
static sint32_t myfatfs_fsinfo( uint32_t *total, uint32_t *used ) static int32_t myfatfs_fsinfo( uint32_t *total, uint32_t *used )
{ {
DWORD free_clusters; DWORD free_clusters;
FATFS *fatfs; FATFS *fatfs;
...@@ -480,21 +481,21 @@ static sint32_t myfatfs_fsinfo( uint32_t *total, uint32_t *used ) ...@@ -480,21 +481,21 @@ static sint32_t myfatfs_fsinfo( uint32_t *total, uint32_t *used )
return last_result == FR_OK ? VFS_RES_OK : VFS_RES_ERR; return last_result == FR_OK ? VFS_RES_OK : VFS_RES_ERR;
} }
static sint32_t myfatfs_chdrive( const char *name ) static int32_t myfatfs_chdrive( const char *name )
{ {
last_result = f_chdrive( name ); last_result = f_chdrive( name );
return last_result == FR_OK ? VFS_RES_OK : VFS_RES_ERR; return last_result == FR_OK ? VFS_RES_OK : VFS_RES_ERR;
} }
static sint32_t myfatfs_chdir( const char *name ) static int32_t myfatfs_chdir( const char *name )
{ {
last_result = f_chdir( name ); last_result = f_chdir( name );
return last_result == FR_OK ? VFS_RES_OK : VFS_RES_ERR; return last_result == FR_OK ? VFS_RES_OK : VFS_RES_ERR;
} }
static sint32_t myfatfs_errno( void ) static int32_t myfatfs_errno( void )
{ {
return -last_result; return -last_result;
} }
...@@ -515,10 +516,10 @@ vfs_fs_fns *myfatfs_realm( const char *inname, char **outname, int set_current_d ...@@ -515,10 +516,10 @@ vfs_fs_fns *myfatfs_realm( const char *inname, char **outname, int set_current_d
// logical drive is specified, check if it's one of ours // logical drive is specified, check if it's one of ours
for (int i = 0; i < FF_VOLUMES; i++) { for (int i = 0; i < FF_VOLUMES; i++) {
size_t volstr_len = c_strlen( volstr[i] ); size_t volstr_len = strlen( volstr[i] );
if (0 == c_strncmp( &(inname[1]), volstr[i], volstr_len )) { if (0 == strncmp( &(inname[1]), volstr[i], volstr_len )) {
oname = c_strdup( inname ); oname = strdup( inname );
c_strcpy( oname, volstr[i] ); strcpy( oname, volstr[i] );
oname[volstr_len] = ':'; oname[volstr_len] = ':';
*outname = oname; *outname = oname;
...@@ -529,11 +530,11 @@ vfs_fs_fns *myfatfs_realm( const char *inname, char **outname, int set_current_d ...@@ -529,11 +530,11 @@ vfs_fs_fns *myfatfs_realm( const char *inname, char **outname, int set_current_d
} else { } else {
// no logical drive in patchspec, are we current drive? // no logical drive in patchspec, are we current drive?
if (is_current_drive) { if (is_current_drive) {
*outname = c_strdup( inname ); *outname = strdup( inname );
return &myfatfs_fs_fns; return &myfatfs_fs_fns;
} }
} }
if (set_current_drive) is_current_drive = FALSE; if (set_current_drive) is_current_drive = false;
return NULL; return NULL;
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment