STM32F1 Programming Manual

Started by tha, January 16, 2021, 06:11:52 AM

Previous topic - Next topic

tha

2.2.5 Bit-banding

A bit-band region แมปแต่ละ word ใน a bit-band alias region เข้ากับ a single bit ใน the bit-band region. The bit-band regions ครอบครอง the lowest 1 MB of the SRAM และ peripheral memory regions.

The memory map มี two 32 MB alias regions ที่แมปถึง two 1 MB bit-band regions:
•   เข้าถึง the 32 MB SRAM alias region จะแมปถึง the 1 MB SRAM bit-band region, ดังแสดงในตาราง 13
•   เข้าถึง the 32 MB peripheral alias region จะแมปถึง the 1 MB peripheral bit-band region, ดังแสดงในตาราง 14.

tha

A word เข้าถึง the SRAM หรือ peripheral bit-band alias regions จะแมปถึง a single bit ใน the SRAM หรือ peripheral bit-band region.

สมการต่อไปนี้แสดงวิธีที่ the alias region แมปไปบน the bit-band region:

bit_word_offset = (byte_offset x 32) + (bit_number x 4)

bit_word_addr = bit_band_base + bit_word_offset

ที่:
•   Bit_word_offset คือตำแหน่งของ the target bit ใน the bit-band memory region.
•   Bit_word_addr คือ the address of the word ใน the alias memory region ที่แมปถึง the targeted bit.
•   Bit_band_base คือ the starting address of the alias region.
•   Byte_offset คือจำนวนของ the byte ใน the bit-band region ที่บรรจุ the targeted bit.
•   Bit_number คือ the bit position, 0-7, ของ the targeted bit.

tha

Figure 10 บนหน้า 29 แสดงตัวอย่างของ bit-band mapping ระหว่าง the SRAM bit-band alias region และ the SRAM bit-band region:
•   The alias word ที่ 0x23FFFFE0 แมปถึง bit[0] ของ the bit-band byte ที่ 0x200FFFFF:
     0x23FFFFE0 = 0x22000000 + (0xFFFFF*32) + (0*4).
•   The alias word ที่ 0x23FFFFFC แมปถึง bit[7] ของ the bit-band byte ที่ 0x200FFFFF:
     0x23FFFFFC = 0x22000000 + (0xFFFFF*32) + (7*4).
•   The alias word ที่ 0x22000000 แมปถึง bit[0] ของ the bit-band byte ที่ 0x20000000:
     0x22000000 = 0x22000000 + (0*32) + (0 *4).
•   The alias word ที่ 0x2200001C แมปถึง bit[7] ของ the bit-band byte ที่ 0x20000000:
     0x2200001C = 0x22000000+ (0*32) + (7*4).



tha

การเข้าถึงโดยตรง an alias region
การเขียนถึง a word ใน the alias region จะอัฟเดต a single bit ใน the bit-band region.

Bit[0] ของ the value ที่เขียนถึง a word ใน the alias region กำหนด the value ที่เขียนถึง the targeted bit ใน the bit-band region. การเขียน a value ด้วย bit[0] เซ็ตเป็น 1 จะเขียน a 1 ไปยัง the bit-band bit, และการเขียน a value ด้วย bit[0] เซ็ตเป็น 0 จะเขียน a 0 ไปยัง the bit-band bit.

Bits[31:1] ของ the alias word ไม่มีผลต่อ the bit-band bit. การเขียน 0x01 มีผลเดียวกันกับการเขียน 0xFF. การเขียน 0x00 มีผลเดียวกันกับการเขียน 0x0E.

การอ่าน a word ใน the alias region:
•   0x00000000 แสดงให้เห็นว่า the targeted bit ใน the bit-band region ถูกเซ็ตเป็น 0
•   0x00000001 แสดงให้เห็นว่า the targeted bit ใน the bit-band region ถูกเซ็ตเป็น 1

การเข้าถึงโดยตรง a bit-band region
Behavior of memory accesses บนหน้า 26 อธิบายลักษณะการทำงานของ direct byte, halfword, or word เข้าถึงไปยัง the bit-band regions.

tha

2.2.6 Memory endianness

The processor ดู memory เป็น a linear collection of bytes ที่ตัวเลขเรียงลำดับจากน้อยไปหามากจากศูนย์ . ตัวอย่างเช่น, bytes 0-3 ถือ the first stored word, และ bytes 4-7 ถือ the second stored word.

Little-endian format

ใน little-endian format, the processor เก็บ the least significant byte ของ a word ที่ the lowest-numbered byte, และ the most significant byte ที่ the highest-numbered byte. ดู Figure 11 สำหรับตัวอย่าง.


tha

2.2.7 Synchronization primitives

The Cortex-M3 instruction set รวมคู่ของ synchronization primitives ไว้. เหล่านี้จัดให้มี a non-blocking mechanism ที่ a thread หรือ process สามารถใช้เพื่อให้ได้ exclusive access ไปยัง a memory location. Software สามารถใช้พวกมันเพื่อดำเนินการ a guaranteed read-modify-write memory update sequence, หรือสำหรับ a semaphore mechanism.

A pair of synchronization primitives ประกอบด้วย:

A Load-Exclusive instruction           ใช้อ่านค่าของ a memory location, โดยร้องขอ exclusive access ไปยัง location นั้น.

A Store-Exclusive instruction          ใช้เพื่อพยายามเขียนไปยัง the same memory location, ส่งคืน a status bit ไปยัง a
                                                             register. หากบิตนี้คือ:
                                                               0: มันแสดงให้เห็นว่า the thread หรือ process ได้รับ exclusive access ไปยัง
                                                                   the memory, และการเขียนประสบความสำเร็จ
                                                               1: มันแสดงให้เห็นว่า the thread หรือ process ไม่ได้รับ exclusive access ไปยัง
                                                                   the memory, และไม่มีการเขียนถูกดำเนินการ

The pairs of Load-Exclusive and Store-Exclusive instructions คือ:
•   The word instructions LDREX and STREX
•   The halfword instructions LDREXH and STREXH
•   The byte instructions LDREXB and STREXB.

Software ต้องใช้ a Load-Exclusive instruction กับ the corresponding Store-Exclusive instruction.

tha

เพื่อดำเนินการ a guaranteed read-modify-write ของ a memory location, software ต้อง:
1.   ใช้ a Load-Exclusive instruction เพื่ออ่านค่าของ the location.
2.   อัฟเดตค่า, ตามที่ต้องการ.
3.   ใช้ a Store-Exclusive instruction เพื่อพยายามเขียน the new value กลับไปยัง the memory location, และทดสอบ the
      returned status bit. หากบิตนี้คือ:
           0:   The read-modify-write สำเร็จเสร็จสมบูรณ์,
           1:   ไม่มีการเขียนถูกดำเนินการ. นี้แสดงให้เห็นว่า the value ที่ส่งคืนกลับที่ step 1 อาจล้าสมัย. The software ต้องพยายาม the
                  read-modify-write sequence ใหม่อีกครั้ง,

tha

Software สามารถใช้ the synchronization primitives เพื่อจัดให้มีใช้ a semaphores ดังต่อไปนี้:
1.  ใช้ a Load-Exclusive instruction เพื่ออ่านจาก the semaphore address เพื่อเช็คว่า the semaphore เป็นอิสระแล้วหรือยัง.
2.   ถ้า the semaphore เป็นอิสระ, ใช้ a Store-Exclusive เพื่อเขียน the claim value ไปยัง the semaphore address.
3.   ถ้า the returned status bit จาก step 2 แสดงให้เห็นว่า the Store-Exclusive ประสพความสำเร็จดังนั้น the software ได้อ้างสิทธิ์
      the semaphore. อย่างไรก็ตาม, ถ้า the Store-Exclusive ประสพความล้มเหลว,  process อีกงานหนึ่งอาจอ้างสิทธิ์ the
      semaphore หลังจาก the software ดำเนินการ step 1.