Line No. | Rev | Author | Line |
---|---|---|---|
1 | 6 | kaklik | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
2 | <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> |
||
3 | <title>Procyon AVRlib: sramsw.c Source File</title> |
||
4 | <link href="dox.css" rel="stylesheet" type="text/css"> |
||
5 | </head><body> |
||
6 | <!-- Generated by Doxygen 1.4.2 --> |
||
7 | <div class="qindex"><a class="qindex" href="main.html">Main Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="annotated.html">Data Structures</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="functions.html">Data Fields</a> | <a class="qindex" href="globals.html">Globals</a> | <a class="qindex" href="pages.html">Related Pages</a></div> |
||
8 | <h1>sramsw.c</h1><a href="sramsw_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment">00001 <span class="comment">/*! \file sramsw.c \brief Software-driven SRAM memory bus access functions. */</span> |
||
9 | 00002 <span class="comment">//*****************************************************************************</span> |
||
10 | 00003 <span class="comment">//</span> |
||
11 | 00004 <span class="comment">// File Name : 'sramsw.c'</span> |
||
12 | 00005 <span class="comment">// Title : Software-driven SRAM memory bus access functions</span> |
||
13 | 00006 <span class="comment">// Author : Pascal Stang - Copyright (C) 2002</span> |
||
14 | 00007 <span class="comment">// Created : 11/11/2002</span> |
||
15 | 00008 <span class="comment">// Revised : 11/13/2002</span> |
||
16 | 00009 <span class="comment">// Version : 1.0</span> |
||
17 | 00010 <span class="comment">// Target MCU : Atmel AVR series</span> |
||
18 | 00011 <span class="comment">// Editor Tabs : 4</span> |
||
19 | 00012 <span class="comment">//</span> |
||
20 | 00013 <span class="comment">// This code is distributed under the GNU Public License</span> |
||
21 | 00014 <span class="comment">// which can be found at http://www.gnu.org/licenses/gpl.txt</span> |
||
22 | 00015 <span class="comment">//</span> |
||
23 | 00016 <span class="comment">//*****************************************************************************</span> |
||
24 | 00017 |
||
25 | 00018 <span class="preprocessor">#include <avr/io.h></span> |
||
26 | 00019 <span class="preprocessor">#include <avr/interrupt.h></span> |
||
27 | 00020 |
||
28 | 00021 <span class="preprocessor">#include "<a class="code" href="global_8h.html">global.h</a>"</span> |
||
29 | 00022 <span class="preprocessor">#include "<a class="code" href="sramsw_8h.html">sramsw.h</a>"</span> |
||
30 | 00023 |
||
31 | 00024 <span class="comment">// global variables</span> |
||
32 | 00025 |
||
33 | 00026 <span class="comment">// functions</span> |
||
34 | <a name="l00027"></a><a class="code" href="sramsw_8h.html#a0">00027</a> <span class="keywordtype">void</span> <a class="code" href="sramsw_8c.html#a0">sramswInit</a>(<span class="keywordtype">void</span>) |
||
35 | 00028 { |
||
36 | 00029 <span class="comment">// initialize port state</span> |
||
37 | 00030 outb(SRAM_ADL, 0xFF); <span class="comment">// addr/data port set to 0xFF (pull-ups enabled)</span> |
||
38 | 00031 outb(SRAM_AH, 0x00); <span class="comment">// high addr port set to 0x00</span> |
||
39 | 00032 <span class="comment">// initialize port directions</span> |
||
40 | 00033 outb(SRAM_ADL_DDR, 0x00); <span class="comment">// addr/data port set to input</span> |
||
41 | 00034 outb(SRAM_AH_DDR, 0xFF); <span class="comment">// high addr port set to output</span> |
||
42 | 00035 <span class="comment">// initialize control line states</span> |
||
43 | 00036 sbi(SRAM_CTRL, SRAM_WR); <span class="comment">// de-assert write (active low)</span> |
||
44 | 00037 sbi(SRAM_CTRL, SRAM_RD); <span class="comment">// de-assert read (active low)</span> |
||
45 | 00038 cbi(SRAM_CTRL, SRAM_ALE); <span class="comment">// de-assert ALE (active high)</span> |
||
46 | 00039 <span class="comment">// set control line direction</span> |
||
47 | 00040 sbi(SRAM_CTRL_DDR, SRAM_WR); |
||
48 | 00041 sbi(SRAM_CTRL_DDR, SRAM_RD); |
||
49 | 00042 sbi(SRAM_CTRL_DDR, SRAM_ALE); |
||
50 | 00043 <span class="comment">// set page lines direction</span> |
||
51 | 00044 outb(SRAM_PAGE_DDR, inb(SRAM_PAGE_DDR) | SRAM_PAGE_MASK ); |
||
52 | 00045 <span class="comment">// initialize page</span> |
||
53 | 00046 <a class="code" href="sramsw_8c.html#a4">sramswSetPage</a>(0); |
||
54 | 00047 } |
||
55 | 00048 |
||
56 | 00049 <span class="keywordtype">void</span> sramswOff(<span class="keywordtype">void</span>) |
||
57 | 00050 { |
||
58 | 00051 } |
||
59 | 00052 |
||
60 | <a name="l00053"></a><a class="code" href="sramsw_8h.html#a1">00053</a> <span class="keywordtype">void</span> <a class="code" href="sramsw_8c.html#a2">sramswWrite</a>(u32 addr, u08 data) |
||
61 | 00054 { |
||
62 | 00055 <span class="comment">// set page</span> |
||
63 | 00056 <a class="code" href="sramsw_8c.html#a4">sramswSetPage</a>( (addr & 0x00FF0000)>>16 ); |
||
64 | 00057 <span class="comment">// set high-order address</span> |
||
65 | 00058 outb(SRAM_AH, (addr & 0x0000FF00)>>8 ); |
||
66 | 00059 <span class="comment">// set low-order address</span> |
||
67 | 00060 outb(SRAM_ADL, addr & 0x000000FF); |
||
68 | 00061 <span class="comment">// apply low-order address to latch</span> |
||
69 | 00062 outb(SRAM_ADL_DDR, 0xFF); |
||
70 | 00063 <span class="comment">// clock latch to save low-order address</span> |
||
71 | 00064 sbi(SRAM_CTRL, SRAM_ALE); <span class="comment">// assert ALE (active high)</span> |
||
72 | 00065 <span class="keyword">asm</span> <span class="keyword">volatile</span> (<span class="stringliteral">"nop"</span>); |
||
73 | 00066 cbi(SRAM_CTRL, SRAM_ALE); <span class="comment">// de-assert ALE (active high)</span> |
||
74 | 00067 |
||
75 | 00068 <span class="comment">// apply data to memory</span> |
||
76 | 00069 outb(SRAM_ADL, data); |
||
77 | 00070 <span class="comment">// clock write line to store data</span> |
||
78 | 00071 cbi(SRAM_CTRL, SRAM_WR); <span class="comment">// assert write (active low)</span> |
||
79 | 00072 <span class="keyword">asm</span> <span class="keyword">volatile</span> (<span class="stringliteral">"nop"</span>); |
||
80 | 00073 sbi(SRAM_CTRL, SRAM_WR); <span class="comment">// de-assert write (active low)</span> |
||
81 | 00074 } |
||
82 | 00075 |
||
83 | <a name="l00076"></a><a class="code" href="sramsw_8h.html#a2">00076</a> u08 <a class="code" href="sramsw_8c.html#a3">sramswRead</a>(u32 addr) |
||
84 | 00077 { |
||
85 | 00078 u08 data; |
||
86 | 00079 |
||
87 | 00080 <span class="comment">// set page</span> |
||
88 | 00081 <a class="code" href="sramsw_8c.html#a4">sramswSetPage</a>( (addr & 0x00FF0000)>>16 ); |
||
89 | 00082 <span class="comment">// set high-order address</span> |
||
90 | 00083 outb(SRAM_AH, (addr & 0x0000FF00)>>8 ); |
||
91 | 00084 <span class="comment">// set low-order address</span> |
||
92 | 00085 outb(SRAM_ADL, addr & 0x000000FF); |
||
93 | 00086 <span class="comment">// apply low-order address to latch</span> |
||
94 | 00087 outb(SRAM_ADL_DDR, 0xFF); |
||
95 | 00088 <span class="comment">// clock latch to save low-order address</span> |
||
96 | 00089 sbi(SRAM_CTRL, SRAM_ALE); <span class="comment">// assert ALE (active high)</span> |
||
97 | 00090 <span class="keyword">asm</span> <span class="keyword">volatile</span> (<span class="stringliteral">"nop"</span>); |
||
98 | 00091 cbi(SRAM_CTRL, SRAM_ALE); <span class="comment">// de-assert ALE (active high)</span> |
||
99 | 00092 |
||
100 | 00093 <span class="comment">// switch data bus to input</span> |
||
101 | 00094 outb(SRAM_ADL_DDR, 0x00); |
||
102 | 00095 <span class="comment">// clear pullups</span> |
||
103 | 00096 outb(SRAM_ADL, 0x00); |
||
104 | 00097 <span class="comment">// request data from memory</span> |
||
105 | 00098 cbi(SRAM_CTRL, SRAM_RD); <span class="comment">// assert read (active low)</span> |
||
106 | 00099 <span class="comment">// retrieve data</span> |
||
107 | 00100 <span class="keyword">asm</span> <span class="keyword">volatile</span> (<span class="stringliteral">"nop"</span>); |
||
108 | 00101 data = inb(SRAM_ADL_IN); |
||
109 | 00102 <span class="comment">// release read line</span> |
||
110 | 00103 sbi(SRAM_CTRL, SRAM_RD); <span class="comment">// de-assert read (active low)</span> |
||
111 | 00104 <span class="comment">// switch data bus to output</span> |
||
112 | 00105 outb(SRAM_ADL_DDR, 0xFF); |
||
113 | 00106 |
||
114 | 00107 <span class="keywordflow">return</span> data; |
||
115 | 00108 } |
||
116 | 00109 |
||
117 | <a name="l00110"></a><a class="code" href="sramsw_8h.html#a3">00110</a> <span class="keywordtype">void</span> <a class="code" href="sramsw_8c.html#a4">sramswSetPage</a>(u08 page) |
||
118 | 00111 { |
||
119 | 00112 outb(SRAM_PAGE, (page & SRAM_PAGE_MASK)); |
||
120 | 00113 } |
||
121 | </pre></div><hr size="1"><address style="align: right;"><small>Generated on Sun Oct 29 03:41:07 2006 for Procyon AVRlib by |
||
122 | <a href="http://www.doxygen.org/index.html"> |
||
123 | <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.2 </small></address> |
||
124 | </body> |
||
125 | </html> |
Powered by WebSVN v2.8.3