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

Subversion Repositories wb4pb

[/] [wb4pb/] [trunk/] [asm/] [pbwbgpio.psm] - Diff between revs 21 and 31

Only display areas with differences | Details | Blame | View Log

Rev 21 Rev 31
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; This sourcecode is released under BSD license.
;; This sourcecode is released under BSD license.
;; Please see http://www.opensource.org/licenses/bsd-license.php for details!
;; Please see http://www.opensource.org/licenses/bsd-license.php for details!
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;
;; Copyright (c) 2010, Stefan Fischer 
;; Copyright (c) 2010, Stefan Fischer 
;; All rights reserved.
;; All rights reserved.
;;
;;
;; Redistribution and use in source and binary forms, with or without
;; Redistribution and use in source and binary forms, with or without
;; modification, are permitted provided that the following conditions are met:
;; modification, are permitted provided that the following conditions are met:
;;
;;
;;  * Redistributions of source code must retain the above copyright notice,
;;  * Redistributions of source code must retain the above copyright notice,
;;    this list of conditions and the following disclaimer.
;;    this list of conditions and the following disclaimer.
;;  * Redistributions in binary form must reproduce the above copyright notice,
;;  * Redistributions in binary form must reproduce the above copyright notice,
;;    this list of conditions and the following disclaimer in the documentation
;;    this list of conditions and the following disclaimer in the documentation
;;    and/or other materials provided with the distribution.
;;    and/or other materials provided with the distribution.
;;  * Neither the name of the author nor the names of his contributors may be
 
;;    used to endorse or promote products derived from this software without
 
;;    specific prior written permission.
 
;;
;;
;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
;; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
;; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
;; ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
;; ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
;; LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
;; LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
;; CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
;; CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
;; ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
;; ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
;; POSSIBILITY OF SUCH DAMAGE.
;; POSSIBILITY OF SUCH DAMAGE.
;;
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; filename: pbwbgpio.psm
;; filename: pbwbgpio.psm
;; description: gpio example, demonstrating access to wishbone peripherals
;; description: gpio example, demonstrating access to wishbone peripherals
;; todo4user: modify main program and gpio_init code as needed
;; todo4user: modify main program and gpio_init code as needed
;; version: 0.0.0
;; version: 0.0.0
;; changelog: - 0.0.0, initial release
;; changelog: - 0.0.0, initial release
;;            - ...
;;            - ...
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; wishbone variables
; wishbone variables
NAMEREG sF , wb_addr
NAMEREG sF , wb_addr
NAMEREG sE , wb_data ; also used as tmp-reg for status polling
NAMEREG sE , wb_data ; also used as tmp-reg for status polling
ADDRESS 000
ADDRESS 000
; main entry point
; main entry point
;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;
DISABLE INTERRUPT
DISABLE INTERRUPT
CALL gpio_init
CALL gpio_init
; mirroring upper nibble gpio inputs
; mirroring upper nibble gpio inputs
; to lower nibble gpio outputs
; to lower nibble gpio outputs
LOAD wb_addr , GPIO_IO_ADDR
LOAD wb_addr , GPIO_IO_ADDR
mainloop:
mainloop:
  CALL wb_rd
  CALL wb_rd
  NAMEREG s0 , i
  NAMEREG s0 , i
  LOAD i , 04
  LOAD i , 04
  for_i_in_4_downto_1_loop: ; bitshifting (wb_data>>4)
  for_i_in_4_downto_1_loop: ; bitshifting (wb_data>>4)
    SR0 wb_data
    SR0 wb_data
    SUB i , 01
    SUB i , 01
    JUMP NZ , for_i_in_4_downto_1_loop
    JUMP NZ , for_i_in_4_downto_1_loop
  CALL wb_wr
  CALL wb_wr
  JUMP mainloop
  JUMP mainloop
; wbs_gpio module subroutines and settings
; wbs_gpio module subroutines and settings
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; usage:
; usage:
; 1. set bitmasks for output enable and output level in gpio_init subroutine
; 1. set bitmasks for output enable and output level in gpio_init subroutine
; 2. call gpio_init subroutine to configure wbs_gpio module for operation
; 2. call gpio_init subroutine to configure wbs_gpio module for operation
; 3. use wb_wr and wb_rd subroutines to access i/o register
; 3. use wb_wr and wb_rd subroutines to access i/o register
; gpio start-up configuration, i. e. i/o direction and default output value
; gpio start-up configuration, i. e. i/o direction and default output value
gpio_init:
gpio_init:
  ; setting all outputs low
  ; setting all outputs low
  LOAD wb_addr , GPIO_IO_ADDR
  LOAD wb_addr , GPIO_IO_ADDR
  LOAD wb_data , 00
  LOAD wb_data , 00
  CALL wb_wr
  CALL wb_wr
  ; configuring lower gpio nibble as output
  ; configuring lower gpio nibble as output
  LOAD wb_addr , GPIO_OE_ADDR
  LOAD wb_addr , GPIO_OE_ADDR
  LOAD wb_data , 0F
  LOAD wb_data , 0F
  CALL wb_wr
  CALL wb_wr
RETURN
RETURN
; register addressing
; register addressing
CONSTANT GPIO_IO_ADDR , 00 ; input/output register
CONSTANT GPIO_IO_ADDR , 00 ; input/output register
CONSTANT GPIO_OE_ADDR , 01 ; output-enable register
CONSTANT GPIO_OE_ADDR , 01 ; output-enable register
; wbm_picoblaze module subroutines and settings
; wbm_picoblaze module subroutines and settings
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; subroutines wb_wr and wb_rd are working together with external wbm_picoblaze
; subroutines wb_wr and wb_rd are working together with external wbm_picoblaze
; wishbone adapter module and therefore should not be modified. wb_wait_on_ack
; wishbone adapter module and therefore should not be modified. wb_wait_on_ack
; is a supporting subroutine, which should not be called directly
; is a supporting subroutine, which should not be called directly
;
;
; transfer principle wishbone write:
; transfer principle wishbone write:
; 1. OUTPUT cycle to set up wishbone address, data and control signals from
; 1. OUTPUT cycle to set up wishbone address, data and control signals from
;    PORT_ID, OUT_PORT and WRITE_STROBE
;    PORT_ID, OUT_PORT and WRITE_STROBE
; 2. INPUT cycle(s) to poll wishbone peripheral acknowledgement using IN_PORT
; 2. INPUT cycle(s) to poll wishbone peripheral acknowledgement using IN_PORT
; => at least one OUTPUT and one INPUT cycle for a write
; => at least one OUTPUT and one INPUT cycle for a write
;
;
; transfer principle wishbone read:
; transfer principle wishbone read:
; 1. INPUT cycle to set up wishbone address and control signals from PORT_ID
; 1. INPUT cycle to set up wishbone address and control signals from PORT_ID
;    and READ_STROBE
;    and READ_STROBE
; 2. INPUT cycle(s) to poll wishbone peripheral acknowledgement using IN_PORT
; 2. INPUT cycle(s) to poll wishbone peripheral acknowledgement using IN_PORT
; 3. the very next INPUT cycle after acknowledgement contains valid wishbone
; 3. the very next INPUT cycle after acknowledgement contains valid wishbone
;    data from IN_PORT
;    data from IN_PORT
; => at least three INPUT cycles for a read
; => at least three INPUT cycles for a read
;
;
; calling examples:
; calling examples:
;
;
; wishbone write code =>
; wishbone write code =>
;
;
; LOAD wb_addr ,  ; setting up address
; LOAD wb_addr ,  ; setting up address
; LOAD wb_data ,  ; setting up data
; LOAD wb_data ,  ; setting up data
; CALL wb_wr ; starting wishbone write cycle
; CALL wb_wr ; starting wishbone write cycle
;  ; wishbone cycle finished
;  ; wishbone cycle finished
;
;
; wishbone read code =>
; wishbone read code =>
;
;
; LOAD wb_addr ,  ; setting up address
; LOAD wb_addr ,  ; setting up address
; CALL wb_rd ; starting wishbone read cycle
; CALL wb_rd ; starting wishbone read cycle
; LOAD  , wb_data ; wb_data is updated now
; LOAD  , wb_data ; wb_data is updated now
;  ; wishbone cycle finished
;  ; wishbone cycle finished
; wishbone write access
; wishbone write access
wb_wr:
wb_wr:
  OUTPUT wb_data , (wb_addr)
  OUTPUT wb_data , (wb_addr)
  CALL wb_wait_on_ack
  CALL wb_wait_on_ack
RETURN
RETURN
; wishbone read access
; wishbone read access
wb_rd:
wb_rd:
  CALL wb_wait_on_ack
  CALL wb_wait_on_ack
  INPUT wb_data , (wb_addr)
  INPUT wb_data , (wb_addr)
RETURN
RETURN
; waiting on wishbone cycle to complete
; waiting on wishbone cycle to complete
wb_wait_on_ack:
wb_wait_on_ack:
  INPUT wb_data , (wb_addr)
  INPUT wb_data , (wb_addr)
  TEST wb_data , WB_ACK_FLAG
  TEST wb_data , WB_ACK_FLAG
  JUMP Z , wb_wait_on_ack
  JUMP Z , wb_wait_on_ack
RETURN
RETURN
CONSTANT WB_ACK_FLAG , 01
CONSTANT WB_ACK_FLAG , 01
; interrupt subroutines and settings
; interrupt subroutines and settings
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; IMPORTANT NOTICE!
; IMPORTANT NOTICE!
; be carefull, if using interrupts. wishbone cycles must be atomar, as any
; be carefull, if using interrupts. wishbone cycles must be atomar, as any
; other processor local bus cycles are normally be. interrupting wishbone
; other processor local bus cycles are normally be. interrupting wishbone
; access may cause a crash of external wishbone master fsm, especially, if
; access may cause a crash of external wishbone master fsm, especially, if
; program flow through isr leads to another wishbone cycle!
; program flow through isr leads to another wishbone cycle!
; interrupt handling template, if needed
; interrupt handling template, if needed
isr:
isr:
RETURNI DISABLE
RETURNI DISABLE
ADDRESS 3FF
ADDRESS 3FF
JUMP isr
JUMP isr
 
 

powered by: WebSVN 2.1.0

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