Moved the programmer protocol to a different file in preparation for sharing it across all the various programs (bootloader, programmer, control program)

This commit is contained in:
Doug Brown 2011-12-26 11:31:45 -08:00
parent 258fb187ad
commit e8999cfc54
2 changed files with 120 additions and 67 deletions

118
programmer_protocol.h Normal file
View File

@ -0,0 +1,118 @@
/*
* programmer_protocol.h
*
* Created on: Dec 26, 2011
* Author: Doug
*/
#ifndef PROGRAMMER_PROTOCOL_H_
#define PROGRAMMER_PROTOCOL_H_
// When the programmer is in "waiting for command" mode,
// you send it one of the bytes below to do something (or begin to do something)
typedef enum ProgrammerCommand
{
EnterWaitingMode = 0,
DoElectricalTest,
IdentifyChips,
ReadByte,
ReadChips,
EraseChips,
WriteChips,
GetBootloaderState,
EnterBootloader,
EnterProgrammer,
BootloaderEraseAndWriteProgram
} ProgrammerCommand;
// After a command is sent, the programmer will always respond with
// one of the replies below. (Depending on the command, it may reply with other
// stuff after that, too)
typedef enum ProgrammerReply
{
CommandReplyOK = 0,
CommandReplyError,
CommandReplyInvalid
} ProgrammerReply;
// ------------------------- ELECTRICAL TEST PROTOCOL -------------------------
// After CommandReplyOK, any failures are reported by the programmer.
// It will send ProgrammerElectricalTestFail followed by two more bytes -- each
// representing an index of the failure location. Any more electrical test failures
// will result in another 3-byte sequence as described above.
// When it's totally finished, it will send ProgrammerElectricalTestDone.
// So a pass would be indicated by no ProgrammerElectricalTestFail sequences being
// sent.
typedef enum ProgrammerElectricalTestReply
{
ProgrammerElectricalTestFail = 0,
ProgrammerElectricalTestDone
} ProgrammerElectricalTestReply;
// ------------------------- IDENTIFY CHIPS PROTOCOL -------------------------
// After CommandReplyOK, it will send the manufacturer ID and device ID of each
// of the 4 chips:
// M1, D1, M2, D2, M3, D3, M4, D4
// followed by ProgrammerIdentifyDone.
typedef enum ProgrammerIdentifyReply
{
ProgrammerIdentifyDone = 0
} ProgrammerIdentifyReply;
// ------------------------- READ PROTOCOL -------------------------
// After CommandReplyOK, the programmer will send a chunk of data.
// The computer will send a reply (see the enum below this one)
// The programmer will then reply to *that* reply (see this enum)
typedef enum ProgrammerReadReply
{
ProgrammerReadOK = 0,
ProgrammerReadError,
ProgrammerReadMoreData,
ProgrammerReadFinished,
ProgrammerReadConfirmCancel
} ProgrammerReadReply;
// When the computer is confirming reception of a block of data from the device,
// it should reply with either OK that it received the data OK, or cancel
// to tell the device that the user canceled the read.
typedef enum ComputerReadReply
{
ComputerReadOK = 0,
ComputerReadCancel
} ComputerReadReply;
// ------------------------- ERASE PROTOCOL -------------------------
// There is none -- a reply of CommandReplyOK will indicate that the erase
// completed successfully.
// ------------------------- WRITE PROTOCOL -------------------------
// After CommandReplyOK, the computer should send one of the commands below.
// The programmer will reply with one of the replies seen in the enum below
// this one, and then the computer can send a 1024-byte chunk of data.
// The programmer will reply with ProgrammerWriteOK, and then the cycle can
// continue (the computer sends another request in this enum)
typedef enum ComputerWriteRequest
{
ComputerWriteMore = 0,
ComputerWriteFinish,
ComputerWriteCancel
} ComputerWriteRequest;
typedef enum ProgrammerWriteReply
{
ProgrammerWriteOK = 0,
ProgrammerWriteError,
ProgrammerWriteConfirmCancel
} ProgrammerWriteReply;
// ------------------------- BOOTLOADER STATE PROTOCOL -------------------------
// If the command is GetBootloaderState, it will reply with CommandReplyOK followed
// by one of the two replies below to tell the control program which mode
// the device is currently in.
typedef enum BootloaderStateReply
{
BootloaderStateInBootloader = 0,
BootloaderStateInProgrammer
} BootloaderStateReply;
#endif /* PROGRAMMER_PROTOCOL_H_ */

View File

@ -10,6 +10,7 @@
#include "../Descriptors.h"
#include "../external_mem.h"
#include "../tests/simm_electrical_test.h"
#include "../programmer_protocol.h"
#define CHIP_SIZE (512UL * 1024UL)
#define READ_CHUNK_SIZE_BYTES 1024UL
@ -55,73 +56,6 @@ typedef enum ProgrammerCommandState
WritingChips
} ProgrammerCommandState;
typedef enum ProgrammerCommand
{
EnterWaitingMode = 0,
DoElectricalTest,
IdentifyChips,
ReadByte,
ReadChips,
EraseChips,
WriteChips,
GetBootloaderState,
EnterBootloader,
EnterProgrammer
} ProgrammerCommand;
typedef enum ProgrammerReply
{
CommandReplyOK = 0,
CommandReplyError,
CommandReplyInvalid
} ProgrammerReply;
typedef enum BootloaderStateReply
{
BootloaderStateInBootloader = 0,
BootloaderStateInProgrammer
} BootloaderStateReply;
typedef enum ComputerReadReply
{
ComputerReadOK = 0,
ComputerReadCancel
} ComputerReadReply;
typedef enum ProgrammerReadReply
{
ProgrammerReadOK = 0,
ProgrammerReadError,
ProgrammerReadMoreData,
ProgrammerReadFinished,
ProgrammerReadConfirmCancel
} ProgrammerReadReply;
typedef enum ComputerWriteReply
{
ComputerWriteMore = 0,
ComputerWriteFinish,
ComputerWriteCancel
} ComputerWriteReply;
typedef enum ProgrammerWriteReply
{
ProgrammerWriteOK = 0,
ProgrammerWriteError,
ProgrammerWriteConfirmCancel
} ProgrammerWriteReply;
typedef enum ProgrammerIdentifyReply
{
ProgrammerIdentifyDone = 0
} ProgrammerIdentifyReply;
typedef enum ProgrammerElectricalTestReply
{
ProgrammerElectricalTestFail = 0,
ProgrammerElectricalTestDone
} ProgrammerElectricalTestReply;
static ProgrammerCommandState curCommandState = WaitingForCommand;
static uint8_t byteAddressReceiveCount = 0;
static uint16_t curReadIndex;
@ -248,6 +182,7 @@ void USBSerial_HandleWaitingForCommandByte(uint8_t byte)
switch (byte)
{
case EnterWaitingMode:
SendByte(CommandReplyOK);
curCommandState = WaitingForCommand;
break;
case DoElectricalTest: