User Tools

Site Tools


lab2

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
lab2 [2010/02/24 23:39] natalialab2 [2010/03/19 12:50] (current) natalia
Line 39: Line 39:
 You MUST invoke OSIntEnter() and OSIntExit() in pairs. In other words, for every call to OSIntEnter() at the beginning of the ISR you MUST have a call to OSIntExit() at the end of the ISR. You MUST invoke OSIntEnter() and OSIntExit() in pairs. In other words, for every call to OSIntEnter() at the beginning of the ISR you MUST have a call to OSIntExit() at the end of the ISR.
  
-Please note that rescheduling is prevented when the scheduler is locked (see [[syntax#OS_SchedLock|OS_SchedLock()]])+Please note that rescheduling is prevented when the scheduler is locked (see OSSchedLock)
  
 == OSTaskCreate == == OSTaskCreate ==
Line 81: Line 81:
   * OS_ERR_PRIO_INVALID: if the priority you specify is higher that the maximum allowed (i.e.>= OS_LOWEST_PRIO) or, you have not specified OS_PRIO_SELF.   * OS_ERR_PRIO_INVALID: if the priority you specify is higher that the maximum allowed (i.e.>= OS_LOWEST_PRIO) or, you have not specified OS_PRIO_SELF.
   * OS_ERR_TASK_DEL: if the task is assigned to a Mutex PIP.   * OS_ERR_TASK_DEL: if the task is assigned to a Mutex PIP.
 +  * OS_ERR_TASK_NOT_EXIST: if the task you want to delete does not exist.
 +  * OS_ERR_TASK_DEL_ISR : if you tried to delete a task from an ISR.
 +
 +Please note:
 +  * To reduce interrupt latency, OSTaskDel() 'disables' the task:
 +  * by making it not ready
 +  * by removing it from any wait lists
 +  * by preventing OSTimeTick() from making the task ready to run. The task can then be 'unlinked' from the miscellaneous structures in μC/OS-II.
 +  * The function OS_Dummy() is called after OS_EXIT_CRITICAL() because, on most processors, the next instruction following the enable interrupt instruction is ignored.
 +  * An ISR cannot delete a task.
 +  * The lock nesting counter is incremented because, for a brief instant, if the current task is being deleted, the current task would not be able to be rescheduled because it is removed from the ready list. Incrementing the nesting counter prevents another task from being scheduled. This means that an ISR would return to the current task which is being deleted. The rest of the deletion would thus be able to be completed.
 +
 +== OSTaskDelReq ==
 +OSTaskDelReq function is used to notify a task to delete itself and to see if a task requested that the current task delete itself. This function is a little tricky to understand. Basically, you have a task that needs to be deleted however, this task has resources that it has allocated (memory buffers, semaphores, mailboxes, queues etc.). The task cannot be deleted otherwise these resources would not be freed. The requesting task calls OSTaskDelReq() to indicate that the task needs to be deleted. Deleting of the task is however, deferred to the task to be deleted. For example, suppose that task #10 needs to be deleted. The requesting task example, task #5, would call OSTaskDelReq(10). When task #10 gets to execute, it calls this function by specifying OS_PRIO_SELF and monitors the returned value. If the return value is OS_ERR_TASK_DEL_REQ, another task requested a task delete. Task #10 would look like this:
 +<code>
 +void Task(void *p_arg)
 +{
 +   .
 +   .
 +   .
 +   while (1)
 +   {
 +      OSTimeDly(1);
 +      if (OSTaskDelReq(OS_PRIO_SELF) == OS_ERR_TASK_DEL_REQ)
 +      {
 +         Release any owned resources;
 +         De-allocate any dynamic memory;
 +         OSTaskDel(OS_PRIO_SELF);
 +      }
 +   }
 +}
 +</code>
 +
 +Arguments:
 +  * Prio argument is the priority of the task to request the delete from
 +
 +Returns :
 +  * OS_ERR_NONE: if the task exist and the request has been registered
 +  * OS_ERR_TASK_NOT_EXIST: if the task has been deleted. This allows the caller to know whether the request has been executed.
 +  * OS_ERR_TASK_DEL: if the task is assigned to a Mutex.
 +  * OS_ERR_TASK_DEL_IDLE: if you requested to delete μC/OS-II's idle task
 +  * OS_ERR_PRIO_INVALID: if the priority you specify is higher that the maximum allowed (i.e. >= OS_LOWEST_PRIO) or, you have not specified OS_PRIO_SELF.
 +  * OS_ERR_TASK_DEL_REQ: if a task (possibly another task) requested that the running task be deleted.
 +
 +== OSTaskSuspend ==
 +OSTaskSuspend function is called to suspend a task. The task can be the calling task if the priority passed to OSTaskSuspend() is the priority of the calling task or OS_PRIO_SELF. You should use this function with great care. If you suspend a task that is waiting for an event (i.e. a message, a semaphore, a queue ...) you will prevent this task from running when the event arrives. 
 +
 +Arguments:
 +  * Prio arguments is the priority of the task to suspend. If you specify OS_PRIO_SELF, the calling task will suspend itself and rescheduling will occur.
 +
 +Returns:
 +  * OS_ERR_NONE: if the requested task is suspended
 +  * OS_ERR_TASK_SUSPEND_IDLE: if you attempted to suspend the idle task which is not allowed.
 +  * OS_ERR_PRIO_INVALID: if the priority you specify is higher that the maximum allowed (i.e. >= OS_LOWEST_PRIO) or, you have not specified OS_PRIO_SELF.
 +  * OS_ERR_TASK_SUSPEND_PRIO: if the task to suspend does not exist
 +  * OS_ERR_TASK_NOT_EXITS: if the task is assigned to a Mutex PIP
 +
 +== OSTaskResume ==
 +OSTaskResume function is called to resume a previously suspended task. This is the only call that will remove an explicit task suspension.
 +
 +Returns:
 +  * OS_ERR_NONE: if the requested task is resumed
 +  * OS_ERR_PRIO_INVALID: if the priority you specify is higher that the maximum allowed (i.e.>= OS_LOWEST_PRIO)
 +  * OS_ERR_TASK_RESUME_PRIO: if the task to resume does not exist
 +  * OS_ERR_TASK_NOT_EXIST: if the task is assigned to a Mutex PIP
 +  * OS_ERR_TASK_NOT_SUSPENDED: if the task to resume has not been suspended
 +
 +== OSTaskChangePrio ==
 +OSTaskChangePrio function allows you to change the priority of a task dynamically. Note that the new priority MUST be available.
 +
 +Returns:
 +  * OS_ERR_NONE: is the call was successful
 +  * OS_ERR_PRIO_INVALID: if the priority you specify is higher that the maximum allowed (i.e. >= OS_LOWEST_PRIO)
 +  * OS_ERR_PRIO_EXIST: if the new priority already exist.
 +  * OS_ERR_PRIO: there is no task with the specified OLD priority (i.e. the OLD task does not exist.
 +  * OS_ERR_TASK_NOT_EXIST: if the task is assigned to a Mutex PIP.
 +
 +== OSSchedLock ==
 +OSSchedLock function is used to prevent rescheduling to take place. This allows your application to prevent context switches until you are ready to permit context switching. You MUST invoke OSSchedLock() and OSSchedUnlock() in pair. In other words, for every call to OSSchedLock() you MUST have a call to OSSchedUnlock().
 +
 +== OSSchedUnlock ==
 +OSSchedUnlock function is used to re-allow rescheduling. You MUST invoke OSSchedLock() and OSSchedUnlock() in pair. In other words, for every call to OSSchedLock() you MUST have a call to OSSchedUnlock().
 +
 +== OSTimeDly ==
 +OSTimeDly function is called to delay execution of the currently running task until the specified number of system ticks expires. This, of course, directly equates to delaying the current task for some time to expire. No delay will result If the specified delay is 0. If the specified delay is greater than 0 then, a context switch will result.
 +
 +Arguments:
 +  * "ticks" is the time delay that the task will be suspended in number of clock 'ticks'. Note that by specifying 0, the task will not be delayed.
 +
 +== OSTimeDlyHMSM ==
 +OSTimeDlyHMSM function is called to delay execution of the currently running task until some time expires. This call allows you to specify the delay time in HOURS, MINUTES, SECONDS and
 +MILLISECONDS instead of ticks.
 +
 +== OS_ENTER_CRITICAL ==
 +OS_ENTER_CRITICAL() is a macro inserts the machine instruction into your code to block all interrupts.
 +
 +== OS_EXIT_CRITICAL ==
 +OS_EXIT_CRITICAL() is a macro inserts the machine instruction to enable interrupts.
 +
 +== OSSemCreate ==
 +OSSemCreate function creates a semaphore.
 +
 +Arguments:
 +  * "cnt" is the initial value for the semaphore. If the value is 0, no resource is available (or no event has occurred). You initialize the semaphore to a non-zero value to specify how many resources are available (e.g. if you have 10 resources, you would initialize the semaphore to 10). 
 +
 +Returns:
 +  * (void *)0 if no event control blocks were available. Otherwise return is a pointer to the event control block (OS_EVENT) associated with the created semaphore.
 +
 +== OSSemPost ==
 +OSSemPost function signals a semaphore Argument pevent is a pointer to the event control block associated with the desired semaphore.
 +
 +Returns:
 +  * OS_ERR_NONE: The call was successful and the semaphore was signaled.
 +  * OS_ERR_SEM_OVF: If the semaphore count exceeded its limit. In other words, you have signalled the semaphore more often than you waited on it with either OSSemAccept() or OSSemPend().
 +  * OS_ERR_EVENT_TYPE: If you didn't pass a pointer to a semaphore.
 +  * OS_ERR_PEVENT_NULL: If 'pevent' is a NULL pointer.
 +
 +== OSSemPendAbort ==
 +OSSemPendAbort function aborts & readies any tasks currently waiting on a semaphore. This function should be used to fault-abort the wait on the semaphore, rather than to normally signal the semaphore via OSSemPost().
 +==== Prelab studies ====
 +Please make sure to read and understand the license agreements listed below:
 +  * {{:legalnotice_os_only.pdf}}
 +  * {{:micrium-sla-cpu.pdf}}
 +  * {{:micrium-sla-p1.pdf}}
 +  * {{:micrium-sla-pl.pdf}}
 +Also read the following study guides and application notes:
 +  * {{:an1004_the_10-minute_guide_to_rtos_.pdf}}
 +  * {{:ucos-ii-refman.pdf}}
 +  * {{:quickrefchart-color.pdf}}
 +  * {{:task-state-diagram.pdf}}
 +  * {{:an1002_mutual_exclusion_semaphores_.pdf}}
 +  * {{:an1005_inter-process_communication_.pdf}}
 +  * {{:an1007a_c_os-ii_and_event_flags_.pdf}}
 +  * {{:ucos-ii-cfgman.pdf}}
 +
 +
 +==== Evaluation ====
 +μC/OS-II source code is divided into platform dependent and platform independent files. Platform independent files can be found in Micrium/Software/uCOS-II/Source/. Platform independent files can be found in Micrium/Software/uCOS-II/Ports/HCS12/Paged/Metrowerks/SerialMonitor/
 +
 +By study the source structure and Micrium/ReadMe/uCOS-II-RefMan.pdf briefly answer the following questions:
 +  - Write a pseudo code using μC/OS-II to create two tasks and protect their critical sections that is accessing a common variable called XYZ.
 +  - In your own words, explain how multitasking is achieved in the μC/OS-II (pay special attention to os_cpu_a.s)?
 +
 +==== Resources =====
 +  * {{:serialmonitor.zip}}
lab2.1267054784.txt.gz · Last modified: 2010/02/24 23:39 by natalia