-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSWD_PhysicalLayer.c
388 lines (370 loc) · 12.1 KB
/
SWD_PhysicalLayer.c
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
/*******************************************************************************
* File Name: SWD_PhysicalLayer.c
* Version 1.0
*
* Description:
* This file provides the source code for the physical layer functions of the
* SWD protocol. These function definitions are the same as the corresponding
* macro definitions in SWD_PhysicalLayer.h
*
* Owner:
* Tushar Rastogi, Application Engineer (tusr@cypress.com)
*
* Related Document:
* AN84858 - PSoC 4 Programming using an External Microcontroller (HSSP)
*
* Hardware Dependency:
* CY8CKIT - 040 / CY8CKIT - 042 / CY8CKIT - 044 PSoC 4 M / CY8CKIT - 042 BLE /
* CY8CKIT - 046 / CY8CKIT - 048 / CY8CKIT - 41-40xx
*
* Code Tested With:
* PSoC Creator 4.0
* ARM GCC 4.9-2015-q1-update
*
* Note:
* The functions defined here are specific to PSoC 5LP Host Programmer.
* Modify the definitions as applicable for your Host Programmer.
*
******************************************************************************
* Copyright (c) 2013-2016, Cypress Semiconductor Corporation.
******************************************************************************
* This software is owned by Cypress Semiconductor Corporation (Cypress) and is
* protected by and subject to worldwide patent protection (United States and
* foreign), United States copyright laws and international treaty provisions.
* Cypress hereby grants to licensee a personal, non-exclusive, non-transferable
* license to copy, use, modify, create derivative works of, and compile the
* Cypress Source Code and derivative works for the sole purpose of creating
* custom software in support of licensee product to be used only in conjunction
* with a Cypress integrated circuit as specified in the applicable agreement.
* Any reproduction, modification, translation, compilation, or representation of
* this software except as specified above is prohibited without the express
* written permission of Cypress.
*
* Disclaimer: CYPRESS MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH
* REGARD TO THIS MATERIAL, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
* Cypress reserves the right to make changes without further notice to the
* materials described herein. Cypress does not assume any liability arising out
* of the application or use of any product or circuit described herein. Cypress
* does not authorize its products for use as critical components in life-support
* systems where a malfunction or failure may reasonably be expected to result in
* significant injury to the user. The inclusion of Cypress' product in a life-
* support systems application implies that the manufacturer assumes all risk of
* such use and in doing so indemnifies Cypress against all charges. Use may be
* limited by and subject to the applicable Cypress software license agreement.
*******************************************************************************/
/********************************************************************************
* Header file Inclusion
********************************************************************************/
#include "SWD_PhysicalLayer.h"
/********************************************************************************
* Function Definitions
********************************************************************************/
/***************************** USER ATTENTION REQUIRED **************************
***************************** HOST PROCESSOR SPECIFIC ***************************
******************* SWD Protocol Physical Layer functions ***********************
*
* All of the function definitions below are for a PSoC 5LP host programmer.
* Modify the definitions as applicable for the specific host programmer.
********************************************************************************/
/*******************************************************************************
* Function Name: SetSwdckCmosOutput
********************************************************************************
*
* Summary:
* Sets the SWDCK pin drive mode as CMOS drive mode.
*
* Parameters:
* None.
*
* Return:
* None.
*
* Note:
* The function definition is the same as the macro definition SWDCK_DRIVEMODE_CMOSOUT in
* SWD_PhysicalLayer.h.
*
*******************************************************************************/
void SetSwdckCmosOutput()
{
// SWDCK_PIN_DM_REG = (SWDCK_PIN_DM_REG & CMOSOUT_DM_ANDMASK) | CMOSOUT_DM_ORMASK;
SWDCK_DRIVEMODE_CMOSOUT;
}
/*******************************************************************************
* Function Name: SetSwdckHizInput
********************************************************************************
*
* Summary:
* Sets the SWDCK pin drive mode as High impedance digital input.
*
* Parameters:
* None.
*
* Return:
* None.
*
* Note:
* The function definition is the same as the macro definition SWDCK_DRIVEMODE_HIGHZIN in
* SWD_PhysicalLayer.h.
*
*******************************************************************************/
void SetSwdckHizInput()
{
// SWDCK_PIN_DM_REG = (SWDCK_PIN_DM_REG & HIGHZIN_DM_ANDMASK) | HIGHZIN_DM_ORMASK;
SWDCK_DRIVEMODE_HIGHZIN;
}
/*******************************************************************************
* Function Name: SetSwdioCmosOutput
********************************************************************************
*
* Summary:
* Sets the SWDIO pin drive mode as CMOS drive mode.
*
* Parameters:
* None.
*
* Return:
* None.
*
* Note:
* The function definition is the same as the macro definition SWDIO_DRIVEMODE_CMOSOUT in
* SWD_PhysicalLayer.h.
*
*******************************************************************************/
void SetSwdioCmosOutput()
{
// SWDIO_PIN_DM_REG = (SWDIO_PIN_DM_REG & CMOSOUT_DM_ANDMASK) | CMOSOUT_DM_ORMASK;
SWDIO_DRIVEMODE_CMOSOUT;
}
/*******************************************************************************
* Function Name: SetSwdioHizInput
********************************************************************************
*
* Summary:
* Sets the SWDIO pin drive mode as High impedance digital input.
*
* Parameters:
* None.
*
* Return:
* None.
*
* Note:
* The function definition is the same as the macro definition SWDIO_DRIVEMODE_HIGHZIN in
* SWD_PhysicalLayer.h.
*
*******************************************************************************/
void SetSwdioHizInput()
{
// SWDIO_PIN_DM_REG = (SWDIO_PIN_DM_REG & HIGHZIN_DM_ANDMASK) | HIGHZIN_DM_ORMASK;
SWDIO_DRIVEMODE_HIGHZIN;
}
/*******************************************************************************
* Function Name: SetXresCmosOutput
********************************************************************************
*
* Summary:
* Sets the XRES pin drive mode as CMOS drive mode.
*
* Parameters:
* None.
*
* Return:
* None.
*
* Note:
* The function definition is the same as the macro definition XRES_DRIVEMODE_CMOSOUT in
* SWD_PhysicalLayer.h.
*
*******************************************************************************/
void SetXresCmosOutput()
{
// XRES_PIN_DM_REG = (XRES_PIN_DM_REG & CMOSOUT_DM_ANDMASK) | CMOSOUT_DM_ORMASK;
XRES_DRIVEMODE_CMOSOUT;
}
/*******************************************************************************
* Function Name: SetXresHizInput
********************************************************************************
*
* Summary:
* Sets the XRES pin drive mode as High impedance digital input.
*
* Parameters:
* None.
*
* Return:
* None.
*
* Note:
* The function definition is the same as the macro definition XRES_DRIVEMODE_HIGHZIN in
* SWD_PhysicalLayer.h.
*
*******************************************************************************/
void SetXresHizInput()
{
// XRES_PIN_DM_REG = (XRES_PIN_DM_REG & HIGHZIN_DM_ANDMASK) | HIGHZIN_DM_ORMASK;
XRES_DRIVEMODE_HIGHZIN;
}
/*******************************************************************************
* Function Name: SetSwdckHigh
********************************************************************************
*
* Summary:
* Sets the SWDCK pin high
*
* Parameters:
* None.
*
* Return:
* None.
*
* Note:
* The function definition is the same as the macro definition SWDCK_OUTPUT_HIGH in
* SWD_PhysicalLayer.h.
*
*******************************************************************************/
void SetSwdckHigh()
{
// SWDCK_PRT_OUT_REG = SWDCK_PRT_OUT_REG | SWDCK_PIN_MASK;
SWDCK_OUTPUT_HIGH;
}
/*******************************************************************************
* Function Name: SetSwdckLow
********************************************************************************
*
* Summary:
* Sets the SWDCK pin low
*
* Parameters:
* None.
*
* Return:
* None.
*
* Note:
* The function definition is the same as the macro definition SWDCK_OUTPUT_LOW in
* SWD_PhysicalLayer.h.
*
*******************************************************************************/
void SetSwdckLow()
{
// SWDCK_PRT_OUT_REG = SWDCK_PRT_OUT_REG & (~SWDCK_PIN_MASK);
SWDCK_OUTPUT_LOW;
}
/*******************************************************************************
* Function Name: SetSwdioHigh
********************************************************************************
*
* Summary:
* Sets the SWDIO pin high
*
* Parameters:
* None.
*
* Return:
* None.
*
* Note:
* The function definition is the same as the macro definition SWDIO_OUTPUT_HIGH in
* SWD_PhysicalLayer.h.
*
*******************************************************************************/
void SetSwdioHigh()
{
// SWDIO_PRT_OUT_REG = SWDIO_PRT_OUT_REG | SWDIO_PIN_MASK;
SWDIO_OUTPUT_HIGH;
}
/*******************************************************************************
* Function Name: SetSwdioLow
********************************************************************************
*
* Summary:
* Sets the SWDIO pin low
*
* Parameters:
* None.
*
* Return:
* None.
*
* Note:
* The function definition is the same as the macro definition SWDIO_OUTPUT_LOW in
* SWD_PhysicalLayer.h.
*
*******************************************************************************/
void SetSwdioLow()
{
// SWDIO_PRT_OUT_REG = SWDIO_PRT_OUT_REG & (~SWDIO_PIN_MASK);
SWDIO_OUTPUT_LOW;
}
/*******************************************************************************
* Function Name: SetXresHigh
********************************************************************************
*
* Summary:
* Sets the XRES pin high
*
* Parameters:
* None.
*
* Return:
* None.
*
* Note:
* The function definition is the same as the macro definition XRES_OUTPUT_HIGH in
* SWD_PhysicalLayer.h.
*
*******************************************************************************/
void SetXresHigh()
{
// XRES_PRT_OUT_REG = XRES_PRT_OUT_REG | XRES_PIN_MASK;
XRES_OUTPUT_HIGH;
}
/*******************************************************************************
* Function Name: SetXresLow
********************************************************************************
*
* Summary:
* Sets the XRES pin low
*
* Parameters:
* None.
*
* Return:
* None.
*
* Note:
* The function definition is the same as the macro definition XRES_OUTPUT_LOW in
* SWD_PhysicalLayer.h.
*
*******************************************************************************/
void SetXresLow()
{
// XRES_PRT_OUT_REG = XRES_PRT_OUT_REG & (~XRES_PIN_MASK);
XRES_OUTPUT_LOW;
}
/*******************************************************************************
* Function Name: ReadSwdio
********************************************************************************
*
* Summary:
* Returns the state of the SWDIO input pin
*
* Parameters:
* None.
*
* Return:
* unsigned char (only one of the two values as given below)
* 0x00 - If the SWDIO pin state is low
* 0x01 - If the SWDIO pin state is high
*
* Note:
* The function definition is the same as the macro definition SWDIO_INPUT_READ in
* SWD_PhysicalLayer.h.
*
*******************************************************************************/
unsigned char ReadSwdio()
{
return(digitalRead(SWDIO_PIN));
}
/* [] END OF FILE */