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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
/*
* Copyright © 2008 Keith Packard <keithp@keithp.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
#ifndef _CCDBG_H_
#define _CCDBG_H_
#include <stdint.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <stdint.h>
#include <assert.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <cp2101.h>
#define CC_DATA CP2101_GPIO_MASK(0)
#define CC_CLOCK CP2101_GPIO_MASK(1)
#define CC_RESET_N CP2101_GPIO_MASK(2)
/* painfully slow for now */
#define CC_CLOCK_US (1000 * 1000)
struct ccdbg {
int fd;
uint8_t debug_data;
int clock;
};
#include "cccp.h"
#define CC_CHIP_ERASE 0x14
#define CC_WR_CONFIG 0x1d
#define CC_RD_CONFIG 0x24
# define CC_CONFIG_TIMERS_OFF (1 << 3)
# define CC_CONFIG_DMA_PAUSE (1 << 2)
# define CC_CONFIG_TIMER_SUSPEND (1 << 1)
# define CC_SET_FLASH_INFO_PAGE (1 << 0)
#define CC_GET_PC 0x28
#define CC_READ_STATUS 0x34
# define CC_STATUS_CHIP_ERASE_DONE (1 << 7)
# define CC_STATUS_PCON_IDLE (1 << 6)
# define CC_STATUS_CPU_HALTED (1 << 5)
# define CC_STATUS_POWER_MODE_0 (1 << 4)
# define CC_STATUS_HALT_STATUS (1 << 3)
# define CC_STATUS_DEBUG_LOCKED (1 << 2)
# define CC_STATUS_OSCILLATOR_STABLE (1 << 1)
# define CC_STATUS_STACK_OVERFLOW (1 << 0)
#define CC_SET_HW_BRKPNT 0x3b
# define CC_HW_BRKPNT_N(n) ((n) << 3)
# define CC_HW_BRKPNT_N_MASK (0x3 << 3)
# define CC_HW_BRKPNT_ENABLE (1 << 2)
#define CC_HALT 0x44
#define CC_RESUME 0x4c
#define CC_DEBUG_INSTR(n) (0x54|(n))
#define CC_STEP_INSTR 0x5c
#define CC_STEP_REPLACE (0x64|(n))
#define CC_GET_CHIP_ID 0x68
/* ccdbg-command.c */
void
ccdbg_reset(struct ccdbg *dbg);
uint8_t
ccdbg_read_status(struct ccdbg *dbg);
uint8_t
ccdbg_rd_config(struct ccdbg *dbg);
/* ccdbg-io.c */
void
ccdbg_quarter_clock(struct ccdbg *dbg);
struct ccdbg *
ccdbg_open(char *file);
void
ccdbg_close(struct ccdbg *dbg);
void
ccdbg_clock_1_0(struct ccdbg *dbg);
void
ccdbg_clock_0_1(struct ccdbg *dbg);
void
ccdbg_write_bit(struct ccdbg *dbg, uint8_t bit);
void
ccdbg_write_byte(struct ccdbg *dbg, uint8_t byte);
uint8_t
ccdbg_read_bit(struct ccdbg *dbg);
uint8_t
ccdbg_read_byte(struct ccdbg *dbg);
void
ccdbg_cmd_write(struct ccdbg *dbg, uint8_t cmd, uint8_t *data, int len);
uint8_t
ccdbg_cmd_write_read8(struct ccdbg *dbg, uint8_t cmd, uint8_t *data, int len);
uint16_t
ccdbg_cmd_write_read16(struct ccdbg *dbg, uint8_t cmd, uint8_t *data, int len);
#endif /* _CCDBG_H_ */
|