1, CC2541 Bluetooth 4.0 Chip Intermediate Tutorial--based on osal operating system Operation process Understanding + timers and serial port routines

Source: Internet
Author: User

This article is based on a week CC2541 notes summary

Suitable for overview and quick index of knowledge--

All Links:

Intermediate Tutorial-osal Operating system \osal operating system-a preliminary study of experimental osal

"Insert" sourceinsight-Engineering Establishment method

Intermediate Tutorial-osal Operating System (Osal System solution basic routines)

Intermediate Tutorial-osal Operating system (learn more about-oled && normal keys and 5-directional buttons-interrupts!!!) This system drive layer is not the same as the application layer ~

Intermediate Tutorial-osal Operating system (adc-photoresistors)

Osal Operating System-experiment 16 serial port baud rate extension

Osal operating system-experimental at command preliminary

Osal operating System-experimental 20 simulated IIC communication + hardware IIC (Mpu6050)

Osal operating system-experimental PWM output (change duty duty)

Osal Operating System-Lab 24 watchdog Wachdog

Osal operating System-experimental SNV internal flash data Read and write

Osal Operating System-experimental 29 system sleep level study

Osal Operating System-experiment 31 slave broadcast power modification

1, the basic process of exploration

Osal's English full name is called "OS abstraction Layer", operating system, born in TI released ZigBee series Chip period, 10 years of history

System Basic Operation Flow:

The >> main function is the basic system initialization and then enters the

Osal_start_system ();
cycle, continuous detection of flag bits, according to different markers to perform different tasks
Look back at the cycle--

1 intMainvoid)2 {3     /*Initialize Hardware*/4Hal_board_init ();//Initialize clock stable clock and so on5 6     //Initialize Board I/O7     //cold start, turn off the LED lights with interrupts, while the next various initialization is undisturbed8 Initboard (ob_cold);9 Ten     /*Initialze the HAL driver*/ One    Haldriverinit (); Initialization of various drivers, such as keys, LCD, ADC, USB, UART, etc. A  -     /*Initialize NV System*/ -     //SNV A flash,4kb space for storing paired data or your user-defined data internally the osal_snv_init (); -  -     /*Initialize LL*/ -  +     /*Initialize the operating system*/ - //OASL operating system initialization, including memory allocation, Message Queuing, timers, power management and tasks such as Osal_init_system (); A  at     /*Enable interrupts*/ -Hal_enable_interrupts ();//turn on global interrupts -  -     //Final Board Initialization -Initboard (Ob_ready);//set flag indicating system initialization complete -  in #ifDefined (power_saving) -     //If you enable low power consumption, start the low power mode, to Osal_pwrmgr_device (pwrmgr_battery); + #endif -     /* the Low-Power section * 1. How to always be in PM1 $ Osal_pwrmgr_device (pwrmgr_always_on);Panax Notoginseng 2. How to enter PM2 - Osal_pwrmgr_device (pwrmgr_battery), which enters PM2 mode when it is idle the 3. How to enter PM3 + Disconnect when there is a connection, stop the broadcast when there is a broadcast, and confirm that all scheduled tasks that you have created are closed. A the system should enter PM3 mode, only external interrupt wake-up the     */ +  -     /*Start osal*/ $    Osal_start_system ();//No Return from Here46/* Osal operating system startup, is actually a large cycle, just check the corresponding flag bit, 47 to specify the corresponding task, see here, students should go where Look at it? Actually, this is the end of it? So where did our app go? 48 is actually initialized in the above function Osal_init_system, now go back and look the Osal_init_system, inside this function, we know. -     */Wuyi     return 0; the}
>> responsible for task traversal (i.e., how to dispatch transactions) ~

Osal_start_system (); Osal_run_system (void) has been executed in the loop: Traverse all events, find one to execute the event, and no event to hibernate

>> process of initialization

Osal_init_system ();---->

Osalinittasks ();//Initialize system tasks, this task initialization is very critical---->

Simplebletest_init (TaskID); And this is our application initialization---->

1 voidsimplebletest_init (uint8 task_id)2 {3     //Save task ID to global variable4Simplebletest_taskid =task_id;5 6     //LCD Display7Hallcdwritestring ("Simplebletest 2", hal_lcd_line_1);8 9     //Setup A delayed profile startupTen     /*11 set up a task, the purpose of this is to follow a multitasking approach to do a simplebletest_processevent is to deal with sbp_start_device_evt13 */14 Osal_se T_event (Simplebletest_taskid, sbp_start_device_evt); the}

Osal_set_event (Simplebletest_taskid, sbp_start_device_evt);//Because of multitasking,

So call this function to set a task the inside of the function is also relatively simple, is to maintain a flag array: tasksevents[task_id] |= Event_flag;

1 uint8 osal_set_event (uint8 task_id, uint16 event_flag)2 {3     if(Task_id <taskscnt)4     {5 halintstate_t intstate;6Hal_enter_critical_section (intstate);//Hold off interrupts7TASKSEVENTS[TASK_ID] |= Event_flag;//Stuff the event bit (s)8Hal_exit_critical_section (intstate);//Release interrupts9         return(SUCCESS);Ten     } One     Else A     { -         return(invalid_task); -     } the}

2,osal system basic process to further understand

2.1. Timer Routines

Timer useful function:(OSAL_TIMERS.C)

LED useful functions:(HAL_LED.C.C)

The previous section talks about moving along the initialization function into the Task Settings section:

Once this is set up, it will eventually trigger the application layer once the corresponding message comes in:

As for why, don't say it first

The rest of the routine process is basically like this!

2.2. Serial Port Routines

The callback function is used when the serial port is initialized, similar to C #, so the data receive is processed in the callback function ~

Above 95 lines, the serial port initialization function parameter is the serial port to receive the callback function----> specific as follows:

The above is the serial receive (using callback), its sending is relatively simple, call the function can:

There are several serial send functions:

Not finished ~ Follow my cc2541 categories

1, CC2541 Bluetooth 4.0 Chip Intermediate Tutorial--based on osal operating system Operation process Understanding + timers and serial port routines

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.