You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ad...@apache.org on 2016/11/29 02:17:15 UTC

[2/7] incubator-mynewt-site git commit: Updated Task lesson

Updated Task lesson

Updated task lesson for latest changes


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/commit/690e7ec8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/tree/690e7ec8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/diff/690e7ec8

Branch: refs/heads/develop
Commit: 690e7ec8fec374e1d536c8bed1a8bc4e255f11a0
Parents: e1c0ab9
Author: David G. Simmons <sa...@mac.com>
Authored: Tue Nov 22 13:21:16 2016 -0500
Committer: David G. Simmons <sa...@mac.com>
Committed: Tue Nov 22 13:21:16 2016 -0500

----------------------------------------------------------------------
 docs/os/tutorials/tasks_lesson.md | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/690e7ec8/docs/os/tutorials/tasks_lesson.md
----------------------------------------------------------------------
diff --git a/docs/os/tutorials/tasks_lesson.md b/docs/os/tutorials/tasks_lesson.md
index 70801ed..5faf358 100644
--- a/docs/os/tutorials/tasks_lesson.md
+++ b/docs/os/tutorials/tasks_lesson.md
@@ -35,7 +35,7 @@ in main.c (located in apps/blinky/src):
 struct os_task work_task;
 ```
 
-A task is represented by the [*os_task*](http://mynewt.apache.org/os/core_os/task/task/#data-structures)  
+A task is represented by the [*os_task*](http://mynewt.apache.org/os/core_os/task/task/#data-structures) 
 struct which will hold the task\u2019s information (name, state, priority, etc.). A task is made up of two 
 main elements, a task function (also known as a task handler) and a task stack.
 
@@ -50,7 +50,6 @@ which are generally 32 bits, making our entire stack 1024 Bytes.
 
 ```c
   #define WORK_STACK_SIZE OS_STACK_ALIGN(256)
-  os_stack_t work_stack[WORK_STACK_SIZE];
 ```
 
 
@@ -97,13 +96,17 @@ Let\u2019s set the priority of `work_task` to 0, because everyone knows that work i
 ### Initialization
 To initialize a new task we use [*os_task_init()*](http://mynewt.apache.org/os/core_os/task/os_task_init/) 
 which takes a number of arguments including our new task function, stack, and priority. Much like `blinky_task`, 
-we\u2019re going to initialize `work_task` inside `init_tasks` to keep our main function clean.
+we\u2019re going to initialize `work_task` inside `init_tasks` to keep our main function clean. We'll set the task stack here and pass it to the `os_task_init()` function as well.
 
 ```c
 int
 init_tasks(void)
 {
     /* \u2026 */
+    os_stack_t *work_stack;
+    work_stack = malloc(sizeof(os_stack_t)*WORK_STACK_SIZE);
+    
+    assert(pstack);
     os_task_init(&work_task, "work", work_task_handler, NULL,
             WORK_TASK_PRIO, OS_WAIT_FOREVER, work_stack,
             WORK_STACK_SIZE);
@@ -151,6 +154,7 @@ os_task_init(&mytask, "mytask", mytask_handler, NULL,
 ```
 
 ##Task Priority, Preempting, and Context Switching
+
 A preemptive RTOS is one in which a higher priority task that is *ready to run* will preempt (i.e. take the 
 place of) the lower priority task which is *running*. When a lower priority task is preempted by a higher 
 priority task, the lower priority task\u2019s context data (stack pointer, registers, etc.) is saved and the new 
@@ -237,9 +241,9 @@ Set a new app location.
 $ newt target set task_tgt app=apps/mynewt_tasks_lesson
 ```
 
-Now let\u2019s take a look at our new code. First, notice that we have abandoned blinking, instead choosing t
-o use the [*console*](http://mynewt.apache.org/latest/os/modules/console/console/) and [*shell*](http://mynewt.apache.org/latest/os/modules/shell/shell/) 
-to follow our tasks through execution.
+Now let\u2019s take a look at our new code. First, notice that we have abandoned blinking, instead 
+choosing to use the [*console*](http://mynewt.apache.org/latest/os/modules/console/console/) 
+and [*shell*](http://mynewt.apache.org/latest/os/modules/shell/shell/) to follow our tasks through execution.
 
 Additionally, we have a number of different tasks:
 
@@ -398,7 +402,8 @@ rate, Task B would take over a minute to finish one cycle.
 
 Feel free to play around with the testing parameters to study the different changes yourself!
 
-##Conclusion
+###Conclusion
+
 Moving forward, tasks are just the tip of the iceberg. The [*scheduler*](http://mynewt.apache.org/latest/os/core_os/context_switch/context_switch/), 
 [*event queues*](http://mynewt.apache.org/latest/os/core_os/event_queue/event_queue/), 
 [*semaphores*](http://mynewt.apache.org/latest/os/core_os/semaphore/semaphore/), and