Port.Pin as function parameter.

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,
let me describe my problem. I have following piece of code written:

typedef struct{
    uint8_t p0:1;
    uint8_t p1:1;
    uint8_t p2:1;
    uint8_t p3:1;
    uint8_t p4:1;
    uint8_t p5:1;
    uint8_t p6:1;
    uint8_t p7:1;
} IO;

#define PORT_B_DDR (*(volatile IO*)&DDRB)
#define PORT_B  (*(volatile IO*)&PORTB)
#define PORT_B_PIN (*(volatile IO*)&PINB)

#define SPI0_CAN_CS   PORT_B.p4
#define SPI0_CAN_CS_DDR  PORT_B_DDR.p4
#define SPI0_CAN_CS_PIN  PORT_B_PIN.p4

How can I pass SPI_CAN_CS as a function parameter. What type is it ?

Any help appreciated :)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Any integer type will accept it.

Taking its address is a no-no.

International Theophysical Year seems to have been forgotten..
Anyone remember the song Jukebox Band?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

To be absolutely clear, skeeve's response implies that you can use pass-by-value semantics only.

Pass-by-reference semantics (and, therefore, the ability for the callee to modify the pin's state via the function parameter) will not work.