mirror of
https://github.com/dougg3/mac-rom-simm-programmer.git
synced 2025-02-28 06:29:34 +00:00
Started writing more command handling
This commit is contained in:
parent
651c3a4be7
commit
f45cc2c4d6
@ -50,7 +50,7 @@
|
||||
<option id="de.innot.avreclipse.cppcompiler.option.optimize.1022518531" name="Optimization Level" superClass="de.innot.avreclipse.cppcompiler.option.optimize"/>
|
||||
</tool>
|
||||
<tool id="de.innot.avreclipse.tool.linker.winavr.app.debug.806884166" name="AVR C Linker" superClass="de.innot.avreclipse.tool.linker.winavr.app.debug">
|
||||
<option id="de.innot.avreclipse.linker.option.otherlinkargs.1714687929" name="Other Arguments" superClass="de.innot.avreclipse.linker.option.otherlinkargs" value="-Wl,--relax,--gc-sections" valueType="string"/>
|
||||
<option id="de.innot.avreclipse.linker.option.otherlinkargs.1714687929" name="Other Arguments" superClass="de.innot.avreclipse.linker.option.otherlinkargs" value="-Wl,--gc-sections" valueType="string"/>
|
||||
<inputType id="de.innot.avreclipse.tool.linker.input.1020880987" name="OBJ Files" superClass="de.innot.avreclipse.tool.linker.input">
|
||||
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
|
||||
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
|
||||
@ -431,7 +431,7 @@
|
||||
<option id="de.innot.avreclipse.cppcompiler.option.optimize.1657124646" name="Optimization Level" superClass="de.innot.avreclipse.cppcompiler.option.optimize" value="de.innot.avreclipse.cppcompiler.optimize.size" valueType="enumerated"/>
|
||||
</tool>
|
||||
<tool id="de.innot.avreclipse.tool.linker.winavr.app.release.381852607" name="AVR C Linker" superClass="de.innot.avreclipse.tool.linker.winavr.app.release">
|
||||
<option id="de.innot.avreclipse.linker.option.otherlinkargs.270243458" name="Other Arguments" superClass="de.innot.avreclipse.linker.option.otherlinkargs" value="-Wl,--relax,--gc-sections" valueType="string"/>
|
||||
<option id="de.innot.avreclipse.linker.option.otherlinkargs.270243458" name="Other Arguments" superClass="de.innot.avreclipse.linker.option.otherlinkargs" value="-Wl,--gc-sections" valueType="string"/>
|
||||
<inputType id="de.innot.avreclipse.tool.linker.input.567763029" name="OBJ Files" superClass="de.innot.avreclipse.tool.linker.input">
|
||||
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
|
||||
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
|
||||
|
22
chip_id.h
Normal file
22
chip_id.h
Normal file
@ -0,0 +1,22 @@
|
||||
/*
|
||||
* chip_id.h
|
||||
*
|
||||
* Created on: Dec 10, 2011
|
||||
* Author: Doug
|
||||
*/
|
||||
|
||||
#ifndef CHIP_ID_H_
|
||||
#define CHIP_ID_H_
|
||||
|
||||
#define SST_GREENLIANT 0xBF
|
||||
#define GLS29EE010 0x07
|
||||
#define GLS29SF020 0x24
|
||||
#define GLS29SF040 0x13
|
||||
#define SST39SF010A 0xB5
|
||||
#define SST39SF020A 0xB6
|
||||
#define SST39SF040 0xB7
|
||||
|
||||
#define AMD 0x01
|
||||
#define AM29F040B 0xA4
|
||||
|
||||
#endif /* CHIP_ID_H_ */
|
@ -9,6 +9,12 @@
|
||||
#include "../LUFA/Drivers/USB/USB.h"
|
||||
#include "../Descriptors.h"
|
||||
#include "../external_mem.h"
|
||||
#include "../tests/simm_electrical_test.h"
|
||||
|
||||
#define READ_CHUNK_SIZE_BYTES 1024UL
|
||||
#if ((READ_CHUNK_SIZE_BYTES % 4) != 0)
|
||||
#error Read chunk size should be a multiple of 4 bytes
|
||||
#endif
|
||||
|
||||
USB_ClassInfo_CDC_Device_t VirtualSerial_CDC_Interface =
|
||||
{
|
||||
@ -18,11 +24,11 @@ USB_ClassInfo_CDC_Device_t VirtualSerial_CDC_Interface =
|
||||
|
||||
.DataINEndpointNumber = CDC_TX_EPNUM,
|
||||
.DataINEndpointSize = CDC_TXRX_EPSIZE,
|
||||
.DataINEndpointDoubleBank = false,
|
||||
.DataINEndpointDoubleBank = true,
|
||||
|
||||
.DataOUTEndpointNumber = CDC_RX_EPNUM,
|
||||
.DataOUTEndpointSize = CDC_TXRX_EPSIZE,
|
||||
.DataOUTEndpointDoubleBank = false,
|
||||
.DataOUTEndpointDoubleBank = true,
|
||||
|
||||
.NotificationEndpointNumber = CDC_NOTIFICATION_EPNUM,
|
||||
.NotificationEndpointSize = CDC_NOTIFICATION_EPSIZE,
|
||||
@ -35,6 +41,38 @@ void USBSerial_Init(void)
|
||||
USB_Init();
|
||||
}
|
||||
|
||||
typedef enum ProgrammerCommandState
|
||||
{
|
||||
WaitingForCommand = 0,
|
||||
ReadingByteWaitingForAddress,
|
||||
ReadingChips,
|
||||
ReadingChipsUnableSendError,
|
||||
} ProgrammerCommandState;
|
||||
|
||||
typedef enum ProgrammerCommand
|
||||
{
|
||||
EnterWaitingMode = 0,
|
||||
DoElectricalTest,
|
||||
IdentifyChips,
|
||||
ReadByte,
|
||||
ReadChips,
|
||||
EraseChips,
|
||||
WriteChips,
|
||||
} ProgrammerCommand;
|
||||
|
||||
typedef enum ProgrammerReply
|
||||
{
|
||||
ReplyOK,
|
||||
ReplyError,
|
||||
};
|
||||
|
||||
static ProgrammerCommandState curCommandState = WaitingForCommand;
|
||||
static uint8_t byteAddressReceiveCount = 0;
|
||||
static uint16_t curReadIndex;
|
||||
|
||||
void USBSerial_HandleWaitingForCommandByte(uint8_t byte);
|
||||
void USBSerial_SendReadDataChunk(void);
|
||||
|
||||
void USBSerial_Check(void)
|
||||
{
|
||||
/*if (USB_DeviceState == DEVICE_STATE_Configured)
|
||||
@ -56,10 +94,89 @@ void USBSerial_Check(void)
|
||||
}
|
||||
}*/
|
||||
|
||||
if (USB_DeviceState == DEVICE_STATE_Configured)
|
||||
{
|
||||
// Check for commands, etc...
|
||||
int16_t recvByte = CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface);
|
||||
|
||||
if (recvByte >= 0)
|
||||
{
|
||||
switch (curCommandState)
|
||||
{
|
||||
case WaitingForCommand:
|
||||
USBSerial_HandleWaitingForCommandByte((uint8_t)recvByte);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CDC_Device_USBTask(&VirtualSerial_CDC_Interface);
|
||||
USB_USBTask();
|
||||
}
|
||||
|
||||
void USBSerial_HandleWaitingForCommandByte(uint8_t byte)
|
||||
{
|
||||
switch (byte)
|
||||
{
|
||||
case EnterWaitingMode:
|
||||
curCommandState = WaitingForCommand;
|
||||
break;
|
||||
case DoElectricalTest:
|
||||
CDC_Device_SendByte(&VirtualSerial_CDC_Interface, ReplyOK);
|
||||
SIMMElectricalTest_Run();
|
||||
curCommandState = WaitingForCommand;
|
||||
break;
|
||||
case IdentifyChips:
|
||||
{
|
||||
struct ChipID chips[4];
|
||||
CDC_Device_SendByte(&VirtualSerial_CDC_Interface, ReplyOK);
|
||||
ExternalMem_IdentifyChips(chips);
|
||||
// TODO: Send chip ID info back to receiver
|
||||
break;
|
||||
}
|
||||
case ReadByte:
|
||||
curCommandState = ReadingByteWaitingForAddress;
|
||||
byteAddressReceiveCount = 0;
|
||||
CDC_Device_SendByte(&VirtualSerial_CDC_Interface, ReplyOK);
|
||||
break;
|
||||
case ReadChips:
|
||||
curCommandState = ReadingChips;
|
||||
curReadIndex = 0;
|
||||
CDC_Device_SendByte(&VirtualSerial_CDC_Interface, ReplyOK);
|
||||
USBSerial_SendReadDataChunk();
|
||||
break;
|
||||
case EraseChips:
|
||||
case WriteChips:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void USBSerial_SendReadDataChunk(void)
|
||||
{
|
||||
// TODO: How do I send an error back to the device?
|
||||
// Maybe the device, when it tries to request the next data chunk,
|
||||
// will get an ERROR response instead of an "OK" response?
|
||||
|
||||
static union
|
||||
{
|
||||
uint32_t readChunks[READ_CHUNK_SIZE_BYTES / 4];
|
||||
uint8_t readChunkBytes[READ_CHUNK_SIZE_BYTES];
|
||||
} chunks;
|
||||
|
||||
ExternalMem_Read(curReadIndex * (READ_CHUNK_SIZE_BYTES/4), chunks.readChunks, READ_CHUNK_SIZE_BYTES/4);
|
||||
uint8_t retVal = CDC_Device_SendData(&VirtualSerial_CDC_Interface, (const char *)chunks.readChunkBytes, READ_CHUNK_SIZE_BYTES);
|
||||
if (retVal != ENDPOINT_RWSTREAM_NoError)
|
||||
{
|
||||
curCommandState = ReadingChipsUnableSendError;
|
||||
}
|
||||
else
|
||||
{
|
||||
curReadIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** Event handler for the library USB Configuration Changed event. */
|
||||
void EVENT_USB_Device_ConfigurationChanged(void)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user