Skip to content

Commit

Permalink
Helper command to check AVR fuse parsing
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.code.sf.net/p/xc3sprog/code/trunk@385 5e3be8be-922f-45f9-ad52-57b51d30232e
  • Loading branch information
u_bonnes committed Oct 1, 2009
1 parent 528f75c commit a5ec759
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ add_executable(debug debug.cpp iobase.cpp ioparport.cpp iodebug.cpp)
add_executable(bitparse bitfile.cpp bitparse.cpp)
add_executable(jedecparse jedecparse.cpp jedecfile.cpp)
add_executable(srecparse srecparse.cpp srecfile.cpp)
add_executable(avrfuseparse avrfuseparse.cpp avrfusefile.cpp)

ADD_CUSTOM_COMMAND(OUTPUT config.h
COMMAND ${CMAKE_COMMAND} -DDEVLIST_DIR=${CMAKE_SOURCE_DIR} -P ${CMAKE_SOURCE_DIR}/devlist.cmk
Expand Down
70 changes: 70 additions & 0 deletions avrfusefile.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/* AVR Fuse file parser
Copyright (C) Uwe Bonnes 2009 [email protected]
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Modifyied from fuse
* Copyright (C) <2001> <AJ Erasmus>
* [email protected]
*/
#ifndef AVRFUSEFILE_H
#define AVRFUSEFILE_H
#include <stdio.h>

typedef struct
{
/* |128|32|16|162|CAN128*/
unsigned M103C:1; /* ATMega103 Compatibility Mode | x | | | | */
unsigned M161C:1; /* ATMeag161 Compatibility Mode | | | | x| */
unsigned WDTON:1; /* Watchdog Always on | x | | | x| x */
unsigned OCDEN:1; /* Enable On Chip Debug | x | x| x| x| x */
unsigned JTAGEN:1; /* JTAG Enable | x | x| x| x| x */
unsigned SPIEN:1; /* Serial Programming Enable | x | x| x| x| x */
unsigned CKOPT:1; /* Oscillator options | x | x| x| x| X */
unsigned EESAVE:1; /* Preserve EEPROM with Erase | x | x| x| x| x */
unsigned BOOTSIZE:2; /* Depends on Device | x | x| x| x| x */
unsigned BOOTRST:1; /* Enable Booting from Bootblock| x | x| x| x| x */
unsigned BODLEVEL:3; /* BOD Level | x | x| x| x| x */
unsigned BODEN:1; /* Brownout Detector Enable | x | x| x| x| */
unsigned SUT:2; /* Start Up Time | x | x| x| x| x */
unsigned CKSEL:4; /* Clock Select | x | x| x| x| x */
unsigned CKDIV8:1; /* Divide clock by 8 | | | | x| x */
unsigned CKOUT:1; /* Clock Output | | | | x| x */
unsigned TA0SEL:1; /* (Reserved for factory tests) | | | | | x */
unsigned LB:2; /* Lock Bits */
unsigned BLB0:2;
unsigned BLB1:2;
}FUSE_BITS;


class AvrFuseFile
{
private:
int index; /* What device*/
FUSE_BITS gFuseBitsAll;
int Tokenize(unsigned char *buffer);
int ParseAvrFuseFile(FILE *fp);
char devicename[256];

public:
AvrFuseFile(int deviceindex =0);
int WriteAvrFuseFile(char * fname);
int ReadAvrFuseFile(char * fname);
int EncodeATMegaFuseBits(void);
void DisplayATMegaFuseData(void);
void DisplayATMegaStartUpTime(void);
};
#endif
42 changes: 42 additions & 0 deletions avrfuseparse.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* AVR .fus file parser
Copyright (C) 2009 Uwe Bonnes [email protected]
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/



#include "avrfusefile.h"
#include "io_exception.h"
#include "javr.h"
int main(int argc, char**args)
{
if(argc < 2)
{
fprintf(stderr,"Usage: %s infile.fus outfile.fus\n",args[0]);
}
else
{
{
AvrFuseFile file(UNKNOWN_DEVICE);
if (file.ReadAvrFuseFile(args[1])<0)
fprintf(stderr, "no valid file given\n");
file.DisplayATMegaFuseData();
file.WriteAvrFuseFile(args[2]);
}
}
}

0 comments on commit a5ec759

Please sign in to comment.