Analysis of---Based on ti cc254x osal
When the tool chain configuration is complete, sourceinsight to you to show a source project, without the help of Baidu and development documents, in one or two hours to understand the source of the composition of the framework and interface, for rapid development?
" how to quickly understand a new embedded operating system " We have analyzed how to quickly understand Osal task scheduling and inter-mission communication (in fact, Osal just resembles a multitasking operating system), and then understand the OASL message generation and processing process, We'll be able to develop it quickly.
First, the source of the message
Embedded system message includes two kinds, one is the system message, including low power, hot Plug and so on, by the system process to deal with, second, the user message, including timer, button, serial, drawing and other messages, by the application process processing. For Ti cc254x Osal, we understand the timer, key, UART is enough.
Second, HAL
Osal provides the user with the HAL Hardware Abstraction layer, which encapsulates the hardware modules of the cc254x, such as timer, key, UART, LED, LCD, Flash, ADC and so on, and provides the user with the operation interface of the hardware module.
CC254X is a low-power Bluetooth integrated chip, the user's product and circuit design will generally refer to the official circuit, and osal for the official approach to the typical circuit design of the system library and interface, the user's code only need to follow the HAL interface provided by the call can be implemented function, Without the need for GPIO-level driver programming to implement the functionality of the module.
For CC254X programming is application programming, is concerned about the HAL interface, can be considered as a hardware-based API interface, and the circuit peripheral functions are relatively fixed, such as LED, LCD, UART used PIN pin is relatively fixed, so call the simple HAL layer interface can realize the function While driver programming is developed for SOC on-chip resources, it needs to be accessed and controlled according to the datasheet explicit physical address resources of the SOC, and provides the API interface to the user. The difference between the two can be understood by the meaning of the HAL hardware abstraction layer. Of course, the understanding of SOC datasheet also helps HAL interface programming.
Third, Timer
For Timer timer interface, it is usually to set the timer and write the callback function when the timer time arrives. The initialization function of the timer module is usually done by the system initialization.
Osal the HAL layer code for the timer is not transparent to the user, we can understand that the HAL layer of the timer is the hardware-related operation of setting up the timer module, and realizes the service process when the timer is interrupted. The wrapper interface of the osal timer is actually encapsulated on the basis of the HAL layer. The main interfaces provided are as follows:
Uint8osal_start_timerex (uint8 TaskID, UInt16 event_id, UInt32 timeout_value)
TaskID identifies which target task to handle this timed arrival message, that is, when timed, the Timer interrupt server function writes the EVENT_ID message to the taskevents[taskid of the target task; event_id can be customized by the user; timeout The _value is a timed time, 1 milliseconds.
This timing interface does not set the callback function at timed completion, but instead sends an event to the target task when the timer is completed. This event is detected during the execution of the target task and the corresponding processing is performed.
Iv. UART
Uarthal layer code for the user is transparent, for user programming, the most important thing is the serial port initialization (baud rate), serial input, serial output.
1. Serial Initialization
Voidnpi_inittransport (npicback_t npicback)
The initialization of the serial port does not take the TaskID parameter, it is a global system-level interface. The use of serial port is generally used to interrupt the serial input, non-disruptive direct serial port output. This function sets the baud rate to 115200.
The Npicback is a callback function that the serial HAL provides to the user, which invokes the callback function when the string is broken. The following events are broken in the string:
In general, we will be in the callback function to achieve serial port reception, such as the implementation of serial port transmission mode. The callback interface is declared as follows:
Typedefvoid (*npicback_t) (uint8 port, uint8 event)
Port is UART0 or UART1, and event is a serial interrupt event.
2. Serial input
Uint16npi_readtransport (uint8 *buf, UInt16 len)
3. Serial output
Uint16npi_writetransport (uint8 *buf, UInt16 len)
From these interfaces the prefix is the NPI, and the real meaning is the network Processor Interface (NPI), which represents the so-called web Transport layer. In fact, just a higher level of data input and output. The bottom of the NPI can be UART, SPI, USB, and so on. We use the UART here by default.
V. Key message sources and processing
1. Thinking before the code is understood
1) The key message is supposed to be related to the application, so it must be bound to a certain taskid. In this simple embedded system, it is generally a task called the UI to handle the key messages uniformly.
2) According to the previous article and the analysis of the previous timer, Osal is designed to send event event_id to the target task, that is, set taskevents[tasked]. We can imagine that when the key is interrupted (or the key is polled) the key is detected and a key event is sent to the target task. But, we think again, send a key event enough? It is obvious that the taskevents element is 16bit, each bit represents an event, representing only 16 events, even if the 16 event is used to denote different keys, it is not enough. Because the system may have more buttons Ah, if this design extensibility is too bad. In fact, it only sends a Key_change event, and the key value is sent to the system's message queue in the form of an MSG message, and the message is also marked with the target taskid.
3) above two points is the key processing mechanism of osal. For rapid user development, you need to know how to add a key or change the gpio of a key, and where is the process for handling keystrokes?
With these questions, we track the process of key processing from beginning to end. Osal the processing mechanism of key is a bit around, but the package is very interesting.
The process of real understanding of key processing mechanism should be in reverse, that is, from the process of the key to push forward, in the field teaching, the code counter-tracking can more reflect the methodology of this article. In order to be more organized, this is the beginning of the sequence.
2. Initialization
1) main->haldriverinit->halkeyinit
2) Main->initboard (Ob_ready)
Onboardkeyintenable= hal_key_interrupt_enable;
Halkeyconfig (onboardkeyintenable, onboard_keycallback);
The relevant code is modified here in HAL_KEYS.C and hal_keys.h, to increase the key or modify the key settings.
Onboard_keycallback is the callback function for the key interrupt. We'll expand the implementation process in the next step and now trace where this callback will be invoked. We start tracking from the source of the interruption.
3. Interruption of the execution process
4. Process of the HAL Layer task
Phalkeyprocessfunction is the onboard_keycallback that was previously set in the Halkeyconfig interface and continues to track the implementation of this function:
What this registeredkeystaskid is, is the task ID that handles the keystroke message. Where is it initialized?
5. Initialization of the key handling task
main-> osal_init_system-> osalinittasks-> Simplebleperipheral_init
Registerforkeys (Simplebleperipheral_taskid)
That is, in this function to assign Simplebleperipheral_taskid to Registeredkeystaskid, that is, simplebleperipheral corresponding task to process the message.
6. Handling of keys
The key handling that the user adds is in the Simplebleperipheral_handlekeys function.
Please step by step to confirm the 1th, the code understanding before the thinking.
Happy holidays!
More original embedded Linux,iot, Bluetooth WiFi development technology share please pay attention to the public number: embedded Penguin ring
&NBS P , &NB Sp , &NB Sp , &NB Sp , &NB Sp , &NB Sp , &NB Sp , &NB Sp , &NB Sp , &NB Sp , &NB Sp , &NB Sp , &NB Sp , &NB Sp , &N Bsp , &NB Sp , &NB Sp , &NB Sp
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
How to quickly understand a new embedded operating system (cont.)