From 72479bee82e20ce5ca45acf52a3e821f25614348 Mon Sep 17 00:00:00 2001 From: r-studio Date: Fri, 9 Apr 2010 09:26:49 +0000 Subject: [PATCH] Added faster baud rate speed when using sm16cf to program Mulle. Added a fix in crt.S for the trampoline bug in the M16c GCC implementation. Fixed a bug in m16c62phardware.h with the atomic statements, the flag register was saved after the interrupts were disabled which is not correct. Some Mulle defines in the Deluge code had accidentally been removed, added these again. Added a faster software spi implementation for the RF230 specific Mulle code. It is still not fast enough, but it could be made faster if the RF230 chip code also would be modified. (Look into this in the future). --- support/make/m16c62p/crt.S | 21 ++- support/make/m16c62p/m16c62p.rules | 2 +- support/make/m16c62p/sm16cf.extra | 4 +- tos/chips/m16c62p/m16c62phardware.h | 4 +- tos/lib/net/Deluge/extra/NetProgC.nc | 2 +- tos/lib/net/Deluge/extra/NetProgM.nc | 6 +- tos/platforms/mulle/.platform | 2 +- tos/platforms/mulle/chips/rf230/HplRF230P.nc | 151 +++++++++++++++++-- 8 files changed, 170 insertions(+), 22 deletions(-) diff --git a/support/make/m16c62p/crt.S b/support/make/m16c62p/crt.S index 14ea1722..6a9cbe9b 100755 --- a/support/make/m16c62p/crt.S +++ b/support/make/m16c62p/crt.S @@ -47,7 +47,7 @@ .text .global __vector_default - + .global m32c_jsri16 .extern _main .section .init0,"ax",@progbits @@ -88,6 +88,25 @@ _start: /* In case we return, should realy generate a reset :/ */ jmp.b 0 +m32c_jsri16: + add.w #-1, sp + /* Read the address (16 bits) and return address (24 bits) off + the stack. */ + mov.w 4[sp], r0 + mov.w 1[sp], r3 + mov.b 3[sp], a0 /* This zero-extends, so the high byte has + zero in it. */ + /* Write the return address, then new address, to the stack. */ + mov.w a0, 1[sp] /* Just to get the zero in 2[sp]. */ + mov.w r0, 0[sp] + mov.w r3, 3[sp] + mov.b a0, 5[sp] + + /* This "returns" to the target address, leaving the pending + return address on the stack. */ + rts + + /* We should probably not get here. */ __vector_default: jmp.a __vector_default diff --git a/support/make/m16c62p/m16c62p.rules b/support/make/m16c62p/m16c62p.rules index 9fb99372..cc0b7bdd 100755 --- a/support/make/m16c62p/m16c62p.rules +++ b/support/make/m16c62p/m16c62p.rules @@ -26,7 +26,7 @@ OBJCOPY = m32c-elf-objcopy OBJDUMP = m32c-elf-objdump SET_ID = tos-set-symbols NCC = ncc -LIBS = -lm -lc -lgcc +LIBS = #-lm -lc -lgcc AMADDR = _ActiveMessageAddressC\$$addr # Uncomment the next two lines if you have a toolchain without the dollar sign diff --git a/support/make/m16c62p/sm16cf.extra b/support/make/m16c62p/sm16cf.extra index f83aa5f7..4a44de2b 100755 --- a/support/make/m16c62p/sm16cf.extra +++ b/support/make/m16c62p/sm16cf.extra @@ -15,13 +15,13 @@ ifdef BOOTLOADER @echo " installing $(PLATFORM) with bootloader using sm16cf" srec_cat $(BOOTLOADER_IMG) $(INSTALL_SREC) -exclude 0x000FFFDC 0x00100000 -o $(BUILDDIR)/main_boot.srec -CRLF sed '/S5/d' $(BUILDDIR)/main_boot.srec > $(BUILDDIR)/main_boot2.srec - $(PROGRAMMER) --device=$(SM16CF) --input-file=$(BUILDDIR)/main_boot2.srec --flash-program + $(PROGRAMMER) --baud-rate=57600 --device=$(SM16CF) --input-file=$(BUILDDIR)/main_boot2.srec --flash-program rm $(BUILDDIR)/main_boot.srec rm $(BUILDDIR)/main_boot2.srec else program: FORCE @echo " installing $(PLATFORM) using sm16cf" - $(PROGRAMMER) --device=$(SM16CF) --input-file=$(INSTALL_SREC) --flash-program + $(PROGRAMMER) --baud-rate=57600 --device=$(SM16CF) --input-file=$(INSTALL_SREC) --flash-program endif program_bl: FORCE diff --git a/tos/chips/m16c62p/m16c62phardware.h b/tos/chips/m16c62p/m16c62phardware.h index d85c2de2..d4f89271 100755 --- a/tos/chips/m16c62p/m16c62phardware.h +++ b/tos/chips/m16c62p/m16c62phardware.h @@ -119,10 +119,10 @@ typedef uint16_t __nesc_atomic_t; inline __nesc_atomic_t __nesc_atomic_start(void) @spontaneous() { __nesc_atomic_t result; - // Disable interrupts - __nesc_disable_interrupt(); // Save the flag register (FLG) asm volatile ("stc flg, %0": "=r"(result): : "%flg"); + // Disable interrupts + __nesc_disable_interrupt(); asm volatile("" : : : "memory"); // ensure atomic section effect visibility return result; } diff --git a/tos/lib/net/Deluge/extra/NetProgC.nc b/tos/lib/net/Deluge/extra/NetProgC.nc index 79bad765..74ad3132 100644 --- a/tos/lib/net/Deluge/extra/NetProgC.nc +++ b/tos/lib/net/Deluge/extra/NetProgC.nc @@ -56,7 +56,7 @@ implementation { components ActiveMessageAddressC; NetProgM.setAmAddress -> ActiveMessageAddressC; -#if !defined(PLATFORM_TINYNODE) +#if !defined(PLATFORM_TINYNODE) && !defined(PLATFORM_MULLE) components CC2420ControlP; NetProgM.CC2420Config -> CC2420ControlP; #endif diff --git a/tos/lib/net/Deluge/extra/NetProgM.nc b/tos/lib/net/Deluge/extra/NetProgM.nc index fc054cff..94368143 100644 --- a/tos/lib/net/Deluge/extra/NetProgM.nc +++ b/tos/lib/net/Deluge/extra/NetProgM.nc @@ -40,7 +40,7 @@ module NetProgM { interface InternalFlash as IFlash; interface Crc; interface Leds; -#if !defined(PLATFORM_TINYNODE) +#if !defined(PLATFORM_TINYNODE) && !defined(PLATFORM_MULLE) interface CC2420Config; #endif async command void setAmAddress(am_addr_t a); @@ -62,7 +62,7 @@ implementation { TOS_NODE_ID = bootArgs.address; call setAmAddress(bootArgs.address); } -#if !defined(PLATFORM_TINYNODE) +#if !defined(PLATFORM_TINYNODE) && !defined(PLATFORM_MULLE) call CC2420Config.setShortAddr(bootArgs.address); call CC2420Config.sync(); #endif @@ -116,7 +116,7 @@ implementation { } } -#if !defined(PLATFORM_TINYNODE) +#if !defined(PLATFORM_TINYNODE) && !defined(PLATFORM_MULLE) event void CC2420Config.syncDone(error_t error) {} #endif } diff --git a/tos/platforms/mulle/.platform b/tos/platforms/mulle/.platform index eb04440c..3a325f0c 100755 --- a/tos/platforms/mulle/.platform +++ b/tos/platforms/mulle/.platform @@ -32,7 +32,7 @@ push( @includes, qw( %T/lib/timer %T/lib/serial %T/lib/diagmsg - %T/lib/printf + %T/lib/net/Deluge ) ); @opts = qw( diff --git a/tos/platforms/mulle/chips/rf230/HplRF230P.nc b/tos/platforms/mulle/chips/rf230/HplRF230P.nc index 1973c681..4891c5e9 100755 --- a/tos/platforms/mulle/chips/rf230/HplRF230P.nc +++ b/tos/platforms/mulle/chips/rf230/HplRF230P.nc @@ -33,7 +33,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ - + /** * Implementation of the time capture on RF230 interrupt and the * FastSpiBus interface. @@ -53,7 +53,7 @@ module HplRF230P uses { interface GeneralIO as PortIRQ; - interface GeneralIO as PortVCC; + interface GeneralIO as PortVCC; interface GpioInterrupt as GIRQ; interface SoftSpiBus as Spi; interface Alarm as Alarm; @@ -97,30 +97,159 @@ implementation call GIRQ.disable(); } + /** + * Faster software implementation of the SPI bus for communication + * with the RF230 chip. + */ + uint8_t fastWrite(uint8_t byte) + { +#define fwMOSIset() P1.BIT.P1_1 = 1 +#define fwMOSIclr() P1.BIT.P1_1 = 0 +#define fwSCLKset() P3.BIT.P3_3 = 1 +#define fwSCLKclr() P3.BIT.P3_3 = 0 +#define fwMISOget() P1.BIT.P1_0 + uint8_t data = 0; + uint8_t mask = 0x80; + atomic { + if (byte & mask) + { + fwMOSIset(); + } + else + { + fwMOSIclr(); + } + fwSCLKclr(); + if( fwMISOget() ) + data |= mask; + fwSCLKset(); + mask >>= 1; + + if (byte & mask) + { + fwMOSIset(); + } + else + { + fwMOSIclr(); + } + fwSCLKclr(); + if( fwMISOget() ) + data |= mask; + fwSCLKset(); + mask >>= 1; + + if (byte & mask) + { + fwMOSIset(); + } + else + { + fwMOSIclr(); + } + fwSCLKclr(); + if( fwMISOget() ) + data |= mask; + fwSCLKset(); + mask >>= 1; + + if (byte & mask) + { + fwMOSIset(); + } + else + { + fwMOSIclr(); + } + fwSCLKclr(); + if( fwMISOget() ) + data |= mask; + fwSCLKset(); + mask >>= 1; + + if (byte & mask) + { + fwMOSIset(); + } + else + { + fwMOSIclr(); + } + fwSCLKclr(); + if( fwMISOget() ) + data |= mask; + fwSCLKset(); + mask >>= 1; + + if (byte & mask) + { + fwMOSIset(); + } + else + { + fwMOSIclr(); + } + fwSCLKclr(); + if( fwMISOget() ) + data |= mask; + fwSCLKset(); + mask >>= 1; + + if (byte & mask) + { + fwMOSIset(); + } + else + { + fwMOSIclr(); + } + fwSCLKclr(); + if( fwMISOget() ) + data |= mask; + fwSCLKset(); + mask >>= 1; + + if (byte & mask) + { + fwMOSIset(); + } + else + { + fwMOSIclr(); + } + fwSCLKclr(); + if( fwMISOget() ) + data |= mask; + fwSCLKset(); + mask >>= 1; + } + return data; + } + uint8_t tmp_data; - async command void FastSpiByte.splitWrite(uint8_t data) + inline async command void FastSpiByte.splitWrite(uint8_t data) { - atomic tmp_data = data; + atomic tmp_data = fastWrite(data); } - async command uint8_t FastSpiByte.splitRead() + inline async command uint8_t FastSpiByte.splitRead() { - atomic return call Spi.write(tmp_data); + atomic return tmp_data; } - async command uint8_t FastSpiByte.splitReadWrite(uint8_t data) + inline async command uint8_t FastSpiByte.splitReadWrite(uint8_t data) { uint8_t b; atomic { - b = call Spi.write(tmp_data); - tmp_data = data; + b = tmp_data; + tmp_data = fastWrite(data); } return b; } - async command uint8_t FastSpiByte.write(uint8_t data) + inline async command uint8_t FastSpiByte.write(uint8_t data) { - return call Spi.write(data); + return fastWrite(data); } } -- 2.39.2