FMUSER Wirless Transmit Video And Audio More Easier !

[email protected] WhatsApp +8618078869184
Language

    51 microcontroller transplantation of μC / OS-II real-time operating system

     

    " μ C / OS-II is an embedded development system with open source code, compact structure and deprivable real-time kernel. The code is short, clear, real-time and high security performance. Most of the code is written in C and has been transplanted to a variety of processor architectures. With the increasing abundance of on-chip resources of 51 single chip microcomputer, it is transplanted on 51 single chip microcomputer μ C / OS-II has become possible. After the system is implanted, the system manages software and hardware resources, simplifies the design of application programs, and makes the functions of application systems more perfect. Therefore, it is transplanted on 51 single chip microcomputer μ C / OS-II is of great significance. one μ Overview of C / OS real-time operating system μ C / OS-II real-time operating system is a multi task real-time kernel that can be transplanted, solidified, cut and deprived. It is suitable for all kinds of microprocessors and microcontrollers. μ C / OS-II mainly includes task scheduling, time management, memory management and event management (semaphore, mailbox and message queue). Its migration is related to four files: assembly file (OS)_ CPU_ A. A SM), processor related C files (OS)_ CPU.H、OS_ CPU_ C. C) and profile (OS)_ CFG.H)。 There are 64 priorities, and the system occupies 8. Users can create 56 tasks, and time slice rotation is not supported. Its basic idea is to "approximately keep the highest priority ready task running all the time". In order to ensure this, it always executes the scheduling algorithm when calling the system function, ending the interrupt and ending the timed interrupt. The original author simplified the computation by calculating the data in advance, and made the delay predictable by carefully designing the structure of the ready table. Task switching is realized by simulating an interrupt. 2 implementation principle of task scheduling Task scheduling is μ The important part of C / OS-II is closely related to the specific microprocessor. Four of the five functions that must be migrated are task related. Task scheduling is to save the register and PC pointer of the current task (i.e. the breakpoint of the current task), then return the register value of the task to be executed to the register and point the PC to the breakpoint of the task to be executed. The implementation of these needs the help of stack and interrupt. For simplicity, first look at the use of stack during function call. When a function is called, an important function of the stack is to save the breakpoint address of the called function. If there are four functions, fun1 calls fun2, fun2 calls fun3, fun3 calls FUN4, and FUN4 is a leaf program (no subroutine call). Suppose you run from fun1 to FUN4, and the stack structure is shown in Figure 1, with add in the middle_ A to add_ D is the data in the stack, SP to sp-7 on the left are the stack pointers, and fun1 to FUN4 on the right are the corresponding calling functions. When running FUN4, the value stored in SP and SP-1 is add_ D. And add_ D is the address of the next line of FUN4 in fun3, that is, the address of lines 3-2 in fun3, and so on, add_ C is the address of line 2-2, add_ B Figure 1 function operation and stack structure are 1-2 line addresses. When function a calls function B, the breakpoint address of function a will be pressed on the stack when entering function B. when function B runs, the breakpoint address of function a in the stack will be popped up to the PC pointer, and the program will then run from the breakpoint of function a. If you change the data in SP and SP-1 in function B, function B will not return to function a at the end of operation, but return to the address represented by the changed data of SP and SP-1. The above is the basic situation during function call. If it is an interrupt, the stack will not only save the breakpoint address, but also automatically save the value of the register. Task scheduling is realized by interrupt. The breakpoint address saved in the interrupt is the breakpoint address of the task. When the task is to be executed again, assign the breakpoint address to the PC, and then the task can be executed in sequence when the task is interrupted. 3. Header file migration Among the four files related to migration, there are two header files. The migration of these two header files is relatively simple. You can refer to other migration procedures. Where OS_ CPU. H mainly includes the definition of data type, stack growth direction, switch interrupt and macro definition of function level task switching. OS_ CFG. H mainly includes the number of tasks, priority levels, events, interrupt beats per second and the enabling definitions of various system functions. 4. Transplantation of assembly and C files There are 14 functions in the two files of assembly and C to be transplanted, of which 9 are interface functions, which can be determined according to actual needs, and 5 must be written. The five functions are: OS_ CPU_ C. Ostaskstkinit() and OS in C file_ CPU_ A. Osstarthighrdy(), osctxsw(), osintctxsw() and ostickisr() in ASM files. The following is a specific analysis of these five functions. 4.1 task stack initialization function ostaskstkinit() This function is called in the task creation function OSTaskCreat () or OSTaskCreatExt (). Because the system applies for an array as a stack for each task, when a task runs, the stack pointer points to the stack of the task. The task stack initialization function initializes the stack of the task to be created when the task is created. However, the stack pointer SP of C51 is 8 bits and can only be addressed within 256 bytes of on-chip RAM. Due to its limited addressing space and unique SP, the stack cannot be defined for each program or mode like DSP or arm, and the stack space needs to be carefully managed. In order to adapt to the above situation, we need to change our thinking. Instead of letting SP point to each task stack space, we need to copy the contents of each task stack space to the system stack. As for how large the stack array space should be and what content should be put in the stack array space, we can learn from the stack pressing of interrupt function in keil. When the interrupt function does not specify a register group, the compiler generally puts PC, ACC, B, dptr, PSW and R0 ~ R7 registers on the stack, where PC and dptr are double bytes and others are single bytes, a total of 15 bytes, Therefore, the stack array is designed to be at least 15 bytes to ensure that the registers used by the task are contained in the stack array. Because the values of registers are placed in each array, the stack array of each task is called register array. For the time being, the register array is designed into 15 bytes to store PC, ACC, B, dptr, PSW, R0 ~ R7 in turn. The function ostaskstkinit() passes four parameters. The first parameter task is the starting address of the created task. This parameter must be saved to the corresponding position of PC in the register array. The second parameter ppdata is the parameter of the created task. In C51 rule, R1 ~ R3 are used to pass the parameter pointer, and this parameter must be saved to the corresponding position of R1 ~ R3 in the register array. The third parameter PTOs is the stack bottom pointer, which initializes the stack pointer from the current address, and the fourth parameter opt is an additional parameter, which is generally not used. 4.2 run the highest priority task function osstarthighrdy() in the waiting task This function is called on the last line of the startup operating system function osstart(), and this function does not return. After passing this function μ C / OS takes over the system. Instead of calling the user task function, osstarthighrdy() makes the PC pointer point to the first address of the task function. And there is only one transfer parameter of the task function. If this parameter is correct, the task function can be guaranteed to run correctly. Before calling osstarthighrdy(), osstart() has prepared the task table of the highest priority task. Just restore the data of the highest priority task table to the stack and execute the return instruction. The most important thing is how to return it to the highest priority task instead of the called function. When the function osstart() calls the function osstarthighrdy(), the breakpoint address is stacked; After osstarthighrdy() is executed, the breakpoint is returned. In osstarthighrdy(), change the values of SP and SP-1 to the address of the highest priority task, so that osstarthighrdy() will return to the highest priority task to run. 4.3 task switching function osctxsw () This function saves the state of the current task, and then runs the highest priority task in the ready state. As mentioned earlier, instead of changing the SP to point to the register array, the number of register arrays is copied to the stack. First look at the general situation, call OSSched () in user task MyTask (void*ppdtat), call TImeDly (), TImeDly (), and have a macro OS_ in OSSched (). TASK_ Sw(), the purpose of this macro is to let the program enter the function osctxsw(). As shown in Figure 1, FUN4 is osctxsw(), fun3 is osschemd(), fun2 is timedly(), and fun1 is mytask(). ADD_ D stores the breakpoint of ossched(), add_ C is the breakpoint of timedly(), add_ B is the breakpoint of mytask(). If task switching is performed, the address value of the high priority task should be assigned to add_ B (i.e. SP-4 and SP-5). The above consideration is the simplest case. When the task is complex, the values of ACC, PSW, dptr or R0 ~ R7 may be changed. When entering the high priority task, the register is not the register value of the task, and the operation result may be incorrect. In the above case, there are two stages to ensure the correct value of the CPU register. The first stage is to save the CPU register value to the register array of the task to be suspended. When osctxsw() is just entered, the CPU register value is the register value of the task to be suspended, so the CPU register value should be locked at the beginning. If OS_ TASK_ If sw() is defined as interrupt, the value of CPU register will be automatically pressed on the stack when entering osctxsw(); If the OS_ TASK_ When SW () is defined as a function, the embedded assembly method is used to stack the CPU register when entering the function. At this time, 13 bytes are pushed into the stack, as shown in add in Figure 1_ Another 13 bytes of data are pushed into D, and then the value is taken out of the stack and placed in the register array of the corresponding task. The second stage is to copy the value of the register array of the task to be executed to the stack. At this time, the corresponding positions of the PC pointer in the stack are sp-17 and SP-18. The 13 bytes from SP to sp-12 correspond to ACC, B, dptr, PSW, R0 ~ R7. 4.4 interrupt level task switching function osintctxsw () The basic idea of this function is the same as that of the previous function. It should save the state of the current task and run the task with the highest priority in the ready state. The difference between the two is that sp-17 and SP-18 are the locations of PC values in the stack of the previous function, and SP to sp-12 are the locations of 13 registers. When interrupt comes, call function OSIntExit () in interrupt, function OSIntExit () call function OSIntCtxSw (), implement task switch in OSIntCtxSw (). Before entering the function osintexit(), the value of the register has been put on the stack, so when running this function, sp-17 and SP-18 in the stack are the positions of PC values. SP-4 through sp-16 are the locations of 13 registers. In Figure 1, the values of the 13 registers of the previous function are pushed into add_ D, and this function is in add_ B applies to add_ The 13 registers pressed between C. 4.5 cycle beat interrupt function ostickisr () This function provides a beat to the system, generally 10 ~ 100 times per second. If the beat frequency is too high, μ C / OS system will occupy a lot of hardware resources; If it is too low, the switching between tasks will be very slow. This function must first ensure that a periodic interrupt is generated. You can use a hardware timer or obtain a 50 / 60Hz clock frequency from AC. This function should do at least three things: 1) when entering an interrupt, increase the interrupt nesting layer counter by 1, indicating that another interrupt is entered, or you can directly call the osintenter() function; 2) Call the clock beat function ostimetick() to inform the system that another beat has passed; 3) Call the osintexit() function to exit the interrupt. This function will handle it automatically. 5 Conclusion This paper describes how to run on 51 single chip microcomputer with limited stack space μ In the porting process of C / OS-II system, the system stack SP is used as the hub of data exchange. In practical application, if the system stack is used to transplant, it can run on other processors only by appropriate rewriting according to the basic idea in this paper. If the stack pointer addressing space of the processor is large enough, you can also open up a stack for each task to realize task scheduling by changing the stack pointer to the stack space of different tasks. Through the operation on 51 single chip microcomputer, it can be seen that μ C / OS-II can also run on CPUs with less stack space., Read the full text“

     

     

     

     

    List all Question

    Nickname

    Email

    Questions

    Our other product:

    Professional FM Radio Station Equipment Package

     



     

    Hotel IPTV Solution

     


      Enter email  to get a surprise

      fmuser.org

      es.fmuser.org
      it.fmuser.org
      fr.fmuser.org
      de.fmuser.org
      af.fmuser.org ->Afrikaans
      sq.fmuser.org ->Albanian
      ar.fmuser.org ->Arabic
      hy.fmuser.org ->Armenian
      az.fmuser.org ->Azerbaijani
      eu.fmuser.org ->Basque
      be.fmuser.org ->Belarusian
      bg.fmuser.org ->Bulgarian
      ca.fmuser.org ->Catalan
      zh-CN.fmuser.org ->Chinese (Simplified)
      zh-TW.fmuser.org ->Chinese (Traditional)
      hr.fmuser.org ->Croatian
      cs.fmuser.org ->Czech
      da.fmuser.org ->Danish
      nl.fmuser.org ->Dutch
      et.fmuser.org ->Estonian
      tl.fmuser.org ->Filipino
      fi.fmuser.org ->Finnish
      fr.fmuser.org ->French
      gl.fmuser.org ->Galician
      ka.fmuser.org ->Georgian
      de.fmuser.org ->German
      el.fmuser.org ->Greek
      ht.fmuser.org ->Haitian Creole
      iw.fmuser.org ->Hebrew
      hi.fmuser.org ->Hindi
      hu.fmuser.org ->Hungarian
      is.fmuser.org ->Icelandic
      id.fmuser.org ->Indonesian
      ga.fmuser.org ->Irish
      it.fmuser.org ->Italian
      ja.fmuser.org ->Japanese
      ko.fmuser.org ->Korean
      lv.fmuser.org ->Latvian
      lt.fmuser.org ->Lithuanian
      mk.fmuser.org ->Macedonian
      ms.fmuser.org ->Malay
      mt.fmuser.org ->Maltese
      no.fmuser.org ->Norwegian
      fa.fmuser.org ->Persian
      pl.fmuser.org ->Polish
      pt.fmuser.org ->Portuguese
      ro.fmuser.org ->Romanian
      ru.fmuser.org ->Russian
      sr.fmuser.org ->Serbian
      sk.fmuser.org ->Slovak
      sl.fmuser.org ->Slovenian
      es.fmuser.org ->Spanish
      sw.fmuser.org ->Swahili
      sv.fmuser.org ->Swedish
      th.fmuser.org ->Thai
      tr.fmuser.org ->Turkish
      uk.fmuser.org ->Ukrainian
      ur.fmuser.org ->Urdu
      vi.fmuser.org ->Vietnamese
      cy.fmuser.org ->Welsh
      yi.fmuser.org ->Yiddish

       
  •  

    FMUSER Wirless Transmit Video And Audio More Easier !

  • Contact

    Address:
    No.305 Room HuiLan Building No.273 Huanpu Road Guangzhou China 510620

    E-mail:
    [email protected]

    Tel / WhatApps:
    +8618078869184

  • Categories

  • Newsletter

    FIRST OR FULL NAME

    E-mail

  • paypal solution  Western UnionBank OF China
    E-mail:[email protected]   WhatsApp:+8618078869184   Skype:sky198710021 Chat with me
    Copyright 2006-2020 Powered By www.fmuser.org

    Contact Us