// Copyright (C) 1999-2005 First Silicon Solutions, Inc.  All rights reserved.
// Revision 1.2  2005/12/21 22:19:01  ernie
// Revision 1.1  2005/08/31 16:33:32  ernie
`timescale 1ns/10ps
module
ccortexm1_uj_jtag
(
uireg
,
urstb
,
udrupd
,
udrck
,
udrcap
,
udrsh
,
utdi
,
utdo
,
utdodrv
,
dutntrst
,
duttck
,
duttms
,
duttdi
,
duttdo
,
gpout
,
gpin
)
;
parameter
uj_jtag_ircode
=
8
'h
33
;
input
[
7
:
0
]
uireg
;
input
urstb
;
input
udrupd
;
input
udrck
;
input
udrcap
;
input
udrsh
;
input
utdi
;
output
utdo
;
output
utdodrv
;
output
dutntrst
;
output
duttck
;
output
duttms
;
output
duttdi
;
input
duttdo
;
output
[
3
:
0
]
gpout
;
input
[
3
:
0
]
gpin
;
reg
[
4
:
0
]
CCORTEXM1OlIIOI
;
reg
[
5
:
0
]
CCORTEXM1IlIIOI
;
wire
[
5
:
0
]
CCORTEXM1llIIOI
;
wire
CCORTEXM1O0IIOI
;
reg
CCORTEXM1I0IIOI
;
wire
duttdi
;
wire
duttms
;
reg
utdo
;
reg
utdodrv
;
reg
CCORTEXM1l0IIOI
;
reg
CCORTEXM1O1IIOI
;
reg
CCORTEXM1I1IIOI
;
reg
[
3
:
0
]
gpout
;
reg
[
3
:
0
]
CCORTEXM1l1IIOI
;
`define CCORTEXM1OOlIOI  \
5 \
'b \
00000
`define CCORTEXM1IOlIOI  \
5 \
'b \
00100
`define CCORTEXM1lOlIOI  \
5 \
'b \
00101
`define CCORTEXM1OIlIOI  \
5 \
'b \
00110
`define CCORTEXM1IIlIOI  \
5 \
'b \
00111
`define CCORTEXM1lIlIOI  \
5 \
'b \
01001
`define CCORTEXM1OllIOI  \
5 \
'b \
01010
`define CCORTEXM1IllIOI  \
5 \
'b \
01011
`define CCORTEXM1lllIOI  \
5 \
'b \
01100
`define CCORTEXM1O0lIOI  \
5 \
'b \
01101
`define CCORTEXM1I0lIOI  \
5 \
'b \
01110
`define CCORTEXM1l0lIOI  \
5 \
'b \
01111
`define CCORTEXM1O1lIOI  \
5 \
'b \
10100
`define CCORTEXM1I1lIOI  \
5 \
'b \
10101
`define CCORTEXM1l1lIOI  \
5 \
'b \
10110
`define CCORTEXM1OO0IOI  \
5 \
'b \
10111
`define CCORTEXM1IO0IOI  \
5 \
'b \
10000
`define CCORTEXM1lO0IOI  \
5 \
'b \
10001
`define CCORTEXM1OI0IOI  \
5 \
'b \
10010
`define CCORTEXM1II0IOI  \
5 \
'b \
10011
assign
CCORTEXM1llIIOI
=
(
&
CCORTEXM1OlIIOI
[
2
:
0
]
)
?
(
CCORTEXM1IlIIOI
-
6
'b
000001
)
:
CCORTEXM1OlIIOI
[
3
]
?
{
utdi
,
CCORTEXM1IlIIOI
[
5
:
1
]
}
:
{
3
'b
000
,
utdi
,
CCORTEXM1IlIIOI
[
2
:
1
]
}
;
assign
CCORTEXM1O0IIOI
=
(
CCORTEXM1llIIOI
==
6
'b
000000
)
;
assign
duttms
=
(
CCORTEXM1I1IIOI
&
utdi
)
|
(
CCORTEXM1l0IIOI
)
;
assign
duttdi
=
utdi
;
always
@
(
posedge
udrck
or
negedge
urstb
)
begin
if
(
~
urstb
)
begin
CCORTEXM1I0IIOI
<=
1
'b
0
;
CCORTEXM1OlIIOI
<=
`CCORTEXM1OOlIOI
;
CCORTEXM1IlIIOI
<=
6
'b
000000
;
gpout
<=
4
'b
0000
;
CCORTEXM1l1IIOI
<=
4
'b
0000
;
end
else
begin
CCORTEXM1l1IIOI
<=
gpin
;
case
(
CCORTEXM1OlIIOI
)
`CCORTEXM1OOlIOI
:
begin
CCORTEXM1I0IIOI
<=
1
'b
0
;
CCORTEXM1IlIIOI
<=
6
'b
000000
;
if
(
(
uireg
==
uj_jtag_ircode
)
&&
udrcap
)
CCORTEXM1OlIIOI
<=
`CCORTEXM1IOlIOI
;
else
CCORTEXM1OlIIOI
<=
`CCORTEXM1OOlIOI
;
end
`CCORTEXM1IOlIOI
,
`CCORTEXM1lOlIOI
,
`CCORTEXM1lIlIOI
,
`CCORTEXM1OllIOI
,
`CCORTEXM1IllIOI
,
`CCORTEXM1lllIOI
,
`CCORTEXM1O0lIOI
,
`CCORTEXM1O1lIOI
,
`CCORTEXM1I1lIOI
:
begin
CCORTEXM1I0IIOI
<=
1
'b
0
;
if
(
udrsh
)
begin
CCORTEXM1IlIIOI
<=
CCORTEXM1llIIOI
;
CCORTEXM1OlIIOI
<=
CCORTEXM1OlIIOI
+
5
'b
00001
;
end
else
if
(
(
uireg
==
uj_jtag_ircode
)
&&
udrcap
)
begin
CCORTEXM1OlIIOI
<=
`CCORTEXM1IOlIOI
;
end
else
if
(
udrupd
)
begin
CCORTEXM1OlIIOI
<=
`CCORTEXM1OOlIOI
;
end
end
`CCORTEXM1OIlIOI
:
begin
if
(
udrsh
)
begin
if
(
CCORTEXM1O0IIOI
)
begin
CCORTEXM1I0IIOI
<=
1
'b
0
;
CCORTEXM1IlIIOI
<=
CCORTEXM1llIIOI
;
CCORTEXM1OlIIOI
<=
`CCORTEXM1lIlIOI
;
end
else
if
(
CCORTEXM1llIIOI
[
2
:
0
]
==
3
'b
111
)
begin
CCORTEXM1I0IIOI
<=
1
'b
0
;
CCORTEXM1IlIIOI
<=
{
2
'b
00
,
CCORTEXM1l1IIOI
[
3
:
0
]
}
;
CCORTEXM1OlIIOI
<=
`CCORTEXM1IO0IOI
;
end
else
begin
CCORTEXM1I0IIOI
<=
1
'b
1
;
CCORTEXM1IlIIOI
<=
CCORTEXM1llIIOI
;
CCORTEXM1OlIIOI
<=
CCORTEXM1OlIIOI
+
5
'b
00001
;
end
end
else
if
(
(
uireg
==
uj_jtag_ircode
)
&&
udrcap
)
begin
CCORTEXM1OlIIOI
<=
`CCORTEXM1IOlIOI
;
end
else
if
(
udrupd
)
begin
CCORTEXM1OlIIOI
<=
`CCORTEXM1OOlIOI
;
end
end
`CCORTEXM1I0lIOI
:
begin
if
(
udrsh
)
begin
CCORTEXM1I0IIOI
<=
&
CCORTEXM1OlIIOI
[
2
:
1
]
&
~
CCORTEXM1O0IIOI
;
CCORTEXM1IlIIOI
<=
CCORTEXM1llIIOI
;
if
(
CCORTEXM1O0IIOI
)
CCORTEXM1OlIIOI
<=
`CCORTEXM1O1lIOI
;
else
CCORTEXM1OlIIOI
<=
CCORTEXM1OlIIOI
+
5
'b
00001
;
end
else
if
(
(
uireg
==
uj_jtag_ircode
)
&&
udrcap
)
begin
CCORTEXM1I0IIOI
<=
1
'b
0
;
CCORTEXM1OlIIOI
<=
`CCORTEXM1IOlIOI
;
end
else
if
(
udrupd
)
begin
CCORTEXM1I0IIOI
<=
1
'b
0
;
CCORTEXM1OlIIOI
<=
`CCORTEXM1OOlIOI
;
end
end
`CCORTEXM1l1lIOI
:
begin
if
(
udrsh
)
begin
CCORTEXM1I0IIOI
<=
&
CCORTEXM1OlIIOI
[
2
:
1
]
&
~
CCORTEXM1O0IIOI
;
CCORTEXM1IlIIOI
<=
CCORTEXM1llIIOI
;
if
(
CCORTEXM1O0IIOI
)
CCORTEXM1OlIIOI
<=
`CCORTEXM1OOlIOI
;
else
CCORTEXM1OlIIOI
<=
CCORTEXM1OlIIOI
+
5
'b
00001
;
end
else
if
(
(
uireg
==
uj_jtag_ircode
)
&&
udrcap
)
begin
CCORTEXM1I0IIOI
<=
1
'b
0
;
CCORTEXM1OlIIOI
<=
`CCORTEXM1IOlIOI
;
end
else
if
(
udrupd
)
begin
CCORTEXM1I0IIOI
<=
1
'b
0
;
CCORTEXM1OlIIOI
<=
`CCORTEXM1OOlIOI
;
end
end
`CCORTEXM1IIlIOI
:
begin
if
(
udrsh
)
begin
CCORTEXM1I0IIOI
<=
~
CCORTEXM1O0IIOI
;
CCORTEXM1IlIIOI
<=
CCORTEXM1llIIOI
;
if
(
CCORTEXM1O0IIOI
)
CCORTEXM1OlIIOI
<=
`CCORTEXM1lIlIOI
;
else
CCORTEXM1OlIIOI
<=
`CCORTEXM1IIlIOI
;
end
else
if
(
(
uireg
==
uj_jtag_ircode
)
&&
udrcap
)
begin
CCORTEXM1I0IIOI
<=
1
'b
0
;
CCORTEXM1OlIIOI
<=
`CCORTEXM1IOlIOI
;
end
else
if
(
udrupd
)
begin
CCORTEXM1I0IIOI
<=
1
'b
0
;
CCORTEXM1OlIIOI
<=
`CCORTEXM1OOlIOI
;
end
end
`CCORTEXM1l0lIOI
:
begin
if
(
udrsh
)
begin
CCORTEXM1I0IIOI
<=
~
CCORTEXM1O0IIOI
;
CCORTEXM1IlIIOI
<=
CCORTEXM1llIIOI
;
if
(
CCORTEXM1O0IIOI
)
CCORTEXM1OlIIOI
<=
`CCORTEXM1O1lIOI
;
else
CCORTEXM1OlIIOI
<=
`CCORTEXM1l0lIOI
;
end
else
if
(
(
uireg
==
uj_jtag_ircode
)
&&
udrcap
)
begin
CCORTEXM1I0IIOI
<=
1
'b
0
;
CCORTEXM1OlIIOI
<=
`CCORTEXM1IOlIOI
;
end
else
if
(
udrupd
)
begin
CCORTEXM1I0IIOI
<=
1
'b
0
;
CCORTEXM1OlIIOI
<=
`CCORTEXM1OOlIOI
;
end
end
`CCORTEXM1OO0IOI
:
begin
if
(
udrsh
)
begin
CCORTEXM1I0IIOI
<=
~
CCORTEXM1O0IIOI
;
CCORTEXM1IlIIOI
<=
CCORTEXM1llIIOI
;
if
(
CCORTEXM1O0IIOI
)
CCORTEXM1OlIIOI
<=
`CCORTEXM1OOlIOI
;
else
CCORTEXM1OlIIOI
<=
`CCORTEXM1OO0IOI
;
end
else
if
(
(
uireg
==
uj_jtag_ircode
)
&&
udrcap
)
begin
CCORTEXM1I0IIOI
<=
1
'b
0
;
CCORTEXM1OlIIOI
<=
`CCORTEXM1IOlIOI
;
end
else
if
(
udrupd
)
begin
CCORTEXM1I0IIOI
<=
1
'b
0
;
CCORTEXM1OlIIOI
<=
`CCORTEXM1OOlIOI
;
end
end
`CCORTEXM1IO0IOI
,
`CCORTEXM1lO0IOI
,
`CCORTEXM1OI0IOI
,
`CCORTEXM1II0IOI
:
begin
CCORTEXM1I0IIOI
<=
1
'b
0
;
if
(
udrsh
)
begin
CCORTEXM1IlIIOI
[
5
:
0
]
<=
{
2
'b
00
,
utdi
,
CCORTEXM1IlIIOI
[
3
:
1
]
}
;
if
(
~&
CCORTEXM1OlIIOI
[
1
:
0
]
)
CCORTEXM1OlIIOI
<=
CCORTEXM1OlIIOI
+
5
'b
00001
;
end
else
if
(
(
uireg
==
uj_jtag_ircode
)
&&
udrcap
)
begin
CCORTEXM1OlIIOI
<=
`CCORTEXM1IOlIOI
;
end
else
if
(
udrupd
)
begin
gpout
<=
CCORTEXM1IlIIOI
[
3
:
0
]
;
CCORTEXM1OlIIOI
<=
`CCORTEXM1OOlIOI
;
end
end
default
:
begin
CCORTEXM1I0IIOI
<=
1
'b
0
;
CCORTEXM1IlIIOI
<=
6
'b
000000
;
if
(
(
uireg
==
uj_jtag_ircode
)
&&
udrcap
)
begin
CCORTEXM1OlIIOI
<=
`CCORTEXM1IOlIOI
;
end
else
begin
CCORTEXM1OlIIOI
<=
`CCORTEXM1OOlIOI
;
end
end
endcase
end
end
always
@
(
negedge
udrck
or
negedge
urstb
)
begin
if
(
~
urstb
)
begin
CCORTEXM1l0IIOI
<=
1
'b
0
;
CCORTEXM1I1IIOI
<=
1
'b
0
;
end
else
begin
CCORTEXM1I1IIOI
<=
~
CCORTEXM1OlIIOI
[
3
]
;
CCORTEXM1l0IIOI
<=
(
CCORTEXM1OlIIOI
==
`CCORTEXM1l0lIOI
)
&&
CCORTEXM1O0IIOI
;
end
end
always
@
(
posedge
udrck
or
negedge
urstb
)
begin
if
(
~
urstb
)
begin
CCORTEXM1O1IIOI
<=
1
'b
0
;
end
else
begin
if
(
~
udrsh
)
CCORTEXM1O1IIOI
<=
1
'b
1
;
else
if
(
CCORTEXM1I0IIOI
)
CCORTEXM1O1IIOI
<=
1
'b
0
;
end
end
assign
duttck
=
~
(
CCORTEXM1O1IIOI
|
~
udrsh
|
(
CCORTEXM1I0IIOI
&
~
udrck
)
)
;
assign
dutntrst
=
urstb
;
always
@
(
posedge
udrck
or
negedge
urstb
)
begin
if
(
~
urstb
)
begin
utdo
<=
1
'b
0
;
utdodrv
<=
1
'b
0
;
end
else
begin
if
(
udrsh
)
utdo
<=
(
CCORTEXM1OlIIOI
[
4
:
2
]
==
3
'b
100
)
?
CCORTEXM1IlIIOI
[
0
]
:
duttdo
;
utdodrv
<=
(
uireg
==
uj_jtag_ircode
)
?
1
'b
1
:
1
'b
0
;
end
end
endmodule
