[fpc-devel] [fpc-pascal] ENC28J60 Ethernet Controller AVR/ARM Driver

Jeppe Johansen jeppe at j-software.dk
Sun Jun 2 16:46:38 CEST 2019


On 6/1/19 3:37 PM, Dimitrios Chr. Ioannidis via fpc-pascal wrote:
>
> Hi,
>
>   I started to write a driver ( 
> https://github.com/dioannidis/fp_ethernet_enc28j60.git ) for this chip 
> ( ENC28J60 Ethernet Controller ) first for the AVR platform, ( heavily 
> inspired from the UIPEthernet library ( 
> https://github.com/UIPEthernet/UIPEthernet.git )) and I want to ask 
> the community, of course, is there anyone that already done it ?
>
>   My goal is to made the free pascal users able to use a very low cost 
> solution Arduino Nano / UNO  development board with a ENC28J60 module 
> for a little IoT ( and not only ) fun, learning e.t.c. ...
>
>   I managed to configure the chip and the driver receives packets ( 
> broadcast packets configured to allow only ARP ).
>
>   Now, because I'm not embedded developer I'm thinking that I would 
> need help / advices to take some decisions so here I am.
>
>   First and more important, in the new FPC version, will the AVR 
> platform review / resolve the following issues :
>
>     "AVR - incorrect stack error checking" 
> (https://bugs.freepascal.org/view.php?id=35332)
It should work now. Looking into whether it will make sense to just use 
up all the space of non-data as suggested in the related issue.
> "AVR - Assembler routines for 8, 16 & 32 bit unsigned div (code 
> contribution)" ( https://bugs.freepascal.org/view.php?id=32103 )
Fixed as well.
> "AVR - invalid address used when evaluating a variable in gdb" ( 
> https://bugs.freepascal.org/view.php?id=33914 )
Looking into this.
> "AVR - Incorrect SPI clock rate bit constant names in some 
> microcontroller units" ( https://bugs.freepascal.org/view.php?id=32339 )
>     and add support for theavrxmega3 subarch, atmega 3208, 3209, 4808, 
> 4809 ( from Christo Crause's repository 
> https://github.com/ccrause/freepascal.git ) ?
>
>   Except from Laksen's ethernet stack ( 
> https://github.com/Laksen/fp-ethernet.git ) is there other, more 
> lightweight, ethernet stack library written in Object Pascal ?
>
Not sure, but I doubt it. But how much more lightweight do you need it 
to be? ;)
>
>   As I'm not a compiler guy, isthe "volatile" intrinsic supported in 
> AVR platform ( I didn't find it in intrinsics unit ) ?
>
It's supported, but it does not do anything at all. At least not now, 
and I don't think that will change. All global variable or pointer 
accesses are considered volatile to my knowledge.

But volatile in FPC does not guarantee any atomic access. So this would 
need to be by you. If what you need is just atomic access, then simple 
functions like these generate optimal code:

procedure AtomicWnrite(var value: word; new_value: word); inline;
var
   b: Byte;
begin
   b:=avr_save;
   value:=new_value;
   avr_restore(b);
end;

function AtomicRead(var value: word): word; inline;
var
   b: Byte;
begin
   b:=avr_save;
   AtomicRead:=value;
   avr_restore(b);
end;
>
>   In FPC embedded world/platforms, is the Object approach more SRAM 
> hungry ( my tests are inconclusive ) from the procedure / function 
> approach ?
>
>   What's more embedded "friendly" ?
>
If used sensibly they should be more or less equal in size, but you will 
see some extra overhead with objects. Mostly due to needing passing the 
pointer to the object as an argument. But you also gain some level of 
abstraction. So it's a tradeoff.
>
> this :
>
> interface
>
> type
>   TUART = Object
>   private
>     FBaudRate: DWord;
>     function Divider: Integer;
>   public
>     procedure Init(const ABaudRate: DWord = 57600);
>     procedure SendChar(c: char);
>     function ReadChar: char;
>     procedure SendString(s: ShortString);
>     procedure SendStringLn(s: ShortString = '');
>   end;
>
> or this :
>
> interface
>
>   var
>     FBaudRate: DWord;
>     function Divider: Integer;
>     procedure Init(const ABaudRate: DWord = 57600);
>     procedure SendChar(c: char);
>     function ReadChar: char;
>     procedure SendString(s: ShortString);
>
>     procedure SendStringLn(s: ShortString = '');
>
>
> And of course anyone who wants to help is welcome .
>
> regards,
>
> -- 
>
> Dimitrios Chr. Ioannidis
>
>
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20190602/c50655ee/attachment.html>


More information about the fpc-devel mailing list