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

Subversion Repositories xulalx25soc

[/] [xulalx25soc/] [trunk/] [rtl/] [spiarbiter.v] - Blame information for rev 9

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 dgisselq
///////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    spiarbiter.v
4
//
5
// Project:     XuLA2 board
6
//
7
// Purpose:     The XuLA2 offers SPI access to both a FLASH and an SD Card.
8
//              This simple script arbitrates between the two of those to
9
//      determine who has access.  Drivers for both chips may interact with
10
//      this arbiter as though it were a SPI device with one additional piece
11
//      of functionality: the clock line may not be brought low until access
12
//      has been granted to the chip.  Thus, the controller wishing to access
13
//      its device should pull the CS line low, and then wait to read that
14
//      its grant line is high.  Once CS is low and grant is high, it may
15
//      then bring CK low and start its transaction.
16
//
17
//      When two or more controllers request access at the same time,
18
//      access will be given in priority order.  Further, access is always
19
//      granted to device 'A' without request as long as device 'B' isn't
20
//      busy.
21
//
22
//
23
// Creator:     Dan Gisselquist, Ph.D.
24
//              Gisselquist Technology, LLC
25
//
26
///////////////////////////////////////////////////////////////////////////
27
//
28
// Copyright (C) 2015, Gisselquist Technology, LLC
29
//
30
// This program is free software (firmware): you can redistribute it and/or
31
// modify it under the terms of  the GNU General Public License as published
32
// by the Free Software Foundation, either version 3 of the License, or (at
33
// your option) any later version.
34
//
35
// This program is distributed in the hope that it will be useful, but WITHOUT
36
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
37
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
38
// for more details.
39
//
40
// License:     GPL, v3, as defined and found on www.gnu.org,
41
//              http://www.gnu.org/licenses/gpl.html
42
//
43
//
44
///////////////////////////////////////////////////////////////////////////
45
//
46
//
47
module  spiarbiter(i_clk,
48
                i_cs_a_n, i_ck_a, i_mosi_a,
49
                i_cs_b_n, i_ck_b, i_mosi_b,
50
                o_cs_a_n, o_cs_b_n, o_ck, o_mosi); // , i_en, o_err
51
        input           i_clk;
52
        input           i_cs_a_n, i_ck_a, i_mosi_a;
53
        // output       wire    o_grant_a;
54
        input           i_cs_b_n, i_ck_b, i_mosi_b;
55
        // output       wire    o_grant_b;
56
        output  wire    o_cs_a_n, o_cs_b_n, o_ck, o_mosi;
57
 
58
        reg     a_owner;
59
        initial a_owner = 1'b1;
60
        always @(posedge i_clk)
61
                if ((i_cs_a_n)&&(i_cs_b_n))
62
                        a_owner <= 1'b1; // Keep control
63
                else if ((i_cs_a_n)&&(~i_cs_b_n))
64
                        a_owner <= 1'b0; // Give up control
65
 
66
        // assign       o_grant_a = a_owner;
67
        // assign       o_grant_b = (~a_owner);
68
 
69
        assign  o_cs_a_n = (~a_owner)||(~i_cs_a_n);
70
        assign  o_cs_b_n = ( a_owner)||(~i_cs_b_n);
71
        assign  o_ck     = ( a_owner)?i_ck_a   : i_ck_b;
72
        assign  o_mosi   = ( a_owner)?i_mosi_a : i_mosi_b;
73
 
74
endmodule
75
 

powered by: WebSVN 2.1.0

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