You would think it should  be used with AVR since the data pointer is
typically 16-bits and the instruction pointer is typically 20-24 bits.  But
it is not, that is because 1) GCC does support the concept of code vs
data.  and 2) a fixed size pointer is used, regardless of actual size of
the address.  AVR also does things differently by defining something called
IPTR (memx) in include/nuttx/compiler.h.  That should have been called CODE.

In arch/avr/include/types (with include/sys/types.h), a pointer is
typically defined to be 16-bits. That limits the size of the instruction
space to 128Kb (I think) and the data space to 64Kb. There are kludges to
access instruction space beyond this (for example,
https://www.avrfreaks.net/forum/size-pointer-flash-memory-atmega2560).

CODE is the matching name for FAR and NEAR.  That former means that the
pointer refers to code and an instruction space pointer should be ubsed and
the latter means that the pointer refers to data and a data space pointer
should used (with a far address or a smaller near address).  In
arch/avr/include/types.h you can see that far and near pointers are
defined.  Removing CODE while keeping FAR and NEAR would be illogical since
they are part of the same solution.


On Wed, Jan 26, 2022 at 7:22 AM Alan Carvalho de Assis <acas...@gmail.com>
wrote:

> Hi Petro,
>
> It is used by Z80, Z180 and Z16/ZNEO, see include/nuttx/compiler.h for
> reference.
>
> BR,
>
> Alan
>
> On 1/26/22, Petro Karashchenko <petro.karashche...@gmail.com> wrote:
> > Hello team,
> >
> > Recently I noticed that some structures in common code use CODE
> > keyword for pointers to functions and some do not, so I have the
> > question: is CODE keyword still supported?
> > Here are few examples:
> > struct automount_lower_s
> > {
> > ...
> >   CODE int (*attach)(FAR const struct automount_lower_s *lower,
> >                       automount_handler_t isr, FAR void *arg);
> >   CODE void (*enable)(FAR const struct automount_lower_s *lower,
> >                       bool enable);
> >   CODE bool (*inserted)(FAR const struct automount_lower_s *lower);
> > };
> > vs
> > struct file_operations
> > {
> >   int     (*open)(FAR struct file *filep);
> >   int     (*close)(FAR struct file *filep);
> >   ssize_t (*read)(FAR struct file *filep, FAR char *buffer, size_t
> buflen);
> >   ssize_t (*write)(FAR struct file *filep, FAR const char *buffer,
> >                    size_t buflen);
> >   off_t   (*seek)(FAR struct file *filep, off_t offset, int whence);
> >   int     (*ioctl)(FAR struct file *filep, int cmd, unsigned long arg);
> >
> >   /* The two structures need not be common after this point */
> >
> >   int     (*poll)(FAR struct file *filep, struct pollfd *fds, bool
> setup);
> > #ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
> >   int     (*unlink)(FAR struct inode *inode);
> > #endif
> > };
> >
> > Will appreciate your feedback.
> >
> > Best regards,
> > Petro
> >
>

Reply via email to