Page 1 of 1

GPIO and leaf procedures

Posted: Wed Sep 05, 2018 9:53 am
by steve64
I suppose GPIO.Put() and GPIO.Get() are not valid inside a leaf procedure, do you confirm?
If so, it would be helpful to allow that. I have a user case in fast bitbanging where
a protocol could be implemented by calling leaf procedures just operating on GPIOs.

Re: GPIO and leaf procedures

Posted: Wed Sep 05, 2018 12:06 pm
by cfbsoftware
By definition leaf procedures cannot call procedures. However, you can call SYSTEM.PUT directly if you want to perform GPIO operations in a leaf procedure. e.g. the Error procedure in the DramTest example lights the red LED before going into an infinite loop.

Code: Select all

PROCEDURE Error();
BEGIN
  GPIO.Put(LEDRed, HIGH);
  WHILE TRUE DO END
END Error;
If this had to be made much more efficient it could be written as a leaf procedure:

Code: Select all

PROCEDURE* Error();
CONST
  GPIO_BSRR = 018H;
  LEDRedOn = {14};
BEGIN
  SYSTEM.PUT(MCU.GPIOBBase + GPIO_BSRR, LEDRedOn);
  WHILE TRUE DO END
END Error;
Although SYSTEM.PUT looks like a procedure, it, like most other SYSTEM functions, generate inline code so it can be used in leaf procedures.

Re: GPIO and leaf procedures

Posted: Wed Sep 05, 2018 12:16 pm
by steve64
Thanks, using PUT and GET in leaf procedures for critical code can be fine.