UM10850
All information provided in this document is subject to legal disclaimers.
© NXP B.V. 2016. All rights reserved.
User manual
Rev. 2.4 — 13 September 2016
115 of 464
NXP Semiconductors
UM10850
Chapter 9: LPC5410x General Purpose I/O (GPIO)
9.6.3 Masked I/O
A port’s MASK register defines which of its pins should be accessible in its MPORT
register. Zeroes in MASK enable the corresponding pins to be read from and written to
MPORT. Ones in MASK force a pin to read as 0 and its output bit to be unaffected by
writes to MPORT. When a port’s MASK register contains all zeros, its PORT and MPORT
registers operate identically for reading and writing.
Applications in which interrupts can result in Masked GPIO operation, or in task switching
among tasks that do Masked GPIO operation, must treat code that uses the Mask register
as a protected/restricted region. This can be done by interrupt disabling or by using a
semaphore.
The simpler way to protect a block of code that uses a MASK register is to disable
interrupts before setting the MASK register, and re-enable them after the last operation
that uses the MPORT or MASK register.
More efficiently, software can dedicate a semaphore to the MASK registers, and
set/capture the semaphore controlling exclusive use of the MASK registers before setting
the MASK registers, and release the semaphore after the last operation that uses the
MPORT or MASK registers.
9.6.4 Recommended practices
The following lists some recommended uses for using the GPIO port registers:
•
For initial setup after Reset or re-initialization, write the PORT registers.
•
To change the state of one pin, write a Byte Pin or Word Pin register.
•
To change the state of multiple pins at a time, write the SET and/or CLR registers.
•
To change the state of multiple pins in a tightly controlled environment like a software
state machine, consider using the NOT register. This can require less write operations
than SET and CLR.
•
To read the state of one pin, read a Byte Pin or Word Pin register.
•
To make a decision based on multiple pins, read and mask a PORT register.