Adaptation/GUID-F09740DA-015B-449D-A124-0BEABBDDCB52.dita
changeset 15 307f4279f433
equal deleted inserted replaced
14:578be2adaf3e 15:307f4279f433
       
     1 <?xml version="1.0" encoding="utf-8"?>
       
     2 <!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. -->
       
     3 <!-- This component and the accompanying materials are made available under the terms of the License 
       
     4 "Eclipse Public License v1.0" which accompanies this distribution, 
       
     5 and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". -->
       
     6 <!-- Initial Contributors:
       
     7     Nokia Corporation - initial contribution.
       
     8 Contributors: 
       
     9 -->
       
    10 <!DOCTYPE concept
       
    11   PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
       
    12 <concept id="GUID-F09740DA-015B-449D-A124-0BEABBDDCB52" xml:lang="en"><title>Enabling
       
    13 and Disabling</title><shortdesc>This document describes how device drivers enable and disable interrupts.</shortdesc><prolog><metadata><keywords/></metadata></prolog><conbody>
       
    14 <p>Drivers can enable and disable the interrupts on the relevant interrupt
       
    15 sources while handling the interrupts using the <xref href="GUID-E7A7083C-97B9-39B9-A147-4A6E314EE3A3.dita"><apiname>Interrupt</apiname></xref> class.
       
    16 Typically, handling an interrupt is done with disabled interrupts. The interrupt
       
    17 is then enabled after the completion of interrupt handling. </p>
       
    18 <codeblock id="GUID-7805933A-51F6-5169-81D0-C1A8E9647C0D" xml:space="preserve">Interrupt::Disable(aIntId);
       
    19 ...
       
    20 // handle interrupt
       
    21 ...
       
    22 Interrupt::Enable(aIntId);
       
    23 </codeblock>
       
    24 <codeblock id="GUID-87C0A4CF-BA67-58DE-A180-EA30189BEDF4" xml:space="preserve">/**
       
    25  Interrupt Service Routine (ISR) for the UART driver. This function
       
    26  is associated with the UART interrupt, EUartIrq (value obtained from 
       
    27  TRM). This function is called whenever there is an interrupt on this 
       
    28  interrupt line and the interrupt source is enabled. The ISR must be a 
       
    29  static void function, taking a single TAny* parameter, which is an 
       
    30  object passed at the time of binding, usually a pointer to the owning
       
    31  class. Interrupt::Enable() must be called to start receiving 
       
    32  interrupts.
       
    33  
       
    34  The ISR implementation is hardware and driver specific. The ISR must
       
    35  be self-contained as the state of the system is indeterminate. It
       
    36  should not signal threads, allocate or de-allocate memory, copy
       
    37  memory to or from user processes, or call most Kernel functions.
       
    38  Also the whole system is blocked while the ISR is running, so it must be
       
    39  kept as short as possible. Any lengthy processing must be done in a
       
    40  delayed function call (DFC).
       
    41  
       
    42  A typical ISR would,
       
    43    Clear the interrupt in the peripheral.
       
    44    Disable the interrupt.
       
    45    Read or write peripheral registers, e.g. to determine errors, or 
       
    46    to start a new task.
       
    47    Read data from, or write data to, the peripheral.
       
    48    Start or stop NTimers or DMA transfer operations.
       
    49    Queue DFCs.
       
    50  
       
    51  @param     aParam
       
    52          pointer to object passed as parameter while binding
       
    53  */    
       
    54 
       
    55 void DExUartPhysicalChannelH4::UartIsr(TAny* aParam)
       
    56     {
       
    57     // Do the high priority device specific interrupt handling
       
    58     // i.e. read the interrupt type from device, clear the 
       
    59     // interrupt.
       
    60     ...
       
    61     // Defer the remaining processing by queuing the respective 
       
    62     // DFC based on the interrupt type
       
    63     ...
       
    64     }</codeblock>
       
    65 <p>Some operations may need to be performed with all the interrupts, not just
       
    66 the particular interrupt source, disabled. In this case, the <xref href="GUID-3A3C08F3-3D33-3D9E-80E7-7855C7B21E02.dita"><apiname>NKern</apiname></xref> class
       
    67 must be used to disable and enable all interrupts globally at the Interrupt
       
    68 controller. <xref href="GUID-3A3C08F3-3D33-3D9E-80E7-7855C7B21E02.dita#GUID-3A3C08F3-3D33-3D9E-80E7-7855C7B21E02/GUID-8C251C65-FDE7-3161-8D2B-61401FB6487F"><apiname>NKern::DisableAllInterrupts()</apiname></xref> can disable all
       
    69 IRQs, or IRQs and FIQs. <xref href="GUID-3A3C08F3-3D33-3D9E-80E7-7855C7B21E02.dita#GUID-3A3C08F3-3D33-3D9E-80E7-7855C7B21E02/GUID-2D328082-3A9F-3467-81CF-B1C68866E163"><apiname>NKern::RestoreInterrupts()</apiname></xref> can
       
    70 restore the interrupts to their state before disabling. </p>
       
    71 <codeblock id="GUID-A34A1AEB-9B00-556D-A280-9BFF7A6BAA8C" xml:space="preserve">alevel = 1; // 1 to disable IRQs and 2 to disable IRQs and FIQs
       
    72 state = NKern::DisableAllInterrupts(aLevel);
       
    73 ...
       
    74 // perform the required operations
       
    75 ...
       
    76 NKern::RestoreInterrupts(state);
       
    77 </codeblock>
       
    78 </conbody></concept>