📄 devapi-api.html
字号:
<!-- Copyright (C) 2009 Free Software Foundation, Inc. -->
<!-- This material may be distributed only subject to the terms -->
<!-- and conditions set forth in the Open Publication License, v1.0 -->
<!-- or later (the latest version is presently available at -->
<!-- http://www.opencontent.org/openpub/). -->
<!-- Distribution of the work or derivative of the work in any -->
<!-- standard (paper) book form is prohibited unless prior -->
<!-- permission is obtained from the copyright holder. -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>The API</TITLE
><meta name="MSSmartTagsPreventParsing" content="TRUE">
<META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REL="HOME"
TITLE="eCos Reference Manual"
HREF="ecos-ref.html"><LINK
REL="UP"
TITLE="Device Driver Interface to the Kernel"
HREF="devapi-device-driver-interface-to-the-kernel.html"><LINK
REL="PREVIOUS"
TITLE="Synchronization Levels"
HREF="devapi-synchronization-levels.html"><LINK
REL="NEXT"
TITLE="File System Support Infrastructure"
HREF="fileio.html"></HEAD
><BODY
CLASS="SECTION"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>eCos Reference Manual</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="devapi-synchronization-levels.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
>Chapter 13. Device Driver Interface to the Kernel</TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="fileio.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="SECTION"
><H1
CLASS="SECTION"
><A
NAME="DEVAPI-API"
>The API</A
></H1
><P
>This section details the Driver Kernel
Interface. Note that most of these functions are identical to Kernel C
API calls, and will in most configurations be wrappers for them. In
non-kernel configurations they will be supported directly by the HAL,
or by code to emulate the required behavior.</P
><P
>This API is defined in the header file
<TT
CLASS="FILENAME"
><cyg/hal/drv_api.h></TT
>.</P
><DIV
CLASS="SECTION"
><H2
CLASS="SECTION"
><A
NAME="AEN6140"
>cyg_drv_isr_lock</A
></H2
><P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
>Function:</DT
><DD
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>void cyg_drv_isr_lock()</PRE
></TD
></TR
></TABLE
></DD
><DT
>Arguments:</DT
><DD
><P
>None</P
></DD
><DT
>Result:</DT
><DD
><P
>None </P
></DD
><DT
>Level:</DT
><DD
><P
>ISR</P
></DD
><DT
>Description:</DT
><DD
><P
> Disables delivery of interrupts, preventing all ISRs running. This
function maintains a counter of the number of times it is
called.
</P
></DD
></DL
></DIV
></DIV
><DIV
CLASS="SECTION"
><H2
CLASS="SECTION"
><A
NAME="AEN6163"
>cyg_drv_isr_unlock</A
></H2
><P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
>Function:</DT
><DD
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>void cyg_drv_isr_unlock()</PRE
></TD
></TR
></TABLE
></DD
><DT
>Arguments:</DT
><DD
><P
>None</P
></DD
><DT
>Result:</DT
><DD
><P
>None </P
></DD
><DT
>Level:</DT
><DD
><P
>ISR</P
></DD
><DT
>Description:</DT
><DD
><P
>Re-enables delivery of interrupts, allowing ISRs to
run. This function decrements the counter maintained by
<CODE
CLASS="FUNCTION"
>cyg_drv_isr_lock()</CODE
>, and only re-allows
interrupts when it goes to zero. </P
></DD
></DL
></DIV
></DIV
><DIV
CLASS="SECTION"
><H2
CLASS="SECTION"
><A
NAME="AEN6187"
>cyg_drv_spinlock_init</A
></H2
><P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
>Function:</DT
><DD
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>void cyg_drv_spinlock_init(cyg_spinlock_t *lock, cyg_bool_t locked )</PRE
></TD
></TR
></TABLE
></DD
><DT
>Arguments:</DT
><DD
><P
><CODE
CLASS="PARAMETER"
>lock</CODE
> - pointer to spinlock to initialize</P
><P
><CODE
CLASS="PARAMETER"
>locked</CODE
> - initial state of lock</P
></DD
><DT
>Result:</DT
><DD
><P
>None</P
></DD
><DT
>Level:</DT
><DD
><P
>Thread</P
></DD
><DT
>Description:</DT
><DD
><P
> Initialize a spinlock. The <CODE
CLASS="PARAMETER"
>locked</CODE
>
argument indicates how the spinlock should be initialized:
<TT
CLASS="LITERAL"
>TRUE</TT
> for locked or <TT
CLASS="LITERAL"
>FALSE</TT
>
for unlocked state.
</P
></DD
></DL
></DIV
></DIV
><DIV
CLASS="SECTION"
><H2
CLASS="SECTION"
><A
NAME="AEN6216"
>cyg_drv_spinlock_destroy</A
></H2
><P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
>Function:</DT
><DD
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>void cyg_drv_spinlock_destroy(cyg_spinlock_t *lock )</PRE
></TD
></TR
></TABLE
></DD
><DT
>Arguments:</DT
><DD
><P
><CODE
CLASS="PARAMETER"
>lock</CODE
> - pointer to spinlock destroy</P
></DD
><DT
>Result:</DT
><DD
><P
>None</P
></DD
><DT
>Level:</DT
><DD
><P
>Thread</P
></DD
><DT
>Description:</DT
><DD
><P
> Destroy a spinlock that is no longer of use. There should be no
CPUs attempting to claim the lock at the time this function is
called, otherwise the behavior is undefined.
</P
></DD
></DL
></DIV
></DIV
><DIV
CLASS="SECTION"
><H2
CLASS="SECTION"
><A
NAME="AEN6240"
>cyg_drv_spinlock_spin</A
></H2
><P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
>Function:</DT
><DD
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>void cyg_drv_spinlock_spin(cyg_spinlock_t *lock )</PRE
></TD
></TR
></TABLE
></DD
><DT
>Arguments:</DT
><DD
><P
><CODE
CLASS="PARAMETER"
>lock</CODE
> - pointer to spinlock to claim</P
></DD
><DT
>Result:</DT
><DD
><P
>None</P
></DD
><DT
>Level:</DT
><DD
><P
>ISR</P
></DD
><DT
>Description:</DT
><DD
><P
> Claim a spinlock, waiting in a busy loop until it is
available. Wherever this is called from, this operation
effectively pauses the CPU until it succeeds. This operations
should therefore be used sparingly, and in situations where
deadlocks/livelocks cannot occur. Also see
<CODE
CLASS="FUNCTION"
>cyg_drv_spinlock_spin_intsave()</CODE
>.
</P
></DD
></DL
></DIV
></DIV
><DIV
CLASS="SECTION"
><H2
CLASS="SECTION"
><A
NAME="AEN6265"
>cyg_drv_spinlock_clear</A
></H2
><P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
>Function:</DT
><DD
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>void cyg_drv_spinlock_clear(cyg_spinlock_t *lock )</PRE
></TD
></TR
></TABLE
></DD
><DT
>Arguments:</DT
><DD
><P
><CODE
CLASS="PARAMETER"
>lock</CODE
> - pointer to spinlock to clear </P
></DD
><DT
>Result:</DT
><DD
><P
>None</P
></DD
><DT
>Level:</DT
><DD
><P
>ISR</P
></DD
><DT
>Description:</DT
><DD
><P
> Clear a spinlock. This clears the spinlock and allows another
CPU to claim it. If there is more than one CPU waiting in
<CODE
CLASS="FUNCTION"
>cyg_drv_spinlock_spin()</CODE
> then just one of
them will be allowed to proceed.
</P
></DD
></DL
></DIV
></DIV
><DIV
CLASS="SECTION"
><H2
CLASS="SECTION"
><A
NAME="AEN6290"
>cyg_drv_spinlock_try</A
></H2
><P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
>Function:</DT
><DD
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>cyg_bool_t cyg_drv_spinlock_try(cyg_spinlock_t *lock )</PRE
></TD
></TR
></TABLE
></DD
><DT
>Arguments:</DT
><DD
><P
><CODE
CLASS="PARAMETER"
>lock</CODE
> - pointer to spinlock to try</P
></DD
><DT
>Result:</DT
><DD
><P
><TT
CLASS="LITERAL"
>TRUE</TT
> if the spinlock was claimed,
<TT
CLASS="LITERAL"
>FALSE</TT
> otherwise.</P
></DD
><DT
>Level:</DT
><DD
><P
>ISR</P
></DD
><DT
>Description:</DT
><DD
><P
> Try to claim the spinlock without waiting. If the spinlock could
be claimed immediately then <TT
CLASS="LITERAL"
>TRUE</TT
> is
returned. If the spinlock is already claimed then the result is
<TT
CLASS="LITERAL"
>FALSE</TT
>.
</P
></DD
></DL
></DIV
></DIV
><DIV
CLASS="SECTION"
><H2
CLASS="SECTION"
><A
NAME="AEN6318"
>cyg_drv_spinlock_test</A
></H2
><P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
>Function:</DT
><DD
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>cyg_bool_t cyg_drv_spinlock_test(cyg_spinlock_t *lock )</PRE
></TD
></TR
></TABLE
></DD
><DT
>Arguments:</DT
><DD
><P
><CODE
CLASS="PARAMETER"
>lock</CODE
> - pointer to spinlock to test</P
></DD
><DT
>Result:</DT
><DD
><P
><TT
CLASS="LITERAL"
>TRUE</TT
> if the spinlock is available,
<TT
CLASS="LITERAL"
>FALSE</TT
> otherwise.</P
></DD
><DT
>Level:</DT
><DD
><P
>ISR</P
></DD
><DT
>Description:</DT
><DD
><P
> Inspect the state of the spinlock. If the spinlock is not locked
then the result is <TT
CLASS="LITERAL"
>TRUE</TT
>. If it is locked then
the result will be <TT
CLASS="LITERAL"
>FALSE</TT
>.
</P
></DD
></DL
></DIV
></DIV
><DIV
CLASS="SECTION"
><H2
CLASS="SECTION"
><A
NAME="AEN6346"
>cyg_drv_spinlock_spin_intsave</A
></H2
><P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
>Function:</DT
><DD
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>void cyg_drv_spinlock_spin_intsave(cyg_spinlock_t *lock,
cyg_addrword_t *istate )</PRE
></TD
></TR
></TABLE
></DD
><DT
>Arguments:</DT
><DD
><P
><CODE
CLASS="PARAMETER"
>lock</CODE
> - pointer to spinlock to claim</P
><P
><CODE
CLASS="PARAMETER"
>istate</CODE
> - pointer to interrupt state save location</P
></DD
><DT
>Result:</DT
><DD
><P
>None</P
></DD
><DT
>Level:</DT
><DD
><P
>ISR</P
></DD
><DT
>Description:</DT
><DD
><P
> This function behaves exactly like
<CODE
CLASS="FUNCTION"
>cyg_drv_spinlock_spin()</CODE
> except that it also
disables interrupts before attempting to claim the lock. The
current interrupt enable state is saved in
<CODE
CLASS="PARAMETER"
>*istate</CODE
>. Interrupts remain disabled once
the spinlock had been claimed and must be restored by calling
<CODE
CLASS="FUNCTION"
>cyg_drv_spinlock_clear_intsave()</CODE
>.
</P
><P
> In general, device drivers should use this function to claim and
release spinlocks rather than the
non-<CODE
CLASS="FUNCTION"
>_intsave()</CODE
> variants, to ensure proper
exclusion with code running on both other CPUs and this CPU.
</P
></DD
></DL
></DIV
></DIV
><DIV
CLASS="SECTION"
><H2
CLASS="SECTION"
><A
NAME="AEN6377"
>cyg_drv_spinlock_clear_intsave</A
></H2
><P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
>Function:</DT
><DD
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>void cyg_drv_spinlock_clear_intsave( cyg_spinlock_t *lock,
cyg_addrword_t istate )</PRE
></TD
></TR
></TABLE
></DD
><DT
>Arguments:</DT
><DD
><P
><CODE
CLASS="PARAMETER"
>lock</CODE
> - pointer to spinlock to clear </P
><P
><CODE
CLASS="PARAMETER"
>istate</CODE
> - interrupt state to restore </P
></DD
><DT
>Result:</DT
><DD
><P
>None</P
></DD
><DT
>Level:</DT
><DD
><P
>ISR</P
></DD
><DT
>Description:</DT
><DD
><P
> This function behaves exactly like
<CODE
CLASS="FUNCTION"
>cyg_drv_spinlock_clear()</CODE
> except that it
also restores an interrupt state saved by
<CODE
CLASS="FUNCTION"
>cyg_drv_spinlock_spin_intsave()</CODE
>. The
<CODE
CLASS="PARAMETER"
>istate</CODE
> argument must have been
initialized by a previous call to
<CODE
CLASS="FUNCTION"
>cyg_drv_spinlock_spin_intsave()</CODE
>.
</P
></DD
></DL
></DIV
></DIV
><DIV
CLASS="SECTION"
><H2
CLASS="SECTION"
><A
NAME="AEN6407"
>cyg_drv_dsr_lock</A
></H2
><P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
>Function:</DT
><DD
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>void cyg_drv_dsr_lock()</PRE
></TD
></TR
></TABLE
></DD
><DT
>Arguments:</DT
><DD
><P
>None</P
></DD
><DT
>Result:</DT
><DD
><P
>None </P
></DD
><DT
>Level:</DT
><DD
><P
>DSR</P
></DD
><DT
>Description:</DT
><DD
><P
>Disables scheduling of DSRs. This function maintains a
counter of the number of times it has been called. </P
></DD
></DL
></DIV
></DIV
><DIV
CLASS="SECTION"
><H2
CLASS="SECTION"
><A
NAME="AEN6430"
>cyg_drv_dsr_unlock</A
></H2
><P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
>Function:</DT
><DD
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>void cyg_drv_dsr_unlock()</PRE
></TD
></TR
></TABLE
></DD
><DT
>Arguments:</DT
><DD
><P
>None</P
></DD
><DT
>Result:</DT
><DD
><P
> </P
><P
>None </P
></DD
><DT
>Level:</DT
><DD
><P
>DSR</P
></DD
><DT
>Description:</DT
><DD
><P
>Re-enables scheduling of DSRs. This function decrements
the counter incremented by
<CODE
CLASS="FUNCTION"
>cyg_drv_dsr_lock()</CODE
>. DSRs are only allowed
to be delivered when the counter goes to zero. </P
></DD
></DL
></DIV
></DIV
><DIV
CLASS="SECTION"
><H2
CLASS="SECTION"
><A
NAME="AEN6455"
>cyg_drv_mutex_init</A
></H2
><P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
>Function:</DT
><DD
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>void cyg_drv_mutex_init(cyg_drv_mutex_t *mutex)</PRE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -