STM32F1 Programming Manual

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

Previous topic - Next topic

tha

2.3.4 Vector table

The vector table บรรจุ the reset value ของ the stack pointer, และ the start addresses, ที่เรียกว่า exception vectors อีกด้วย, สำหรับทุก exception handlers. Figure 12 บนหน้า 35 แสดงลำดับของ the exception vectors ใน the vector table. The least-significant bit ของแต่ละ vector ต้องเป็น 1, แสดงให้เห็นว่า the exception handler เป็น Thumb code.



เมื่อ system reset, the vector table ถูกคงที่ที่ address 0x00000000. Privileged software สามารถเขียนถึง the VTOR เพื่อย้าย the vector table start address ไปยัง a different memory location, ในช่วง 0x00000080 ถึง 0x3FFFFF80, ดู Vector table offset register (SCB_VTOR) บนหน้า 133.

tha

2.3.5 Exception priorities

ตาม Table 16 บนหน้า 33 แสดง, ทุก exceptions มี an associated priority, พร้อมด้วย:
•   A lower priority value แสดงให้เห็น a higher priority
•   Configurable priorities สำหรับทุก exceptions ยกเว้น Reset, Hard fault, และ NMI.

ถ้า software ไม่กำหนดค่า priorities ใดๆ, ดังนั้นทุกl exceptions ที่มี a configurable priority จะมี a priority of 0. สำหรับข้อมูลเกี่ยวกับการกำหนดค่า exception priorities ดู
•   System handler priority registers (SHPRx) บนหน้า 138
•   Interrupt priority registers (NVIC_IPRx) บนหน้า 125

Configurable priority values อยู่ในช่วง 0-15. นี้หมายความว่า the Reset, Hard fault, และ NMI exceptions, ที่มี fixed negative priority values, จะมี priority สูงกว่า exception อื่นใดๆเสมอ.

tha

ตัวอย่างเช่น, การกำหนด a higher priority value ให้กับ IRQ[0] และ a lower priority value ให้กับ IRQ[1] หมายความว่า IRQ[1] มี priority สูงกว่า IRQ[0]. ถ้าทั้ง IRQ[1] และ IRQ[0] ถูกยืนยัน, IRQ[1] จะถูกประมวลผลก่อน IRQ[0].

ถ้าหลาย pending exceptions มี the same priority, the pending exception ที่มี the lowest exception number จะได้รับการประมวลผล. ตัวอย่างเช่น, ถ้าทั้ง IRQ[0] และ IRQ[1] กำลัง pending และมี the same priority, ดังนั้น IRQ[0] จะถูกประมวลผลก่อน IRQ[1].

เมื่อ the processor กำลังปฏิบัติ an exception handler, the exception handler จะถูกยึดไว้ใช้สิทธิ์ทำงานก่อนถ้า a higher priority exception เกิดขึ้น. ถ้า an exception ที่เกิดขึ้นมี the same priority กับ the exception ที่กำลังถูกจัดการ, the handler จะไม่ถูกยึดไว้ใช้สิทธิ์ทำงานก่อน, โดยไม่คำนึงถึง the exception number. อย่างไรก็ตาม, สถานะของ the new interrupt จะเปลี่ยนไปเป็น pending.


tha

2.3.6 Interrupt priority grouping

เพื่อเพิ่ม priority control ใน systems ที่มี interrupts, the NVIC รองรับ priority grouping. นี้จะแบ่งแต่ละ interrupt priority register entry ลงในสอง fields:
•   An upper field ที่กำหนด the group priority
•   A lower field ที่กำหนด a subpriority ภายใน the group.

มีเพียง the group priority ที่ตัดสิน preemption of interrupt exceptions. เมื่อ the processor กำลังปฏิบัติ an interrupt exception handler, interrupt อื่นอีกตัวที่มี the same group priority กับ the interrupt ที่กำลังถูกปฏิบัติจะไม่ถูกยึดไว้ใช้สิทธิ์ทำงานก่อน the handler,

ถ้าหลาย pending interrupts มี the same group priority, the subpriority field จะตัดสินลำดับที่พวกมันจะถูกประมวลผล. ถ้าหลาย pending interrupts มี the same group priority and subpriority, the interrupt ที่มี the lowest IRQ number จะถูกประมวลผลก่อน.

สำหรับข้อมูลเกี่ยวกับการแบ่ง the interrupt priority fields ลงใน group priority and subpriority, ดู Application interrupt and reset control register (SCB_AIRCR) บนหน้า 134.

tha

2.3.7 Exception entry and return

คำอธิบายของ exception handling ใช้ข้อกำหนดต่อไปนี้:

Preemption                   เมื่อ the processor กำลังปฏิบัติ an exception handler, an exception สามารถยึดไว้ใช้สิทธิ์ทำงาน
                                       ก่อน the exception handler ถ้า priority ของมันสูงกว่า the priority ของ the exception ที่กำลัง
                                       ถูกจัดการ. ดู Section 2.3.6: Interrupt priority grouping สำหรับข้อมูลเพิ่มเติมเกี่ยวกับ
                                       preemption โดย an interrupt.
                                       เมื่อ exception ตัวหนึ่งยึดไว้ใช้สิทธิ์ทำงานก่อน exception อื่นอีกตัวหนึ่ง, the exceptions จะถูกเรียก
                                       ว่า nested exceptions. ดู Exception entry บนหน้า 37 ข้อมูลเพิ่มเติม.
Return                          สิ่งนี้เกิดขึ้นเมื่อ the exception handler เสร็จสมบูรณ์, และ:
                                        •   ไม่มี pending exception ที่มี sufficient priority ที่จะถูกบริการ
                                        •   The completed exception handler ไม่ได้จัดการ a late-arriving exception.
                                        the processor pops the stack และกู้คืน the processor state กลับสู่ the state เดิมก่อน the
                                        interrupt เกิดขึ้น. ดู Exception return บนหน้า 38 สำหรับข้อมูลเพิ่มเติม.
Tail-chaining                  กลไกนี้ช่วยเร่งความเร็ว exception servicing. เมื่อเสร็จสมบูรณ์ an exception handler, ถ้ามี a
                                        pending exception ที่ตรงตามข้อกำหนดสำหรับ exception entry, the stack pop จะถูกข้ามไปและ
                                        ควบคุมการส่งถ่ายไปยัง the new exception handler.
Late-arriving                 กลไกนี้เร่งความเร็ว preemption. ถ้า a higher priority exception เกิดขึ้นในระหว่าง state saving
                                       สำหรับ a previous exception, the processor จะสลับไปจัดการ the higher priority exception
                                       และเริ่มต้น the vector fetch สำหรับ exception นั้น. State saving จะไม่ได้รับผลกระทบจาก late
                                       arrival เนื่องจาก the state saved เป็นเหมือนกันสำหรับทั้งสอง exceptions. ดังนั้น the state
                                       saving จะดำเนินต่อไปโดยไม่หยุดชะงัก. The processor สามารถยอมรับ a late arriving exception
                                       จนกระทั่ง the first instruction ของ the exception handler ของ the original exception เข้าสู่
                                       the execute stage ของ the processor. เมื่อ return จาก the exception handler ของ the late-
                                       arriving exception, the normal tail-chaining rules apply(ประยุกต์ใช้).

tha

Exception entry(การเข้าสู่)

Exception entry เกิดขึ้นเมื่อมี a pending exception ที่มี sufficient priority และอย่างใดอย่างหนึ่ง:
•   The processor อยู่ใน Thread mode
•   The new exception มี priority สูงกว่า the exception ที่กำลังถูกจัดการ, ซึ่งในกรณีนี้ the new exception ยึดไว้ใช้สิทธิ์ทำงานก่อน the original exception.

เมื่อ exception หนึ่งยึดไว้ใช้สิทธิ์ทำงานก่อน exception อื่นอีกตัวหนึ่ง, the exceptions จะซ้อนกัน.

Sufficient priority หมายถึง the exception มี priority มากกว่าขีดจำกัดใดๆที่เซ็ตโดย the mask registers, ดู Exception mask registers บนหน้า 19. An exception ที่มี priority น้อยกว่านี้อยู่ระหว่างรอดำเนินการแต่จะไม่ถูกจัดการโดย the processor.

เมื่อ the processor ได้รับ an exception, ยกเว้น the exception เป็น a tail-chained หรือ a late-arriving exception, the processor จะใส่(pushes) information ลงบน the current stack. การดำเนินการนี้ถูกเรียกว่า stacking และ the structure ของ eight data words ถูกเรียกว่า stack frame. The stack frame บรรจุ the following information:
•   R0-R3, R12
•   Return address
•   PSR
•   LR.

tha

ทันทีหลังจาก stacking, the stack pointer จะระบุ the lowest address ใน the stack frame. ยกเว้น stack alignment ถูกปิดใช้งาน, the stack frame ถูกจัดแถวเป็น a double-word address. ถ้า the STKALIGN bit ของ the Configuration Control Register (CCR) ถูกเซ็ตเป็น 1, stack align adjustment จะถูกดำเนินการในระหว่าง stacking.

The stack frame รวมเอาไว้ the return address. นี้คือ the address ของ the next instruction ในโปรแกรมที่ถูกอินเตอรฺรัพท์. ค่านี้จะถูกกู้คืนไปยัง the PC ที่ exception return เพื่อว่าโปรแกรมที่ถูกอินเตอรฺรัพท์จะกลับมาทำงานต่อ.

tha

ควบคู่ไปกับ the stacking operation, the processor กระทำ a vector fetch ที่อ่าน the exception handler start address จาก the vector table. เมื่อ stacking เสร็จสมบูรณ์, the processor สตาร์ทการปฏิบัติ the exception handler. ในเวลาเดียวกัน, the processor จะเขียน an EXC_RETURN value ไปยัง the LR. นี้ระบุซึ่ง stack pointer ตรงกันกับ the stack frame และ operation mode อะไรที่ the processor เคยอยู่ในนั้นก่อน the entry จะเกิดขึ้น.

ถ้าไม่มี higher priority exception เกิดขึ้นในระหว่าง exception entry, the processor สตาร์ทการปฏิบัติ the exception handler และเปลี่ยนโดยอัตโนมัติสถานะของ the corresponding pending interrupt ไปเป็น active

ถ้า higher priority exception อื่นอีกตัวหนึ่งเกิดขึ้นในระหว่าง exception entry, the processor สตาร์ทการปฏิบัติ the exception handler สำหรับ exception นี้และไม่เปลี่ยน the pending status ของ the earlier exception. นี้คือ the late arrival case.