Skip to content

Commit 80749ac

Browse files
Trying accommodate to the present SPI/TWI naming scheme
1 parent cddd052 commit 80749ac

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

simavr/sim/avr/avr_mcu_section.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,16 @@ enum {
7474
};
7575

7676
#define BITBANG_ON_SPI(_name) \
77-
((uint64_t)(_name - '0') << 0)
77+
((uint64_t)(_name >= '0' ? ((1 << (_name - '0'))&0xFF) : (1 << 8)) << 0)
7878

7979
#define BITBANG_ON_UART(_name) \
80-
((uint64_t)(_name - '0') << 8)
80+
((uint64_t)((1 << (_name - '0'))&0xFF) << 16)
8181

8282
#define BITBANG_ON_TWI(_name) \
83-
((uint64_t)(_name - '0') << 16)
83+
((uint64_t)(1) << 24)
8484

8585
#define BITBANG_ON_LIN(_name) \
86-
((uint64_t)(_name - '0') << 24)
86+
((uint64_t)(1) << 32)
8787

8888
#if __AVR__
8989
/*
@@ -163,8 +163,8 @@ struct avr_mmcu_vcd_trace_t {
163163
* module to ensure it's implemented).
164164
* By default bitbang is off for every peripheral.
165165
* You can turn it on using bitmask for specific peripheral instance,
166-
* e.g. the following turns it on for SPI0 and SPI1:
167-
* AVR_MCU_BITBANG(BITBANG_ON_SPI('0') | BITBANG_ON_SPI('1'));
166+
* e.g. the following turns it on for SPI0 and for USART1 in SPI mode:
167+
* AVR_MCU_BITBANG(BITBANG_ON_SPI(0) | BITBANG_ON_SPI('1'));
168168
*/
169169
#define AVR_MCU_BITBANG(_peripheral_on_mask) \
170170
AVR_MCU_LONGLONG(AVR_MMCU_TAG_BITBANG, _peripheral_on_mask)

simavr/sim/avr_spi.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ void avr_spi_init(avr_t * avr, avr_spi_t * port);
7878

7979
#define AVR_SPIX_DECLARE(_name, _prr, _prspi, _ss_pin_port, _p_sck, _p_miso, _p_mosi, _p_ss) \
8080
.spi = { \
81-
.name = '0' + _name,\
81+
.name = _name, \
8282
.disabled = AVR_IO_REGBIT(_prr, _prspi), \
8383
\
8484
.r_spdr = SPDR ## _name, \
@@ -108,7 +108,7 @@ void avr_spi_init(avr_t * avr, avr_spi_t * port);
108108

109109
#define AVR_SPI_DECLARE(_prr, _prspi, _ss_pin_port, _p_sck, _p_miso, _p_mosi, _p_ss) \
110110
.spi = { \
111-
.name = '0', \
111+
.name = 0, \
112112
.disabled = AVR_IO_REGBIT(_prr, _prspi), \
113113
\
114114
.r_spdr = SPDR, \

simavr/sim/sim_elf.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,20 @@ avr_load_firmware(
107107
avr_set_command_register(avr, firmware->command_register_addr);
108108
avr_set_console_register(avr, firmware->console_register_addr);
109109

110-
// initialize bitbang mode
110+
// initialize bitbang mode for multi-instance peripherals
111111
for (char name = '0'; name < '9'; name++) {
112112
if ((firmware->bitbang_on_mask & BITBANG_ON_SPI(name)) != 0) {
113113
uint32_t f = 0;
114114
avr_ioctl(avr, AVR_IOCTL_SPI_GET_FLAGS(name), &f);
115115
f |= AVR_SPI_FLAG_BITBANG_ON;
116116
avr_ioctl(avr, AVR_IOCTL_SPI_SET_FLAGS(name), &f);
117117
}
118+
if ((firmware->bitbang_on_mask & BITBANG_ON_SPI(name - '0')) != 0) {
119+
uint32_t f = 0;
120+
avr_ioctl(avr, AVR_IOCTL_SPI_GET_FLAGS(name), &f);
121+
f |= AVR_SPI_FLAG_BITBANG_ON;
122+
avr_ioctl(avr, AVR_IOCTL_SPI_SET_FLAGS(name), &f);
123+
}
118124
if ((firmware->bitbang_on_mask & BITBANG_ON_UART(name)) != 0) {
119125
//TODO: implement bitbang mode for UART modeule
120126
}

0 commit comments

Comments
 (0)