1

I am learning ARM7-TDMI using NXP LPC2148.

While studying the reference manual, I came across these two functions - IOSET AND IOCLR , used to set and clear the port bits respectively,

As per the reference manual:

" This register controls the state of output pins in conjunction with the IOCLR register. Writing ones produces highs at the corresponding port pins. Writing zeroes has no effect"

Reading this I got curious as to why they had to define two different functions to do this? Wouldn't it take more memory? I mean they could have used IOSET and a single function where writing 1 produces high at pin while 0 produces low.

Additionally, why writing 0s to IOSET has no effect? I tried Googling this question but it is not explained anywhere.

Anybody got an explanation with respect to soft/hardware reasons?

Luffy
  • 65
  • 7

2 Answers2

1

The functionality is already possible by just writing the IO data output register. But to clear and set bits with it, you need a read-modify-write sequence. Sometimes you have IO pins that are controlled by different RTOS tasks, or interrupts, and it would mean to set output data register you have to always disable interrupts or scheduling so that the update happens atomically. With separate registers to set pins high and low you don't need to read anything, just control the bits you want high or low.

Justme
  • 147,557
  • 4
  • 113
  • 291
1

why they had to define two different functions to do this?

It allows for more atomic control of the bits. Alternative is that you need a read-modify-write sequence. You would need to use semaphores to make sure no other process gets in between your read and write. For the ARM7TMI this is possible but if you have multiple processor cores this gets a lot more complex as just disabling interrupts does not prevent another processor from getting in between you read and your write

Wouldn't it take more memory?

Yes, it use a bigger part of the memory map. But most CPUs/controllers take a big chunk out of the address map for all the I/O ports. A hundred more locations is noise in the whole design. (If you check you find that most I/O maps are very, very sparsely populated)

why writing 0s to IOSET has no effect?

As the register only sets bits, you need some sort of condition which bits to set and which bits to leave unmodified. The designers decided if you write has a '1' it sets the bit. Thus writing '0' leaves the bit the same.

If you are interested here is a diagram how it works in hardware. Maybe that is easier to understand.

For setting bits this is seen as logic by most users. It becomes more difficult if you want to clear a bit. Normally of you 'AND' with '0' the bit is cleared. So how, as a designer of the logic, should you make a 'bit clear' function. Does a '1' clear the bit or does a '0' clear the bit. I have always used the former in my designs

Oldfart
  • 14,380
  • 2
  • 16
  • 41