23
FreeRTOS Collaborators 2015 Spring Xiao Yi Kai , Zhang Weihao , Yu Zhiwei , Wang Haoyu , Hong Wei Kai Spring 2014 Liang Yingrui , Li Qilin , square waterman , Chen Ying stretch Total pen 2015 Spring Hackpad GitHub Spring 2014 Hackpad GitHub Directory FreeRTOS architecture Source  Naming Rules Run FreeRTOS on STM32F4-Discovery Task Ready list of form data Communications schedule Interrupt processing Hardware drivers Effectiveness Evaluation Test environment set up A discussion Two issues discussed Reference material FreeRTOS architecture Official website: http://www.freertos.org/ FreeRTOS is a relatively small operating system to other operating systems. FreeRTOS minimized core includes only three .c files (tasks.c, queue.c, list.c) and a handful of heade r files, a total of less than 9000 lines of code, including the notes and blank line s. After a typical compiled binary (binary code) is less than 10 KB. FreeR TOS the code can be divided into three main blocks: tasks, communications and hardware interfaces. Tasks (Task): FreeRTOS about half of the core code is used to deal with the majority of the operating system of primary concern: the task, the task that the user has defined priority C functions. task.c and task.h respo nsible for all, heavy work schedule for the establishment and maintenance tasks. Communication (Communica tion): the task is very important, but between tasks can communicate with each other is more important! The second topic that brings out the FreeRT OS of: communication. FreeR TOS core about 40% of the code is used to handle communication s. queue.c and queue.h FreeR TOS handles communicatio ns, tasks and interrupt (interrupt) using the queue (queue, queue) to send data to each other, and using semaphore mutex and critical section used to distribute the signal. Hardware interface: there are nearly 9000 lines of code consisting of basic FreeR TOS, this part has nothing to do with the hardware Wiki - FreeR TOS https://translate.googleusercontent.com/translate c?depth=1&hl=id&ru... 11/10/2015 5:52 1 of 23

Wiki - FreeRTOS

Embed Size (px)

DESCRIPTION

rtos, computer engineering for student in university. real time os.

Citation preview

Page 1: Wiki - FreeRTOS

7/17/2019 Wiki - FreeRTOS

http://slidepdf.com/reader/full/wiki-freertos 1/23

FreeRTOS

Collaborators

2015 Spring

Xiao Yi Kai , Zhang Weihao , Yu Zhiwei , Wang Haoyu , Hong Wei Kai

Spring 2014

Liang Yingrui , Li Qilin , square waterman , Chen Ying stretch

Total pen

2015 Spring

Hackpad

GitHub

Spring 2014

Hackpad

GitHub

Directory

FreeRTOS architecture

Source

 Naming Rules

Run FreeRTOS on STM32F4-Discovery

Task 

Ready list of form data

Communications

schedule

Interrupt processing

Hardware drivers

Effectiveness Evaluation

Test environment set up

A discussion

Two issues discussed

Reference material

FreeRTOS architecture

Official website: http://www.freertos.org/

FreeRTOS is a relatively small operating system to other operating systems. FreeRTOS minimized core includes only three .c files (tasks.c,

queue.c, list.c) and a handful of header files, a total of less than 9000 lines of code, including the notes and blank lines. After a typical

compiled binary (binary code) is less than 10 KB.

FreeRTOS the code can be divided into three main blocks: tasks, communications and hardware interfaces.

Tasks (Task): FreeRTOS about half of the core code is used to deal with the majority of the operating system of primary concern: the

task, the task that the user has defined priority C functions. task.c and task.h responsible for all, heavy work schedule for the

establishment and maintenance tasks.

Communication (Communication): the task is very important, but between tasks can communicate with each other is more important!

The second topic that brings out the FreeRTOS of: communication. FreeRTOS core about 40% of the code is used to handlecommunications. queue.c and queue.h FreeRTOS handles communications, tasks and interrupt (interrupt) using the queue (queue,

queue) to send data to each other, and using semaphore mutex and critical section used to distribute the signal.

Hardware interface: there are nearly 9000 lines of code consisting of basic FreeRTOS, this part has nothing to do with the hardware

i - FreeRTOS https://translate.googleusercontent.com/translate_c?depth=1&hl=id&ru...

0/2015 5:52 1 of 23

Page 2: Wiki - FreeRTOS

7/17/2019 Wiki - FreeRTOS

http://slidepdf.com/reader/full/wiki-freertos 2/23

(hardware-independent), with a code FreeRTOS on different hardware platforms can run. Approximately 6% of FreeRTOS core code,

in between and hardware-independent and hardware FreeRTOS core and associated code plays a spacer ( shim ) role. We will discuss

in the next section of code and hardware-related. [#] _ 

.. [#] With cloc statistics FreeRTOS 8.0.0 of include / * .c portable / GCC / ARM_CM4F / etc directory, can be obtained free of notes, the

number of blank lines for 6566, but statistics and platform-dependent part ( portable / GCC / ARM_CM4F / directory), it is 435 lines. Can

 be calculated: 435/6566 = 0.06625 = 6%, in line with the description, but the original 9000 line refers to the argument containing notes

(actually 8759 lines)

Source

Official Download: https://sourceforge.net/projects/freertos

Latest version: v8.2.1

Core code: (Source)

tasks.c: The main task in charge of archives

queue.c: between management task communication (the concept of message queue)

list.c: provides systems and applications will be used as a real list data structure

- Selective Archives: timer.c, croutine.c (co-routine), event_groups.c

And hardware associated with this item: in ARM Cortext-M3, for example, can be found in the Source / portable / GCC /

ARM_CM3 in

 portmacro.h: defines a hardware-related variables, such as data type definitions, as well as hardware-related function call name is

defined (in portXXXXX name), etc., each function call unified platform

 port.c: define contains hardware-related code implementations

FreeRTOSConfig.h: contains the clock speed, heap size, mutexes, etc. are defined here (need to establish their own)

Back to Contents

Data types and naming rules

On different hardware devices, communication ports on the set is different, as defined in portmacro.h within the header file, there are two

special data types portTickType and portBASE_TYPE.

Data patterns

 portTickType: for storing the tick count value may be used to determine the block number 

 portBASE_TYPE: defined as the architectural foundation of variables, with each different hardware to applications, such as in the

32-bit architecture, which is a 32-bit patterns, most commonly used for the storage limit or Bollinger number.

FreeRTOS clear definition of the variable name and data type, there will be no circumstances be confused with the use of unsigned and

signed occur.

Variable

char type: with c as prefix

short type: in s prefix

long Type: with l as prefix

float type: a prefix to f 

double Type: with d as prefix

Enum variables: the e is prefix

 portBASE_TYPE or other (such as struct): x is a prefix to

There is an additional prefix pointer p, such as short type pointer prefix of ps

unsigned types of variables have an extra prefix u, for example, unsigned short type variable prefix to us

Function: to return value patterns and the location of the beginning of the file name (prefix)

vTaskPriority () is task.c the return value of the function is void patterns

xQueueReceive () is queue.c the return value of the function patterns as portBASE_TYPE

i - FreeRTOS https://translate.googleusercontent.com/translate_c?depth=1&hl=id&ru...

0/2015 5:52 2 of 23

Page 3: Wiki - FreeRTOS

7/17/2019 Wiki - FreeRTOS

http://slidepdf.com/reader/full/wiki-freertos 3/23

Can only be used in the file (scope is limited in file) function to prv beginning with (private)

Local macros are all uppercase letters in FreeRTOS in the definition, the former name of the lowercase letters macro definitions:

macro name

 portMAX_DELAY: portable.h

configUSE_PREEMPTION: FreeRTOSConfig.h

General macro return value is defined pdTRUE and pdPASS to 1, pdFALSE and pdFAIL zero.

Run FreeRTOS on STM32F4-Discovery

Back to Contents

Task

Task (task) is the basic unit of execution in FreeRTOS, each task is represented by a C function composition, meaning that you need to

define a C function, and then use xTaskCreate () this API to create a task, this C function has several features, its return value must be a

void, which usually have an infinite loop, all the work will be on this task is carried out in a loop, and this function will not return,

FreeRTOS not allowed to own task end (with return or execution to the last line of the function)

After the Task is created out, it is equipped with its own stack space and stack variable (function is defined in the variable)

A typical task function as follows:

.. Code-block :: c

void ATaskFunction (void * pvParameters) {int i = 0; // each use this function to establish a task has its own

Task of state

Ready: ready state to be executed

Running: the state of being executed by the CPU

Blocked: waiting state (usually waiting for an event)Suspended: wait for the state (through the API to require exit schedule)

Each state will give a list FreeRTOS store (except running)

Establish task function

.. Code-block :: c

portBASE_TYPE xTaskCreate (pdTASK_CODE pvTaskCode, const si

 pvTaskCode: that we define the C function to establish task 

 pcName: any given task name, this name is used for identification

 purposes only and will not be adopted in the task managementusStackDepth: stack size

 pvParameters: an array of arguments to the task, that is, we declared in the

C function parameter 

uxPriority: definition of the priority tasks, in FreeRTOS, and 0 the lowest,

(configMAX_PRIORITIES - 1) Highest

 pxCreatedTask: handle , is an out of the task can be used to establish an

identification symbol

Delete task function

.. Code-block :: c

void vTaskDelete (xTaskHandle pxTaskToDelete);

 pxTaskToDelete: use to identify which handle a task. This possibility exists if an execution error (fail) occurs in the loop, you need to

i - FreeRTOS https://translate.googleusercontent.com/translate_c?depth=1&hl=id&ru...

0/2015 5:52 3 of 23

Page 4: Wiki - FreeRTOS

7/17/2019 Wiki - FreeRTOS

http://slidepdf.com/reader/full/wiki-freertos 4/23

 jump out of the loop and terminate (himself) to perform, then you need to remove yourself vTaskDelete wrong example occurred:

If a task today is to access a database, but the database or data table does not exist, it should end task 1.

If a client task today is to keep up the server to make the connection (listening is the loop), but found no client-side network 

connection, it should be the end of the task 

2.

Ready list of form data

FreeRTOS use the ready list to manage ready to perform tasks, and ready list of data storage mode as shown below

The next task to be executed when

the OS will be elected during the

context switch

The following is a ready list

selected part of the

implementation program in

accordance with the priority

objective, FreeRTOS priority

minimum of 0, the larger the

number, the higher the priority

task.c

.. Code-block :: c

#define taskSELECT_HIGHEST

From the previous figure we can

know a ready task list each index

 points to a bunch of their task list,

so

listGET_OWNER_OF_NEXT_ENTRY is in a ready task list in the index to get a task in which the task list of TCB

include / list.h

.. Code-block :: c

#define listGET_OWNER_OF_NEXT_ENTRY (pxTCB, pxList) {List_t * const pxConstList = (pxList); / * Increment the i

Task Control Block (TCB) data structure ( tasks.c )

.. Code-block :: c

/ * In file: tasks.c * / typedef struct tskTaskControlBlock {volatile portSTACK_TYPE * pxTopOfStack; / * point

 pxTopOfStack, pxEndOfStack: the size of the stack of records

uxPriority, uxBasePriority: the former record current priority, the latter recording the original priority (may occur in Mutex)

xGenericListItem, xEventListItem: when a task is placed in a list of FreeRTOS, FreeRTOS insertion point in the task TCB pointer 

 place

i - FreeRTOS https://translate.googleusercontent.com/translate_c?depth=1&hl=id&ru...

0/2015 5:52 4 of 23

Page 5: Wiki - FreeRTOS

7/17/2019 Wiki - FreeRTOS

http://slidepdf.com/reader/full/wiki-freertos 5/23

When xTaskCreate () function is called, and a task will be created. FreeRTOS will be assigned to each task a new TCB target, to record its

name, priority and other details, and then configure HeapStack space requested by the user (assuming there is enough memory to use), and

the members of the TCB pxStack recorded in the memory of the start address Stack.

TCB and stack configuration of function - prvAllocateTCBAndStack () ( tasks.c )

.. Code-block :: c

/ * Stack memory in descending * / #if (portSTACK_GROWTH> 0) {/ * pvPortMalloc is to do memory configuration *

When performing pvPortMalloc, we will carry out vTaskSuspendAll ();, by context swiitch of swap out action does not occur, the

configuration memory space, and then wait until the configuration is complete call xTaskResumeAll ();

 pvPortMalloc in port.c which defines, basically do memory configuration, according to the various port to implement pvPortMalloc.

 pvPortMallocAligned which can be seen in the FreeRTOS.h define the space as if it is judged not configured, perform pvPortMalloc,

if there is a direct use puxStackBuffer.

Hardware-level settings

To facilitate scheduling, when creating a new task, stack data, in addition to the others, but also add a "empty" register information (in

theory does not have the information when you register the first performance), so that the new task is like When the context switch is

selected as the task, in accordance with the naming conventions of the aforementioned variables, here is the real way to make

 portable / GCC / ARM_CM4F / port.c

.. Code-block :: c

/ * In file:. Port.c * / StackType_t * pxPortInitialiseStack (StackType_t * pxTopOfStack, TaskFunction_t pxCode

After the TCB initialization is complete, we should connect the TCB other relevant list, this process must be halted temporarily interrupt

function, so as not to set up before the list was not interrupted settings (such systick)

The ARM Cortex-M4 processor is interrupted when the task encounters, the content will register a push into the top of the stack of the task 

to be executed and then pop out the next time, here is where the real work in port.c

 portable / GCC / ARM_CM4F / port.c

.. Code-block :: c

/ * In file: port.c * / void xPortPendSVHandler (void) {/ * This is a naked function * / __asm volatile ("mrs r

Interrupt the real work is in control of the CPU interrupt permission register (basepri) content to the highest, at this time will not have any

interrupt can be called, the name of the function call is ulPortSetInterruptMask ()

 portable / GCC / ARM_CM4F / port.c

.. Code-block :: c

__attribute __ ((naked)) uint32_t ulPortSetInterruptMask (void) {__asm volatile ("mrs r0, basepri \ n" "mov r1,

Thereby mask masked out all interrupt (all lower priority than configMAX_SYSCALL_INTERRUPT_PRIORITY the task will not be

executed)

Reference: http://www.freertos.org/RTOS-Cortex-M3-M4.html

When vTaskCreate () after the task is created out of the need to use vTaskStartScheduler () to start the scheduler decide which task begins

execution, when vTaskStartScheduler () when the call will first establish a idle task, the task is to ensure that CPU at any one time there is

at least one task can be executed (instead of directly switched back to kernel task) in vTaskStartScheduler () when the call is automatically

set up user task, idle task's priority is 0 (lowest), the purpose is to ensure that when there are other user task When entering the ready list

can be executed immediately

vTaskStartScheduler ( tasks.c )

.. Code-block :: c

i - FreeRTOS https://translate.googleusercontent.com/translate_c?depth=1&hl=id&ru...

0/2015 5:52 5 of 23

Page 6: Wiki - FreeRTOS

7/17/2019 Wiki - FreeRTOS

http://slidepdf.com/reader/full/wiki-freertos 6/23

/ * Add the idle task at the lowest priority. * / #if (INCLUDE_xTaskGetIdleTaskHandle == 1) {/ * Create the idl

Then just call xPortStartScheduler () to perform the task 

Blocked

Task blocked state is usually task into a wait state needs an event occurs, the event is usually the time to execute (for example systick 

interrupt) or in response to the synchronization process, if, as the beginning of the ATaskFunciton () is used while (1 ) {} This infinite loop

to wait for the event, will take up CPU computing resources, which is task is actually running, but powerless to do anything, just to occupy

the resource wait event, it is a good practice to change with vTaskDelay (), when the task calls the vTaskDelay (), task will enter the

 blocked state, you can make out of the CPU resources

Use infinite loop execution timing diagram

Use vTaskDelay () execution timing diagram

vTaskDelay (): This parameter directly to the value

if the function is ticks, for example vTaskDelay

(250) is suspended 250 ticks meaning, due to the

different length of time a tick for each CPU,

FreeRTOS portTICK_RATE_MS this macro

 provides a constant, You can help us to convert the

number of ticks in milliseconds (ms), that is to say

vTaskDelay (250 / portTICK_RATE_MS) this

writing, is to make task pause 250 milliseconds

(ms) means (v8.2.1 renamed

 portTICK_PERIOD_MS)

Suspended

If a task is block for a long time

or there will be a period of time

less than that it will be thrown

into the suspend state. Scenario:There is a taskPrint this task only

 print data, and there are several

taskOperator responsible for 

doing arithmetic, if the operation

to be a long time, you can be

thrown into the taskPrint suspend

state, after the operation until all

are completed, and then enter the

ready wake taskPrint state, and finally print out the information.

vTaskSuspend usage examples:

.. Code-block :: c

 void vAFunction (void) {TaskHandle_t xHandle; // Create a task, storing the handle xTaskCreate (vTaskCode, "NA

Back to Contents

Communications

In FreeRTOS, the communication between the task by the information sent to the queue and the read data queue in realization

Queue

FreeRTOS's task is to use deep copy

of the default way to the information

sent to the queue, that is a copy of a

i - FreeRTOS https://translate.googleusercontent.com/translate_c?depth=1&hl=id&ru...

0/2015 5:52 6 of 23

Page 7: Wiki - FreeRTOS

7/17/2019 Wiki - FreeRTOS

http://slidepdf.com/reader/full/wiki-freertos 7/23

will according to the character data

to a queue, when the data to be

transferred is large, it is

recommended not to pass such, change indicators using data transfer methods, such as shallow copy. Benefits can copy data directly bigger 

drawback is that affect the memory content. No matter which way you choose to put in the queue, FreeRTOS only care about the size of the

data, and do not care what kind of data copy approach.

Shallow Copy

Deep Copy

Queue structure

queue.c

.. Code-block :: c

/ * In file: queue.c

Because a queue can be

written multiple task (ie

send data), so there

xTasksWaitingToSend this

list to track the live block 

the task (data waiting to

 be written to the queue

in the task), whenever 

there is an item to be

removed from the queue

in In addition, the

system will check 

xTasksWaitingToSend,

waiting to see if there is

a task in the list, and

select a task in which

the highest priority, to

restore it to perform the

write operation to the

information, if these are

the same task of priority We will pick the longest waiting task.

There are many task from the queue when read data is the same (ie, receive data), if the queue is not any item, while there are several task 

you want to read the information, these task will be added xTasksWaitingToReceive, whenever item is placed in a queue, the system as to

check xTasksWaitingToReceive, waiting to see if there is a task in the list, and select a task in which the highest priority, to restore it to

 perform data read operation, If the task of priority are the same, it will pick the longest waiting task.

Queue Usage

/CORTEX_M4F_STM32_DISCOVERY/main.c

.. Code-block :: c

/ * File: ./CORTEX_M4F_STM32F407ZG-SK/main.c*/ / * line: 47 * / xQueueHandle MsgQueue; / * line: 214 * / void Q

Operating function definition queue in the Source / queue.c

FreeRTOS queue can also be used to implement semaphore and mutex:

* Semaphores - to make a task wake wake (wake) another task, such as: producer and consumer * Mutexes - used fo

Differences mutex and semaphore, see this essay: http://embeddedgurus.com/barr-code/2008/01/rtos-myth-1-mutexes-and-semaphores-

are-interchangeable/

i - FreeRTOS https://translate.googleusercontent.com/translate_c?depth=1&hl=id&ru...

0/2015 5:52 7 of 23

Page 8: Wiki - FreeRTOS

7/17/2019 Wiki - FreeRTOS

http://slidepdf.com/reader/full/wiki-freertos 8/23

Implement semaphore

 N-element semaphore, only synchronous uxMessagesWaiting, and only care about how many queue entries are occupied, which

uxItemSize is 0, item and data copying is not required.

 Need to use the ARM Cortex-M4F unique mechanism in order to make real semaphore, this mechanism is "at the same time access

uxMessagesWaiting must ensure that only one task in making a change (into and out of critical section)," To prevent the first two Methods

task enters modified as follows:

 portable / GCC / ARM_CM4F / port.c

.. Code-block :: c

/ * In file: port.c * / void vPortEnterCritical (void) {portDISABLE_INTERRUPTS (); uxCriticalNesting ++; __asm

Implementing mutex

Because pcHead and pcTail not, so use overloadind to achieve better utilization:

queue.c

.. Code-block :: c

 / * Effectively make a union out of the xQUEUE structure * / #define uxQueueType pcHead #define pxMutexHolder

Supplementary: http://embeddedgurus.com/barr-code/2008/03/rtos-myth-3-mutexes-are-needed-at-the-task-level/

Producers and consumers

Use FreeRTOS the semaphore and mutex to implement the producer and consumer issues:

.. Code-block :: c

SemaphoreHandle_t xMutex = NULL; SemaphoreHandle_t empty = NULL; SemaphoreHandle_t full = NULL; xQueueHandle bu

Back to Contents

schedule

 basic concept

FreeRTOS, in addition to the

requirements of the kernel task to hand

over control of the CPU outside, task can

also be possible to hand over control of its

own CPU

Delay (sleep): Pause a period of time

/CORTEX_M4F_STM32_DISCOVERY

/main.c

.. Code-block :: c

void Task2 (void * pvParameters) {while (1) {vTaskDelay (1000); itoa (iii, 10); iii = 0;}}

Use vTaskDelay (ticks) will be removed from the current task of ListItem ReadyList and placed DelayList or OverflowDelayList in (systick 

determined by the presence or absence of overflow plus systick now want to wait), but the task is not in a call vTaskDelay () after 

immediately hand over control of the CPU, but the next time systick interrupt before release

wait (block): wait for access to resources or events

.. Code-block :: c

void QTask2 (void * pvParameters) {uint32_t rcv = 0; while (1) {if (xQueueReceive (MsgQueue, & rcv, 100 / portT

i - FreeRTOS https://translate.googleusercontent.com/translate_c?depth=1&hl=id&ru...

0/2015 5:52 8 of 23

Page 9: Wiki - FreeRTOS

7/17/2019 Wiki - FreeRTOS

http://slidepdf.com/reader/full/wiki-freertos 9/23

Use xQueueReceive (xQueue, * pvBuffer, xTicksToWait), the waiting time has not arrived yet portMAX_DELAY (FreeRTOS longest wait

time), task will be placed EventList waiting for access to resources or event. If the waiting time to portMAX_DELAY, it will be moved to

SuspendList continue to wait

RTOS tick 

 portable / GCC / ARM_CM4F /

 port.c

Implementing details

.. Code-block :: c

void xPortSysTickHandler (

.. Code-block :: c

BaseType_t xTaskIncrement

Starvation If a high priority task 

to occupy CPU, the lower 

 priority task can not be

 performed, starvation will occur (low priority for a long time can not get CPU execution)

(FreeRTOS schedule uses a multi-level queue, so?)

Back to Contents

Interrupt processing

Here the main discussion is ARM Cortext-M3 interrupt (Exception), are the following:

Reset: from the specified address in the vector table, with privileged thread mode and press the reset executed

 NMI: it simply is in addition to the external reset strongest exception

Will trigger this exception exception handler do unexpected tragedy occurs when: Hard FaultMemory management fault: When the memory protection fails, the exception is triggered MPU, to disable the device into the

absolutely inaccessible memory area

Bus Fault: memory-related error occurred when transaction execution instruction or data, may be bus problems

Usage fault: undefined instruction executed or illegal unaligned access, invalid state when instruction is executed, Error exception

return, divided by 0 (need to set their own)

SVCall: supervisor call SVC instruction execution (under the OS environment)

PendSV: In the OS environment, usually for context switch

SysTick: When the countdown timer reaches zero trigger, you can also use the software interrupt, OS will put this exception as

system tick.

Request peripheral devices triggered exception, or a software generated: Interrupt (IRQ)

The following discusses interrupt handling interrupts to do, a practice used to wait for the task interrupt occurs fragment domestic

semaphore boxes, one ISR (interrupt service routine) is used to (task) semaphore, as well as to deal with the release of a handler task to

handle the ISR, which makes use of a more streamlined ISR 

In the process of interfacing hardware and software interrupt diagram is as follows:

i - FreeRTOS https://translate.googleusercontent.com/translate_c?depth=1&hl=id&ru...

0/2015 5:52 9 of 23

Page 10: Wiki - FreeRTOS

7/17/2019 Wiki - FreeRTOS

http://slidepdf.com/reader/full/wiki-freertos 10/23

 Nested Vectored Interrupt Controller (NVIC)

 NVIC is part of the Cortex-M3, he is used to manage a group of various peripheral hardware interrupt signals scratchpad, EXIT is used to

manage a variety of hardware on board STM32 interrupt controller, EXIT through the interrupt signal GPIO gave Cortext-M3 NVIC

register on, FreeRTOS through operations in NVIC and call interrupt service routine to handle hardware interrupts.

In Lab40 in, visualizer / main.c in there defined interrupt and get the kind of interrupt priority: the

.. Code-block :: c

#define NVIC_INTERRUPTx_PRIORITY ((volatile unsigned char *) 0xE000E400) ... int get_interrupt_priority (int in

External Interrupt (EXTI)

Each interrupt handler sort and Name Definition (not real as content) are placed in startup_stm32f429_439xx.s, the implement is placed

elsewhere, FreeRTOS user can define an external interrupt channel EXTI_Line0 to EXTI_Line15, but EXTI_Line10 ~ 15 and EXTI_Line5

~ 9 is set to the same external interrupt channel, which means that Line15 Line10 and will call the same handler, and if Line10 Line15

require different tasks, they have to make a judgment trigger sources within the handler EXTI_Line10_15

file: startup_stm32f429_439xx.s line: 158

CORTEX_M4F_STM32_DISCOVERY / startup / startup_stm32f4xx.s

.. Code-block :: c

 .word EXTI0_IRQHandler / * EXTI Line0 * / .word EXTI1_IRQHandler / * EXTI Line1 * / .word EXTI2_IRQHandler / *

EXTI must be used before:

1. and GPIO connections, as a trigger source (information about GPIO, refer to the next section) 2. Set EXTI *

FreeRTOS operating in the real EXTI as follows:

CORTEX_M4F_STM32_DISCOVERY / main.c

.. Code-block :: c

i - FreeRTOS https://translate.googleusercontent.com/translate_c?depth=1&hl=id&ru...

0/2015 5:52 10 of 23

Page 11: Wiki - FreeRTOS

7/17/2019 Wiki - FreeRTOS

http://slidepdf.com/reader/full/wiki-freertos 11/23

 / * Configure PA0 pin as input floating * / GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_InitStructure.GP

Back to Contents

Hardware drivers

Here it is to introduce the use GPIO allows hardware-driven approach through the example of the LED

GPIO Profile

GPIO is to allow developers can register by changing the contents of a specific location information to control various peripheral hardware,

or by external input, to change the register contents, so that the hardware that made the change after reaction

In the STM32 development board can see a lot of pins, general STM32F429 board has 7 GPIO ports, namely Port A, B, C, D, E, F and G,

each port has its own scratchpad sequence is as follows, each with 32 pins (corresponding to 32 bits): * GPIO port mode register 

(GPIOx_MODER) * GPIO port output type register (GPIOx_OTYPER) * GPIO port output speed register (GPIOx_OSPEEDR) * GPIO

 port pull-up / pull-down register (GPIOx_PUPDR) * GPIO port input data register (GPIOx _IDR) * GPIO port outp ut data register 

(GPIOx_ODR) * GPIO port bit set / reset register (GPIOx _BSRR) * GPIO port bit reset register (GPIOx_BRR) * GPIO port configuration

lock register (GPIOx_LCKR) * GPIO alternate function low register (GPIOx_AFRL) * GPIO alternate function high register 

(GPIOx_AFRH) GPIOx for example, when x is A, it means we now access the GPIO Port A

Before using GPIO, you must be pre-set behavior and details to LED within the initial job stm32f429i_discovery.c view

Utilities / STM32F429I-Discovery / stm32f429i_discovery.c

.. Code-block :: c

/ * In file: stm32f429i_discovery.c * / void STM_EVAL_LEDInit (Led_TypeDef Led) {GPIO_InitTypeDef GPIO_InitStru

Users use to open the bus GPIO's clock, then use GPIO_InitStructure (struct data type) to store relevant settings and to GPIO_Init () to do

the set of memory

Underlying implementations

LED above the initial process continues, for example, which relates to the function of the hardware set RCC_AHB1PeriphClockCmd () andGPIO_Init ()

First discuss RCC_AHB1PeriphClockCmd ():

.. Code-block :: c

/ * In file: stm32f4xx.h * / typedef struct {... __IO uint32_t AHB1ENR; / * <RCC AHB1 peripheral clock register

 Not difficult to find, GPIO peripheral set on fairly simple implementations, namely in pre-defined memory segment, in accordance with the

definition of the set designer will write parameters where

It is worth mentioning, GPIO initialization and setting are all performed at run time, even if the program is still in operation can be

redefined or even close vicinity, which makes use of more flexible MCU

GPIO_Init () implementation is also inseparable from the write data to the memory issue, but set the project is more, setting process is also

more complicated

GPIO_Init ():

CORTEX_M4F_STM32_DISCOVERY / Libraries / STM32F4xx_StdPeriph_Driver / src / stm32f4xx_gpio.c

.. Code-block :: c

/ * In file: stm32f4xx_gpio.c * / void GPIO_Init (GPIO_TypeDef * GPIOx, GPIO_InitTypeDef * GPIO_InitStruct) {ui

Reference STM32Cube_FW_F4_V1.1.0 / Projects / STM32F429I-Discovery / Examples / GPIO / GPIO_EXTI / readme.txt

Back to Contents

i - FreeRTOS https://translate.googleusercontent.com/translate_c?depth=1&hl=id&ru...

0/2015 5:52 11 of 23

Page 12: Wiki - FreeRTOS

7/17/2019 Wiki - FreeRTOS

http://slidepdf.com/reader/full/wiki-freertos 12/23

Effectiveness Evaluation

Context switch

Context switch means task A CPU usage rights when you want to surrender to the task B, OS will task A current status and data registers

stored within memory, then the state of the previous task B to be read from memory Process scratchpad

FreeRTOS want to know the context switch time, we designed a test method: CORTEX_M4F_STM32_DISCOVERY / main.c

.. Code-block :: c

uint32_t iii = 0; void Task1 (void * pvParameters) {while (1) {iii ++; while (STM_EVAL_PBGetState (BUTTON_USER)

1. Firstly task1 and task2, which is greater than the priority of task2

task1 priority. task2 first implementation, and (task2) immediately

moved to block the call vTaskDelay make task2 state one second, then it

will happen context switch, switch to task1 executed within one second

of time, task1 will keep the global variables iii do + +, until one second

after the end of back task2 execution, then the value of the print iii task2,

and the iii reset to 0, this is a cycle. Iii This action available within one

second can go much, let one second can run to the k value.

Establish task3 and set its priority higher than task2, task3 performs

vTaskDelay 300 seconds and 300 seconds after the end, be interrupted iii ++ task1 performed, and then printed out by the task3 iii

value, set it as final_i, k values final_i value The difference is the context of the total time switch.

2.

Below is randomly picked 45 iii value made chart, where the average value iii: 4280015

Then we measured final_i value, average: 3913853, it is

obtained (4280015 --3913853) / 4,280,015 = 0.0855 (sec)

The sum of all context switch time of 0.0855 seconds

representatives within 300 seconds of the test

And because one cycle (first step) will go through two context

switch (above), we measured a total of 600 context switch

300, so we measured about each context switch: 0.0855 / 600

= 142.5 (us)

interrupt latency

We measure is manually set a framework for external

interrupt, occurs BUTTON_USER pressed, the following

 program is our real work:

CORTEX_M4F_STM32_DISCOVERY / main.c

.. Code-block :: c

i = 0; while (STM_EVAL_PBGetState (BUTTON_USER)) {i ++;}

When BUTTON_USER pressed, it will first execute i ++ until interruptHandler process interrupt, you can read the i value that interrupt

latency, and implement and found i still zero.

IPC (Inter-Process Communication) throughput

Test program, in the first 167 rows can change the time to execute

SysTick minimum can only be set to 1 / 100,000 (one hundred thousandth) seconds

If set to 1/1000000 (ppm) seconds, then even the data copy to queue in too late to perform

Environment settings:

i - FreeRTOS https://translate.googleusercontent.com/translate_c?depth=1&hl=id&ru...

0/2015 5:52 12 of 23

Page 13: Wiki - FreeRTOS

7/17/2019 Wiki - FreeRTOS

http://slidepdf.com/reader/full/wiki-freertos 13/23

SysTick is 1 / 100,000 (one hundred thousandth) seconds1.

Queue the length of 100002.

Queue of ItemSize as uint32_t3.

Test-way (send)

If you use only send data to perform a task, then, in the 100 SysTicks time can be thrown about 740, in 1000 SysTicks time can be thrown

about 7500,

Within the 1 SysTick average send 7.5个, so throughput is about: 7.5 * 100000 * 4 = 3 (Mbytes / s)

Test-way (send and receive)

If you add a task to receive data, send data and the same priority and the priority

By 1000 SysTicks can receive 2962,

The average received 2.962 1 SysTick, so throughput is about: 2.962 * 100000 * 4 = 1.185 (Mbytes / s)

Test each ItemSize make changes

If each ItemSize as uint16_t, the throughput is about: 2.893 * 100000 * 2 = 0.579 (Mbytes / s)

If each ItemSize as uint64_t, the throughput is about: 2.823 * 100000 * 8 = 2.258 (Mbytes / s)

More than three comparison, when uint64_t best throughput,

and the difference between the minimum snd and rcv.

realtime capability

Back to Contents

Test environment set up

Installation

1. Install st-link and openOCD, refer to [this page] (https://stm32f429.hackpad.com/NOTE-W

Porting Commentary

Tools:

stlink: to burn or GDB server tools

openocd: used to execute GDB server and enable semihosting

FreeRTOS version: 8.2.1

Board: STM32F429 Discovery

Porting FreeRTOS to STM32F429-Discovery is a few main focus

Utility: From STM32F429I-Discovery_FW_V1.0.1 (official driver), use is to provide some of the operations of the hardware

 peripheral library (API), such as an LCD

1.

FreeRTOS: FreeRTOS the source code, in the download package back FreeRTOSV8.2.1 / FreeRTOS / Source2.

CORTEX_M4F_SK: In your downloaded package FreeRTOSV8.2.1 / FreeRTOS / Demo, purpose is to provide a platform

CORTEX_M4F_SK drive library on the square belongs to FreeRTOS software interface developed

3.

App development

In Lab39's freertos-basic applications in FreeRTOS source src / and include /, for example, we integrated into app /, and the src / main.c

alone in pulling out, and continued myFreeRTOS (branch: game) architecture archives , application game / and main.c are placed here

CORTEX_M4F_SK, so the project is structured as follows:

i - FreeRTOS https://translate.googleusercontent.com/translate_c?depth=1&hl=id&ru...

0/2015 5:52 13 of 23

Page 14: Wiki - FreeRTOS

7/17/2019 Wiki - FreeRTOS

http://slidepdf.com/reader/full/wiki-freertos 14/23

.. Code-block ::

. | ___ CORTEX_M4F_SK | | __ app / | | __ main.c | | __ others C files | ___ FreeRTOS | ___ Utility

Hint: main.c have a model, in STM32F429I-Discovery_FW_V1.0.1 / Projects / Template

Reference: http: //www.st.com/web/en/resource/technical/document/reference_manual/DM00031020.pdf 

API: Utilities / STM32F429I-Discovery

Back to Contents

A discussion

Q2: Suspend the relevant code

FreeRTOS provide vTaskSuspend () and vTaskResume () API to provide these two we can make task enters suspend state. FreeRTOS there

is another API to vTaskSuspendAll () when the main purpose of a particular task when executed, can make within a certain period

scheduler is suspend, prevent context switch occurs as a method to control the uxSchedulerSuspended real variables, vTaskSuspendAll ()

let uxSchedulerSuspended + 1 enter suspendall state then when that part of the code executing the vTaskresumeall let

uxSchedulerSuspended-1 This usage will be used again in a lot of task 

For example: vTaskDelay, vTaskDelayUntil in order to allow a smooth connected DelayedList Tasks without interruption, when scheduler 

is suspend, context switch is pending, and in the case of scheduler is suspend, interrupt can not change the TCB xStateListItem. And

PendingReadyList usage also suspend when the scheduler is if you want to lift the block this time interrupt status of a task, then the need to

interrupt this task the event list item to xPendingReadyList put in, so that relieve suspend scheduler, you can be within xPendingReadyList

The task placed in the ready list.

Q3: Priority scope and definition of Where

In ./CORTEX_M4F_STM32F407ZG-SK/FreeRTOSconfig.h in

.. Code-block :: c

#define configMAX_PRIORITIES (5)

Q4: Why doubly linked list

Because the doubly linked list when you insert a new ITEM has constant time complexity of O (1), and Singly linked list is O (n)

Q5: Why FREERTOS return after FORK is a STRUCT instead of PID

Traced the xTaskCreate the code, found him to be executed xTaskGenericCreate this function, and xTaskGenericCreate is completed after 

the malloc function in TCB, return values are two-fold:

 pdPASS

errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY

Data type is BaseType_t, declared in portmacro.h in:

.. Code-block :: c

typedef long BaseType_t;

So he uses the return value: Return to inform whether success in malloc memory.

The linux using backhaul because the parent PID using wait () to wait for the child, after the child when the execution will call exit (),

 parent which can clean up child process. If the parent does not use wait (), it will cause the parent may have to end, and this causes child

 become zombie.

FreeRTOS the task create:

.. Code-block :: c

i - FreeRTOS https://translate.googleusercontent.com/translate_c?depth=1&hl=id&ru...

0/2015 5:52 14 of 23

Page 15: Wiki - FreeRTOS

7/17/2019 Wiki - FreeRTOS

http://slidepdf.com/reader/full/wiki-freertos 15/23

xTaskCreate (vTaskCode, "NAME", STACK_SIZE, & ucParameterToPass, tskIDLE_PRIORITY, & xHandle);

Handle deposit which is newly created TCB address the structure of the future you want to delete this task, then you can use the following

method:

.. Code-block :: c

/ * Use the handle to delete the task * / if (xHandle = NULL {vTaskDelete (xHandle);}.!

And Linux's parent and the child to the same address space, if the return address for the child's future when the parent should remove the

child, they also put themselves to delete linux ... So instead of using a PID structure of address .

Q6: STACK arrangement position, how to store

Store order:

xPSR 

PC: Program counter contents stored under the processor to access a command here LR: link rigisiter: save the subroutine return address

R12: Intra-Procedure-call scratch register R3: parameters R2: parameters R1: parameters R0: parameters

 portINITIAL_EXEC_RETURN: Each task to safeguard their own return value

R11R10

R9

R8

R7

R6

R5

R4

 NOTE: xPSR: Composite of the 3 PSRs,

APSR-Application Program Status Register-condition flags (deposit negative, zero, carry, overflow, etc.) IPSR-I

Q7: LR (Link Rigisiter) usefulness

When a task A execution is interrupted (possibly system tick or high priority Task appears) to record Task A execution to a position where,

when other programs executed, can return to continue the trip Task A

Q8: Why is R12 R3 R2 R1 to reserve it?

R0 ~ R3 for temporarily Argument of scratch rigister (reason 4 register is to handle values larger than 32 bits)

R0 R1 result of value can scratch subroutine

R12: As The Intra-Procedure-call scratch register.

And why is that a few, easy to use because the call

R12 (IP) Usage:

.. Code-block :: c

mov ip, lr bl lowlevel_init mov lr, ip ip bl first deposit lr scratch skip other branch of local branch jumps b

PS About veneer: ARM can support 32-bit and 16-bit instructions each switch (THUMB is the ARM 16-bit instruction set), wherein the

switching program segment called veneer 

Back to Contents

Q9: Who received the New Task Ready List

.. Code-block :: c

i - FreeRTOS https://translate.googleusercontent.com/translate_c?depth=1&hl=id&ru...

0/2015 5:52 15 of 23

Page 16: Wiki - FreeRTOS

7/17/2019 Wiki - FreeRTOS

http://slidepdf.com/reader/full/wiki-freertos 16/23

GDB Trace result Breakpoint 1, xTaskGenericCreate (pxTaskCode = 0x80003b1 <GameTask>, pcName = 0x800ea84 "GameT

 prvInitialiseTaskLists (void)

Only when the list has not been initialized, it will be executed. Preset will establish pxReadyTasksLists, xDelayedTaskList1, xDelaye

traceMOVED_TASK_TO_READY_STATEdTaskList2, xPendingReadyList, in accordance with the user setting you can choose whether to

establish xTasksWaitingTermination and xSuspendedTaskList

 prvAddTaskToReadyList (pxNewTCB)

The pxNewTCB connect pxReadyTasksLists, prvAddTaskToReadyList () code as follows

.. Code-block :: c

#define prvAddTaskToReadyList (pxTCB) \ traceMOVED_TASK_TO_READY_STATE (pxTCB) \ taskRECORD_READY_PRIORITY ((px

traceMOVED_TASK_TO_READY_STATE

.. Code-block :: c

#ifndef traceMOVED_TASK_TO_READY_STATE #define traceMOVED_TASK_TO_READY_STATE (pxTCB) #endif

Custom function, no pre-defined. Debug with

taskRECORD_READY_PRIORITY

.. Code-block :: c

#define taskRECORD_READY_PRIORITY (uxPriority) \ {\ if ((uxPriority)> uxTopReadyPriority) \ {\ uxTopReadyPriori

Check the current task's priority is higher than the "current highest priority." If yes, it will update the current highest priority.

vListInsertEnd

.. Code-block :: c

void vListInsertEnd (List_t * const pxList, ListItem_t * const pxNewListItem) {ListItem_t * const pxIndex = pxL

The pxNewListItem inserted into pxList rearmost

Back to Contents

Q10: arm conditional code?

conditional code usage as additional instruction after certain conditions, to define the instruction code execution

Q11: Thumb state bit execution state bit??

Within EPSR-Execution Program Status

Register have kept Thumb state bit and the

execution state bits, where the execution state

 bits contains two overlapping areas: **

If-Then (IT) instruction1.

Interruptible-Continuable Instruction (ICI) field)2.

about IT

IT (If - Then) instruction by the IT abuts 1 to 4

consisting of a subsequent instruction (IT block).

http://web.eecs.umich.edu/ Prabal / teaching /

eecs373-F10 / Readings / ARMv7-M_ARM.pdf p.148

 p.149 IT Instruction Example:

.. Code-block :: c

i - FreeRTOS https://translate.googleusercontent.com/translate_c?depth=1&hl=id&ru...

0/2015 5:52 16 of 23

Page 17: Wiki - FreeRTOS

7/17/2019 Wiki - FreeRTOS

http://slidepdf.com/reader/full/wiki-freertos 17/23

if (R4 == R5) {R7 = R8 + R9; R7 / = 2;} else {R7 = R10 + R11; R7 * = 2;}

converts to http://wiki.csie.ncku.edu.tw/embedded/freertos

.. Code-block :: c

CMP R4, R5 ITTEE EQ ADDEQ R7, R8, R9; if R4 = R5, R7 = R8 + R9 ASREQ R7, R7, # 1; if R4 = R5, R7 / = 2 ADDNE R7

about ICI

Multi-register (multy register) reads (LDM) and write (STM) is interrupted, ICI used to save the implementation process, the next register 

number.

Q12: R0 ~ R3, R12, LR These correspond to the function call is where?

Q13: R4 ~ R11 used at what time?

Q14: continue Q5, ask 

FreeRTOS design concepts go

back to see part of the OS fork 

Excerpt from the book version and

translation dinosaur eight P110 ~

112: * parent program (parent

 process) a subroutine (child

 process), these new programs are

 produced (fork ()), it will form the

 program tree (tree of processes).

Generally speaking, a program will

need some resources (resource),

subroutines or subroutines directly

resources are limited resources in

the parent program. "Limitation

subprogram in the parentapplication resource in" generate

too much routine can be prevented

 because overloaded (overloading)

occur.

A typical approach is to call fork ()

i - FreeRTOS https://translate.googleusercontent.com/translate_c?depth=1&hl=id&ru...

0/2015 5:52 17 of 23

Page 18: Wiki - FreeRTOS

7/17/2019 Wiki - FreeRTOS

http://slidepdf.com/reader/full/wiki-freertos 18/23

after the parent program and subroutines one can use exec () to call a new program to replace its own memory space, the benefits of 

this approach is that the father, a subprogram can run different programs and may also make communication (communicate).

Q15: VFP has several registers

ARM floating-point architecture (VFP, full name Vector Floating-Point) for the operation of floating-point arithmetic provides hardware

support.

http://infocenter.arm.com/help/index.jsp?topic=

/com.arm.doc.ddi0439b/Chdhfiah.html

The above table format will be used VFP REG

Also has a separate registers FPU has 32 (32bit)

(S0 ~ S31)

So PORT.C void xPortPendSVHandler (void)

.. Code-block :: c

"Tst r14, # 0x10 \ n" / * Is the task using the FPU context? If so, push high vfp registers. * / "It eq \ n" "v

HIGH will put part piled up (by STMDB reached)

Q16 :! What (group language)

 Note that the exclamation mark in ARM assembly code means that the index operation is performed before applying the real instruction.

For example, str r2, [r3, # -4] means:! Store r2 value to the ptr {r3-4} and r3 = r3 -4.

Instruction Set Architecture:

.. Code-block :: c

ADD R0, R0, # 1; R0 ← R0 + 1 STR R0, [R1]; R0 → [R1] // R0 value is transferred to the value of R1 to the memor

About STMxx and LDMxx instruction

Q17: attribute ((naked)) naked is doing?

After compiler compile function at function

entry and exit will add some code, such as save

used registers, add return code.

But if you do not want to add these compiler 

code, you can add attribut when function

declaration: naked

.. Code-block :: c

void funA (void) __attribute__ ((naked)) {... asm ("ret");}

Q18: vPortEnterCritical code Why can ensure that only one task to enter the critical section uxCriticalNesting ++?

.. Code-block :: c

funcA () {vPortEnterCritical (); ... funcB (); ... vPortExitCritical ();} funcB () {vPortEnterCritical (); ...

Q19: schedule over there [in the general non-real-time operating system, usually every task will be assigned to the same CPU usage

time, RTOS is not always the case, in addition to the follow-up will be referred to the relevant information requested by the kernel

task to hand over control of the CPU, but each task can also choose their own surrender control of the CPU, Jufan] make

corrections

In the above updates

Q20: About xTaskIncrementTick () code

i - FreeRTOS https://translate.googleusercontent.com/translate_c?depth=1&hl=id&ru...

0/2015 5:52 18 of 23

Page 19: Wiki - FreeRTOS

7/17/2019 Wiki - FreeRTOS

http://slidepdf.com/reader/full/wiki-freertos 19/23

In the above updates

Q21: queue implementations are not cycle?

, The reference

.. Code-block :: c

pxQueue-> pcWriteTo + = pxQueue-> uxItemSize; if (pxQueue-> pcWriteTo> = pxQueue-> pcTail) / * lint e946 MISRA

Back to Contents

Two issues discussed

(In two parts catalog links purely for convenience)

Q22: Lab40 why visualizer / main.c of get_time () where scale is microsecond?

The problem is that, in order to calculate the context switch time, the time we need to take the system (the system startup date after the

time), has been used before in Lab40 tick count to get the system time, get_time in visualizer / main.c in () final return of xTaskGetTick

() + (reload - current / reload) is present, the system has performed ticks plus the number of count downs through the current

system of (1 / x tick, read as "one of x minutes tick"), which segment is to use tick to indicate the current elapsed time, put this ticks turn

into human readable time, that is, to make ticks converted into second, a practice that is multiplied by the "unit of magnitude (scale)", the

definition of this scale before return Please refer to the following segments:

<Visualizer / main.c>

We care about is why the scale unit is microsecond it?

First up the chase defined configTICK_RATE_HZ of:

<Visualizer / FreeRTOSConfig.h>

So scale = 1000000/100 (tick / sec) = 10000, but we still do

not know what unit to the next scale, becauseconfigTICK_RATE_HZ only frequency, which is the "per 

unit time, there are several tick", the official did not define

this unit what time it is.

However, we note that the use of the manual

mentioned, FreeRTOS management task in time, there

is a API - vTaskDelay () can be used to make Task 

 pause for some time, used as follows:

This code uses the vTaskDelay () to pause the task,

file specification parameters of this function is an

integer constant if the unit is ticks, ie incoming

integer as: The above program vTaskDelay (500),

will be suspended 500 ticks, and We pass the

 parameter code is 500 / portTICK_RATE_MS, so

you can make notes said task pause 500 ms (10 ^

-3 second), so n / portTICK_RATE_MS is ms, but

at this time should not be ticks of n (the result of 

our discussion)

Then we chase portTICK_RATE_MS definition:

<freertos-basic / freertos / libraries / FreeRTOS / portable / GCC / ARM_CM3 / portmacro.h>

(In v8.2.1, portTICK_RATE_MS

was renamed to

 portTICK_PERIOD_MS)

i - FreeRTOS https://translate.googleusercontent.com/translate_c?depth=1&hl=id&ru...

0/2015 5:52 19 of 23

Page 20: Wiki - FreeRTOS

7/17/2019 Wiki - FreeRTOS

http://slidepdf.com/reader/full/wiki-freertos 20/23

At this point, we down as follows:

.. Code-block :: text

vTaskDelay () the parameter is tick units vTaskDelay (500 / portTICK_RATE_MS) = vTaskDelay (500/1000 / configTI

The original blind spot is that the "magnitude" Take 1000, it would become 1ms 1000ms, is actually the "value" multiplied by 1000, when 1

ms corresponding value of 1000 is the corresponding value us

subproblem: return equation is not accurate, because (reload - current) / reload always 0, (because int / int), which is part of have to

try to improve, but not return float / double (WHY?)

 jserv: conduct division, FPU may not be enabled

Back to Contents

Q23. FreeRTOS how to catch up with yourself?

Why know vTaskDelete (NULL) The NULL is a task in itself? **

In task.c (line 400) among us to find the vTaskDelete (NULL) as a solid macro:

.. Code-block :: c

void vTaskDelete (TaskHandle_t xTaskToDelete) {TCB_t * pxTCB; taskENTER_CRITICAL (); {/ * If null is passed in

Under what circumstances, will perform to vTaskDelete (NULL) do? In case this code will execute an infinite loop when it?

FreeRTOS task function because there are not allowed to return, he was not allowed to perform to the last line, so if you do this task, you

should delete this task (Reference: http://redmilk525study.blogspot.tw/2014/09/freertos-task- management.html )

There is a possibility that, if an execution error (fail) occurs in the loop, you need to jump out of the loop and terminate (himself) to

 perform, then you need to remove yourself vTaskDelete wrong example occurred:

1. If a task today is to access a database, but the database or data table does not exist, it should be the end

Q24. The usStackDepth how to calculate his space?

In FreeRTOS inside, usStackDepth set 100, assuming that each stack is 16 bits wide, he occupied memory space is 200 bytes, the value

specified is stacked stack space (stack size) can keep the number of word (4 bytes), If set to 100, the system will allocate 400 bytes to the

task, there is no easy way to calculate how much space a task in the end, most of the practices are simply given a first advance estimate of 

the value, and then with the task operation Message to adjust.

Q25. Why configMAX_PRIORITIES to -1?

The problem is in thinking: if configMAX_PRIORITIES set to 10, why can not assign 10 to a task?

From pxReadyTasksLists [uxTopReadyPriority] looks

ready list should be different for each index

showing priority (in other words, the same index of 

the ready list of tasks should be the priority of the

same)

Therefore, in order to configure the length of the

ready list, and only from 0 ~ priority - 1, that is,

you are to make ready list length is 10

(representing the priority 0 - 9), then you should configMAX_PRIORITY though set to 10 , but only when the highest assign permissions

configMAX_PRIORITY, in fact, I just have a 1 if the array is simple to understand 10 the definition of priority, in fact, write the program is to define 0

9 of it, start counting from 0 is indeed right.

Back to Contents

Q26. Really put to the ready list of what? Is placed handle?

i - FreeRTOS https://translate.googleusercontent.com/translate_c?depth=1&hl=id&ru...

0/2015 5:52 20 of 23

Page 21: Wiki - FreeRTOS

7/17/2019 Wiki - FreeRTOS

http://slidepdf.com/reader/full/wiki-freertos 21/23

<Freertos / libraries / FreeRTOS / include / task.h # L345>

.. Code-block :: c

#define xTaskCreate (pvTaskCode, pcName, usStackDepth, pvParameters, uxPriority, pxCreatedTask) xTaskGenericCre

(This is the same line three lines, not easy to read and broken lines)

Here the xTaskGenericCreate () packaged xTaskCreate (), so the main the call vTaskCrate () actually call xTaskGenericCreate ()

Then call <freertos / libraries / FreeRTOS / tasks.c # L551> of xTaskGenericCreate, in xTaskGenericCreate we find the task to joinreadyList place (# 704):

.. Code-block :: c prvAddTaskToReadyList (pxNewTCB);

So this is actually the task of the TCB join readyList

How to identify the task that it? (( configASSERT (pxTaskCode); not registered taskCode, configASSERT () is used to test)) in line 621

(xTaskGenericCreate):

.. Code-block :: c

. / * Setup the newly allocated TCB with the initial state of the task * / prvInitialiseTCBVariables (pxNewTCB,

Seen here with pcName did not taskCode, we know pcName only do developers recognize, do not do systems management, so catch up

with the following

.. Code-block :: c

#if (portUSING_MPU_WRAPPERS == 1) {pxNewTCB-> pxTopOfStack = pxPortInitialiseStack (pxTopOfStack, pxTaskCode, p

Should be recorded in the TCB because the starting address of the stack, there pxTaskCode, not with handle! (However, if the handle is

 pointing pxTopOfStack ???)

handle: (Taiwan: control code in: handle) is a practical significance for access to the task of "indicators", he was to provide an

external system or program with reference to the current task 

For example: delete task 

.. Code-block :: c

vTaskCreate (..., taskA, ...)

When we want to call vTaskDelete to delete taskA, in order to allow access to taskA vTaskDelete the memory address, and we want to pass

a pointer to vTaskDelete taskA indicator, this indicator is the handle

Establishing handle as follows:

.. Code-block :: c

xTaskHandle handleTaskA; // establish an index used to point taskA the handle variable vTaskCreate (.., taskA,

Q27. FreeRTOS Where pcCurrentTCB to update this pointer? Pointing latest task is running?

This question is to explore how to use scheduler, still working ... to be continue.

Q28. Why not use the linked-list to record priority value?

Because linked-list to go to sort the words, there are N, there may be n ^ 2 or nlogn time complexity, and the array can do random access,

which in priority as the index of the ready list, it will be more than linked -list more direct access to the specified priority

Use uxTopReadyPrioirty is because the space for time, the search will only constant time complexity

Q29. XListEnd where?

xLIST the xListEnd is xLIST (linked-list?) tails

i - FreeRTOS https://translate.googleusercontent.com/translate_c?depth=1&hl=id&ru...

0/2015 5:52 21 of 23

Page 22: Wiki - FreeRTOS

7/17/2019 Wiki - FreeRTOS

http://slidepdf.com/reader/full/wiki-freertos 22/23

Q30. What FreeRTOS the event definition? Is synchronous or asynchronous mechanism?

-Event Bits are used to indicate if an event has occurred or not Event bits are often referred to as event flag

group has a lot of bit, representing

an event task is waiting, and not

necessarily all of the bit will be

used to see how many task event

task waits for example:

.. Code-block :: text

A message has been received

TCB structure there are two

xListItem: xGenericListItem and xEventListItem

.. Code-block :: c

xListItem xGenericListItem; / * to record task of TCB in FreeRTOS ready and blocked queue position * / xListIte

Regardless xGenericListItem or xEventListItem, are xListItem_t patterns, the structure is defined in list.h:

.. Code-block :: c

struct xLIST_ITEM {listFIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE configLIST_VOLATILE TickType_t xItemValue; struct

Back to Contents

Q31. How do you know which task is now in a state? Code corresponding to the state diagram where?

Task four states blocked ('B'), ready ('R'), deleted ('D') or suspended ('S')

vTaskList (buf) will be written into the task all the information within buf, after then print out the contents of buf 

.. Code-block :: c

fio_printf (1, "\ n \ rName State Priority Stack Num \ n \ r"); fio_printf (1, "************************* *****

We can know in which state task 

.. Code-block :: text

vTaskList () calls uxTaskGetSystemState (), then formats the raw data generated by uxTaskGetSystemState () into

Q32. Videos about pxStack and pxTopOfStack the memory map (with gdb to trace)

2015 Spring Semester v8.2.1 version

<Freertos / libraries / FreeRTOS / portable / GCC / ARM_CM3 / port.c>

.. Code-block :: c

. / * * See header file for description * / StackType_t * pxPortInitialiseStack (StackType_t * pxTopOfStack, Ta

Reference Lab33 use "(gdb) target: remote" + "info registers" to observe scratchpad contents, and in freertos-basic / tool / gdbscript in there

were already target: remote 3333 a, freertos / mk / qemu.mk Call qemu and direct access to the gdb, so you can use info registers to

observe, below is pxPortStackInitialise () after finished BSR Figure

i - FreeRTOS https://translate.googleusercontent.com/translate_c?depth=1&hl=id&ru...

0/2015 5:52 22 of 23

Page 23: Wiki - FreeRTOS

7/17/2019 Wiki - FreeRTOS

http://slidepdf.com/reader/full/wiki-freertos 23/23

Q33. In FreeRTOS inside, its pid where are you? How do I know the task id information?

FreeRTOS create a new task in different ways and Linux, the former is vTaskCreate (), if there is return, will return pdPass task or error to

indicate the success of the establishment, if you want the program to identify this task, when we must create vTaskCreate a given task TCB

used to record the address of the starting handle index, and therefore there is no PID FreeRTOS

FreeRTOS through a task pxCurrentTCB indicators to access basic information about the current point, that if you want to know the task 

information, are to access TCB, 2007 years of data show that seems to be through the access pxCurrentTCB-> uxTCBNumber to get task 

number, but has no current project of TCB

As far as using the handle to get the task id is wrong, because the handle is pointing to the TCB address, he also access TCB

Back to Contents

Reference material

The Architecture of Open Source Applications: FreeRTOS

Simplified Chinese translation

Study of an operating system: FreeRTOS

FreeRTOS immediate core Practical Guide

i - FreeRTOS https://translate.googleusercontent.com/translate_c?depth=1&hl=id&ru...