23#include "mmhal_core.h"
24#include "mmhal_uart.h"
32#define SEQ_NUM_LEN (4)
34#define COMMAND_MAX_LEN (252)
36#define RESPONSE_MAX_LEN (2048)
38#define RESPONSE_HDR_LEN (12)
63 struct mmbuf *rsp_buf = NULL;
64 uint32_t response_len;
72 printf(
"Received command packet too short\n");
85 printf(
"Executing command...\n");
94 printf(
"Command executed successfully. Sending response...\n");
99 uint8_t result_code[4] = {};
101 printf(
"Failed to execute command. Status code %d\n", status);
106 result_code[0] = MM_ENOMEM;
110 result_code[0] = MM_ENODEV;
114 result_code[0] = MM_EINVAL;
118 result_code[0] = MM_ETIMEDOUT;
122 result_code[0] = MM_EFAULT;
143 printf(
"Failed to send response (%d)\n", ret);
147 printf(
"Response sent\n");
167 for (ii = 0; ii <
length; ii++)
169 status =
slip_rx(slip_state, data[ii]);
174 if (slip_state->
length <
sizeof(uint16_t))
176 printf(
"Received command packet too short. Ignoring...\n");
181 if ((slip_state->
buffer[slip_state->
length - 2] == (crc & 0xFF)) &&
182 (slip_state->
buffer[slip_state->
length - 1] == (crc >> 8)))
186 if (mmbuffer == NULL)
190 printf(
"Error: memory allocation failure\n");
199 printf(
"CRC validation failure\n");
222 printf(
"\n\nRF Test Application (Built "__DATE__
223 " " __TIME__
")\n\n");
static uint8_t * mmbuf_append(struct mmbuf *mmbuf, uint32_t len)
Reserves space immediately after the data currently in the given mmbuf and returns a pointer to this ...
static uint32_t mmbuf_get_data_length(struct mmbuf *mmbuf)
Gets the length of the data currently in the mmbuf.
static uint8_t * mmbuf_remove_from_end(struct mmbuf *mmbuf, uint32_t len)
Remove data from the end of the mmbuf.
struct mmbuf * mmbuf_alloc_on_heap(uint32_t space_at_start, uint32_t space_at_end)
Allocate a new mmbuf on the heap (using mmosal_malloc()).
void mmbuf_release(struct mmbuf *mmbuf)
Release a reference to the given mmbuf.
static void mmbuf_append_data(struct mmbuf *mmbuf, const uint8_t *data, uint32_t len)
Appends the given data to the data already in the mmbuf.
static uint8_t * mmbuf_get_data_start(struct mmbuf *mmbuf)
Gets a pointer to the start of the data in the mmbuf.
uint16_t mmcrc_16_xmodem(uint16_t crc, const void *data, size_t data_len)
Compute the CRC-16 for the data buffer using the XMODEM model.
void mmhal_set_deep_sleep_veto(uint8_t veto_id)
Sets a deep sleep veto that will prevent the device from entering deep sleep.
@ MMHAL_VETO_ID_APP_MIN
Start of deep sleep veto ID range that is available for application use.
void mmhal_uart_tx(const uint8_t *data, size_t length)
Transmit data on the UART.
void mmhal_uart_init(mmhal_uart_rx_cb_t rx_cb, void *rx_cb_arg)
Initialize the UART HAL and perform any setup necessary.
#define MM_UNUSED(_x)
Casts the given expression to void to avoid "unused" warnings from the compiler.
enum mmwlan_status mmwlan_set_power_save_mode(enum mmwlan_ps_mode mode)
Sets whether or not the 802.11 power save is enabled.
@ MMWLAN_PS_DISABLED
Power save disabled.
enum mmwlan_status mmwlan_ate_execute_command(uint8_t *command, uint32_t command_len, uint8_t *response, uint32_t *response_len)
Execute a test/debug command.
mmwlan_status
Enumeration of status return codes.
@ MMWLAN_INVALID_ARGUMENT
The operation failed due to an invalid argument.
@ MMWLAN_TIMED_OUT
Failed due to timeout.
@ MMWLAN_SUCCESS
The operation was successful.
@ MMWLAN_NO_MEM
Failed due to memory allocation failure.
@ MMWLAN_UNAVAILABLE
Functionality is temporarily unavailable.
enum slip_rx_status slip_rx(struct slip_rx_state *state, uint8_t c)
Handle reception of a character in a SLIP stream.
#define SLIP_RX_STATE_INIT(_buffer, _buffer_length)
Static initializer for slip_rx_state.
int slip_tx(slip_transport_tx_fn transport_tx_fn, void *transport_tx_arg, const uint8_t *packet, size_t packet_len)
Transmit a packet with SLIP framing.
slip_rx_status
Enumeration of SLIP status codes.
#define SLIP_RX_BUFFER_SIZE
Recommended RX buffer size.
@ SLIP_RX_COMPLETE
A complete packet with length > 0 has been received.
Morse Micro application helper routines for initializing/de-initializing the Wireless LAN interface a...
void app_wlan_init(void)
Initializes the WLAN interface (and dependencies) using settings specified in the config store.
#define RESPONSE_HDR_LEN
Length of a response header (excluding status field).
#define RESPONSE_MAX_LEN
Maximum possible length of a response that we may wish to send.
static void rf_test_handle_command(struct mmbuf *cmd_buf)
Callback to handle reception of a command packet from the data-link HAL.
static struct slip_rx_state rx_slip_state
State data for SLIP processing on receive path.
static void uart_rx_handler(const uint8_t *data, size_t length, void *arg)
Handler for UART HAL RX callback.
static uint8_t slip_rx_buffer[SLIP_RX_BUFFER_SIZE]
Buffer for SLIP processing on receive path.
void app_init(void)
Main entry point to the application.
#define SEQ_NUM_LEN
Length of the sequence number field appended to command/response packets.
static int slip_tx_handler(uint8_t c, void *arg)
TX callback handler for SLIP.
Core mmbuf data structure.
Structure used to contain the current state for the SLIP receiver.
uint8_t * buffer
Reference to buffer where processed bytes are received.
size_t length
Length of the currently received frame, excluding escape bytes.