Subversion Repositories svn.mios

Rev

Rev 15 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
44 tk 1
; $Id: iic_midi_tick.asm 44 2008-01-30 21:39:30Z tk $
2
;
3
;  Assembly based IIC MIDI Tick Handler
4
;
5
; ==========================================================================
6
;
7
;  Copyright 2006 Thorsten Klose (tk@midibox.org)
8
;  Licensed for personal non-commercial use only.
9
;  All other rights reserved.
10
; 
11
; ==========================================================================
12
 
13
    radix   dec
14
#include <mios.h>
15
#include <mios_vectors.inc>
16
#include <macros.h>
17
 
18
; ==========================================================================
19
 
20
    ;; export lables
21
    global  IIC_MIDI_Tick
22
 
23
    global  _IIC_MIDI_Tick      ; (for C, declaration in iic_midi.h)
24
 
25
    ;; import lables
26
    extern  _sysex_owner
27
    extern  _ROUTER_Rx_IIC0
28
    extern  _ROUTER_Rx_IIC1
29
    extern  _ROUTER_Rx_IIC2
30
    extern  _ROUTER_Rx_IIC3
31
 
32
    ;; from $MIOS_PATH/modules/iic_midi.asm:
33
    extern  _IIC_MIDI_Receive
34
 
35
    extern  _iic_midi_rx_package
36
    extern  _iic_midi_tx_package
37
 
38
; ==========================================================================
39
 
40
;; assembly/C compatible defines
41
#include "router_ports.h"
42
 
43
; ==========================================================================
44
 
45
;; base address and max number of IIC slaves
46
#define IIC_MIDI_BASE_ADDR  0x10
47
#define IIC_MIDI_MAX_NUMBER 4
48
 
49
;; use Receive Interrupt lines for faster polling?
50
#define IIC_MIDI_USE_RI     1
51
 
52
; ==========================================================================
53
IIC_MIDI_TICK code
54
; ==========================================================================
55
 
56
 
57
;; --------------------------------------------------------------------------
58
;;  FUNCTION: IIC_MIDI_Tick
59
;;  DECLARATION: void IIC_MIDI_Tick(void)
60
;;  DESCRIPTION: should be called from USER_Tick to check for incoming
61
;;  messages from the IIC MIDI slaves
62
;;  The global hook "_ROUTER_Rx_IIC[0123]" will be called once a complete
63
;;  package has been received - this function is defined in router.c
64
;;  IN:   -
65
;;  OUT:  -
66
;;  USES: -
67
;; --------------------------------------------------------------------------
68
_IIC_MIDI_Tick          ; (for C, declaration in iic_midi.h)
69
IIC_MIDI_Tick
70
    bsf LATD, 4
71
 
72
    ;; exit if the internal USART is the SysEx owner
73
    SET_BSR _sysex_owner
74
    movf    _sysex_owner, W, BANKED
75
    xorlw   PORT_INT0
76
    bz  IIC_MIDI_Tick_End
77
 
78
#if IIC_MIDI_MAX_NUMBER >= 1
79
IIC_MIDI_Tick_Slave0
80
    movlw   0x00
81
    call    _IIC_MIDI_Receive
82
    bz  IIC_MIDI_Tick_Slave0_End
83
 
84
    movff   _iic_midi_rx_package+3, POSTDEC0
85
    movff   _iic_midi_rx_package+2, POSTDEC0
86
    movff   _iic_midi_rx_package+1, POSTDEC0
87
    movf    _iic_midi_rx_package+0, W
88
    call    _ROUTER_Rx_IIC0
89
    movf    PREINC0,; (not used anymore)
90
    movf    PREINC0,; (not used anymore)
91
    movf    PREINC0,; (not used anymore)
92
 
93
IIC_MIDI_Tick_Slave0_End
94
    ;; loop so long IIC0 is the SysEx owner
95
    ;; TODO: add timeout
96
    clrwdt          ; feed watchdog
97
    SET_BSR _sysex_owner
98
    movf    _sysex_owner, W, BANKED
99
    xorlw   PORT_IIC0
100
    bz  IIC_MIDI_Tick_Slave0
101
#endif
102
 
103
#if IIC_MIDI_MAX_NUMBER >= 2
104
IIC_MIDI_Tick_Slave1
105
    movlw   0x01
106
    call    _IIC_MIDI_Receive
107
    bz  IIC_MIDI_Tick_Slave1_End
108
 
109
    movff   _iic_midi_rx_package+3, POSTDEC0
110
    movff   _iic_midi_rx_package+2, POSTDEC0
111
    movff   _iic_midi_rx_package+1, POSTDEC0
112
    movf    _iic_midi_rx_package+0, W
113
    call    _ROUTER_Rx_IIC1
114
    movf    PREINC0,; (not used anymore)
115
    movf    PREINC0,; (not used anymore)
116
    movf    PREINC0,; (not used anymore)
117
IIC_MIDI_Tick_Slave1_End
118
    ;; loop so long IIC1 is the SysEx owner
119
    ;; TODO: add timeout
120
    clrwdt          ; feed watchdog
121
    SET_BSR _sysex_owner
122
    movf    _sysex_owner, W, BANKED
123
    xorlw   PORT_IIC1
124
    bz  IIC_MIDI_Tick_Slave1
125
#endif
126
 
127
#if IIC_MIDI_MAX_NUMBER >= 3
128
IIC_MIDI_Tick_Slave2
129
    movlw   0x02
130
    call    _IIC_MIDI_Receive
131
    bz  IIC_MIDI_Tick_Slave2_End
132
 
133
    movff   _iic_midi_rx_package+3, POSTDEC0
134
    movff   _iic_midi_rx_package+2, POSTDEC0
135
    movff   _iic_midi_rx_package+1, POSTDEC0
136
    movf    _iic_midi_rx_package+0, W
137
    call    _ROUTER_Rx_IIC2
138
    movf    PREINC0,; (not used anymore)
139
    movf    PREINC0,; (not used anymore)
140
    movf    PREINC0,; (not used anymore)
141
IIC_MIDI_Tick_Slave2_End
142
    ;; loop so long IIC2 is the SysEx owner
143
    ;; TODO: add timeout
144
    clrwdt          ; feed watchdog
145
    SET_BSR _sysex_owner
146
    movf    _sysex_owner, W, BANKED
147
    xorlw   PORT_IIC2
148
    bz  IIC_MIDI_Tick_Slave2
149
#endif
150
 
151
#if IIC_MIDI_MAX_NUMBER >= 4
152
IIC_MIDI_Tick_Slave3
153
    movlw   0x03
154
    call    _IIC_MIDI_Receive
155
    bz  IIC_MIDI_Tick_Slave3_End
156
 
157
    movff   _iic_midi_rx_package+3, POSTDEC0
158
    movff   _iic_midi_rx_package+2, POSTDEC0
159
    movff   _iic_midi_rx_package+1, POSTDEC0
160
    movf    _iic_midi_rx_package+0, W
161
    call    _ROUTER_Rx_IIC3
162
    movf    PREINC0,; (not used anymore)
163
    movf    PREINC0,; (not used anymore)
164
    movf    PREINC0,; (not used anymore)
165
IIC_MIDI_Tick_Slave3_End
166
    ;; loop so long IIC3 is the SysEx owner
167
    ;; TODO: add timeout
168
    clrwdt          ; feed watchdog
169
    SET_BSR _sysex_owner
170
    movf    _sysex_owner, W, BANKED
171
    xorlw   PORT_IIC3
172
    bz  IIC_MIDI_Tick_Slave3
173
#endif
174
 
175
IIC_MIDI_Tick_End
176
    bcf LATD, 4
177
 
178
    return
179
 
180
; ==========================================================================
181
    END