source: arduino-1-6-7/trunk/fuentes/arduino-ide-amd64/hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/UTILS/DEBUG/debug.c @ 4837

Last change on this file since 4837 was 4837, checked in by daduve, 2 years ago

Adding new version

File size: 3.7 KB
Line 
1/* This source file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
2
3/*This file is prepared for Doxygen automatic documentation generation.*/
4/*! \file *********************************************************************
5 *
6 * \brief Macros and functions dedicated to debug purposes.
7 *
8 * - Compiler:           IAR EWAVR32 and GNU GCC for AVR32
9 * - Supported devices:  All AVR32 devices with a USART module can be used.
10 *
11 * \author               Atmel Corporation: http://www.atmel.com \n
12 *                       Support and FAQ: http://support.atmel.no/
13 *
14 ******************************************************************************/
15
16/* Copyright (c) 2009 Atmel Corporation. All rights reserved.
17 *
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions are met:
20 *
21 * 1. Redistributions of source code must retain the above copyright notice, this
22 * list of conditions and the following disclaimer.
23 *
24 * 2. Redistributions in binary form must reproduce the above copyright notice,
25 * this list of conditions and the following disclaimer in the documentation
26 * and/or other materials provided with the distribution.
27 *
28 * 3. The name of Atmel may not be used to endorse or promote products derived
29 * from this software without specific prior written permission.
30 *
31 * 4. This software may only be redistributed and used in connection with an Atmel
32 * AVR product.
33 *
34 * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
35 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
36 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
37 * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
38 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
39 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
40 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
41 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
42 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
43 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
44 *
45 */
46
47#include "compiler.h"
48#include "debug.h"
49#include "util.h"
50
51
52#if (defined __GNUC__)
53#   include "malloc.h"
54
55U32 get_heap_curr_used_size( void )
56{
57  struct mallinfo my_info=mallinfo();
58  return my_info.uordblks;
59}
60
61U32 get_heap_total_used_size( void )
62{
63  struct mallinfo my_info=mallinfo();
64  return my_info.arena;
65}
66#endif
67
68U32 get_heap_free_size( void )
69{
70  U32 high_mark= AVR32_SRAM_SIZE;
71  U32 low_mark = 0;
72  U32 size ;
73  void* p_mem;
74
75  size = (high_mark + low_mark)/2;
76
77  do
78  {
79    p_mem = malloc(size);
80    if( p_mem != NULL)
81    { // Can allocate memory
82      free(p_mem);
83      low_mark = size;
84    }
85    else
86    { // Can not allocate memory
87      high_mark = size;
88    }
89
90    size = (high_mark + low_mark)/2;
91  }
92  while( (high_mark-low_mark) >1 );
93
94  return size;
95}
96
97static void* round_trace_pbuf;
98static U32   round_trace_size;
99
100void uc3_round_trace_init(void* buf, U32 size)
101{
102  round_trace_pbuf = buf;
103  (*(U32*)round_trace_pbuf)=(U32)buf+4;
104  round_trace_size = size;
105}
106
107void uc3_round_trace(U32 val)
108{
109  //Disable_global_interrupt();
110
111  U32* p_wr = (U32*)(*(U32*)round_trace_pbuf);
112  *p_wr = val;
113  p_wr++;
114  if( ((U32)p_wr % round_trace_size) ==0 )
115    p_wr= (U32*)round_trace_pbuf+1;
116  *p_wr = 0xdeadbeef;
117  *(U32*)round_trace_pbuf = (U32)p_wr;
118
119  //Enable_global_interrupt();
120}
121
122void dump(char* _buf, uint16_t _count) {
123
124        int i;
125        for (i = 0; i < _count; ++i)
126        {
127                printk("0x%x ", _buf[i]);
128                if ((i!=0)&&(i % 10 == 0))
129                        printk("\n\t");
130        }
131        printk("\n");
132}
133
Note: See TracBrowser for help on using the repository browser.