From a21c122435b22457399624a60dbca442d0c3588e Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Sat, 25 Apr 2009 13:24:58 +0200 Subject: * digital/avr/modules/isp: - added user callbacks. - removed incomplete watchdog support. --- digital/avr/modules/isp/avrconfig.h | 18 +++++++++++++++- digital/avr/modules/isp/isp.c | 36 +++++++++++++++++++++++++++++++- digital/avr/modules/isp/isp.h | 12 +++++++++++ digital/avr/modules/isp/test/avrconfig.h | 23 +++++++++++++++++++- digital/avr/modules/isp/test/test_isp.c | 26 +++++++++++++++++++++++ 5 files changed, 112 insertions(+), 3 deletions(-) diff --git a/digital/avr/modules/isp/avrconfig.h b/digital/avr/modules/isp/avrconfig.h index daabef56..a3aedf85 100644 --- a/digital/avr/modules/isp/avrconfig.h +++ b/digital/avr/modules/isp/avrconfig.h @@ -32,7 +32,7 @@ #define AC_ISP_FRAME_SEND_CHAR uart0_putc /** Should be implemented by the user (isp_proto) to accept a frame. */ #define AC_ISP_FRAME_ACCEPT_FRAME isp_proto_accept -/** Should be implemeted by the user to send a frame. */ +/** Should be implemented by the user to send a frame. */ #define AC_ISP_PROTO_SEND isp_frame_send_frame /** Programmer signature. */ #define AC_ISP_PROTO_SIGNATURE "APBisp_2" @@ -42,5 +42,21 @@ #define AC_ISP_PROTO_HW_VERSION 0x02 /** Programmer software version. */ #define AC_ISP_PROTO_SW_VERSION 0x0204 +/** Should be implemented by the user to enable SPI programming: + * - set RESET and SCK to low, + * - power on, or if not possible, do a positive RESET pulse, + * - enable SPI. */ +#define AC_ISP_SPI_ENABLE isp_spi_enable +/** Should be implemented by the user to disable SPI programming: + * - disable SPI, + * - release RESET, + * - power off if desired. */ +#define AC_ISP_SPI_DISABLE isp_spi_disable +/** Should be implemented by the user to do a pulse on SCK. This is used to + * try to resynchronise. */ +#define AC_ISP_SPI_SCK_PULSE isp_spi_sck_pulse +/** Should be implemented by the user to send and receive a byte using the SPI + * bus. */ +#define AC_ISP_SPI_TX isp_spi_tx #endif /* avrconfig_h */ diff --git a/digital/avr/modules/isp/isp.c b/digital/avr/modules/isp/isp.c index dd688e75..07eabafa 100644 --- a/digital/avr/modules/isp/isp.c +++ b/digital/avr/modules/isp/isp.c @@ -26,6 +26,8 @@ * }}} */ #include "common.h" +#include "modules/utils/utils.h" + #include "isp.h" /** ISP context. */ @@ -78,6 +80,39 @@ struct isp_t /** Global context. */ static struct isp_t isp_global; +#define isp_spi_enable AC_ISP_SPI_ENABLE +#define isp_spi_disable AC_ISP_SPI_DISABLE +#define isp_spi_sck_pulse AC_ISP_SPI_SCK_PULSE +#define isp_spi_tx AC_ISP_SPI_TX + +/** Transmit a 16 bit data. */ +static void +isp_spi_tx_16 (uint16_t data) +{ + isp_spi_tx ((data >> 8) & 0xff); + isp_spi_tx ((data >> 0) & 0xff); +} + +/** Transmit a 32 bit data and return last byte received. This is used for + * RDY/BSY polling. */ +static uint8_t +isp_spi_tx_32 (uint32_t data) +{ + isp_spi_tx ((data >> 24) & 0xff); + isp_spi_tx ((data >> 16) & 0xff); + isp_spi_tx ((data >> 8) & 0xff); + return isp_spi_tx ((data >> 0) & 0xff); +} + +/** Wait for the specified delay, which can be a variable (it must be a + * constant for utils_delay_ms. */ +static void +isp_delay_ms (uint8_t delay_ms) +{ + while (delay_ms--) + utils_delay_ms (1); +} + /** Enable SPI port and enter programing mode. * - timeout_ms: command time-out, unused. * - stab_delay_ms: stabilisation delay once device is reseted and SPI @@ -114,7 +149,6 @@ isp_enter_progmode (uint8_t timeout_ms, uint8_t stab_delay_ms, /* Synchronisation loops. */ for (i = 0; i < synch_loops; i++) { - isp_wd_kick (); isp_delay_ms (cmd_exe_delay_ms); isp_spi_tx (cmd[0]); isp_delay_ms (byte_delay_ms); diff --git a/digital/avr/modules/isp/isp.h b/digital/avr/modules/isp/isp.h index 24142333..88b35c28 100644 --- a/digital/avr/modules/isp/isp.h +++ b/digital/avr/modules/isp/isp.h @@ -123,4 +123,16 @@ void isp_multi (uint8_t num_tx, uint8_t num_rx, uint8_t rx_start, const uint8_t *dout, uint8_t *din); +void +AC_ISP_SPI_ENABLE (void); + +void +AC_ISP_SPI_DISABLE (void); + +void +AC_ISP_SPI_SCK_PULSE (void); + +uint8_t +AC_ISP_SPI_TX (uint8_t data); + #endif /* isp_h */ diff --git a/digital/avr/modules/isp/test/avrconfig.h b/digital/avr/modules/isp/test/avrconfig.h index daabef56..3ddf50fa 100644 --- a/digital/avr/modules/isp/test/avrconfig.h +++ b/digital/avr/modules/isp/test/avrconfig.h @@ -25,6 +25,11 @@ * * }}} */ +/* utils */ +/** AVR Frequency : 1000000, 1843200, 2000000, 3686400, 4000000, 7372800, + * 8000000, 11059200, 14745600, 16000000, 18432000, 20000000. */ +#define AC_FREQ 8000000 + /* isp - ISP module. */ /** Size of isp_frame buffer. */ #define AC_ISP_FRAME_BUFFER_SIZE 275 @@ -32,7 +37,7 @@ #define AC_ISP_FRAME_SEND_CHAR uart0_putc /** Should be implemented by the user (isp_proto) to accept a frame. */ #define AC_ISP_FRAME_ACCEPT_FRAME isp_proto_accept -/** Should be implemeted by the user to send a frame. */ +/** Should be implemented by the user to send a frame. */ #define AC_ISP_PROTO_SEND isp_frame_send_frame /** Programmer signature. */ #define AC_ISP_PROTO_SIGNATURE "APBisp_2" @@ -42,5 +47,21 @@ #define AC_ISP_PROTO_HW_VERSION 0x02 /** Programmer software version. */ #define AC_ISP_PROTO_SW_VERSION 0x0204 +/** Should be implemented by the user to enable SPI programming: + * - set RESET and SCK to low, + * - power on, or if not possible, do a positive RESET pulse, + * - enable SPI. */ +#define AC_ISP_SPI_ENABLE isp_spi_enable +/** Should be implemented by the user to disable SPI programming: + * - disable SPI, + * - release RESET, + * - power off if desired. */ +#define AC_ISP_SPI_DISABLE isp_spi_disable +/** Should be implemented by the user to do a pulse on SCK. This is used to + * try to resynchronise. */ +#define AC_ISP_SPI_SCK_PULSE isp_spi_sck_pulse +/** Should be implemented by the user to send and receive a byte using the SPI + * bus. */ +#define AC_ISP_SPI_TX isp_spi_tx #endif /* avrconfig_h */ diff --git a/digital/avr/modules/isp/test/test_isp.c b/digital/avr/modules/isp/test/test_isp.c index ca0fd355..339019e7 100644 --- a/digital/avr/modules/isp/test/test_isp.c +++ b/digital/avr/modules/isp/test/test_isp.c @@ -33,3 +33,29 @@ main (void) return 0; } +void +AC_ISP_SPI_ENABLE (void) +{ +} + +void +AC_ISP_SPI_DISABLE (void) +{ +} + +void +AC_ISP_SPI_SCK_PULSE (void) +{ +} + +uint8_t +AC_ISP_SPI_TX (uint8_t data) +{ + return 0; +} + +void +AC_ISP_FRAME_SEND_CHAR (uint8_t data) +{ +} + -- cgit v1.2.3