summaryrefslogtreecommitdiff
path: root/digital/zigbit/bitcloud/stack/Components/HAL/avr/atmega1281/common/include/halAssert.h
blob: 92e0497f16b29df6b53060a8c84ffe6ecf89d6e7 (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
/**************************************************************************//**
  \file  halAssert.h

  \brief Implementation of avr assert algorithm.

  \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:
      18/08/08 A. Khromykh - Created
 ******************************************************************************/
/******************************************************************************
 *   WARNING: CHANGING THIS FILE MAY AFFECT CORE FUNCTIONALITY OF THE STACK.  *
 *   EXPERT USERS SHOULD PROCEED WITH CAUTION.                                *
 ******************************************************************************/

#ifndef _HALASSERT_H
#define _HALASSERT_H

#ifdef  __IAR_SYSTEMS_ICC__
#ifndef _SYSTEM_BUILD
#pragma system_include
#endif
#endif

/******************************************************************************
                   Includes section
******************************************************************************/
#include <halClkCtrl.h>
#include <wdtCtrl.h>

/******************************************************************************
                   Define(s) section
******************************************************************************/
#define DELAY_VALUE 0x000000ul

#ifdef _SYS_ASSERT_ON_

#if defined(_HAL_ASSERT_INTERFACE_UART0_)
  #define UBRRNH UBRR0H
  #define UBRRNL UBRR0L
  #define UCSRNA UCSR0A
  #define UCSRNB UCSR0B
  #define UCSRNC UCSR0C
  #define UDRN   UDR0
#elif defined(_HAL_ASSERT_INTERFACE_UART1_)
  #define UBRRNH UBRR1H
  #define UBRRNL UBRR1L
  #define UCSRNA UCSR1A
  #define UCSRNB UCSR1B
  #define UCSRNC UCSR1C
  #define UDRN   UDR1
#else
  #error " Unknown assert interface "
#endif

/******************************************************************************
                   Inline static functions section
******************************************************************************/
INLINE void halAssert(uint8_t condition, uint16_t dbgCode)
{
  if (!condition)
  {
    uint32_t delay;

    HAL_StopWdt();
    asm("cli");
    DDRB |= 0xE0;
    /* Init UART */
    UBRRNH = 0;
    if (4000000ul == HAL_ReadFreq())
      UBRRNL = 12;
    else
      UBRRNL = 25;
    UCSRNA = (1 << U2X1);
    UCSRNB = (1 << TXEN1);
    UCSRNC = (3 << UCSZ10);
    while(1)
    {
      PORTB &= ~0xE0;
      /* Send high byte of message to UART */
      while (!(UCSRNA & (1 << UDRE1)));
      UDRN = (dbgCode >> 8);
      /* Send low byte of message to UART */
      while (!(UCSRNA & (1 << UDRE1)));
      UDRN = dbgCode;
      delay = DELAY_VALUE;
      while (delay--);

      PORTB |= 0xE0;
      delay = (DELAY_VALUE / 2);
      while(delay--);
    }
  }
}

#else /* _SYS_ASSERT_ON_ */
  #define halAssert(condition, dbgCode)
#endif /* _SYS_ASSERT_ON_ */

#endif /* _HALASSERT_H */

// eof halAssert.h