add first peripheral set
[shakti-peripherals.git] / src / peripherals / i2c / I2C_Defs.bsv
1 /*
2 Copyright (c) 2013, IIT Madras
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6
7 * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
8 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9 * Neither the name of IIT Madras nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10
11 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
12 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
13 */
14 /* This file defines the functions and the types required to implement I2C routines */
15 // ================================================
16 // Types
17
18 // Chip Clock Frequencies -- Assuming 50MHz Processor operating frequencies
19 `define CLK3 15
20 `define CLK443 9
21 `define CLK6 6
22 `define CLK8 4
23 `define CLK12 2
24
25 //Bus Clock Frequencies -- Assuming 8MHz Chip Clock Frequency
26 `define SCL90 81
27 `define SCL45 180
28 `define SCL11 692
29 `define SCL1 6992
30
31
32 typedef union tagged {
33 void Dead;
34 void Idle;
35 void STA;
36 void NAck_1;
37 void RTSTA;
38 void SendAddr;
39 void Intrpt;
40 void SendData;
41 void ReadData;
42 void ResetI2C;
43 void BError;
44 void Ack;
45 void NAck;
46 void SwitchMode;
47 void MultipleTrans;
48 void End;
49 void Idleready;
50 } MTrans_State deriving (Bits, Eq);
51
52 typedef union tagged {
53 void Dead;
54 void Idle;
55 void STA;
56 void SendAddr;
57 void Intrpt;
58 void ReadData;
59 void Ack;
60 void NAck;
61 void End;
62 } MRecv_State deriving (Bits, Eq);
63
64 typedef enum {
65 Write,
66 Read
67 } Transaction deriving (Bits, Eq);
68
69 // ================================================
70 // I2C Registers Map -- Custom for now. Should Adhere to the Driver
71 typedef enum {
72 //Registers
73 S2 = 'h00,
74 Control = 'h08,
75 S0 = 'h10,
76 Status = 'h18,
77 S01 = 'h20,
78 S3 = 'h28,
79 Time = 'h30,
80 SCL = 'h38,
81 DRV0 = 'h40,
82 DRV1 = 'h48,
83 DRV2 = 'h50,
84 PD = 'h58,
85 PPEN = 'h60,
86 PRG_SLEW = 'h68,
87 PUQ = 'h70,
88 PWRUPZHL = 'h78,
89 PWRUP_PULL_EN= 'h80
90 }I2C deriving (Bits, Eq);
91
92 typedef Bit#(8) I2C_RegWidth;
93