Is it possible to toggle a group of pins on J2 at once ?

Discussion to talk about software related topics only.
Post Reply
lnguyen
Posts: 6
Joined: Wed Sep 30, 2015 9:59 am

Is it possible to toggle a group of pins on J2 at once ?

Post by lnguyen »

I'm experimenting the MOD5234 pins class function for J2 . It's simple to set the logic for a pin on J2, after config its as a GPIO, then I know can do this

J2[n] = 0; or J2[n] = 1;

My question is it possible to do this for a group of 8 pins at once?
User avatar
dciliske
Posts: 623
Joined: Mon Feb 06, 2012 9:37 am
Location: San Diego, CA
Contact:

Re: Is it possible to toggle a group of pins on J2 at once ?

Post by dciliske »

Not using the Pins class. You'll need to directly access the register associated with one of the GPIO ports.

-Dan
Dan Ciliske
Project Engineer
Netburner, Inc
lnguyen
Posts: 6
Joined: Wed Sep 30, 2015 9:59 am

Re: Is it possible to toggle a group of pins on J2 at once ?

Post by lnguyen »

Thanks Dan,

Could that be related to the switching speed, which I'm trying to improve? Please advise,

For example, J2[36] idle state is high, and I have this code:

J2[36] = 0;
J2[36] = 1;

This generates a 2.68 uS pulse (active low) on the scope, which I think is quite slow,... would directly access the register also speed it up ?
rnixon
Posts: 833
Joined: Thu Apr 24, 2008 3:59 pm

Re: Is it possible to toggle a group of pins on J2 at once ?

Post by rnixon »

There's 3 levels of speed for toggling gpio, the 54415 platform has an example, but the concept is the same for any platform:
Pins Class, easiest but slowest
C code programming registers
Assembly code programming registers
lnguyen
Posts: 6
Joined: Wed Sep 30, 2015 9:59 am

Re: Is it possible to toggle a group of pins on J2 at once ?

Post by lnguyen »

rnixon wrote:There's 3 levels of speed for toggling gpio, the 54415 platform has an example, but the concept is the same for any platform:
Pins Class, easiest but slowest
C code programming registers
Assembly code programming registers
Oh yes,

It speeds up a great deal with registers setting, the 2.68 uS pulse is now 100 ns, my task now reduced to 5 sec, which used to be 1 min 15 sec

Thanks a lot, I think C-code is good enough at this point,.. and I've forgot almost everything about assembly :-)
User avatar
dciliske
Posts: 623
Joined: Mon Feb 06, 2012 9:37 am
Location: San Diego, CA
Contact:

Re: Is it possible to toggle a group of pins on J2 at once ?

Post by dciliske »

Ok. I've got to ask: WHAT ARE YOU BIT BANGING???!!! My math says that's ~25 Million bits.
Dan Ciliske
Project Engineer
Netburner, Inc
lnguyen
Posts: 6
Joined: Wed Sep 30, 2015 9:59 am

Re: Is it possible to toggle a group of pins on J2 at once ?

Post by lnguyen »

Hi Dciliske,

Srry for delay, it's been a while & we were busy in others stuff.

Yup you're right, I used the module ports to config a mid-scale FPGA. The actual configuration bits is only 8 Mb, but I've got to read it from flash and do the loading. So the over all loading time is about 5 sec. Another choice is to do the Byte-loading to speed it up, that was why I asked if it's possible to toggle 8 bits at once. But for now we are ok with this loading scheme
seulater
Posts: 445
Joined: Fri Apr 25, 2008 5:26 am

Re: Is it possible to toggle a group of pins on J2 at once ?

Post by seulater »

Since I did not see anyone directly answer you question, I thought I would.

In this folder C:\nburn\MOD5234\system you will find a file called pins.cpp.
This file will help you to bitbang pins faster than say doing:
J2[36] = 0;
J2[36] = 1;

The following will toglle pins much faster than the above.
So say you want to quickly toggle J2-36 look in that file for PinIO::set, and then look for the case number of the pin you want. You will first find the set which is:

case 36:
sim.gpio.ppdsdr_timer = 0x01;
sim.gpio.pddr_timer |= 0x01;

Then later down you will find the clear:

case 36:
sim.gpio.pclrr_timer = ~0x01;
sim.gpio.pddr_timer |= 0x01;


Now that you have that, you will first want to set the pin as an output, from these you will see that sim.gpio.pddr_timer |= 0x01; does this.
So in your main.cpp file one thing you must do before using that pin is simply add that line. Then next if you want to toggle the pin use what you found in the 2 case statemetns for set and clear of the pin. so in the end you will have the following.

#include <pins.h>
sim.gpio.pddr_timer |= 0x01; // Enable pin as GPIO as an output pin

main()
{
while(1)
{
sim.gpio.ppdsdr_timer = 0x01; // Sets Pin J2-36 high
sim.gpio.pclrr_timer = ~0x01; // Sets Pin J2-36 low
}

...
}

Or to make it more code readable later I define them like this.


#define myPinHigh sim.gpio.ppdsdr_timer = 0x01; // Sets Pin J2-36 high
#define myPinLow sim.gpio.pclrr_timer = ~0x01; // Sets Pin J2-36 low

while(1)
{
myPinHigh
myPinLow
}

Or if you want a one liner to toggle you can do this:
#define myPinToggle sim.gpio.ppdsdr_timer = 0x01; asm("NOP"); sim.gpio.pclrr_timer = ~0x01; asm("NOP"); sim.gpio.ppdsdr_timer = 0x01; // Toggle H,L,H. Do not need the nop if necessary.


while(1)
{
myPinToggle
}





Now for toggling a whole Byte of data you now need to look in the file C:\nburn\MOD5234\include\sim5235.h
in there you will find:
vubyte podr_datah; /* 0x10_0001 -> 0x10_0001 - PODR Data High */
vubyte podr_datal; /* 0x10_0002 -> 0x10_0002 - PODR Data Low */


First thing is to set it as output like so, you can use datal or datah, I will use datah for example.

sim.gpio.pddr_datah = 0xff; // set all pins as outputs.

Now you can set those pins as well to mimic a 8-bit data bus by

sim.gpio.podr_datah = x;

Dont forget to #include the sim5235.h file in your app or the sim stuff wont work.
Post Reply