Custom port A9G module: help wanted

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
pulkin
Posts: 49
Joined: Tue Feb 19, 2019 10:22 pm

Re: Custom port A9G module: help wanted

Post by pulkin » Sun Mar 10, 2019 3:14 pm

So what kind of API should I implement for the scenario: "SMS recieved", for example?

pulkin
Posts: 49
Joined: Tue Feb 19, 2019 10:22 pm

Re: Custom port A9G module: help wanted

Post by pulkin » Thu Apr 11, 2019 10:24 pm

I have the following piece of code (porting esp32 sockets):

Code: Select all

#include "py/stream.h"

void function(void){
    mp_stream_p_t x;
    x.read = NULL;
}
It fails at the assignment with error: expected identifier before ‘(’ token. Any idea?

jickster
Posts: 629
Joined: Thu Sep 07, 2017 8:57 pm

Re: Custom port A9G module: help wanted

Post by jickster » Thu Apr 11, 2019 11:22 pm

That code by itself should compile.
Something in the .h is causing the error.


Sent from my iPhone using Tapatalk Pro

pulkin
Posts: 49
Joined: Tue Feb 19, 2019 10:22 pm

Re: Custom port A9G module: help wanted

Post by pulkin » Fri Apr 12, 2019 11:58 am


User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Custom port A9G module: help wanted

Post by dhylands » Fri Apr 12, 2019 3:14 pm

To figure out what's going on, you need to look at the preprocessed source file.

On the pyboard, there is a rule in the makefile to create preprocessed files.

If, for example, I was trying to see the preprocessed file for ports/stm32/adc.c it produces an object file build-PYBV11/adc.o so I could ask do:

Code: Select all

make BOARD=PYBV11 build-PYBV11/adc.pp
(i.e. replace .o with .pp) and the adc.pp file will have the preprocessed file that the compiler sees.

This will typically make it easier to figure out what's actually going on, which will often wind up being some macro being defined in an unexpected way.

pulkin
Posts: 49
Joined: Tue Feb 19, 2019 10:22 pm

Re: Custom port A9G module: help wanted

Post by pulkin » Fri Apr 12, 2019 7:22 pm

Given I have this in the pp:

Code: Select all

	mp_stream_p_t x;
	x.(g_InterfaceVtbl->lwip_read) = NULL;
is it reasonable to assume that our Chinese friends bundle a 'read' macro that was substituted? How do I get rid of it without changing outer files and imports?

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Custom port A9G module: help wanted

Post by dhylands » Fri Apr 12, 2019 9:23 pm

It would seem that way.

You can put

Code: Select all

#if defined(read)
#undef read
#endif
in your code after the #includes

However, read seems pretty generic and that #define might mess up other things which you might not be able to fix as easily (just a heads up)

If the #include file containing the #define read is guarded (i.e. protects itself from being included multiple times) then you might be able to #include it, #undef read and then go along with your other #includes.

If you search for read in the .pp file you should see the #define (if you use the same options that MicroPython is using for producing the .pp files it keeps all of the #defines around)

pulkin
Posts: 49
Joined: Tue Feb 19, 2019 10:22 pm

Re: Custom port A9G module: help wanted

Post by pulkin » Sun Apr 28, 2019 2:39 pm

What kind of mechanism finalizes objects (i.e. closes files on reference count = 0) in micropython? Is it GC? What do I need implement for it?

jickster
Posts: 629
Joined: Thu Sep 07, 2017 8:57 pm

Re: Custom port A9G module: help wanted

Post by jickster » Sun Apr 28, 2019 3:01 pm

pulkin wrote:What kind of mechanism finalizes objects (i.e. closes files on reference count = 0) in micropython? Is it GC? What do I need implement for it?
There’s no reference counting in micropython unless you implement it yourself.

You have to enable the macro MICROPY_ENABLE_FINALISER.

Also for your object, you need to define __del__ because finalization calls that method.

If you want reference counting for some resource, you would implement that in the constructor and __del__


Sent from my iPhone using Tapatalk Pro

pulkin
Posts: 49
Joined: Tue Feb 19, 2019 10:22 pm

Re: Custom port A9G module: help wanted

Post by pulkin » Sun Apr 28, 2019 3:37 pm

OK, to try this out I need to also enable gc. So my question is: what does micropython gc actually do? What is the difference between micropython running with gc and without it?

Post Reply