Skip to content

Commit

Permalink
Update to latest note-c master. (#127)
Browse files Browse the repository at this point in the history
* remove note-c before re-add

* Squashed 'src/note-c/' content from commit 96e5ca2

git-subtree-dir: src/note-c
git-subtree-split: 96e5ca2c2ec7724d6133ac67225d51482ee1f328

* Update to latest note-c master.
  • Loading branch information
haydenroche5 authored Feb 1, 2024
1 parent 8253f4d commit 0951357
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 34 deletions.
18 changes: 0 additions & 18 deletions src/note-c/n_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,14 @@ NOTE_C_STATIC const char * i2cNoteQueryLength(uint32_t * available,
// Send a dummy I2C transaction to prime the Notecard
const char *err = _I2CReceive(_I2CAddress(), &dummy_buffer, 0, available);
if (err) {
#ifdef ERRDBG
NOTE_C_LOG_ERROR(err);
#endif
return err;
}

// If we've timed out, return an error
if (timeoutMs && _GetMs() - startMs >= timeoutMs) {
const char *err = ERRSTR("timeout: no response from Notecard {io}", c_iotimeout);
#ifdef ERRDBG
NOTE_C_LOG_ERROR(err);
#endif
return err;
}
}
Expand Down Expand Up @@ -119,9 +115,7 @@ const char *i2cNoteTransaction(const char *request, size_t reqLen, char **respon
uint32_t available = 0;
err = i2cNoteQueryLength(&available, timeoutMs);
if (err) {
#ifdef ERRDBG
NOTE_C_LOG_ERROR(ERRSTR("failed to query Notecard", c_err));
#endif
_UnlockI2C();
return err;
}
Expand All @@ -131,9 +125,7 @@ const char *i2cNoteTransaction(const char *request, size_t reqLen, char **respon
jsonbuf = (uint8_t *)_Malloc(jsonbufAllocLen + 1);
if (jsonbuf == NULL) {
const char *err = ERRSTR("transaction: jsonbuf malloc failed", c_mem);
#ifdef ERRDBG
NOTE_C_LOG_ERROR(err);
#endif
_UnlockI2C();
return err;
}
Expand All @@ -150,9 +142,7 @@ const char *i2cNoteTransaction(const char *request, size_t reqLen, char **respon
if (jsonbuf) {
_Free(jsonbuf);
}
#ifdef ERRDBG
NOTE_C_LOG_ERROR(ERRSTR("error occured during receive", c_iobad));
#endif
_UnlockI2C();
return err;
}
Expand All @@ -169,9 +159,7 @@ const char *i2cNoteTransaction(const char *request, size_t reqLen, char **respon
uint8_t *jsonbufNew = (uint8_t *)_Malloc(jsonbufAllocLen + 1);
if (jsonbufNew == NULL) {
const char *err = ERRSTR("transaction: jsonbuf grow malloc failed", c_mem);
#ifdef ERRDBG
NOTE_C_LOG_ERROR(err);
#endif
if (jsonbuf) {
_Free(jsonbuf);
}
Expand Down Expand Up @@ -368,9 +356,7 @@ const char *i2cChunkedReceive(uint8_t *buffer, uint32_t *size, bool delay, uint3
const char *err = _I2CReceive(_I2CAddress(), (buffer + received), requested, available);
if (err) {
*size = received;
#ifdef ERRDBG
NOTE_C_LOG_ERROR(err);
#endif
return err;
}

Expand Down Expand Up @@ -414,11 +400,9 @@ const char *i2cChunkedReceive(uint8_t *buffer, uint32_t *size, bool delay, uint3
// Exit on timeout
if (timeoutMs && (_GetMs() - startMs >= timeoutMs)) {
*size = received;
#ifdef ERRDBG
if (received) {
NOTE_C_LOG_ERROR(ERRSTR("received only partial reply before timeout", c_iobad));
}
#endif
return ERRSTR("timeout: transaction incomplete {io}", c_iotimeout);
}

Expand Down Expand Up @@ -461,9 +445,7 @@ const char *i2cChunkedTransmit(uint8_t *buffer, uint32_t size, bool delay)
estr = _I2CTransmit(_I2CAddress(), chunk, chunkLen);
if (estr != NULL) {
_I2CReset(_I2CAddress());
#ifdef ERRDBG
NOTE_C_LOG_ERROR(estr);
#endif
return estr;
}
chunk += chunkLen;
Expand Down
16 changes: 1 addition & 15 deletions src/note-c/n_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ const char *serialNoteTransaction(const char *request, size_t reqLen, char **res
// max timeout and ultimately in our error handling.
for (const uint32_t startMs = _GetMs(); !_SerialAvailable(); ) {
if (timeoutMs && (_GetMs() - startMs) >= timeoutMs) {
#ifdef ERRDBG
NOTE_C_LOG_ERROR(ERRSTR("reply to request didn't arrive from module in time", c_iotimeout));
#endif
NOTE_C_LOG_DEBUG(ERRSTR("reply to request didn't arrive from module in time", c_iotimeout));
return ERRSTR("transaction timeout {io}", c_iotimeout);
}
if (!cardTurboIO) {
Expand All @@ -78,9 +76,7 @@ const char *serialNoteTransaction(const char *request, size_t reqLen, char **res
uint8_t *jsonbuf = (uint8_t *)_Malloc(jsonbufAllocLen + 1);
if (jsonbuf == NULL) {
const char *err = ERRSTR("transaction: jsonbuf malloc failed", c_mem);
#ifdef ERRDBG
NOTE_C_LOG_ERROR(err);
#endif
return err;
}

Expand All @@ -93,9 +89,7 @@ const char *serialNoteTransaction(const char *request, size_t reqLen, char **res
const char *err = serialChunkedReceive((uint8_t *)(jsonbuf + jsonbufLen), &jsonbufAvailLen, true, (CARD_INTRA_TRANSACTION_TIMEOUT_SEC * 1000), &available);
if (err) {
_Free(jsonbuf);
#ifdef ERRDBG
NOTE_C_LOG_ERROR(ERRSTR("error occured during receive", c_iobad));
#endif
return err;
}
jsonbufLen += jsonbufAvailLen;
Expand All @@ -111,9 +105,7 @@ const char *serialNoteTransaction(const char *request, size_t reqLen, char **res
uint8_t *jsonbufNew = (uint8_t *)_Malloc(jsonbufAllocLen + 1);
if (jsonbufNew == NULL) {
const char *err = ERRSTR("transaction: jsonbuf grow malloc failed", c_mem);
#ifdef ERRDBG
NOTE_C_LOG_ERROR(err);
#endif
_Free(jsonbuf);
return err;
}
Expand Down Expand Up @@ -190,11 +182,7 @@ bool serialNoteReset(void)
break;
}

#ifdef ERRDBG
NOTE_C_LOG_ERROR(somethingFound ? ERRSTR("unrecognized data from notecard", c_iobad) : ERRSTR("notecard not responding", c_iobad));
#else
NOTE_C_LOG_ERROR(ERRSTR("notecard not responding", c_iobad));
#endif

_DelayMs(CARD_RESET_DRAIN_MS);
if (!_SerialReset()) {
Expand Down Expand Up @@ -234,11 +222,9 @@ const char *serialChunkedReceive(uint8_t *buffer, uint32_t *size, bool delay, ui
while (!_SerialAvailable()) {
if (timeoutMs && (_GetMs() - startMs >= timeoutMs)) {
*size = received;
#ifdef ERRDBG
if (received) {
NOTE_C_LOG_ERROR(ERRSTR("received only partial reply before timeout", c_iobad));
}
#endif
return ERRSTR("timeout: transaction incomplete {io}",c_iotimeout);
}
// Yield while awaiting the first byte (lazy). After the first byte,
Expand Down
1 change: 0 additions & 1 deletion src/note-c/note.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
#define ERRSTR(x,y) (y)
#else
#define ERRSTR(x,y) (x)
#define ERRDBG
#endif

#ifdef NOTE_C_TEST_SINGLE_PRECISION
Expand Down

0 comments on commit 0951357

Please sign in to comment.