File: singlepincomm.h

package info (click to toggle)
simulavr 1.0.0%2Bgit20160221.e53413b-1
  • links: PTS
  • area: main
  • in suites: buster
  • size: 5,748 kB
  • sloc: cpp: 35,491; python: 6,991; ansic: 3,567; makefile: 1,072; sh: 653; asm: 414; tcl: 320
file content (134 lines) | stat: -rw-r--r-- 3,940 bytes parent folder | download | duplicates (2)
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#ifndef SINGLEPINCOMM_REGISTERS
#define SINGLEPINCOMM_REGISTERS
//-----------------------------------------------------------------------------
// Copyright (C) 2009 Onno Kortmann <onno@gmx.net>
//  
// This program 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 2 of the License, or
// (at your option) any later version.
//  
// This program 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 this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA..
//-----------------------------------------------------------------------------
//
// IMPORTANT NOTE: This file is only to illustrate the simulavrxx<->verilog
// interface and is by no means any reference for anything whatsoever!  It
// probably contains lots of bugs! As already stated above, there is no
// warranty!
//
//-----------------------------------------------------------------------------
; used by the low level parts
#if SPC_16BIT_TIME
#define lowcntl		r0
#define highcntl	r1
#endif

#define lowcnth		r20
#define highcnth	r21
	
#define temp0		r16
#define temp1		r17
#define trxbyte		r18
#define bitcnt		r19

// Register which may be used for the configurable software delay
#define	spc_delay	r2
//-----------------------------------------------------------------------------
// Port definition for SPC
#define SPC_PORT	PORTB
#define SPC_DDR		DDRB
#define SPC_PIN		PINB
#define SPC_BIT		PB2

// Debugging?
#define SPC_DEBUG			0

// Iff true, take the software-configurable delay from register spc_delay
#define SPC_SWDELAY			1
	
// Constant to delay the short delay (t_s) */
#define SPC_TSVALUE			150
// Multiplier N to go from t_s to t_l:	 t_l=N*t_s */
#define SPC_N				3
	
// Iff true, enclose all timing sensitive parts in CLI/SEI pairs.
#define	SPC_CLISEI			0

// Iff true, implement reading of the flash space through command 0x03 in the menu
#define SPC_FLASH_READ			1

// timeout in high-byte loop cycles for RX bit (0=> 256*256 cycles)
#define SPC_RX_TIMEOUT			0

// Iff true, wait for the line to be high first for each bit
#define SPC_RX_WAIT_INITIAL_HIGH	0

/// Iff true, use 16bit registers for timing
#define SPC_16BIT_TIME			0	
//-----------------------------------------------------------------------------
/* Simple menu for the slave.
   Call it to allow the master to read/write the RAM. */

.macro spc_slave_menu
	clr trxbyte
	rcall spc_trx_slave
	brts ssm_end		; timeout!
	cpi trxbyte, 0x01	; ram read?
	breq ssm_read
	cpi trxbyte, 0x02	; ram write?
	breq ssm_write
#if SPC_FLASH_READ
	cpi trxbyte, 0x03	; flash read?
	breq ssm_flash_read
#endif
	brne ssm_end		; something unknown...
ssm_read:
	rcall spc_trx_slave	; read low byte for location
	brts ssm_end
	mov r30, trxbyte

	rcall spc_trx_slave	; and high byte
	brts ssm_end
	mov r31, trxbyte

	ld trxbyte, Z		; load byte to transmit
	rcall spc_trx_slave	; and send it!
	rjmp ssm_end

ssm_write:
	rcall spc_trx_slave	; read low byte for location
	brts ssm_end
	mov r30, trxbyte

	rcall spc_trx_slave	; and high byte
	brts ssm_end
	mov r31, trxbyte

	rcall spc_trx_slave	; and byte to write!
	brts ssm_end
	st Z, trxbyte
#if SPC_FLASH_READ
ssm_flash_read:
	rcall spc_trx_slave	; read low byte for location
	brts ssm_end
	mov r30, trxbyte

	rcall spc_trx_slave	; and high byte
	brts ssm_end
	mov r31, trxbyte

	lpm			; load byte to transmit!
	mov trxbyte, r0		; r0 can be used, is lowcnt
	rcall spc_trx_slave	; and send it!
#endif
ssm_end:
.endm
//-----------------------------------------------------------------------------
#endif