summaryrefslogtreecommitdiff
path: root/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/common/src/halIrq.c
blob: b119fe4dc02658a42e70ed4d25ef2edc0e37643a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/**************************************************************************//**
  \file  halIrq.c

  \brief Implementation of HWD IRQ interface.

  \author
      Atmel Corporation: http://www.atmel.com \n
      Support email: avr@atmel.com

    Copyright (c) 2008-2011, Atmel Corporation. All rights reserved.
    Licensed under Atmel's Limited License Agreement (BitCloudTM).

  \internal
    History:
      5/12/07 A. Khromykh - Created
 ******************************************************************************/
/******************************************************************************
 *   WARNING: CHANGING THIS FILE MAY AFFECT CORE FUNCTIONALITY OF THE STACK.  *
 *   EXPERT USERS SHOULD PROCEED WITH CAUTION.                                *
 ******************************************************************************/

/******************************************************************************
                   Includes section
******************************************************************************/
#include <halIrq.h>
#include <sleep.h>
#include <halSleepTimerClock.h>
#include <halAppClock.h>
#include <halDbg.h>
#include <halDiagnostic.h>

/******************************************************************************
                   Global variables section
******************************************************************************/
#if defined(PLATFORM_ZIGBIT)
  IrqCallback_t IrqCallbackList[HAL_NUM_IRQ_LINES] = {NULL, NULL};
#else
  IrqCallback_t IrqCallbackList[HAL_NUM_IRQ_LINES] = {NULL, NULL, NULL};
#endif

/******************************************************************************
                   Implementations section
******************************************************************************/
/******************************************************************************
Sets configuration of pins and the registers.
Parameters:
  irqNumber - number of interrupt.
  irqMode - mode of interrupt
Returns:
  none.
******************************************************************************/
void halSetIrqConfig(uint8_t irqNumber, uint8_t irqMode)
{
  uint8_t ui8ShiftCount = (irqNumber - IRQ_4) << 1;
  // IRQ pin is input
  DDRE &= ~(1 << irqNumber);
  PORTE |= (1 << irqNumber);
  // Clear previous settings of corresponding interrupt sense control
  EICRB &= ~(3 << ui8ShiftCount);
  // Setup corresponding interrupt sence control
  EICRB |= (irqMode & 0x03) << ui8ShiftCount;
  // Clear the INTn interrupt flag
  EIFR |= (1 << irqNumber);
}

/**************************************************************************//**
\brief Clears configuration of pins and the registers.
\param[in]
  irqNumber - number of interrupt.
******************************************************************************/
void halClrIrqConfig(uint8_t irqNumber)
{
  uint8_t ui8ShiftCount = (irqNumber - IRQ_4) << 1;
  DDRE &= ~(1 << irqNumber);// IRQ pin is input
  PORTE &= ~(1 << irqNumber); // pullup off
  EICRB &= ~(3 << ui8ShiftCount);
}

#if !defined(PLATFORM_ZIGBIT)
/******************************************************************************
 External interrupt 5 handler
******************************************************************************/
ISR(INT5_vect)
{
  BEGIN_MEASURE
  halWakeupFromIrq();
  /* user's callback */
  if (NULL != IrqCallbackList[IRQ_5 - HAL_FIRST_VALID_IRQ])
    IrqCallbackList[IRQ_5 - HAL_FIRST_VALID_IRQ]();
  END_MEASURE(HALISR_INT5_VECT_TIME_LIMIT)
}
#endif

/******************************************************************************
 External interrupt 6 handler
******************************************************************************/
ISR(INT6_vect)
{
  BEGIN_MEASURE
  halWakeupFromIrq();
  /* user's callback */
  if (NULL != IrqCallbackList[IRQ_6 - HAL_FIRST_VALID_IRQ])
    IrqCallbackList[IRQ_6 - HAL_FIRST_VALID_IRQ]();
  END_MEASURE(HALISR_INT6_VECT_TIME_LIMIT)
}

/******************************************************************************
 External interrupt 7 handler
******************************************************************************/
ISR(INT7_vect)
{
  BEGIN_MEASURE
  halWakeupFromIrq();
  /* user's callback */
  if (NULL != IrqCallbackList[IRQ_7 - HAL_FIRST_VALID_IRQ])
    IrqCallbackList[IRQ_7 - HAL_FIRST_VALID_IRQ]();
  END_MEASURE(HALISR_INT7_VECT_TIME_LIMIT)
}
// eof irq.c