Merge ccdbg and altos sources into one giant repository
[fw/altos] / target / ee / ee.c
index ed13d0ad455e4655b525c6d4686ed7805e9436dd..9ea22cdcc41fe74081e0a94c9ea0c10c22afe1df 100644 (file)
@@ -26,6 +26,10 @@ sfr at 0x80 P0;
 sfr at 0x90 P1;
 sfr at 0xA0 P2;
 sfr at 0xC6 CLKCON;
+sfr at 0xbe SLEEP;
+
+# define SLEEP_USB_EN          (1 << 7)
+# define SLEEP_XOSC_STB                (1 << 6)
 
 sfr at 0xF1 PERCFG;
 #define PERCFG_T1CFG_ALT_1     (0 << 6)
@@ -170,7 +174,7 @@ uint8_t
 bitbang_in_bit(void)
 {
        uint8_t b;
-       
+
        delay(1);
        SCK = 1;
        delay(1);
@@ -274,6 +278,7 @@ usart_in_out(uint8_t byte)
        while ((U0CSR & UxCSR_TX_BYTE) == 0)
                ;
        U0CSR &= ~UxCSR_TX_BYTE;
+       return U0DBUF;
 }
 
 void
@@ -314,7 +319,7 @@ wrsr(uint8_t status)
        spi_out_byte(status);
        spi_cs(1);
 }
-       
+
 void
 wren(void)
 {
@@ -378,7 +383,9 @@ main ()
 
        P1DIR |= 2;
        CLKCON = 0;
-       
+       while (!(SLEEP & SLEEP_XOSC_STB))
+               ;
+
        spi_init();
 
        status = rdsr();