Subversion Repositories svn.mios

Rev

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

Rev Author Line No. Line
53 tk 1
; $Id: mios_bankstick.inc 53 2008-01-30 22:52:41Z tk $
1 tk 2
;
3
; MIOS BankStick routines
4
;
5
; ==========================================================================
6
;
7
;  Copyright 1998-2006 Thorsten Klose (tk@midibox.org)
8
;  Licensed for personal non-commercial use only.
9
;  All other rights reserved.
10
;
11
; ==========================================================================
12
 
13
#define MIOS_BANKSTICK_16BIT 1
14
 
15
;; --------------------------------------------------------------------------
16
;;  FUNCTION: MIOS_BANKSTICK_Write
17
;;  C_DECLARATION: unsigned char MIOS_BANKSTICK_Write(unsigned int addr, unsigned char value)
18
;;  DESCRIPTION: writes a byte into BankStick. <BR>
19
;;  If verify mode has been enabled with MIOS_BANKSTICK_CtrlSet, write access will
20
;;  be skipped if content is equal to the byte which should be written<BR>
21
;;  Returned Error Status:<BR>
22
;;     0x00: no error<BR>
23
;;     0x01: byte mismatch (write failed) -- only set if verify enabled<BR>
24
;;     0x02: BankStick not available
25
;;  IN:	  byte in WREG, address in MIOS_PARAMETER[12] (0x0000-0xffff)
26
;;  C_IN: byte in <value>, address in <addr> (0x0000-0xffff)
27
;;  OUT:  error status in WREG
28
;;        MIOS_PARAMETER[12] will be incremented
29
;;        MIOS_BOX_STAT[MIOS_BOX_STAT_BS_AVAILABLE] cleared if write failed
30
;;  C_OUT: error status
31
;;        MIOS_BOX_STAT.BS_AVAILABLE cleared if write failed
32
;;  USES: BSR, MIOS_PARAMETER[12]
33
;;  EXAMPLE:
34
;;
35
;;	;; write 0x47 0x11 to address 0x3000-0x3001 of the BankStick
36
;;	movlw	0x00			; store low-byte of address in
37
;;	movwf	MIOS_PARAMETER1		; MIOS_PARAMETER1
38
;;	movlw	0x30			; store high-byte of address in
39
;;	movwf	MIOS_PARAMETER2		; MIOS_PARAMETER2
40
;;	movlw	0x47			; write 0x47 to 0x3000
41
;;	call	MIOS_BANKSTICK_Write	; (address will be incremented
42
;;					; after write)
43
;;	bnz	BSProgrammingFailed	; branch to your exception handler
44
;;					; if necessary
45
;;	movlw	0x11			; write 0x11 to 0x3001
46
;;	call	MIOS_BANKSTICK_Write	; (address will be incremented
47
;;					;  after write)
48
;;	bnz	BSProgrammingFailed	; branch to your exception handler
49
;;					; if necessary
50
;;
51
;;  C_EXAMPLE:
52
;;
53
;;	unsigned char error = 0;
54
;;
55
;;	// write 0x47 0x11 to address 0x3000-0x3001 of the BankStick
56
;;	error |= MIOS_BANKSTICK_Write(0x3000, 0x47);
57
;;	error |= MIOS_BANKSTICK_Write(0x3001, 0x11);
58
;;
59
;;	if( error ) {
60
;;	  // here you could do some error handling
61
;;	}
62
;;
63
;; --------------------------------------------------------------------------
64
MIOS_BANKSTICK_Write
65
	SET_BSR	MIOS_TMP2
66
	movwf	MIOS_TMP2, BANKED
67
 
68
	BRA_IFSET MIOS_BOX_CFG1, MIOS_BOX_CFG1_BS_DIS_VERIFY, ACCESS, MIOS_BANKSTICK_Write_NoVerifyR
69
 
70
	rcall	MIOS_BANKSTICK_Read		; don't write if value is equal
71
	BRA_IFCLR MIOS_BOX_STAT, MIOS_BOX_STAT_BS_AVAILABLE, ACCESS, MIOS_BANKSTICK_Write_NA
72
	cpfseq	MIOS_TMP2, BANKED
73
	rgoto MIOS_BANKSTICK_WriteNow
74
	movlw	0x00
75
	rgoto	MIOS_BANKSTICK_Write_End
76
 
77
MIOS_BANKSTICK_WriteNow
78
	decf	MIOS_PARAMETER1, F		; decrement MIOS_PARAMETER[12]
79
	skpc
80
	decf	MIOS_PARAMETER2, F
81
 
82
MIOS_BANKSTICK_Write_NoVerifyR
83
	movf	MIOS_TMP2, W, BANKED	; get byte
84
 
85
	rcall	MIOS_IIC_Start		; start IIC
86
 
87
	rlf	MIOS_BOX_CFG1, W
88
	andlw	0x0e
89
	iorlw	0xa0			; set address
90
	rcall	MIOS_IIC_ByteSend
91
#if MIOS_BANKSTICK_16BIT == 1
92
	movf	MIOS_PARAMETER2, W	; send high address
93
	rcall	MIOS_IIC_ByteSend
94
#endif
95
	movf	MIOS_PARAMETER1, W	; send low address
96
	rcall	MIOS_IIC_ByteSend
97
 
98
	incf	MIOS_PARAMETER1, F		; increment MIOS_PARAMETER[12]
99
	skpnz
100
	incf	MIOS_PARAMETER2, F
101
 
102
	BRA_IFCLR MIOS_BOX_STAT, MIOS_BOX_STAT_BS_AVAILABLE, ACCESS, MIOS_BANKSTICK_Write_NA
103
 
104
	movf	MIOS_TMP2, W, BANKED	; send byte which should be written into EEPROM
105
	rcall	MIOS_IIC_ByteSend
106
 
107
	rcall	MIOS_IIC_Stop		; stop IIC
108
 
109
	;; wait until write cycle is finished
110
MIOS_BANKSTICK_Write_Poll
111
	;; memo: time out counter should be inserted here!
112
	bsf	MIOS_BOX_STAT, MIOS_BOX_STAT_BS_AVAILABLE
113
 
114
	rcall	MIOS_IIC_Start
115
	rlf	MIOS_BOX_CFG1, W
116
	andlw	0x0e
117
	iorlw	0xa0			; set address
118
	rcall	MIOS_IIC_ByteSend
119
	rcall	MIOS_IIC_Stop		; stop IIC
120
 
121
	BRA_IFCLR MIOS_BOX_STAT, MIOS_BOX_STAT_BS_AVAILABLE, ACCESS, MIOS_BANKSTICK_Write_Poll
122
 
123
 
124
	movlw	0x00
125
	BRA_IFSET MIOS_BOX_CFG1, MIOS_BOX_CFG1_BS_DIS_VERIFY, ACCESS, MIOS_BANKSTICK_Write_NoVerify2
126
 
127
	decf	MIOS_PARAMETER1, F		; decrement MIOS_PARAMETER[12]
128
	skpc
129
	decf	MIOS_PARAMETER2, F
130
 
131
	rcall	MIOS_BANKSTICK_Read		; read address again
132
	BRA_IFCLR MIOS_BOX_STAT, MIOS_BOX_STAT_BS_AVAILABLE, ACCESS, MIOS_BANKSTICK_Write_NA
133
	cpfseq	MIOS_TMP2, BANKED
134
	rgoto MIOS_BANKSTICK_Write_Error
135
	movlw	0x00				; error status = OK
136
	rgoto	MIOS_BANKSTICK_Write_End
137
MIOS_BANKSTICK_Write_NA
138
	movlw	0x02				; error status = not available
139
	rgoto	MIOS_BANKSTICK_Write_End
140
MIOS_BANKSTICK_Write_Error
141
	movlw	0x01				; error status = failed
142
	;; 	rgoto	MIOS_BANKSTICK_Write_End
143
MIOS_BANKSTICK_Write_End
144
MIOS_BANKSTICK_Write_NoVerify2
145
	andlw	0xff				; update STATUS register
146
	return
147
 
148
;; --------------------------------------------------------------------------
149
;;  FUNCTION: MIOS_BANKSTICK_WritePage
150
;;  C_DECLARATION: unsigned char MIOS_BANKSTICK_WritePage(unsigned int addr, unsigned char *buffer)
151
;;  DESCRIPTION: writes a 64 bytes page into BankStick.
152
;;  If verify mode has been enabled with MIOS_BANKSTICK_CtrlSet, write access will
153
;;  be skipped if content is equal to the byte which should be written
154
;;  Returned Error Status:
155
;;     0x00: no error
156
;;     0x01: byte mismatch (write failed) -- only set if verify enabled
157
;;     0x02: BankStick not available
158
;;  IN:	  pointer to write buffer (64 bytes) in FSR1
159
;;        address in MIOS_PARAMETER[12] (0x0000-0xffc0)
160
;;  C_IN: pointer to write buffer (64 bytes) in <buffer>
161
;;        address in <addr> (0x0000-0xffc0)
162
;;  OUT:  error status in WREG
163
;;        MIOS_PARAMETER[12] will be incremented to next page address (+64)
164
;;        FSR1 will be left untouched
165
;;        MIOS_BOX_STAT[MIOS_BOX_STAT_BS_AVAILABLE] is cleared if write failed
166
;;  C_OUT: error status in WREG
167
;;        MIOS_BOX_STAT.BS_AVAILABLE is cleared if write failed
168
;;  USES: BSR, MIOS_PARAMETER[12]
169
;;  EXAMPLE:
170
;;
171
;;	;; write a page of 64 bytes to BankStick memory at address 0x1240
172
;;	movlw	0x40			; store low-byte of address in
173
;;	movwf	MIOS_PARAMETER1		; MIOS_PARAMETER1
174
;;	movlw	0x12			; store high-byte of address in
175
;;	movwf	MIOS_PARAMETER2		; MIOS_PARAMETER2
176
;;	lfsr	FSR1, 0x100		; a free 64 byte buffer in RAM which
177
;;					: contains some data
178
;;	call	MIOS_BANKSTICK_WritePage; initiate the write
179
;;	bnz	BSProgrammingFailed	; branch to your exception handler
180
;;					; if necessary
181
;;
182
;;  C_EXAMPLE:
183
;;
184
;;	unsigned char buffer[64];
185
;;	unsigned char i;
186
;;
187
;;	// fill buffer with some bytes
188
;;	for(i=0; i<64; ++i)
189
;;	  buffer[i] = i;
190
;;
191
;;	// write a page of 64 bytes to BankStick memory at address 0x3000
192
;;	if( MIOS_BANKSTICK_WritePage(0x3000, buffer) ) {
193
;;	  // here you could do some error handling
194
;;	}
195
;;
196
;; --------------------------------------------------------------------------
197
MIOS_BANKSTICK_WritePage
198
	SET_BSR	MIOS_TMP2
199
 
200
	;; align address
201
	movlw	0xc0
202
	andwf	MIOS_PARAMETER1, F
203
 
204
	BRA_IFSET MIOS_BOX_CFG1, MIOS_BOX_CFG1_BS_DIS_VERIFY, ACCESS, MIOS_BANKSTICK_WritePage_NoVR
205
 
206
	;; first compare buffer with BankStick content
207
	clrf	MIOS_TMP2, BANKED
208
MIOS_BANKSTICK_WritePage_CLoop1
209
	rcall	MIOS_BANKSTICK_Read		; don't write if value is equal
210
	BRA_IFCLR MIOS_BOX_STAT, MIOS_BOX_STAT_BS_AVAILABLE, ACCESS, MIOS_BANKSTICK_WritePage_NA
211
	movwf	MIOS_PARAMETER3
212
	movf	MIOS_TMP2, W, BANKED
213
	movf	PLUSW1, W
214
	xorwf	MIOS_PARAMETER3, W
215
	bnz	MIOS_BANKSTICK_WritePageNow
216
	incf	MIOS_TMP2, F, BANKED
217
	BRA_IFCLR MIOS_TMP2, 6, BANKED, MIOS_BANKSTICK_WritePage_CLoop1
218
 
219
	;; no mismatches: don't write, error status = ok
220
	movlw	0x00
221
	rgoto	MIOS_BANKSTICK_WritePage_End
222
 
223
MIOS_BANKSTICK_WritePageNow
224
	;; fix pointer
225
	decf	MIOS_PARAMETER1, F
226
	skpc
227
	decf	MIOS_PARAMETER2, F
228
	movlw	0xc0
229
	andwf	MIOS_PARAMETER1, F
230
 
231
MIOS_BANKSTICK_WritePage_NoVR
232
	rcall	MIOS_IIC_Start		; start IIC
233
 
234
	rlf	MIOS_BOX_CFG1, W
235
	andlw	0x0e
236
	iorlw	0xa0			; set address
237
	rcall	MIOS_IIC_ByteSend
238
#if MIOS_BANKSTICK_16BIT == 1
239
	movf	MIOS_PARAMETER2, W	; send high address
240
	rcall	MIOS_IIC_ByteSend
241
#endif
242
	movf	MIOS_PARAMETER1, W	; send low address
243
	rcall	MIOS_IIC_ByteSend
244
 
245
	movlw	0x40
246
	addwf	MIOS_PARAMETER1, F		; increment MIOS_PARAMETER[12]
247
	movlw	0x00
248
	addwfc	MIOS_PARAMETER2, F
249
 
250
	;; write 64 bytes into buffer
251
	clrf	MIOS_TMP2, BANKED
252
MIOS_BANKSTICK_WritePage_WLoop
253
	movf	MIOS_TMP2, W, BANKED	; send byte which should be written into EEPROM
254
	movf	PLUSW1, W
255
	rcall	MIOS_IIC_ByteSend
256
	BRA_IFCLR MIOS_BOX_STAT, MIOS_BOX_STAT_BS_AVAILABLE, ACCESS, MIOS_BANKSTICK_WritePage_NA
257
	incf	MIOS_TMP2, F, BANKED
258
	BRA_IFCLR MIOS_TMP2, 6, BANKED, MIOS_BANKSTICK_WritePage_WLoop
259
 
260
	rcall	MIOS_IIC_Stop		; stop IIC
261
 
262
	;; wait until write cycle is finished
263
MIOS_BANKSTICK_WritePage_Poll
264
	;; memo: time out counter should be inserted here!
265
	bsf	MIOS_BOX_STAT, MIOS_BOX_STAT_BS_AVAILABLE
266
 
267
	rcall	MIOS_IIC_Start
268
	rlf	MIOS_BOX_CFG1, W
269
	andlw	0x0e
270
	iorlw	0xa0			; set address
271
	rcall	MIOS_IIC_ByteSend
272
	rcall	MIOS_IIC_Stop		; stop IIC
273
 
274
	BRA_IFCLR MIOS_BOX_STAT, MIOS_BOX_STAT_BS_AVAILABLE, ACCESS, MIOS_BANKSTICK_WritePage_Poll
275
 
276
 
277
	movlw	0x00
278
	BRA_IFSET MIOS_BOX_CFG1, MIOS_BOX_CFG1_BS_DIS_VERIFY, ACCESS, MIOS_BANKSTICK_WritePage_NoV2
279
 
280
	;; fix pointer
281
	decf	MIOS_PARAMETER1, F
282
	skpc
283
	decf	MIOS_PARAMETER2, F
284
	movlw	0xc0
285
	andwf	MIOS_PARAMETER1, F
286
 
287
	;; first compare buffer with BankStick content
288
	clrf	MIOS_TMP2, BANKED
289
MIOS_BANKSTICK_WritePage_CLoop2
290
	rcall	MIOS_BANKSTICK_Read		; don't write if value is equal
291
	BRA_IFCLR MIOS_BOX_STAT, MIOS_BOX_STAT_BS_AVAILABLE, ACCESS, MIOS_BANKSTICK_WritePage_NA
292
	movwf	MIOS_PARAMETER3
293
	movf	MIOS_TMP2, W, BANKED
294
	movf	PLUSW1, W
295
	xorwf	MIOS_PARAMETER3, W
296
	bnz	MIOS_BANKSTICK_WritePage_Error
297
	incf	MIOS_TMP2, F, BANKED
298
	BRA_IFCLR MIOS_TMP2, 6, BANKED, MIOS_BANKSTICK_WritePage_CLoop2
299
	movlw	0x00				; error status = OK
300
	rgoto	MIOS_BANKSTICK_WritePage_End
301
MIOS_BANKSTICK_WritePage_NA
302
	movlw	0x02				; error status = not available
303
	rgoto	MIOS_BANKSTICK_WritePage_End
304
MIOS_BANKSTICK_WritePage_Error
305
	movlw	0x01				; error status = failed
306
	;; 	rgoto	MIOS_BANKSTICK_WritePage_End
307
MIOS_BANKSTICK_WritePage_End
308
MIOS_BANKSTICK_WritePage_NoV2
309
	andlw	0xff				; update STATUS register
310
	return
311
 
312
;; --------------------------------------------------------------------------
313
;;  FUNCTION: MIOS_BANKSTICK_Read
314
;;  C_DECLARATION: unsigned char MIOS_BANKSTICK_Read(unsigned int addr)
315
;;  DESCRIPTION: reads a byte from BankStick.
316
;;  IN:	  address in MIOS_PARAMETER[12] (0x0000-0xffff)
317
;;  C_IN: address in <addr> (0x0000-0xffff)
318
;;  OUT:  BankStick content in WREG
319
;;        MIOS_PARAMETER[12] will be incremented
320
;;        MIOS_BOX_STAT[MIOS_BOX_STAT_BS_AVAILABLE] is zero if read failed
321
;;  C_OUT:  BankStick content
322
;;        MIOS_BOX_STAT.BS_AVAILABLE cleared if read failed
323
;;  USES: BSR, MIOS_PARAMETER[12]
324
;;  EXAMPLE:
325
;;
326
;;	;; load a byte from address 0x7fff (the last in a 32k BankStick)
327
;;	movlw	0xff			; initialize pointer to BankStick
328
;;					; address
329
;;	movwf	MIOS_PARAMETER1		; -> 0x7fff
330
;;	movlw	0x7f
331
;;	movwf	MIOS_PARAMETER2
332
;;	call	MIOS_BANKSTICK_Read	; load byte from BankStick
333
;;					; branch to error exception
334
;;					; routine if neccesary
335
;;	BRA_IFCLR MIOS_BOX_STAT, MIOS_BOX_STAT_BS_AVAILABLE, ACCESS, BankStickNotAvl
336
;;
337
;;  C_EXAMPLE:
338
;;
339
;;	// load a byte from address 0x7fff (the last in a 32k BankStick)
340
;;	value = MIOS_BANKSTICK_Read(0x7fff);
341
;;
342
;;	if( !MIOS_BOX_STAT.BS_AVAILABLE ) {
343
;;	  // here you could do some error handling
344
;;	}
345
;;
346
;; --------------------------------------------------------------------------
347
MIOS_BANKSTICK_Read
348
	rcall	MIOS_IIC_Start		; start IIC
349
 
350
	rlf	MIOS_BOX_CFG1, W
351
	andlw	0x0e
352
	iorlw	0xa0			; set address
353
	rcall	MIOS_IIC_ByteSend
354
#if MIOS_BANKSTICK_16BIT == 1
355
	movf	MIOS_PARAMETER2, W	; send high address
356
	rcall	MIOS_IIC_ByteSend
357
#endif
358
	movf	MIOS_PARAMETER1, W	; send low address
359
	rcall	MIOS_IIC_ByteSend
360
 
361
	rcall	MIOS_IIC_Start		; start IIC again
362
	rlf	MIOS_BOX_CFG1, W
363
	andlw	0x0e
364
	iorlw	0xa1
365
	rcall	MIOS_IIC_ByteSend
366
	rcall	MIOS_IIC_ByteReceive	; read byte #0
367
	SET_BSR	MIOS_TMP1
368
	movwf	MIOS_TMP1, BANKED
369
	rcall	MIOS_IIC_NakSend
370
	rcall	MIOS_IIC_Stop		; stop IIC
371
 
372
	incf	MIOS_PARAMETER1, F		; increment MIOS_PARAMETER[12]
373
	skpnz
374
	incf	MIOS_PARAMETER2, F
375
 
376
	movf	MIOS_TMP1, W, BANKED
377
 
378
	return
379
 
380
;; --------------------------------------------------------------------------
381
;;  FUNCTION: MIOS_BANKSTICK_ReadPage
382
;;  C_DECLARATION: unsigned char MIOS_BANKSTICK_ReadPage(unsigned int addr, unsigned char *buffer)
383
;;  DESCRIPTION: reads a 64 bytes page from BankStick.
384
;;  IN:	  pointer to read buffer (64 bytes) in FSR1
385
;;        address in MIOS_PARAMETER[12] (0x0000-0xffc0)
386
;;  C_IN: pointer to read buffer (64 bytes) in <buffer><BR>
387
;;        address in <addr> (0x0000-0xffc0)
388
;;  OUT:  BankStick content in read buffer
389
;;        MIOS_PARAMETER[12] will be incremented to next page address (+64)
390
;;        FSR1 will be left untouched
391
;;        MIOS_BOX_STAT[MIOS_BOX_STAT_BS_AVAILABLE] is also zero if write failed
392
;;  C_OUT: BankStick content in read buffer
393
;;        MIOS_BOX_STAT.BS_AVAILABLE is also zero if write failed
394
;;  USES: BSR, MIOS_PARAMETER[12]
395
;;  EXAMPLE:
396
;;
397
;;	;; read a page of 64 bytes from BankStick memory at address 0x1240
398
;;	movlw	0x40			; store low-byte of address in
399
;;	movwf	MIOS_PARAMETER1		; MIOS_PARAMETER1
400
;;	movlw	0x12			; store high-byte of address in
401
;;	movwf	MIOS_PARAMETER2		; MIOS_PARAMETER2
402
;;	lfsr	FSR1, 0x100		; a free 64 byte buffer in RAM which
403
;;					: contains some data
404
;;	call	MIOS_BANKSTICK_ReadPage	; start the page read
405
;;	BRA_IFCLR MIOS_BOX_STAT, MIOS_BOX_STAT_BS_AVAILABLE, ACCESS, BankStickNotAvl
406
;;
407
;;  C_EXAMPLE:
408
;;
409
;;	unsigned char buffer[64];
410
;;
411
;;	// read a page of 64 bytes from BankStick memory at address 0x1240
412
;;	MIOS_BANKSTICK_ReadPage(0x1240, buffer);
413
;;
414
;;	if( !MIOS_BOX_STAT.BS_AVAILABLE ) {
415
;;	  // here you could do some error handling
416
;;	}
417
;;
418
;; --------------------------------------------------------------------------
419
MIOS_BANKSTICK_ReadPage
420
	;; align address
421
	movlw	0xc0
422
	andwf	MIOS_PARAMETER1, F
423
 
424
	rcall	MIOS_IIC_Start		; start IIC
425
 
426
	rlf	MIOS_BOX_CFG1, W
427
	andlw	0x0e
428
	iorlw	0xa0			; set address
429
	rcall	MIOS_IIC_ByteSend
430
#if MIOS_BANKSTICK_16BIT == 1
431
	movf	MIOS_PARAMETER2, W	; send high address
432
	rcall	MIOS_IIC_ByteSend
433
#endif
434
	movf	MIOS_PARAMETER1, W	; send low address
435
	rcall	MIOS_IIC_ByteSend
436
 
437
	rcall	MIOS_IIC_Start		; start IIC again
438
	rlf	MIOS_BOX_CFG1, W
439
	andlw	0x0e
440
	iorlw	0xa1
441
	rcall	MIOS_IIC_ByteSend
442
 
443
	;; read 64 bytes
444
	SET_BSR	MIOS_TMP2
445
	clrf	MIOS_TMP2, BANKED
446
MIOS_BANKSTICK_ReadPage_Loop
447
	rcall	MIOS_IIC_ByteReceive	; read byte #0
448
	SET_BSR	MIOS_TMP1
449
	movwf	MIOS_TMP1, BANKED
450
	movf	MIOS_TMP2, W, BANKED
451
	movff	MIOS_TMP1, PLUSW1
452
	incf	MIOS_TMP2, F, BANKED
453
	movf	MIOS_TMP2, W, BANKED
454
	andlw	0x3f
455
	bz	MIOS_BANKSTICK_ReadPage_LoopBrk
456
	rcall	MIOS_IIC_AckSend
457
	rgoto	MIOS_BANKSTICK_ReadPage_Loop
458
 
459
MIOS_BANKSTICK_ReadPage_LoopBrk
460
	rcall	MIOS_IIC_NakSend
461
 
462
	rcall	MIOS_IIC_Stop		; stop IIC
463
 
464
	movlw	0x40
465
	addwf	MIOS_PARAMETER1, F		; increment MIOS_PARAMETER[12] by 0x40
466
	skpnc
467
	incf	MIOS_PARAMETER2, F
468
 
469
	return
470
 
471
 
472
;; --------------------------------------------------------------------------
473
;;  FUNCTION: MIOS_BANKSTICK_CtrlSet
474
;;  C_DECLARATION: void MIOS_BANKSTICK_CtrlSet(unsigned char ctrl)
475
;;  DESCRIPTION: sets the BankStick control register<BR>
476
;;     bit 2-0: selects the BankStick (1 of 8, address defined with pin A0-A2 of the EEPROM)<BR>
477
;;     bit 7:   if set, the verify during BankStick write will be disabled
478
;;  IN:	  control register content in WREG
479
;;  C_IN: control register content in <ctrl>
480
;;  OUT:  -
481
;;  USES: -
482
;;  EXAMPLE:
483
;;	;; write 0x47 0x11 to address 0x3000-0x3001 of the BankStick number 7
484
;;	movlw	0x07			; select 8th BankStick
485
;;	call	MIOS_BANKSTICK_CtrlSet
486
;;	movlw	0x00			; store low-byte of address in
487
;;	movwf	MIOS_PARAMETER1		; MIOS_PARAMETER1
488
;;	movlw	0x30			; store high-byte of address in
489
;;	movwf	MIOS_PARAMETER2		; MIOS_PARAMETER2
490
;;	movlw	0x47			; write 0x47 to 0x3000
491
;;	call	MIOS_BANKSTICK_Write	; (address will be incremented
492
;;					; after write)
493
;;	bnz	BSProgrammingFailed	; branch to your exception handler
494
;;					; if necessary
495
;;	movlw	0x11			; write 0x11 to 0x3001
496
;;	call	MIOS_BANKSTICK_Write	; (address will be incremented
497
;;					; after write)
498
;;	bnz	BSProgrammingFailed	; branch to your exception handler
499
;;					; if necessary
500
;;	movlw	0x00			; select first BankStick again
501
;;	call	MIOS_BANKSTICK_CtrlSet
502
;;  C_EXAMPLE:
503
;;
504
;;	unsigned char error = 0;
505
;;
506
;;	// write 0x47 0x11 to address 0x3000-0x3001 of the BankStick number 7
507
;;	MIOS_BANKSTICK_CtrlSet(0x07); // select 8th BankStick
508
;;	error |= MIOS_BANKSTICK_Write(0x3000, 0x47);
509
;;	error |= MIOS_BANKSTICK_Write(0x3001, 0x11);
510
;;
511
;; --------------------------------------------------------------------------
512
MIOS_BANKSTICK_CtrlSet
513
	bcf	MIOS_BOX_CFG1, MIOS_BOX_CFG1_BS_A0
514
	bcf	MIOS_BOX_CFG1, MIOS_BOX_CFG1_BS_A1
515
	bcf	MIOS_BOX_CFG1, MIOS_BOX_CFG1_BS_A2
516
	bcf	MIOS_BOX_CFG1, MIOS_BOX_CFG1_BS_DIS_VERIFY
517
 
518
	btfsc	WREG, 7
519
	bsf	MIOS_BOX_CFG1, MIOS_BOX_CFG1_BS_DIS_VERIFY
520
 
521
	andlw	0x07
522
	iorwf	MIOS_BOX_CFG1, F
523
	return
524
 
525
;; --------------------------------------------------------------------------
526
;;  FUNCTION: MIOS_BANKSTICK_CtrlGet
527
;;  C_DECLARATION: unsigned char MIOS_BANKSTICK_CtrlGet(void)
528
;;  DESCRIPTION: returns the BankStick control status
529
;;  IN:  -
530
;;  C_IN:  -
531
;;  OUT:  WREG[2..0]: A2-A0
532
;;        WREG[7]: Verify disabled
533
;;  C_OUT:  bit [2..0]: A2-A0
534
;;        bit [7]: Verify disabled
535
;;  USES: -
536
;; --------------------------------------------------------------------------
537
MIOS_BANKSTICK_CtrlGet
538
	movf	MIOS_BOX_CFG1, W
539
	andlw	0x07
540
	btfsc	MIOS_BOX_CFG1, MIOS_BOX_CFG1_BS_DIS_VERIFY
541
	iorlw 0x80
542
	return
543