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

Subversion Repositories wb4pb

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

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
; IMPORTANT NOTICE!
43
; be carefull, if using interrupts. wishbone cycles must be atomar, as any
44
; other processor local bus cycles are normally be. interrupting wishbone
45
; access may cause a crash of external wishbone master fsm, especially, if
46
; program flow through isr leads to another wishbone cycle!
47
 
48
 
49
NAMEREG sF , wb_addr
50
NAMEREG sE , wb_data ; also used as tmp-reg for status polling
51
 
52
CONSTANT WB_ACK_FLAG , 01
53
 
54
CONSTANT GPIO_IO_ADDR , 00
55
CONSTANT GPIO_OE_ADDR , 01
56
 
57
 
58
ADDRESS 000
59
 
60
; main entry point
61
DISABLE INTERRUPT
62
 
63
CALL gpio_init
64
 
65
; mirroring upper nibble gpio inputs
66
; to lower nibble gpio outputs
67
LOAD wb_addr , GPIO_IO_ADDR
68
mainloop:
69
  CALL wb_rd
70
  NAMEREG s0 , i
71
  LOAD i , 04
72
  for_i_in_4_downto_1_loop: ; bitshifting (wb_data>>4)
73
    SR0 wb_data
74
    SUB i , 01
75
    JUMP NZ , for_i_in_4_downto_1_loop
76
  CALL wb_wr
77
  JUMP mainloop
78
 
79
gpio_init:
80
  ; setting all outputs low
81
  LOAD wb_addr , GPIO_IO_ADDR
82
  LOAD wb_data , 00
83
  CALL wb_wr
84
  ; configuring lower gpio nibble as output
85
  LOAD wb_addr , GPIO_OE_ADDR
86
  LOAD wb_data , 0F
87
  CALL wb_wr
88
RETURN
89
 
90
; subroutines wb_wr and wb_rd are working together with external wbm_picoblaze
91
; wishbone adapter module and therefore should not be modified. wb_wait_on_ack
92
; is a supporting subroutine, which should not be called directly
93
;
94
; transfer principle wishbone write:
95
; 1. OUTPUT cycle to set up wishbone address, data and control signals from
96
;    PORT_ID, OUT_PORT and WRITE_STROBE
97
; 2. INPUT cycle(s) to poll wishbone peripheral acknowledgement using IN_PORT
98
; => at least one OUTPUT and one INPUT cycle for a write
99
;
100
; transfer principle wishbone read:
101
; 1. INPUT cycle to set up wishbone address and control signals from PORT_ID
102
;    and READ_STROBE
103
; 2. INPUT cycle(s) to poll wishbone peripheral acknowledgement using IN_PORT
104
; 3. the very next INPUT cycle after acknowledgement contains valid wishbone
105
;    data from IN_PORT
106
; => at least three INPUT cycles for a read
107
;
108
; calling examples:
109
;
110
; wishbone write code =>
111
;
112
; LOAD wb_addr ,  ; setting up address
113
; LOAD wb_data ,  ; setting up data
114
; CALL wb_wr ; starting wishbone write cycle
115
;  ; wishbone cycle finished
116
;
117
; wishbone read code =>
118
;
119
; LOAD wb_addr ,  ; setting up address
120
; CALL wb_rd ; starting wishbone read cycle
121
;  ; wishbone cycle finished, wb_data is updated now
122
 
123
; wishbone write access
124
wb_wr:
125
  OUTPUT wb_data , (wb_addr)
126
  CALL wb_wait_on_ack
127
RETURN
128
 
129
; wishbone read access
130
wb_rd:
131
  CALL wb_wait_on_ack
132
  INPUT wb_data , (wb_addr)
133
RETURN
134
 
135
; waiting on wishbone cycle to complete
136
wb_wait_on_ack:
137
  INPUT wb_data , (wb_addr)
138
  TEST wb_data , WB_ACK_FLAG
139
  JUMP Z , wb_wait_on_ack
140
RETURN
141
 
142
; interrupt handling template, if needed
143
isr:
144
RETURNI DISABLE
145
ADDRESS 3FF
146
JUMP isr

powered by: WebSVN 2.1.0

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