forked from X360Tools/PicoFlasher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sdio.pio
67 lines (58 loc) · 2.24 KB
/
sdio.pio
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
; Copyright (c) 2022 Balázs Triszka <balika011@gmail.com>
;
; This program is free software; you can redistribute it and/or modify it
; under the terms and conditions of the GNU General Public License,
; version 2, as published by the Free Software Foundation.
;
; This program is distributed in the hope 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 this program. If not, see <http://www.gnu.org/licenses/>.
; NOTE IT IS IMPERATIVE THAT YOU DON"T SCREW UP THE CLOCK EVEN FOR ONE HALF CYCLE, OTHERWISE THE DEVICE WILL LIKELY BE DISPLEASED AND MAY SEND GARBAGE (EVEN IF IT ISN"T DOING ANYTHING IMPORTANT WHEN YOU DO SO)
.define sd_irq_num 7
.program sd_clk
.side_set 1
.wrap_target
irq sd_irq_num side 1
irq clear sd_irq_num side 0
.wrap
.program sd_cmd_or_dat
.origin 0 ; must load at zero (offsets are hardcoded in instruction stream)
public no_arg_state_wait_high: ; this is a no arg state which means it must always appear in the second half of a word
; make sure pins are hi when we set output dir (note if we are 1 bit we'll be configured for 1 pin only, so sending 0b1111 is fine)
set pins, 0b1111
set pindirs, 0b1111
public no_arg_state_waiting_for_cmd:
out exec, 16 ; expected to be a jmp to a state
public state_send_bits:
out x, 16
wait 0 irq sd_irq_num
send_loop1:
out pins, 1
jmp x-- send_loop1
public state_inline_instruction:
out exec, 16 ; may be any instruction
.wrap_target
out exec, 16 ; expected to be a jmp to a state
public state_receive_bits:
out x, 16
set pindirs, 0
wait 1 pin, 0
wait 0 pin, 0
wait 0 irq sd_irq_num
; note we use wrap setup to configure receive bit/nibble transfers
public wrap_for_4bit_receive:
receive_loop1:
in pins, 1
jmp x-- receive_loop1
.wrap
; #if INCLUDE_4BIT
public wrap_target_for_4bit_receive:
receive_loop4:
in pins, 4
jmp x-- receive_loop4
out exec, 16 ; expected to be a jmp to a state
; #endif