[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-libc-dev] RFC: avr/bits.h
From: |
Bob Paddock |
Subject: |
Re: [avr-libc-dev] RFC: avr/bits.h |
Date: |
Tue, 01 Mar 2005 13:15:53 -0500 |
User-agent: |
Opera M2/7.54u1 (Win32, build 3918) |
On Tue, 01 Mar 2005 10:00:13 -0700, E. Weddington <address@hidden> wrote:
Bob Paddock wrote:
I wanted to do a test case
Doing the test case right in the first place always help.
You can not us a BIT() inside of a bit_set(). :-(
Lets try a correct test case with your foo() added:
#include <inttypes.h>
#include <avr/io.h>
#include "bits.h"
uint16_t shorttest_u16 = (uint16_t) 0;
uint32_t longtest_u32 = (uint32_t) 0;
void foo(void);
void foo(void)
{
bit_set(PORTD, 3);
}
int main( void )
{
bit_set( shorttest_u16, 0 );
bit_set( shorttest_u16, 1 );
bit_set( shorttest_u16, 2 );
bit_set( shorttest_u16, 3 );
bit_set( shorttest_u16, 4 );
bit_set( shorttest_u16, 5 );
bit_set( shorttest_u16, 6 );
bit_set( shorttest_u16, 7 );
bit_set( shorttest_u16, 8 );
bit_set( shorttest_u16, 9 );
bit_set( shorttest_u16, 10 );
bit_set( shorttest_u16, 11 );
bit_set( shorttest_u16, 12 );
bit_set( shorttest_u16, 13 );
bit_set( shorttest_u16, 14 );
bit_set( shorttest_u16, 15 );
bit_set( longtest_u32, 0 );
bit_set( longtest_u32, 7 );
bit_set( longtest_u32, 8 );
bit_set( longtest_u32, 15 );
bit_set( longtest_u32, 16 );
bit_set( longtest_u32, 31 );
foo();
}
#define bit_32(x) ((uint32_t)1 << (x))
I used these:
#define BIT(bitpos) ((uint32_t)1<<(bitpos))
#define bit_set(var, bit) ((var) |= BIT(bit))
#define bit_clear(var, bit) ((var) &= ~BIT(bit))
#define bit_toggle(var, bit) ((var) ^= BIT(bit))
#define bit_read(var, bit) ((var) & BIT(bit))
All of the code lookes reasonable now that I don't
have recursive macros, even got the proper sbi for PORTD.
34 foo:
35 .LFB2:
36 .LM1:
37 /* prologue: frame size=0 */
38 /* prologue end (size=0) */
39 .LM2:
40 0000 939A sbi 50-0x20,3
41 /* epilogue: frame size=0 */
Is there some case where the construct ((uint32_t)1<<(bitpos))
is really going to promote to 32 bit code?
Re: [avr-libc-dev] RFC: avr/bits.h, Dave Hylands, 2005/03/01
Re: [avr-libc-dev] RFC: avr/bits.h, Joerg Wunsch, 2005/03/01
Re: [avr-libc-dev] RFC: avr/bits.h, Nicolas Schodet, 2005/03/01