Updated Benito project -- added hardware interrupt and software buffering for serial data reception to prevent missed characters, condensed pulse generation counters into a struct for clarity.
Added check to CDC_Device_BytesReceived() to ensure 0 is returned when device is not enumerated to a host. Move AVRISP project's V2Protocol_DelayMS() function to be static inline, as it is now very minimal. Added extra project doxygen documentation.
This commit is contained in:
		
							parent
							
								
									f070902bdb
								
							
						
					
					
						commit
						6d1adf7339
					
				
					 14 changed files with 318 additions and 53 deletions
				
			
		| 
						 | 
				
			
			@ -38,13 +38,15 @@
 | 
			
		|||
 | 
			
		||||
	/* Includes: */
 | 
			
		||||
		#include <LUFA/Drivers/USB/USB.h>
 | 
			
		||||
		#include <LUFA/Drivers/Peripheral/SPI.h>
 | 
			
		||||
		
 | 
			
		||||
		#include "../Descriptors.h"
 | 
			
		||||
		#include "V2ProtocolConstants.h"
 | 
			
		||||
		#include "V2ProtocolParams.h"
 | 
			
		||||
		#include "V2ProtocolTarget.h"
 | 
			
		||||
 | 
			
		||||
	/* Macros: */
 | 
			
		||||
	/* Macros: */
 | 
			
		||||
		/** Programmer ID string, returned to the host during the CMD_SIGN_ON command processing */
 | 
			
		||||
		#define PROGRAMMER_ID                   "AVRISP_MK2"
 | 
			
		||||
		
 | 
			
		||||
		#define READ_WRITE_HIGH_BYTE_MASK       (1 << 3)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -67,7 +67,7 @@ static ParameterItem_t ParameterTable[] =
 | 
			
		|||
		  .ParamPrivellages = PARAM_PRIV_READ                    },
 | 
			
		||||
 | 
			
		||||
		{ .ParamID          = PARAM_SCK_DURATION,
 | 
			
		||||
		  .ParamValue       = 0x06,
 | 
			
		||||
		  .ParamValue       = (TOTAL_PROGRAMMING_SPEEDS - 1),
 | 
			
		||||
		  .ParamPrivellages = PARAM_PRIV_READ | PARAM_PRIV_WRITE },
 | 
			
		||||
 | 
			
		||||
		{ .ParamID          = PARAM_RESET_POLARITY,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -46,15 +46,19 @@
 | 
			
		|||
		#include "V2ProtocolConstants.h"
 | 
			
		||||
 | 
			
		||||
	/* Macros: */
 | 
			
		||||
		/* Parameter privellage mask to allow the host PC to read the parameter's value */
 | 
			
		||||
		#define PARAM_PRIV_READ   (1 << 0)
 | 
			
		||||
 | 
			
		||||
		/* Parameter privellage mask to allow the host PC to change the parameter's value */
 | 
			
		||||
		#define PARAM_PRIV_WRITE  (1 << 1)
 | 
			
		||||
 | 
			
		||||
	/* Type Defines: */
 | 
			
		||||
		/** Type define for a parameter table entry indicating a PC readable or writable device parameter. */
 | 
			
		||||
		typedef struct
 | 
			
		||||
		{
 | 
			
		||||
			const uint8_t ParamID;
 | 
			
		||||
			uint8_t ParamValue;
 | 
			
		||||
			uint8_t ParamPrivellages;
 | 
			
		||||
			const uint8_t ParamID; /**< Parameter ID number to uniquely identify the parameter within the device */
 | 
			
		||||
			uint8_t ParamValue; /**< Current parameter's value within the device */
 | 
			
		||||
			uint8_t ParamPrivellages;  /**< Parameter privellages to allow the host to read or write the parameter's value */
 | 
			
		||||
		} ParameterItem_t;
 | 
			
		||||
 | 
			
		||||
	/* Function Prototypes: */
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -40,7 +40,7 @@ uint32_t CurrentAddress;
 | 
			
		|||
 | 
			
		||||
uint8_t V2Protocol_GetSPIPrescalerMask(void)
 | 
			
		||||
{
 | 
			
		||||
	static const uint8_t SPIMaskFromSCKDuration[] =
 | 
			
		||||
	static const uint8_t SPIMaskFromSCKDuration[TOTAL_PROGRAMMING_SPEEDS] =
 | 
			
		||||
	{
 | 
			
		||||
		#if (F_CPU == 8000000)
 | 
			
		||||
		SPI_SPEED_FCPU_DIV_2,
 | 
			
		||||
| 
						 | 
				
			
			@ -76,12 +76,6 @@ void V2Protocol_ChangeTargetResetLine(bool ResetTarget)
 | 
			
		|||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void V2Protocol_DelayMS(uint8_t MS)
 | 
			
		||||
{
 | 
			
		||||
	TCNT0  = 0;
 | 
			
		||||
	while (TCNT0 < MS);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint8_t V2Protocol_WaitForProgComplete(uint8_t ProgrammingMode, uint16_t PollAddress, uint8_t PollValue,
 | 
			
		||||
                                       uint8_t DelayMS, uint8_t ReadMemCommand)
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			@ -96,7 +90,7 @@ uint8_t V2Protocol_WaitForProgComplete(uint8_t ProgrammingMode, uint16_t PollAdd
 | 
			
		|||
			break;
 | 
			
		||||
		case PROG_MODE_WORD_VALUE_MASK:
 | 
			
		||||
		case PROG_MODE_PAGED_VALUE_MASK:
 | 
			
		||||
			TCNT0  = 0;
 | 
			
		||||
			TCNT0 = 0;
 | 
			
		||||
 | 
			
		||||
			do
 | 
			
		||||
			{
 | 
			
		||||
| 
						 | 
				
			
			@ -121,7 +115,7 @@ uint8_t V2Protocol_WaitForProgComplete(uint8_t ProgrammingMode, uint16_t PollAdd
 | 
			
		|||
 | 
			
		||||
uint8_t V2Protocol_WaitWhileTargetBusy(void)
 | 
			
		||||
{
 | 
			
		||||
	TCNT0  = 0;
 | 
			
		||||
	TCNT0 = 0;
 | 
			
		||||
	
 | 
			
		||||
	do
 | 
			
		||||
	{
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -48,11 +48,22 @@
 | 
			
		|||
		#include "V2ProtocolParams.h"
 | 
			
		||||
 | 
			
		||||
	/* Macros: */
 | 
			
		||||
		/** Total number of allowable ISP programming speeds supported by the device */
 | 
			
		||||
		#define TOTAL_PROGRAMMING_SPEEDS  7
 | 
			
		||||
 | 
			
		||||
		/** Timeout in milliseconds of target busy-wait loops waiting for a command to complete */
 | 
			
		||||
		#define TARGET_BUSY_TIMEOUT_MS    150
 | 
			
		||||
	
 | 
			
		||||
		
 | 
			
		||||
	/* External Variables: */
 | 
			
		||||
		extern uint32_t CurrentAddress;
 | 
			
		||||
 | 
			
		||||
	/* Inline Functions: */
 | 
			
		||||
		static inline void V2Protocol_DelayMS(uint8_t MS)
 | 
			
		||||
		{
 | 
			
		||||
			TCNT0 = 0;
 | 
			
		||||
			while (TCNT0 < MS);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
	/* Function Prototypes: */
 | 
			
		||||
			uint8_t V2Protocol_GetSPIPrescalerMask(void);
 | 
			
		||||
			void    V2Protocol_ChangeTargetResetLine(bool ResetTarget);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue