My base: Can be under the existing C program to make some changes, will not be transplanted, will not write the driver, it is difficult to write the program from start to finish.
Rt-thread Foundation: Before looking at a little rtthread_manual.zh.pdf (that is, Rt-thread user manual), found very ugly understand, only understand some basic knowledge, such as thread scheduling approximate meaning. Decide to go directly to the program, do not understand the back to read the manual.
1. Using the rt-thread1.2.1 version, open the program found in the project directory there are many groups, not to control it, directly look at the applications group, there are two. c files, respectively, APPLICATION.C and STARTUP.C.
The preliminary judgment Startup.c's function is the system initialization and the initiation, but the APPLICATION.C function is realizes the user specific function request .
2. Enter the Startup.c file, which contains three header files, two sub-functions, and a main function.
int main (void)
{
/* Disable Interrupt First */
Rt_hw_interrupt_disable ();
/* Startup Rt-thread RTOS */
Rtthread_startup ();
return 0;
}
3. About Rt_hw_interrupt_disable ();
F12 rt_hw_interrupt_disable (); Tracking is not over, so use Find in files to trace to Context_rvds. s file has such a paragraph
;/*
; * rt_base_t rt_hw_interrupt_disable ();
; */
Rt_hw_interrupt_disable PROC
EXPORT rt_hw_interrupt_disable
MRS R0, Primask
Cpsid I
BX LR
Endp
The ①proc and ENDP were used together, indicating a subroutine.
②export, which means that the variables used in this program are provided to other modules for invocation. IMPORT, defined to indicate that this is a label of an external variable, not defined in this program.
③mrs:move to register the contents of the status register to the general register from the State register. Msr:move to state register the from register transmits the contents of the universal register to the status register.
④ "Cpsid i" for CORTEX-M3 is the assembly instruction to shut down the interrupt, you can see the cortex-m3 authoritative guide
The function of ⑤bx LR is equivalent to the Mov pc,lr that jumps to the address stored in the LR. So what address is LR storing? LR is the connection register (link register, LR), there are two special uses of LR in the ARM architecture: one is to save the subroutine return address, and the other is that when the exception occurs, the value saved in LR equals the value of the PC minus 4 (or minus 2) when the exception occurs. Therefore, in various exception modes, the value of LR can be returned to the appropriate location before the exception occurs. When a subroutine is called through the BL or BLX instruction, the hardware automatically saves the subroutine return address in the R14 register. When the subroutine returns, the value of LR is copied to the program counter PC to enable the subroutine to return.
All in all, rt_hw_interrupt_disable (), is to shut down the global interruption use, can not go to the drill. As for why the global interrupt is closed at the beginning of the program, it is because you want the initialization to be complete, the initialization is not completed, the interruption can cause errors, let's think of it.
2015-07-20
Rt-thread Study Notes (i)