Microchip® Advanced Software Framework

serial_bridge.c File Reference

Serial Bridge.

Copyright (c) 2020-2021 Microchip Technology Inc. and its subsidiaries.

#include <asf.h>
#include "common/include/nm_common.h"
#include "bus_wrapper/include/nm_bus_wrapper.h"
#include "driver/source/nmbus.h"
#include "driver/include/m2m_wifi.h"
#include "buffered_uart.h"
#include <string.h>

Data Structures

struct  nm_command
 
struct  serial_bridge_frame
 
struct  serial_bridge_frame_buffer
 
struct  serial_bridge_frame_lookup
 

Macros

#define PACKET_QUEUE_BUFFER_SIZE   2048
 
#define SERIAL_BRIDGE_LOOKUP_TABLE_ENTRIES   sizeof(serial_bridge_lookup_table) / sizeof(struct serial_bridge_frame_lookup)
 

Functions

static sint8 enter_wifi_firmware_download (void)
 Process input UART command and forward to SPI. More...
 
int main (void)
 Main application function. More...
 
static void serial_bridge_frame_buffer_pop (struct serial_bridge_frame_buffer *frame, int size)
 
static int serial_bridge_frame_get_nm_command (struct serial_bridge_frame *frame, struct nm_command *cmd)
 Read out the first 13bytes and copy into cmd buffer after checking the frame. More...
 
static int serial_bridge_frame_receive (struct serial_bridge_frame_buffer *frame, uint16_t len)
 
static void serial_bridge_process_frame (void)
 Parse incoming frame and find the handler to process the request. More...
 
static int serial_bridge_process_read_block (struct serial_bridge_frame *frame)
 Handles the UART frame from nm_read_block() in nmuart.c. More...
 
static int serial_bridge_process_read_reg_with_ret (struct serial_bridge_frame *frame)
 Handles the UART frame from nm_read_reg_with_ret() in nmuart.c. More...
 
static int serial_bridge_process_reboot_cmd (struct serial_bridge_frame *frame)
 
static int serial_bridge_process_reconfigure (struct serial_bridge_frame *frame)
 Handles the UART frame from nm_reconfigure() in nmuart.c. More...
 
static int serial_bridge_process_sync_cmd (struct serial_bridge_frame *frame)
 Handles the UART frame from nm_sync_cmd() in nmuart.c. More...
 
static int serial_bridge_process_write_block (struct serial_bridge_frame *frame)
 Handles frame from nm_uart_write_block() in nmuart.c. More...
 
static int serial_bridge_process_write_reg (struct serial_bridge_frame *frame)
 Handles the UART frame from nm_write_reg() in nmuart.c. More...
 

Variables

static struct
serial_bridge_frame_buffer 
frame_buffer
 
tstrWifiInitParam gstrWifiParam
 
struct serial_bridge_frame_lookup serial_bridge_lookup_table []
 

#define PACKET_QUEUE_BUFFER_SIZE   2048
#define SERIAL_BRIDGE_LOOKUP_TABLE_ENTRIES   sizeof(serial_bridge_lookup_table) / sizeof(struct serial_bridge_frame_lookup)

static sint8 enter_wifi_firmware_download ( void  )
static
int main ( void  )

Main application function.

Application entry point.

Returns
program return value.

References board_init(), buffered_uart_init(), enter_wifi_firmware_download(), M2M_ERR, M2M_SUCCESS, m2m_wifi_download_mode(), nm_bsp_init(), and sysclk_init().

static int serial_bridge_frame_get_nm_command ( struct serial_bridge_frame frame,
struct nm_command cmd 
)
static
static int serial_bridge_frame_receive ( struct serial_bridge_frame_buffer frame,
uint16_t  len 
)
static
static int serial_bridge_process_read_block ( struct serial_bridge_frame frame)
static
static int serial_bridge_process_read_reg_with_ret ( struct serial_bridge_frame frame)
static
static int serial_bridge_process_reboot_cmd ( struct serial_bridge_frame frame)
static
static int serial_bridge_process_reconfigure ( struct serial_bridge_frame frame)
static
static int serial_bridge_process_sync_cmd ( struct serial_bridge_frame frame)
static

Handles the UART frame from nm_sync_cmd() in nmuart.c.

References buffered_uart_putchar(), and serial_bridge_frame_buffer_pop().

Referenced by enter_wifi_firmware_download().

static int serial_bridge_process_write_reg ( struct serial_bridge_frame frame)
static

tstrWifiInitParam gstrWifiParam
struct serial_bridge_frame_lookup serial_bridge_lookup_table[]
Initial value:
= {
{{0x12 }, 1, 1, serial_bridge_process_sync_cmd },
{{0xa5, 0x01}, 2, sizeof(struct serial_bridge_frame), serial_bridge_process_write_reg },
{{0xa5, 0x02}, 2, sizeof(struct serial_bridge_frame), serial_bridge_process_read_block },
{{0xa5, 0x03}, 2, sizeof(struct serial_bridge_frame), serial_bridge_process_write_block },
{{0xa5, 0x05}, 2, sizeof(struct serial_bridge_frame), serial_bridge_process_reconfigure },
}
static int serial_bridge_process_write_block(struct serial_bridge_frame *frame)
Handles frame from nm_uart_write_block() in nmuart.c.
Definition: serial_bridge.c:230
static int serial_bridge_process_sync_cmd(struct serial_bridge_frame *frame)
Handles the UART frame from nm_sync_cmd() in nmuart.c.
Definition: serial_bridge.c:155
static int serial_bridge_process_read_reg_with_ret(struct serial_bridge_frame *frame)
Handles the UART frame from nm_read_reg_with_ret() in nmuart.c.
Definition: serial_bridge.c:171
Definition: serial_bridge.c:76
static int serial_bridge_process_read_block(struct serial_bridge_frame *frame)
Handles the UART frame from nm_read_block() in nmuart.c.
Definition: serial_bridge.c:211
static int serial_bridge_process_reboot_cmd(struct serial_bridge_frame *frame)
Definition: serial_bridge.c:162
static int serial_bridge_process_write_reg(struct serial_bridge_frame *frame)
Handles the UART frame from nm_write_reg() in nmuart.c.
Definition: serial_bridge.c:194
static int serial_bridge_process_reconfigure(struct serial_bridge_frame *frame)
Handles the UART frame from nm_reconfigure() in nmuart.c.
Definition: serial_bridge.c:252