Microchip® Advanced Software Framework

board_monitor.c File Reference

SAM4L-EK Board Monitor Control.

Copyright (c) 2012-2018 Microchip Technology Inc. and its subsidiaries.

#include "board_monitor.h"
#include "delay.h"

Macros

#define BM_CTRL   0x03
 Enable/disable the board monitor. More...
 
#define BM_GET_FIRMWARE_VERSION   0x11
 Send Firmware Version Request. More...
 
#define BM_LED_CLR   0x05
 Turn-off a LED of the board monitor. More...
 
#define BM_LED_SET   0x04
 Turn-on a LED of the board monitor. More...
 
#define BM_LED_TGL   0x06
 Toggle a LED of the board monitor. More...
 
#define BM_MCU_GET_CURRENT   0x0A
 Send Current Consumption Measured Request. More...
 
#define BM_MCU_GET_FIFO_FREE_SIZE   0x0D
 Send free size (in byte) of the board monitor command fifo request. More...
 
#define BM_MCU_RET_CURRENT   0x0C
 Return Current Consumption Measured. More...
 
#define BM_MCU_RET_FIFO_FREE_SIZE   0x0E
 Return the free size (in byte) of the board monitor command fifo. More...
 
#define BM_MCU_STATUS   0x07
 Send MCU power saving information to the board monitor. More...
 
#define BM_MSG_ID_DEFAULT   0
 Board Monitor Message Default ID Message. More...
 
#define BM_MSG_LENGTH_DEFAULT   9
 Board Monitor Message Number of bytes to transfer. More...
 
#define BM_MSG_START_PATTERN   0x75
 Board Monitor Message Start pattern. More...
 
#define BM_MSG_STOP_PATTERN   0xa3
 Board Monitor Message Stop pattern. More...
 
#define BM_PICOUART_SEND   0x09
 Send PicoUart Frame. More...
 
#define BM_POINTER_CTRL   0x01
 Enable/disable the board monitor mouse-like pointer. More...
 
#define BM_POINTER_MOVE   0x02
 Send new mouse pointer position. More...
 
#define BM_PRINT_CLEAR   0x10
 Clear Print Text Area On Board Monitor. More...
 
#define BM_PRINT_TEXT   0x0F
 Print Text On Board Monitor. More...
 
#define BM_PRINT_TEXT_DEEP   6
 
#define BM_PRINT_TEXT_SIZE   21
 
#define BM_PULLUP_TWI   0x08
 Enable/disable the pull-up on TWI lines. More...
 
#define BM_RET_FIRMWARE_VERSION   0x12
 Return Firmware Version value . More...
 
#define BM_TGL_BUTTON   0x0B
 Force Toggle of Button Line. More...
 

Functions

void bm_ctrl (bool state)
 Enable/disable the board monitor. More...
 
bool bm_get_fifo_free_size (uint16_t *free_size)
 Return the free size (in byte) of the board monitor command fifo. More...
 
bool bm_get_firmware_version (uint8_t *fw_minor_version, uint8_t *fw_major_version)
 Get Firmware Version. More...
 
bool bm_get_mcu_current (uint32_t *sleep_mode, float *current)
 Return Current Consumption Measured. More...
 
void bm_init (void)
 Configure the USART. More...
 
void bm_led_clr (uint32_t led)
 Turn-off a LED of the board monitor. More...
 
void bm_led_set (uint32_t led)
 Turn-on a LED of the board monitor. More...
 
void bm_led_tgl (uint32_t led)
 Toggle a LED of the board monitor. More...
 
void bm_mouse_pointer_ctrl (bool state)
 Enable/disable the board monitor mouse-like pointer. More...
 
void bm_mouse_pointer_move (uint32_t x, uint32_t y)
 Send new mouse pointer position. More...
 
void bm_print_clear (void)
 Clear Print Text Area. More...
 
void bm_print_txt (uint8_t *str, uint8_t str_length)
 Print Text On Board Monitor. More...
 
void bm_pullup_twi (bool state)
 Enable/disable the pull-up on TWI lines. More...
 
void bm_send_mcu_status (uint32_t power_scaling, uint32_t sleep_mode, uint32_t cpu_freq, uint32_t cpu_src)
 Send MCU power saving information to the board monitor, in order to get them displayed on the OLED screen. More...
 
void bm_send_picouart_frame (uint8_t frame, uint32_t timeout_ms)
 Send PicoUart Frame. More...
 
void bm_tgl_button (uint32_t timeout_ms)
 Force Toggle of Button Line. More...
 

#define BM_CTRL   0x03

Enable/disable the board monitor.

Referenced by bm_ctrl().

#define BM_GET_FIRMWARE_VERSION   0x11

Send Firmware Version Request.

Referenced by bm_get_firmware_version().

#define BM_LED_CLR   0x05

Turn-off a LED of the board monitor.

Referenced by bm_led_clr().

#define BM_LED_SET   0x04

Turn-on a LED of the board monitor.

Referenced by bm_led_set().

#define BM_LED_TGL   0x06

Toggle a LED of the board monitor.

Referenced by bm_led_tgl().

#define BM_MCU_GET_CURRENT   0x0A

Send Current Consumption Measured Request.

Referenced by bm_get_mcu_current().

#define BM_MCU_GET_FIFO_FREE_SIZE   0x0D

Send free size (in byte) of the board monitor command fifo request.

Referenced by bm_get_fifo_free_size().

#define BM_MCU_RET_CURRENT   0x0C

Return Current Consumption Measured.

Referenced by bm_get_mcu_current().

#define BM_MCU_RET_FIFO_FREE_SIZE   0x0E

Return the free size (in byte) of the board monitor command fifo.

Referenced by bm_get_fifo_free_size().

#define BM_MCU_STATUS   0x07

Send MCU power saving information to the board monitor.

Referenced by bm_send_mcu_status().

#define BM_MSG_ID_DEFAULT   0

Board Monitor Message Default ID Message.

#define BM_MSG_LENGTH_DEFAULT   9

Board Monitor Message Number of bytes to transfer.

#define BM_PICOUART_SEND   0x09

Send PicoUart Frame.

Referenced by bm_send_picouart_frame().

#define BM_POINTER_CTRL   0x01

Enable/disable the board monitor mouse-like pointer.

Referenced by bm_mouse_pointer_ctrl().

#define BM_POINTER_MOVE   0x02

Send new mouse pointer position.

Referenced by bm_mouse_pointer_move().

#define BM_PRINT_CLEAR   0x10

Clear Print Text Area On Board Monitor.

Referenced by bm_print_clear().

#define BM_PRINT_TEXT   0x0F

Print Text On Board Monitor.

Referenced by bm_print_txt().

#define BM_PRINT_TEXT_DEEP   6
#define BM_PRINT_TEXT_SIZE   21

Referenced by bm_print_txt().

#define BM_PULLUP_TWI   0x08

Enable/disable the pull-up on TWI lines.

Referenced by bm_pullup_twi().

#define BM_RET_FIRMWARE_VERSION   0x12

Return Firmware Version value .

Referenced by bm_get_firmware_version().

#define BM_TGL_BUTTON   0x0B

Force Toggle of Button Line.

Referenced by bm_tgl_button().

void bm_ctrl ( bool  state)

Enable/disable the board monitor.

Parameters
statetrue to enable, false to disable.

References BM_CTRL, BM_MSG_START_PATTERN, BM_MSG_STOP_PATTERN, BM_USART_USART, usart_disable_tx(), usart_enable_tx(), usart_is_tx_empty(), and usart_putchar().

bool bm_get_fifo_free_size ( uint16_t *  free_size)
bool bm_get_firmware_version ( uint8_t *  fw_minor_version,
uint8_t *  fw_major_version 
)

Get Firmware Version.

Parameters
fw_minor_versionFirmware Version (in ascii format).
fw_major_versionFirmware Version (in ascii format).

References BM_GET_FIRMWARE_VERSION, BM_MSG_START_PATTERN, BM_MSG_STOP_PATTERN, BM_RET_FIRMWARE_VERSION, BM_USART_USART, delay_ms, usart_disable_rx(), usart_disable_tx(), usart_enable_rx(), usart_enable_tx(), usart_getchar(), usart_is_tx_empty(), and usart_putchar().

bool bm_get_mcu_current ( uint32_t *  sleep_mode,
float *  current 
)

Return Current Consumption Measured.

Parameters
sleep_modeSleep Mode Desired.
currentCurrent Value Measured.

References BM_MCU_GET_CURRENT, BM_MCU_RET_CURRENT, BM_MSG_START_PATTERN, BM_MSG_STOP_PATTERN, BM_USART_USART, usart_disable_rx(), usart_disable_tx(), usart_enable_rx(), usart_enable_tx(), usart_getchar(), usart_is_tx_empty(), and usart_putchar().

void bm_init ( void  )

Configure the USART.

Configure the board monitor.

References BM_USART_USART, sysclk_enable_peripheral_clock(), sysclk_get_peripheral_bus_hz(), and usart_init_rs232().

Referenced by ui_init().

void bm_led_clr ( uint32_t  led)

Turn-off a LED of the board monitor.

Parameters
ledled number. Range is [0; 3].

References BM_LED_CLR, BM_MSG_START_PATTERN, BM_MSG_STOP_PATTERN, BM_USART_USART, usart_disable_tx(), usart_enable_tx(), usart_is_tx_empty(), and usart_putchar().

void bm_led_set ( uint32_t  led)

Turn-on a LED of the board monitor.

Parameters
ledled number. Range is [0; 3].

References BM_LED_SET, BM_MSG_START_PATTERN, BM_MSG_STOP_PATTERN, BM_USART_USART, usart_disable_tx(), usart_enable_tx(), usart_is_tx_empty(), and usart_putchar().

void bm_led_tgl ( uint32_t  led)

Toggle a LED of the board monitor.

Parameters
ledled number. Range is [0; 3].

References BM_LED_TGL, BM_MSG_START_PATTERN, BM_MSG_STOP_PATTERN, BM_USART_USART, usart_disable_tx(), usart_enable_tx(), usart_is_tx_empty(), and usart_putchar().

void bm_mouse_pointer_ctrl ( bool  state)

Enable/disable the board monitor mouse-like pointer.

Parameters
statetrue to enable, false to disable.

References BM_MSG_START_PATTERN, BM_MSG_STOP_PATTERN, BM_POINTER_CTRL, BM_USART_USART, usart_disable_tx(), usart_enable_tx(), usart_is_tx_empty(), and usart_putchar().

Referenced by ui_init(), ui_uhi_hid_mouse_change(), and ui_usb_connection_event().

void bm_mouse_pointer_move ( uint32_t  x,
uint32_t  y 
)

Send new mouse pointer position.

Parameters
xx position. Range is [0; 127].
yy position range is [0; 63].

References BM_MSG_START_PATTERN, BM_MSG_STOP_PATTERN, BM_POINTER_MOVE, BM_USART_USART, usart_disable_tx(), usart_enable_tx(), usart_is_tx_empty(), and usart_putchar().

Referenced by ui_usb_sof_event().

void bm_print_txt ( uint8_t *  str,
uint8_t  str_length 
)

Print Text On Board Monitor.

Parameters
strString pattern.
str_lengthString length pattern.

References BM_MSG_START_PATTERN, BM_MSG_STOP_PATTERN, BM_PRINT_TEXT, BM_PRINT_TEXT_SIZE, BM_USART_USART, usart_disable_tx(), usart_enable_tx(), usart_is_tx_empty(), and usart_putchar().

void bm_pullup_twi ( bool  state)

Enable/disable the pull-up on TWI lines.

Parameters
statetrue to enable, false to disable.

References BM_MSG_START_PATTERN, BM_MSG_STOP_PATTERN, BM_PULLUP_TWI, BM_USART_USART, usart_disable_tx(), usart_enable_tx(), usart_is_tx_empty(), and usart_putchar().

void bm_send_mcu_status ( uint32_t  power_scaling,
uint32_t  sleep_mode,
uint32_t  cpu_freq,
uint32_t  cpu_src 
)

Send MCU power saving information to the board monitor, in order to get them displayed on the OLED screen.

Parameters
power_scalingPower scaling.
sleep_modeSleep mode.
cpu_freqCPU frequency.
cpu_srcCPU source clock.

References BM_MCU_STATUS, BM_MSG_START_PATTERN, BM_MSG_STOP_PATTERN, BM_USART_USART, usart_disable_tx(), usart_enable_tx(), usart_is_tx_empty(), and usart_putchar().

void bm_send_picouart_frame ( uint8_t  frame,
uint32_t  timeout_ms 
)

Send PicoUart Frame.

Note that the timeout countdown starts after a 500ms delay in order to keep a stable current measurement.

Parameters
frameFrame to be sent.
timeout_msTimeout value in ms.

References BM_MSG_START_PATTERN, BM_MSG_STOP_PATTERN, BM_PICOUART_SEND, BM_USART_USART, usart_disable_tx(), usart_enable_tx(), usart_is_tx_empty(), and usart_putchar().

void bm_tgl_button ( uint32_t  timeout_ms)

Force Toggle of Button Line.

Parameters
timeout_msTimeout value in ms.

References BM_MSG_START_PATTERN, BM_MSG_STOP_PATTERN, BM_TGL_BUTTON, BM_USART_USART, usart_disable_tx(), usart_enable_tx(), usart_is_tx_empty(), and usart_putchar().