Skip to content

Commit

Permalink
Adding define in C API for global var section (#961)
Browse files Browse the repository at this point in the history
  • Loading branch information
nquarton authored Oct 13, 2023
1 parent 09aa219 commit f5cd2b7
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions libcaliptra/src/caliptra_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,18 @@
#include "caliptra_mbox.h"
#include "caliptra_enums.h"

#define CALIPTRA_STATUS_NOT_READY 0
#define CALIPTRA_STATUS_NOT_READY (0)

struct caliptra_buffer g_mbox_pending_rx_buffer = {NULL, 0};
// User can define a data section for global vars if needed like #define CALIPTRA_API_GLOBAL_SECTION ".custom_section"
#ifdef CALIPTRA_API_GLOBAL_SECTION
#define CALIPTRA_API_GLOBAL_SECTION_ATTRIBUTE __attribute__((section(CALIPTRA_API_GLOBAL_SECTION)))
#else
#define CALIPTRA_API_GLOBAL_SECTION_ATTRIBUTE
#endif

// All globals should use CALIPTRA_API_GLOBAL_SECTION_ATTRIBUTE
// Globals should be uninitialized to maximize environment compatibility
static struct caliptra_buffer g_mbox_pending_rx_buffer CALIPTRA_API_GLOBAL_SECTION_ATTRIBUTE;

/**
* calculate_caliptra_checksum
Expand Down Expand Up @@ -423,14 +432,11 @@ int caliptra_mailbox_execute(uint32_t cmd, struct caliptra_buffer *mbox_tx_buffe
return status;
}

// HW lock should prevent this from happening
if (g_mbox_pending_rx_buffer.data != NULL) {
return API_INTERNAL_ERROR;
}

// Store buffer info
// Store buffer info or init to zero
if (mbox_rx_buffer != NULL) {
g_mbox_pending_rx_buffer = *mbox_rx_buffer;
} else {
g_mbox_pending_rx_buffer = (struct caliptra_buffer){NULL, 0};
}

// Stop here if this is async (user will poll and complete)
Expand Down

0 comments on commit f5cd2b7

Please sign in to comment.