On Wed, 11 Oct 2023 at 12:01, Rod Webster <r...@vehiclemods.net.au> wrote:
>
> Here is another example where a 16 bit word is decoded into individual pins
> but the word is also used as a pin

Well, it shouldn't be....
The size of "unsigned int" is platform dependent, all HAL components
should be using the HAL types for the memory locations that are
defined as pins, in this case it should be hal_u32_t.

> typedef union
> {
>   struct
>   {
>     unsigned char SwitchOn        : 1;  // 00
>     unsigned char EnableVoltage   : 1;  // 01
>     unsigned char QuickStop       : 1;  // 02
>     unsigned char EnableOperation : 1;  // 03
>     unsigned char StartHome       : 1;  // 04 not used in CSP or homing
>     unsigned char bit5            : 1;  // 05 not used in CSP or homing
>     unsigned char bit6            : 1;  // 06 not used in CSP or homing
>     unsigned char Faultreset      : 1;  // 07
>     unsigned char Timeout         : 1;  // 08
>     unsigned char bit9            : 1;  // 09 not used in any mode
>     unsigned char keep            : 6;  // 10-15 not used in any mode
>   }b;
>     unsigned int Word;
> }Control_t;

> Converted to 64 bit variables to contain the bits sounds just awful.

If the code had been written correctly as:

typedef union
{
  struct
  {
    unsigned char SwitchOn        : 1;  // 00
...
    unsigned char keep            : 6;  // 10-15 not used in any mode
  }b;
    hal_u32_t Word;
}Control_t;

And if hal_u32_t was mapped into an S64 (as I am proposing) then
nothing at all would need to change in this code.

> I really think typed variables should be retained.

I am only proposing to combine the current 4 integer hal pin types into one.

> If you don't understand data types, there is no place for you to be
> programming in C

You are aware that even in C the size of an "int" is platform and
compiler dependent? Maybe consider the possibility that I do
understand datatypes, and also understand how they work in the context
of HAL pins.

-- 
atp
"A motorcycle is a bicycle with a pandemonium attachment and is
designed for the especial use of mechanical geniuses, daredevils and
lunatics."
— George Fitch, Atlanta Constitution Newspaper, 1912


_______________________________________________
Emc-developers mailing list
Emc-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emc-developers

Reply via email to