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

Subversion Repositories m16c5x

[/] [m16c5x/] [trunk/] [RTL/] [Src/] [M16C5x.tty] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 MichaelA
////////////////////////////////////////////////////////////////////////////////
2
//
3
//  Copyright 2013 by Michael A. Morris, dba M. A. Morris & Associates
4
//
5
//  All rights reserved. The source code contained herein is publicly released
6
//  under the terms and conditions of the GNU Lesser Public License. No part of
7
//  this source code may be reproduced or transmitted in any form or by any
8
//  means, electronic or mechanical, including photocopying, recording, or any
9
//  information storage and retrieval system in violation of the license under
10
//  which the source code is released.
11
//
12
//  The source code contained herein is free; it may be redistributed and/or
13
//  modified in accordance with the terms of the GNU Lesser General Public
14
//  License as published by the Free Software Foundation; either version 2.1 of
15
//  the GNU Lesser General Public License, or any later version.
16
//
17
//  The source code contained herein is freely released WITHOUT ANY WARRANTY;
18
//  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
19
//  PARTICULAR PURPOSE. (Refer to the GNU Lesser General Public License for
20
//  more details.)
21
//
22
//  A copy of the GNU Lesser General Public License should have been received
23
//  along with the source code contained herein; if not, a copy can be obtained
24
//  by writing to:
25
//
26
//  Free Software Foundation, Inc.
27
//  51 Franklin Street, Fifth Floor
28
//  Boston, MA  02110-1301 USA
29
//
30
//  Further, no use of this source code is permitted in any form or means
31
//  without inclusion of this banner prominently in any derived works.
32
//
33
//  Michael A. Morris
34
//  Huntsville, AL
35
//
36
////////////////////////////////////////////////////////////////////////////////
37
 
38
`timescale 1ns / 1ps
39
 
40
////////////////////////////////////////////////////////////////////////////////
41
// Company:         M. A. Morris & Associates
42
// Engineer:        Michael A. Morris
43
//
44
// Create Date:     19:30:58 06/15/2013
45
// Design Name:     Microcomputer Implementation using P16C5x Processor Core
46
// Module Name:     M16C5x.v
47
// Project Name:    C;\XProjects\ISE10.1i\M16C5x
48
// Target Devices:  RAM-based FPGA
49
// Tool versions:   Xilinx ISE 10.1i SP3
50
//
51
// Description:
52
//
53
//  This module is a microcomputer implementation using an FPGA-based processor
54
//  core based on the P16C5x module. The P16C5x is derived from the released
55
//  PIC16C5x core found on GitHUB. The P16C5x differs from that core in that the
56
//  TRISA..TRISC registers, and the IO Ports A..C have been removed and replaced
57
//  by a number of WE and RE strobes and an IO data bus.
58
//
59
//  This modification has been done to demonstrate how the PIC16C5x core can be
60
//  adapted to interface to a UART or an SPI Master. By using the P16C5x core,
61
//  a microcomputer implementation can be generated for a small FPGA that pro-
62
//  vides significant processing capabilities. By using a core like the P16C5x,
63
//  standard programming languages and support tools can be used to ease the
64
//  development of sophisticated FPGA-based products.
65
//
66
// Dependencies:    M16C5x_ClkGen.v
67
//                      ClkGen.xaw
68
//                      fedet.v
69
//                  P16C5x.v
70
//                      P16C5x_IDec.v
71
//                      P16C5x_ALU.v
72
//                  M16C5x_SPI.v
73
//                      DPSFmnCE.v
74
//                      SPIxIF.v
75
//                  M16C5x_UART.v
76
//                      SSPx_Slv.v
77
//                      SSP_UART.v
78
//                          re1ce.v
79
//                          DPSFmnCE.v
80
//                          UART_BRG.v
81
//                          UART_TXSM.v
82
//                          UART_RXSM.v
83
//                          UART_RTO.v
84
//                          UART_INT.v
85
//                              redet.v
86
//                              fedet.v
87
//
88
// Revision:
89
//
90
//  0.01    13F15   MAM     Initial creation of the M16C5x module.
91
//
92
//  2.20    13G14   MAM     Updated all of the module instantiations and the top
93
//                          module to support the parameterization of the soft-
94
//                          core microcontroller from the top level: M16C5x. Up-
95
//                          dated Dependencies section, and set revision to
96
//                          match the release number on GitHUB.
97
//
98
//  2.30    13G21   MAM     Changed UART Clk to operate from the Clk2x output of
99
//                          DCM. Gives a fixed value for the UART Clk regardless
100
//                          of the ClkFX output frequency. Adjusted default PS,
101
//                          Div values to produce 9600 bps as the default.
102
//
103
// Additional Comments:
104
//
105
////////////////////////////////////////////////////////////////////////////////
106
 
107
module M16C5x #(
108
    // P16C5x Module Parameter Settings
109
 
110
    parameter pWDT_Size  = 20,              // 20 - synthesis; 10 - Simulation
111
    parameter pRstVector = 12'h7FF,         // Reset Vector Location (PIC16F59)
112
    parameter pUserProg  = "Src/M16C5x_Tst4.coe",   // Tst Pgm file: 4096 x 12
113
    parameter pRAMA_Init = "Src/RAMA.coe",  // RAM A initial value file ( 8x8)
114
    parameter pRAMB_Init = "Src/RAMB.coe",  // RAM B initial value file (64x8)
115
 
116
    // M16C5x_SPI Module Parameter Settings
117
 
118
    parameter pSPI_CR_Default = 8'b0_110_00_0_0,    // SPI Interface Defaults
119
    parameter pSPI_TF_Depth   = 4,          // Tx FIFO Depth: 2**pTF_Depth
120
    parameter pSPI_RF_Depth   = 4,          // Rx FIFO Depth: 2**pRF_Depth
121
    parameter pSPI_TF_Init    = "Src/TF_Init.coe",  // Tx FIFO Memory Init
122
    parameter pSPI_RF_Init    = "Src/RF_Init.coe",  // Rx FIFO Memory Init
123
 
124
    // SSP_UART Module Parameter Settings
125
 
126
    parameter pPS_Default    = 4'h0,        // see baud rate tables SSP_UART
127
    parameter pDiv_Default   = 8'hBF,       // BR = 9600 @UART_Clk = 29.4912 MHz
128
    parameter pRTOChrDlyCnt  = 3,           // Rcv Time Out Character Dly Count
129
    parameter pUART_TF_Depth = 0,           // Tx FIFO Depth: 2**(pTF_Depth + 4)
130
    parameter pUART_RF_Depth = 3,           // Rx FIFO Depth: 2**(pRF_Depth + 4)
131
    parameter pUART_TF_Init  = "Src/UART_TF.coe",   // Tx FIFO Memory Init
132
    parameter pUART_RF_Init  = "Src/UART_RF.coe"    // Rx FIFO Memory Init
133
)(
134
    input   ClkIn,                      // External Clk - drives 4x DCM
135
 
136
    input   nMCLR,                      // Master Clear Input
137
    input   nT0CKI,                     // Timer 0 Clk Input
138
    input   nWDTE,                      // Watch Dog Timer Enable
139
 
140
    input   PROM_WE,                    // Temporary Signal to Force Block RAM
141
 
142
    output  TD,                         // UART TD Output
143
    input   RD,                         // UART RD Input
144
    output  nRTS,                       // UART Request To Send (active low) Out
145
    input   nCTS,                       // UART Clear to Send (active low) Input
146
    output  DE,                         // UART RS-485 Driver Enable
147
 
148
    output  [2:0] nCS,                  // SPI Chip Select (active low) Output
149
    output  SCK,                        // SPI Serial Clock
150
    output  MOSI,                       // SPI Master Out/Slave In Output
151
    input   MISO,                       // SPI Master In/Slave Out Input
152
 
153
    //  Test Signals
154
 
155
    output  [2:0] nCSO,
156
    output  nWait
157
);
158
 
159
////////////////////////////////////////////////////////////////////////////////
160
//
161
//  Declarations
162
//
163
 
164
reg     ClkEn;
165
 
166
reg     [11:0] PROM [4095:0];           // User Program ROM (3x Block RAMs)
167
wire    [11:0] PROM_Addrs;              // Program Counter from CPU
168
reg     [11:0] PROM_DO;                 // Instruction Register to CPU
169
 
170
reg     nWDTE_IFD, nT0CKI_IFD;          // IOB FFs for external inputs
171
wire    WDTE, T0CKI;
172
 
173
wire    [7:0] IO_DO;                    // IO Data Output bus
174
reg     [7:0] IO_DI;                    // IO Data Input bus
175
 
176
reg     [7:0] TRISA, TRISB;             // IO Ports
177
reg     [7:0] PORTA, PORTB;
178
 
179
wire    [1:0] CS;                       // Chip select outputs of the SPI Mstr
180
wire    SPI_SCK;                        // SPI SCK for internal components
181
wire    SPI_MOSI, SPI_MISO;
182
 
183
wire    [7:0] SPI_DO;                   // Output Data Bus of SPI Master module
184
wire    TF_EF, TF_FF, RF_EF, RF_FF;     // SPI Module Status Signals
185
 
186
wire    SSP_MISO;                       // SSP UART MISO signal
187
wire    RTS, CTS;                       // SSP UART Modem Control Signals
188
wire    IRQ;                            // SSP UART Interrupt Request Signal
189
 
190
////////////////////////////////////////////////////////////////////////////////
191
//
192
//  Implementation
193
//
194
 
195
// Instantiate the Clk and Reset Generator Module
196
 
197
M16C5x_ClkGen   ClkGen (
198
                    .nRst(nMCLR),
199
                    .ClkIn(ClkIn),
200
 
201
                    .Clk(Clk),              // Clk      <= (M/D) x ClkIn
202
                    .Clk_UART(Clk_UART),    // Clk_UART <= 2x ClkIn
203
                    .BufClkIn(),            // RefClk   <= Buffered ClkIn
204
 
205
                    .Rst(Rst)
206
                );
207
 
208
//  Generate Clock Enable (Clk/2)
209
 
210
always @(posedge Clk or posedge Rst) ClkEn <= #1 ((Rst) ? 0 : ~ClkEn);
211
 
212
//  Register Inputs and connect to CPU
213
 
214
always @(posedge Clk) nWDTE_IFD  <= #1 ((Rst) ? 1 : nWDTE );
215
always @(posedge Clk) nT0CKI_IFD <= #1 ((Rst) ? 1 : nT0CKI);
216
 
217
assign WDTE  = ~nWDTE_IFD;
218
assign T0CKI = ~nT0CKI_IFD;
219
 
220
// Instantiate the P16C5x module
221
 
222
P16C5x  #(
223
            .pRstVector(pRstVector),
224
            .pWDT_Size(pWDT_Size),
225
            .pRAMA_Init(pRAMA_Init),
226
            .pRAMB_Init(pRAMB_Init)
227
        ) CPU (
228
            .POR(Rst),
229
            .Clk(Clk),
230
            .ClkEn(ClkEn),
231
 
232
            .MCLR(Rst),
233
            .T0CKI(T0CKI),
234
            .WDTE(WDTE),
235
 
236
            .PC(PROM_Addrs),
237
            .ROM(PROM_DO),
238
 
239
            .WE_TRISA(WE_TRISA),
240
            .WE_TRISB(WE_TRISB),
241
            .WE_TRISC(WE_TRISC),
242
            .WE_PORTA(WE_PORTA),
243
            .WE_PORTB(WE_PORTB),
244
            .WE_PORTC(WE_PORTC),
245
            .RE_PORTA(RE_PORTA),
246
            .RE_PORTB(RE_PORTB),
247
            .RE_PORTC(RE_PORTC),
248
 
249
            .IO_DO(IO_DO),
250
            .IO_DI(IO_DI),
251
 
252
            .Rst(),
253
 
254
            .OPTION(),
255
            .IR(),
256
            .dIR(),
257
            .ALU_Op(),
258
            .KI(),
259
            .Err(),
260
            .Skip(),
261
            .TOS(),
262
            .NOS(),
263
            .W(),
264
            .FA(),
265
            .DO(),
266
            .DI(),
267
            .TMR0(),
268
            .FSR(),
269
            .STATUS(),
270
            .T0CKI_Pls(),
271
            .WDTClr(),
272
            .WDT(),
273
            .WDT_TC(),
274
            .WDT_TO(),
275
            .PSCntr(),
276
            .PSC_Pls()
277
        );
278
 
279
////////////////////////////////////////////////////////////////////////////////
280
//
281
//  User Program ROM
282
//
283
 
284
initial
285
  $readmemh(pUserProg, PROM, 0, 4095);
286
 
287
assign WE_PROM = ClkEn & WE_PORTA & PROM_WE;
288
 
289
always @(posedge Clk)
290
begin
291
    if(Rst)
292
        PROM_DO <= #1 0;
293
    else if(WE_PROM)
294
        PROM[{PORTB[7:0], TRISB[7:4]}] <= #1 {TRISB[3:0], TRISA[7:0]};
295
    else
296
        PROM_DO <= #1 PROM[PROM_Addrs];
297
end
298
 
299
//always @(posedge ) begin
300
//    if () begin
301
//        if ()
302
//            [] <= ;
303
//         <= [];
304
//    end
305
//    if ()
306
//         <= [];
307
//end
308
 
309
////////////////////////////////////////////////////////////////////////////////
310
//
311
//  M16C5x I/O
312
//
313
 
314
always @(posedge Clk)
315
begin
316
    if(Rst) begin
317
        TRISA <= #1 ~0;
318
        TRISB <= #1 ~0;
319
        //
320
        PORTA <= #1 ~0;
321
        PORTB <= #1 ~0;
322
    end else if(ClkEn) begin
323
        TRISA <= #1 ((WE_TRISA) ? IO_DO : TRISA);
324
        TRISB <= #1 ((WE_TRISB) ? IO_DO : TRISB);
325
        //
326
        PORTA <= #1 ((WE_PORTA) ? IO_DO : PORTA);
327
        PORTB <= #1 ((WE_PORTB) ? IO_DO : PORTB);
328
    end
329
end
330
 
331
always @(*)
332
begin
333
    casex({RE_PORTA, RE_PORTB, RE_PORTC})
334
        3'b1xx  : IO_DI <= {IRQ, CTS, RTS, DE, RF_FF, RF_EF, TF_FF, TF_EF};
335
        3'b01x  : IO_DI <= PORTB;
336
        3'b001  : IO_DI <= SPI_DO;
337
        default : IO_DI <= 0;
338
    endcase
339
end
340
 
341
//assign TD      = ~PORTA[7];
342
//assign nRTS    = ~PORTA[6];
343
assign nCSO[2] = 1;
344
assign nCSO[1] = 1;
345
assign nCSO[0] = ~CS[0];
346
assign nWait   = ~CS[1];
347
 
348
// Instantiate the M16C5x SPI Interface module
349
 
350
assign SPI_MISO = ((CS[1]) ? SSP_MISO : MISO);
351
 
352
M16C5x_SPI  #(
353
                .pCR_Default(pSPI_CR_Default),
354
                .pTF_Depth(pSPI_TF_Depth),
355
                .pRF_Depth(pSPI_RF_Depth),
356
                .pTF_Init(pSPI_TF_Init),
357
                .pRF_Init(pSPI_RF_Init)
358
            ) SPI (
359
                .Rst(Rst),
360
                .Clk(Clk),
361
 
362
                .ClkEn(ClkEn),
363
 
364
                .WE_CR(WE_TRISC),
365
                .WE_TF(WE_PORTC),
366
                .RE_RF(RE_PORTC),
367
                .DI(IO_DO),
368
                .DO(SPI_DO),
369
 
370
                .CS(CS[1:0]),
371
                .SCK(SCK),
372
                .MOSI(SPI_MOSI),
373
                .MISO(SPI_MISO),
374
 
375
                .SS(SS),
376
                .TF_FF(TF_FF),
377
                .TF_EF(TF_EF),
378
                .RF_FF(RF_FF),
379
                .RF_EF(RF_EF)
380
            );
381
 
382
assign nCS[0] = ~CS[0];
383
assign nCS[1] = ~CS[1];
384
assign nCS[2] = 1'b1;
385
 
386
assign MOSI = SPI_MOSI;
387
 
388
//  Instantiate Global Clock Buffer for driving the SPI Clock to internal nodes
389
 
390
BUFG    BUF1 (
391
            .I(SCK),
392
            .O(SPI_SCK)
393
        );
394
 
395
//  Instantiate UART with an NXP LPC213x/LPC214x SSP-compatible interface
396
 
397
assign CTS = ~nCTS;
398
 
399
M16C5x_UART #(
400
                .pPS_Default(pPS_Default),
401
                .pDiv_Default(pDiv_Default),
402
                .pRTOChrDlyCnt(pRTOChrDlyCnt),
403
                .pTF_Depth(pUART_TF_Depth),
404
                .pRF_Depth(pUART_RF_Depth),
405
                .pTF_Init(pUART_TF_Init),
406
                .pRF_Init(pUART_RF_Init)
407
            ) UART (
408
                .Rst(Rst),
409
 
410
                .Clk_UART(Clk_UART),
411
 
412
                .SSEL(CS[1]),
413
                .SCK(SPI_SCK),
414
                .MOSI(SPI_MOSI),
415
                .MISO(SSP_MISO),
416
 
417
                .TxD(TD),
418
                .RTS(RTS),
419
                .RxD(RD),
420
                .CTS(CTS),
421
 
422
                .DE(DE),
423
 
424
                .IRQ(IRQ)
425
            );
426
 
427
assign nRTS = ~RTS;
428
 
429
endmodule
430
 

powered by: WebSVN 2.1.0

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