Skip to content

Commit

Permalink
Allow transmissions to be retried if the controller was busy (#26)
Browse files Browse the repository at this point in the history
* Allow transmissions to be retried if the controller was busy / out of buffer space.

* Fixed comments.

---------

Co-authored-by: Simon Cahill <[email protected]>
  • Loading branch information
pgreenland and SimonCahill committed Feb 21, 2024
1 parent 65e6167 commit a933e6a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ First, create some [shim](https://en.wikipedia.org/wiki/Shim_(computing)) functi
```C
/* required, this must send a single CAN message with the given arbitration
* ID (i.e. the CAN message ID) and data. The size will never be more than 8
* bytes. */
* bytes. Should return ISOTP_RET_OK if frame sent successfully.
* May return ISOTP_RET_NOSPACE if the frame could not be sent but may be
* retried later. Should return ISOTP_RET_ERROR in case frame could not be sent.
*/
int isotp_user_send_can(const uint32_t arbitration_id,
const uint8_t* data, const uint8_t size) {
// ...
Expand Down
2 changes: 2 additions & 0 deletions isotp.c
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,8 @@ void isotp_poll(IsoTpLink *link) {
if (link->send_offset >= link->send_size) {
link->send_status = ISOTP_SEND_STATUS_IDLE;
}
} else if (ISOTP_RET_NOSPACE == ret) {
/* shim reported that it isn't able to send a frame at present, retry on next call */
} else {
link->send_status = ISOTP_SEND_STATUS_ERROR;
}
Expand Down
1 change: 1 addition & 0 deletions isotp_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#define ISOTP_RET_NO_DATA -5
#define ISOTP_RET_TIMEOUT -6
#define ISOTP_RET_LENGTH -7
#define ISOTP_RET_NOSPACE -8

/* return logic true if 'a' is after 'b' */
#define IsoTpTimeAfter(a,b) ((int32_t)((int32_t)(b) - (int32_t)(a)) < 0)
Expand Down
14 changes: 10 additions & 4 deletions isotp_user.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,21 @@
extern "C" {
#endif

/* user implemented, print debug message */
/** @brief user implemented, print debug message */
void isotp_user_debug(const char* message, ...);

/* user implemented, send can message. should return ISOTP_RET_OK when success.
*/
/**
* @brief user implemented, send can message. should return ISOTP_RET_OK when success.
*
* @return may return ISOTP_RET_NOSPACE if the CAN transfer should be retried later
* or ISOTP_RET_ERROR if transmission couldn't be completed
*/
int isotp_user_send_can(const uint32_t arbitration_id,
const uint8_t* data, const uint8_t size);

/* user implemented, get microsecond */
/**
* @brief user implemented, gets the amount of time passed since the last call in microseconds
*/
uint32_t isotp_user_get_us(void);

#ifdef __cplusplus
Expand Down

0 comments on commit a933e6a

Please sign in to comment.