ee_gary wrote:
>Hi everybody,
>
>I'm wondering what is the best way to set and clear I/O bits without
>keeping track of what port they are on. For example, something like:
>
>#define myOutput1 IO2PIN.1
>#define myOutput2 IO3PIN.28
>
>
>
As per ANSI C, define a MACRO, For example:
============= begin ===============
typedef struct
{
REG32 in0; // P0 Pin Value Register
REG32 set0; // P0 Pin Output Set Register
REG32 dir0; // P0 Pin Direction Register
REG32 clr0; // P0 Pin Output Clear Register
EG32 in1; // P1 Pin Value Register
REG32 set1; // P1 Pin Output Set Register
REG32 dir1; // P1 Pin Direction Register
REG32 clr1; // P1 Pin Output Clear Register
REG32 in2; // P2 Pin Value Register
REG32 set2; // P2 Pin Output Set Register
REG32 dir2; // P2 Pin Direction Register
REG32 clr2; // P2 Pin Output Clear Register
REG32 in3; // P3 Pin Value Register
REG32 set3; // P3 Pin Output Set Register
REG32 dir3; // P3 Pin Direction Register
REG32 clr3; // P3 Pin Output Clear Register
} gpioRegs_t;
#define GPIO1 ((gpioRegs_t *)0xE0028000)
#ifndef BIT
#define BIT(n) (1 << (n))
#endif
#define LED_EVENT_BIT BIT(20) // P1.20 output - low for EVENT LED.
#define IOPIN1 GPIO->in1 /* Pin Value Register */
#define IOSET1 GPIO->set1 /* Pin Output Set Register */
#define IODIR1 GPIO->dir1 /* Pin Direction Register */
#define IOCLR1 GPIO->clr1 /* Pin Output Clear Register */
============== THEN DO ====================
main () {
IOCLR1 = LED_EVENT_BIT;
IOSET1 = LED_EVENT_BIT;
}
============ OR ================
< the above defines>
static inline eventLedOff (void) { IOSET1 = LED_EVENT_BIT; }
static inline eventLedOn (void) { IOCLR1 = LED_EVENT_BIT; }
void main (void)
{
eventLedOn ();
eventLedOff ();
}
============ snip =====================
Making the function both static and inline will optimize (-O2 or -Os)
into inline assembly rather than a function call.
There are no "bitwise" functions in gcc such as set_bit(LED_EVENT_BIT)
or clear_bit(LED_EVENT_BIT), but you can write your own...
Regards,
TomW
--
Tom Walsh - WN3L - Embedded Systems Consultant
http://openhardware.net, http://cyberiansoftware.com
"Windows? No thanks, I have work to do..."
----------------------------------------------------Message
Re: [lpc2000] Bit set/clear w/ gcc
2006-01-07 by Tom Walsh
Attachments
- No local attachments were found for this message.