Gpio_out_xor

GPIO_REG(GPIO_IOF_SEL) |= ( (1 << GREEN_LED_OFFSET) | (1 << BLUE_LED_OFFSET) | (1 << RED_LED_OFFSET));
GPIO_REG(GPIO_IOF_EN ) |= ( (1 << GREEN_LED_OFFSET) | (1 << BLUE_LED_OFFSET) | (1 << RED_LED_OFFSET));
GPIO_REG(GPIO_OUTPUT_XOR) &= ~( (1 << GREEN_LED_OFFSET) | (1 << BLUE_LED_OFFSET));
GPIO_REG(GPIO_OUTPUT_XOR) |= (1 << RED_LED_OFFSET);

what does it mean? (last two lines) can some one explain?

Have you read chapter 11 of the E300 Platform Reference Manual? Although to be fair there isn’t a lot of tutorial material there. I guess it assumes familiarity with other microcontrollers.

I believe the GPIO_OUTPUT_XOR register should toggle any GPIO pin whose bit it set to 1 when a write is made to the register.

In which case those last two lines look like a bug. I don’t know what is supposed to happen if you read from that register. Maybe it should be:

GPIO_REG(GPIO_OUTPUT_XOR) =  (1 << GREEN_LED_OFFSET) | (1 << BLUE_LED_OFFSET);
GPIO_REG(GPIO_OUTPUT_XOR) = (1 << RED_LED_OFFSET);

Which could be combined into one assignment, after initial set up.

Yeah I read.yes i understood !Well ,the information was good and helpful and i feel that i should improve my understanding over micro controllers.Anyways thank you.

A lot of the ARM microcontrollers have individual “set” and “clear” registers that let you do things like…

GPIO_REG(GPIO_OUTPUT_CLEAR) =  (1 << GREEN_LED_OFFSET) | (1 << BLUE_LED_OFFSET);
GPIO_REG(GPIO_OUTPUT_SET) = (1 << RED_LED_OFFSET);

… to turn off the green and blue LED’s GPIOs and turn on the red LED’s GPIO without having to read the whole IO register to a CPU register, turn bits on and off, and write the new value back.

We don’t seem to have that, but I guess the XOR register will often allow the same kind of things, possibly even with slightly less code if you implicitly already know the previous state.
.

As opposed to reserving special differently-addressed memory regions for atomic set and clear of device bits (bit banding), the RISC-V amoor and amoand instructions allow you to set and clear bits in a memory-mapped device with a single instruction using the normal device address. Amoxor lets you toggle the bits as described by Bruce.

1 Like

great!

should we connect IOREF 3v or 5v J1 jumper to use the digital pins?
and if so, can i use F-F jumper wire instead? i dont have the jumper pin.

That depends what voltage peripherals you want to connect.

It doesn’t matter what kind of wire you use to connect the pins as long as there is electrical continuity.

Okay then.
Thank you Bruce.