aboutsummaryrefslogtreecommitdiff
path: root/bootloaders/nuevo_diskloader/src
diff options
context:
space:
mode:
Diffstat (limited to 'bootloaders/nuevo_diskloader/src')
-rw-r--r--bootloaders/nuevo_diskloader/src/DiskLoader.cpp76
-rw-r--r--bootloaders/nuevo_diskloader/src/USBAPI.h1
-rw-r--r--bootloaders/nuevo_diskloader/src/USBCore.cpp13
3 files changed, 78 insertions, 12 deletions
diff --git a/bootloaders/nuevo_diskloader/src/DiskLoader.cpp b/bootloaders/nuevo_diskloader/src/DiskLoader.cpp
index cbb709b..3b8657e 100644
--- a/bootloaders/nuevo_diskloader/src/DiskLoader.cpp
+++ b/bootloaders/nuevo_diskloader/src/DiskLoader.cpp
@@ -3,7 +3,8 @@
*/
#include "Platform.h"
-#include "USBCore.h"
+//#include "USBCore.h"
+
//extern "C"
void entrypoint(void) __attribute__ ((naked)) __attribute__ ((section (".vectors")));
@@ -12,10 +13,10 @@ void entrypoint(void)
asm volatile (
"eor r1, r1\n" // Zero register
"out 0x3F, r1\n" // SREG
- "ldi r28, 0xFF\n"
- "ldi r29, 0x0A\n"
- "out 0x3E, r29\n" // SPH
- "out 0x3D, r28\n" // SPL
+ "ldi r28, 0xFF\n" // Y-register
+ "ldi r29, 0x0A\n" // Y-register
+// "out 0x3E, r29\n" // SPH
+// "out 0x3D, r28\n" // SPL
"rjmp main" // Stack is all set up, start the main code
::);
}
@@ -27,11 +28,11 @@ volatile u16 _timeout;
void Program(u8 ep, u16 page, u8 count)
{
- u8 write = page < 28*1024; // Don't write over firmware please
+ u8 write = page < 30*1024; // Don't write over firmware please
if (write)
boot_page_erase(page);
- USB_Recv(ep,_flashbuf,count); // Read while page is erasing
+ USB_Recv_block(ep,_flashbuf,count); // Read while page is erasing
if (!write)
return;
@@ -93,6 +94,20 @@ const u8 _consts[] =
0x00, //
};
+int getch(void)
+{
+ u16 timeout;
+ u8 c;
+ for (timeout = 0; timeout; timeout--)
+ {
+ c = USB_Recv(CDC_RX);
+ if (c != -1)
+ return c;
+ }
+ return -1;
+}
+
+
int main(void) __attribute__ ((naked));
int main()
{
@@ -110,14 +125,18 @@ int main()
);
TX_LED_OFF();
RX_LED_OFF();
- L_LED_OFF();
- USB.attach();
+ L_LED_OFF();
+
+ /* UART setup stuff */
+
+ /* end UART setup stuff */
+
+ USB.attach();
sei();
_inSync = STK_INSYNC;
_ok = STK_OK;
-
for (;;)
{
u8* packet = _flashbuf;
@@ -143,7 +162,8 @@ int main()
}
_timeout = 0;
// Read params
- USB_Recv(CDC_RX, packet, len);
+// USB_Recv(CDC_RX, packet, len);
+ USB_Recv_block(CDC_RX, packet, len);
// Send a response
u8 send = 0;
@@ -187,8 +207,40 @@ int main()
// if (Serial.available() > 0 && Serial.read() != ' ')
// break;
// if (USB_Available(CDC_RX) && USB_Recv(CDC_RX) != ' ')
+
+// u8 countdown = 10;
+// while (!USB_Available(CDC_RX))
+// {
+// if (countdown-- == 0)
+// break;
+// }
+// u8 x = USB_Recv(CDC_RX);
+// if (x != -1 && x != ' ')
+// {
+// L_LED_ON();
+// break;
+// }
+
+// if (getch() != ' ')
+// break;
+
+// while (!USB_Available(CDC_RX))
+// ;
+//
+// int x = USB_Recv(CDC_RX);
+// if (x == -1)
+// {
+// UEINTX = 0x6B;
+// break;
+// }
+// else if (x != ' ')
+// {
+//// UEINTX = 0x6B;
+// break;
+// }
+
u16 countdown = 5000;
- while (!USB_Available(CDC_RX) && countdown-- > 10)
+ while (countdown-- > 10 && !USB_Available(CDC_RX))
;
if (USB_Recv(CDC_RX) != ' ')
break;
diff --git a/bootloaders/nuevo_diskloader/src/USBAPI.h b/bootloaders/nuevo_diskloader/src/USBAPI.h
index ca205a1..1724ce1 100644
--- a/bootloaders/nuevo_diskloader/src/USBAPI.h
+++ b/bootloaders/nuevo_diskloader/src/USBAPI.h
@@ -74,6 +74,7 @@ int USB_RecvControl(void* d, int len);
uint8_t USB_Available(uint8_t ep);
int USB_Send(uint8_t ep, const void* data, int len); // blocking
int USB_Recv(uint8_t ep, void* data, int len); // non-blocking
+void USB_Recv_block(u8 ep, u8* dst, int len); // blocking
int USB_Recv(uint8_t ep); // non-blocking
void USB_Flush(uint8_t ep);
diff --git a/bootloaders/nuevo_diskloader/src/USBCore.cpp b/bootloaders/nuevo_diskloader/src/USBCore.cpp
index cfcef73..fffe6f7 100644
--- a/bootloaders/nuevo_diskloader/src/USBCore.cpp
+++ b/bootloaders/nuevo_diskloader/src/USBCore.cpp
@@ -217,6 +217,19 @@ u8 USB_Available(u8 ep)
return FifoByteCount();
}
+void USB_Recv_block(u8 ep, u8* dst, int len)
+{
+ SetEP(ep);
+ while (len--)
+ {
+ while (!ReadWriteAllowed())
+ ;
+ *dst++ = Recv8();
+ if (!ReadWriteAllowed()) // release empty buffer
+ ReleaseRX();
+ }
+}
+
// Non Blocking receive
// Return number of bytes read
int USB_Recv(u8 ep, void* d, int len)