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

Subversion Repositories wb4pb

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

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

powered by: WebSVN 2.1.0

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