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

Subversion Repositories usb_fpga_2_04

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

powered by: WebSVN 2.1.0

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