TWIRP compile Error

Go To Last Post
25 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hey guys,
I am trying to compile the source for TWIRP in codevision. I am getting these errors.

LDS  r26,_outbufpr	//trying to load from r11 using LDS???
error (1194) invalid number

STS  _outbufpr,R26	//trying to load from r11 using LDS???
error (1210) invalid number

lds	r26,_inbufpw	//trying to load from r12 using LDS???
error (1272) invalid number

sts	_inbufpw,r26	//trying to load from r12 using LDS???
error (1286) invalid number

The above names are defined below:
//this from the include file
.DEF _outbufpw=R10
.DEF _outbufpr=R11
.DEF _inbufpw=R12
.DEF _inbufpr=R13

and here:
//this from the IRv4.c

register byte b, pw, n, bursts;
byte *outbufpw, *outbufpr;
byte *inbufpw, *inbufpr;
byte k1;
byte signature[6];

Obviously I am not the only one with this problem????
Anyone have a solution?

Much appreciated.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The source of LDS or the destination of STS should be a MEMORY LOCATION, not a register number so those .DEF's don't seem to make much sense

Cliff

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If the .defs are correct though, you need to use MOV instead of LDS and STS.

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks guys,
here are the uart routines. This is what the compiler gave me. It looks like the code stores the buffer pointer in ram @outbufpr when it is done sending data to the uart. It also does the same for the inbufpr, when done receiving.

;INTERRUPT SERVICE, UART TRANSMIT
;transmit data register empty condition.

_UART_TX_isr:
    	push r30			; save registers used herein
    	in   r30,SREG
    	push r30
    	push r26
   	tst	outbufcount		; buffer empty?
    	breq uartTX20                      
    	dec	outbufcount		; decrement count	
	LDS  r26,outbufpr		; buffer pointer in X reg
	LD   R30,X+         		; get from buffer (8 bit pointer)
	OUT  UDR,R30			; send to UART
	ldi	r30,LOW(_outbufend)	; address of end of buffer+1
	cp	r26,r30			; at end of buffer?
	brne uartTX10			; not at end of circular buffer
	ldi r26,LOW(_outbuf)		; wrap

uartTX10:
	STS  outbufpr,R26
	rjmp uartTX30			; return from interrupt
uartTX20:
	cbi  UCR,5			; disable TX interrupts
uartTX30:
	pop r26
	pop r30
	out SREG,r30
	pop r30
	reti
;**********************************************************
_UART_RX_isr:
    	push r30			; save registers used herein
    	in   r30,SREG
    	push r30
    	push r26
	ldi r26,INBUFSIZE		; size of input buffer storage area
	cp  r26,inbufcount		; compare to count of bytes alread in buffer 
	in  r30,UDR			; input from UART (flags unaffected)
	brne uartRX05			; branch if buffer is not full
	set				; buffer full error, set the T bit
	bld  errorflags,errorbitUARTrx 	; set flag bit
	rjmp uartRX20			; exit, discarding new byte
 
; store received byte in buffer   
uartRX05:
	inc	inbufcount 		; incrm count
	lds	r26,inbufpw
	st	X+,r30 			; store in buffer
	ldi	r30,LOW(_inbufend)
	cp	r26,r30			; wrap pointer if at end of buffer
	brne uartRX10
	ldi	r26,LOW(_inbuf)
uartRX10:
	sts	inbufpw,r26

uartRX20:				; restore registers, exit interrupt	
	pop r26
	pop r30
	out SREG,r30
	pop r30
	reti

_sendbyte:
	PUSH R15
	LDI  R30,LOW(8)
	CP   R3,R30
	BRSH PC+2
	RJMP _0x3
	SET
	BLD  R2,3
	ADIW R28,1
	RET
_0x3:
	cli			;disable interrupts while changing variable use in interrupt
	SBIC 0xA,5		;if interrupt handler has finished buffer
	RJMP _0x4

	LDI  R30,LOW(_outbuf)	;outbufpw = outbufpr = outbuf;  // initialize pointers
	MOV  R11,R30
	MOV  R10,R30

	LD   R30,Y		; send byte to UART, no need to buffer
	OUT  0xC,R30

	SBI  0xA,5		; enable uART TX interrupt
	RJMP _0x5
_0x4:
	INC  R3			;outbufcount
	MOV  R30,R10		;store in buffer for interrupt
	INC  R10
	LD   R26,Y
	STD  Z+0,R26
 		
	__POINTB1MN _outbuf,8	;if (outbufpw == &outbuf[UARTSENDBUFSIZE])
	CP   R30,R10
	BREQ PC+2
	RJMP _0x6
			
	LDI  R30,LOW(_outbuf)	;outbufpw = outbuf;
	MOV  R10,R30
_0x6:
_0x5:
	sei

	ADIW R28,1
	RET
;-----------------------------------------------------------------------
;RETURNS ONE BYTE FROM SERIAL PORT RECEIVE DATA, IF AVAILABLE

_receivebyte:
	PUSH R15

	ST   -Y,R16	; is buffer empty?
	TST  R4
	BREQ PC+2
	RJMP _0x7

	LDI  R16,LOW(0)	;no, change return value
	RJMP _0x8
_0x7:
	LDI  R16,LOW(1)
	cli		;disable interrupts while changing variable use in interrupt
;by = *inbufpr++
;get from buffer, storein param passed as pointer
	MOV  R30,R13
	INC  R13
	LD   R30,Z
	LDD  R26,Y+1
	ST   X,R30
;if (inbufpr == &inbuf[UARTRECEIVEBUFSIZE])	// wrap write pointer
	__POINTB1MN _inbuf,80
	CP   R30,R13
	BREQ PC+2
	RJMP _0x9
;inbufpr = inbuf;		
	LDI  R30,LOW(_inbuf)
	MOV  R13,R30
;--inbufcount
; one less byte is in the buffer	
_0x9:
	DEC  R4
	sei
_0x8:
	MOV  R30,R16
	LDD  R16,Y+0
	ADIW R28,2
	RET

I would really like to know if anyone else successfully compiled the program since it has been on this site for a long time now. I searched and there are no other posts mentioning errors.

I just don't understand what this means:

register byte b, pw, n, bursts;
byte *outbufpw, *outbufpr;
byte *inbufpw, *inbufpr;
byte k1;
byte signature[6]; 

outbufpw is obviously a data word.
same with inbufpw

Help is certainly appreciated!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

newbie123 wrote:

register byte b, pw, n, bursts;
byte *outbufpw, *outbufpr;
byte *inbufpw, *inbufpr;
byte k1;
byte signature[6]; 

outbufpw is obviously a data word.


No - outbufpw is a pointer to a data word (a byte)

If there's one thing to learn from this code snippet, it's the importance of commenting your variable definitions!
At a guess, I'd say it should be something like this:

// Pointers for the output buffer:
byte *outbufpw; // Write pointer - points to the location at which the next write
                // to the buffer will take place.
byte *outbufpr; // Read  pointer - points to the location at which the next read
                // from the buffer will take place.

// Pointers for the input buffer:
byte *inbufpw;  // Write pointer - points to the location at which the next write  
                // to the buffer will take place.
byte *inbufpr;  // Read  pointer - points to the location at which the next read
                // from the buffer will take place.

It looks like 2 circular buffers (aka "ring" buffers) - one for output, and one for input. This, of course, should also be fully described in the comments...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I don't understand a few things. You first say

Quote:

I am trying to compile the source for TWIRP in codevision.

Ok; CodeVisionAVR is a C compiler. Then you go on to show

Quote:

LDS r26,_outbufpr //trying to load from r11 using LDS???
error (1194) invalid number

which I don't quite know what it is. Does AVRASM2 now accept // as a comment delimiter? Gotta look that up.

But anyway, if the "include file" has those DEF lines, that sounds a bit strainge for a Codevision file to me.

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi folks. If I can help, please let me know (I wrote TWIRP).
The assembly language code in TWIRP is embedded in the codevision C file using the Codevision pragma for in-line assembly code.
For example the code below is the interrupt service routine for the UART transmitter.

Variables in RAM are declared in the C program. The asm code accesses these variables by prepending an underscore to the variable's name. This is a Codevision convention.

interrupt [UART_DRE] void UART_TX_isr(void) {
//---- Qssembly language interrupt handler for UART.
//     Optimizes speed and minimizes RAM used for register saves
#asm
    push r30			; save registers used herein
    in   r30,SREG
    push r30
    push r26
    tst	_outbufcount	; buffer empty?
    breq uartTX20                      
    dec	_outbufcount	; decrement count	
	LDS  r26,_outbufpr	; buffer pointer in X reg
	LD   R30,X+         ; get from buffer (8 bit pointer)
	OUT  UDR,R30		; send to UART
	ldi	r30,LOW(_outbufend)	; address of end of buffer+1
	cp	r26,r30			; at end of buffer?
	brne uartTX10		; not at end of circular buffer
	ldi r26,LOW(_outbuf)	; wrap
uartTX10:
	STS  _outbufpr,R26
	rjmp uartTX30		; return from interrupt
	
uartTX20:
	cbi  UCR,5			; disable TX interrupts
uartTX30:
	pop r26
    pop r30
    out SREG,r30
    pop r30
    reti
#endasm

I dug up the .prj (codevision project) file and compiled without error. Be sure to use that project file. It defines the memory model to be "Tiny" so that pointers are 8 not 16 bits for the '2313 chip's 256 bytes of RAM. And it defines that AVR as the target. If you are targeting a chip with more than 256 bytes, you'll need to change this. And change the asm code to load 16 bits into the X or Y register rather than 8. I did the 8 bit pointer thing to save code space.

Sorry the declrations aren't commented. The C and asm code is pretty well commented. A novice in C (as I once was) would not know that

byte *ppp
declares ppp to be a pointer to a byte.

In the Tiny memory model mode, pointers are 8 not 16 bits.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

stevech wrote:

Variables in RAM are declared in the C program. The asm code accesses these variables by prepending an underscore to the variable's name. This is a Codevision convention.
I dug up the .prj (codevision project) file and compiled without error. Be sure to use that project file.

Thanks for the response Steve, I am using the files direct from the zip file I downloaded here. All I am doing is double clicking on the prj file, when it opens in codevision, I save it and then click make.

The asm code I posted is what the compiler produces, (I am not good with C, that is why I posted that code)
I did however use the code exactly as it was in the project without modifications, and I still get those four errors pertaining to the buffer pointers.

I can compile other codevision projects that I downloaded no problem, maybe this is a problem with the newest codevision version?

Since I am not a C person,I did assemble the code using the asm output that the compiler produced. With a little bit of modification, I got it to assemble without any errors in avrstudio4. The 4 errors with the ram buffer pointers were still there. The only way I got it to work was this way:
(Please remember that I am not very experienced, and still in the learning process. Any criticism/advice/ideas, will be appreciated!)

.DSEG
.ORG 0x70
	
_ticksmsec:
	.BYTE 0x1
_signature:
	.BYTE 0x6
_outbuf:
	.BYTE 0x8
_outbufend:			; so the assembly code knows where this is

_inbuf:				; UART receive buffer
	.BYTE 0x50
_inbufend:
	.EQU INBUFSIZE = _inbufend - _inbuf
inbufpw:
	.byte 2
outbufpw:
	.byte 2
outbufpr:
	.byte 1
inbufpr:
	.byte 1

Please correct me if I did something wrong.

If you successfully produced a hex file can you post it or msg it to me? I want to make sure I am doing this correctly before I build the hardware. Comparing what I have to your hex file will allow me to verify that everything is ok before proceeding.
Thank you for the interesting code, and all the help!

Cheers!

Last Edited: Sun. Aug 20, 2006 - 12:21 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This is what codevision produces, these four errors.
When you double click on the error, codevision takes you to the error.
I pasted the lines below the error so you would see it easily.
Remember I am using CODEVISION running the prj file with the C source code, NOT avrstudio.

clicking on the assembler TAB I get this:

 
AVRASM: AVR macro assembler 2.1.2 (build 99 Nov  4 2005 09:35:05)
Copyright (C) 1995-2005 ATMEL Corporation

irv4.asm(1207): error: Invalid number
	LDS  r26,_outbufpr	; buffer pointer in X reg

irv4.asm(1223): error: Invalid number
	STS  _outbufpr,R26

irv4.asm(1285): error: Invalid number
	lds	r26,_inbufpw

irv4.asm(1299): error: Invalid number
	sts	_inbufpw,r26

Assembly failed, 4 errors.

clicking on the compiler TAB, I get this:

Chip: AT90S2313
Memory model: Tiny
Optimize for: Speed
(s)printf features: int, width
(s)scanf 

features: int, width
Promote char to int: No
char is unsigned: Yes
8 bit enums: Yes
Automatic 

register allocation: On

3414 line(s) compiled
No errors
No warnings

Bit variables area: 2h to 

2h
Bit variables size: 1 byte(s)

Data Stack area: 60h to 6Fh
Data Stack size: 16 byte(s)
Estimated Data Stack usage: 16 byte(s)

Global variables area: 70h to CEh
Global variables size: 

95 byte(s)

Hardware Stack area: CFh to DFh
Hardware Stack size: 17 byte(s)

Heap size: 0 

byte(s)

EEPROM usage: 0 byte(s) (0.0% of EEPROM)
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hmmm
Your listing seems to say that register R26 is not defined in the assembler. Odd. The R26-27 pair is called the X register. Indeed, R26 does exist for the AT90S2313. So it's something to do with you having a newer version, and the defs are screwed up somehow.

I looked at a listing on my PC and I see an older assembler.

AVRASM ver. 1.52  irv4.asm Sun Apr 10 20:56:22 2005


         ;CodeVisionAVR C Compiler V1.24.3b Evaluation
         ;(C) Copyright 1998-2004 Pavel Haiduc, HP InfoTech s.r.l.
         ;http://www.hpinfotech.com
         ;e-mail:office@hpinfotech.com
         
         ;Chip type           : AT90S2313
         ;Clock frequency     : 10.000000 MHz
         ;Memory model        : Tiny
         ;Optimize for        : Speed
         ;(s)printf features  : int, width
         ;(s)scanf features   : int, width
         ;External SRAM size  : 0
         ;Data Stack size     : 16 byte(s)
         ;Heap size           : 0 byte(s)
         ;Promote char to int : No
         ;char is unsigned    : Yes
         ;8 bit enums         : Yes
         ;Automatic register allocation : On

[/code]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The problem seemed to be that I did not declare the pointers used in the interrupt routine as volatile (they're not, but...) so a later compiler version assigned them to registers. Hence the errors. So I changed them to volatile and it compiles OK.

Next problem: This forum will not let me add or replace the ZIP files for TWIRP. Don't know why.

meanwhile, make your declarations look like this:

// ---- MINIMAL use of variables - need lots of buffer space in RAM
volatile byte ticksmsec;
byte outbufcount;
byte inbufcount;
volatile byte delayval;

register byte b, pw, n, bursts;
volatile byte *outbufpw;
volatile byte *outbufpr;       
volatile byte *inbufpw;
volatile byte *inbufpr;
byte k1;
byte signature[6];
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

it compiles 100% with no errors now,

Thankyou

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'll upload the overall source to Projects when the forum moderator tells me why I'm getting errors. Posted to the freaks.net topic area

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

The problem seemed to be that I did not declare the pointers used in the interrupt routine as volatile (they're not, but...) so a later compiler version assigned them to registers.

There are a lot of implications in that single sentence and side note.

Probably true that in CV "volatile" will trump "register". I'd have to check it out. But instead of taking the side-step (which you claim in the aside is not the case), why not just face the situation directly and tell the compiler what you want--turn off Automatic Register Allocation in the Project options.

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:
Quote:

The problem seemed to be that I did not declare the pointers used in the interrupt routine as volatile (they're not, but...) so a later compiler version assigned them to registers.

There are a lot of implications in that single sentence and side note.

Probably true that in CV "volatile" will trump "register". I'd have to check it out. But instead of taking the side-step (which you claim in the aside is not the case), why not just face the situation directly and tell the compiler what you want--turn off Automatic Register Allocation in the Project options.

Lee

Thanks for the suggestions..

A) I did this in 2003 and haven't touched it since. Perhaps Automatic Register Allocation wasn't an option then, don't recall.

B) I wouldn't want to prohibit Automatic Register Allocation for all variables, just the ones used in the ISR.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i was also getting the above mentioned errors while compiling. thanks you so much steve. you have written a very nice code for twirp. i was getting errors, but when i was looking at the code my mind was not ready to think that there is any mistake in the code. i always thought that its the problem of assembler. thanks steve

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hi, its compiling ok, but assembler generating the same errors.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

codevision 2 generates errors while assembling but 1.25 compiles and assembles with no errors, just a warning that hardware stack is too low.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

why codevision 2 produces errors. i dont know, if steve can help?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

turning off automatic register allocation is not the solution of problem.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

why codevision 2 produces errors. i dont know, if steve can help?

I think you are going to have to tell the crystal ball gazers where what those errors actually are.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i am sorry clawson i cannot understand this joke. english is not my mother language.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

i am sorry clawson i cannot understand this joke. english is not my mother language.

Then how do you know it is a joke? :wink:

You are only saying "errors". A compiler can leave hundreds or thousands of different errors. No one here can guess with what errors it is that you are seeing. If you want to talk about specific error messages then post the exact error message text (by copy and paste, not by typing it in - especially not if English is not your mother tounge).

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

you are right, thats my mistake. following are the error messages generated by codevision 2 assembler.

AVRASM: AVR macro assembler 2.1.17 (build 435 Apr 10 2008 09:27:55)
Copyright (C) 1995-2008 ATMEL Corporation
\TWIRP Codevision C\IRv4.asm(1278): error: Invalid number
\TWIRP Codevision C\IRv4.asm(1294): error: Invalid number
\TWIRP Codevision C\IRv4.asm(1361): error: Invalid number
\TWIRP Codevision C\IRv4.asm(1375): error: Invalid number

Assembly failed, 4 errors.
'////////////////////////////////////
what i gues is that asmblr cannot recognize the register

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

the register is r26 of 90S2313. all 4 errors are for this register. with asm command,
LDS
STS
inc
Hope you can help.