Commit a7de2e9cc6eb908647f60af8dcda72f43121e316
1 parent
458a7e78
Changed cast style, changed millis() in ISR to micros(), added a few noInterrupt…
…s() - interrups() sequences
Showing
2 changed files
with
16 additions
and
7 deletions
src/EasyOpenTherm.cpp
| ... | ... | @@ -276,17 +276,17 @@ bool OTDataLinkLayer::parity() { |
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | OTDataLinkLayer::MSG_TYPE OTDataLinkLayer::type() { |
| 279 | - return OTDataLinkLayer::MSG_TYPE(_frame & 0x70000000); | |
| 279 | + return (OTDataLinkLayer::MSG_TYPE)(_frame & 0x70000000); | |
| 280 | 280 | } |
| 281 | 281 | |
| 282 | 282 | |
| 283 | 283 | uint8_t OTDataLinkLayer::dataID() { |
| 284 | - return uint8_t((_frame & 0xff0000) >> 16); | |
| 284 | + return (uint8_t)((_frame & 0xff0000) >> 16); | |
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | |
| 288 | 288 | uint16_t OTDataLinkLayer::value() { |
| 289 | - return uint16_t(_frame & 0xffff); | |
| 289 | + return (uint16_t)(_frame & 0xffff); | |
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | |
| ... | ... | @@ -327,7 +327,7 @@ bool OTDataLinkLayer::_parity(uint32_t fr |
| 327 | 327 | frame ^= frame >> 4; |
| 328 | 328 | frame ^= frame >> 2; |
| 329 | 329 | frame ^= frame >> 1; |
| 330 | - return (~frame) & 1; | |
| 330 | + return ((~frame) & 1) == 1; | |
| 331 | 331 | } |
| 332 | 332 | |
| 333 | 333 | |
| ... | ... | @@ -376,7 +376,8 @@ bool OTPhysicalLayer::send(uint32_t fr |
| 376 | 376 | return false; |
| 377 | 377 | } |
| 378 | 378 | |
| 379 | - if(_state == STATE::READY && millis() - _lastReceivedTimestampMs < 100) { | |
| 379 | +// if(_state == STATE::READY && millis() - _lastReceivedTimestampMs < 100) { | |
| 380 | + if(_state == STATE::READY && millis() - _lastReceivedTimestampMicros < 100) { | |
| 380 | 381 | |
| 381 | 382 | return false; // Wait at least 100 ms after receiving the final bit of the latest frame before sending a new frame |
| 382 | 383 | } |
| ... | ... | @@ -393,8 +394,10 @@ bool OTPhysicalLayer::send(uint32_t fr |
| 393 | 394 | |
| 394 | 395 | digitalWrite(_txPin, HIGH); // idle |
| 395 | 396 | |
| 397 | + noInterrupts(); //\\// | |
| 396 | 398 | _frame = 0; |
| 397 | 399 | _state = STATE::WAITING; |
| 400 | + interrupts(); ////// | |
| 398 | 401 | |
| 399 | 402 | _lastSentTimestampMs = millis(); |
| 400 | 403 | |
| ... | ... | @@ -407,7 +410,9 @@ bool OTPhysicalLayer::receive(uint32_t & fr |
| 407 | 410 | |
| 408 | 411 | if(_state != STATE::READY) { // ::handleInterrupt() will set _state to STATE::READY upon receiving a complete frame (including start and stop bits) |
| 409 | 412 | if(_primary && millis() - _lastSentTimestampMs > 800) { // ::send() will set _lastSentTimestampMs to after sending the final bit. A secondary never times out, it keeps on listning to the primary |
| 413 | + noInterrupts(); //\\// | |
| 410 | 414 | _state = STATE::INVALID; // timeout |
| 415 | + interrupts(); ////// | |
| 411 | 416 | } |
| 412 | 417 | |
| 413 | 418 | return false; |
| ... | ... | @@ -420,7 +425,9 @@ bool OTPhysicalLayer::receive(uint32_t & fr |
| 420 | 425 | |
| 421 | 426 | |
| 422 | 427 | void OTPhysicalLayer::reset() { |
| 428 | + noInterrupts(); //\\// | |
| 423 | 429 | _state = STATE::INVALID; |
| 430 | + interrupts(); ////// | |
| 424 | 431 | } |
| 425 | 432 | |
| 426 | 433 | |
| ... | ... | @@ -478,7 +485,8 @@ void OTPhysicalLayer::handleInterrupt() { |
| 478 | 485 | lastTimestamp = timestamp; |
| 479 | 486 | mask >>= 1; |
| 480 | 487 | } else { // stop bit |
| 481 | - _lastReceivedTimestampMs = millis(); | |
| 488 | +// _lastReceivedTimestampMs = millis(); | |
| 489 | + _lastReceivedTimestampMicros = micros(); | |
| 482 | 490 | _state = STATE::READY; |
| 483 | 491 | } |
| 484 | 492 | } | ... | ... |
src/EasyOpenTherm.h
| ... | ... | @@ -527,7 +527,8 @@ private: |
| 527 | 527 | |
| 528 | 528 | volatile uint32_t _frame; |
| 529 | 529 | uint32_t _lastSentTimestampMs; |
| 530 | - volatile uint32_t _lastReceivedTimestampMs; | |
| 530 | +// volatile uint32_t _lastReceivedTimestampMs; | |
| 531 | + volatile uint32_t _lastReceivedTimestampMicros; | |
| 531 | 532 | |
| 532 | 533 | uint8_t _rxPin; |
| 533 | 534 | uint8_t _txPin; | ... | ... |