發表文章

目前顯示的是 3月, 2018的文章

Pointer

圖片
Pointer use ex result

Class

圖片
class 將程式的變數轉換為物件的型式 大多數class的邊寫方法都會與main當分開 分為一個.h當用來定義class中會用到的變數型態或function型態 和另一cpp執行檔用來實做.h檔中定義的各變數或function   Example1 main.c header file app file result define variables in donstructors Example2 main.c header file app file result use class constant function 當以class之變數型態定義變數時,若此定義之變數為constant則只能使用class內之constant function Example3 main.c header file app file result define class constant variable 我們知道constant variable的數值需要在定義值時順便給與,但是相同的class可以代表不同的物體,可能會有同的constant數值,這時候可以使用 member initialization list 再設定物件時定義數值。 Example4 main.c header file app file result Friend Functions 正常來說定義在class 內 private的變數不能被外部改變,但我們可以藉由定意外不function 為class 的friend function,讓這個friend function可以編輯private 內的變數。 注意當要將物件(class)傳入function 時需以指標的形式 Example5 main.c header file app file result Example

Overloading

Function Overloading Function Overloading 只要函式的輸入參數數量或是型態不同,就能夠讓多個不同功能的函式擁有一樣的名子 Example

Default Values For Parameters

Default Values For Parameters 函式的輸入參數可以在函式定義時事先給予預設值。 Example

EXTI 外部中斷

圖片
GPIO as Interrupt The external interrupt/event controller consists of up to 23 edge detectors for generating event/interrupt requests. Each input line can be independently configured to select the type (interrupt or event) and the corresponding trigger event (rising or falling or both). Each line can also masked independently. A pending register maintains the status line of the interrupt requests. GPIO Interrupt In section one (GPIOs) we have 16 interrupt lines. They are line0 to line15 and they also represent pin number. This means, PA0 is connected to Line0 and PA13 is connected to Line13 . All pins with same number are connected to line with same number. They are multiplexed to one line. PA0 and PB0 and PC0 and so on, are connected to Line0 , so you can use only one pin at one time to handle interrupt from there. PA0 and PA5 are connected to different lines, they can be used at the same time. Each line can trigger an interrupt on rising, falling or rising_falling enge on si...

Interrupt Management

圖片
Embedded real-time systems have to take actions in response to events that originate from the environment. For example, a packet arriving on an Ethernet peripheral (the event) might require passing to a TCP/IP stack for processing (the action). Non-trivial systems will have to service events that originate from multiple sources, all of which will have different processing overhead and response time requirements. In each case, a judgment has to be made as to the best event processing implementation strategy: How should the event be detected? Interrupts are normally used, but inputs can also be polled. When interrupts are used, how much processing should be performed inside the interrupt service routine (ISR), and how much outside? It is normally desirable to keep each ISR as short as possible. How events are communicated to the main (non-ISR) code, and how can this code be structured to best accommodate processing of potentially asynchronous occurrences? It is important to draw a distin...

05 Software Timer Management

圖片
Software timers are used to schedule the execution of a  function at a set time in the future , or periodically with a fixed frequency . The function executed by the software timer is called the software timer’s callback function. Software timers are implemented by, and are under the control of, the FreeRTOS kernel. They do not require hardware support, and are not related to hardware timers or hardware counters. Note that, in line with the FreeRTOS philosophy of using innovative design to ensure maximum efficiency, software timers do not use any processing time unless a software timer callback function is actually executing . To include software timer functionality: Build the FreeRTOS source file FreeRTOS/Source/timers.c as part of your project. Set configUSE_TIMERS to 1 in FreeRTOSConfig.h. Software Timer Callback Functions void ATimerCallback( TimerHandle_t xTimer ); Software timer callback functions execute from start to finish, and exit in the normal way. They should be kept ...

test

圖片
The receiving task has the lowest priority, so it will run only when both sending tasks are in the Blocked state. The sending tasks will enter the Blocked state only when the queue is full, so the receiving task will execute only when the queue is already full. Therefore, it always expects to receive data even when it does not specify a block time. //code #include "FreeRTOS.h" #include "task.h" #include "stm32f4xx.h" #include "queue.h" //Task1 // ---------------------------------------------------------------------------- QueueHandle_t xQueue; static void vSenderTask( void *pvParameters ) { int32_t lValueToSend; BaseType_t xStatus; /* Two instances of this task are created so the value that is sent to the queue is passed in via the task parameter - this way each instance can use a different value. The queue was created to hold values of type int32_t, so cast the parameter to the required type. */ lValueToSend = ( int32_t ) pvParame...

freeRTOS Queu Management

圖片
‘Queues’ provide a task-to-task, task-to-interrupt, and interrupt-to-task communication mechanism. Characteristics of a Queue Data Storage A queue can hold a finite number of fixed size data items. The maximum number of items a queue can hold is called its ‘length’. Both the length and the size of each data item are set when the queue is created. Queues are normally used as First In First Out (FIFO) buffers, where data is written to the end (tail) of the queue and removed from the front (head) of the queue. There are two ways in which queue behavior could have been implemented: 1. Queue by copy Queuing by copy means the data sent to the queue is copied byte for byte into the queue 2. Queue by reference Queuing by reference means the queue only holds pointers to the data sent to the queue, not the data itself. FreeRTOS uses the queue by copy method. Queuing by copy is considered to be simultaneously more powerful and simpler to use than queueing by reference becaus...

freeRTOS Scheduling Algorithms(任務調度器設定)

圖片
Prioritized Pre-emptive Scheduling with Time Slicing(具有時間片斷的優先優先調度) sets the FreeRTOS scheduler to use a scheduling algorithm called ‘Fixed Priority Pre-emptive Scheduling with Time Slicing’ (設定程此模式的方法) #define configUSE_PREEMPTION 1//(在FreeRTOSConfig.h內) #define configUSE_TIME_SLICING    1//(在FreeRTOS.h內) 關鍵詞解釋 Fixed Priority Scheduling algorithms described as ‘Fixed Priority’ do not change the priority assigned to the tasks being scheduled, but also do not prevent the tasks themselves from changing their own priority, or that of other tasks. Pre-emptive Pre-emptive scheduling algorithms will immediately ‘pre-empt’ the Running state task if a task that has a priority higher than the Running state task enters the Ready state. Being pre-empted means being involuntarily (without explicitly yielding or blocking) moved out of the Running state and into the Ready state to allow a different task to enter the Running state. Time Slicing Time slicing is used...

freeRTOS Deleting a Task

vTaskDelete() A task can use the vTaskDelete() API function to delete itself, or any other task. Note that the vTaskDelete() API function is available only when INCLUDE_vTaskDelete is set to 1 in FreeRTOSConfig.h. Deleted tasks no longer exist and cannot enter the Running state again. It is the responsibility of the idle task to free memory allocated to tasks that have since been deleted. Therefore, it is important that applications using the vTaskDelete() API function do not completely starve the idle task of all processing time . Note: Only memory allocated to a task by the kernel itself will be freed automatically when the task is deleted. Any memory or other resource that the implementation of the task allocated must be freed explicitly. void vTaskDelete( TaskHandle_t pxTaskToDelete ); pxTaskToDelete The handle of the task that is to be deleted (the subject task)—see the pxCreatedTask parameter of the xTaskCreate() API function for information on obtaining handles t...

freeRTOS Changing the Priority of a Task

vTaskPrioritySet() The vTaskPrioritySet() API function can be used to change the priority of any task after the scheduler has been started. Note that the vTaskPrioritySet() API function is available only when INCLUDE_vTaskPrioritySet is set to 1 in FreeRTOSConfig.h. void vTaskPrioritySet( TaskHandle_t pxTask, UBaseType_t uxNewPriority ); pxTask The handle of the task whose priority is being modified (the subject task)—see the pxCreatedTask parameter of the xTaskCreate() API function for information on obtaining handles to tasks. A task can change its own priority by passing NULL in place of a valid task handle. uxNewPriority The priority to which the subject task is to be set. This is capped automatically to the maximum available priority of (configMAX_PRIORITIES – 1), where configMAX_PRIORITIES is a compile time constant set in the FreeRTOSConfig.h header file uxTaskPriorityGet() The uxTaskPriorityGet() API function can be used to query the priority of a task. Note that ...