8f937bd431e618c89dc649e6ad3f5100008422ee
[fw/altos] / ccdbg.h
1 /*
2  * Copyright © 2008 Keith Packard <keithp@keithp.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  */
18
19 #ifndef _CCDBG_H_
20 #define _CCDBG_H_
21
22 #include <stdint.h>
23 #include <stdlib.h>
24 #include <unistd.h>
25 #include <string.h>
26 #include <stdio.h>
27 #include <stdint.h>
28 #include <assert.h>
29 #include <sys/types.h>
30 #include <sys/ioctl.h>
31 #include <cp2101.h>
32
33 #define CC_DATA         CP2101_GPIO_MASK(0)
34 #define CC_CLOCK        CP2101_GPIO_MASK(1)
35 #define CC_RESET_N      CP2101_GPIO_MASK(2)
36
37 /* painfully slow for now */
38 #define CC_CLOCK_US     (2 * 1000)
39
40 struct ccdbg {
41         int     fd;
42         uint8_t debug_data;
43         int     clock;
44 };
45
46 #include "cccp.h"
47
48 #define CC_CHIP_ERASE           0x14
49
50 #define CC_WR_CONFIG            0x1d
51 #define CC_RD_CONFIG            0x24
52 # define CC_CONFIG_TIMERS_OFF           (1 << 3)
53 # define CC_CONFIG_DMA_PAUSE            (1 << 2)
54 # define CC_CONFIG_TIMER_SUSPEND        (1 << 1)
55 # define CC_SET_FLASH_INFO_PAGE         (1 << 0)
56
57 #define CC_GET_PC               0x28
58 #define CC_READ_STATUS          0x34
59 # define CC_STATUS_CHIP_ERASE_DONE      (1 << 7)
60 # define CC_STATUS_PCON_IDLE            (1 << 6)
61 # define CC_STATUS_CPU_HALTED           (1 << 5)
62 # define CC_STATUS_POWER_MODE_0         (1 << 4)
63 # define CC_STATUS_HALT_STATUS          (1 << 3)
64 # define CC_STATUS_DEBUG_LOCKED         (1 << 2)
65 # define CC_STATUS_OSCILLATOR_STABLE    (1 << 1)
66 # define CC_STATUS_STACK_OVERFLOW       (1 << 0)
67
68 #define CC_SET_HW_BRKPNT        0x3b
69 # define CC_HW_BRKPNT_N(n)      ((n) << 3)
70 # define CC_HW_BRKPNT_N_MASK    (0x3 << 3)
71 # define CC_HW_BRKPNT_ENABLE    (1 << 2)
72
73 #define CC_HALT                 0x44
74 #define CC_RESUME               0x4c
75 #define CC_DEBUG_INSTR(n)       (0x54|(n))
76 #define CC_STEP_INSTR           0x5c
77 #define CC_STEP_REPLACE         (0x64|(n))
78 #define CC_GET_CHIP_ID          0x68
79
80 #endif /* _CCDBG_H_ */