forked from hzeller/beagleg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pru-generic-io-routines.hp
83 lines (77 loc) · 2.67 KB
/
pru-generic-io-routines.hp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
;; -*- asm -*-
;;
;; (c) 2013, 2014, 2015 Henner Zeller <[email protected]>
;; H Hartley Sweeten <[email protected]>
;;
;; This file is part of BeagleG. http://github.com/hzeller/beagleg
;;
;; BeagleG is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; BeagleG is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with BeagleG. If not, see <http://www.gnu.org/licenses/>.
;;;;
;;; Each hardware/<CAPE> subdirectory needs to include a pru-io-routines.hp
;;; file that contains the functions defined in this file. The simplest
;;; way is to just include this generic file (albeit a bit slower).
;;; (TODO: auto generate optimized assembler with a little program).
;;;;
;;; Set/Clr a GPIO pin based on 'bit' being set/clr in 'bits'
;;; Uses:
;;; r4 : the base address of the gpio bank to set/clr the pin
;;; r5 : the bitmask to set/clr the gpio pin
;;; r6 : scratch
.macro SetGPIO
.mparam bits, bit, gpio_def
MOV r4, (gpio_def & 0xfffff000)
QBEQ no_map, r4.w2, GPIO_NOT_MAPPED
MOV r5, 1 << (gpio_def & 0x1f)
QBBS set_gpio, bits, bit
MOV r6, GPIO_CLEARDATAOUT
QBA update_gpio
set_gpio:
MOV r6, GPIO_SETDATAOUT
update_gpio:
ADD r4, r4, r6
SBBO r5, r4, 0, 4
no_map:
.endm
;;; Set the motor enable signal based on the flag (r3) bit 0
EnableMotors:
SetGPIO r3, 0, MOTOR_ENABLE_GPIO
RET
;;; Set the aux bit signals based on the travel_params.aux (r3) bit 0..1
SetAuxBits:
SetGPIO r3, 0, AUX_1_GPIO
SetGPIO r3, 1, AUX_2_GPIO
RET
;;; Set the motor direction signals based from queue_header.direction_bits (r3)
;;; bit 0..7
SetDirections:
SetGPIO r3, 0, MOTOR_1_DIR_GPIO
SetGPIO r3, 1, MOTOR_2_DIR_GPIO
SetGPIO r3, 2, MOTOR_3_DIR_GPIO
SetGPIO r3, 3, MOTOR_4_DIR_GPIO
SetGPIO r3, 4, MOTOR_5_DIR_GPIO
SetGPIO r3, 5, MOTOR_6_DIR_GPIO
SetGPIO r3, 6, MOTOR_7_DIR_GPIO
SetGPIO r3, 7, MOTOR_8_DIR_GPIO
RET
;;; Set the motor step signals based on bit 31 of the mstate of the motor
SetSteps:
SetGPIO mstate.m1, 31, MOTOR_1_STEP_GPIO
SetGPIO mstate.m2, 31, MOTOR_2_STEP_GPIO
SetGPIO mstate.m3, 31, MOTOR_3_STEP_GPIO
SetGPIO mstate.m4, 31, MOTOR_4_STEP_GPIO
SetGPIO mstate.m5, 31, MOTOR_5_STEP_GPIO
SetGPIO mstate.m6, 31, MOTOR_6_STEP_GPIO
SetGPIO mstate.m7, 31, MOTOR_7_STEP_GPIO
SetGPIO mstate.m8, 31, MOTOR_8_STEP_GPIO
RET