@ -37,16 +37,10 @@
# if defined(ENABLE_ISP_PROTOCOL) || defined(__DOXYGEN__)
/** Converts the given AVR Studio SCK duration parameter (set by a SET PARAM command from the host) to the nearest
* possible SPI clock prescaler mask for passing to the SPI_Init ( ) routine .
*
* \ return Nearest SPI prescaler mask for the given SCK frequency
*/
uint8_t ISPTarget_GetSPIPrescalerMask ( void )
/** List of SPI prescaler masks for possible AVRStudio ISP programming speeds. */
static uint8_t SPIMaskFromSCKDuration [ ] PROGMEM =
{
static const uint8_t SPIMaskFromSCKDuration [ ] =
{
# if (F_CPU == 8000000)
# if (F_CPU == 8000000)
SPI_SPEED_FCPU_DIV_2 , // AVRStudio = 8MHz SPI, Actual = 4MHz SPI
SPI_SPEED_FCPU_DIV_2 , // AVRStudio = 4MHz SPI, Actual = 4MHz SPI
SPI_SPEED_FCPU_DIV_4 , // AVRStudio = 2MHz SPI, Actual = 2MHz SPI
@ -54,7 +48,7 @@ uint8_t ISPTarget_GetSPIPrescalerMask(void)
SPI_SPEED_FCPU_DIV_16 , // AVRStudio = 500KHz SPI, Actual = 500KHz SPI
SPI_SPEED_FCPU_DIV_32 , // AVRStudio = 250KHz SPI, Actual = 250KHz SPI
SPI_SPEED_FCPU_DIV_64 , // AVRStudio = 125KHz SPI, Actual = 125KHz SPI
# elif (F_CPU == 16000000)
# elif (F_CPU == 16000000)
SPI_SPEED_FCPU_DIV_2 , // AVRStudio = 8MHz SPI, Actual = 8MHz SPI
SPI_SPEED_FCPU_DIV_4 , // AVRStudio = 4MHz SPI, Actual = 4MHz SPI
SPI_SPEED_FCPU_DIV_8 , // AVRStudio = 2MHz SPI, Actual = 2MHz SPI
@ -62,17 +56,24 @@ uint8_t ISPTarget_GetSPIPrescalerMask(void)
SPI_SPEED_FCPU_DIV_32 , // AVRStudio = 500KHz SPI, Actual = 500KHz SPI
SPI_SPEED_FCPU_DIV_64 , // AVRStudio = 250KHz SPI, Actual = 250KHz SPI
SPI_SPEED_FCPU_DIV_128 // AVRStudio = 125KHz SPI, Actual = 125KHz SPI
# else
# else
# error No SPI prescaler masks for chosen F_CPU speed.
# endif
} ;
# endif
} ;
/** Converts the given AVR Studio SCK duration parameter (set by a SET PARAM command from the host) to the nearest
* possible SPI clock prescaler mask for passing to the SPI_Init ( ) routine .
*
* \ return Nearest SPI prescaler mask for the given SCK frequency
*/
uint8_t ISPTarget_GetSPIPrescalerMask ( void )
{
uint8_t SCKDuration = V2Params_GetParameterValue ( PARAM_SCK_DURATION ) ;
if ( SCKDuration > = sizeof ( SPIMaskFromSCKDuration ) )
SCKDuration = ( sizeof ( SPIMaskFromSCKDuration ) - 1 ) ;
return SPIMaskFromSCKDuration [ SCKDuration ] ;
return pgm_read_byte ( & SPIMaskFromSCKDuration [ SCKDuration ] ) ;
}
/** Asserts or deasserts the target's reset line, using the correct polarity as set by the host using a SET PARAM command.