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

Subversion Repositories wb4pb

[/] [wb4pb/] [trunk/] [asm/] [pbwbgpio.psm] - Blame information for rev 21

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

Line No. Rev Author Line
1 2 ste.fis
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;; This sourcecode is released under BSD license.
3
;; Please see http://www.opensource.org/licenses/bsd-license.php for details!
4
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5
;;
6
;; Copyright (c) 2010, Stefan Fischer 
7
;; All rights reserved.
8
;;
9
;; Redistribution and use in source and binary forms, with or without
10
;; modification, are permitted provided that the following conditions are met:
11
;;
12
;;  * Redistributions of source code must retain the above copyright notice,
13
;;    this list of conditions and the following disclaimer.
14
;;  * Redistributions in binary form must reproduce the above copyright notice,
15
;;    this list of conditions and the following disclaimer in the documentation
16
;;    and/or other materials provided with the distribution.
17
;;  * Neither the name of the author nor the names of his contributors may be
18
;;    used to endorse or promote products derived from this software without
19
;;    specific prior written permission.
20
;;
21
;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22
;; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23
;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24
;; ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25
;; LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26
;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27
;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28
;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29
;; CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
;; ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31
;; POSSIBILITY OF SUCH DAMAGE.
32
;;
33
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
34
;; filename: pbwbgpio.psm
35
;; description: gpio example, demonstrating access to wishbone peripherals
36
;; todo4user: modify main program and gpio_init code as needed
37
;; version: 0.0.0
38
;; changelog: - 0.0.0, initial release
39
;;            - ...
40
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
41
 
42
 
43 21 ste.fis
; wishbone variables
44 2 ste.fis
NAMEREG sF , wb_addr
45
NAMEREG sE , wb_data ; also used as tmp-reg for status polling
46
 
47
 
48
ADDRESS 000
49
 
50
; main entry point
51 21 ste.fis
;;;;;;;;;;;;;;;;;;
52
 
53 2 ste.fis
DISABLE INTERRUPT
54
 
55
CALL gpio_init
56
 
57
; mirroring upper nibble gpio inputs
58
; to lower nibble gpio outputs
59
LOAD wb_addr , GPIO_IO_ADDR
60
mainloop:
61
  CALL wb_rd
62
  NAMEREG s0 , i
63
  LOAD i , 04
64
  for_i_in_4_downto_1_loop: ; bitshifting (wb_data>>4)
65
    SR0 wb_data
66
    SUB i , 01
67
    JUMP NZ , for_i_in_4_downto_1_loop
68
  CALL wb_wr
69
  JUMP mainloop
70
 
71 21 ste.fis
 
72
; wbs_gpio module subroutines and settings
73
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
74
 
75
; usage:
76
; 1. set bitmasks for output enable and output level in gpio_init subroutine
77
; 2. call gpio_init subroutine to configure wbs_gpio module for operation
78
; 3. use wb_wr and wb_rd subroutines to access i/o register
79
 
80
; gpio start-up configuration, i. e. i/o direction and default output value
81 2 ste.fis
gpio_init:
82
  ; setting all outputs low
83
  LOAD wb_addr , GPIO_IO_ADDR
84
  LOAD wb_data , 00
85
  CALL wb_wr
86
  ; configuring lower gpio nibble as output
87
  LOAD wb_addr , GPIO_OE_ADDR
88
  LOAD wb_data , 0F
89
  CALL wb_wr
90
RETURN
91
 
92 21 ste.fis
; register addressing
93
CONSTANT GPIO_IO_ADDR , 00 ; input/output register
94
CONSTANT GPIO_OE_ADDR , 01 ; output-enable register
95
 
96
 
97
; wbm_picoblaze module subroutines and settings
98
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
99
 
100 2 ste.fis
; subroutines wb_wr and wb_rd are working together with external wbm_picoblaze
101
; wishbone adapter module and therefore should not be modified. wb_wait_on_ack
102
; is a supporting subroutine, which should not be called directly
103
;
104
; transfer principle wishbone write:
105
; 1. OUTPUT cycle to set up wishbone address, data and control signals from
106
;    PORT_ID, OUT_PORT and WRITE_STROBE
107
; 2. INPUT cycle(s) to poll wishbone peripheral acknowledgement using IN_PORT
108
; => at least one OUTPUT and one INPUT cycle for a write
109
;
110
; transfer principle wishbone read:
111
; 1. INPUT cycle to set up wishbone address and control signals from PORT_ID
112
;    and READ_STROBE
113
; 2. INPUT cycle(s) to poll wishbone peripheral acknowledgement using IN_PORT
114
; 3. the very next INPUT cycle after acknowledgement contains valid wishbone
115
;    data from IN_PORT
116
; => at least three INPUT cycles for a read
117
;
118
; calling examples:
119
;
120
; wishbone write code =>
121
;
122
; LOAD wb_addr ,  ; setting up address
123
; LOAD wb_data ,  ; setting up data
124
; CALL wb_wr ; starting wishbone write cycle
125
;  ; wishbone cycle finished
126
;
127
; wishbone read code =>
128
;
129
; LOAD wb_addr ,  ; setting up address
130
; CALL wb_rd ; starting wishbone read cycle
131 21 ste.fis
; LOAD  , wb_data ; wb_data is updated now
132
;  ; wishbone cycle finished
133 2 ste.fis
 
134
; wishbone write access
135
wb_wr:
136
  OUTPUT wb_data , (wb_addr)
137
  CALL wb_wait_on_ack
138
RETURN
139
 
140
; wishbone read access
141
wb_rd:
142
  CALL wb_wait_on_ack
143
  INPUT wb_data , (wb_addr)
144
RETURN
145
 
146
; waiting on wishbone cycle to complete
147
wb_wait_on_ack:
148
  INPUT wb_data , (wb_addr)
149
  TEST wb_data , WB_ACK_FLAG
150
  JUMP Z , wb_wait_on_ack
151
RETURN
152
 
153 21 ste.fis
CONSTANT WB_ACK_FLAG , 01
154
 
155
 
156
; interrupt subroutines and settings
157
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
158
 
159
; IMPORTANT NOTICE!
160
; be carefull, if using interrupts. wishbone cycles must be atomar, as any
161
; other processor local bus cycles are normally be. interrupting wishbone
162
; access may cause a crash of external wishbone master fsm, especially, if
163
; program flow through isr leads to another wishbone cycle!
164
 
165 2 ste.fis
; interrupt handling template, if needed
166
isr:
167
RETURNI DISABLE
168
ADDRESS 3FF
169
JUMP isr

powered by: WebSVN 2.1.0

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