Commit c647c276 authored by Dean Camera's avatar Dean Camera
Browse files

Minor changes to the AVRISP project for code clarity.

parent 8bb007f8
...@@ -120,11 +120,11 @@ void Process_AVRISP_Commands(void) ...@@ -120,11 +120,11 @@ void Process_AVRISP_Commands(void)
Endpoint_SelectEndpoint(AVRISP_DATA_EPNUM); Endpoint_SelectEndpoint(AVRISP_DATA_EPNUM);
/* Check to see if a V2 Protocol command has been received - if not, abort */ /* Check to see if a V2 Protocol command has been received */
if (!(Endpoint_IsOUTReceived())) if (Endpoint_IsOUTReceived())
return; {
/* Pass off processing of the V2 Protocol command to the V2 Protocol handler */
/* Pass off processing of the V2 Protocol command to the V2 Protocol handler */ V2Protocol_ProcessCommand();
V2Protocol_ProcessCommand(); }
} }
...@@ -301,11 +301,9 @@ static void V2Protocol_Command_ProgramMemory(uint8_t V2Command) ...@@ -301,11 +301,9 @@ static void V2Protocol_Command_ProgramMemory(uint8_t V2Command)
uint8_t ProgrammingCommands[3]; uint8_t ProgrammingCommands[3];
uint8_t PollValue1; uint8_t PollValue1;
uint8_t PollValue2; uint8_t PollValue2;
uint8_t ProgData[256]; uint8_t ProgData[256]; // Note, the Jungo driver has a very short ACK timeout period, need to buffer the
} Write_Memory_Params; } Write_Memory_Params; // whole page and ACK the packet as fast as possible to prevent it from aborting
uint8_t* NextWriteByte = Write_Memory_Params.ProgData;
Endpoint_Read_Stream_LE(&Write_Memory_Params, sizeof(Write_Memory_Params) - sizeof(Write_Memory_Params.ProgData)); Endpoint_Read_Stream_LE(&Write_Memory_Params, sizeof(Write_Memory_Params) - sizeof(Write_Memory_Params.ProgData));
Write_Memory_Params.BytesToWrite = SwapEndian_16(Write_Memory_Params.BytesToWrite); Write_Memory_Params.BytesToWrite = SwapEndian_16(Write_Memory_Params.BytesToWrite);
...@@ -329,6 +327,8 @@ static void V2Protocol_Command_ProgramMemory(uint8_t V2Command) ...@@ -329,6 +327,8 @@ static void V2Protocol_Command_ProgramMemory(uint8_t V2Command)
uint16_t PollAddress = 0; uint16_t PollAddress = 0;
uint8_t PollValue = (V2Command == CMD_PROGRAM_FLASH_ISP) ? Write_Memory_Params.PollValue1 : uint8_t PollValue = (V2Command == CMD_PROGRAM_FLASH_ISP) ? Write_Memory_Params.PollValue1 :
Write_Memory_Params.PollValue2; Write_Memory_Params.PollValue2;
uint8_t* NextWriteByte = Write_Memory_Params.ProgData;
if (Write_Memory_Params.ProgrammingMode & PROG_MODE_PAGED_WRITES_MASK) if (Write_Memory_Params.ProgrammingMode & PROG_MODE_PAGED_WRITES_MASK)
{ {
uint16_t StartAddress = (CurrentAddress & 0xFFFF); uint16_t StartAddress = (CurrentAddress & 0xFFFF);
......
...@@ -132,7 +132,7 @@ uint8_t V2Params_GetParameterValue(uint8_t ParamID) ...@@ -132,7 +132,7 @@ uint8_t V2Params_GetParameterValue(uint8_t ParamID)
{ {
ParameterItem_t* ParamInfo = V2Params_GetParamFromTable(ParamID); ParameterItem_t* ParamInfo = V2Params_GetParamFromTable(ParamID);
if (ParamInfo == NULL) if ((ParamInfo == NULL) || !(ParamInfo->ParamPrivellages & PARAM_PRIV_READ))
return 0; return 0;
return ParamInfo->ParamValue; return ParamInfo->ParamValue;
...@@ -149,7 +149,7 @@ void V2Params_SetParameterValue(uint8_t ParamID, uint8_t Value) ...@@ -149,7 +149,7 @@ void V2Params_SetParameterValue(uint8_t ParamID, uint8_t Value)
{ {
ParameterItem_t* ParamInfo = V2Params_GetParamFromTable(ParamID); ParameterItem_t* ParamInfo = V2Params_GetParamFromTable(ParamID);
if (ParamInfo == NULL) if ((ParamInfo == NULL) || !(ParamInfo->ParamPrivellages & PARAM_PRIV_WRITE))
return; return;
ParamInfo->ParamValue = Value; ParamInfo->ParamValue = Value;
......
...@@ -85,7 +85,7 @@ void V2Protocol_ChangeTargetResetLine(bool ResetTarget) ...@@ -85,7 +85,7 @@ void V2Protocol_ChangeTargetResetLine(bool ResetTarget)
{ {
if (ResetTarget) if (ResetTarget)
{ {
RESET_LINE_DDR |= RESET_LINE_MASK; RESET_LINE_DDR |= RESET_LINE_MASK;
if (!(V2Params_GetParameterValue(PARAM_RESET_POLARITY))) if (!(V2Params_GetParameterValue(PARAM_RESET_POLARITY)))
RESET_LINE_PORT |= RESET_LINE_MASK; RESET_LINE_PORT |= RESET_LINE_MASK;
...@@ -155,17 +155,14 @@ uint8_t V2Protocol_WaitWhileTargetBusy(void) ...@@ -155,17 +155,14 @@ uint8_t V2Protocol_WaitWhileTargetBusy(void)
{ {
TCNT0 = 0; TCNT0 = 0;
bool DeviceBusy;
do do
{ {
SPI_SendByte(0xF0); SPI_SendByte(0xF0);
SPI_SendByte(0x00); SPI_SendByte(0x00);
SPI_SendByte(0x00); SPI_SendByte(0x00);
DeviceBusy = (SPI_ReceiveByte() & 0x01);
} }
while (DeviceBusy && (TCNT0 < TARGET_BUSY_TIMEOUT_MS)); while ((SPI_ReceiveByte() & 0x01) && (TCNT0 < TARGET_BUSY_TIMEOUT_MS));
if (TCNT0 >= TARGET_BUSY_TIMEOUT_MS) if (TCNT0 >= TARGET_BUSY_TIMEOUT_MS)
return STATUS_RDY_BSY_TOUT; return STATUS_RDY_BSY_TOUT;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment