OpenCores
URL https://opencores.org/ocsvn/usb_fpga_2_14/usb_fpga_2_14/trunk

Subversion Repositories usb_fpga_2_14

[/] [usb_fpga_2_14/] [trunk/] [fx2/] [ztex-debug.h] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 ZTEX
/*%
2
   ZTEX Firmware Kit for EZ-USB FX2 Microcontrollers
3
   Copyright (C) 2009-2017 ZTEX GmbH.
4
   http://www.ztex.de
5
 
6
   This Source Code Form is subject to the terms of the Mozilla Public
7
   License, v. 2.0. If a copy of the MPL was not distributed with this file,
8
   You can obtain one at http://mozilla.org/MPL/2.0/.
9
 
10
   Alternatively, the contents of this file may be used under the terms
11
   of the GNU General Public License Version 3, as described below:
12
 
13
   This program is free software; you can redistribute it and/or modify
14
   it under the terms of the GNU General Public License version 3 as
15
   published by the Free Software Foundation.
16
 
17
   This program is distributed in the hope that it will be useful, but
18
   WITHOUT ANY WARRANTY; without even the implied warranty of
19
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20
   General Public License for more details.
21
 
22
   You should have received a copy of the GNU General Public License
23
   along with this program; if not, see http://www.gnu.org/licenses/.
24
%*/
25
 
26
/*
27
    debug helper
28
*/
29
#ifndef[ZTEX_DEBUG_H]
30
#define[ZTEX_DEBUG_H]
31
 
32
#ifndef[DEBUG_STACK_SIZE]
33
#error[Macro `DEBUG_STACK_SIZE' is not defined.]
34
#endif
35
 
36
#ifndef[DEBUG_MSG_SIZE]
37
#error[Macro `DEBUG_MSG_SIZE' is not defined.]
38
#endif
39
 
40
#define[@CAPABILITY_DEBUG;]
41
 
42
__xdata WORD debug_counter;                               // message number 
43
__xdata BYTE debug_stack_size;                            // stack size in messages
44
__xdata BYTE debug_msg_size;                              // message size in bytes
45
__xdata BYTE debug_stack[DEBUG_STACK_SIZE*DEBUG_MSG_SIZE];  // message stack
46
__xdata BYTE* __xdata debug_stack_ptr;                        // pointer to the last message added
47
 
48
__xdata BYTE debug_msg_buf[DEBUG_MSG_SIZE];               // user buffer: user should write data to this buffer
49
__xdata BYTE* __xdata debug_read_addr;
50
 
51
/* *********************************************************************
52
   ***** debug_add_msg *************************************************
53
   ********************************************************************* */
54
// adds the current message (stored in debug_msg_buf) to the message stack
55
void debug_add_msg () {
56
    BYTE i;
57
    i = debug_counter % DEBUG_STACK_SIZE;
58
    debug_stack_ptr = &debug_stack[i*DEBUG_MSG_SIZE];
59
    MEM_COPY1(debug_msg_buf,*debug_stack_ptr,DEBUG_MSG_SIZE);
60
    debug_counter += 1;
61
}
62
 
63
/* *********************************************************************
64
   ***** debug_add_msg *************************************************
65
   ********************************************************************* */
66
// init the variables
67
void debug_init () {
68
    debug_counter = 0;                             // message number 
69
    debug_stack_size = DEBUG_STACK_SIZE;
70
    debug_msg_size = DEBUG_MSG_SIZE;
71
    debug_stack_ptr = debug_stack;
72
}
73
 
74
/* *********************************************************************
75
   ***** EP0 vendor request 0x28 ***************************************
76
   ********************************************************************* */
77
// read the debug data
78
BYTE debug_read_ep0 () {
79
    BYTE b;
80
    b = ep0_payload_transfer;
81
    if ( b != 0) {
82
        MEM_COPY1(*debug_read_addr,EP0BUF,b);
83
    }
84
    debug_read_addr += b;
85
    return b;
86
}
87
 
88
ADD_EP0_VENDOR_REQUEST((0x28,,                          // read the debug data
89
    debug_read_addr = (__xdata BYTE*)&debug_counter;
90
    EP0BCH = 0;
91
    EP0BCL = debug_read_ep0();
92
,,
93
    EP0BCH = 0;
94
    EP0BCL = debug_read_ep0();
95
));;
96
 
97
#endif  /*ZTEX_DEBUG_H*/

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.