Is there any way to pass port as the parameter to the function

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

Hi Guys,

 

I did not program AVR for years now and just think if it is possible to pass PORTx to the function and use it directly like in the ARM micros?

foo(GPIO_TypeDef *gpio, uint8_t pin, ....)

 

This topic has a solution.

Last Edited: Sun. Sep 17, 2017 - 06:42 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

First hit when Googling "AVR pass port as parameter to function": http://www.atmel.com/webdoc/avrl... .

 

HTH!

"He used to carry his guitar in a gunny sack, or sit beneath the tree by the railroad track. Oh the engineers would see him sitting in the shade, Strumming with the rhythm that the drivers made. People passing by, they would stop and say, "Oh, my, what that little country boy could play!" [Chuck Berry]

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

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

Thank you - yes I did not do my home work. 

 

Edit - late edit but I tried to find the excuse for my laziness but I have not found any :(

Last Edited: Sat. Sep 16, 2017 - 11:12 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Aaah -- another new fan of "generic I/O" on an AVR8.

 

Many threads on this.  A few months ago, there was at least once a week.

http://www.avrfreaks.net/comment...

http://www.avrfreaks.net/comment...

 

I'll drag out my tired old questions:

 

-- What makes this attractive to you?  Does the wiring of your app magically change during run time, so you need to make an elaborate setup to handle such morphing?

 

-- AVR8 instruction set doesn't lend itself well.  So instead of "direct" access taking a couple cycles with no RMW effects and no temporary registers needed, your favoured mechanism takes many cycles, needs intermediate registers, and can introduce RMW possibilities.

 

"You make the call."

http://operations.nfl.com/the-of...

 

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

Last Edited: Sat. Sep 16, 2017 - 11:53 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Not the new fan - porting one of my libraries to avr8 (I did not program them for a very long time, now use only Cortex ones). I know the downsides but do not want to rewrite the rest of the code.
 

Last Edited: Sun. Sep 17, 2017 - 12:14 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Next you'll decry how slow your library code is on AVR8.  And then we'll here about "non-working ports" which will be traced back to subtle RMW effects.

 

All that said -- go for it.  How hard could it be?  In the end you only set/clear a bit in an I/O register.  You should find examples here.  Did you follow all the links I gave to prior discussions?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

Meanwhile I have finished porting and started testing. It works as expected. I know the downsides and I am not going to complain about avr-s. Forced to use atmega as the controller is built in the device.
 

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

as the side effect of this project - any pattern LED blinking library with callbacks.

 

https://github.com/diymat/AVR/tr...