Skip to content

Commit

Permalink
Changes:
Browse files Browse the repository at this point in the history
-Bugfix: Raspi WriteRegister fault when address |= (value<<shift)

New:
-
  • Loading branch information
pi authored and pi committed Jul 10, 2014
1 parent d7136ae commit 997381e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
4 changes: 2 additions & 2 deletions bananaIO/src/Gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ int ReadPinValue(int pin) {

void WritePinValue(int pin, int value) {
if(value == LOW)
WriteRegister(CurrentSoc.Register.GpioClear, pin, 1, GPIO_PIN_CLEAR_VALUE);
WriteRegister(CurrentSoc.Register.GpioClear, pin, GPIO_PIN_CLEAR_MASK, GPIO_PIN_CLEAR_VALUE);
else
WriteRegister(CurrentSoc.Register.GpioSet, pin, 1, GPIO_PIN_SET_VALUE);
WriteRegister(CurrentSoc.Register.GpioSet, pin, GPIO_PIN_SET_MASK, GPIO_PIN_SET_VALUE);
}

int digitalRead(int pin)
Expand Down
3 changes: 3 additions & 0 deletions bananaIO/src/RaspberryPi.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
extern "C" {
#endif

#define GPIO_PIN_CLEAR_MASK 0xFFFFFFFF
#define GPIO_PIN_CLEAR_VALUE 1

#define GPIO_PIN_SET_MASK 0xFFFFFFFF
#define GPIO_PIN_SET_VALUE 1

#define SOC_REGISTER_PAGE_SIZE 4096
Expand Down
26 changes: 12 additions & 14 deletions bananaIO/src/Register.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct Register *NewRegister(volatile uint32_t *mappedMemory, int portRegister,
result->PinsPerPort = SOC_REGISTER_BLOCKSIZE * registerCount * result->PinsPerRegister;

result->mappedMemory = mappedMemory;

return result;

}
Expand All @@ -33,19 +33,17 @@ void WriteRegister(struct Register *reg, int pin, int resetMask, int value) {
int registerOffset = pin % reg->PinsPerPort / reg->PinsPerRegister; // debug
int offset = portOffset + (reg->PortRegister / SOC_REGISTER_BLOCKSIZE) + registerOffset;

int val;

val = *(reg->mappedMemory + offset); // debug
*(reg->mappedMemory + offset) &= ~(resetMask << shift);
val = *(reg->mappedMemory + offset); // debug
*(reg->mappedMemory + offset) |= (value << shift);
val = *(reg->mappedMemory + offset); // debug


if (resetMask == -1)
*(reg->mappedMemory + offset) = (value << shift); // just set value into address. Raspi Set Register!?
else
{
*(reg->mappedMemory + offset) &= ~(resetMask << shift); // mask
*(reg->mappedMemory + offset) |= (value << shift); // and set
}

}

void SetRegisterBit(struct Register *reg, int pin)
{
void SetRegisterBit(struct Register *reg, int pin) {
int shift = (pin % reg->PinsPerRegister) * reg->BitsPerPin;
int port = pin / reg->PinsPerPort; // debug
int portOffset = port * (SOC_REGISTER_PORT_SIZE / SOC_REGISTER_BYTE_PER_REGISTER); // debug
Expand Down Expand Up @@ -105,9 +103,9 @@ void WriteRegister(struct Register *reg, int pin, int resetMask, int value) {
int val;
val = *(reg->mappedMemory + offset); // debug
*(reg->mappedMemory + offset) &= ~(resetMask << shift);
*(reg->mappedMemory + offset) &= ~(resetMask << shift);
val = *(reg->mappedMemory + offset); // debug
*(reg->mappedMemory + offset) |= (value << shift);
*(reg->mappedMemory + offset) |= (value << shift);
val = *(reg->mappedMemory + offset); // debug
Expand Down
2 changes: 1 addition & 1 deletion bananaIO/src/SocConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
extern "C" {
#endif

#define BANANE 1
//#define BANANE 1


#ifdef __cplusplus
Expand Down

0 comments on commit 997381e

Please sign in to comment.