--- /dev/null
+#include "platform.h"
+
+#include <avr/io.h>
+#include <util/delay.h>
+
+//! Receive a byte.
+unsigned char serial0_rx(){
+ while( !(UCSR0A & (1 << RXC0)) );
+ return UDR0;
+}
+
+//! Receive a byte.
+unsigned char serial1_rx(){
+ return 0;
+}
+
+//! Transmit a byte.
+void serial0_tx(unsigned char x){
+ while (!(UCSR0A & (1<<UDRE0)) );
+ UDR0 = x;
+}
+
+//! Transmit a byte on the second UART.
+void serial1_tx(unsigned char x){
+}
+
+//! Set the baud rate.
+void setbaud0(unsigned char rate){
+ /* disable briefly */
+ UCSR0B = 0;
+
+ UBRR0L = 4; /* 500,000 baud at 20MHz */
+ //UBRR0L = 1; /* 500,000 baud at 8MHz */
+ //UBRR0L = 103; /* 9600 baud */
+ // XXX UBRR0L = 8; /* 115200 baud ERROR RATE TOO HIGH */
+ UBRR0H = 0;
+
+ UCSR0A = (1 << U2X0); /* double the baud rate */
+ UCSR0C = (3 << UCSZ00); /* 8N1 */
+
+ /* enabling rx/tx must be done after frame/baud setup */
+ UCSR0B = ((1 << TXEN0) | (1 << RXEN0));
+
+ return;
+
+}
+
+//! Set the baud rate of the second uart.
+void setbaud1(unsigned char rate){
+ //http://mspgcc.sourceforge.net/baudrate.html
+ switch(rate){
+ case 1://9600 baud
+
+ break;
+ case 2://19200 baud
+
+ break;
+ case 3://38400 baud
+
+ break;
+ case 4://57600 baud
+
+ break;
+ default:
+ case 5://115200 baud
+
+ break;
+ }
+}
+
+
+void zigduino_init_uart0(){
+ setbaud0(0);
+ _delay_ms(500); //takes a bit to stabilize
+}
+
+void led_init(){
+
+}
+
+void led_on() {
+ PLEDOUT |= (1 << PLEDPIN);
+}
+
+void led_off() {
+ PLEDOUT &= ~(1 << PLEDPIN);
+}
+
+void zigduino_init(){
+ uint8_t x;
+
+ /* explicitly clear interrupts */
+ cli();
+
+ /* move the vectors */
+
+ /* move interrupts from boot flash section */
+ /* NB */
+ /* you MUST use a variable during this process. even highly optimized,
+ * masking the bit, shifting, ANDing, and setting MCUCR will exceed
+ * 4 CPU cycles! set a variable with the desired value for MCUCR and
+ * then set the register once IVCE is enabled
+ */
+ x = MCUCR & ~(1 << IVSEL);
+
+ /* enable change of interrupt vectors */
+ /* NOTE: setting IVCE disables interrupts until the bit is auto-unset
+ * 4 cycles after being set or after IVSEL is written
+ */
+ MCUCR |= (1 << IVCE);
+ MCUCR = x;
+
+ /* disable the watchdog timer; this macro will disable interrupts for us */
+ /* NOTE: ensure that the WDRF flag is unset in the MCUSR or we will spinlock
+ * when the watchdog times out
+ */
+ MCUSR &= ~(1 << WDRF);
+ wdt_disable();
+
+ /* init the USART */
+ zigduino_init_uart0();
+
+ /* set the LED as an output */
+ PLEDDIR |= (1 << PLEDPIN);
+ PLEDOUT |= (1 << PLEDPIN);
+
+ /* explicitly enable interrupts */
+ sei();
+}
+
+void
+zigduino_reboot()
+{
+ MCUSR &= ~(1 << WDRF);
+ wdt_enable(WDTO_15MS);
+ while(1)
+ _delay_ms(127);
+}
+
+void zigduino_init_uart1(){
+}
+
+uint8_t
+zigduino_get_byte(uint16_t v)
+{
+ /* NB */
+ /* we are only passed in a 16bit word. should
+ * be increased to 32bit if we want to handle
+ * far reads as well
+ */
+/* XXX should be far on the 1284P, but there are bugs with flash reads using _far */
+/* XXX until the bugs are figured out (probably my fault?) use _near */
+ return pgm_read_byte_near(v);
+}
+
+int *
+zigduino_ramend(void)
+{
+ /* NB */
+ /* ATmega1284P has 16K SRAM */
+ return (int * )0x4000;
+}
+
+void
+led_toggle(void)
+{
+ led_on();
+ _delay_ms(30);
+ led_off();
+}
+
--- /dev/null
+/*! \file donbfet.h
+ \author Don A. Bailey
+ \brief Port descriptions for the DonbFET platform.
+*/
+
+/* NB: define default CPU frequency */
+//XXX #define F_CPU 8000000UL
+#define F_CPU 20000000UL
+
+#include <avr/io.h>
+#include <avr/wdt.h>
+#include <avr/boot.h>
+#include <avr/sleep.h>
+#include <avr/interrupt.h>
+#include <avr/pgmspace.h>
+#include <util/delay.h>
+#include <inttypes.h>
+#include <stdint.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <ctype.h>
+
+/* all AVR SRAM starts after I/O mapped memory and registers */
+#define RAMSTART 0x100
+
+#ifndef PB0
+# define PB0 PORTB0
+#endif
+#ifndef PA0
+# define PA0 PORTA0
+#endif
+#ifndef PA1
+# define PA1 PORTA1
+#endif
+#ifndef PA2
+# define PA2 PORTA2
+#endif
+#ifndef PA3
+# define PA3 PORTA3
+#endif
+#ifndef PA4
+# define PA4 PORTA4
+#endif
+#ifndef PA5
+# define PA5 PORTA5
+#endif
+
+//LED on P1.0
+#define PLEDOUT PORTB
+#define PLEDDIR DDRB
+#define PLEDPIN PB0
+
+//Use P3 instead of P5 for target I/O on chips without P5.
+#ifdef msp430f2274
+//#warning "No P5, using P3 instead. Will break 2618 and 1612 support."
+# define P5OUT P3OUT
+# define P5DIR P3DIR
+# define P5IN P3IN
+# define P5REN P3REN
+
+# define SPIOUT P3OUT
+# define SPIDIR P3DIR
+# define SPIIN P3IN
+# define SPIREN P3REN
+#else
+
+# if (platform == zigduino)
+# define SPIOUT PORTA
+# define SPIDIR DDRA
+# define SPIIN PINA
+//# define SPIREN P5REN
+# endif
+#endif
+
+//This is how things used to work, don't do it anymore.
+//#ifdef msp430x1612
+//#define P5REN somedamnedextern
+//#endif
+
+#if (platform == zigduino)
+# define SETSS PORTA|=SS;
+# define CLRSS PORTA&=~SS;
+# define DIRSS DDRA|=SS;
+#else
+//No longer works for Hope badge.
+# define SETSS P5OUT|=BIT0
+# define CLRSS P5OUT&=~BIT0
+# define DIRSS P5DIR|=BIT0;
+#endif
+
+//Used for the Nordic port, !RST pin on regular GoodFET.
+#define SETCE P2OUT|=BIT6
+#define CLRCE P2OUT&=~BIT6
+#define DIRCE P2DIR|=BIT6
+
+// network byte order converters
+#define htons(x) ((((uint16_t)(x) & 0xFF00) >> 8) | \
+ (((uint16_t)(x) & 0x00FF) << 8))
+#define htonl(x) ((((uint32_t)(x) & 0xFF000000) >> 24) | \
+ (((uint32_t)(x) & 0x00FF0000) >> 8) | \
+ (((uint32_t)(x) & 0x0000FF00) << 8) | \
+ (((uint32_t)(x) & 0x000000FF) << 24))
+
+#define ntohs htons
+#define ntohl htonl
+
+extern uint8_t zigduino_get_byte(uint16_t);
+