[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] 32-bits time

From: David Kelly
Subject: Re: [avr-gcc-list] 32-bits time
Date: Thu, 13 Oct 2005 20:12:09 -0500

On Thu, Oct 13, 2005 at 09:10:17AM +0200, Bjarne Laursen wrote:

A few additions to David Kelly's code:

inline uint32_t timer32_now(void)
   int8_t sreg;
   union {
       struct {
           uint16_t lo, hi;
       } w;
       uint32_t l;
      uint8_t b[4]; // <------ added: access as bytes
   } temp;

Below is the way I usually do the above. Didn't have it under my mouse
last night:

typedef union {

    uint32_t u32;

    int32_t i32;

    struct {
        uint16_t lo, hi;
     } u16;

    struct {
        uint8_t lo;
        uint16_t mid;
        uint8_t hi;
     } hml;

    struct {
        uint8_t lo, b, c, hi;
    } u8;

    struct {
        int8_t lo, b, c, hi;
    } i8;

} union32_t;

Easy enough to hack into whatever shape desired. The idea is to use
named members of a union rather than type casting and shifting.

David Kelly N4HHE, address@hidden
Whom computers would destroy, they must first drive mad.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]