Skip to content

unnecessary atomicity code in digitalWrite() and etc. #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
WestfW opened this issue Nov 2, 2018 · 2 comments
Closed

unnecessary atomicity code in digitalWrite() and etc. #3

WestfW opened this issue Nov 2, 2018 · 2 comments

Comments

@WestfW
Copy link
Contributor

WestfW commented Nov 2, 2018

The Mega-0 OUTSET and OUTCLR registers are atomic by nature, so interrupts do not need to be disabled in the digitalWrite() code that manipulates them. (code that does &= or |= still needs such wrappers, since all the IOREGes are now outside the SBI/CBI range and will result in non-atomic access.)

	/* Output direction */
	if(port->DIR & bit_mask){

//OMIT		/* Save system status and disable interrupts */
//OMIT		uint8_t status = SREG;
//OMIT		cli();

		/* Set output to value */
		if (val == LOW) { /* If LOW */
			port->OUTCLR = bit_mask;

		} else if (val == TOGGLE) { /* If TOGGLE */
			port->OUTTGL = bit_mask;
									/* If HIGH OR  > TOGGLE  */
		} else {
			port->OUTSET = bit_mask;
		}

//OMIT		/* Restore system status */
//OMIT		SREG = status;

	/* Input direction */
	} else {

@facchinm
Copy link
Member

facchinm commented Nov 8, 2018

Thanks for pointing it out! Would you mind to post a pull request so you can have the paternity of the commit?

@facchinm
Copy link
Member

facchinm commented Nov 9, 2018

Fixed by merging #7 , thanks!

@facchinm facchinm closed this as completed Nov 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants