ih_timer3_capt.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2001-2005 by egnite Software GmbH. All rights reserved.
00003  *
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions
00006  * are met:
00007  *
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. Neither the name of the copyright holders nor the names of
00014  *    contributors may be used to endorse or promote products derived
00015  *    from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY EGNITE SOFTWARE GMBH AND CONTRIBUTORS
00018  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00019  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00020  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL EGNITE
00021  * SOFTWARE GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00022  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00023  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
00024  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
00025  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00026  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
00027  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00028  * SUCH DAMAGE.
00029  *
00030  * For additional information see http://www.ethernut.de/
00031  *
00032  */
00033 
00079 #include <dev/irqreg.h>
00080 
00081 #if defined(MCU_AT90CAN128) || defined(MCU_ATMEGA2561)
00082 #define INT_MASK_REG    TIMSK3
00083 #define INT_STATUS_REG  TIFR3
00084 #define INT_ENABLE_BIT  ICIE3
00085 #define INT_STATUS_BIT  ICF3
00086 #define INT_PRIORITY    0
00087 #else
00088 #define INT_MASK_REG    ETIMSK
00089 #define INT_STATUS_REG  ETIFR
00090 #define INT_ENABLE_BIT  TICIE3
00091 #define INT_STATUS_BIT  ICF3
00092 #define INT_PRIORITY    0
00093 #endif
00094 
00099 
00100 #if defined(SIG_INPUT_CAPTURE3) || defined(iv_TIMER3_CAPT)
00101 
00102 static int AvrTimer3InCaptIrqCtl(int cmd, void *param);
00103 
00104 IRQ_HANDLER sig_INPUT_CAPTURE3 = {
00105 #ifdef NUT_PERFMON
00106     0,                          /* Interrupt counter, ir_count. */
00107 #endif
00108     NULL,                       /* Passed argument, ir_arg. */
00109     NULL,                       /* Handler subroutine, ir_handler. */
00110     AvrTimer3InCaptIrqCtl       /* Interrupt control, ir_ctl. */
00111 };
00112 
00127 static int AvrTimer3InCaptIrqCtl(int cmd, void *param)
00128 {
00129     int rc = 0;
00130     u_int *ival = (u_int *) param;
00131     int enabled = bit_is_set(INT_MASK_REG, INT_ENABLE_BIT);
00132 
00133     /* Disable interrupt. */
00134     cbi(INT_MASK_REG, INT_ENABLE_BIT);
00135 
00136     switch (cmd) {
00137     case NUT_IRQCTL_INIT:
00138     case NUT_IRQCTL_CLEAR:
00139         /* Clear any pending interrupt. */
00140         outb(INT_STATUS_REG, _BV(INT_STATUS_BIT));
00141         break;
00142     case NUT_IRQCTL_STATUS:
00143         if (bit_is_set(INT_STATUS_REG, INT_STATUS_BIT)) {
00144             *ival = 1;
00145         } else {
00146             *ival = 0;
00147         }
00148         if (enabled) {
00149             *ival |= 0x80;
00150         }
00151         break;
00152     case NUT_IRQCTL_ENABLE:
00153         enabled = 1;
00154         break;
00155     case NUT_IRQCTL_DISABLE:
00156         enabled = 0;
00157         break;
00158     case NUT_IRQCTL_GETPRIO:
00159         *ival = INT_PRIORITY;
00160         break;
00161 #ifdef NUT_PERFMON
00162     case NUT_IRQCTL_GETCOUNT:
00163         *ival = (u_int) sig_INPUT_CAPTURE3.ir_count;
00164         sig_INPUT_CAPTURE3.ir_count = 0;
00165         break;
00166 #endif
00167     default:
00168         rc = -1;
00169         break;
00170     }
00171 
00172     /* Enable interrupt. */
00173     if (enabled) {
00174         sbi(INT_MASK_REG, INT_ENABLE_BIT);
00175     }
00176     return rc;
00177 }
00178 
00182 #ifdef __IMAGECRAFT__
00183 #pragma interrupt_handler SIG_INPUT_CAPTURE3:iv_TIMER3_CAPT
00184 #endif
00185 NUTSIGNAL(SIG_INPUT_CAPTURE3, sig_INPUT_CAPTURE3)
00186 #endif
00187 

© 2000-2007 by egnite Software GmbH - visit http://www.ethernut.de/