Sleep delay necessary for SAMD21 debug print

1 post / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have a samd21g18a setup using ASF and freeRTOS.  I have implemented tickless mode and it works great so far.  I have added a check for debug print (modified version of dbg_print.c from ASF) to make sure the USART buffer is empty before I sleep.  I found I had to add a small time delay to make sure I didn't lose the last byte.  From what I read that sounds like one way of handling it.  Is there another option?

 

 

static void debugPrintInterrupt(uint8_t dummy)
{
	if (BufferTail == BufferHead) {
		DebugIsNotEmpty = false;
		DelayStart = SysTick->VAL;
		SercomDebug->INTENCLR.reg = SERCOM_USART_INTFLAG_DRE;
		return;
	}
	
	uint8_t data;
	data = DebugBuffer[BufferTail++];
	BufferTail &= DBG_BUFFER_MASK;

	SercomDebug->DATA.reg = data;
}

bool debugPrintNotReadyToSleep(void) {
	if (BufferHead != BufferTail) {
		return true;
	}
	else if (DebugIsNotEmpty) {
		return true;
	}
	else if (usDelayNotDone(10, DelayStart)) {
		return true;
	}
	else {
		return false;
	}
}