help replacing line with NOP

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

I have some time sensitive code that I used some debug to make work.  Now I need to remove the debug but I can not find the right NOP substitutes

 

code

DDRB=0xff;
int count=0;
memset(BB_ReadBuffer,0,size);
WHILE_DATA_IS_LO//wait for busy to send, then sync in
if (count == 15000) return -1;//was not ready.
_delay_us(4.3);
for (char b = 0; b < size; b++)
{
	BB_ReadBuffer[b] >>=1; PORTD=0; if (PINF & _DATA)   _delay_us(.2); else BB_ReadBuffer[b] |= 0x80;  PORTB = 0x40;_delay_us(3.6);
	BB_ReadBuffer[b] >>=1; PORTD=0; if (PINF & _DATA)   _delay_us(.2); else BB_ReadBuffer[b] |= 0x80;  PORTB = 0x40;_delay_us(3.6);
	BB_ReadBuffer[b] >>=1; PORTD=0; if (PINF & _DATA)   _delay_us(.2); else BB_ReadBuffer[b] |= 0x80;  PORTB = 0x40;_delay_us(3.6);
	BB_ReadBuffer[b] >>=1; PORTD=0; if (PINF & _DATA)   _delay_us(.2); else BB_ReadBuffer[b] |= 0x80;  PORTB = 0x40;_delay_us(3.6);
	BB_ReadBuffer[b] >>=1; PORTD=0; if (PINF & _DATA)   _delay_us(.2); else BB_ReadBuffer[b] |= 0x80;  PORTB = 0x40;_delay_us(3.6);
	BB_ReadBuffer[b] >>=1; PORTD=0; if (PINF & _DATA)   _delay_us(.2); else BB_ReadBuffer[b] |= 0x80;  PORTB = 0x40;_delay_us(3.6);
	BB_ReadBuffer[b] >>=1; PORTD=0; if (PINF & _DATA)   _delay_us(.2); else BB_ReadBuffer[b] |= 0x80;  PORTB = 0x40;_delay_us(3.6);
	BB_ReadBuffer[b] >>=1; PORTD=0; if (PINF & _DATA)   _delay_us(.2); else BB_ReadBuffer[b] |= 0x80;  PORTB = 0x40;

	count=0;
	if ( PINF & _DATA )
	{
		WHILE_DATA_IS_HI
		WHILE_DATA_IS_LO
		_delay_us(1.1);
	}
	else
	{
		WHILE_DATA_IS_LO
		WHILE_DATA_IS_HI
		WHILE_DATA_IS_LO
		_delay_us(1);
	}

}
_delay_us(10);

I have the lss file here for that section (more if needed)

 

 a30:	40 e0       	ldi	r20, 0x00	; 0
	if (count == 15000) return -1;//was not ready.
	_delay_us(4.2);
	for (char b = 0; b < size; b++)
 a32:	90 e4       	ldi	r25, 0x40	; 64
	{
		BB_ReadBuffer[b] >>=1; PORTB = 0; if (PINF & _DATA)   _delay_us(.2); else BB_ReadBuffer[b] |= 0x80;  PORTB = 0x40;_delay_us(3.6);
 a34:	4c 17       	cp	r20, r28
	int count=0;
	memset(BB_ReadBuffer,0,size);
	WHILE_DATA_IS_LO//wait for busy to send, then sync in
	if (count == 15000) return -1;//was not ready.
	_delay_us(4.2);
	for (char b = 0; b < size; b++)
 a36:	09 f4       	brne	.+2      	; 0xa3a <Read+0x3e>
 a38:	c0 c0       	rjmp	.+384    	; 0xbba <__stack+0xbb>
 a3a:	80 81       	ld	r24, Z
	{
		BB_ReadBuffer[b] >>=1; PORTB = 0; if (PINF & _DATA)   _delay_us(.2); else BB_ReadBuffer[b] |= 0x80;  PORTB = 0x40;_delay_us(3.6);

I tried replace with NOP's like this

		BB_ReadBuffer[b] >>=1; asm("NOP;NOP\n"); if (PINF & _DATA)   _delay_us(.2); else BB_ReadBuffer[b] |= 0x80;  PORTB = 0x40;_delay_us(3.6);
		BB_ReadBuffer[b] >>=1; asm("NOP;NOP\n"); if (PINF & _DATA)   _delay_us(.2); else BB_ReadBuffer[b] |= 0x80;  PORTB = 0x40;_delay_us(3.6);
		BB_ReadBuffer[b] >>=1; asm("NOP;NOP\n"); if (PINF & _DATA)   _delay_us(.2); else BB_ReadBuffer[b] |= 0x80;  PORTB = 0x40;_delay_us(3.6);
		BB_ReadBuffer[b] >>=1; asm("NOP;NOP\n"); if (PINF & _DATA)   _delay_us(.2); else BB_ReadBuffer[b] |= 0x80;  PORTB = 0x40;_delay_us(3.6);
		BB_ReadBuffer[b] >>=1; asm("NOP;NOP\n"); if (PINF & _DATA)   _delay_us(.2); else BB_ReadBuffer[b] |= 0x80;  PORTB = 0x40;_delay_us(3.6);
		BB_ReadBuffer[b] >>=1; asm("NOP;NOP\n"); if (PINF & _DATA)   _delay_us(.2); else BB_ReadBuffer[b] |= 0x80;  PORTB = 0x40;_delay_us(3.6);
		BB_ReadBuffer[b] >>=1; asm("NOP;NOP\n"); if (PINF & _DATA)   _delay_us(.2); else BB_ReadBuffer[b] |= 0x80;  PORTB = 0x40;_delay_us(3.6);
		BB_ReadBuffer[b] >>=1; asm("NOP;NOP\n"); if (PINF & _DATA)   _delay_us(.2); else BB_ReadBuffer[b] |= 0x80;  PORTB = 0x40;

but no amount of NOPs work.  I'm guessing the ASM is making preparations above the block of code but I'm not experienced  enough to see what is going on . I also need to figure out the replacement for the PORTB = 0x40's

 

This topic has a solution.
Last Edited: Wed. Jul 24, 2019 - 10:46 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

 

A compare of the two lss files helped. turns out this out is two cycles and the second " "PORTB = 0x40" was pretty easy to make work out. Self solved post.

 

solution was

BB_ReadBuffer[b] >>=1; asm("NOP\nNOP\n"); if (PINF & _DATA)   _delay_us(.2); else BB_ReadBuffer[b] |= 0x80;  _delay_us(3.7);

 

Last Edited: Wed. Jul 24, 2019 - 10:47 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you need cycle accurate timing do not use C !