Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Ivan Grokhotkov
@igrr
need to think if there are some edge cases when this can break existing sketches
Me No Dev
@me-no-dev
it will prevent anyone to write an interrupt enabled stuff using C
same as with digitalRead/Write and so on
Ivan Grokhotkov
@igrr
Oh yeah, right, it will break twi.c for example
#ifdef __cplusplus maybe, and different names for C- and C++ versions (non-mangled and mangled)
with C version implemented in C++, and calls C++ version :)
Me No Dev
@me-no-dev
:D
Ivan Grokhotkov
@igrr
scratch that, twi.c doesn't use attachInterrupt
Me No Dev
@me-no-dev
no, but other things might
as far as I know all arduinos are C on that side
can we wrap the c++ callback and that be called from the C callback if lambda is needed?
sticilface
@sticilface
That was quick! Awesome!
Cheers.
Under 10min. Even more awesome!!
Me No Dev
@me-no-dev
@igrr is the size of the pointer to the labda the same as to a normal C function?
we have this struct in the core for each attached interrupt
typedef struct {
  uint8_t mode;
  void (*fn)(void);
} interrupt_handler_t;
Ivan Grokhotkov
@igrr
well, lambda is just one case, in general the idea is to support any function object
so in theory you could store an object pointer and a member function pointer, but doing that manually is dirty and discouraged since c++11
or even, c++0x
marksev1
@marksev1
So the sparkfun lib for the Apds-9930 gesture sensor uses interrupts that means ita no-go for a esp running wifi. But what if i had that sensor on arduino promini and it would send data via serial to esp8266? Would that work?
Clemens Kirchgatterer
@everslick
any thoughts on declaring malloc, free and realloc as weak (attribute((weak))) so we can wrap them in sketches (for debugging and profiling purposes) ?
Ivan Grokhotkov
@igrr
You mean wrap as -WL,wrap,malloc or just redefine weak symbol?
I think making malloc weak is not very useful, because it's a big complex function, and you would have to duplicate it's functionality in your sketch. That would be difficult because it uses some static variables from umm_malloc.c
Wrapping may be useful, because you can call real definition after/before you do profiling/logging
I wonder how widespread such use would be though... It's pretty easy to add corresponding flags locally in your platform.txt, so maybe a short piece of documentation on how to do that would be sufficient?
Clemens Kirchgatterer
@everslick
i would like libraries also to use MY wrapper, that call malloc/free themself (also new and delete, but they call malloc and free anyway). i do not care so much as HOW this can be acomplished. i'm open to suggestions.
i just found #ifdef UMM_REDEFINE_MEM_FUNCTIONS. if there was a way to unset this define, i could wrap malloc/free in my scatch and call umm_malloc in my wrappers.
Me No Dev
@me-no-dev
you comment it and it's unset. umm is built with the core every time you compile the sketch
Clemens Kirchgatterer
@everslick
Me No Dev, yes i know, but that means i have to mess with my local copy of the Arduino core. I'd prefere to be able to do it from my makefile or such
Me No Dev
@me-no-dev
whatever way you chose, you will need to modify a file or two. If you do your own makefile, then maybe you can wrpa them and go that way with just modifying the flags
there are already two functions rewritten and you can see the flags in the platform.txt
then one is implemented in core_esp8266_postmortem.c
system_restart_local that is
Clemens Kirchgatterer
@everslick
thx, i look at plattform.txt and postmortem.c
Clemens Kirchgatterer
@everslick
hmm, i see __wrap_system_restart_local(), but i don't see where it is used ??? i' confused
Me No Dev
@me-no-dev
for example there is a function called system_restart_local that is in the inclued prebuilt libs that we need to overwrite in order to get the stack trace
so we need our function to be called instead
and we wrap it this way :)
Clemens Kirchgatterer
@everslick
-Wl,-wrap,system_restart_local AHH
abviously th linker adds _wrap by itself ?
Me No Dev
@me-no-dev
yes and __real_[method name]
Clemens Kirchgatterer
@everslick
thats what ivan mentioned above
now i get it
Me No Dev
@me-no-dev
that coresponds to the original function
Clemens Kirchgatterer
@everslick
so i have to declare extern void ___real_malloc(size_t) and implement void ___wrap_malloc(size_t)
and set the linker flag -Wl,wrap,malloc and be done
argl this chat swallows all kind of symbols :(
Me No Dev
@me-no-dev
extern void * __real_malloc(size_t);
void * __wrap_malloc(size_t len){
  ets_printf("trying to mallog %u bytes\n", len);
  return __real_malloc(len);
}
Clemens Kirchgatterer
@everslick
nice, cut'n paste for me! THX!!! :-)