~ubuntu-branches/ubuntu/edgy/avra/edgy

« back to all changes in this revision

Viewing changes to SOURCE/device.c

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Landschoff
  • Date: 2005-06-29 11:04:43 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20050629110443-4e8z9ddzpqllq5fq
Tags: 1.0.1-0.1
* NMU.
* New upstream release including new device types that I need...
* SOURCE/Makefile: Fix upstream version to 1.0.1.
* debian/rules (build,clean,install): Adjust for new Makefile and 
  sources location.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***********************************************************************
 
2
 *
 
3
 *  avra - Assembler for the Atmel AVR microcontroller series
 
4
 *
 
5
 *  Copyright (C) 1998-2004 Jon Anders Haugum, Tobias Weber
 
6
 *
 
7
 *  This program is free software; you can redistribute it and/or modify
 
8
 *  it under the terms of the GNU General Public License as published by
 
9
 *  the Free Software Foundation; either version 2 of the License, or
 
10
 *  (at your option) any later version.
 
11
 *
 
12
 *  This program is distributed in the hope that it will be useful,
 
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 *  GNU General Public License for more details.
 
16
 *
 
17
 *  You should have received a copy of the GNU General Public License
 
18
 *  along with this program; see the file COPYING.  If not, write to
 
19
 *  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
20
 *  Boston, MA 02111-1307, USA.
 
21
 *
 
22
 *
 
23
 *  Authors of avra can be reached at:
 
24
 *     email: jonah@omegav.ntnu.no, tobiw@suprafluid.com
 
25
 *     www: http://sourceforge.net/projects/avra
 
26
 */
 
27
 
 
28
/*
 
29
 * Added ATtiny26 to struct device device_list[].  
 
30
 * Updated FLASH memory size for other ATtiny parts. 
 
31
 * ATtiny10, 11, 12, 15 Flash s/b 512 words.
 
32
 * ATtiny 28, 22 Flash s/b 1024 words.
 
33
 * JEG 5-01-03 
 
34
 */
 
35
 
 
36
/*
 
37
 * Added ATtiny13 and ATtiny2313 to struct device device_list[].  
 
38
 * JEG 11-12-03 
 
39
 */
 
40
 
 
41
/*
 
42
 * Added ATmega48, ATmega88 and ATmega168 to struct device device_list[].  
 
43
 * JEG 04-16-04 
 
44
 */
 
45
 
 
46
#include <stdlib.h>
 
47
#include <string.h>
 
48
 
 
49
#include "misc.h"
 
50
#include "avra.h"
 
51
#include "device.h"
 
52
 
 
53
#define DEV_VAR    "__DEVICE__" // Device var name
 
54
#define FLASH_VAR  "__FLASH_SIZE__"     // Flash size var name
 
55
#define EEPROM_VAR "__EEPROM_SIZE__"    // EEPROM size var name
 
56
#define RAM_VAR    "__RAM_SIZE__"       // RAM size var name
 
57
#define DEV_PREFIX "__"         // Device name prefix
 
58
#define DEV_SUFFIX "__"         // Device name suffix
 
59
#define DEF_DEV_NAME "DEFAULT"  // Default device name (without prefix/suffix)
 
60
#define MAX_DEV_NAME 32         // Max device name length
 
61
 
 
62
// Name, Flash, RAM, EEPROM, flags
 
63
// Name,   Flash(words),    RAM, EEPROM, flags
 
64
struct device device_list[] =
 
65
{
 
66
  {       NULL, 4194304, 8388608, 65536, 0}, // Total instructions: 137
 
67
  {"AT90S1200",     512,       0,    64, DF_NO_MUL|DF_NO_JMP|DF_TINY1X|DF_NO_XREG|DF_NO_YREG|DF_NO_LPM|DF_NO_ELPM|DF_NO_SPM|DF_NO_ESPM|DF_NO_MOVW|DF_NO_BREAK|DF_NO_EICALL|DF_NO_EIJMP}, // 137 - MUL(6) - JMP(2) - TINY(10)
 
68
  {"ATtiny10",      512,       0,     0, DF_NO_MUL|DF_NO_JMP|DF_TINY1X|DF_NO_XREG|DF_NO_YREG|DF_NO_LPM_X|DF_NO_ELPM|DF_NO_SPM|DF_NO_ESPM|DF_NO_MOVW|DF_NO_BREAK|DF_NO_EICALL|DF_NO_EIJMP},
 
69
  {"ATtiny11",      512,       0,     0, DF_NO_MUL|DF_NO_JMP|DF_TINY1X|DF_NO_XREG|DF_NO_YREG|DF_NO_LPM_X|DF_NO_ELPM|DF_NO_SPM|DF_NO_ESPM|DF_NO_MOVW|DF_NO_BREAK|DF_NO_EICALL|DF_NO_EIJMP},
 
70
  {"ATtiny12",      512,       0,    64, DF_NO_MUL|DF_NO_JMP|DF_TINY1X|DF_NO_XREG|DF_NO_YREG|DF_NO_LPM_X|DF_NO_ELPM|DF_NO_SPM|DF_NO_ESPM|DF_NO_MOVW|DF_NO_BREAK|DF_NO_EICALL|DF_NO_EIJMP},
 
71
  {"ATtiny13",      512,      64,    64, DF_NO_MUL|DF_NO_JMP|DF_NO_ELPM|DF_NO_ESPM|DF_NO_EICALL|DF_NO_EIJMP},
 
72
  {"ATtiny15",      512,       0,    64, DF_NO_MUL|DF_NO_JMP|DF_TINY1X|DF_NO_XREG|DF_NO_YREG|DF_NO_LPM_X|DF_NO_ELPM|DF_NO_SPM|DF_NO_ESPM|DF_NO_MOVW|DF_NO_BREAK|DF_NO_EICALL|DF_NO_EIJMP},
 
73
  {"ATtiny28",     1024,       0,     0, DF_NO_MUL|DF_NO_JMP|DF_TINY1X|DF_NO_XREG|DF_NO_YREG|DF_NO_LPM_X|DF_NO_ELPM|DF_NO_SPM|DF_NO_ESPM|DF_NO_MOVW|DF_NO_BREAK|DF_NO_EICALL|DF_NO_EIJMP},
 
74
  {"ATtiny22",     1024,     128,   128, DF_NO_MUL|DF_NO_JMP|DF_NO_LPM_X|DF_NO_ELPM|DF_NO_SPM|DF_NO_ESPM|DF_NO_MOVW|DF_NO_BREAK|DF_NO_EICALL|DF_NO_EIJMP},
 
75
  {"ATtiny26",     1024,     128,   128, DF_NO_MUL|DF_NO_JMP|DF_NO_LPM_X|DF_NO_ELPM|DF_NO_SPM|DF_NO_ESPM|DF_NO_MOVW|DF_NO_BREAK|DF_NO_EICALL|DF_NO_EIJMP},
 
76
  {"ATtiny2313",   1024,     128,   128, DF_NO_MUL|DF_NO_JMP|DF_NO_ELPM|DF_NO_ESPM|DF_NO_EICALL|DF_NO_EIJMP},
 
77
  {"AT90S2313",    1024,     128,   128, DF_NO_MUL|DF_NO_JMP|DF_NO_LPM_X|DF_NO_ELPM|DF_NO_SPM|DF_NO_ESPM|DF_NO_MOVW|DF_NO_BREAK|DF_NO_EICALL|DF_NO_EIJMP},
 
78
  {"AT90S2323",    1024,     128,   128, DF_NO_MUL|DF_NO_JMP|DF_NO_LPM_X|DF_NO_ELPM|DF_NO_SPM|DF_NO_ESPM|DF_NO_MOVW|DF_NO_BREAK|DF_NO_EICALL|DF_NO_EIJMP},
 
79
  {"AT90S2333",    1024,     128,   128, DF_NO_MUL|DF_NO_JMP|DF_NO_LPM_X|DF_NO_ELPM|DF_NO_SPM|DF_NO_ESPM|DF_NO_MOVW|DF_NO_BREAK|DF_NO_EICALL|DF_NO_EIJMP},
 
80
  {"AT90S2343",    1024,     128,   128, DF_NO_MUL|DF_NO_JMP|DF_NO_LPM_X|DF_NO_ELPM|DF_NO_SPM|DF_NO_ESPM|DF_NO_MOVW|DF_NO_BREAK|DF_NO_EICALL|DF_NO_EIJMP},
 
81
  {"AT90S4414",    2048,     256,   256, DF_NO_MUL|DF_NO_JMP|DF_NO_LPM_X|DF_NO_ELPM|DF_NO_SPM|DF_NO_ESPM|DF_NO_MOVW|DF_NO_BREAK|DF_NO_EICALL|DF_NO_EIJMP},
 
82
  {"AT90S4433",    2048,     128,   256, DF_NO_MUL|DF_NO_JMP|DF_NO_LPM_X|DF_NO_ELPM|DF_NO_SPM|DF_NO_ESPM|DF_NO_MOVW|DF_NO_BREAK|DF_NO_EICALL|DF_NO_EIJMP},
 
83
  {"AT90S4434",    2048,     256,   256, DF_NO_MUL|DF_NO_JMP|DF_NO_LPM_X|DF_NO_ELPM|DF_NO_SPM|DF_NO_ESPM|DF_NO_MOVW|DF_NO_BREAK|DF_NO_EICALL|DF_NO_EIJMP},
 
84
  {"AT90S8515",    4096,     512,   512, DF_NO_MUL|DF_NO_JMP|DF_NO_LPM_X|DF_NO_ELPM|DF_NO_SPM|DF_NO_ESPM|DF_NO_MOVW|DF_NO_BREAK|DF_NO_EICALL|DF_NO_EIJMP}, // 137 - MUL(6) - JMP(2) - LPM_X(2) - ELPM(3) - SPM - ESPM - MOVW - BREAK - EICALL - EIJMP = 118
 
85
  {"AT90C8534",    4096,     256,   512, DF_NO_MUL|DF_NO_JMP|DF_NO_LPM_X|DF_NO_ELPM|DF_NO_SPM|DF_NO_ESPM|DF_NO_MOVW|DF_NO_BREAK|DF_NO_EICALL|DF_NO_EIJMP},
 
86
  {"AT90S8535",    4096,     512,   512, DF_NO_MUL|DF_NO_JMP|DF_NO_LPM_X|DF_NO_ELPM|DF_NO_SPM|DF_NO_ESPM|DF_NO_MOVW|DF_NO_BREAK|DF_NO_EICALL|DF_NO_EIJMP},
 
87
  {"ATmega8",      4096,    1024,   512, DF_NO_EICALL|DF_NO_EIJMP|DF_NO_ELPM|DF_NO_ESPM},
 
88
  {"ATmega161",    8192,    1024,   512, DF_NO_EICALL|DF_NO_EIJMP|DF_NO_ELPM|DF_NO_ESPM},
 
89
  {"ATmega162",    8192,    1024,   512, DF_NO_EICALL|DF_NO_EIJMP|DF_NO_ELPM|DF_NO_ESPM},
 
90
  {"ATmega163",    8192,    1024,   512, DF_NO_EICALL|DF_NO_EIJMP|DF_NO_ELPM|DF_NO_ESPM},
 
91
  {"ATmega16",     8192,    1024,   512, DF_NO_EICALL|DF_NO_EIJMP|DF_NO_ELPM|DF_NO_ESPM},
 
92
  {"ATmega323",   16384,    2048,  1024, DF_NO_EICALL|DF_NO_EIJMP|DF_NO_ELPM|DF_NO_ESPM}, // 137 - EICALL - EIJMP - ELPM(3) - ESPM = 131 (Data sheet says 130 but it's wrong)
 
93
  {"ATmega32",    16384,    2048,  1024, DF_NO_EICALL|DF_NO_EIJMP|DF_NO_ELPM|DF_NO_ESPM},
 
94
  {"ATmega603",   32768,    4096,  2048, DF_NO_EICALL|DF_NO_EIJMP|DF_NO_MUL|DF_NO_MOVW|DF_NO_LPM_X|DF_NO_ELPM|DF_NO_SPM|DF_NO_ESPM|DF_NO_BREAK},
 
95
  {"ATmega103",   65536,    4096,  4096, DF_NO_EICALL|DF_NO_EIJMP|DF_NO_MUL|DF_NO_MOVW|DF_NO_LPM_X|DF_NO_ELPM_X|DF_NO_SPM|DF_NO_ESPM|DF_NO_BREAK}, // 137 - EICALL - EIJMP - MUL(6) - MOVW - LPM_X(2) - ELPM_X(2) - SPM - ESPM - BREAK = 121
 
96
  {"ATmega104",   65536,    4096,  4096, DF_NO_EICALL|DF_NO_EIJMP|DF_NO_ESPM}, // Old name for mega128
 
97
  {"ATmega128",   65536,    4096,  4096, DF_NO_EICALL|DF_NO_EIJMP|DF_NO_ESPM}, // 137 - EICALL - EIJMP - ESPM = 134 (Data sheet says 133 but it's wrong)
 
98
  {"AT94K",        8192,   16384,     0, DF_NO_EICALL|DF_NO_EIJMP|DF_NO_ELPM|DF_NO_SPM|DF_NO_ESPM|DF_NO_BREAK}, // 137 - EICALL - EIJMP - ELPM(3) - SPM - ESPM - BREAK = 129
 
99
  {"ATmega48",     2048,     512,   256, DF_NO_EICALL|DF_NO_EIJMP|DF_NO_ELPM|DF_NO_ESPM},
 
100
  {"ATmega88",     4096,    1024,   512, DF_NO_EICALL|DF_NO_EIJMP|DF_NO_ELPM|DF_NO_ESPM},
 
101
  {"ATmega168",    8192,    1024,   512, DF_NO_EICALL|DF_NO_EIJMP|DF_NO_ELPM|DF_NO_ESPM},
 
102
  {NULL, 0, 0, 0, 0}
 
103
};
 
104
 
 
105
static int LastDevice=0;
 
106
 
 
107
static int def_var(struct prog_info *pi, char *name, int value) 
 
108
{
 
109
        struct label *label;
 
110
 
 
111
        for(label = pi->first_variable; label; label = label->next)
 
112
                if(!nocase_strcmp(label->name, name)) {
 
113
                        label->value = value;
 
114
                        return(True);
 
115
                }
 
116
        label = malloc(sizeof(struct label));
 
117
        if(!label) {
 
118
                print_msg(pi, MSGTYPE_OUT_OF_MEM, NULL);
 
119
                return(False);
 
120
        }
 
121
        label->next = NULL;
 
122
        if(pi->last_variable)
 
123
                pi->last_variable->next = label;
 
124
        else
 
125
                pi->first_variable = label;
 
126
        pi->last_variable = label;
 
127
        label->name = malloc(strlen(name) + 1);
 
128
        if(!label->name) {
 
129
                print_msg(pi, MSGTYPE_OUT_OF_MEM, NULL);
 
130
                return(False);
 
131
        }
 
132
        strcpy(label->name, name);
 
133
        label->value = value;
 
134
        return(True);
 
135
}
 
136
 
 
137
/*********************************************/
 
138
/* Define vars for device in LastDevice   */
 
139
/*********************************************/
 
140
 
 
141
static void def_dev(struct prog_info *pi)
 
142
{
 
143
   def_var(pi,DEV_VAR,LastDevice);
 
144
   def_var(pi,FLASH_VAR,device_list[LastDevice].flash_size);
 
145
   def_var(pi,EEPROM_VAR,device_list[LastDevice].eeprom_size);
 
146
   def_var(pi,RAM_VAR,device_list[LastDevice].ram_size);
 
147
}
 
148
 
 
149
struct device *get_device(struct prog_info *pi, char *name)
 
150
{
 
151
        int i = 1;
 
152
 
 
153
    LastDevice = 0;
 
154
        if(name == NULL) {
 
155
        def_dev(pi);
 
156
            return(&device_list[0]);
 
157
        }
 
158
        while(device_list[i].name) {
 
159
                if(!nocase_strcmp(name, device_list[i].name)) {
 
160
                        LastDevice=i;
 
161
            def_dev(pi);
 
162
                        return(&device_list[i]);
 
163
                }
 
164
                i++;
 
165
        }
 
166
        def_dev(pi);
 
167
        return(NULL);
 
168
}
 
169
 
 
170
static int def_const(struct prog_info *pi, const char *name, int value) 
 
171
{
 
172
        struct label *label;
 
173
 
 
174
        label = malloc(sizeof(struct label));
 
175
        if(!label) {
 
176
                print_msg(pi, MSGTYPE_OUT_OF_MEM, NULL);
 
177
                return(False);
 
178
        }
 
179
        label->next = NULL;
 
180
        if(pi->last_constant)
 
181
                pi->last_constant->next = label;
 
182
        else
 
183
                pi->first_constant = label;
 
184
        pi->last_constant = label;
 
185
        label->name = malloc(strlen(name) + 1);
 
186
        if(!label->name) {
 
187
                print_msg(pi, MSGTYPE_OUT_OF_MEM, NULL);
 
188
                return(False);
 
189
        }
 
190
        strcpy(label->name, name);
 
191
        label->value = value;
 
192
        return(True);
 
193
}
 
194
 
 
195
// Pre-define devices
 
196
void predef_dev(struct prog_info *pi) 
 
197
{
 
198
        int i;
 
199
        char temp[MAX_DEV_NAME+1];
 
200
 
 
201
 
 
202
        def_dev(pi);
 
203
        for (i=0;(!i)||(device_list[i].name);i++) {
 
204
                strncpy(temp,DEV_PREFIX,MAX_DEV_NAME);
 
205
                if (!i) strncat(temp,DEF_DEV_NAME,MAX_DEV_NAME);
 
206
                else strncat(temp,device_list[i].name,MAX_DEV_NAME);
 
207
                strncat(temp,DEV_SUFFIX,MAX_DEV_NAME);
 
208
                def_const(pi,temp,i);
 
209
        }
 
210
}
 
211
 
 
212
void list_devices()
 
213
{
 
214
  int i = 1;
 
215
  printf("Device name | Flash size | RAM size | EEPROM size |  Supported\n"
 
216
         "            |  (words)   | (bytes)  |   (bytes)   | instructions\n"
 
217
         "------------+------------+----------+-------------+--------------\n"
 
218
         " (default)  |   %7d  |  %7d |    %5d    |     %3d\n",
 
219
         device_list[0].flash_size, device_list[0].ram_size, device_list[0].eeprom_size,
 
220
         count_supported_instructions(device_list[0].flag));
 
221
  while(device_list[i].name) {
 
222
    printf(" %-10s |   %7d  |  %7d |    %5d    |     %3d\n", device_list[i].name,
 
223
           device_list[i].flash_size, device_list[i].ram_size,
 
224
           device_list[i].eeprom_size, count_supported_instructions(device_list[i].flag));
 
225
    i++;
 
226
  }
 
227
}
 
228
 
 
229
/* end of device.c */
 
230