Skip to content
GitLab
  • Menu
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • F firmware
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 74
    • Issues 74
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 29
    • Merge requests 29
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Releases
  • External wiki
    • External wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • card10
  • firmware
  • Issues
  • #177
Closed
Open
Created Oct 03, 2019 by Rahix@rahixOwner

Proper sleep implementation in Pycardium

The current sleep in Pycardium (based on mxc_delay()) is not ideal for a number of reasons:

  1. It busy-spins for the duration of the delay which wastes energy unnecessarily and does not allow for any sort of sleep.
  2. It does not run scheduled interrupt handlers. This is most noticeable with button-interrupts as implemented in !297.
  3. It is not interruptible by CTRL-C.

The best solution to this is probably a re-implementation of the logic behind mxc_delay(). This means defining a SysTick_Handler to count overflows and a delay-function which checks the timer value on every IRQ wakeup. In (simplified) code:

void systick_delay(uint32_t usec)
{
	/* Setup SysTick */
	/* ... */

	while (waiting) {
		/* Handle scheduled interrupt handlers/callbacks */
		mp_handle_pending();
		/* Wait for any IRQ, including the SysTick */
		__WFI();
	}

	/* Tear down SysTick */
	/* ... */
}

Note that this implementation does not deal with CTRL-C correctly yet (point 3). I'm not quite sure what is needed for that to work properly.

Assignee
Assign to
Time tracking