📄 misc_synchronization.htm
字号:
<html><!-- InstanceBegin template="/Templates/helpnav.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<!-- InstanceBeginEditable name="doctitle" -->
<title>Driver Support Routines: Synchronization</title>
<!-- InstanceEndEditable -->
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
<!-- InstanceParam name="HeaderColor" type="color" value="#0000FF" -->
<!-- InstanceParam name="FooterColor" type="color" value="#0000FF" -->
<!-- InstanceParam name="NavBackgroundColor" type="color" value="#FFFFFF" -->
<!-- InstanceParam name="BodyBackgroundColor" type="color" value="#FFFFFF" -->
<link href="CodeTHelp.css" rel="stylesheet" type="text/css">
</head><a name="TopTopic"></a>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="100%" border="0" cellspacing="0" cellpadding="4">
<tr>
<td width="40%" rowspan="2" bgcolor="#0000FF"><a href="http://www.codetelligence.com"><img src="Images/codetelligence_lrg.gif" name="image" width="252" height="40" border="0"></a></td>
<td width="60%" height="62" bgcolor="#0000FF">
<font color="#FFFFFF" size="5" face="Arial, Helvetica, sans-serif"><strong>Embedded SDIO Driver Kit Help </strong></font></td>
</tr>
</table>
<table width="100%" border="0" cellspacing="10" cellpadding="0">
<tr>
<td width="93%"><font face="Arial, Helvetica, sans-serif">
<p class="Topic"><!-- InstanceBeginEditable name="SubTemplate" --> Synchronization<!-- InstanceEndEditable --> </p>
</font></td>
<td><!-- InstanceBeginEditable name="NavBack" --><a href="misc_debugging.htm"><img src="Images/leftarrow.gif" width="27" height="32" border="0"></a><!-- InstanceEndEditable --></td><td><!-- InstanceBeginEditable name="Nav" --><a href="reference_top.htm"><img src="Images/rightarrow.gif" width="27" height="32" border="0"></a><!-- InstanceEndEditable --></td>
</tr>
</table>
<hr>
<table width="100%" border="0" cellspacing="0" cellpadding="15">
<tr><td>
<!-- InstanceBeginEditable name="Help Content" -->
<OBJECT type="application/x-oleobject" classid="clsid:1e2a7bd0-dab9-11d0-b93a-00c04fc99f9e">
<param name="Keyword" value="Driver Support Routines: Synchronization">
</OBJECT>
<p class="BODYTEXT">The SDK defines a set of synchronization primitives for os-independent
portions of code. These primitives are usable in a majority of situations,
however in some instances (synchronizing with true ISRs) an OS dependent method
must be employed. These primitives protect access to data structures between
different execution contexts. These execution contexts could be threads, worker
tasks and even threads/tasks on separate processors. Some synchronization
primitives can potentially block and force a rescheduling of the current execution
context.
This
may not be legal in all types of contexts and is dependent on the operating
system. When developing a driver it is highly recommended that the DEBUG macro
be defined
to enable
assertions
in
the synchronization
primitives. This will alert the developer when a synchronization function is
used in the wrong context.</p>
<p class="HEADING3">Critical Sections:</p>
<p class="BODYTEXT">This is a fast synchronization lock.
Critical sections can be called from any context and is typically used to protect
sections of code between processors. Critical sections should only be used
to protect small sections of code. A critical section object <font face="Courier New, Courier, mono">(OS_CRITICAL_SECTION)</font> can
be initialized with <font face="Courier New, Courier, mono"><a href="Support_Reference.htm#FUNC_CriticalSectionInit">CriticalSectionInit()</a></font> .
A critical section is entered using <font face="Courier New, Courier, mono"><a href="Support_Reference.htm#FUNC_CriticalSectionAcquire">CriticalSectionAcquire()</a></font> and
on exit the code should call <font face="Courier New, Courier, mono"><a href="Support_Reference.htm#FUNC_CriticalSectionRelease">CriticalSectionRelease()</a>.</font></p>
<p class="HEADING3">Semaphore:</p>
<p class="BODYTEXT">A semaphore is appropriate
where execution must wait (block) for a resource before continuing.
Semaphores can also be used to provide mutually exclusive access
to a data structure (also known as a mutex). A mutex can be implemented as
a semaphore whose
initialization count is set to one. Semaphores will block the calling context
when the semaphore count is zero, allowing the OS to continue scheduling
other
threads/tasks.
A semaphore
should
be used
for
synchronizing
execution
where the processing time could be long. A semaphore object (<font face="Courier New, Courier, mono">OS_SEMAPHORE</font>)
is initialized with <font face="Courier New, Courier, mono"><a href="Support_Reference.htm#FUNC_SemaphoreInitialize">SemaphoreInitialize()</a></font>,
which takes an initial count. Each time <font face="Courier New, Courier, mono"><a href="Support_Reference.htm#FUNC_SemaphorePendInterruptable">SemaphorePendInterruptable()</a></font> is
called, the count is checked for zero and decremented if not zero. If the count
is zero the calling context
is blocked until the semaphore count is incremented past zero using <font face="Courier New, Courier, mono"><a href="Support_Reference.htm#FUNC_SemaphorePost">SemaphorePost()</a></font>.
The following code demonstrates the use of a semaphore:</p>
<pre>
status = SemaphoreInitialize(&semLock,1);
if (!SDIO_SUCCESS(status)) {
// failed to create semaphore...
}
if (!SDIO_SUCCESS(status = SemaphorePendInterruptable(&semlock))) {
// failed ...
}
// ... acquired semaphore
// release semaphore
if (!SDIO_SUCCESS(status = SemaphorePost(&semlock))) {
// failed....
}
</pre>
<p class="HEADING3">ISR Synchronization:</p>
<p class="BODYTEXT">Host controller drivers often deal with the synchronization
of a hardware interrupt routine. This should not be confused with SDIO IRQs
which execute in a pseudo thread-like context. The os-independent primitives
are not suitable for this task and the
driver
writer
should utilize an OS-specific ISR synchronization
method. </p>
<p class="BODYTEXT"> </p>
<p class="BODYTEXT"> </p>
<p class="BODYTEXT"><center>
</center><br>
<center>
</center></p>
<p class="BODYTEXT"> </p>
<p><br>
</p>
<!-- InstanceEndEditable -->
<br/></table></td></tr>
<table width="100%" border="0" cellspacing="0" cellpadding="2" >
<tr> <td><div align="right"><a href="#TopTopic">Back to top</a></div></td></tr>
<tr bgcolor="#0000FF">
<td>
<font color="#FFFFFF"face="Arial, Helvetica, sans-serif"><strong>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -