Declaration of bit using codeWarrior

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Declaration of bit using codeWarrior

ソリューションへジャンプ
1,643件の閲覧回数
mohamedmajdeb
Contributor II

Hello,

please can you tell me how to declare an array of bits in CodeWarrior?

Thanks.

1 解決策
1,146件の閲覧回数
egoodii
Senior Contributor III

'C', in any case, is NOT very 'friendly' to booleans represented as single bits, and even LESS helpful trying to work with a 'array of one-bit booleans' in a bits[x] access fashion.

BUT the Kinetis 'K' family has the ARM bit-banding hardware that DOES allow (the CPU-only!) read and write access to single-bits anywhere in upper-RAM space!  BUT I know of NO tools that are 'any help' in using this function.  Firstly, you have to make sure the array is allocated in UPPER ram (the half starting at 0x20000000).  In general, this means you have to 'make your own allocation' in space you steal from the linker.

So, say I take the top 4K away from the IDE tools (making the end-of-RAM in a 128Kram part 0x2000EFFF), and allocate myself some vars out there:

DIGOUT_bits   DIGOUT_map @ 0x2000F000u;   //Global storage of the current operational bits

Then a macro of this form will calculate the bit-band-alias address for that SRAM address:

    #define BITBAND_SRAM_A(Addr,Bit) (0x22000000u + (((uint32_t)(Addr) - (uint32_t)0x20000000u)<<5) + (((uint32_t)(Bit))<<2))

which you can use, for instance, with a pointer like this:

          uint32_t * offset;

         offset = (uint32_t *)BITBAND_SRAM_A(&DIGOUT_map,0);  //Convert to bit-band address, starting right at the LSB

         *offset = 1;

and pointer-math will allow you to index any other bits in that space.

         *(offset+3) = 3F;

The net-result of these two 'writes' is for 0x2000F000 to contain the byte 0x09.

The LSB is all you read or write, irrespective of the size of read or write performed.

Another way to get there is to pre-compute the bit-band address for the space you've carved out, and just allocate your 'booleans' out there (manually, of course!) for the compiler to address:

        static uint32_t bits[227] @ 0x221E0000u;   //Bit-band alias of 0x2000F000, occupies 28-3/8 bytes

                    ..or, alternative syntax: static uint32_t bits[227] @ BITBAND_SRAM_A(0x2000F000, 0);

        bits[7] = 1;

        printf(" %i %i %i\n",bits[0],bits[1],bits[2]);

        ......etc.

This is another case of a 'basic ARM function' for which the Kinetis documentation is 'terse' at best!  You have to go right to www.arm.com to fetch the operational documentation such as DDI0439C_cortex_m4_r0p1_trm.pdf section 3.7 "Bit-banding".

元の投稿で解決策を見る

6 返答(返信)
1,147件の閲覧回数
egoodii
Senior Contributor III

'C', in any case, is NOT very 'friendly' to booleans represented as single bits, and even LESS helpful trying to work with a 'array of one-bit booleans' in a bits[x] access fashion.

BUT the Kinetis 'K' family has the ARM bit-banding hardware that DOES allow (the CPU-only!) read and write access to single-bits anywhere in upper-RAM space!  BUT I know of NO tools that are 'any help' in using this function.  Firstly, you have to make sure the array is allocated in UPPER ram (the half starting at 0x20000000).  In general, this means you have to 'make your own allocation' in space you steal from the linker.

So, say I take the top 4K away from the IDE tools (making the end-of-RAM in a 128Kram part 0x2000EFFF), and allocate myself some vars out there:

DIGOUT_bits   DIGOUT_map @ 0x2000F000u;   //Global storage of the current operational bits

Then a macro of this form will calculate the bit-band-alias address for that SRAM address:

    #define BITBAND_SRAM_A(Addr,Bit) (0x22000000u + (((uint32_t)(Addr) - (uint32_t)0x20000000u)<<5) + (((uint32_t)(Bit))<<2))

which you can use, for instance, with a pointer like this:

          uint32_t * offset;

         offset = (uint32_t *)BITBAND_SRAM_A(&DIGOUT_map,0);  //Convert to bit-band address, starting right at the LSB

         *offset = 1;

and pointer-math will allow you to index any other bits in that space.

         *(offset+3) = 3F;

The net-result of these two 'writes' is for 0x2000F000 to contain the byte 0x09.

The LSB is all you read or write, irrespective of the size of read or write performed.

Another way to get there is to pre-compute the bit-band address for the space you've carved out, and just allocate your 'booleans' out there (manually, of course!) for the compiler to address:

        static uint32_t bits[227] @ 0x221E0000u;   //Bit-band alias of 0x2000F000, occupies 28-3/8 bytes

                    ..or, alternative syntax: static uint32_t bits[227] @ BITBAND_SRAM_A(0x2000F000, 0);

        bits[7] = 1;

        printf(" %i %i %i\n",bits[0],bits[1],bits[2]);

        ......etc.

This is another case of a 'basic ARM function' for which the Kinetis documentation is 'terse' at best!  You have to go right to www.arm.com to fetch the operational documentation such as DDI0439C_cortex_m4_r0p1_trm.pdf section 3.7 "Bit-banding".

1,146件の閲覧回数
guillaumetiffin
Contributor III

Hello Mohamed,

I think that your post is at the wrong place.

Then I didn't understand your question.

The declaration of an array of bits depends on the programmation language.

If you a programming in C, C++. If you use MQX or not  and so on...

If you give me more informations I may help you.

Regards,

Guillaume

1,146件の閲覧回数
hectorsanchez
Contributor IV

Moving the thread to the right place, thanks for your help Guillaume

0 件の賞賛
1,146件の閲覧回数
mohamedmajdeb
Contributor II

give me the right place :smileysad:
thank you

0 件の賞賛
1,146件の閲覧回数
hectorsanchez
Contributor IV

Hi Mohamed,

Did you fix your problem?

B.R.

Hector Sanchez

0 件の賞賛
1,146件の閲覧回数
mohamedmajdeb
Contributor II

Hi Hector
it's okay
thank you  :smileyhappy:   

0 件の賞賛