|
| 1 | +// Zinc, the bare metal stack for rust. |
| 2 | +// Copyright 2014 Ben Gamari <[email protected]> |
| 3 | +// |
| 4 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +// you may not use this file except in compliance with the License. |
| 6 | +// You may obtain a copy of the License at |
| 7 | +// |
| 8 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +// |
| 10 | +// Unless required by applicable law or agreed to in writing, software |
| 11 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +// See the License for the specific language governing permissions and |
| 14 | +// limitations under the License. |
| 15 | + |
| 16 | +/*! |
| 17 | +SPI peripheral |
| 18 | +*/ |
| 19 | + |
| 20 | +/// Registers |
| 21 | +pub mod reg { |
| 22 | + use lib::volatile_cell::VolatileCell; |
| 23 | + use core::ops::Drop; |
| 24 | + |
| 25 | + ioregs!(SPI = { |
| 26 | + 0x0 => reg32 mcr { //! Module configuration register |
| 27 | + 0 => halt, //= Start/stop transfers |
| 28 | + 8..9 => smpl_pt { //! How many clocks between SCK edge and SIN sample |
| 29 | + 0x0 => SMPL_PT_0_CLKS, |
| 30 | + 0x1 => SMPL_PT_1_CLKS, |
| 31 | + 0x2 => SMPL_PT_2_CLKS, |
| 32 | + } |
| 33 | + 10 => clr_rxf, //= Flush RX FIFO |
| 34 | + 11 => clr_txf, //= Flush TX FIFO |
| 35 | + 12 => dis_rxf, //= Disable receive FIFO |
| 36 | + 13 => dis_txf, //= Disable transmit FIFO |
| 37 | + 14 => mdis, //= Disable module |
| 38 | + 15 => doze, //= Doze enable |
| 39 | + 16..20 => pcsis[5], //= Chip select inactive states |
| 40 | + 24 => rooe, //= Receive FIFO overflow overwrite enable |
| 41 | + 26 => mtfe, //= Modified timing format enable |
| 42 | + 27 => frz, //= Freeze |
| 43 | + 28..29 => dconf { //! Peripheral configuration |
| 44 | + 0x0 => SPI, |
| 45 | + } |
| 46 | + 30 => cont_scke, //= Continuous SCK enable |
| 47 | + 31 => mstr { //! Master/slave mode select |
| 48 | + 0x0 => SLAVE, |
| 49 | + 0x1 => MASTER, |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + 0x8 => reg32 tcr { //! Transfer count register |
| 54 | + 16..31 => tcnt, //= Number of frames transmitted |
| 55 | + } |
| 56 | + |
| 57 | + 0xc => reg32 ctar[2] { //! Clock and transfer attributes |
| 58 | + /// Baud rate scaler (master only) |
| 59 | + /// |
| 60 | + /// SCK baud rate = (f_sys / PBR) * (1 + DBR) / BR |
| 61 | + 0..3 => br, |
| 62 | + /// Delay after transfer scaler (master only) |
| 63 | + /// |
| 64 | + /// t_delay = (1/f_sys) * PDT * DT |
| 65 | + 4..7 => dt, |
| 66 | + /// After SCK delay scaler (master only) |
| 67 | + /// |
| 68 | + /// t_ASC = (1/f_sys) * PASC * ASC |
| 69 | + 8..11 => asc, |
| 70 | + /// CS to SCK delay scaler (master only) |
| 71 | + 12..15 => cssck, |
| 72 | + /// Baud rate prescaler (master only) |
| 73 | + 17..16 => pbr { |
| 74 | + 0x0 => PBR_2, |
| 75 | + 0x1 => PBR_3, |
| 76 | + 0x2 => PBR_5, |
| 77 | + 0x3 => PBR_7, |
| 78 | + } |
| 79 | + /// Delay after transfer prescaler (master only) |
| 80 | + 18..19 => pdt { |
| 81 | + 0x0 => PDT_2, |
| 82 | + 0x1 => PDT_3, |
| 83 | + 0x2 => PDT_5, |
| 84 | + 0x3 => PDT_7, |
| 85 | + }, |
| 86 | + /// After SCK delay prescaler (master only) |
| 87 | + 20..21 => pasc { |
| 88 | + 0x0 => PASC_2, |
| 89 | + 0x1 => PASC_3, |
| 90 | + 0x2 => PASC_5, |
| 91 | + 0x3 => PASC_7, |
| 92 | + }, |
| 93 | + /// CS to SCK delay prescaler (master only) |
| 94 | + 22..23 => pcssck { |
| 95 | + 0x0 => PCSSCK_2, |
| 96 | + 0x1 => PCSSCK_3, |
| 97 | + 0x2 => PCSSCK_5, |
| 98 | + 0x3 => PCSSCK_7, |
| 99 | + }, |
| 100 | + /// Transfer LSB first (master only) |
| 101 | + 24 => lsbfe, |
| 102 | + /// Clock phase |
| 103 | + 25 => cpha, |
| 104 | + /// Clock polarity |
| 105 | + 26 => cpol, |
| 106 | + /// Frame size |
| 107 | + /// |
| 108 | + /// Number of bits transferred per frame minus one. |
| 109 | + /// In master mode the top bit of this field is the DBR, double |
| 110 | + /// baud rate, flag |
| 111 | + 27..31 => fmsz, |
| 112 | + } |
| 113 | + |
| 114 | + 0x2c => reg32 sr { //! Status register |
| 115 | + 0..3 => popnxtptr, //= Pop next pointer |
| 116 | + 4..7 => rxctr, //= RX FIFO counter |
| 117 | + 8..11 => txnxtptr, //= Transmit next pointer |
| 118 | + 12..15 => txctr, //= TX FIFO counter |
| 119 | + 17 => rfdf: set_to_clear, //= Receive FIFO drain flag |
| 120 | + 19 => rfof: set_to_clear, //= Receive FIFO overflow flag |
| 121 | + 25 => tfff: set_to_clear, //= Transmit FIFO fill flag |
| 122 | + 27 => tfuf: set_to_clear, //= Transmit FIFO underflow flag |
| 123 | + 28 => eoqf: set_to_clear, //= End of queue flag |
| 124 | + 30 => rxrxs: set_to_clear, //= TX/RX running |
| 125 | + 31 => tcf: set_to_clear, //= Transfer complete flag |
| 126 | + } |
| 127 | + |
| 128 | + 0x30 => reg32 rser { //! DMA/interrupt request select and enable |
| 129 | + /// Receive FIFO drain DMA/interrupt request select |
| 130 | + 16 => rfdf_dirs { |
| 131 | + 0x0 => RFDF_IRQ, |
| 132 | + 0x1 => RFDF_DMA, |
| 133 | + } |
| 134 | + 17 => rfdf_re, //= Recieve FIFO drain request enable |
| 135 | + 19 => rfof_re, //= Receive FIFO overflow request enable |
| 136 | + /// Transmit FIFO fill DMA/interrupt request select |
| 137 | + 24 => tfff_dirs { |
| 138 | + 0x0 => TFFF_IRQ, |
| 139 | + 0x1 => TFFF_DMA, |
| 140 | + } |
| 141 | + 25 => tfff_re, //= Transmit FIFO fill request enable |
| 142 | + 27 => tfuf_re, //= Transmit FIFO underflow request enable |
| 143 | + 28 => eoqf_re, //= End of Queue request enable |
| 144 | + 31 => tcf_re, //= Transmission complete request enable |
| 145 | + } |
| 146 | + |
| 147 | + 0x34 => reg32 pushr { //! TX FIFO register |
| 148 | + 0..15 => txdata, //= Transmitted data |
| 149 | + 16..21 => pcs[6], //= Chip select state (master only) |
| 150 | + /// Clear transfer counter (`TCR.TCNT`) (master only) |
| 151 | + 26 => ctcnt, |
| 152 | + /// Set End of Queue flag (`SR.EOQF`) at end of transfer (master only) |
| 153 | + 27 => eoq, |
| 154 | + 28..30 => ctas, //= CTAR select (master only) |
| 155 | + 31 => cont, //= Continuous CS enable (master only) |
| 156 | + } |
| 157 | + |
| 158 | + 0x38 => reg32 popr { //! RX FIFO register |
| 159 | + 0..31 => rxdata: ro, //= Received data |
| 160 | + } |
| 161 | + |
| 162 | + 0x3c => reg32 txfr[4] { //! TX FIFO debug registers |
| 163 | + 0..15 => txdata: ro, |
| 164 | + 16..31 => txcmd_txdata: ro, |
| 165 | + } |
| 166 | + |
| 167 | + 0x7c => reg32 rxfr[4] { //! RX FIFO debug registers |
| 168 | + 0..31 => rxdata: ro, |
| 169 | + } |
| 170 | + }) |
| 171 | +} |
0 commit comments