Skip to content

Commit

Permalink
More cross-demo file synchronisation
Browse files Browse the repository at this point in the history
  • Loading branch information
Tony Smith committed Jul 24, 2024
1 parent 156ab09 commit 63527b2
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 15 deletions.
9 changes: 4 additions & 5 deletions app/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
// Central store for Microvisor resource handles used in this code.
// See `https://www.twilio.com/docs/iot/microvisor/syscalls#handles`
struct {
static struct {
MvNotificationHandle notification;
MvNetworkHandle network;
MvChannelHandle channel;
Expand All @@ -23,10 +23,9 @@ struct {
// Central store for HTTP request management notification records.
// Holds HTTP_NT_BUFFER_SIZE_R records at a time -- each record is 16 bytes in size.
static struct MvNotification http_notification_center[HTTP_NT_BUFFER_SIZE_R] __attribute__((aligned(8)));
// Modified in ISR
static volatile uint32_t current_notification_index = 0;

// Defined in `main.c`, modified in ISR
// Defined in `main.c`
extern volatile bool received_request;
extern volatile bool channel_was_closed;

Expand Down Expand Up @@ -130,7 +129,7 @@ void http_setup_notification_center(void) {
// Ask Microvisor to establish the notification center
// and confirm that it has accepted the request
enum MvStatus status = mvSetupNotifications(&http_notification_setup, &http_handles.notification);
do_assert(status == MV_STATUS_OKAY, "Could not set up HTTP channel NC");
do_assert(status == MV_STATUS_OKAY, "Could not set up HTTP channel Notification Center");

// Start the notification IRQ
NVIC_ClearPendingIRQ(TIM8_BRK_IRQn);
Expand Down Expand Up @@ -183,7 +182,7 @@ enum MvStatus http_send_request(uint32_t item_number) {
// Issue the request -- and check its status
enum MvStatus status = mvSendHttpRequest(http_handles.channel, &request_config);
if (status == MV_STATUS_OKAY) {
server_log("Request sent to Microvisor Cloud");
server_log("Request sent to the Microvisor Cloud");
} else if (status == MV_STATUS_CHANNELCLOSED) {
server_error("HTTP channel %lu already closed", (uint32_t)http_handles.channel);
} else {
Expand Down
4 changes: 2 additions & 2 deletions app/logging.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Microvisor HTTP Communications Demo
* Microvisor C Demos
*
* Copyright © 2024, KORE Wireless
* Licence: MIT
Expand All @@ -25,9 +25,9 @@ static uint8_t log_buffer[LOG_BUFFER_SIZE_B] __attribute__((aligned(512))) = {0
static uint32_t log_state = USER_HANDLE_LOGGING_OFF;

// Entities for local serial logging
static bool uart_available = false;
// Declared in `uart_logging.c`
extern UART_HandleTypeDef uart;
static bool uart_available = false;


/**
Expand Down
2 changes: 1 addition & 1 deletion app/logging.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Microvisor HTTP Communications Demo
* Microvisor C Demos
*
* Copyright © 2024, KORE Wireless
* Licence: MIT
Expand Down
9 changes: 4 additions & 5 deletions app/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,20 +207,19 @@ static void task_http(void *argument) {

// Run the thread's main loop
while (1) {
MvChannelHandle channel_handle = http_get_handle();
uint32_t tick = HAL_GetTick();
if (tick - send_tick > REQUEST_SEND_PERIOD_MS) {
// Display the current count
send_tick = tick;
server_log("Ping %lu", ping_count++);

// No channel open? The try and open a new one
if (channel_handle == 0 && http_open_channel()) {
if (http_get_handle() == 0 && http_open_channel()) {
if (http_send_request(ping_count) != 0) do_close_channel = true;
kill_time = tick;
} else {
server_error("Channel handle not zero");
if (channel_handle != 0) do_close_channel = true;
server_error("Channel handle not zero or could not open channel");
if (http_get_handle() != 0) do_close_channel = true;
}
}

Expand All @@ -230,7 +229,7 @@ static void task_http(void *argument) {
// Respond to unexpected channel closure
if (channel_was_closed) {
enum MvClosureReason reason = 0;
if (mvGetChannelClosureReason(channel_handle, &reason) == MV_STATUS_OKAY) {
if (mvGetChannelClosureReason(http_get_handle(), &reason) == MV_STATUS_OKAY) {
server_log("Closure reason: %lu", (uint32_t)reason);
}

Expand Down
2 changes: 1 addition & 1 deletion app/network.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Microvisor HTTP Communications Demo
* Microvisor C Demos
*
* Copyright © 2024, KORE Wireless
* Licence: MIT
Expand Down
2 changes: 1 addition & 1 deletion app/network.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Microvisor HTTP Communications Demo
* Microvisor C Demos
*
* Copyright © 2024, KORE Wireless
* Licence: MIT
Expand Down

0 comments on commit 63527b2

Please sign in to comment.