Bo Qiang / Mbed 2 deprecated TestAVRISP

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers AVRISP.h Source File

AVRISP.h

00001 //****************************************************************************/
00002 // Description:
00003 //
00004 //  Program AVR chips with the AVR910 ISP (in-system programming) protocol,
00005 //  using an mbed.
00006 //
00007 // This is a wrapper for AVR_ISP_Programmer_v2
00008 //
00009 //****************************************************************************/
00010 
00011 #ifndef AVRISP_H
00012 #define AVRISP_H
00013 
00014 //****************************************************************************/
00015 // Includes
00016 //****************************************************************************/
00017 #include "mbed.h"
00018 
00019 //****************************************************************************/
00020 // Definations for: ATMEGA1284p
00021 //****************************************************************************/
00022 #define SIGNATURE_BYTE_1    0x1E
00023 #define SIGNATURE_BYTE_2    0x97
00024 #define SIGNATURE_BYTE_3    0x05
00025 #define PAGE_SIZE           128
00026 #define NUM_PAGE            512
00027 
00028 //****************************************************************************/
00029 // Definations for programming
00030 //****************************************************************************/
00031 #define LSB(I) ((I) & 0xFF)
00032 #define MSB(I) (((I) & 0xF00) >> 8)
00033 #define TARGET_CLK 1000000L
00034 #define MAX_PAGE_SIZE (PAGE_SIZE >> 1) //divide max page size by 2 to get number of words per page
00035 
00036 class AVRISP
00037 {
00038     public:
00039         AVRISP(PinName mosi, PinName miso, PinName sclk, PinName reset);
00040         bool EnableProgrammingMode();
00041         void LeaveProgrammingMode();
00042         int ReadChipSignatureByte1();
00043         int ReadChipSignatureByte2();
00044         int ReadChipSignatureByte3();
00045         void StillProgramming();
00046         void ChipErase();
00047         void WriteFuseLow(uint8_t fuseLow);
00048         int ReadFuseLow();
00049         void WriteFuseHigh(uint8_t fuseHigh);
00050         int ReadFuseHigh();
00051         void WriteFuseExtended(uint8_t fuseExtended);
00052         int ReadFuseExtended();
00053         void WriteLockByte(uint8_t lockByte);
00054         int ReadLockByte();
00055         void WriteProgramPage(uint16_t addr);
00056         void LoadProgramPage(uint16_t addr,uint8_t lowData,uint8_t highData);
00057         uint8_t ReadByte(FILE *file);
00058         void ReadProgramFlash(uint8_t addrMSB, uint8_t addrLSB);
00059         bool ProgramFlash(char *hexFileName);
00060 
00061     private:
00062         SPI*        spiPort;
00063         DigitalOut  *resetPin;
00064 };
00065 
00066 #endif