Subversion Repositories svnkaklik

Rev

Rev 410 | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
134 kaklik 1
#!/bin/sh 
2
prg="adude"
3
#
4
help()
5
{
6
	echo "prg_fusebit_uc -- read and write fuse bits of the atmega8"
7
	echo ""
8
	echo "Usage: prg_fusebit_uc [-hu] -r|-w Freq"
9
	echo ""
10
	echo "OPTIONS: -h this help"
11
	echo "         -r read fuse bytes"
12
	echo "         -u use uisp instead of avrdude"
13
	echo "            avrdude can automatically detect dapa or avrusb500."
14
	echo "            uisp can only be used with the parallel port dapa."
15
	echo "         -w write fuse bytes such that a given Freq is used"
16
	echo "            a frequency of 0 means external crystal. Possible"
17
	echo "            values are 0,1,2,4,8"
18
	echo ""
19
	echo "EXAMPLE: program the fuses to 4MHz internal"
20
	echo "         prg_fusebit_uc -w 4"
21
	echo ""
22
	echo "Warning: you can not undo the setting \"external crystal\" unless"
23
	echo "         you have a crystal that works."
24
	echo "This script can be easily adapted to different programmer types"
25
	exit 0
26
}
27
while [ -n "$1" ]; do
28
case $1 in
29
    -h) help;shift 1;;
30
    -u) prg="uisp";shift 1;;
31
    -r) opt_r="1";shift 1;;
32
    -w) opt_w="1";freq="$2";shift 2;;
33
    -*) echo "error: no such option $1. -h for help";exit 1;;
34
    *)  break;;
35
esac
36
done
37
 
38
if [ -z "$opt_r" -a  -z "$opt_w" ];then
39
	# one of those options is mandatory
40
	help
41
fi
42
 
43
hf=0xd9
44
if [ "$opt_w" = "1" ]; then
45
	case $freq in
46
	    0) lf=0xee;echo "Make sure you have a crystal otherwise you can not change this!";sleep 2;;
47
	    1) lf=0xe1;;
48
	    2) lf=0xe2;;
49
	    4) lf=0xe3;;
50
	    8) lf=0xe4;;
51
	    *) echo "error: no such frequency, -h for help";exit 1;;
52
	esac
53
fi
54
 
55
 
56
if [ "$prg" = "uisp" ]; then
57
	if [ "$opt_r" = "1" ];then
58
		set -x
59
		uisp -dlpt=/dev/parport0 -dprog=dapa --rd_fuses
60
		set +x
61
		echo "Explanation: Fuse Low Byte: 0xe1 (1MHz intern), 0xe3 (4MHz intern), "
62
		echo "             0xe4 (8MHz intern)"
63
		echo "             Fuse High Byte should be 0xd9"
64
		exit 0
65
	fi
66
	if [ "$opt_w" = "1" ]; then
67
		set -x
68
		uisp -dlpt=/dev/parport0 -dprog=dapa --wr_fuse_l=$lf
69
		uisp -dlpt=/dev/parport0 -dprog=dapa --wr_fuse_h=$hf
70
		set +x
71
		exit 0
72
	fi
73
 
74
fi
75
if [ "$prg" = "adude" ]; then
76
	if grep "Vendor=0403 ProdID=6001" /proc/bus/usb/devices > /dev/null ; then
77
		prg="avrusb500"
78
	else
79
		prg="dapa"
80
	fi
81
	if [ "$opt_r" = "1" ];then
82
		set -x
83
		avrdude -p m8 -c $prg -v -q
84
		set +x
85
		echo "Explanation: Fuse Low Byte: 0xe1 (1MHz intern), 0xe3 (4MHz intern), "
86
		echo "             0xe4 (8MHz intern)"
87
		echo "             Fuse High Byte should be 0xd9"
88
		exit 0
89
	fi
90
	if [ "$opt_w" = "1" ]; then
91
		set -x
92
		avrdude -p m8 -c $prg -u -v -U lfuse:w:$lf:m
93
		avrdude -p m8 -c $prg -u -v -U hfuse:w:$hf:m
94
		set +x
95
		exit 0
96
	fi
97
fi