Browse Source

Resolve #174 by replacing and modifying logic according to another model.

master
parent
commit
bb6402bbd6
100 changed files with 3018 additions and 24870 deletions
  1. +1687
    -2167
      firmware/SendcommPeer2P/SendcommPeer2P.cproj
  2. +1
    -4
      firmware/SendcommPeer2P/src/ASF/common/boards/board.h
  3. +3
    -17
      firmware/SendcommPeer2P/src/ASF/common/utils/parts.h
  4. +0
    -175
      firmware/SendcommPeer2P/src/ASF/common2/components/display/ssd1306/ssd1306.c
  5. +0
    -330
      firmware/SendcommPeer2P/src/ASF/common2/components/display/ssd1306/ssd1306.h
  6. BIN
      firmware/SendcommPeer2P/src/ASF/common2/services/gfx_mono/docsrc/gfx_mono_overview.png
  7. +0
    -320
      firmware/SendcommPeer2P/src/ASF/common2/services/gfx_mono/gfx_mono.h
  8. +0
    -256
      firmware/SendcommPeer2P/src/ASF/common2/services/gfx_mono/gfx_mono_framebuffer.c
  9. +0
    -86
      firmware/SendcommPeer2P/src/ASF/common2/services/gfx_mono/gfx_mono_framebuffer.h
  10. +0
    -496
      firmware/SendcommPeer2P/src/ASF/common2/services/gfx_mono/gfx_mono_generic.c
  11. +0
    -121
      firmware/SendcommPeer2P/src/ASF/common2/services/gfx_mono/gfx_mono_generic.h
  12. +0
    -687
      firmware/SendcommPeer2P/src/ASF/common2/services/gfx_mono/gfx_mono_spinctrl.c
  13. +0
    -241
      firmware/SendcommPeer2P/src/ASF/common2/services/gfx_mono/gfx_mono_spinctrl.h
  14. +0
    -415
      firmware/SendcommPeer2P/src/ASF/common2/services/gfx_mono/gfx_mono_text.c
  15. +0
    -167
      firmware/SendcommPeer2P/src/ASF/common2/services/gfx_mono/gfx_mono_text.h
  16. +0
    -362
      firmware/SendcommPeer2P/src/ASF/common2/services/gfx_mono/gfx_mono_ug_2832hsweg04.c
  17. +0
    -158
      firmware/SendcommPeer2P/src/ASF/common2/services/gfx_mono/gfx_mono_ug_2832hsweg04.h
  18. +0
    -65
      firmware/SendcommPeer2P/src/ASF/common2/services/gfx_mono/sysfont.c
  19. +0
    -60
      firmware/SendcommPeer2P/src/ASF/common2/services/gfx_mono/sysfont.h
  20. +0
    -58
      firmware/SendcommPeer2P/src/ASF/common2/services/gfx_mono/tools/bitmap.py
  21. +0
    -133
      firmware/SendcommPeer2P/src/ASF/common2/services/gfx_mono/tools/dump_display_over_serial.py
  22. +0
    -6
      firmware/SendcommPeer2P/src/ASF/common2/services/gfx_mono/tools/readme.txt
  23. +35
    -24
      firmware/SendcommPeer2P/src/ASF/sam0/boards/samr34_sendcomm/board_init.c
  24. +9
    -9
      firmware/SendcommPeer2P/src/ASF/sam0/boards/samr34_sendcomm/samr34_sendcomm.h
  25. +3
    -3
      firmware/SendcommPeer2P/src/ASF/sam0/drivers/extint/extint.h
  26. +2
    -2
      firmware/SendcommPeer2P/src/ASF/sam0/drivers/extint/extint_sam_l_c/extint.c
  27. +5
    -5
      firmware/SendcommPeer2P/src/ASF/sam0/drivers/nvm/nvm.c
  28. +2
    -2
      firmware/SendcommPeer2P/src/ASF/sam0/drivers/nvm/nvm.h
  29. +1
    -1
      firmware/SendcommPeer2P/src/ASF/sam0/drivers/port/port.h
  30. +3
    -3
      firmware/SendcommPeer2P/src/ASF/sam0/drivers/rtc/rtc_count.h
  31. +2
    -2
      firmware/SendcommPeer2P/src/ASF/sam0/drivers/rtc/rtc_sam_l_c/rtc_count.c
  32. +0
    -607
      firmware/SendcommPeer2P/src/ASF/sam0/drivers/sercom/i2c/i2c_common.h
  33. +0
    -619
      firmware/SendcommPeer2P/src/ASF/sam0/drivers/sercom/i2c/i2c_master.h
  34. +0
    -1040
      firmware/SendcommPeer2P/src/ASF/sam0/drivers/sercom/i2c/i2c_sam0/i2c_master.c
  35. +0
    -108
      firmware/SendcommPeer2P/src/ASF/sam0/drivers/sercom/i2c/quick_start_master/qs_i2c_master_basic_use.h
  36. +0
    -164
      firmware/SendcommPeer2P/src/ASF/sam0/drivers/sercom/i2c/quick_start_master_dma/qs_i2c_master_dma.h
  37. +1
    -1
      firmware/SendcommPeer2P/src/ASF/sam0/drivers/sercom/sercom_pinout.h
  38. +145
    -0
      firmware/SendcommPeer2P/src/ASF/sam0/drivers/sercom/spi/quick_start_master_callback/qs_spi_master_callback.h
  39. +139
    -0
      firmware/SendcommPeer2P/src/ASF/sam0/drivers/sercom/spi/quick_start_slave_callback/qs_spi_slave_callback.h
  40. +2
    -2
      firmware/SendcommPeer2P/src/ASF/sam0/drivers/sercom/spi/spi.c
  41. +1
    -1
      firmware/SendcommPeer2P/src/ASF/sam0/drivers/sercom/spi/spi.h
  42. +731
    -0
      firmware/SendcommPeer2P/src/ASF/sam0/drivers/sercom/spi/spi_interrupt.c
  43. +180
    -0
      firmware/SendcommPeer2P/src/ASF/sam0/drivers/sercom/spi/spi_interrupt.h
  44. +3
    -13
      firmware/SendcommPeer2P/src/ASF/sam0/drivers/sercom/usart/usart.c
  45. +1
    -1
      firmware/SendcommPeer2P/src/ASF/sam0/drivers/sercom/usart/usart.h
  46. +1
    -1
      firmware/SendcommPeer2P/src/ASF/sam0/drivers/system/clock/gclk.h
  47. +1
    -1
      firmware/SendcommPeer2P/src/ASF/sam0/drivers/system/pinmux/pinmux.h
  48. +14
    -14
      firmware/SendcommPeer2P/src/ASF/sam0/drivers/system/power/power_sam_l/power.h
  49. +3
    -3
      firmware/SendcommPeer2P/src/ASF/sam0/drivers/system/reset/reset_sam_l/reset.h
  50. +12
    -12
      firmware/SendcommPeer2P/src/ASF/sam0/drivers/tc/tc.h
  51. +1
    -1
      firmware/SendcommPeer2P/src/ASF/sam0/drivers/tc/tc_interrupt.c
  52. +1
    -1
      firmware/SendcommPeer2P/src/ASF/sam0/drivers/tc/tc_interrupt.h
  53. +1
    -1
      firmware/SendcommPeer2P/src/ASF/sam0/drivers/tc/tc_sam_l_c/tc.c
  54. +0
    -4
      firmware/SendcommPeer2P/src/ASF/sam0/utils/header_files/io.h
  55. +28
    -31
      firmware/SendcommPeer2P/src/ASF/sam0/utils/linker_scripts/samr34/gcc/samr34j18b_flash.ld
  56. +0
    -111
      firmware/SendcommPeer2P/src/ASF/thirdparty/CMSIS/license.txt
  57. +0
    -23
      firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/EULA.txt
  58. +0
    -1458
      firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/include/miwi_api.h
  59. +0
    -35
      firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/license.txt
  60. +0
    -192
      firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/lcd/lcd.c
  61. +0
    -126
      firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/lcd/lcd.h
  62. +0
    -136
      firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/pds/inc/nv/D_Nv.h
  63. +0
    -40
      firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/pds/inc/nv/D_Nv_Bindings.h
  64. +0
    -46
      firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/pds/inc/nv/D_Nv_Init.h
  65. +0
    -127
      firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/pds/inc/nv/External/D_XNv.h
  66. +0
    -40
      firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/pds/inc/nv/External/D_XNv_Bindings.h
  67. +0
    -81
      firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/pds/inc/nv/External/D_XNv_Init.h
  68. +0
    -186
      firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/pds/inc/nv/External/S_XNv.h
  69. +0
    -70
      firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/pds/inc/nv/External/S_XNv_Bindings.h
  70. +0
    -92
      firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/pds/inc/nv/External/S_XNv_Init.h
  71. +0
    -216
      firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/pds/inc/nv/S_Nv.h
  72. +0
    -71
      firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/pds/inc/nv/S_Nv_Bindings.h
  73. +0
    -91
      firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/pds/inc/nv/S_Nv_Init.h
  74. +0
    -48
      firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/pds/inc/nv/S_Nv_Internal.h
  75. +0
    -386
      firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/pds/inc/pdsDataServer.h
  76. +0
    -42
      firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/pds/inc/pdsMemIds.h
  77. +0
    -55
      firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/pds/inc/wl/wlPdsBindings.h
  78. +0
    -110
      firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/pds/inc/wl/wlPdsMemIds.h
  79. +0
    -66
      firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/pds/inc/wl/wlPdsTaskManager.h
  80. +0
    -61
      firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/pds/inc/wl/wlPdsTypes.h
  81. +0
    -237
      firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/pds/inc/wl/wlPdsTypesConverter.h
  82. +0
    -262
      firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/pds/src/nv/D_Nv.c
  83. +0
    -425
      firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/pds/src/nv/External/D_XNv-SamR21.c
  84. +0
    -113
      firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/pds/src/nv/External/S_Nv-External.c
  85. +0
    -1713
      firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/pds/src/nv/External/S_XNv.c
  86. +0
    -1742
      firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/pds/src/nv/S_Nv-SamR21.c
  87. +0
    -410
      firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/pds/src/wl/wlPdsDataServer.c
  88. +0
    -99
      firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/pds/src/wl/wlPdsInit.c
  89. +0
    -99
      firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/pds/src/wl/wlPdsTaskManager.c
  90. +0
    -182
      firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/pds/src/wl/wlPdsTypesConverter.c
  91. +0
    -1534
      firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/source/mimac/mimac.c
  92. +0
    -624
      firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/source/mimac/mimac.h
  93. +0
    -337
      firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/source/mimac/phy/phy.h
  94. +0
    -589
      firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/source/mimac/phy/sx1276/phy.c
  95. +0
    -85
      firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/source/miwi_p2p_star/miwi_nvm.h
  96. +0
    -2947
      firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/source/miwi_p2p_star/miwi_p2p.c
  97. +0
    -212
      firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/source/miwi_p2p_star/miwi_p2p.h
  98. +0
    -68
      firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/source/miwi_p2p_star/miwi_p2p_pds.c
  99. +0
    -233
      firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/source/sys/mimem.c
  100. +0
    -50
      firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/source/sys/mimem.h

+ 1687
- 2167
firmware/SendcommPeer2P/SendcommPeer2P.cproj
File diff suppressed because it is too large
View File


+ 1
- 4
firmware/SendcommPeer2P/src/ASF/common/boards/board.h View File

@@ -158,7 +158,6 @@ extern "C" {
#define SAMR30_MODULE_XPLAINED_PRO 102 //!< SAM R30 Module Xplained Pro board.
#define SAMR21G18_MODULE 103 //!< SAMR21G18-MR210UA Module.
#define SAMR21B18_MODULE 104 //!< SAMR21B18-MZ210PA Module.
#define WLR089_XPLAINED_PRO 105 //!< WLR089_XPLAINED_PRO board.
#define SAMR34_SENDCOMM 123 //!< SAMR34 Sendcomm board.
//! @}

@@ -384,13 +383,11 @@ extern "C" {
# include "samr21b18_module/samr21b18_module.h"
#elif BOARD == SAMR34_XPLAINED_PRO && defined(__SAMR34J18B__)
# include "samr34_xplained_pro/samr34_xplained_pro.h"
#elif BOARD == WLR089_XPLAINED_PRO && defined(__WLR089U0__)
# include "wlr089_xplained_pro/wlr089_xplained_pro.h"
#elif BOARD == USER_BOARD
// User-reserved area: #include the header file of your board here (if any).
# include "user_board.h"
#elif BOARD == SAMR34_SENDCOMM && defined(__SAMR34J18B__)
# include "samr34_sendcomm/samr34_sendcomm.h"
# include "user_board.h"
#elif BOARD == DUMMY_BOARD
# include "dummy/dummy_board.h"
#elif BOARD == SAMB11ZR_SENSOR_TAG


+ 3
- 17
firmware/SendcommPeer2P/src/ASF/common/utils/parts.h View File

@@ -3,7 +3,7 @@
*
* \brief Atmel part identification macros
*
* Copyright (c) 2012-2020 Microchip Technology Inc. and its subsidiaries.
* Copyright (c) 2012-2018 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
@@ -974,7 +974,6 @@
SAM_PART_IS_DEFINED(SAMR35J17B) || \
SAM_PART_IS_DEFINED(SAMR35J16B) \
)

/* Group for SAMR35 B variant: SAMR35J [16/17/18]B */
#define SAMR35JXXB ( \
SAM_PART_IS_DEFINED(SAMR35J18B) || \
@@ -982,16 +981,6 @@
SAM_PART_IS_DEFINED(SAMR35J16B) \
)

/* Group for SAMR35 B variant: SAMR35J [16/17/18]B */
#define WLR089U ( \
SAM_PART_IS_DEFINED(WLR089U0) \
)

/* Group for WLR089U variant: SAMR35U [0] */
#define WLR089U0 ( \
SAM_PART_IS_DEFINED(WLR089U0) \
)

/**
* \name SAMB11 series
* @{
@@ -1685,9 +1674,6 @@
/** SAMR35 Family */
#define SAMR35 (SAMR35J)

/** SAMR35 Family */
#define WLR089 (WLR089U)

/** SAMB11 Family */
#define SAMB11 (SAMB11G || BTLC1000)

@@ -1751,7 +1737,7 @@
/** SAM0 product line (cortex-m0+) */
#define SAM0 (SAMD20 || SAMD21 || SAMR21 || SAMD10 || SAMD11 || SAML21 ||\
SAMDA1 || SAMC20 || SAMC21 || SAML22 || SAMD09 || SAMR30 || SAMHA1 ||\
SAMHA0 || SAMR34 || SAMR35 || WLR089)
SAMHA0 || SAMR34 || SAMR35)

/** @} */

@@ -1765,4 +1751,4 @@

/** @} */

#endif /* ATMEL_PARTS_H */
#endif /* ATMEL_PARTS_H */

+ 0
- 175
firmware/SendcommPeer2P/src/ASF/common2/components/display/ssd1306/ssd1306.c View File

@@ -1,175 +0,0 @@
/**
* \file
*
* \brief SSD1306 OLED display controller driver.
*
* Copyright (c) 2012-2018 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/
/*
* Support and FAQ: visit <a href="https://www.microchip.com/support/">Microchip Support</a>
*/
#include "ssd1306.h"

struct spi_module ssd1306_master;
struct spi_slave_inst ssd1306_slave;

/**
* \internal
* \brief Initialize the hardware interface
*
* Depending on what interface used for interfacing the OLED controller this
* function will initialize the necessary hardware.
*/
static void ssd1306_interface_init(void)
{
struct spi_config config;
struct spi_slave_inst_config slave_config;

spi_slave_inst_get_config_defaults(&slave_config);
slave_config.ss_pin = SSD1306_CS_PIN;
spi_attach_slave(&ssd1306_slave, &slave_config);

spi_get_config_defaults(&config);

config.mux_setting = SSD1306_SPI_PINMUX_SETTING;
config.pinmux_pad0 = SSD1306_SPI_PINMUX_PAD0;
config.pinmux_pad1 = SSD1306_SPI_PINMUX_PAD1;
config.pinmux_pad2 = SSD1306_SPI_PINMUX_PAD2;
config.pinmux_pad3 = SSD1306_SPI_PINMUX_PAD3;
config.mode_specific.master.baudrate = SSD1306_CLOCK_SPEED;

spi_init(&ssd1306_master, SSD1306_SPI, &config);
spi_enable(&ssd1306_master);

struct port_config pin;
port_get_config_defaults(&pin);
pin.direction = PORT_PIN_DIR_OUTPUT;

port_pin_set_config(SSD1306_DC_PIN, &pin);
port_pin_set_config(SSD1306_RES_PIN, &pin);
}

/**
* \brief Initialize the OLED controller
*
* Call this function to initialize the hardware interface and the OLED
* controller. When initialization is done the display is turned on and ready
* to receive data.
*/
void ssd1306_init(void)
{
// Initialize delay routine
delay_init();

// Initialize the interface
ssd1306_interface_init();

// Do a hard reset of the OLED display controller
ssd1306_hard_reset();

// Set the reset pin to the default state
port_pin_set_output_level(SSD1306_RES_PIN, true);

// 1/32 Duty (0x0F~0x3F)
ssd1306_write_command(SSD1306_CMD_SET_MULTIPLEX_RATIO);
ssd1306_write_command(0x1F);

// Shift Mapping RAM Counter (0x00~0x3F)
ssd1306_write_command(SSD1306_CMD_SET_DISPLAY_OFFSET);
ssd1306_write_command(0x00);

// Set Mapping RAM Display Start Line (0x00~0x3F)
ssd1306_write_command(SSD1306_CMD_SET_DISPLAY_START_LINE(0x00));

// Set Column Address 0 Mapped to SEG0
ssd1306_write_command(SSD1306_CMD_SET_SEGMENT_RE_MAP_COL127_SEG0);

// Set COM/Row Scan Scan from COM63 to 0
ssd1306_write_command(SSD1306_CMD_SET_COM_OUTPUT_SCAN_DOWN);

// Set COM Pins hardware configuration
ssd1306_write_command(SSD1306_CMD_SET_COM_PINS);
ssd1306_write_command(0x02);

ssd1306_set_contrast(0x8F);

// Disable Entire display On
ssd1306_write_command(SSD1306_CMD_ENTIRE_DISPLAY_AND_GDDRAM_ON);

ssd1306_display_invert_disable();

// Set Display Clock Divide Ratio / Oscillator Frequency (Default => 0x80)
ssd1306_write_command(SSD1306_CMD_SET_DISPLAY_CLOCK_DIVIDE_RATIO);
ssd1306_write_command(0x80);

// Enable charge pump regulator
ssd1306_write_command(SSD1306_CMD_SET_CHARGE_PUMP_SETTING);
ssd1306_write_command(0x14);

// Set VCOMH Deselect Level
ssd1306_write_command(SSD1306_CMD_SET_VCOMH_DESELECT_LEVEL);
ssd1306_write_command(0x40); // Default => 0x20 (0.77*VCC)

// Set Pre-Charge as 15 Clocks & Discharge as 1 Clock
ssd1306_write_command(SSD1306_CMD_SET_PRE_CHARGE_PERIOD);
ssd1306_write_command(0xF1);

ssd1306_display_on();
}

/**
* \brief Writes a command to the display controller
*
* This functions pull pin D/C# low before writing to the controller. Different
* data write function is called based on the selected interface.
*
* \param command the command to write
*/
void ssd1306_write_command(uint8_t command)
{
spi_select_slave(&ssd1306_master, &ssd1306_slave, true);
port_pin_set_output_level(SSD1306_DC_PIN, false);
spi_write_buffer_wait(&ssd1306_master, &command, 1);
spi_select_slave(&ssd1306_master, &ssd1306_slave, false);
}

/**
* \brief Write data to the display controller
*
* This functions sets the pin D/C# before writing to the controller. Different
* data write function is called based on the selected interface.
*
* \param data the data to write
*/
void ssd1306_write_data(uint8_t data)
{
spi_select_slave(&ssd1306_master, &ssd1306_slave, true);
port_pin_set_output_level(SSD1306_DC_PIN, true);
spi_write_buffer_wait(&ssd1306_master, &data, 1);
spi_select_slave(&ssd1306_master, &ssd1306_slave, false);
}

+ 0
- 330
firmware/SendcommPeer2P/src/ASF/common2/components/display/ssd1306/ssd1306.h View File

@@ -1,330 +0,0 @@
/**
* \file
*
* \brief SSD1306 OLED display controller driver.
*
* Copyright (c) 2012-2018 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/
/*
* Support and FAQ: visit <a href="https://www.microchip.com/support/">Microchip Support</a>
*/
#ifndef SSD1306_H_INCLUDED
#define SSD1306_H_INCLUDED

#include <compiler.h>
#include <port.h>
#include <spi.h>
#include <delay.h>

// controller and OLED configuration file
#include "conf_ssd1306.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* \defgroup ssd1306_oled_controller_group SSD1306 OLED Controller Low-level\
* driver
*
* This is a low level driver for the SSD1306 OLED controller through 4-wire SPI.
* It provides basic functions for initializing and writing to the OLED
* controller. In addition to hardware control and use of the OLED controller
* internal functions.
*
* Before writing data to the display call \ref ssd1306_init() which will set up
* the physical interface and the OLED. A file named \ref conf_ssd1306.h is needed
* to define which interface to use. For more information see the Interface
* selection section. In addition one also need to define the pins
* \ref SSD1306_DC_PIN, \ref SSD1306_CS_PIN and \ref SSD1306_RES_PIN and the
* display \ref SSD1306_CLOCK_SPEED.
*
* \warning This driver is not reentrant and can not be used in interrupt\
* service routines without extra care.
*
*
* An example \ref conf_ssd1306.h file could look like
* \code
// interface selection
#define SSD1306_SPI SERCOM2

#define SSD1306_CLOCK_SPEED 1000000

#define SSD1306_DC_PIN PIN_PB24
#define SSD1306_CS_PIN PIN_PB27
#define SSD1306_RES_PIN PIN_PA17
\endcode
*
* \section dependencies Dependencies
* This driver depends on the following modules:
* - \ref asfdoc_sam0_port_group for IO port control.
* - \ref asfdoc_sam0_system_group for getting system clock speeds for init functions.
* - \ref asfdoc_sam0_sercom_spi_group for communication with the OLED controller
* - \ref asfdoc_sam0_sercom_spi_group for communication with the OLED controller
* @{
*/

//! \name Fundamental Command defines
//@{
#define SSD1306_CMD_COL_ADD_SET_LSB(column) (0x00 | (column))
#define SSD1306_CMD_COL_ADD_SET_MSB(column) (0x10 | (column))
#define SSD1306_CMD_SET_MEMORY_ADDRESSING_MODE 0x20
#define SSD1306_CMD_SET_COLUMN_ADDRESS 0x21
#define SSD1306_CMD_SET_PAGE_ADDRESS 0x22
#define SSD1306_CMD_SET_DISPLAY_START_LINE(line) (0x40 | (line))
#define SSD1306_CMD_SET_CONTRAST_CONTROL_FOR_BANK0 0x81
#define SSD1306_CMD_SET_CHARGE_PUMP_SETTING 0x8D
#define SSD1306_CMD_SET_SEGMENT_RE_MAP_COL0_SEG0 0xA0
#define SSD1306_CMD_SET_SEGMENT_RE_MAP_COL127_SEG0 0xA1
#define SSD1306_CMD_ENTIRE_DISPLAY_AND_GDDRAM_ON 0xA4
#define SSD1306_CMD_ENTIRE_DISPLAY_ON 0xA5
#define SSD1306_CMD_SET_NORMAL_DISPLAY 0xA6
#define SSD1306_CMD_SET_INVERSE_DISPLAY 0xA7
#define SSD1306_CMD_SET_MULTIPLEX_RATIO 0xA8
#define SSD1306_CMD_SET_DISPLAY_ON 0xAF
#define SSD1306_CMD_SET_DISPLAY_OFF 0xAE
#define SSD1306_CMD_SET_PAGE_START_ADDRESS(page) (0xB0 | (page))
#define SSD1306_CMD_SET_COM_OUTPUT_SCAN_UP 0xC0
#define SSD1306_CMD_SET_COM_OUTPUT_SCAN_DOWN 0xC8
#define SSD1306_CMD_SET_DISPLAY_OFFSET 0xD3
#define SSD1306_CMD_SET_DISPLAY_CLOCK_DIVIDE_RATIO 0xD5
#define SSD1306_CMD_SET_PRE_CHARGE_PERIOD 0xD9
#define SSD1306_CMD_SET_COM_PINS 0xDA
#define SSD1306_CMD_SET_VCOMH_DESELECT_LEVEL 0xDB
#define SSD1306_CMD_NOP 0xE3
//@}
//! \name Graphic Acceleration Command defines
//@{
#define SSD1306_CMD_SCROLL_H_RIGHT 0x26
#define SSD1306_CMD_SCROLL_H_LEFT 0x27
#define SSD1306_CMD_CONTINUOUS_SCROLL_V_AND_H_RIGHT 0x29
#define SSD1306_CMD_CONTINUOUS_SCROLL_V_AND_H_LEFT 0x2A
#define SSD1306_CMD_DEACTIVATE_SCROLL 0x2E
#define SSD1306_CMD_ACTIVATE_SCROLL 0x2F
#define SSD1306_CMD_SET_VERTICAL_SCROLL_AREA 0xA3
//@}

/**
* \name Interface selection
*
* The OLED controller support both serial and parallel mode, that means there
* is a number of possible ways of interfacing the controller using different
* SAM peripherals. The different interfaces can be selected using different
* defines. This driver supports the serial communication mode using an
* SPI Master.
*
* \note The current driver only support serial mode.
*/
/** @{@} */

extern struct spi_module ssd1306_master;
extern struct spi_slave_inst ssd1306_slave;

//! \name OLED controller write and read functions
//@{
void ssd1306_write_command(uint8_t command);

void ssd1306_write_data(uint8_t data);

/**
* \brief Read data from the controller
*
* \note The controller does not support read in serial mode.
*
* \retval 8 bit data read from the controller
*/
static inline uint8_t ssd1306_read_data(void)
{
return 0;
}

/**
* \brief Read status from the controller
*
* \note The controller does not support read in serial mode.
*
* \retval 8 bit status read from the controller
*/
static inline uint8_t ssd1306_get_status(void)
{
return 0;
}
//@}

//! \name OLED Controller reset
//@{

/**
* \brief Perform a hard reset of the OLED controller
*
* This functions will reset the OLED controller by setting the reset pin low.
*/
static inline void ssd1306_hard_reset(void)
{
uint32_t delay_10us = 10 * (system_gclk_gen_get_hz(0)/1000000);
port_pin_set_output_level(SSD1306_RES_PIN, false);
delay_cycles(delay_10us); // At lest 10us
port_pin_set_output_level(SSD1306_RES_PIN, true);
delay_cycles(delay_10us); // At lest 10us
}
//@}

//! \name Sleep control
//@{
/**
* \brief Enable the OLED sleep mode
*/
static inline void ssd1306_sleep_enable(void)
{
ssd1306_write_command(SSD1306_CMD_SET_DISPLAY_OFF);
}

/**
* \brief Disable the OLED sleep mode
*/
static inline void ssd1306_sleep_disable(void)
{
ssd1306_write_command(SSD1306_CMD_SET_DISPLAY_ON);
}
//@}

//! \name Address setup for the OLED
//@{
/**
* \brief Set current page in display RAM
*
* This command is usually followed by the configuration of the column address
* because this scheme will provide access to all locations in the display
* RAM.
*
* \param address the page address
*/
static inline void ssd1306_set_page_address(uint8_t address)
{
// Make sure that the address is 4 bits (only 8 pages)
address &= 0x0F;
ssd1306_write_command(SSD1306_CMD_SET_PAGE_START_ADDRESS(address));
}

/**
* \brief Set current column in display RAM
*
* \param address the column address
*/
static inline void ssd1306_set_column_address(uint8_t address)
{
// Make sure the address is 7 bits
address &= 0x7F;
ssd1306_write_command(SSD1306_CMD_COL_ADD_SET_MSB(address >> 4));
ssd1306_write_command(SSD1306_CMD_COL_ADD_SET_LSB(address & 0x0F));
}

/**
* \brief Set the display start draw line address
*
* This function will set which line should be the start draw line for the OLED.
*/
static inline void ssd1306_set_display_start_line_address(uint8_t address)
{
// Make sure address is 6 bits
address &= 0x3F;
ssd1306_write_command(SSD1306_CMD_SET_DISPLAY_START_LINE(address));
}
//@}

//! \name Display hardware control
//@{
/**
* \brief Turn the OLED display on
*
* This function will turn on the OLED.
*/
static inline void ssd1306_display_on(void)
{
ssd1306_write_command(SSD1306_CMD_SET_DISPLAY_ON);
}

/**
* \brief Turn the OLED display off
*
* This function will turn off the OLED.
*/
static inline void ssd1306_display_off(void)
{
ssd1306_write_command(SSD1306_CMD_SET_DISPLAY_OFF);
}

/**
* \brief Set the OLED contrast level
*
* \param contrast a number between 0 and 0xFF
*
* \retval contrast the contrast value written to the OLED controller
*/
static inline uint8_t ssd1306_set_contrast(uint8_t contrast)
{
ssd1306_write_command(SSD1306_CMD_SET_CONTRAST_CONTROL_FOR_BANK0);
ssd1306_write_command(contrast);
return contrast;
}

/**
* \brief Invert all pixels on the device
*
* This function will invert all pixels on the OLED
*
*/
static inline void ssd1306_display_invert_enable(void)
{
ssd1306_write_command(SSD1306_CMD_SET_INVERSE_DISPLAY);
}

/**
* \brief Disable invert of all pixels on the device
*
* This function will disable invert on all pixels on the OLED
*
*/
static inline void ssd1306_display_invert_disable(void)
{
ssd1306_write_command(SSD1306_CMD_SET_NORMAL_DISPLAY);
}
//@}

//! \name Initialization
//@{
void ssd1306_init(void);
//@}

/** @} */

#ifdef __cplusplus
}
#endif

#endif /* SSD1306_H_INCLUDED */

BIN
firmware/SendcommPeer2P/src/ASF/common2/services/gfx_mono/docsrc/gfx_mono_overview.png View File

Before After
Width: 709  |  Height: 1049  |  Size: 125KB

+ 0
- 320
firmware/SendcommPeer2P/src/ASF/common2/services/gfx_mono/gfx_mono.h View File

@@ -1,320 +0,0 @@
/**
* \file
*
* \brief Monochrome graphic library API header file
*
* Copyright (c) 2011-2018 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/
/*
* Support and FAQ: visit <a href="https://www.microchip.com/support/">Microchip Support</a>
*/
#ifndef GFX_MONO_H
#define GFX_MONO_H

#include <stdint.h>

#include "compiler.h"

#ifndef PROGMEM_DECLARE
# define PROGMEM_DECLARE(type, name) const type name
# define PROGMEM_T const
# define PROGMEM_PTR_T const *
# define PROGMEM_READ_BYTE(x) *(x)
# define PROGMEM_STRING_T const char*
#endif

/**
* \defgroup asfdoc_common2_gfx_mono Monochrome graphical display system
*
* See \ref asfdoc_common2_gfx_mono_quickstart.
*
* This library provides an interface to drawing graphics on monochrome
* graphical displays
*
* The graphics drivers consists of the following:
* - Display driver interface (gfx_mono.h)
* - General graphics drawing primitives (gfx_mono_generic.h)
* - Display specific implementation (ex. gfx_mono_ug_2832hsweg04.h)
*
* The generic drawing primitives is a library of functions for drawing
* graphics primitives such as lines, rectangles and circles. It uses other
* functions implemented by the display driver for drawing the primitives. The
* implementation of these functions can optionally be used by a display
* driver, but if the hardware of the display allows faster handling of any of
* the primitives, the display driver can implement it directly.
*
* The display specific drivers provides an interface to the graphical display.
* It implements the low level communication with the display hardware, putting
* pixels on the display and drawing primitives such as lines, circles and
* rectangles. Depending on the display driver implementation, drawing the
* graphics primitives might be handled by the generic graphics drawing
* primitives rather than the display driver itself.
*
* \section asfdoc_common2_gfx_mono_examples Examples
* The following examples are available for the driver:
* - \ref asfdoc_common2_gfx_mono_quickstart
* - \ref asfdoc_common2_gfx_mono_sysfont_example
* - \ref asfdoc_common2_gfx_mono_spinner_example
*
* \section asfdoc_common2_gfx_mono_api_overview API Overview
*
* \note The functions in the library are not interrupt safe.
* @{
*/

typedef uint8_t gfx_mono_color_t;
typedef uint8_t gfx_coord_t;

/** Pixel operations */
enum gfx_mono_color {
/** Pixel is cleared */
GFX_PIXEL_CLR = 0,
/** Pixel is set on screen (OR) */
GFX_PIXEL_SET = 1,
/** Pixel is XORed */
GFX_PIXEL_XOR = 2,
};

/** Bitmap types */
enum gfx_mono_bitmap_type {
/** Bitmap stored in SRAM */
GFX_MONO_BITMAP_RAM,
/** Bitmap stored in progmem */
GFX_MONO_BITMAP_PROGMEM
};

/* Cannot be moved to top, as they use the bitmap and color enums. */
#ifdef USE_SDL
# include "gfx_mono_sdl.h"
#elif defined(GFX_MONO_C12832_A1Z)
# include "gfx_mono_c12832_a1z.h"
#elif defined(GFX_MONO_UG_2832HSWEG04)
# include "gfx_mono_ug_2832hsweg04.h"
#else
/* NULL driver by default */
# include "gfx_mono_null.h"
#endif
#include "gfx_mono_generic.h"

/** \name Circle Sector Definitions */
/** @{ */

/** Bitmask for drawing circle octant 0. */
#define GFX_OCTANT0 (1 << 0)
/** Bitmask for drawing circle octant 1. */
#define GFX_OCTANT1 (1 << 1)
/** Bitmask for drawing circle octant 2. */
#define GFX_OCTANT2 (1 << 2)
/** Bitmask for drawing circle octant 3. */
#define GFX_OCTANT3 (1 << 3)
/** Bitmask for drawing circle octant 4. */
#define GFX_OCTANT4 (1 << 4)
/** Bitmask for drawing circle octant 5. */
#define GFX_OCTANT5 (1 << 5)
/** Bitmask for drawing circle octant 6. */
#define GFX_OCTANT6 (1 << 6)
/** Bitmask for drawing circle octant 7. */
#define GFX_OCTANT7 (1 << 7)

/** Bitmask for drawing circle quadrant 0. */
#define GFX_QUADRANT0 (GFX_OCTANT0 | GFX_OCTANT1)
/** Bitmask for drawing circle quadrant 1. */
#define GFX_QUADRANT1 (GFX_OCTANT2 | GFX_OCTANT3)
/** Bitmask for drawing circle quadrant 2. */
#define GFX_QUADRANT2 (GFX_OCTANT4 | GFX_OCTANT5)
/** Bitmask for drawing circle quadrant 3. */
#define GFX_QUADRANT3 (GFX_OCTANT6 | GFX_OCTANT7)

/** Bitmask for drawing left half of circle. */
#define GFX_LEFTHALF (GFX_QUADRANT3 | GFX_QUADRANT0)
/** Bitmask for drawing top half of circle. */
#define GFX_TOPHALF (GFX_QUADRANT0 | GFX_QUADRANT1)
/** Bitmask for drawing right half of circle. */
#define GFX_RIGHTHALF (GFX_QUADRANT1 | GFX_QUADRANT2)
/** Bitmask for drawing bottom half of circle. */
#define GFX_BOTTOMHALF (GFX_QUADRANT2 | GFX_QUADRANT3)

/** Bitmask for drawing whole circle. */
#define GFX_WHOLE 0xFF

/** @} */

/** \name Graphic Drawing Primitives */
/** @{ */

/**
* \def gfx_mono_draw_horizontal_line(x, y, length, color)
* \brief Draw a horizontal line, one pixel wide.
*
* \param[in] x X coordinate of leftmost pixel.
* \param[in] y Y coordinate of the line.
* \param[in] length Length of the line in pixels.
* \param[in] color Pixel operation of the line.
*/

/**
* \def gfx_mono_draw_vertical_line(x, y, length, color)
* \brief Draw a vertical line, one pixel wide.
*
* \param[in] x X coordinate of the line.
* \param[in] y Y coordinate of the topmost pixel.
* \param[in] length Length of the line in pixels.
* \param[in] color Pixel operation of the line.
*/

/**
* \def gfx_mono_draw_line(x1, y1, x2, y2, color)
* \brief Draw a line between two arbitrary points.
*
* \param[in] x1 Start X coordinate.
* \param[in] y1 Start Y coordinate.
* \param[in] x2 End X coordinate.
* \param[in] y2 End Y coordinate.
* \param[in] color Pixel operation of the line.
*/

/**
* \def gfx_mono_draw_rect(x, y, width, height, color)
* \brief Draw an outline of a rectangle.
*
* \param[in] x X coordinate of the left side.
* \param[in] y Y coordinate of the top side.
* \param[in] width Width of the rectangle.
* \param[in] height Height of the rectangle.
* \param[in] color Pixel operation of the line.
*/

/**
* \def gfx_mono_draw_filled_rect(x, y, width, height, color)
* \brief Draw a filled rectangle.
*
* \param[in] x X coordinate of the left side.
* \param[in] y Y coordinate of the top side.
* \param[in] width Width of the rectangle.
* \param[in] height Height of the rectangle.
* \param[in] color Pixel operation of the line
*/

/**
* \def gfx_mono_draw_circle(x, y, radius, color, octant_mask)
* \brief Draw an outline of a circle or arc.
*
* The radius is the distance from the center to the circumference,
* which means that the total width or height of a circle will be
* (radius*2+1).
*
* The octant_mask parameter is a bitmask that decides which octants of
* the circle to draw. Use the GFX_OCTANTn, GFX_QUADRANTn, GFX_xHALF and
* GFX_WHOLE constants and OR them together if required. Radius equal to
* zero gives a single pixel.
*
* \param[in] x X coordinate of center.
* \param[in] y Y coordinate of center.
* \param[in] radius Circle radius in pixels.
* \param[in] color Pixel operation.
* \param[in] octant_mask Bitmask indicating which octants to draw.
*/

/**
* \def gfx_mono_draw_filled_circle(x, y, radius, color, quadrant_mask)
* \brief Draw a filled circle or sector.
*
* The radius is the distance from the center to the circumference,
* which means that the total width or height of a circle will be
* (radius*2+1).
*
* The quadrant_mask parameter is a bitmask that decides which quadrants
* of the circle to draw. Use the GFX_QUADRANTn, GFX_xHALF and
* GFX_WHOLE constants and OR them together if required. Radius equal to
* zero gives a single pixel.
*
* \note This function only supports quadrants while gfx_draw_circle()
* supports octants. This is to improve performance on drawing
* filled circles.
*
* \param[in] x X coordinate of center.
* \param[in] y Y coordinate of center.
* \param[in] radius Circle radius in pixels.
* \param[in] color Pixel operation.
* \param[in] quadrant_mask Bitmask indicating which quadrants to draw.
*/

/** @} */

/** @} */

/**
* \page asfdoc_common2_gfx_mono_quickstart Quick Start Guide for the mono graphics service
*
* This is the quick start guide for the \ref asfdoc_common2_gfx_mono "Monochrome Graphics service",
* with step-by-step instructions on how to configure and use it for a specific
* use case.
*
* \section asfdoc_common2_gfx_mono_quickstart_basic Basic usage of the graphics service
* This use case will demonstrate initializing the mono graphics service and
* then draw a black line on the screen from coordinates X=10, Y=10 to X=20,
* Y=20.
*
* \section asfdoc_common2_gfx_mono_basic_usage Usage steps
* \subsection asfdoc_common2_gfx_mono_basic_usage_code Example code
* Add to, e.g., the main function in the application C-file:
* \code
system_init();
gfx_mono_init();
gfx_mono_draw_line(10, 10, 20, 20, GFX_PIXEL_SET);
\endcode
*
* \subsection gfx_mono_basic_usage_workflow Workflow
* -# Initialize system:
* - \code system_init(); \endcode
* -# Initialize monochrome graphics service
* - \code gfx_mono_init(); \endcode
* - \note This will call the init function for the low level display
* controller driver and intialize the screen to a cleared background.
* -# Draw a line from 10,10 to 20,20:
* - \code gfx_mono_draw_line(10, 10, 20, 20, GFX_PIXEL_SET); \endcode
* - \note This uses GFX_PIXEL_SET to set the display pixels on the line;
* other options can be found in \ref gfx_mono_color.
*/

/**
* \page asfdoc_common2_gfx_mono_exqsg Examples for GFX Mono Library
*
* This is a list of the available Quick Start guides (QSGs) and example applications
* for \ref asfdoc_common2_gfx_mono. QSGs are simple examples with step-by-step instructions
* to configure and use this driver in a selection of use cases. Note that QSGs can be compiled as
* a standalone application or be added to the user application.
* - \subpage asfdoc_common2_gfx_mono_quickstart
* - \subpage asfdoc_common2_gfx_mono_font_quickstart
* - \subpage asfdoc_common2_gfx_mono_sysfont_example
* - \subpage asfdoc_common2_gfx_mono_spinner_example
*
*/


#endif /* GFX_MONO_H */

+ 0
- 256
firmware/SendcommPeer2P/src/ASF/common2/services/gfx_mono/gfx_mono_framebuffer.c View File

@@ -1,256 +0,0 @@
/**
* \file
*
* \brief Local framebuffer
*
* Copyright (c) 2011-2018 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/
/*
* Support and FAQ: visit <a href="https://www.microchip.com/support/">Microchip Support</a>
*/

#include "gfx_mono_framebuffer.h"

/* Pointer to the framebuffer; updated by the gfx_mono_set_framebuffer function */
static uint8_t *fbpointer;

/**
* \brief Set the LCD framebuffer.
*
* \param[in] framebuffer A pointer to an allocated area of RAM that can hold the
* framebuffer.
*
* A small example:
* \code
uint8_t framebuffer[FRAMEBUFFER_SIZE];
gfx_mono_set_framebuffer(framebuffer);
\endcode
*/
void gfx_mono_set_framebuffer(uint8_t *framebuffer)
{
fbpointer = framebuffer;
}

/**
* \brief Put a page from RAM to the framebuffer
*
* \param[in] data Pointer to data to be written
* \param[in] page Page address
* \param[in] column Offset into page (x coordinate)
* \param[in] width Number of bytes to be written.
*
* The following example will write 32 bytes from data_buf to the page 0,
* column 10 (byte 10 to 42 in the framebuffer).
* \code
gfx_mono_framebuffer_put_page(data_buf, 0, 10, 32);
\endcode
*/
void gfx_mono_framebuffer_put_page(gfx_mono_color_t *data, gfx_coord_t page,
gfx_coord_t column, gfx_coord_t width)
{
gfx_mono_color_t *data_pt = data;
gfx_coord_t *framebuffer_pt = fbpointer +
((page * GFX_MONO_LCD_WIDTH) + column);

do {
*framebuffer_pt++ = *data_pt++;
} while (--width > 0);
}

/**
* \brief Read a page from the framebuffer
*
* \param[in] data Pointer where to store the read data
* \param[in] page Page address
* \param[in] column Offset into page (x coordinate)
* \param[in] width Number of bytes to be read
*
* The following example will read back the first 128 bytes (first page) from
* the framebuffer:
* \code
gfx_mono_framebuffer_get_page(read_buffer, 0, 0, 128);
\endcode
*/
void gfx_mono_framebuffer_get_page(gfx_mono_color_t *data, gfx_coord_t page, \
gfx_coord_t column, gfx_coord_t width)
{
gfx_coord_t *framebuffer_pt = fbpointer +
((page * GFX_MONO_LCD_WIDTH) + column);
do {
*data++ = *framebuffer_pt++;
} while (--width > 0);
}

/**
* \brief Draw pixel to framebuffer
*
* \param[in] x X coordinate of the pixel
* \param[in] y Y coordinate of the pixel
* \param[in] color Pixel operation
*
*/
void gfx_mono_framebuffer_draw_pixel(gfx_coord_t x, gfx_coord_t y,
gfx_mono_color_t color)
{
uint8_t page;
uint8_t pixel_mask;
uint8_t pixel_value;

/* Discard pixels drawn outside the screen */
if ((x > GFX_MONO_LCD_WIDTH - 1) || (y > GFX_MONO_LCD_HEIGHT - 1)) {
return;
}

page = y / GFX_MONO_LCD_PIXELS_PER_BYTE;
pixel_mask = (1 << (y - (page * 8)));

/*
* Read the page containing the pixel in interest, then perform the
* requested action on this pixel before writing the page back to the
* display.
*/
pixel_value = gfx_mono_framebuffer_get_byte(page, x);

switch (color) {
case GFX_PIXEL_SET:
pixel_value |= pixel_mask;
break;

case GFX_PIXEL_CLR:
pixel_value &= ~pixel_mask;
break;

case GFX_PIXEL_XOR:
pixel_value ^= pixel_mask;
break;

default:
break;
}

gfx_mono_framebuffer_put_byte(page, x, pixel_value);
}

/**
* \brief Get the pixel value at x,y in framebuffer
*
* \param[in] x X coordinate of pixel
* \param[in] y Y coordinate of pixel
* \return Non zero value if pixel is set.
*
*/
uint8_t gfx_mono_framebuffer_get_pixel(gfx_coord_t x, gfx_coord_t y)
{
uint8_t page;
uint8_t pixel_mask;

if ((x > GFX_MONO_LCD_WIDTH - 1) || (y > GFX_MONO_LCD_HEIGHT - 1)) {
return 0;
}

page = y / GFX_MONO_LCD_PIXELS_PER_BYTE;
pixel_mask = (1 << (y - (page * 8)));

return gfx_mono_framebuffer_get_byte(page, x) & pixel_mask;
}

/**
* \brief Put a byte to the framebuffer
*
* \param[in] page Page address
* \param[in] column Page offset (x coordinate)
* \param[in] data Data to be written
*
* This example will put the value 0xFF to the first byte in the framebuffer
* \code
gfx_mono_framebuffer_put_byte(0, 0, 0xFF);
\endcode
*/
void gfx_mono_framebuffer_put_byte(gfx_coord_t page, gfx_coord_t column,
uint8_t data)
{
*(fbpointer + (page * GFX_MONO_LCD_WIDTH) + column) = data;
}

/**
* \brief Get a byte from the framebuffer
*
* \param[in] page Page address
* \param[in] column Page offset (x coordinate)
* \return data from LCD controller or framebuffer.
*
* The following code will read the first byte of the framebuffer
* \code
data = gfx_mono_framebuffer_get_byte(0, 0);
\endcode
*/
uint8_t gfx_mono_framebuffer_get_byte(gfx_coord_t page, gfx_coord_t column)
{
return *(fbpointer + (page * GFX_MONO_LCD_WIDTH) + column);
}

/**
* \brief Read/Modify/Write a byte in the framebuffer
*
* This function will read the byte from the framebuffer and
* do a mask operation on the byte according to the pixel operation selected
* by the color argument and the pixel mask provided.
*
* \param[in] page Page address
* \param[in] column Page offset (x coordinate)
* \param[in] pixel_mask Mask for pixel operation
* \param[in] color Pixel operation
*
* A small example that will XOR the first byte of the framebuffer with 0xAA
* \code
gfx_mono_framebuffer_mask_byte(0,0,0xAA,GFX_PIXEL_XOR);
\endcode
*/
void gfx_mono_framebuffer_mask_byte(gfx_coord_t page, gfx_coord_t column,
gfx_mono_color_t pixel_mask, gfx_mono_color_t color)
{
gfx_mono_color_t temp;

temp = gfx_mono_get_byte(page, column);

switch (color) {
case GFX_PIXEL_SET:
temp |= pixel_mask;
break;

case GFX_PIXEL_CLR:
temp &= ~pixel_mask;
break;

case GFX_PIXEL_XOR:
temp ^= pixel_mask;
break;
}

gfx_mono_put_byte(page, column, temp);
}

+ 0
- 86
firmware/SendcommPeer2P/src/ASF/common2/services/gfx_mono/gfx_mono_framebuffer.h View File

@@ -1,86 +0,0 @@
/**
* \file
*
* \brief Monochrome graphic library framebuffer device
*
* Copyright (c) 2011-2018 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/
/*
* Support and FAQ: visit <a href="https://www.microchip.com/support/">Microchip Support</a>
*/
#ifndef GFX_MONO_FRAMEBUFFER
#define GFX_MONO_FRAMEBUFFER

#include "gfx_mono.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* \ingroup asfdoc_common2_gfx_mono
* \defgroup asfdoc_common2_gfx_mono_framebuffer_group Framebuffer
*
* This module provides read/write from and to a framebuffer in RAM. This is
* needed when using a controller that does not provide a way to read back data
* from the LCD controller memory. In this case we need to buffer the data in
* a local framebuffer to allow manipulation on pixel level. It is generally
* not recommended to access the framebuffer directly; this is handled by the
* graphic driver when needed.
*
* @{
*/

void gfx_mono_set_framebuffer(uint8_t *framebuffer);

void gfx_mono_framebuffer_put_page(gfx_mono_color_t *data, gfx_coord_t page,
gfx_coord_t page_offset, gfx_coord_t width);

void gfx_mono_framebuffer_get_page(gfx_mono_color_t *data, gfx_coord_t page,
gfx_coord_t page_offset, gfx_coord_t width);

void gfx_mono_framebuffer_draw_pixel(gfx_coord_t x, gfx_coord_t y,
gfx_mono_color_t color);

uint8_t gfx_mono_framebuffer_get_pixel(gfx_coord_t x, gfx_coord_t y);

void gfx_mono_framebuffer_put_byte(gfx_coord_t page, gfx_coord_t column,
uint8_t data);

uint8_t gfx_mono_framebuffer_get_byte(gfx_coord_t page, gfx_coord_t column);

void gfx_mono_framebuffer_mask_byte(gfx_coord_t page, gfx_coord_t column,
gfx_mono_color_t pixel_mask, gfx_mono_color_t color);

/** @} */

#ifdef __cplusplus
}
#endif

#endif /* GFX_MONO_FRAMEBUFFER */

+ 0
- 496
firmware/SendcommPeer2P/src/ASF/common2/services/gfx_mono/gfx_mono_generic.c View File

@@ -1,496 +0,0 @@
/**
* \file
*
* \brief Generic monochrome LCD graphic primitives
*
* Copyright (c) 2011-2018 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/

/**
* \ingroup asfdoc_common2_gfx_mono_generic_group
* @{
*/
/*
* Support and FAQ: visit <a href="https://www.microchip.com/support/">Microchip Support</a>
*/
#include "gfx_mono_generic.h"

/**
* \brief Draw a horizontal line, one pixel wide (generic implementation)
*
* \note This function does a very simple bounds checking that does not
* check if the line is placed outside the screen. If you supply an
* x- or y-coordinate outside the display the behaviour is undefined,
* and you risk overwriting portions of internal SRAM.
*
* \param[in] x X coordinate of leftmost pixel.
* \param[in] y Y coordinate of the line.
* \param[in] length Length of the line in pixels.
* \param[in] color Pixel operation of the line.
*/
void gfx_mono_generic_draw_horizontal_line(gfx_coord_t x, gfx_coord_t y,
gfx_coord_t length, enum gfx_mono_color color)
{
uint8_t page;
uint8_t pixelmask;
uint8_t temp;

/* Clip line length if too long */
if (x + length > GFX_MONO_LCD_WIDTH) {
length = GFX_MONO_LCD_WIDTH - x;
}

page = y / 8;
pixelmask = (1 << (y - (page * 8)));

if (length == 0) {
/* Nothing to do. Move along. */
return;
}

switch (color) {
case GFX_PIXEL_SET:
while (length-- > 0) {
temp = gfx_mono_get_byte(page, x + length);
temp |= pixelmask;
gfx_mono_put_byte(page, x + length, temp);
}
break;

case GFX_PIXEL_CLR:
while (length-- > 0) {
temp = gfx_mono_get_byte(page, x + length);
temp &= ~pixelmask;
gfx_mono_put_byte(page, x + length, temp);
}
break;

case GFX_PIXEL_XOR:
while (length-- > 0) {
temp = gfx_mono_get_byte(page, x + length);
temp ^= pixelmask;
gfx_mono_put_byte(page, x + length, temp);
}
break;

default:
break;
}
}

/**
* \brief Draw a vertical line, one pixel wide (generic implementation)
*
* \note This function does a very simple bounds checking that does not
* check if the line is placed outside the screen. If you supply an
* x- or y-coordinate outside the display the behaviour is undefined,
* and you risk overwriting portions of internal SRAM.
*
* \param[in] x X coordinate of the line.
* \param[in] y Y coordinate of the topmost pixel.
* \param[in] length Length of the line in pixels.
* \param[in] color Pixel operation of the line.
*/
void gfx_mono_generic_draw_vertical_line(gfx_coord_t x, gfx_coord_t y,
gfx_coord_t length, enum gfx_mono_color color)
{
if (length == 0) {
return;
}

gfx_coord_t y2 = y + length - 1;

if (y == y2) {
gfx_mono_draw_pixel(x, y, color);
return;
}

if (y2 >= GFX_MONO_LCD_HEIGHT - 1) {
y2 = GFX_MONO_LCD_HEIGHT - 1;
}

gfx_coord_t y1page = y / 8;
gfx_coord_t y2page = y2 / 8;

uint8_t y1bitpos = y & 0x07;
uint8_t y2bitpos = y2 & 0x07;

uint8_t y1pixelmask = 0xFF << y1bitpos;
uint8_t y2pixelmask = 0xFF >> (7 - y2bitpos);

/* The pixels are on the same page; combine masks */
if (y1page == y2page) {
uint8_t pixelmask = y1pixelmask & y2pixelmask;
gfx_mono_mask_byte(y1page, x, pixelmask, color);
} else {
gfx_mono_mask_byte(y1page, x, y1pixelmask, color);

while (++y1page < y2page) {
gfx_mono_mask_byte(y1page, x, 0xFF, color);
}

gfx_mono_mask_byte(y2page, x, y2pixelmask, color);
}
}

/**
* \brief Draw a line between two arbitrary points (generic implementation).
*
* \param[in] x1 Start X coordinate.
* \param[in] y1 Start Y coordinate.
* \param[in] x2 End X coordinate.
* \param[in] y2 End Y coordinate.
* \param[in] color Pixel operation of the line.
*/
void gfx_mono_generic_draw_line(gfx_coord_t x1, gfx_coord_t y1,
gfx_coord_t x2, gfx_coord_t y2,
enum gfx_mono_color color)
{
uint8_t i;
uint8_t x;
uint8_t y;
int8_t xinc;
int8_t yinc;
int8_t dx;
int8_t dy;
int8_t e;

/* swap x1,y1 with x2,y2 */
if (x1 > x2) {
dx = x1;
x1 = x2;
x2 = dx;
dy = y1;
y1 = y2;
y2 = dy;
}

dx = x2 - x1;
dy = y2 - y1;

x = x1;
y = y1;

if (dx < 0) {
xinc = -1;
dx = -dx;
} else {
xinc = 1;
}

if (dy < 0) {
yinc = -1;
dy = -dy;
} else {
yinc = 1;
}

if (dx > dy) {
e = dy - dx;
for (i = 0; i <= dx; i++) {
gfx_mono_draw_pixel(x, y, color);
if (e >= 0) {
e -= dx;
y += yinc;
}

e += dy;
x += xinc;
}
} else {
e = dx - dy;
for (i = 0; i <= dy; i++) {
gfx_mono_draw_pixel(x, y, color);
if (e >= 0) {
e -= dy;
x += xinc;
}

e += dx;
y += yinc;
}
}
}

/**
* \brief Draw an outline of a rectangle (generic implementation).
*
* \param[in] x X coordinate of the left side.
* \param[in] y Y coordinate of the top side.
* \param[in] width Width of the rectangle.
* \param[in] height Height of the rectangle.
* \param[in] color Pixel operation of the line.
*/
void gfx_mono_generic_draw_rect(gfx_coord_t x, gfx_coord_t y,
gfx_coord_t width, gfx_coord_t height,
enum gfx_mono_color color)
{
gfx_mono_draw_horizontal_line(x, y, width, color);
gfx_mono_draw_horizontal_line(x, y + height - 1, width, color);

gfx_mono_draw_vertical_line(x, y, height, color);
gfx_mono_draw_vertical_line(x + width - 1, y, height, color);
}

/**
* \brief Draw a filled rectangle (generic implementation).
*
* \param[in] x X coordinate of the left side.
* \param[in] y Y coordinate of the top side.
* \param[in] width Width of the rectangle.
* \param[in] height Height of the rectangle.
* \param[in] color Pixel operation of the line
*/
void gfx_mono_generic_draw_filled_rect(gfx_coord_t x, gfx_coord_t y,
gfx_coord_t width, gfx_coord_t height,
enum gfx_mono_color color)
{
if (height == 0) {
/* Nothing to do. Move along. */
return;
}

while (height-- > 0) {
gfx_mono_draw_horizontal_line(x, y + height, width, color);
}
}

/**
* \brief Draw an outline of a circle or arc (generic implementation).
*
* The radius is the distance from the center to the circumference,
* which means that the total width or height of a circle will be
* (radius*2+1).
*
* The octant_mask parameter is a bitmask that decides which octants of
* the circle to draw. Use the GFX_OCTANTn, GFX_QUADRANTn, GFX_xHALF and
* GFX_WHOLE constants and OR them together if required. Radius equal to
* zero gives a single pixel.
*
* \param[in] x X coordinate of center.
* \param[in] y Y coordinate of center.
* \param[in] radius Circle radius in pixels.
* \param[in] color Pixel operation.
* \param[in] octant_mask Bitmask indicating which octants to draw.
*/
void gfx_mono_generic_draw_circle(gfx_coord_t x, gfx_coord_t y,
gfx_coord_t radius, enum gfx_mono_color color,
uint8_t octant_mask)
{
gfx_coord_t offset_x;
gfx_coord_t offset_y;
int16_t error;

/* Draw only a pixel if radius is zero. */
if (radius == 0) {
gfx_mono_draw_pixel(x, y, color);
return;
}

/* Set up start iterators. */
offset_x = 0;
offset_y = radius;
error = 3 - 2 * radius;

/* Iterate offsetX from 0 to radius. */
while (offset_x <= offset_y) {
/* Draw one pixel for each octant enabled in octant_mask. */
if (octant_mask & GFX_OCTANT0) {
gfx_mono_draw_pixel(x + offset_y, y - offset_x, color);
}

if (octant_mask & GFX_OCTANT1) {
gfx_mono_draw_pixel(x + offset_x, y - offset_y, color);
}

if (octant_mask & GFX_OCTANT2) {
gfx_mono_draw_pixel(x - offset_x, y - offset_y, color);
}

if (octant_mask & GFX_OCTANT3) {
gfx_mono_draw_pixel(x - offset_y, y - offset_x, color);
}

if (octant_mask & GFX_OCTANT4) {
gfx_mono_draw_pixel(x - offset_y, y + offset_x, color);
}

if (octant_mask & GFX_OCTANT5) {
gfx_mono_draw_pixel(x - offset_x, y + offset_y, color);
}

if (octant_mask & GFX_OCTANT6) {
gfx_mono_draw_pixel(x + offset_x, y + offset_y, color);
}

if (octant_mask & GFX_OCTANT7) {
gfx_mono_draw_pixel(x + offset_y, y + offset_x, color);
}

/* Update error value and step offset_y when required. */
if (error < 0) {
error += ((offset_x << 2) + 6);
} else {
error += (((offset_x - offset_y) << 2) + 10);
--offset_y;
}

/* Next X. */
++offset_x;
}
}

/**
* \brief Draw a filled circle or sector (generic implementation).
*
* The radius is the distance from the center to the circumference,
* which means that the total width or height of a circle will be
* (radius*2+1).
*
* The quadrant_mask parameter is a bitmask that decides which quadrants
* of the circle to draw. Use the GFX_QUADRANTn, GFX_xHALF and
* GFX_WHOLE constants and OR them together if required. Radius equal to
* zero gives a single pixel.
*
* \note This function only supports quadrants while gfx_draw_circle()
* supports octants. This is to improve performance on drawing
* filled circles.
*
* \param[in] x X coordinate of center.
* \param[in] y Y coordinate of center.
* \param[in] radius Circle radius in pixels.
* \param[in] color Pixel operation.
* \param[in] quadrant_mask Bitmask indicating which quadrants to draw.
*/
void gfx_mono_generic_draw_filled_circle(gfx_coord_t x, gfx_coord_t y,
gfx_coord_t radius, enum gfx_mono_color color,
uint8_t quadrant_mask)
{
gfx_coord_t offset_x;
gfx_coord_t offset_y;
int16_t error;

/* Draw only a pixel if radius is zero. */
if (radius == 0) {
gfx_mono_draw_pixel(x, y, color);
return;
}

/* Set up start iterators. */
offset_x = 0;
offset_y = radius;
error = 3 - 2 * radius;

/* Iterate offset_x from 0 to radius. */
while (offset_x <= offset_y) {
/* Draw vertical lines tracking each quadrant. */
if (quadrant_mask & GFX_QUADRANT0) {
gfx_mono_draw_vertical_line(x + offset_y,
y - offset_x, offset_x + 1, color);
gfx_mono_draw_vertical_line(x + offset_x,
y - offset_y, offset_y + 1, color);
}

if (quadrant_mask & GFX_QUADRANT1) {
gfx_mono_draw_vertical_line(x - offset_y,
y - offset_x, offset_x + 1, color);
gfx_mono_draw_vertical_line(x - offset_x,
y - offset_y, offset_y + 1, color);
}

if (quadrant_mask & GFX_QUADRANT2) {
gfx_mono_draw_vertical_line(x - offset_y,
y, offset_x + 1, color);
gfx_mono_draw_vertical_line(x - offset_x,
y, offset_y + 1, color);
}

if (quadrant_mask & GFX_QUADRANT3) {
gfx_mono_draw_vertical_line(x + offset_y,
y, offset_x + 1, color);
gfx_mono_draw_vertical_line(x + offset_x,
y, offset_y + 1, color);
}

/* Update error value and step offset_y when required. */
if (error < 0) {
error += ((offset_x << 2) + 6);
} else {
error += (((offset_x - offset_y) << 2) + 10);
--offset_y;
}

/* Next X. */
++offset_x;
}
}

/**
* \brief Put bitmap from FLASH or RAM to display
*
* This function will output bitmap data from FLASH or RAM.
* The bitmap y-coordinate will be aligned with display pages, rounded down.
* Ie: placing a bitmap at x=10, y=5 will put the bitmap at x = 10,y = 0 and
* placing a bitmap at x = 10, y = 10 will put the bitmap at x = 10, y = 8
*
*/
void gfx_mono_generic_put_bitmap(struct gfx_mono_bitmap *bitmap, gfx_coord_t x,
gfx_coord_t y)
{
gfx_coord_t num_pages = bitmap->height / 8;
gfx_coord_t page = y / 8;
gfx_coord_t column;
gfx_coord_t i;
gfx_mono_color_t temp;

switch (bitmap->type) {
case GFX_MONO_BITMAP_PROGMEM:
for (i = 0; i < num_pages; i++) {
for (column = 0; column < bitmap->width; column++) {
temp = PROGMEM_READ_BYTE(bitmap->data.progmem
+ (i * bitmap->width)
+ column);
gfx_mono_put_byte(i + page, column + x, temp);
}
}
break;

case GFX_MONO_BITMAP_RAM:
for (i = 0; i < num_pages; i++) {
gfx_mono_put_page(bitmap->data.pixmap
+ (i * bitmap->width), page + i, x,
bitmap->width);
}
break;

default:
break;
}
}

/** @} */

+ 0
- 121
firmware/SendcommPeer2P/src/ASF/common2/services/gfx_mono/gfx_mono_generic.h View File

@@ -1,121 +0,0 @@
/**
* \file
*
* \brief Generic monochrome LCD graphic primitives
*
* Copyright (c) 2011-2018 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/
/*
* Support and FAQ: visit <a href="https://www.microchip.com/support/">Microchip Support</a>
*/
#ifndef GFX_MONO_GENERIC
#define GFX_MONO_GENERIC
#include "gfx_mono.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* \ingroup asfdoc_common2_gfx_mono
* \defgroup asfdoc_common2_gfx_mono_generic_group Generic monochrome graphic primitives
*
* This is a service providing generic implementations of graphic primitives
* - Horizontal line
* - Vertical line
* - Line
* - Circle (filled/not filled)
* - Rectangle (filled/not filled)
*
* it also provides functionality to draw a bitmap to the graphic memory.
*
* These functions are made available if the graphic hardware being used do
* not implement the functionality in hardware. This is true in most cases.
*
* This service is included as a requirement for a
* hardware specific component that uses these functions, and provides a
* asfdoc_common2_draw_pixel function.
*
* @{
*/

/**
* \brief Storage structure for bitmap pixel data and metadata
*/
struct gfx_mono_bitmap {
/** Width of bitmap */
gfx_coord_t width;
/** Height of bitmap */
gfx_coord_t height;
/** Bitmap type */
enum gfx_mono_bitmap_type type;
union {
/** Pointer to pixels for bitmap stored in RAM */
gfx_mono_color_t *pixmap;
/** Pointer to pixels for bitmap stored in progmem */
gfx_mono_color_t PROGMEM_T *progmem;
}
data;
};

void gfx_mono_generic_draw_horizontal_line(gfx_coord_t x, gfx_coord_t y,
gfx_coord_t length, enum gfx_mono_color color);

void gfx_mono_generic_draw_vertical_line(gfx_coord_t x, gfx_coord_t y,
gfx_coord_t length, enum gfx_mono_color color);

void gfx_mono_generic_draw_line(gfx_coord_t x1, gfx_coord_t y1,
gfx_coord_t x2, gfx_coord_t y2,
enum gfx_mono_color color);

void gfx_mono_generic_draw_rect(gfx_coord_t x, gfx_coord_t y,
gfx_coord_t width, gfx_coord_t height,
enum gfx_mono_color color);

void gfx_mono_generic_draw_filled_rect(gfx_coord_t x, gfx_coord_t y,
gfx_coord_t width, gfx_coord_t height,
enum gfx_mono_color color);

void gfx_mono_generic_draw_circle(gfx_coord_t x, gfx_coord_t y,
gfx_coord_t radius, enum gfx_mono_color color,
uint8_t octant_mask);

void gfx_mono_generic_draw_filled_circle(gfx_coord_t x, gfx_coord_t y,
gfx_coord_t radius, enum gfx_mono_color color,
uint8_t quadrant_mask);

void gfx_mono_generic_put_bitmap(struct gfx_mono_bitmap *bitmap, gfx_coord_t x,
gfx_coord_t y);

/** @} */

#ifdef __cplusplus
}
#endif

#endif /* GFX_MONO_GENERIC */

+ 0
- 687
firmware/SendcommPeer2P/src/ASF/common2/services/gfx_mono/gfx_mono_spinctrl.c View File

@@ -1,687 +0,0 @@
/**
* \file
*
* \brief Spin control widget
* Copyright (c) 2011-2018 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/
/*
* Support and FAQ: visit <a href="https://www.microchip.com/support/">Microchip Support</a>
*/

#include "sysfont.h"
#include "stdio.h"
#include "gfx_mono.h"
#include "gfx_mono_spinctrl.h"

PROGMEM_DECLARE(gfx_mono_color_t, spin_indicator_data[]) = {
GFX_MONO_SPINCTRL_SPIN_INDICATOR_BITMAP
};

PROGMEM_DECLARE(gfx_mono_color_t, indicator_data[]) = {
GFX_MONO_SPINCTRL_INDICATOR_BITMAP
};

struct gfx_mono_bitmap gfx_mono_spinctrl_bitmap_spin_indicator = {
.height = GFX_MONO_SPINCTRL_SPIN_INDICATOR_HEIGHT,
.width = GFX_MONO_SPINCTRL_SPIN_INDICATOR_WIDTH,
.type = GFX_MONO_BITMAP_PROGMEM,
.data.progmem = spin_indicator_data
};

struct gfx_mono_bitmap gfx_mono_spinctrl_bitmap_indicator = {
.height = GFX_MONO_SPINCTRL_INDICATOR_HEIGHT,
.width = GFX_MONO_SPINCTRL_INDICATOR_WIDTH,
.type = GFX_MONO_BITMAP_PROGMEM,
.data.progmem = indicator_data
};

/**
* \brief Draw or delete indicator arrow in front of spinner
*
* \param[in] *spinner initialized gfx_mono_spinctrl struct
* \param[in] draw true on draw, false on delete
*/
static void gfx_mono_spinctrl_draw_indicator(struct gfx_mono_spinctrl *spinner,
bool draw)
{
if (draw) {
gfx_mono_put_bitmap(&gfx_mono_spinctrl_bitmap_indicator, 0,
spinner->y);
} else {
gfx_mono_draw_filled_rect(0, spinner->y,
GFX_MONO_SPINCTRL_INDICATOR_WIDTH,
GFX_MONO_SPINCTRL_INDICATOR_HEIGHT,
GFX_PIXEL_CLR);
}
}

/**
* \brief Draw or delete indicator in front of spinner data
*
* \param[in] spinner pointer to initialized gfx_mono_spinctrl struct
* \param[in] draw true on draw, false on delete
*/
static void gfx_mono_spinctrl_draw_spin_indicator(struct gfx_mono_spinctrl
*spinner, bool draw)
{
if (draw) {
gfx_mono_put_bitmap(&gfx_mono_spinctrl_bitmap_spin_indicator,
GFX_MONO_LCD_WIDTH - GFX_MONO_SPINCTRL_SPIN_INDICATOR_WIDTH,
spinner->y);
} else {
gfx_mono_draw_filled_rect(GFX_MONO_LCD_WIDTH -
GFX_MONO_SPINCTRL_SPIN_INDICATOR_WIDTH,
spinner->y,
GFX_MONO_SPINCTRL_SPIN_INDICATOR_WIDTH,
GFX_MONO_SPINCTRL_SPIN_INDICATOR_HEIGHT,
GFX_PIXEL_CLR);
}
}

/**
* \brief Draw OK button at bottom of screen
*
* This function draws an OK button at the bottom of the screen. It will
* also draw an indicator arrow in front of the button if the indicator bool
* is true. If the draw bool is false, the OK button will be deleted, and if
* the indicator bool is false, the indicator will be deleted.
*
* \param[in] draw true on draw, false on delete
* \param[in] indicator true on draw indicator, false on delete
*/
static void gfx_mono_spinctrl_draw_button(bool draw, bool indicator)
{
uint8_t width;
uint8_t height;
uint8_t offset;
char string_buf[22];

/* Clear bottom line */
gfx_mono_draw_filled_rect(0,
(SYSFONT_HEIGHT + 1) *
GFX_MONO_SPINCTRL_MAX_ELEMENTS_IN_SPINCOLLECTION,
GFX_MONO_LCD_WIDTH, SYSFONT_HEIGHT, GFX_PIXEL_CLR);

snprintf(string_buf, sizeof(string_buf), "OK");
gfx_mono_get_string_bounding_box(string_buf, &sysfont, &width, &height);
offset = (GFX_MONO_LCD_WIDTH - width) / 2;

if (draw) {
/* Draw OK button in the middle of the last line */
gfx_mono_draw_string(string_buf, offset,
(SYSFONT_HEIGHT + 1) *
GFX_MONO_SPINCTRL_MAX_ELEMENTS_IN_SPINCOLLECTION,
&sysfont);
if (indicator) {
/* Draw indicator arrow in front of button */
gfx_mono_put_bitmap(&gfx_mono_spinctrl_bitmap_indicator,
offset - GFX_MONO_SPINCTRL_INDICATOR_WIDTH,
(SYSFONT_HEIGHT + 1) *
GFX_MONO_SPINCTRL_MAX_ELEMENTS_IN_SPINCOLLECTION);
} else {
/* Delete indicator */
gfx_mono_draw_filled_rect(offset -
GFX_MONO_SPINCTRL_INDICATOR_WIDTH,
(SYSFONT_HEIGHT + 1) *
GFX_MONO_SPINCTRL_MAX_ELEMENTS_IN_SPINCOLLECTION,
GFX_MONO_SPINCTRL_INDICATOR_WIDTH,
GFX_MONO_SPINCTRL_INDICATOR_HEIGHT,
GFX_PIXEL_CLR);
}
} else {
/* Delete OK button */
gfx_mono_draw_filled_rect(
offset - GFX_MONO_SPINCTRL_INDICATOR_WIDTH,
(SYSFONT_HEIGHT + 1) *
GFX_MONO_SPINCTRL_MAX_ELEMENTS_IN_SPINCOLLECTION, 20,
SYSFONT_HEIGHT, GFX_PIXEL_CLR);
}
}

/**
* \brief Draw spinner at its position.
*
* This function draws a spinner at its position.
* The title of the spinner is only drawn if the redraw option is set.
* If the spinner is in focus, arrows will be drawn next to the spinner value
* to indicate that it is spinnable.
*
* \param[in] spinner pointer to initialized gfx_mono_spinctrl struct
* \param[in] redraw true if title of spinner should be drawn
*/
void gfx_mono_spinctrl_draw(struct gfx_mono_spinctrl *spinner, bool redraw)
{
char string_buf[GFX_MONO_SPINCTRL_INT_SPINNER_WIDTH];
uint8_t index;
uint8_t offset;

if (redraw) {
/* Clear line */
gfx_mono_draw_filled_rect(0, spinner->y, GFX_MONO_LCD_WIDTH,
SYSFONT_HEIGHT, GFX_PIXEL_CLR);
/* Draw title */
gfx_mono_draw_progmem_string((char PROGMEM_PTR_T)spinner->title,
GFX_MONO_SPINCTRL_INDICATOR_WIDTH + 1,
spinner->y, &sysfont);
}

if (spinner->in_focus) {
gfx_mono_spinctrl_draw_spin_indicator(spinner, true);
} else {
gfx_mono_spinctrl_draw_spin_indicator(spinner, false);
}

if (spinner->datatype == SPINTYPE_INTEGER) {
offset = GFX_MONO_LCD_WIDTH -
(SYSFONT_WIDTH *
GFX_MONO_SPINCTRL_INT_SPINNER_WIDTH);
snprintf(string_buf, sizeof(string_buf), "%d",
spinner->integer_data);
/* Delete previous spinner data */
gfx_mono_draw_filled_rect(offset, spinner->y,
GFX_MONO_LCD_WIDTH - offset -
GFX_MONO_SPINCTRL_SPIN_INDICATOR_WIDTH,
SYSFONT_HEIGHT,
GFX_PIXEL_CLR);
/* Draw integer data */
gfx_mono_draw_string(string_buf, offset, spinner->y, &sysfont);
} else if (spinner->datatype == SPINTYPE_STRING) {
index = spinner->strings.index;
offset = GFX_MONO_LCD_WIDTH -
(SYSFONT_WIDTH *
GFX_MONO_SPINCTRL_STRING_SPINNER_WIDTH);

/* Delete previous spinner data */
gfx_mono_draw_filled_rect(offset, spinner->y,
GFX_MONO_LCD_WIDTH - offset -
GFX_MONO_SPINCTRL_SPIN_INDICATOR_WIDTH,
SYSFONT_HEIGHT,
GFX_PIXEL_CLR);

/* Draw string data */
gfx_mono_draw_progmem_string(
(char PROGMEM_PTR_T)spinner->strings.data[index], offset,
spinner->y, &sysfont);
}
}

/**
* \brief Initialize a spinner.
*
* This function initializes a spinner to either
* \ref gfx_mono_spinctrl_type_t "SPINTYPE_STRING" spinner that spins through
* the strings in a \ref PROGMEM_STRING_T or a
* \ref gfx_mono_spinctrl_type_t "SPINTYPE_INTEGER" spinner that spins through
* integers.
* If the spinner type is SPINTYPE_INTEGER, it will spin from lower_limit to
* upper_limit.
* If the spinner type is SPINTYPE_STRING, a pointer to a PROGMEM_STRING_T must
* be provided, and the spinner will spin through the strings starting at
* index lower_limit ending at index upper_limit.
* The y parameter specifies where to place the spinner on the screen, but is
* overwritten if the spinner is put in a spincollection.
*
* \param[out] spinner pointer to initialized gfx_mono_spinctrl struct
* \param[in] datatype typer of spinner, integer or string
* \param[in] title title of spinner
* \param[in] data pointer to progmem string array if datatype is string.
* NULL if datatype is integer.
* \param[in] lower_limit lower limit and start value of spinner's data
* \param[in] upper_limit upper limit of spinner's data
* \param[in] y y position of spinner
*/
void gfx_mono_spinctrl_init(struct gfx_mono_spinctrl *spinner,
gfx_mono_spinctrl_type_t datatype, PROGMEM_STRING_T title,
PROGMEM_STRING_T *data, int16_t lower_limit,
int16_t upper_limit,
gfx_coord_t y)
{
/* Initialization of spinner parameters */
spinner->title = title;
spinner->datatype = datatype;
spinner->lower_limit = lower_limit;
spinner->upper_limit = upper_limit;
spinner->y = y;
spinner->in_focus = false;
spinner->last_saved_value = spinner->lower_limit;

if (datatype == SPINTYPE_STRING) {
spinner->strings.data = data;
spinner->strings.index = lower_limit;
} else {
spinner->integer_data = lower_limit;
}
}

/**
* \brief Initialize a spincollection.
*
* This function initializes a spincollection to which spinners can be added.
*
* \param[out] collection pointer to gfx_mono_spinctrl_spincollection to Initialize
*/
void gfx_mono_spinctrl_spincollection_init(struct
gfx_mono_spinctrl_spincollection *collection)
{
collection->active_spinner = false;
collection->current_selection = 0;
collection->number_of_spinners = 0;
collection->init = true;
}

/**
* \brief Add spinner to spincollection
*
* This function adds an initialized spinner to a spincollection and positions
* it below any other spinners in the spincollection on the screen. The
* spinners in the spincollection are linked together and number of spinners is
* updated.
* It is not possible to add more spinners than
* \ref GFX_MONO_SPINCTRL_MAX_ELEMENTS_IN_SPINCOLLECTION "maximum number of
* spinners in a spincollection".
*
* \param[in] spinner pointer to initialized gfx_mono_spinctrl struct to add
* to collection
* \param[in] spinners pointer to initialized gfx_mono_spinctrl_spincollection
* struct
*
*/
void gfx_mono_spinctrl_spincollection_add_spinner(struct
gfx_mono_spinctrl *spinner,
struct gfx_mono_spinctrl_spincollection *spinners)
{
uint8_t i;
struct gfx_mono_spinctrl *lastspinner;

/* Do not add more spinner elements than maximum number of spinners */
if (spinners->number_of_spinners >=
GFX_MONO_SPINCTRL_MAX_ELEMENTS_IN_SPINCOLLECTION) {
return;
}

/* Place new spinner below previous spinners on screen */
spinner->y = (SYSFONT_HEIGHT + 1) * spinners->number_of_spinners;

/* Add pointer to the spinner in spincollection if empty */
if (spinners->number_of_spinners == 0) {
spinners->collection = spinner;
} else {
lastspinner = spinners->collection;
for (i = 1; i < spinners->number_of_spinners; i++) {
lastspinner = lastspinner->next;
}
/* Link the new spinner to the current last spinner in the
* collection */
lastspinner->next = spinner;
/* Link the current last spinner as previous spinner for new
* spinner */
spinner->prev = lastspinner;
}

/* Set added spinner as last spinner in collection */
spinners->collection_last = spinner;
/* Update number of spinners in collection */
spinners->number_of_spinners++;
}

/**
* \brief Show spincollection
*
* This function draws all the spinners in a spincollection to the screen,
* together with an OK button at the bottom. It also draws an indicator arrow
* in front of the top spinner.
*
* \param[in] spinners pointer to initialized spincollection to display
*/
void gfx_mono_spinctrl_spincollection_show(struct
gfx_mono_spinctrl_spincollection *spinners)
{
uint8_t i;
struct gfx_mono_spinctrl *iterator;

/* Clear screen */
gfx_mono_draw_filled_rect(0, 0, GFX_MONO_LCD_WIDTH, GFX_MONO_LCD_HEIGHT,
GFX_PIXEL_CLR);

/* Make sure there are spinners in the collection */
if (spinners->number_of_spinners == 0) {
return;
}

/* Draw spinners on screen */
iterator = spinners->collection;
for (i = 0; i < spinners->number_of_spinners; i++) {
gfx_mono_spinctrl_draw(iterator, true);
iterator = iterator->next;
}
/* Draw OK button at bottom of screen */
gfx_mono_spinctrl_draw_button(true, false);
/* Draw indicator arrow in front of first spinner */
gfx_mono_spinctrl_draw_indicator(spinners->collection, true);
}

/**
* \brief Step up spinner data
*
* This function steps up the data, making sure it does not go
* beyond the upper limit. Wraps around if it does.
*
* \param[in] spinner pointer to initialized spinner.
*/
static void gfx_mono_spinctrl_step_up(struct gfx_mono_spinctrl *spinner)
{
/* Check if spinner type is integer or string, increment integer data or
* move to next string index.
*/
if (spinner->datatype == SPINTYPE_INTEGER) {
if (spinner->integer_data < spinner->upper_limit) {
spinner->integer_data++;
} else {
spinner->integer_data = spinner->lower_limit;
}
} else if (spinner->datatype == SPINTYPE_STRING) {
if (spinner->strings.index < spinner->upper_limit) {
spinner->strings.index++;
} else {
(spinner->strings.index) = spinner->lower_limit;
}
}
}

/**
* \brief Step down spinner data
*
* * This function steps down the data, making sure it does not go
* below the lower limit. Wraps around if it does.
*
* \param[in] spinner pointer to initialized spinner.
*/
static void gfx_mono_spinctrl_step_down(struct gfx_mono_spinctrl *spinner)
{
/* Check if spinner type is integer or string, increment integer data,
* move to next string index.
*/
if (spinner->datatype == SPINTYPE_INTEGER) {
if (spinner->integer_data > spinner->lower_limit) {
spinner->integer_data--;
} else {
spinner->integer_data = spinner->upper_limit;
}
} else if (spinner->datatype == SPINTYPE_STRING) {
if (spinner->strings.index > (spinner->lower_limit)) {
spinner->strings.index--;
} else {
spinner->strings.index = spinner->upper_limit;
}
}
}

/**
* \brief Update single spinner depending on input.
*
* \param[in] spinner pointer to initialized spinner.
* \param[in] keycode keycode to process
*
* \retval selected selected spinner value
* \retval GFX_MONO_SPINCTRL_EVENT_IDLE spinner spinning
* \retval GFX_MONO_SPINCTRL_EVENT_BACK spinner deselected
*/
int16_t gfx_mono_spinctrl_process_key(struct gfx_mono_spinctrl *spinner,
uint8_t keycode)
{
switch (keycode) {
case GFX_MONO_SPINCTRL_KEYCODE_DOWN:
if (spinner->in_focus) {
gfx_mono_spinctrl_step_down(spinner);
/* Update spinner on display */
gfx_mono_spinctrl_draw(spinner, false);
}

/* Nothing selected yet */
return GFX_MONO_SPINCTRL_EVENT_IDLE;

case GFX_MONO_SPINCTRL_KEYCODE_UP:
if (spinner->in_focus) {
gfx_mono_spinctrl_step_up(spinner);
/* Update spinner on display */
gfx_mono_spinctrl_draw(spinner, false);
}

/* Nothing selected yet */
return GFX_MONO_SPINCTRL_EVENT_IDLE;

case GFX_MONO_SPINCTRL_KEYCODE_ENTER:
if (spinner->in_focus) {
if (spinner->datatype == SPINTYPE_INTEGER) {
spinner->in_focus = false;
gfx_mono_spinctrl_draw(spinner, false);
/* Store saved value in case of aborting spinner
* later */
spinner->last_saved_value
= spinner->integer_data;
/* Got what we want. Return selection. */
return spinner->integer_data;
} else if (spinner->datatype == SPINTYPE_STRING) {
spinner->in_focus = false;
gfx_mono_spinctrl_draw(spinner, false);
/* Store saved value in case of aborting spinner
* later */
spinner->last_saved_value
= spinner->strings.index;
/* Got what we want. Return selection. */
return spinner->strings.index;
}
} else {
/* Spinner selected */
spinner->in_focus = true;
gfx_mono_spinctrl_draw(spinner, false);
return GFX_MONO_SPINCTRL_EVENT_IDLE;
}

case GFX_MONO_SPINCTRL_KEYCODE_BACK:
/* User pressed "back" key, */
spinner->in_focus = false;
/* Spinner choice aborted, show last saved value instead */
if (spinner->datatype == SPINTYPE_INTEGER) {
spinner->integer_data = spinner->last_saved_value;
} else if (spinner->datatype == SPINTYPE_STRING) {
spinner->strings.index = spinner->last_saved_value;
}

gfx_mono_spinctrl_draw(spinner, false);
return GFX_MONO_SPINCTRL_EVENT_BACK;

default:
/* Unknown key event */
return GFX_MONO_SPINCTRL_EVENT_IDLE;
}
}

/**
* \brief Update spincollection on screen depending on input
*
* This function returns \ref GFX_MONO_SPINCTRL_EVENT_FINISH if user has
* pressed the OK button. The spinner choices can then be extracted from the
* results array. If a spinner is of type SPINTYPE_STRING, the index of the
* progmem string will be stored in the results array, else the selected
* integer value will be stored.
* The choice from the first spinner added to the spincollection will be stored
* at index 0 in the results array, the second at index 1 and so on.
* If user has pressed the back button, \ref GFX_MONO_SPINCTRL_EVENT_BACK is
* returned, signalling that the application should be cancelled.
*
* \param[in] spinners pointer to initialized
* gfx_mono_spinctrl_spincollection
* \param[in] keycode keycode to process
* \param[in] results array to store results from the spinners, must be of
* same length as number of spinners
*
* \retval GFX_MONO_SPINCTRL_EVENT_FINISH user pressed ok button
* \retval GFX_MONO_SPINCTRL_EVENT_BACK user cancelled
* \retval GFX_MONO_SPINCTRL_EVENT_IDLE user is navigating in spincollection
*/
int16_t gfx_mono_spinctrl_spincollection_process_key(struct
gfx_mono_spinctrl_spincollection *spinners, uint8_t keycode,
int16_t results[])
{
uint8_t i;
struct gfx_mono_spinctrl *iterator;

/* Make sure there are spinners in the collection, if not, cancel */
if (spinners->number_of_spinners == 0) {
return GFX_MONO_SPINCTRL_EVENT_BACK;
}

/* Store initial values in results array first time function is run */
if (spinners->init) {
iterator = spinners->collection;
for (i = 0; i < spinners->number_of_spinners; i++) {
if (iterator->datatype == SPINTYPE_INTEGER) {
results[i] = iterator->integer_data;
} else {
results[i] = iterator->strings.index;
}

iterator = iterator->next;
}
spinners->init = false;
}

/* Find current spinner selection */
iterator = spinners->collection;
if (spinners->current_selection != GFX_MONO_SPINCTRL_BUTTON) {
for (i = 0; i < spinners->current_selection; i++) {
iterator = iterator->next;
}
}

if (spinners->active_spinner) {
/* Process chosen spinner */
spinners->selection = gfx_mono_spinctrl_process_key(iterator,
keycode);
if (spinners->selection == GFX_MONO_SPINCTRL_EVENT_BACK) {
/* User has exited spinner without saving the result */
spinners->active_spinner = false;
} else if (spinners->selection !=
GFX_MONO_SPINCTRL_EVENT_IDLE) {
/* Value selected, store in array */
results[spinners->current_selection]
= spinners->selection;
/* Step out of spinner and into spincollection */
spinners->active_spinner = false;
}

return GFX_MONO_SPINCTRL_EVENT_IDLE;
} else {
switch (keycode) {
case GFX_MONO_SPINCTRL_KEYCODE_DOWN:
if (spinners->current_selection ==
GFX_MONO_SPINCTRL_BUTTON) {
spinners->current_selection = 0;
/* Delete indicator arrow in front of button */
gfx_mono_spinctrl_draw_button(true, false);
/* Draw indicator arrow in front of first
* spinner */
gfx_mono_spinctrl_draw_indicator(iterator,
true);
} else if (spinners->current_selection <
spinners->number_of_spinners - 1) {
/* Delete indicator arrow */
gfx_mono_spinctrl_draw_indicator(iterator,
false);
spinners->current_selection++;
/* Draw indicator arrow in front of new spinner */
gfx_mono_spinctrl_draw_indicator(iterator->next,
true);
} else {
/* Delete indicator arrow */
gfx_mono_spinctrl_draw_indicator(iterator,
false);
spinners->current_selection
= GFX_MONO_SPINCTRL_BUTTON;
/* Draw indicator arrow in front of button */
gfx_mono_spinctrl_draw_button(true, true);
}

return GFX_MONO_SPINCTRL_EVENT_IDLE;

case GFX_MONO_SPINCTRL_KEYCODE_UP:
if (spinners->current_selection ==
GFX_MONO_SPINCTRL_BUTTON) {
/* Delete indicator arrow in front of button */
gfx_mono_spinctrl_draw_button(true, false);
spinners->current_selection
= spinners->number_of_spinners - 1;
/* Draw indicator arrow in front of new spinner */
gfx_mono_spinctrl_draw_indicator(
spinners->collection_last,
true);
} else if (spinners->current_selection > 0) {
/* Delete indicator arrow */
gfx_mono_spinctrl_draw_indicator(iterator,
false);
spinners->current_selection--;
/* Draw indicator arrow in front of new spinner */
gfx_mono_spinctrl_draw_indicator(iterator->prev,
true);
} else {
/* Delete indicator arrow */
gfx_mono_spinctrl_draw_indicator(iterator,
false);
spinners->current_selection
= GFX_MONO_SPINCTRL_BUTTON;
/* Draw indicator arrow in front of button */
gfx_mono_spinctrl_draw_button(true, true);
}

return GFX_MONO_SPINCTRL_EVENT_IDLE;

case GFX_MONO_SPINCTRL_KEYCODE_ENTER:
if (spinners->current_selection ==
GFX_MONO_SPINCTRL_BUTTON) {
/* Finished with all selections, return */
return GFX_MONO_SPINCTRL_EVENT_FINISH;
} else {
/* Spinner selected, send next keycode directly
* to spinner */
gfx_mono_spinctrl_process_key(iterator,
keycode);
spinners->active_spinner = true;
return GFX_MONO_SPINCTRL_EVENT_IDLE;
}

case GFX_MONO_SPINCTRL_KEYCODE_BACK:
/* User pressed "back" key, */
return GFX_MONO_SPINCTRL_EVENT_BACK;

default:
/* Unknown key event */
return GFX_MONO_SPINCTRL_EVENT_IDLE;
}
}
}

+ 0
- 241
firmware/SendcommPeer2P/src/ASF/common2/services/gfx_mono/gfx_mono_spinctrl.h View File

@@ -1,241 +0,0 @@
/**
* \file
*
* \brief Spin control widget
*
* Copyright (c) 2011-2018 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/
/*
* Support and FAQ: visit <a href="https://www.microchip.com/support/">Microchip Support</a>
*/
#ifndef GFX_MONO_SPINCTRL_H
#define GFX_MONO_SPINCTRL_H

#include "gfx_mono.h"
#include "conf_spinctrl.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* \ingroup asfdoc_common2_gfx_mono
* \defgroup asfdoc_common2_gfx_mono_spinctrl Spinner widget for monochrome graphical displays
*
* This module provides a spinner widget system for monochrome graphical
* displays.
*
* There is support for having one single spinner on the screen, or a
* collection of spinners.
*
* Typical flow of an application using the spincollection system:
*
* 1) Define spinners.\n
* 2) Initialize each spinners with \ref gfx_mono_spinctrl_init.\n
* 3) Define a spincollection struct and initialize it with
* \ref gfx_mono_spinctrl_spincollection_init.\n
* 4) Add spinners to spincollection with
* \ref gfx_mono_spinctrl_spincollection_add_spinner.\n
* 5) Draw spincollection to screen with
* \ref gfx_mono_spinctrl_spincollection_show.\n
* 6) Define a result array to store the spinner choices.\n
* 7) Update spinners and result array with user input using function
* \ref gfx_mono_spinctrl_spincollection_process_key.\n
* 8) Interpret \ref gfx_mono_spinctrl_spincollection_process_key return
* value.\n
* 9) Go to 7.\n
*
* Typical flow of an application using a single spinner:
*
* 1) Define spinner.\n
* 2) Initialize the spinners with \ref gfx_mono_spinctrl_init with preferred y
* position on screen.\n
* 3) Draw spinner to screen with \ref gfx_mono_spinctrl_draw.\n
* 4) Update spinner with user input using function
* \ref gfx_mono_spinctrl_process_key.\n
* 5) Interpret \ref gfx_mono_spinctrl_process_key return value.\n
* 6) Go to 4.\n
*
* Before the spinners can be updated, you need input from the user. Methods
* for getting input is not part of the spinner widget.
*
* \note The spinners will be linked together when added to a spincollection,
* and can therefore not be used in two spincollections at the same time.
*
* As soon as input is received, inform the spincollection system or the single
* spinner using the \ref gfx_mono_spinctrl_spincollection_process_key function
* or the \ref gfx_mono_spinctrl_process_key function.
* These functions will then return a status code and act depending on the
* given keycode:
*
* GFX_MONO_SPINCTRL_KEYCODE_DOWN : Change selection to next spinner value or
* to next spinner or OK button in a spincollection.
*
* GFX_MONO_SPINCTRL_KEYCODE_UP : Change selection to previous spinner value
* or to previous spinner or OK button in a spincollection.
*
* GFX_MONO_SPINCTRL_KEYCODE_ENTER : Select spinner value or select spinner or
* OK button in a spincollection.
*
* GFX_MONO_SPINCTRL_KEYCODE_BACK : Deselect spinner or cancel spincollection
* application.
*
* The value of the keycodes used are defined in conf_spinctrl.h. These values
* can be changed if needed.
*
* The graphical indicators used to indicate spinner selections are defined in
* conf_spinctrl.h. These indicators can be changed if needed.
* @{
*/

/** Spinner idle event */
#define GFX_MONO_SPINCTRL_EVENT_IDLE 0xFF
/** Spinner back button pressed event */
#define GFX_MONO_SPINCTRL_EVENT_BACK 0xFE
/** Spinner ok button pressed event */
#define GFX_MONO_SPINCTRL_EVENT_FINISH 0xFD

/** OK button */
#define GFX_MONO_SPINCTRL_BUTTON 0xFF

/** Maximum number of spinner elements on display */
#define GFX_MONO_SPINCTRL_ELEMENTS_PER_SCREEN \
((GFX_MONO_LCD_HEIGHT / SYSFONT_LINESPACING) - 1)

/**
* Maximum numbers of spinner elements in a spincollection - limited to
* one screen.
*/
#define GFX_MONO_SPINCTRL_MAX_ELEMENTS_IN_SPINCOLLECTION \
GFX_MONO_SPINCTRL_ELEMENTS_PER_SCREEN

/** Width of string spinner choices */
#define GFX_MONO_SPINCTRL_STRING_SPINNER_WIDTH 9
/** Width of integer spinner choices */
#define GFX_MONO_SPINCTRL_INT_SPINNER_WIDTH 9

/** Enum to specify what kind of data spinner should spin */
typedef enum gfx_mono_spinctrl_type_enum {
SPINTYPE_STRING,
SPINTYPE_INTEGER
} gfx_mono_spinctrl_type_t;

/** String struct */
struct gfx_mono_spinctrl_string {
/** Pointer to progmem strings to spin through
* \note Each string must be shorter than
* \ref GFX_MONO_SPINCTRL_STRING_SPINNER_WIDTH characters.
* If not, printing it to the screen will corrupt the spinner
* appearance.
*/
PROGMEM_STRING_T *data;
/** Index in string array */
uint8_t index;
};

/** Spin control struct */
struct gfx_mono_spinctrl {
/** Spinner title */
PROGMEM_STRING_T title;
/** Type of data to spin */
gfx_mono_spinctrl_type_t datatype;
/** Spinner data, depends on spinner datatype. */
union {
/** Spinner strings and index */
struct gfx_mono_spinctrl_string strings;
/** Spinner integer data */
int16_t integer_data;
};
/** Variable to store the last selected spinner value */
uint16_t last_saved_value;

/**
* Lower limit for spinning, must be positive and fit in uin8_t for
* spinner type SPINTYPE_STRING
*/
int16_t lower_limit;

/**
* Upper limit for spinning, must be positive and fit in uin8_t for
* spinner type SPINTYPE_STRING
*/
int16_t upper_limit;
/** Y coordinate for placement of spinner on screen */
gfx_coord_t y;
/** Boolean to tell if spinner is in focus or not */
bool in_focus;
/** Pointer to next spinner in a spincollection */
struct gfx_mono_spinctrl *next;
/** Pointer to previous spinner in a spincollection */
struct gfx_mono_spinctrl *prev;
};

/** Collection of spinners struct */
struct gfx_mono_spinctrl_spincollection {
/** Pointer to the first spinner in the collection */
struct gfx_mono_spinctrl *collection;
/** Pointer to the last spinner in the collection */
struct gfx_mono_spinctrl *collection_last;
/** Number of spinners in collection */
uint8_t number_of_spinners;
/** Current spinner/button */
uint8_t current_selection;
/** Return value from selected spinner */
uint16_t selection;
/** Boolean to tell if input should be sent directly to a spinner */
bool active_spinner;
/** Boolean to initialize results array when starting key processing */
bool init;
};

void gfx_mono_spinctrl_init(struct gfx_mono_spinctrl *spinner,
gfx_mono_spinctrl_type_t datatype, PROGMEM_STRING_T title,
PROGMEM_STRING_T *data, int16_t lower_limit,
int16_t upper_limit,
gfx_coord_t y);
void gfx_mono_spinctrl_draw(struct gfx_mono_spinctrl *spinner, bool redraw);
void gfx_mono_spinctrl_spincollection_init(struct
gfx_mono_spinctrl_spincollection *collection);
void gfx_mono_spinctrl_spincollection_add_spinner(struct gfx_mono_spinctrl
*spinner, struct gfx_mono_spinctrl_spincollection *spinners);
void gfx_mono_spinctrl_spincollection_show(struct
gfx_mono_spinctrl_spincollection *spinners);
int16_t gfx_mono_spinctrl_process_key(struct gfx_mono_spinctrl *spinner,
uint8_t keycode);

int16_t gfx_mono_spinctrl_spincollection_process_key(struct
gfx_mono_spinctrl_spincollection *spinners, uint8_t keycode,
int16_t results[]);

/** @} */

#ifdef __cplusplus
}
#endif

#endif /* GFX_MONO_SPINCTRL_H */

+ 0
- 415
firmware/SendcommPeer2P/src/ASF/common2/services/gfx_mono/gfx_mono_text.c View File

@@ -1,415 +0,0 @@
/**
* \file
*
* \brief Font and text drawing routines
*
* Copyright (c) 2010-2018 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/
/*
* Support and FAQ: visit <a href="https://www.microchip.com/support/">Microchip Support</a>
*/
#include "stddef.h"
#include "assert.h"

#include "gfx_mono.h"
#include "gfx_mono_text.h"
#include <asf.h>

#ifndef CONFIG_FONT_PIXELS_PER_BYTE
# define CONFIG_FONT_PIXELS_PER_BYTE 8
#endif

#define EXTMEM_BUF_SIZE 20

#if defined(CONFIG_HUGEMEM) || defined(__DOXYGEN__)

/**
* \internal
* \brief Helper function that draws a character from a font in hugemem
* to the display
*
* This function will first calculate the start offset in the font character
* data before iterating over the specific character data.
*
* Only pixels in the character that should be enabled are done so, the caller
* is required to prepare the drawing area before printing a character to it.
* This is done by the gfx_mono_draw_string() and
* gfx_mono_draw_progmem_string() functions.
*
* \param[in] ch Character to be drawn
* \param[in] x X coordinate on screen.
* \param[in] y Y coordinate on screen.
* \param[in] font Font to draw character in
*/
static void gfx_mono_draw_char_hugemem(const char ch, const gfx_coord_t x,
const gfx_coord_t y, const struct font *font)
{
uint8_t i;
uint8_t char_row_size;
uint8_t glyph_size;
uint16_t glyph_data_offset;
uint8_t char_buff[EXTMEM_BUF_SIZE];
uint8_t buffer_pos;
uint8_t rows_left;

/* Sanity check on parameters, assert if font is NULL. */
Assert(font != NULL);

gfx_coord_t inc_x = x;
gfx_coord_t inc_y = y;

char_row_size = font->width / CONFIG_FONT_PIXELS_PER_BYTE;
if (font->width % CONFIG_FONT_PIXELS_PER_BYTE) {
char_row_size++;
}

glyph_size = char_row_size * font->height;
glyph_data_offset = glyph_size * ((uint8_t)ch - font->first_char);
buffer_pos = EXTMEM_BUF_SIZE;
rows_left = font->height;

do {
static uint8_t glyph_byte = 0;
uint8_t pixelsToDraw = font->width;

for (i = 0; i < pixelsToDraw; i++) {
if (i % CONFIG_FONT_PIXELS_PER_BYTE == 0) {
/* Read another byte from hugemem */
if (buffer_pos >= EXTMEM_BUF_SIZE) {
hugemem_ptr_t source
= font->data.hugemem;
source = (hugemem_ptr_t)
((uint32_t)source +
glyph_data_offset);

hugemem_read_block(char_buff, source,
EXTMEM_BUF_SIZE);

glyph_data_offset += EXTMEM_BUF_SIZE;
buffer_pos = 0;
}

glyph_byte = char_buff[buffer_pos];
buffer_pos++;
}

/* Draw bit of glyph to screen */
if ((glyph_byte & 0x80)) {
gfx_mono_draw_pixel(inc_x, inc_y,
GFX_PIXEL_SET);
}

inc_x += 1;
glyph_byte <<= 1;
}

inc_y += 1;
inc_x = x;
} while (--rows_left > 0);
}

#endif

/**
* \internal
* \brief Helper function that draws a character from a font in progmem
* to the display
*
* This function will first calculate the start offset in the font character
* data before iterating over the specific character data.
*
* Only pixels in the character that should be enabled are done so, the caller
* is required to prepare the drawing area before printing a character to it.
* This is done by the gfx_mono_draw_string() and
* gfx_mono_draw_progmem_string() functions.
*
* \param[in] ch Character to be drawn
* \param[in] x X coordinate on screen.
* \param[in] y Y coordinate on screen.
* \param[in] font Font to draw character in
*/
static void gfx_mono_draw_char_progmem(const char ch, const gfx_coord_t x,
const gfx_coord_t y, const struct font *font)
{
uint8_t PROGMEM_PTR_T glyph_data;
uint16_t glyph_data_offset;
uint8_t char_row_size;
uint8_t rows_left;
uint8_t i;

/* Sanity check on parameters, assert if font is NULL. */
Assert(font != NULL);

gfx_coord_t inc_x = x;
gfx_coord_t inc_y = y;

char_row_size = font->width / CONFIG_FONT_PIXELS_PER_BYTE;
if (font->width % CONFIG_FONT_PIXELS_PER_BYTE) {
char_row_size++;
}

glyph_data_offset = char_row_size * font->height *
((uint8_t)ch - font->first_char);
glyph_data = font->data.progmem + glyph_data_offset;
rows_left = font->height;

do {
uint8_t glyph_byte = 0;
uint8_t pixelsToDraw = font->width;

for (i = 0; i < pixelsToDraw; i++) {
if (i % CONFIG_FONT_PIXELS_PER_BYTE == 0) {
glyph_byte = PROGMEM_READ_BYTE(glyph_data);
glyph_data++;
}

if ((glyph_byte & 0x80)) {
gfx_mono_draw_pixel(inc_x, inc_y,
GFX_PIXEL_SET);
}

inc_x += 1;
glyph_byte <<= 1;
}

inc_y += 1;
inc_x = x;
rows_left--;
} while (rows_left > 0);
}

/**
* \brief Draws a character to the display
*
* \param[in] c Character to be drawn
* \param[in] x X coordinate on screen.
* \param[in] y Y coordinate on screen.
* \param[in] font Font to draw character in
*/
void gfx_mono_draw_char(const char c, const gfx_coord_t x, const gfx_coord_t y,
const struct font *font)
{
gfx_mono_draw_filled_rect(x, y, font->width, font->height,
GFX_PIXEL_CLR);

switch (font->type) {
case FONT_LOC_PROGMEM:
gfx_mono_draw_char_progmem(c, x, y, font);
break;

#ifdef CONFIG_HUGEMEM
case FONT_LOC_HUGEMEM:
gfx_mono_draw_char_hugemem(c, x, y, font);
break;

#endif
default:
/* Unsupported mode, call assert */
Assert(false);
break;
}
}

/**
* \brief Draws a string to the display
*
* This function will draw a string located in memory to the display.
*
* \param[in] str Pointer to string
* \param[in] x X coordinate on screen.
* \param[in] y Y coordinate on screen.
* \param[in] font Font to draw string in
*/
void gfx_mono_draw_string(const char *str, gfx_coord_t x, gfx_coord_t y,
const struct font *font)
{
/* Save X in order to know where to return to on CR. */
const gfx_coord_t start_of_string_position_x = x;

/* Sanity check on parameters, assert if str or font is NULL. */
Assert(str != NULL);
Assert(font != NULL);

/* Draw characters until trailing null byte */
do {
/* Handle '\n' as newline, draw normal characters. */
if (*str == '\n') {
x = start_of_string_position_x;
y += font->height + 1;
} else if (*str == '\r') {
/* Skip '\r' characters. */
} else {
gfx_mono_draw_char(*str, x, y, font);
x += font->width;
}
} while (*(++str));
}

/**
* \brief Draws a string located in program memory to the display
*
* This function will draw a string located in program memory to the display,
* this differs from gfx_mono_draw_string() by using constant string data from
* the program memory instead of string data in RAM.
*
* Using program memory for constant strings will reduce the applications need
* for RAM, and thus lower the overall size footprint.
*
* \param[in] str Pointer to string located in program memory
* \param[in] x X coordinate on screen.
* \param[in] y Y coordinate on screen.
* \param[in] font Font to draw string in
*/
void gfx_mono_draw_progmem_string(char PROGMEM_PTR_T str, gfx_coord_t x,
gfx_coord_t y, const struct font *font)
{
char temp_char;

/* Sanity check on parameters, assert if str or font is NULL. */
Assert(str != NULL);
Assert(font != NULL);

/* Save X in order to know where to return to on CR. */
const gfx_coord_t start_of_string_position_x = x;

/* Draw characters until trailing null byte */
temp_char = PROGMEM_READ_BYTE((uint8_t PROGMEM_PTR_T)str);

while (temp_char) {
/* Handle '\n' as newline, draw normal characters. */
if (temp_char == '\n') {
x = start_of_string_position_x;
y += font->height + 1;
} else if (temp_char == '\r') {
/* Skip '\r' characters. */
} else {
gfx_mono_draw_char(temp_char, x, y, font);
x += font->width;
}

temp_char = PROGMEM_READ_BYTE((uint8_t PROGMEM_PTR_T)(++str));
}
}

/**
* \brief Computes the bounding box of a string
*
* \note If string is empty the returned width will be 1 pixel and the height
* equal to the font height.
*
* \param[in] str String to calculate bounding box for
* \param[in] font Font used
* \param[in] width Pointer to width result
* \param[in] height Pointer to height result
*/
void gfx_mono_get_string_bounding_box(const char *str, const struct font *font,
gfx_coord_t *width, gfx_coord_t *height)
{
gfx_coord_t font_width = font->width;
gfx_coord_t font_height = font->height;

gfx_coord_t max_width = 1;
gfx_coord_t max_height = font_height;
gfx_coord_t x = 0;

/* Sanity check on parameters, assert if str or font is NULL. */
Assert(str != NULL);
Assert(font != NULL);

/* Handle each character until trailing null byte */
do {
/* Handle '\n' as newline, draw normal characters. */
if (*str == '\n') {
x = 0;
max_height += font_height;
} else if (*str == '\r') {
/* Skip '\r' characters. */
} else {
x += font_width;
if (x > max_width) {
max_width = x;
}
}
} while (*(++str));

/* Return values through references */
*width = max_width;
*height = max_height;
}

/**
* \brief Computes the bounding box of a string located in program memory
*
* \note If string is empty the returned width will be 1 pixel and the height
* equal to the font height.
*
* \param[in] str String in program memory to calculate bounding box for
* \param[in] font Font used
* \param[in] width Pointer to width result
* \param[in] height Pointer to height result
*/
void gfx_mono_get_progmem_string_bounding_box(char PROGMEM_PTR_T str,
const struct font *font, gfx_coord_t *width,
gfx_coord_t *height)
{
gfx_coord_t font_width = font->width;
gfx_coord_t font_height = font->height;

char temp_char;
gfx_coord_t max_width = 1;
gfx_coord_t max_height = font_height;
gfx_coord_t x = 0;

/* Sanity check on parameters, assert if str or font is NULL. */
Assert(str != NULL);
Assert(font != NULL);

/* Handle each character until trailing null byte */
temp_char = PROGMEM_READ_BYTE((uint8_t PROGMEM_PTR_T)str);

while (temp_char) {
/* Handle '\n' as newline, draw normal characters. */
if (temp_char == '\n') {
x = 0;
max_height += font_height;
} else if (*str == '\r') {
/* Skip '\r' characters. */
} else {
x += font_width;
if (x > max_width) {
max_width = x;
}
}

temp_char = PROGMEM_READ_BYTE((uint8_t PROGMEM_PTR_T)(++str));
}

/* Return values through references */
*width = max_width;
*height = max_height;
}

+ 0
- 167
firmware/SendcommPeer2P/src/ASF/common2/services/gfx_mono/gfx_mono_text.h View File

@@ -1,167 +0,0 @@
/**
* \file
*
* \brief Monochrome graphic library API header file
*
* Copyright (c) 2011-2018 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/
/*
* Support and FAQ: visit <a href="https://www.microchip.com/support/">Microchip Support</a>
*/
#ifndef GFX_MONO_TEXT_H_INCLUDED
#define GFX_MONO_TEXT_H_INCLUDED

#include <stdint.h>

#include "compiler.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* \ingroup asfdoc_common2_gfx_mono
* \defgroup asfdoc_common2_gfx_mono_font GFX Mono Font Library
* This modules provides functionality for outputting a monochrome font
* to a display.
*
* \section asfdoc_common2_gfx_mono_font_api_overview API Overview
* @{
*/

/**
* \brief Valid storage locations for font data
*
* Add support for fonts in regular ram
*/
enum font_data_type {
/** Font data stored in program/flash memory. */
FONT_LOC_PROGMEM,
};

/** Storage structure for font meta data. */
struct font {
/** Type of storage used for binary font data. See \ref font_data_type. */
enum font_data_type type;
union {
/**
* Pointer to where the binary font data is stored. This
* variable is accessed either through hugemem or progmem
* depending on the value of \a type.
*/
#ifdef CONFIG_HAVE_HUGEMEM
hugemem_ptr_t hugemem;
#endif
uint8_t PROGMEM_PTR_T progmem;
} data;
/** Width of one font character, in pixels. */
uint8_t width;
/** Height of one font character, in pixels. */
uint8_t height;
/** ASCII value of first character in font set. */
uint8_t first_char;
/** ASCII value of last character in the set. */
uint8_t last_char;
};

/** \name Strings and characters located in RAM */
/** @{ */
void gfx_mono_draw_char(const char c, const gfx_coord_t x, const gfx_coord_t y,
const struct font *font);

void gfx_mono_draw_string(const char *str, const gfx_coord_t x,
const gfx_coord_t y, const struct font *font);

void gfx_mono_get_string_bounding_box(char const *str, const struct font *font,
gfx_coord_t *width, gfx_coord_t *height);

/** @} */

/** \name Strings located in flash */
/** @{ */
void gfx_mono_draw_progmem_string(char PROGMEM_PTR_T str, gfx_coord_t x,
gfx_coord_t y, const struct font *font);

void gfx_mono_get_progmem_string_bounding_box(char PROGMEM_PTR_T str,
const struct font *font, gfx_coord_t *width,
gfx_coord_t *height);

/** @} */

/** @} */

/**
* \page asfdoc_common2_gfx_mono_font_quickstart Quick Start Guide for the mono font service
*
* This is the quick start guide for the \ref asfdoc_common2_gfx_mono_font
* with step-by-step instructions on how to configure and use it for a specific
* use case.
*
* \section asfdoc_common2_gfx_mono_font_quickstart_basic Basic usage of the graphics service
* This use case will demonstrate initializing the mono graphics service and
* then draw a "Hello world!" sting on the display.
*
* \section asfdoc_common2_gfx_mono_font_quickstart_depend Dependencies
* In order to use this quick start, the following dependencies are needed:
* - \ref asfdoc_samd20_system_group
* - \ref asfdoc_common2_gfx_mono_font
* - \ref conf_sysfont.h Containing the actual font.
*
* \section asfdoc_common2_gfx_mono_font_basic_usage Usage steps
* \subsection gfx_mono_font_basic_usage_code Example code
* Add to, e.g., the main function in the application C-file:
* \code
system_init();

gfx_mono_init();

gfx_mono_draw_string("Hello world!",0, 0, &sysfont);

while (1) {

}
\endcode
*
* \subsection asfdoc_common2_gfx_mono_font_basic_usage_workflow Workflow
* -# Initialize system:
* - \code system_init(); \endcode
* -# Initialize monochrome graphics service
* - \code gfx_mono_init(); \endcode
* - \note This will call the init function for the low level display
* controller driver and intialize the screen to a cleared background.
* -# Draw a string on the screen starting at pixel (0,0)
* - \code gfx_mono_draw_string("Hello world!",0, 0, &sysfont); \endcode
* - \note This uses \ref conf_sysfont.h where sysfont is defines to give the font
* to be used on the screen.
*/

#ifdef __cplusplus
}
#endif

#endif /* GFX_MONO_TEXT_H_INCLUDED */

+ 0
- 362
firmware/SendcommPeer2P/src/ASF/common2/services/gfx_mono/gfx_mono_ug_2832hsweg04.c View File

@@ -1,362 +0,0 @@
/**
* \file
*
* \brief Haven Display UG 2832HSWEG04 display glue code for display controller
*
* Copyright (c) 2013-2018 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/
/*
* Support and FAQ: visit <a href="https://www.microchip.com/support/">Microchip Support</a>
*/
#include "gfx_mono_ug_2832hsweg04.h"

/* If we are using a serial interface without readback, use framebuffer */

#ifdef CONFIG_SSD1306_FRAMEBUFFER
static uint8_t framebuffer[GFX_MONO_LCD_FRAMEBUFFER_SIZE];
#endif

/**
* \brief Initialize SSD1306 controller and LCD display.
* It will also write the graphic controller RAM to all zeroes.
*
* \note This function will clear the contents of the display.
*/
void gfx_mono_ssd1306_init(void)
{
uint8_t page;
uint8_t column;

#ifdef CONFIG_SSD1306_FRAMEBUFFER
gfx_mono_set_framebuffer(framebuffer);
#endif

/* Initialize the low-level display controller. */
ssd1306_init();

/* Set display to output data from line 0 */
ssd1306_set_display_start_line_address(0);

/* Clear the contents of the display.
* If using a framebuffer (SPI interface) it will both clear the
* controller memory and the framebuffer.
*/
for (page = 0; page < GFX_MONO_LCD_PAGES; page++) {
for (column = 0; column < GFX_MONO_LCD_WIDTH; column++) {
gfx_mono_ssd1306_put_byte(page, column, 0x00, true);
}
}
}

#ifdef CONFIG_SSD1306_FRAMEBUFFER
/**
* \brief Put framebuffer to LCD controller
*
* This function will output the complete framebuffer from RAM to the
* LCD controller.
*
* \note This is done automatically if using the graphic primitives. Only
* needed if you are manipulating the framebuffer directly in your code.
*/
void gfx_mono_ssd1306_put_framebuffer(void)
{
uint8_t page;

for (page = 0; page < GFX_MONO_LCD_PAGES; page++) {
ssd1306_set_page_address(page);
ssd1306_set_column_address(0);
gfx_mono_ssd1306_put_page(framebuffer
+ (page * GFX_MONO_LCD_WIDTH), page, 0,
GFX_MONO_LCD_WIDTH);
}
}
#endif

/**
* \brief Draw pixel to screen
*
* \param[in] x X coordinate of the pixel
* \param[in] y Y coordinate of the pixel
* \param[in] color Pixel operation
*
* The following will set the pixel at x=10,y=10:
* \code
gfx_mono_ssd1306_draw_pixel(10, 10, GFX_PIXEL_SET);
\endcode
* The following example will clear the pixel at x=10,y=10:
* \code
gfx_mono_ssd1306_draw_pixel(10, 10, GFX_PIXEL_CLR);
\endcode
* And the following will toggle the pixel at x=10,y=10:
* \code
gfx_mono_ssd1306_draw_pixel(10, 10, GFX_PIXEL_XOR);
\endcode
*/
void gfx_mono_ssd1306_draw_pixel(gfx_coord_t x, gfx_coord_t y,
gfx_coord_t color)
{
uint8_t page;
uint8_t pixel_mask;
uint8_t pixel_value;

/* Discard pixels drawn outside the screen */
if ((x > GFX_MONO_LCD_WIDTH - 1) || (y > GFX_MONO_LCD_HEIGHT - 1)) {
return;
}

page = y / GFX_MONO_LCD_PIXELS_PER_BYTE;
pixel_mask = (1 << (y - (page * 8)));

/*
* Read the page containing the pixel in interest, then perform the
* requested action on this pixel before writing the page back to the
* display.
*/
pixel_value = gfx_mono_get_byte(page, x);

switch (color) {
case GFX_PIXEL_SET:
pixel_value |= pixel_mask;
break;

case GFX_PIXEL_CLR:
pixel_value &= ~pixel_mask;
break;

case GFX_PIXEL_XOR:
pixel_value ^= pixel_mask;
break;

default:
break;
}

gfx_mono_put_byte(page, x, pixel_value);
}

/**
* \brief Get the pixel value at x,y
*
* \param[in] x X coordinate of pixel
* \param[in] y Y coordinate of pixel
* \return Non zero value if pixel is set.
*
* The following example will read the pixel value from x=10,y=10:
* \code
pixelval = gfx_mono_ssd1306_get_pixel(10,10);
\endcode
*/
uint8_t gfx_mono_ssd1306_get_pixel(gfx_coord_t x, gfx_coord_t y)
{
uint8_t page;
uint8_t pixel_mask;

if ((x > GFX_MONO_LCD_WIDTH - 1) || (y > GFX_MONO_LCD_HEIGHT - 1)) {
return 0;
}

page = y / GFX_MONO_LCD_PIXELS_PER_BYTE;
pixel_mask = (1 << (y - (page * 8)));

return gfx_mono_get_byte(page, x) & pixel_mask;
}

/**
* \brief Put a page from RAM to display controller.
*
* If the controller is accessed by the SPI interface, we can not read
* back data from the LCD controller RAM. Because of this all data that is
* written to the LCD controller in this mode is also written to a framebuffer
* in MCU RAM.
*
* \param[in] data Pointer to data to be written
* \param[in] page Page address
* \param[in] column Offset into page (x coordinate)
* \param[in] width Number of bytes to be written.
*
* The following example will write 32 bytes from data_buf to the page 0,
* column 10. This will place data_buf in the rectangle x1=10,y1=0,x2=42,y2=8
* (10 pixels from the upper left corner of the screen):
* \code
gfx_mono_ssd1306_put_page(data_buf, 0, 10, 32);
\endcode
*/
void gfx_mono_ssd1306_put_page(gfx_mono_color_t *data, gfx_coord_t page,
gfx_coord_t column, gfx_coord_t width)
{
#ifdef CONFIG_SSD1306_FRAMEBUFFER
gfx_mono_framebuffer_put_page(data, page, column, width);
#endif
ssd1306_set_page_address(page);
ssd1306_set_column_address(column);

do {
ssd1306_write_data(*data++);
} while (--width);
}

/**
* \brief Read a page from the LCD controller
*
* If the LCD controller is accessed by the SPI interface we cannot read
* data directly from the controller. In that case we will read the data from
* the local framebuffer instead.
*
* \param[in] data Pointer where to store the read data
* \param[in] page Page address
* \param[in] column Offset into page (x coordinate)
* \param[in] width Number of bytes to be read
*
* The following example will read back the first 128 bytes (first page) from
* the display memory:
* \code
gfx_mono_ssd1306_get_page(read_buffer, 0, 0, 128);
\endcode
*/
void gfx_mono_ssd1306_get_page(gfx_mono_color_t *data, gfx_coord_t page,
gfx_coord_t column, gfx_coord_t width)
{
#ifdef CONFIG_SSD1306_FRAMEBUFFER
gfx_mono_framebuffer_get_page(data, page, column, width);
#else
ssd1306_set_page_address(page);
ssd1306_set_column_address(column);

do {
*data++ = ssd1306_read_data();
} while (--width);
#endif
}

/**
* \brief Put a byte to the display controller RAM
*
* If the LCD controller is accessed by the SPI interface we will also put the
* data to the local framebuffer.
*
* \param[in] page Page address
* \param[in] column Page offset (x coordinate)
* \param[in] data Data to be written
* \param[in] force Forces the write
*
* This example will put the value 0xFF to the first byte in the display memory
* setting a 8 pixel high column of pixels in the upper left corner of the
* display.
* \code
gfx_mono_ssd1306_put_byte(0, 0, 0xFF, false);
\endcode
*/
void gfx_mono_ssd1306_put_byte(gfx_coord_t page, gfx_coord_t column,
uint8_t data, bool force)
{
#ifdef CONFIG_SSD1306_FRAMEBUFFER
if (!force && data == gfx_mono_framebuffer_get_byte(page, column)) {
return;
}
gfx_mono_framebuffer_put_byte(page, column, data);
#endif

ssd1306_set_page_address(page);
ssd1306_set_column_address(column);

ssd1306_write_data(data);
}

/**
* \brief Get a byte from the display controller RAM
*
* If the LCD controller is accessed by the SPI interface we cannot read the
* data. In this case return the data from the local framebuffer instead.
*
* \param[in] page Page address
* \param[in] column Page offset (x coordinate)
* \return data from LCD controller or framebuffer.
*
* The following code will read the first byte from the display memory or the
* local framebuffer if direct read is not possible. The data represents the
* pixels from x = 0 and y = 0 to y = 7.
* \code
data = gfx_mono_ssd1306_get_byte(0, 0);
\endcode
*/
uint8_t gfx_mono_ssd1306_get_byte(gfx_coord_t page, gfx_coord_t column)
{
#ifdef CONFIG_SSD1306_FRAMEBUFFER
return gfx_mono_framebuffer_get_byte(page, column);

#else
ssd1306_set_page_address(page);
ssd1306_set_column_address(column);

return ssd1306_read_data();

#endif
}

/**
* \brief Read/Modify/Write a byte on the display controller
*
* This function will read the byte from the display controller (or the
* framebuffer if we cannot read directly from the controller) and
* do a mask operation on the byte according to the pixel operation selected
* by the color argument and the pixel mask provided.
*
* \param[in] page Page address
* \param[in] column Page offset (x coordinate)
* \param[in] pixel_mask Mask for pixel operation
* \param[in] color Pixel operation
*
* A small example that will XOR the first byte of display memory with 0xAA
* \code
gfx_mono_ssd1306_mask_byte(0,0,0xAA,GFX_PIXEL_XOR);
\endcode
*/
void gfx_mono_ssd1306_mask_byte(gfx_coord_t page, gfx_coord_t column,
gfx_mono_color_t pixel_mask, gfx_mono_color_t color)
{
gfx_mono_color_t temp = gfx_mono_get_byte(page, column);

switch (color) {
case GFX_PIXEL_SET:
temp |= pixel_mask;
break;

case GFX_PIXEL_CLR:
temp &= ~pixel_mask;
break;

case GFX_PIXEL_XOR:
temp ^= pixel_mask;
break;

default:
break;
}

gfx_mono_put_byte(page, column, temp);
}

+ 0
- 158
firmware/SendcommPeer2P/src/ASF/common2/services/gfx_mono/gfx_mono_ug_2832hsweg04.h View File

@@ -1,158 +0,0 @@
/**
* \file
*
* \brief Haven Display UG 2832HSWEG04 display glue code for display controller
*
* Copyright (c) 2012-2018 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/
/*
* Support and FAQ: visit <a href="https://www.microchip.com/support/">Microchip Support</a>
*/

#ifndef GFX_MONO_2832HSWEG04_H
#define GFX_MONO_2832HSWEG04_H
#include "compiler.h"
#include "ssd1306.h"

#include "gfx_mono.h"
#include "gfx_mono_framebuffer.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* \ingroup asfdoc_common2_gfx_mono
* \defgroup asfdoc_common2_gfx_mono_2832hsweg04_group 2832HSWEG04 graphic library abstraction
*
* This module is an abstraction layer between the graphic library and the
* 2832HSWEG04 monochrome LCD display connected to a SSD1306 LCD controller.
*
* As the controller does not provide any hardware accelerated graphic, all the
* graphic primitives are provided by the \ref asfdoc_common2_gfx_mono_generic_group service.
*
* \note Do not call the gfx_mono_ssd1306_ functions directly. use the gfx_mono
* names that are defined in this header and documented in \ref asfdoc_common2_gfx_mono .
* Ie. gfx_mono_draw_pixel() should be used, not gfx_mono_ssd1306_draw_pixel()
* @{
*/

#define GFX_MONO_LCD_WIDTH 128
#ifndef GFX_MONO_LCD_HEIGHT
# define GFX_MONO_LCD_HEIGHT 32
#endif
#define GFX_MONO_LCD_PIXELS_PER_BYTE 8
#define GFX_MONO_LCD_PAGES (GFX_MONO_LCD_HEIGHT / \
GFX_MONO_LCD_PIXELS_PER_BYTE)
#define GFX_MONO_LCD_FRAMEBUFFER_SIZE ((GFX_MONO_LCD_WIDTH * \
GFX_MONO_LCD_HEIGHT) / GFX_MONO_LCD_PIXELS_PER_BYTE)

#define gfx_mono_draw_horizontal_line(x, y, length, color) \
gfx_mono_generic_draw_horizontal_line(x, y, length, color)

#define gfx_mono_draw_vertical_line(x, y, length, color) \
gfx_mono_generic_draw_vertical_line(x, y, length, color)

#define gfx_mono_draw_line(x1, y1, x2, y2, color) \
gfx_mono_generic_draw_line(x1, y1, x2, y2, color)

#define gfx_mono_draw_rect(x, y, width, height, color) \
gfx_mono_generic_draw_rect(x, y, width, height, color)

#define gfx_mono_draw_filled_rect(x, y, width, height, color) \
gfx_mono_generic_draw_filled_rect(x, y, width, height, \
color)

#define gfx_mono_draw_circle(x, y, radius, color, octant_mask) \
gfx_mono_generic_draw_circle(x, y, radius, color, \
octant_mask)

#define gfx_mono_draw_filled_circle(x, y, radius, color, quadrant_mask) \
gfx_mono_generic_draw_filled_circle(x, y, radius, \
color, quadrant_mask)

#define gfx_mono_put_bitmap(bitmap, x, y) \
gfx_mono_generic_put_bitmap(bitmap, x, y)

#define gfx_mono_draw_pixel(x, y, color) \
gfx_mono_ssd1306_draw_pixel(x, y, color)

#define gfx_mono_get_pixel(x, y) \
gfx_mono_ssd1306_get_pixel(x, y)

#define gfx_mono_init() \
gfx_mono_ssd1306_init()

#define gfx_mono_put_page(data, page, column, width) \
gfx_mono_ssd1306_put_page(data, page, column, width)

#define gfx_mono_get_page(data, page, column, width) \
gfx_mono_ssd1306_get_page(data, page, column, width)

#define gfx_mono_put_byte(page, column, data) \
gfx_mono_ssd1306_put_byte(page, column, data, false)

#define gfx_mono_get_byte(page, column) \
gfx_mono_ssd1306_get_byte(page, column)

#define gfx_mono_mask_byte(page, column, pixel_mask, color) \
gfx_mono_ssd1306_mask_byte(page, column, pixel_mask, color)

#define gfx_mono_put_framebuffer() \
gfx_mono_ssd1306_put_framebuffer()

void gfx_mono_ssd1306_put_framebuffer(void);

void gfx_mono_ssd1306_put_page(gfx_mono_color_t *data, gfx_coord_t page,
gfx_coord_t page_offset, gfx_coord_t width);

void gfx_mono_ssd1306_get_page(gfx_mono_color_t *data, gfx_coord_t page,
gfx_coord_t page_offset, gfx_coord_t width);

void gfx_mono_ssd1306_init(void);

void gfx_mono_ssd1306_draw_pixel(gfx_coord_t x, gfx_coord_t y,
gfx_mono_color_t color);

uint8_t gfx_mono_ssd1306_get_pixel(gfx_coord_t x, gfx_coord_t y);

void gfx_mono_ssd1306_put_byte(gfx_coord_t page, gfx_coord_t column,
uint8_t data, bool force);

uint8_t gfx_mono_ssd1306_get_byte(gfx_coord_t page, gfx_coord_t column);

void gfx_mono_ssd1306_mask_byte(gfx_coord_t page, gfx_coord_t column,
gfx_mono_color_t pixel_mask, gfx_mono_color_t color);

/** @} */

#ifdef __cplusplus
}
#endif

#endif /* GFX_MONO_2832HSWEG04_H */

+ 0
- 65
firmware/SendcommPeer2P/src/ASF/common2/services/gfx_mono/sysfont.c View File

@@ -1,65 +0,0 @@
/**
* \file
*
* \brief Graphical font support
*
* Copyright (c) 2009-2018 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/
/*
* Support and FAQ: visit <a href="https://www.microchip.com/support/">Microchip Support</a>
*/
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#include <assert.h>

#include "conf_sysfont.h"

#include "gfx_mono.h"
#include "sysfont.h"

// Use macro from conf_sysfont.h to define font glyph data.
SYSFONT_DEFINE_GLYPHS;

/**
* \brief Initialize a basic system font
*
* This initializes a basic system font globally usable by the application.
*/
struct font sysfont = {
.type = FONT_LOC_PROGMEM,
.width = SYSFONT_WIDTH,
.height = SYSFONT_HEIGHT,
.first_char = SYSFONT_FIRSTCHAR,
.last_char = SYSFONT_LASTCHAR,
.data = {
.progmem = sysfont_glyphs,
},
};

/** @} */

+ 0
- 60
firmware/SendcommPeer2P/src/ASF/common2/services/gfx_mono/sysfont.h View File

@@ -1,60 +0,0 @@
/**
* \file
*
* \brief Graphical System Font system
*
* Copyright (c) 2009-2018 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/
/*
* Support and FAQ: visit <a href="https://www.microchip.com/support/">Microchip Support</a>
*/

#ifndef SYSFONT_H_INCLUDED
#define SYSFONT_H_INCLUDED

#include "conf_sysfont.h"
#include "gfx_mono.h"
#include "gfx_mono_text.h"

/**
* \ingroup asfdoc_common2_gfx_mono_font
* \defgroup asfdoc_common2_gfx_mono_sysfont System font
*
* The system font objects are globally available for a graphical application.
* System fonts are by design read only, hence there are not any functions to
* change them during runtime. If the application needs additional fonts it
* should add additional font objects.
* \section asfdoc_common2_gfx_mono_sysfont_api_overview API Overview
* @{
*/

extern struct font sysfont;

/** @} */

#endif /* SYSFONT_H_INCLUDED */

+ 0
- 58
firmware/SendcommPeer2P/src/ASF/common2/services/gfx_mono/tools/bitmap.py View File

@@ -1,58 +0,0 @@
##
# \file
#
# \brief Output a 2 color bitmap as an uint8_t array
#
# Copyright (C) 2011-2018 Microchip Technology Inc. and its subsidiaries.
#
# \page License
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. The name of Atmel may not be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# 4. This software may only be redistributed and used in connection with an
# Atmel microcontroller product.
#
# THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
# EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from PIL import Image
import sys

im = Image.open(sys.argv[1]);
new_im = im.load()

width, height = im.size

for y in range(0, height) :
for x in range(0, width) :
if 0 < new_im[x, y]:
new_im[x, y] = 1
sys.stdout.write(str(new_im[x, y]))
sys.stdout.write("\n")

sys.stdout.write("\n uint8_t image_header[] = {\n")
for y in range(0, height, 8) :
for x in range(0, width) :
first_byte = str(new_im[x, y + 7]) + str(new_im[x, y+6]) + str(new_im[x, y+5]) + str(new_im[x, y+4]) + str(new_im[x, y+3]) + str(new_im[x, y+2]) + str(new_im[x, y+1]) + str(new_im[x, y+0])
print "0x%x," % int(first_byte, 2),

sys.stdout.write("};\n")

+ 0
- 133
firmware/SendcommPeer2P/src/ASF/common2/services/gfx_mono/tools/dump_display_over_serial.py View File

@@ -1,133 +0,0 @@
##
# \file
#
# \brief Convert display data on a serial line to a graphical representation
#
# Copyright (C) 2011-2018 Microchip Technology Inc. and its subsidiaries.
#
# \page License
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. The name of Atmel may not be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# 4. This software may only be redistributed and used in connection with an
# Atmel microcontroller product.
#
# THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
# EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import sys
import serial
import os.path
import argparse

def scan_for_ports():
available_ports = []

for index in range(64):
try:
serial_port = serial.Serial(index)
available_ports.append((index, serial_port.portstr))
serial_port.close()
except serial.SerialException:
pass
except IndexError as Error:
pass

for port_number, port_name in available_ports:
print "%02d - %s" % (port_number, port_name)

return available_ports

def dump_display_data(serial_port, baud_rate, output_file_name):
try:
output_file = open(output_file_name, 'w')
port = serial.Serial(port = serial_port,
baudrate = baud_rate, timeout = 1)
port.close()
port.open()
except ValueError as e:
print "error: invalid serial port parameters. %s" % (str(e))
output_file.close()
return -1
except serial.SerialException as e:
print "error: could not open serial port. %s" % (str(e))
output_file.close()
return -1
except IOError as e:
print "error: could not open output file. %s" % (str(e))
return -1

print "Display on %s: %u,8,N,1" % (port.name, port.baudrate)
port.write("D")
line = port.readline()
display_data = ""
while(line[:2] != "};") :
display_data = display_data + line[:-1]
line = port.readline()
display_data = display_data + line
port.close()

print "Writing data to file %s" % (output_file_name)
output_file.write(display_data)

output_file.close()

def main():
parser = argparse.ArgumentParser(description="This script will try to "
"open the given serial port, send a string to "
"instruct the target device to dump the contents of "
"the display to a serial link in XPM format. The "
"received file is then written to 'display.xpm', "
"unless a file is specified by the -o option.")
parser.add_argument("-p", "--port", dest="serial_port",
help="which serial port to open")
parser.add_argument("-b", "--baud", dest="baudrate", type=int,
help="baud rate to use for serial communication",
default=19200)
parser.add_argument("-o", "--output", dest="output_file",
help="write XPM image to FILE. Default is display.xpm.",
metavar="FILE", default="display.xpm")
parser.add_argument("-s", "--scan", action="store_true",
dest="scan_ports",
help="scan for available serial ports and exit",
default=False)

arguments = parser.parse_args()

if arguments.scan_ports:
scan_for_ports()
sys.exit()

if arguments.serial_port is None:
parser.print_usage()
sys.exit()

if os.path.exists(arguments.output_file):
print "Warning: output file '%s' already exists" % (arguments.output_file)
print "Do you want to write over file '%s'?" % (arguments.output_file)
answer = raw_input("[yes/NO] ")
if answer not in ("yes", "Yes", "YES"):
sys.exit()

dump_display_data(arguments.serial_port, arguments.baudrate, arguments.output_file)

if __name__ == "__main__":
main()

+ 0
- 6
firmware/SendcommPeer2P/src/ASF/common2/services/gfx_mono/tools/readme.txt View File

@@ -1,6 +0,0 @@

dump_display_over_serial.py
Convert display data on a serial line to a .XPM file

bitmap.py
Convert an indexed 2 color bitmap to an uint8_t array

+ 35
- 24
firmware/SendcommPeer2P/src/ASF/sam0/boards/samr34_sendcomm/board_init.c View File

@@ -47,34 +47,45 @@ void board_init(void);

void system_board_init(void)
{
struct port_config pin_conf;
port_get_config_defaults(&pin_conf);
struct port_config pin_conf;
port_get_config_defaults(&pin_conf);

/* Configure LEDs as outputs, turn them off */
pin_conf.direction = PORT_PIN_DIR_OUTPUT;
port_pin_set_config(LED_0_PIN, &pin_conf);
port_pin_set_output_level(LED_0_PIN, LED_0_INACTIVE);
/* Configure LEDs as outputs, turn them off */
pin_conf.direction = PORT_PIN_DIR_OUTPUT;
port_pin_set_config(LED_1_PIN, &pin_conf);
port_pin_set_output_level(LED_1_PIN, LED_1_INACTIVE);
/* Configure LEDs as outputs, turn them off */
pin_conf.direction = PORT_PIN_DIR_OUTPUT;
port_pin_set_config(LED_0_PIN, &pin_conf);
port_pin_set_output_level(LED_0_PIN, LED_0_INACTIVE);
/* Configure LEDs as outputs, turn them off */
pin_conf.direction = PORT_PIN_DIR_OUTPUT;
port_pin_set_config(LED_1_PIN, &pin_conf);
port_pin_set_output_level(LED_1_PIN, LED_1_INACTIVE);
#ifdef RFSWITCH_ENABLE
/* Configure RFSWITCH as output */
pin_conf.direction = PORT_PIN_DIR_OUTPUT;
port_pin_set_config(RF_SWITCH_PIN, &pin_conf);
port_pin_set_output_level(RF_SWITCH_PIN, RF_SWITCH_INACTIVE);
/* Configure RFSWITCH as output */
pin_conf.direction = PORT_PIN_DIR_OUTPUT;
port_pin_set_config(RF_SWITCH_PIN, &pin_conf);
port_pin_set_output_level(RF_SWITCH_PIN, RF_SWITCH_INACTIVE);
#endif

#ifdef TCXO_ENABLE
/* Configure TXPO PWR as output */
pin_conf.direction = PORT_PIN_DIR_OUTPUT;
port_pin_set_config(TCXO_PWR_PIN, &pin_conf);
port_pin_set_output_level(TCXO_PWR_PIN, TCXO_PWR_INACTIVE);
/* Configure TXPO PWR as output */
pin_conf.direction = PORT_PIN_DIR_OUTPUT;
port_pin_set_config(TCXO_PWR_PIN, &pin_conf);
port_pin_set_output_level(TCXO_PWR_PIN, TCXO_PWR_INACTIVE);
#endif
/* Set buttons as inputs */
pin_conf.direction = PORT_PIN_DIR_INPUT;
pin_conf.input_pull = PORT_PIN_PULL_UP;
port_pin_set_config(BUTTON_0_PIN, &pin_conf);
/* Set buttons as inputs */
pin_conf.direction = PORT_PIN_DIR_INPUT;
pin_conf.input_pull = PORT_PIN_PULL_UP;
port_pin_set_config(BUTTON_0_PIN, &pin_conf);

// Sendcomm: Redirect crystal to clock pins
#ifdef CLOCKHACK_ENABLE
/* Copy LSE crystal frequency to a pin */
struct system_pinmux_config pinmux_config;
system_pinmux_get_config_defaults(&pinmux_config);

pinmux_config.mux_position= PINMUX_PA22H_GCLK_IO6;
pinmux_config.direction = SYSTEM_PINMUX_PIN_DIR_OUTPUT;

system_pinmux_pin_set_config(PIN_PA22, &pinmux_config);
#endif /* #ifdef CLOCKHACK_ENABLE */
}

+ 9
- 9
firmware/SendcommPeer2P/src/ASF/sam0/boards/samr34_sendcomm/samr34_sendcomm.h View File

@@ -3,7 +3,7 @@
*
* \brief SAMR34 Sendcomm board definition
*
* Copyright (c) 2020 Europalab Devices ApS
* Copyright (c) 2021 Europalab Devices ApS
*
* \asf_license_start
*
@@ -95,16 +95,16 @@ void system_board_init(void);

/** \name RF SWITCH definitions
* @{ */
#define RF_SWITCH_PIN PIN_PA13
#define RF_SWITCH_ACTIVE true
#define RF_SWITCH_INACTIVE !RF_SWITCH_ACTIVE
#define RF_SWITCH_PIN PIN_PA13
#define RF_SWITCH_ACTIVE true
#define RF_SWITCH_INACTIVE !RF_SWITCH_ACTIVE
/** @} */

/** \name TCXO PWR Pin definitions
* @{ */
#define TCXO_PWR_PIN PIN_PA09
#define TCXO_PWR_ACTIVE true
#define TCXO_PWR_INACTIVE !TCXO_PWR_ACTIVE
#define TCXO_PWR_PIN PIN_PA09
#define TCXO_PWR_ACTIVE true
#define TCXO_PWR_INACTIVE !TCXO_PWR_ACTIVE
/** @} */


@@ -485,8 +485,8 @@ void system_board_init(void);
#define DIO5_EIC_PINMUX PINMUX_PB00A_EIC_EXTINT0
#define DIO5_EIC_LINE 0

#define SX_RF_RESET_HIGH true
#define SX_RF_RESET_LOW !SX_RF_RESET_HIGH
#define SX_RF_RESET_HIGH true
#define SX_RF_RESET_LOW !SX_RF_RESET_HIGH

/** @} */



+ 3
- 3
firmware/SendcommPeer2P/src/ASF/sam0/drivers/extint/extint.h View File

@@ -280,7 +280,7 @@ struct extint_chan_conf {
uint32_t gpio_pin_mux;
/** Internal pull to enable on the input pin */
enum extint_pull gpio_pin_pull;
#if (SAML21) || (SAML22) || (SAMC20) || (SAMC21) || (SAMR30) || (SAMR34) || (SAMR35) || (WLR089)
#if (SAML21) || (SAML22) || (SAMC20) || (SAMC21) || (SAMR30) || (SAMR34) || (SAMR35)
/** Enable asynchronous edge detection. */
bool enable_async_edge_detection;
#else
@@ -326,7 +326,7 @@ struct extint_nmi_conf {
* detection modes for NMIs.
*/
enum extint_detect detection_criteria;
#if (SAML21) || (SAML22) || (SAMC20) || (SAMC21) || (SAMR30) || (SAMR34) || (SAMR35) || (WLR089)
#if (SAML21) || (SAML22) || (SAMC20) || (SAMC21) || (SAMR30) || (SAMR34) || (SAMR35)
/** Enable asynchronous edge detection. */
bool enable_async_edge_detection;
#endif
@@ -465,7 +465,7 @@ static inline void extint_nmi_get_config_defaults(
config->gpio_pin_pull = EXTINT_PULL_UP;
config->filter_input_signal = false;
config->detection_criteria = EXTINT_DETECT_FALLING;
#if (SAML21) || (SAML22) || (SAMC20) || (SAMC21) || (SAMR30) || (SAMR34) || (SAMR35) || (WLR089)
#if (SAML21) || (SAML22) || (SAMC20) || (SAMC21) || (SAMR30) || (SAMR34) || (SAMR35)
config->enable_async_edge_detection = false;
#endif



+ 2
- 2
firmware/SendcommPeer2P/src/ASF/sam0/drivers/extint/extint_sam_l_c/extint.c View File

@@ -302,7 +302,7 @@ void extint_chan_set_config(
= (EIC_module->CONFIG[channel / 8].reg &
~((EIC_CONFIG_SENSE0_Msk | EIC_CONFIG_FILTEN0) << config_pos)) |
(new_config << config_pos);
#if (SAML22) || (SAML21XXXB) || (SAMC20) || (SAMR30) || (SAMR34) || (SAMR35) || (WLR089)
#if (SAML22) || (SAML21XXXB) || (SAMC20) || (SAMR30) || (SAMR34) || (SAMR35)
/* Config asynchronous edge detection */
if (config->enable_async_edge_detection) {
EIC_module->ASYNCH.reg |= (1UL << channel);
@@ -370,7 +370,7 @@ enum status_code extint_nmi_set_config(
new_config |= EIC_NMICTRL_NMIFILTEN;
}

#if (SAML21XXXB) || (SAML22) || (SAMC21) || (SAMR30) || (SAMR34) || (SAMR35) || (WLR089)
#if (SAML21XXXB) || (SAML22) || (SAMC21) || (SAMR30) || (SAMR34) || (SAMR35)
/* Enable asynchronous edge detection if requested in the config */
if (config->enable_async_edge_detection) {
new_config |= EIC_NMICTRL_NMIASYNCH;


+ 5
- 5
firmware/SendcommPeer2P/src/ASF/sam0/drivers/nvm/nvm.c View File

@@ -99,7 +99,7 @@ enum status_code nvm_set_config(
/* Get a pointer to the module hardware instance */
Nvmctrl *const nvm_module = NVMCTRL;

#if (SAML21) || (SAML22) || (SAMC20) || (SAMC21) || (SAMR30) || (SAMR34) || (SAMR35) || (WLR089)
#if (SAML21) || (SAML22) || (SAMC20) || (SAMC21) || (SAMR30) || (SAMR34) || (SAMR35)
/* Turn on the digital interface clock */
system_apb_clock_set_mask(SYSTEM_CLOCK_APB_APBB, MCLK_APBBMASK_NVMCTRL);
#else
@@ -794,7 +794,7 @@ static void _nvm_translate_raw_fusebits_to_struct (
((raw_user_row[0] & NVMCTRL_FUSES_EEPROM_SIZE_Msk)
>> NVMCTRL_FUSES_EEPROM_SIZE_Pos);

#if (SAML21) || (SAML22) || (SAMR30) || (SAMR34) || (SAMR35) || (WLR089)
#if (SAML21) || (SAML22) || (SAMR30) || (SAMR34) || (SAMR35)
fusebits->bod33_level = (uint8_t)
((raw_user_row[0] & FUSES_BOD33USERLEVEL_Msk)
>> FUSES_BOD33USERLEVEL_Pos);
@@ -884,7 +884,7 @@ static void _nvm_translate_raw_fusebits_to_struct (
fusebits->wdt_timeout_period = (uint8_t)
((raw_user_row[0] & WDT_FUSES_PER_Msk) >> WDT_FUSES_PER_Pos);

#if (SAML21) || (SAML22) || (SAMC20) || (SAMC21) || (SAMR30) || (SAMR34) || (SAMR35) || (WLR089)
#if (SAML21) || (SAML22) || (SAMC20) || (SAMC21) || (SAMR30) || (SAMR34) || (SAMR35)
fusebits->wdt_window_timeout = (enum nvm_wdt_window_timeout)
((raw_user_row[1] & WDT_FUSES_WINDOW_Msk) >> WDT_FUSES_WINDOW_Pos);
#else
@@ -983,7 +983,7 @@ enum status_code nvm_set_fuses(struct nvm_fusebits *fb)
fusebits[0] &= (~NVMCTRL_FUSES_EEPROM_SIZE_Msk);
fusebits[0] |= NVMCTRL_FUSES_EEPROM_SIZE(fb->eeprom_size);

#if (SAML21) || (SAML22) || (SAMR30) || (SAMR34) || (SAMR35) || (WLR089)
#if (SAML21) || (SAML22) || (SAMR30) || (SAMR34) || (SAMR35)
fusebits[0] &= (~FUSES_BOD33USERLEVEL_Msk);
fusebits[0] |= FUSES_BOD33USERLEVEL(fb->bod33_level);

@@ -1033,7 +1033,7 @@ enum status_code nvm_set_fuses(struct nvm_fusebits *fb)
fusebits[0] &= (~WDT_FUSES_PER_Msk);
fusebits[0] |= fb->wdt_timeout_period << WDT_FUSES_PER_Pos;

#if (SAML21) || (SAML22) || (SAMC20) || (SAMC21) || (SAMR30) || (SAMR34) || (SAMR35) || (WLR089)
#if (SAML21) || (SAML22) || (SAMC20) || (SAMC21) || (SAMR30) || (SAMR34) || (SAMR35)
fusebits[1] &= (~WDT_FUSES_WINDOW_Msk);
fusebits[1] |= fb->wdt_window_timeout << WDT_FUSES_WINDOW_Pos;
#else


+ 2
- 2
firmware/SendcommPeer2P/src/ASF/sam0/drivers/nvm/nvm.h View File

@@ -283,12 +283,12 @@ extern "C" {
* Define NVM features set according to the different device families.
* @{
*/
#if (SAML21) || (SAML22) || (SAMDA1) || (SAMC20) || (SAMC21) || (SAMR30) || (SAMR34) || (SAMR35) || defined(SAMD21_64K) || (SAMHA1) || (WLR089) || (SAMR34) \
#if (SAML21) || (SAML22) || (SAMDA1) || (SAMC20) || (SAMC21) || (SAMR30) || (SAMR34) || (SAMR35) || defined(SAMD21_64K) || (SAMHA1) || (SAMR34) \
|| defined(__DOXYGEN__)
/** Read while write EEPROM emulation feature. */
# define FEATURE_NVM_RWWEE
#endif
#if (SAML21) || (SAMR30) || (SAMR34) || (SAMR35) || (WLR089) || defined(__DOXYGEN__)
#if (SAML21) || (SAMR30) || (SAMR34) || (SAMR35) || defined(__DOXYGEN__)
/** Brown-out detector internal to the voltage regulator for VDDCORE. */
#define FEATURE_BOD12
#endif


+ 1
- 1
firmware/SendcommPeer2P/src/ASF/sam0/drivers/port/port.h View File

@@ -164,7 +164,7 @@ extern "C" {
* Define port features set according to different device family.
* @{
*/
#if (SAML21) || (SAML22) || (SAMC20) || (SAMC21) || (SAMR30) || (SAMR34) || (SAMR35) || (WLR089) || defined(__DOXYGEN__)
#if (SAML21) || (SAML22) || (SAMC20) || (SAMC21) || (SAMR30) || (SAMR34) || (SAMR35) || defined(__DOXYGEN__)
/** Event input control feature support for PORT group. */
# define FEATURE_PORT_INPUT_EVENT
#endif


+ 3
- 3
firmware/SendcommPeer2P/src/ASF/sam0/drivers/rtc/rtc_count.h View File

@@ -367,7 +367,7 @@ extern "C" {
* Define port features set according to different device family.
* @{
*/
#if (SAML21) || (SAML22) || (SAMC20) || (SAMC21) || (SAMR30) || (SAMR34) || (SAMR35) || (WLR089) || defined(__DOXYGEN__)
#if (SAML21) || (SAML22) || (SAMC20) || (SAMC21) || (SAMR30) || (SAMR34) || (SAMR35) || defined(__DOXYGEN__)
/** RTC periodic interval interrupt. */
# define FEATURE_RTC_PERIODIC_INT
/** RTC prescaler is off. */
@@ -724,7 +724,7 @@ struct rtc_count_config {
* needed for reading */
bool continuously_update;
#endif
#if (SAML21XXXB) || (SAML22) || (SAMC20) || (SAMC21) || (SAMR30) || (SAMR34) || (SAMR35) || (WLR089)
#if (SAML21XXXB) || (SAML22) || (SAMC20) || (SAMC21) || (SAMR30) || (SAMR34) || (SAMR35)
/** Enable count read synchronization. The COUNT value requires
* synchronization when reading. Disabling the synchronization
* will prevent the COUNT value from displaying the current value. */
@@ -774,7 +774,7 @@ static inline void rtc_count_get_config_defaults(
#ifdef FEATURE_RTC_CONTINUOUSLY_UPDATED
config->continuously_update = false;
#endif
#if (SAML21XXXB) || (SAML22) || (SAMC20) || (SAMC21) || (SAMR30) || (SAMR34) || (SAMR35) || (WLR089)
#if (SAML21XXXB) || (SAML22) || (SAMC20) || (SAMC21) || (SAMR30) || (SAMR34) || (SAMR35)
config->enable_read_sync = true;
#endif



+ 2
- 2
firmware/SendcommPeer2P/src/ASF/sam0/drivers/rtc/rtc_sam_l_c/rtc_count.c View File

@@ -203,9 +203,9 @@ static enum status_code _rtc_count_set_config(

Rtc *const rtc_module = module->hw;

#if SAML21 || SAMR30 || (SAMR34) || (SAMR35) || (WLR089)
#if SAML21 || SAMR30 || (SAMR34) || (SAMR35)
rtc_module->MODE0.CTRLA.reg = RTC_MODE0_CTRLA_MODE(0)
#if (SAML21XXXB) || (SAMR30) || (SAMR34) || (SAMR35) || (WLR089)
#if (SAML21XXXB) || (SAMR30) || (SAMR34) || (SAMR35)
| (config->enable_read_sync << RTC_MODE0_CTRLA_COUNTSYNC_Pos)
#endif
| config->prescaler;


+ 0
- 607
firmware/SendcommPeer2P/src/ASF/sam0/drivers/sercom/i2c/i2c_common.h View File

@@ -1,607 +0,0 @@
/**
* \file
*
* \brief SAM SERCOM I2C Common Driver
*
* Copyright (c) 2012-2018 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/
/*
* Support and FAQ: visit <a href="https://www.microchip.com/support/">Microchip Support</a>
*/
#ifndef I2C_COMMON_H_INCLUDED
#define I2C_COMMON_H_INCLUDED

#include <compiler.h>
#include <sercom.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
* \if (I2C_MASTER_MODE && I2C_SLAVE_MODE)
* \defgroup asfdoc_sam0_sercom_i2c_group SAM I2C (SERCOM I2C) Driver
* \elseif I2C_MASTER_MODE
* \defgroup asfdoc_sam0_sercom_i2c_group SAM I2C Master Mode (SERCOM I2C) Driver
* \elseif I2C_SLAVE_MODE
* \defgroup asfdoc_sam0_sercom_i2c_group SAM I2C Slave Mode (SERCOM I2C) Driver
* \endif
*
* This driver for Atmel&reg; | SMART ARM&reg;-based microcontrollers provides
* an interface for the configuration and management of the device's SERCOM
* I<SUP>2</SUP>C module, for the transfer of data via an I<SUP>2</SUP>C bus.
* The following driver API modes are covered by this manual:
*
* \if I2C_MASTER_MODE
* - Master Mode Polled APIs
* \endif
* \if I2C_MASTER_CALLBACK_MODE
* - Master Mode Callback APIs
* \endif
* \if I2C_SLAVE_MODE
* - Slave Mode Polled APIs
* \endif
* \if I2C_SLAVE_CALLBACK_MODE
* - Slave Mode Callback APIs
* \endif
*
* The following peripheral is used by this module:
* - SERCOM (Serial Communication Interface)
*
* The following devices can use this module:
* - Atmel | SMART SAM D20/D21
* - Atmel | SMART SAM R21
* - Atmel | SMART SAM D09/D10/D11
* - Atmel | SMART SAM L21/L22
* - Atmel | SMART SAM DA1
* - Atmel | SMART SAM C20/C21
* - Atmel | SMART SAM HA1
* - Atmel | SMART SAM R30
* - Atmel | SMART SAM R34
* - Atmel | SMART SAM R35
*
* The outline of this documentation is as follows:
* - \ref asfdoc_sam0_sercom_i2c_prerequisites
* - \ref asfdoc_sam0_sercom_i2c_overview
* - \ref asfdoc_sam0_sercom_i2c_special_considerations
* - \ref asfdoc_sam0_sercom_i2c_extra
* - \ref asfdoc_sam0_sercom_i2c_examples
* - \ref asfdoc_sam0_sercom_i2c_api_overview
*
* \section asfdoc_sam0_sercom_i2c_prerequisites Prerequisites
* There are no prerequisites.
*
* \section asfdoc_sam0_sercom_i2c_overview Module Overview
* The outline of this section is as follows:
* - \ref asfdoc_sam0_sercom_i2c_module_features
* - \ref asfdoc_sam0_sercom_i2c_functional_desc
* - \ref asfdoc_sam0_sercom_i2c_bus_topology
* - \ref asfdoc_sam0_sercom_i2c_transactions
* - \ref asfdoc_sam0_sercom_i2c_multi_master
* - \ref asfdoc_sam0_sercom_i2c_bus_states
* - \ref asfdoc_sam0_sercom_i2c_timeout
* - \ref asfdoc_sam0_sercom_i2c_sleep_modes
*
* \subsection asfdoc_sam0_sercom_i2c_module_features Driver Feature Macro Definition
* <table>
* <tr>
* <th>Driver Feature Macro</th>
* <th>Supported devices</th>
* </tr>
* <tr>
* <td>FEATURE_I2C_FAST_MODE_PLUS_AND_HIGH_SPEED</td>
* <td>SAM D21/R21/D10/D11/L21/L22/DA1/C20/C21/HA1/R34/R35</td>
* </tr>
* <tr>
* <td>FEATURE_I2C_10_BIT_ADDRESS</td>
* <td>SAM D21/R21/D10/D11/L21/L22/DA1/C20/C21/HA1/R34/R35</td>
* </tr>
* <tr>
* <td>FEATURE_I2C_SCL_STRETCH_MODE</td>
* <td>SAM D21/R21/D10/D11/L21/L22/DA1/C20/C21/HA1/R34/R35</td>
* </tr>
* <tr>
* <td>FEATURE_I2C_SCL_EXTEND_TIMEOUT</td>
* <td>SAM D21/R21/D10/D11/L21/L22/DA1/C20/C21/HA1/R34/R35</td>
* </tr>
* </table>
* \note The specific features are only available in the driver when the selected
* device supports those features.
* \note When using the I2C high-speed mode for off-board communication,
* there are various high frequency interference, which can lead to distortion of the signals
* and communication failure. When using Xplained Pro boards in order to test I2C high-speed
* communication, the following recommendation should be followed:
* - Use the SDA-line on PA08 and SCL-line on PA09 for both boards. This will provide stronger
* pull-ups on both SDA and SCL.
* - The SCL should not be higher than 1.5MHz.
*
* \subsection asfdoc_sam0_sercom_i2c_functional_desc Functional Description
* The I<SUP>2</SUP>C provides a simple two-wire bidirectional bus consisting of a
* wired-AND type serial clock line (SCL) and a wired-AND type serial data line
* (SDA).
*
* The I<SUP>2</SUP>C bus provides a simple, but efficient method of interconnecting
* multiple master and slave devices. An arbitration mechanism is provided for
* resolving bus ownership between masters, as only one master device may own
* the bus at any given time. The arbitration mechanism relies on the wired-AND
* connections to avoid bus drivers short-circuiting.
*
* A unique address is assigned to all slave devices connected to the bus. A
* device can contain both master and slave logic, and can emulate multiple
* slave devices by responding to more than one address.
*
* \subsection asfdoc_sam0_sercom_i2c_bus_topology Bus Topology
* The I<SUP>2</SUP>C bus topology is illustrated in
* \ref asfdoc_sam0_sercom_i2c_bus_topology_figure "the figure below". The pull-up
* resistors (Rs) will provide a high level on the bus lines when none of the
* I<SUP>2</SUP>C devices are driving the bus. These are optional, and can be
* replaced with a constant current source.
*
* \anchor asfdoc_sam0_sercom_i2c_bus_topology_figure
* \image html bus_topology.svg "I2C Bus Topology" Width=100%
*
* \subsection asfdoc_sam0_sercom_i2c_transactions Transactions
* The I<SUP>2</SUP>C standard defines three fundamental transaction formats:
* - Master Write
* - The master transmits data packets to the slave after addressing it
* - Master Read
* - The slave transmits data packets to the master after being addressed
* - Combined Read/Write
* - A combined transaction consists of several write and read transactions
*
* A data transfer starts with the master issuing a \b Start condition on the
* bus, followed by the address of the slave together with a bit to indicate
* whether the master wants to read from or write to the slave.
* The addressed slave must respond to this by sending an \b ACK back to the
* master.
*
* After this, data packets are sent from the master or slave, according to the
* read/write bit. Each packet must be acknowledged (ACK) or not
* acknowledged (NACK) by the receiver.
*
* If a slave responds with a NACK, the master must assume that the slave
* cannot receive any more data and cancel the write operation.
*
* The master completes a transaction by issuing a \b Stop condition.
*
* A master can issue multiple \b Start conditions during a transaction; this
* is then called a \b Repeated \b Start condition.
*
* \subsubsection asfdoc_sam0_sercom_i2c_address_packets Address Packets
* The slave address consists of seven bits. The 8<SUP>th</SUP> bit in the transfer
* determines the data direction (read or write). An address packet always
* succeeds a \b Start or \b Repeated \b Start condition. The 8<SUP>th</SUP> bit is handled
* in the driver, and the user will only have to provide the 7-bit address.
*
* \subsubsection asfdoc_sam0_sercom_i2c_data_packets Data Packets
* Data packets are nine bits long, consisting of one 8-bit data byte, and an
* acknowledgement bit. Data packets follow either an address packet or another
* data packet on the bus.
*
* \subsubsection asfdoc_sam0_sercom_i2c_trans_examples Transaction Examples
* The gray bits in the following examples are sent from master to slave, and
* the white bits are sent from slave to master.
* Example of a read transaction is shown in
* \ref asfdoc_sam0_sercom_i2c_trans_examples_i2c_read "the figure below". Here, the
* master first issues a \b Start condition and gets ownership of the bus. An
* address packet with the direction flag set to read is then sent and
* acknowledged by the slave. Then the slave sends one data packet which is
* acknowledged by the master. The slave sends another packet, which is not
* acknowledged by the master and indicates that the master will terminate the
* transaction. In the end, the transaction is terminated by the master issuing
* a \b Stop condition.
*
* \anchor asfdoc_sam0_sercom_i2c_trans_examples_i2c_read
* \image html i2c_read.svg "I2C Packet Read" Width=100%
*
* Example of a write transaction is shown in
* \ref asfdoc_sam0_sercom_i2c_trans_examples_i2c_write "the figure below". Here, the
* master first issues a \b Start condition and gets ownership of the bus. An
* address packet with the dir flag set to write is then sent and acknowledged
* by the slave. Then the master sends two data packets, each acknowledged by
* the slave. In the end, the transaction is terminated by the master issuing
* a \b Stop condition.
*
* \anchor asfdoc_sam0_sercom_i2c_trans_examples_i2c_write
* \image html i2c_write.svg "I2C Packet Write" Width=100%
*
* \subsubsection asfdoc_sam0_sercom_i2c_packet_timeout Packet Timeout
* When a master sends an I<SUP>2</SUP>C packet, there is no way of
* being sure that a slave will acknowledge the packet. To avoid stalling the
* device forever while waiting for an acknowledge, a user selectable timeout
* is provided in the \ref i2c_master_config struct which
* lets the driver exit a read or write operation after the specified time.
* The function will then return the STATUS_ERR_TIMEOUT flag.
*
* This is also the case for the slave when using the functions postfixed
* \c _wait.
*
* The time before the timeout occurs, will be the same as
* for \ref asfdoc_sam0_sercom_i2c_unknown_bus_timeout "unknown bus state" timeout.
*
* \subsubsection asfdoc_sam0_sercom_i2c_repeated_start Repeated Start
* To issue a \b Repeated \b Start, the functions postfixed \c _no_stop must be
* used.
* These functions will not send a \b Stop condition when the transfer is done,
* thus the next transfer will start with a \b Repeated \b Start. To end the
* transaction, the functions without the \c _no_stop postfix must be used
* for the last read/write.
*
* \subsection asfdoc_sam0_sercom_i2c_multi_master Multi Master
* In a multi master environment, arbitration of the bus is important, as only
* one master can own the bus at any point.
*
* \subsubsection asfdoc_sam0_sercom_i2c_arbitration Arbitration
*
* \par Clock stretching
* The serial clock line is always driven by a master device. However, all
* devices connected to the bus are allowed stretch the low period of the clock
* to slow down the overall clock frequency or to insert wait states while
* processing data.
* Both master and slave can randomly stretch the clock, which will force the
* other device into a wait-state until the clock line goes high again.
*
* \par Arbitration on the data line
* If two masters start transmitting at the same time, they will both transmit
* until one master detects that the other master is pulling the data line low.
* When this is detected, the master not pulling the line low, will stop the
* transmission and wait until the bus is idle.
* As it is the master trying to contact the slave with the lowest address that
* will get the bus ownership, this will create an arbitration scheme always
* prioritizing the slaves with the lowest address in case of a bus collision.
*
* \subsubsection asfdoc_sam0_sercom_i2c_clock_sync Clock Synchronization
* In situations where more than one master is trying to control the bus clock
* line at the same time, a clock synchronization algorithm based on the same
* principles used for clock stretching is necessary.
*
*
* \subsection asfdoc_sam0_sercom_i2c_bus_states Bus States
* As the I<SUP>2</SUP>C bus is limited to one transaction at the time,
* a master that wants to perform a bus transaction must wait until the bus is
* free.
* Because of this, it is necessary for all masters in a multi-master system to
* know the current status of the bus to be able to avoid conflicts and to
* ensure data integrity.
* \li \b IDLE No activity on the bus (between a \b Stop and a new \b Start
* condition)
* \li \b OWNER If the master initiates a transaction successfully
* \li \b BUSY If another master is driving the bus
* \li \b UNKNOWN If the master has recently been enabled or connected to
* the bus. Is forced to \b IDLE after given
* \ref asfdoc_sam0_sercom_i2c_unknown_bus_timeout "timeout" when
* the master module is enabled
*
* The bus state diagram can be seen in
* \ref asfdoc_sam0_sercom_i2c_bus_states_figure "the figure below".
* \li S: Start condition
* \li P: Stop condition
* \li Sr: Repeated start condition
* \anchor asfdoc_sam0_sercom_i2c_bus_states_figure
* \image html bus_state_diagram.svg "I2C Bus State Diagram" Width=100%
*
* \subsection asfdoc_sam0_sercom_i2c_timeout Bus Timing
* Inactive bus timeout for the master and SDA hold time is configurable in the
* drivers.
*
* \subsubsection asfdoc_sam0_sercom_i2c_unknown_bus_timeout Unknown Bus State Timeout
* When a master is enabled or connected to the bus, the bus state will be
* unknown until either a given timeout or a stop command has occurred. The
* timeout is configurable in the \ref i2c_master_config struct.
* The timeout time will depend on toolchain and optimization level used, as
* the timeout is a loop incrementing a value until it reaches the specified
* timeout value.
*
* \subsubsection sda_hold SDA Hold Timeout
* When using the I<SUP>2</SUP>C in slave mode, it will be important to
* set a SDA hold time which assures that the master will be able to pick up
* the bit sent from the slave. The SDA hold time makes sure that this is the
* case by holding the data line low for a given period after the negative edge
* on the clock.
*
* The SDA hold time is also available for the master driver, but is not a
* necessity.
*
* \subsection asfdoc_sam0_sercom_i2c_sleep_modes Operation in Sleep Modes
* The I<SUP>2</SUP>C module can operate in all sleep modes by setting
* the run_in_standby Boolean in the \ref i2c_master_config or
* \ref i2c_slave_config struct.
* The operation in slave and master mode is shown in
* \ref asfdoc_sam0_sercom_i2c_sleep_modes_table "the table below".
*
* \anchor asfdoc_sam0_sercom_i2c_sleep_modes_table
* <table>
* <caption>I2C Standby Operations</caption>
* <tr>
* <th>Run in standby</th>
* <th>Slave</th>
* <th>Master</th>
* </tr>
* <tr>
* <td>false</td>
* <td>Disabled, all reception is dropped</td>
* <td>Generic Clock (GCLK) disabled when master is idle</td>
* </tr>
* <tr>
* <td>true</td>
* <td>Wake on address match when enabled</td>
* <td>GCLK enabled while in sleep modes</td>
* </tr>
* </table>
*
*
* \section asfdoc_sam0_sercom_i2c_special_considerations Special Considerations
*
* \if (I2C_MASTER_CALLBACK_MODE || I2C_SLAVE_CALLBACK_MODE)
* \subsection asfdoc_sam0_sercom_i2c_common_interrupt Interrupt-driven Operation
* While an interrupt-driven operation is in progress, subsequent calls to a
* write or read operation will return the STATUS_BUSY flag, indicating that
* only one operation is allowed at any given time.
*
* To check if another transmission can be initiated, the user can either call
* another transfer operation, or use the
* \ref i2c_master_get_job_status/\ref i2c_slave_get_job_status functions
* depending on mode.
*
* If the user would like to get callback from operations while using the
* interrupt-driven driver, the callback must be registered and then enabled
* using the "register_callback" and "enable_callback" functions.
* \else
* There are no special considerations for this driver for the APIs listed in
* this document.
* \endif
*
* \section asfdoc_sam0_sercom_i2c_extra Extra Information
* For extra information, see \ref asfdoc_sam0_sercom_i2c_extra_info_page.
* This includes:
* - \ref asfdoc_sam0_sercom_i2c_acronyms
* - \ref asfdoc_sam0_sercom_i2c_extra_dependencies
* - \ref asfdoc_sam0_sercom_i2c_extra_errata
* - \ref asfdoc_sam0_sercom_i2c_extra_history
*
* \section asfdoc_sam0_sercom_i2c_examples Examples
*
* For a list of examples related to this driver, see
* \ref asfdoc_sam0_sercom_i2c_exqsg.
*
* \section asfdoc_sam0_sercom_i2c_api_overview API Overview
* @{
*/

/**
* \name Driver Feature Definition
* Define SERCOM I<SUP>2</SUP>C driver features set according to different device family.
*
* @{
*/
#if (SAMD21) || (SAMR21) || (SAMD10) || (SAMD11) || (SAML21) || (SAMDA1) || \
(SAMHA1) || (SAMHA0) || (SAML22) || (SAMC20) || (SAMC21) || (SAMD09) || (SAMR30) || (SAMR34) || (SAMR35) || (WLR089) || defined(__DOXYGEN__)
/** Fast mode plus and high speed support. */
# define FEATURE_I2C_FAST_MODE_PLUS_AND_HIGH_SPEED
/** 10-bit address support */
# define FEATURE_I2C_10_BIT_ADDRESS
/** SCL stretch mode support */
# define FEATURE_I2C_SCL_STRETCH_MODE
/** SCL extend timeout support */
# define FEATURE_I2C_SCL_EXTEND_TIMEOUT
# define FEATURE_I2C_DMA_SUPPORT
#endif
/*@}*/

/** \brief Transfer direction
*
* For master: transfer direction or setting direction bit in address.
* For slave: direction of request from master.
*/
enum i2c_transfer_direction {
/** Master write operation is in progress */
I2C_TRANSFER_WRITE = 0,
/** Master read operation is in progress */
I2C_TRANSFER_READ = 1,
};

/** @} */

#ifdef __cplusplus
}
#endif

/**
* \page asfdoc_sam0_sercom_i2c_extra_info_page Extra Information for SERCOM I2C Driver
*
* \section asfdoc_sam0_sercom_i2c_acronyms Acronyms
* \ref asfdoc_sam0_sercom_i2c_acronyms_table "Below" is a table listing the acronyms
* used in this module, along with their intended meanings.
*
* \anchor asfdoc_sam0_sercom_i2c_acronyms_table
* <table>
* <caption>Acronyms</caption>
* <tr>
* <th>Acronym</th>
* <th>Description</th>
* </tr>
* <tr>
* <td>SDA</td>
* <td>Serial Data Line</td>
* </tr>
* <tr>
* <td>SCL</td>
* <td>Serial Clock Line</td>
* </tr>
* <tr>
* <td>SERCOM</td>
* <td>Serial Communication Interface</td>
* </tr>
* <tr>
* <td>DMA</td>
* <td>Direct Memory Access</td>
* </tr>
* </table>
*
* \section asfdoc_sam0_sercom_i2c_extra_dependencies Dependencies
* The I<SUP>2</SUP>C driver has the following dependencies:
* \li \ref asfdoc_sam0_system_pinmux_group "System Pin Multiplexer Driver"
*
*
* \section asfdoc_sam0_sercom_i2c_extra_errata Errata
* There are no errata related to this driver.
*
* \section asfdoc_sam0_sercom_i2c_extra_history Module History
* \ref asfdoc_sam0_sercom_i2c_extra_history_table "Below" is an overview of the
* module history, detailing enhancements and fixes made to the module since
* its first release. The current version of this corresponds to the newest
* version listed in
* \ref asfdoc_sam0_sercom_i2c_extra_history_table "the table below".
*
* \anchor asfdoc_sam0_sercom_i2c_extra_history_table
* <table>
* <caption>Module History</caption>
* <tr>
* <th>Changelog</th>
* </tr>
* <tr>
* <td>
* \li Added 10-bit addressing and high speed support in SAM D21
* \li Separate structure i2c_packet into i2c_master_packet and i2c_slave packet
* </td>
* </tr>
* <tr>
* <td>
* \li Added support for SCL stretch and extended timeout hardware features in SAM D21
* \li Added fast mode plus support in SAM D21
* </td>
* </tr>
* <tr>
* <td>Fixed incorrect logical mask for determining if a bus error has
* occurred in I<SUP>2</SUP>C Slave mode
* </td>
* </tr>
* <tr>
* <td>Initial Release</td>
* </tr>
* </table>
*/

/**
* \page asfdoc_sam0_sercom_i2c_exqsg Examples for SERCOM I2C Driver
*
* This is a list of the available Quick Start guides (QSGs) and example
* applications for \ref asfdoc_sam0_sercom_i2c_group. QSGs are simple examples with
* step-by-step instructions to configure and use this driver in a selection of
* use cases. Note that a QSG can be compiled as a standalone application or be
* added to the user application.
*
* \if I2C_MASTER_MODE
* - \subpage asfdoc_sam0_sercom_i2c_master_basic_use_case "Quick Start Guide for the I2C Master module - Basic Use Case"
* \endif
* \if I2C_MASTER_CALLBACK_MODE
* - \subpage asfdoc_sam0_sercom_i2c_master_callback_use_case "Quick Start Guide for the I2C Master module - Callback Use Case"
* - \subpage asfdoc_sam0_sercom_i2c_master_dma_use_case "Quick Start Guide for the I2C Master module - DMA Use Case"
* \endif
* \if I2C_SLAVE_MODE
* - \subpage asfdoc_sam0_sercom_i2c_slave_basic_use_case "Quick Start Guide for the I2C Slave module - Basic Use Case"
* \endif
* \if I2C_SLAVE_CALLBACK_MODE
* - \subpage asfdoc_sam0_sercom_i2c_slave_callback_use_case "Quick Start Guide for the I2C Slave module - Callback Use Case"
* - \subpage asfdoc_sam0_sercom_i2c_slave_dma_use_case "Quick Start Guide for the I2C Slave module - DMA Use Case"
* \endif
*
* \page asfdoc_sam0_sercom_i2c_document_revision_history Document Revision History
*
* \if (I2C_MASTER_MODE || I2C_MASTER_CALLBACK_MODE)
* <table>
* <tr>
* <th>Doc. Rev.</th>
* <th>Date</th>
* <th>Comments</th>
* </tr>
* <tr>
* <td>42117E</td>
* <td>12/2015</td>
* <td>Added support for SAM L21/L22, SAM DA1, SAM D09, and SAM C21</td>
* </tr>
* <tr>
* <td>42117D</td>
* <td>12/2014</td>
* <td>Added support for 10-bit addressing and high speed in SAM D21.
* Added support for SAM R21 and SAM D10/D11.</td>
* </tr>
* <tr>
* <td>42117C</td>
* <td>01/2014</td>
* <td>Added support for SAM D21</td>
* </tr>
* <tr>
* <td>42117B</td>
* <td>06/2013</td>
* <td>Corrected documentation typos. Updated I<SUP>2</SUP>C Bus State Diagram.</td>
* </tr>
* <tr>
* <td>42117A</td>
* <td>06/2013</td>
* <td>Initial release</td>
* </tr>
* </table>
* \else
* <table>
* <tr>
* <th>Doc. Rev.</th>
* <th>Date</th>
* <th>Comments</th>
* </tr>
* <tr>
* <td>42116E</td>
* <td>12/2015</td>
* <td>Added support for SAM L21/L22, SAM DA1, SAM D09, and SAM C21</td>
* </tr>
* <tr>
* <td>42116D</td>
* <td>12/2014</td>
* <td>Added support for 10-bit addressing and high speed in SAM D21.
* Added support for SAM R21 and SAM D10/D11.</td>
* </tr>
* <tr>
* <td>42116C</td>
* <td>01/2014</td>
* <td>Added support for SAM D21</td>
* </tr>
* <tr>
* <td>42116B</td>
* <td>06/2013</td>
* <td>Corrected documentation typos. Updated I<SUP>2</SUP>C Bus State Diagram.</td>
* </tr>
* <tr>
* <td>42116A</td>
* <td>06/2013</td>
* <td>Initial release</td>
* </tr>
* </table>
*\endif
*/

#endif /* I2C_COMMON_H_INCLUDED */

+ 0
- 619
firmware/SendcommPeer2P/src/ASF/sam0/drivers/sercom/i2c/i2c_master.h View File

@@ -1,619 +0,0 @@
/**
* \file
*
* \brief SAM SERCOM I2C Master Driver
*
* Copyright (c) 2012-2018 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/
/*
* Support and FAQ: visit <a href="https://www.microchip.com/support/">Microchip Support</a>
*/

#ifndef I2C_MASTER_H_INCLUDED
#define I2C_MASTER_H_INCLUDED

#include "i2c_common.h"
#include <sercom.h>
#include <pinmux.h>

#if I2C_MASTER_CALLBACK_MODE == true
# include <sercom_interrupt.h>
#endif

#ifdef __cplusplus
extern "C" {
#endif

#ifndef PINMUX_DEFAULT
# define PINMUX_DEFAULT 0
#endif

/**
* \addtogroup asfdoc_sam0_sercom_i2c_group
*
* @{
*/

/**
* \brief I<SUP>2</SUP>C master packet for read/write
*
* Structure to be used when transferring I<SUP>2</SUP>C master packets.
*/
struct i2c_master_packet {
/** Address to slave device */
uint16_t address;
/** Length of data array */
uint16_t data_length;
/** Data array containing all data to be transferred */
uint8_t *data;
/** Use 10-bit addressing. Set to false if the feature is not supported by the device */
bool ten_bit_address;
/** Use high speed transfer. Set to false if the feature is not supported by the device */
bool high_speed;
/** High speed mode master code (0000 1XXX), valid when high_speed is true */
uint8_t hs_master_code;
};

/** \brief Interrupt flags
*
* Flags used when reading or setting interrupt flags.
*/
enum i2c_master_interrupt_flag {
/** Interrupt flag used for write */
I2C_MASTER_INTERRUPT_WRITE = 0,
/** Interrupt flag used for read */
I2C_MASTER_INTERRUPT_READ = 1,
};

/**
* \brief Values for hold time after start bit.
*
* Values for the possible I<SUP>2</SUP>C master mode SDA internal hold times after start
* bit has been sent.
*/
enum i2c_master_start_hold_time {
/** Internal SDA hold time disabled */
I2C_MASTER_START_HOLD_TIME_DISABLED = SERCOM_I2CM_CTRLA_SDAHOLD(0),
/** Internal SDA hold time 50ns - 100ns */
I2C_MASTER_START_HOLD_TIME_50NS_100NS = SERCOM_I2CM_CTRLA_SDAHOLD(1),
/** Internal SDA hold time 300ns - 600ns */
I2C_MASTER_START_HOLD_TIME_300NS_600NS = SERCOM_I2CM_CTRLA_SDAHOLD(2),
/** Internal SDA hold time 400ns - 800ns */
I2C_MASTER_START_HOLD_TIME_400NS_800NS = SERCOM_I2CM_CTRLA_SDAHOLD(3),
};

/**
* \brief Values for inactive bus time-out.
*
* If the inactive bus time-out is enabled and the bus is inactive for
* longer than the time-out setting, the bus state logic will be set to idle.
*/
enum i2c_master_inactive_timeout {
/** Inactive bus time-out disabled */
I2C_MASTER_INACTIVE_TIMEOUT_DISABLED = SERCOM_I2CM_CTRLA_INACTOUT(0),
/** Inactive bus time-out 5-6 SCL cycle time-out */
I2C_MASTER_INACTIVE_TIMEOUT_55US = SERCOM_I2CM_CTRLA_INACTOUT(1),
/** Inactive bus time-out 10-11 SCL cycle time-out */
I2C_MASTER_INACTIVE_TIMEOUT_105US = SERCOM_I2CM_CTRLA_INACTOUT(2),
/** Inactive bus time-out 20-21 SCL cycle time-out */
I2C_MASTER_INACTIVE_TIMEOUT_205US = SERCOM_I2CM_CTRLA_INACTOUT(3),
};

/**
* \brief I<SUP>2</SUP>C frequencies
*
* Values for I<SUP>2</SUP>C speeds supported by the module. The driver
* will also support setting any other value, in which case set
* the value in the \ref i2c_master_config at desired value divided by 1000.
*
* Example: If 10KHz operation is required, give baud_rate in the configuration
* structure the value 10.
*/
enum i2c_master_baud_rate {
/** Baud rate at 100KHz (Standard-mode) */
I2C_MASTER_BAUD_RATE_100KHZ = 100,
/** Baud rate at 400KHz (Fast-mode) */
I2C_MASTER_BAUD_RATE_400KHZ = 400,
#ifdef FEATURE_I2C_FAST_MODE_PLUS_AND_HIGH_SPEED
/** Baud rate at 1MHz (Fast-mode Plus) */
I2C_MASTER_BAUD_RATE_1000KHZ = 1000,
/** Baud rate at 3.4MHz (High-speed mode) */
I2C_MASTER_BAUD_RATE_3400KHZ = 3400,
#endif
};

#ifdef FEATURE_I2C_FAST_MODE_PLUS_AND_HIGH_SPEED
/**
* \brief Enum for the transfer speed
*
* Enum for the transfer speed.
*/
enum i2c_master_transfer_speed {
/** Standard-mode (Sm) up to 100KHz and Fast-mode (Fm) up to 400KHz */
I2C_MASTER_SPEED_STANDARD_AND_FAST = SERCOM_I2CM_CTRLA_SPEED(0),
/** Fast-mode Plus (Fm+) up to 1MHz */
I2C_MASTER_SPEED_FAST_MODE_PLUS = SERCOM_I2CM_CTRLA_SPEED(1),
/** High-speed mode (Hs-mode) up to 3.4MHz */
I2C_MASTER_SPEED_HIGH_SPEED = SERCOM_I2CM_CTRLA_SPEED(2),
};
#endif

#if I2C_MASTER_CALLBACK_MODE == true
/**
* \brief Callback types
*
* The available callback types for the I<SUP>2</SUP>C master module.
*/
enum i2c_master_callback {
/** Callback for packet write complete */
I2C_MASTER_CALLBACK_WRITE_COMPLETE = 0,
/** Callback for packet read complete */
I2C_MASTER_CALLBACK_READ_COMPLETE = 1,
/** Callback for error */
I2C_MASTER_CALLBACK_ERROR = 2,
# if !defined(__DOXYGEN__)
/** Total number of callbacks */
_I2C_MASTER_CALLBACK_N = 3,
# endif
};

# if !defined(__DOXYGEN__)
/* Prototype for software module */
struct i2c_master_module;

typedef void (*i2c_master_callback_t)(
struct i2c_master_module *const module);
# endif
#endif

/**
* \brief SERCOM I<SUP>2</SUP>C Master driver software device instance structure.
*
* SERCOM I<SUP>2</SUP>C Master driver software instance structure, used to
* retain software state information of an associated hardware module instance.
*
* \note The fields of this structure should not be altered by the user
* application; they are reserved for module-internal use only.
*/
struct i2c_master_module {
#if !defined(__DOXYGEN__)
/** Hardware instance initialized for the struct */
Sercom *hw;
/** Module lock */
volatile bool locked;
/** Unknown bus state timeout */
uint16_t unknown_bus_state_timeout;
/** Buffer write timeout value */
uint16_t buffer_timeout;
/** If true, stop condition will be sent after a read/write */
bool send_stop;
/** If true, nack signal will be sent after a read/write */
bool send_nack;
# if I2C_MASTER_CALLBACK_MODE == true
/** Pointers to callback functions */
volatile i2c_master_callback_t callbacks[_I2C_MASTER_CALLBACK_N];
/** Mask for registered callbacks */
volatile uint8_t registered_callback;
/** Mask for enabled callbacks */
volatile uint8_t enabled_callback;
/** The total number of bytes to transfer */
volatile uint16_t buffer_length;
/**
* Counter used for bytes left to send in write and to count number of
* obtained bytes in read
*/
volatile uint16_t buffer_remaining;
/** Data buffer for packet write and read */
volatile uint8_t *buffer;
/** Save direction of async request. 1 = read, 0 = write */
volatile enum i2c_transfer_direction transfer_direction;
/** Status for status read back in error callback */
volatile enum status_code status;
# endif
#endif
};

/**
* \brief Configuration structure for the I<SUP>2</SUP>C Master device
*
* This is the configuration structure for the I<SUP>2</SUP>C Master device. It
* is used as an argument for \ref i2c_master_init to provide the desired
* configurations for the module. The structure should be initialized using the
* \ref i2c_master_get_config_defaults.
*/
struct i2c_master_config {
/** Baud rate (in KHz) for I<SUP>2</SUP>C operations in
* standard-mode, Fast-mode, and Fast-mode Plus Transfers,
* \ref i2c_master_baud_rate */
uint32_t baud_rate;
#ifdef FEATURE_I2C_FAST_MODE_PLUS_AND_HIGH_SPEED
/** Baud rate (in KHz) for I<SUP>2</SUP>C operations in
* High-speed mode, \ref i2c_master_baud_rate */
uint32_t baud_rate_high_speed;
/** Transfer speed mode */
enum i2c_master_transfer_speed transfer_speed;
#endif
/** GCLK generator to use as clock source */
enum gclk_generator generator_source;
/** Bus hold time after start signal on data line */
enum i2c_master_start_hold_time start_hold_time;
/** Unknown bus state \ref asfdoc_sam0_sercom_i2c_unknown_bus_timeout "timeout" */
uint16_t unknown_bus_state_timeout;
/** Timeout for packet write to wait for slave */
uint16_t buffer_timeout;
/** Set to keep module active in sleep modes */
bool run_in_standby;
/** PAD0 (SDA) pinmux */
uint32_t pinmux_pad0;
/** PAD1 (SCL) pinmux */
uint32_t pinmux_pad1;
/** Set to enable SCL low time-out */
bool scl_low_timeout;
/** Inactive bus time out */
enum i2c_master_inactive_timeout inactive_timeout;
#ifdef FEATURE_I2C_SCL_STRETCH_MODE
/** Set to enable SCL stretch only after ACK bit (required for high speed) */
bool scl_stretch_only_after_ack_bit;
#endif
#ifdef FEATURE_I2C_SCL_EXTEND_TIMEOUT
/** Set to enable slave SCL low extend time-out */
bool slave_scl_low_extend_timeout;
/** Set to enable maser SCL low extend time-out */
bool master_scl_low_extend_timeout;
#endif
/** Get more accurate BAUD, considering rise time(required for standard-mode and Fast-mode) */
uint16_t sda_scl_rise_time_ns;
};

/**
* \name Lock/Unlock
* @{
*/

/**
* \brief Attempt to get lock on driver instance
*
* This function checks the instance's lock, which indicates whether or not it
* is currently in use, and sets the lock if it was not already set.
*
* The purpose of this is to enable exclusive access to driver instances, so
* that, e.g., transactions by different services will not interfere with each
* other.
*
* \param[in,out] module Pointer to the driver instance to lock
*
* \retval STATUS_OK If the module was locked
* \retval STATUS_BUSY If the module was already locked
*/
static inline enum status_code i2c_master_lock(
struct i2c_master_module *const module)
{
enum status_code status;

system_interrupt_enter_critical_section();

if (module->locked) {
status = STATUS_BUSY;
} else {
module->locked = true;
status = STATUS_OK;
}

system_interrupt_leave_critical_section();

return status;
}

/**
* \brief Unlock driver instance
*
* This function clears the instance lock, indicating that it is available for
* use.
*
* \param[in,out] module Pointer to the driver instance to lock
*
* \retval STATUS_OK If the module was locked
* \retval STATUS_BUSY If the module was already locked
*/
static inline void i2c_master_unlock(struct i2c_master_module *const module)
{
module->locked = false;
}

/** @} */

/**
* \name Configuration and Initialization
* @{
*/

/**
* \brief Returns the synchronization status of the module
*
* Returns the synchronization status of the module.
*
* \param[in] module Pointer to software module structure
*
* \return Status of the synchronization.
* \retval true Module is busy synchronizing
* \retval false Module is not synchronizing
*/
static inline bool i2c_master_is_syncing (
const struct i2c_master_module *const module)
{
/* Sanity check */
Assert(module);
Assert(module->hw);

SercomI2cm *const i2c_hw = &(module->hw->I2CM);

#if defined(FEATURE_SERCOM_SYNCBUSY_SCHEME_VERSION_1)
return (i2c_hw->STATUS.reg & SERCOM_I2CM_STATUS_SYNCBUSY);
#elif defined(FEATURE_SERCOM_SYNCBUSY_SCHEME_VERSION_2)
return (i2c_hw->SYNCBUSY.reg & SERCOM_I2CM_SYNCBUSY_MASK);
#else
# error Unknown SERCOM SYNCBUSY scheme!
#endif
}

#if !defined(__DOXYGEN__)
/**
* \internal
* Wait for hardware module to sync
*
* \param[in] module Pointer to software module structure
*/
static void _i2c_master_wait_for_sync(
const struct i2c_master_module *const module)
{
/* Sanity check */
Assert(module);

while (i2c_master_is_syncing(module)) {
/* Wait for I2C module to sync. */
}
}
#endif

/**
* \brief Gets the I<SUP>2</SUP>C master default configurations
*
* Use to initialize the configuration structure to known default values.
*
* The default configuration is as follows:
* - Baudrate 100KHz
* - GCLK generator 0
* - Do not run in standby
* - Start bit hold time 300ns - 600ns
* - Buffer timeout = 65535
* - Unknown bus status timeout = 65535
* - Do not run in standby
* - PINMUX_DEFAULT for SERCOM pads
*
* Those default configuration only available if the device supports it:
* - High speed baudrate 3.4MHz
* - Standard-mode and Fast-mode transfer speed
* - SCL stretch disabled
* - Slave SCL low extend time-out disabled
* - Master SCL low extend time-out disabled
*
* \param[out] config Pointer to configuration structure to be initiated
*/
static inline void i2c_master_get_config_defaults(
struct i2c_master_config *const config)
{
/*Sanity check argument */
Assert(config);
config->baud_rate = I2C_MASTER_BAUD_RATE_100KHZ;
#ifdef FEATURE_I2C_FAST_MODE_PLUS_AND_HIGH_SPEED
config->baud_rate_high_speed = I2C_MASTER_BAUD_RATE_3400KHZ;
config->transfer_speed = I2C_MASTER_SPEED_STANDARD_AND_FAST;
#endif
config->generator_source = GCLK_GENERATOR_0;
config->run_in_standby = false;
config->start_hold_time = I2C_MASTER_START_HOLD_TIME_300NS_600NS;
config->buffer_timeout = 65535;
config->unknown_bus_state_timeout = 65535;
config->pinmux_pad0 = PINMUX_DEFAULT;
config->pinmux_pad1 = PINMUX_DEFAULT;
config->scl_low_timeout = false;
config->inactive_timeout = I2C_MASTER_INACTIVE_TIMEOUT_DISABLED;
#ifdef FEATURE_I2C_SCL_STRETCH_MODE
config->scl_stretch_only_after_ack_bit = false;
#endif
#ifdef FEATURE_I2C_SCL_EXTEND_TIMEOUT
config->slave_scl_low_extend_timeout = false;
config->master_scl_low_extend_timeout = false;
#endif
/* The typical value is 215ns */
config->sda_scl_rise_time_ns = 215;
}

enum status_code i2c_master_init(
struct i2c_master_module *const module,
Sercom *const hw,
const struct i2c_master_config *const config);

/**
* \brief Enables the I<SUP>2</SUP>C module
*
* Enables the requested I<SUP>2</SUP>C module and set the bus state to IDLE
* after the specified \ref asfdoc_sam0_sercom_i2c_timeout "timeout" period if no
* stop bit is detected.
*
* \param[in] module Pointer to the software module struct
*/
static inline void i2c_master_enable(
const struct i2c_master_module *const module)
{
/* Sanity check of arguments */
Assert(module);
Assert(module->hw);

SercomI2cm *const i2c_module = &(module->hw->I2CM);

/* Timeout counter used to force bus state */
uint32_t timeout_counter = 0;

/* Wait for module to sync */
_i2c_master_wait_for_sync(module);

/* Enable module */
i2c_module->CTRLA.reg |= SERCOM_I2CM_CTRLA_ENABLE;

#if I2C_MASTER_CALLBACK_MODE == true
/* Enable module interrupts */
system_interrupt_enable(_sercom_get_interrupt_vector(module->hw));
#endif
/* Start timeout if bus state is unknown */
while (!(i2c_module->STATUS.reg & SERCOM_I2CM_STATUS_BUSSTATE(1))) {
timeout_counter++;
if(timeout_counter >= (module->unknown_bus_state_timeout)) {
/* Timeout, force bus state to idle */
i2c_module->STATUS.reg = SERCOM_I2CM_STATUS_BUSSTATE(1);
/* Workaround #1 */
return;
}
}
}

/**
* \brief Disable the I<SUP>2</SUP>C module
*
* Disables the requested I<SUP>2</SUP>C module.
*
* \param[in] module Pointer to the software module struct
*/
static inline void i2c_master_disable(
const struct i2c_master_module *const module)
{
/* Sanity check of arguments */
Assert(module);
Assert(module->hw);

SercomI2cm *const i2c_module = &(module->hw->I2CM);

#if I2C_MASTER_CALLBACK_MODE == true
/* Disable module interrupts */
system_interrupt_disable(_sercom_get_interrupt_vector(module->hw));
#endif

/* Wait for module to sync */
_i2c_master_wait_for_sync(module);

/* Disbale interrupt */
i2c_module->INTENCLR.reg = SERCOM_I2CM_INTENCLR_MASK;
/* Clear interrupt flag */
i2c_module->INTFLAG.reg = SERCOM_I2CM_INTFLAG_MASK;

/* Disable module */
i2c_module->CTRLA.reg &= ~SERCOM_I2CM_CTRLA_ENABLE;

}

void i2c_master_reset(struct i2c_master_module *const module);

/** @} */

/**
* \name Read and Write
* @{
*/

enum status_code i2c_master_read_packet_wait(
struct i2c_master_module *const module,
struct i2c_master_packet *const packet);

enum status_code i2c_master_read_packet_wait_no_stop(
struct i2c_master_module *const module,
struct i2c_master_packet *const packet);

enum status_code i2c_master_write_packet_wait(
struct i2c_master_module *const module,
struct i2c_master_packet *const packet);

enum status_code i2c_master_write_packet_wait_no_stop(
struct i2c_master_module *const module,
struct i2c_master_packet *const packet);

void i2c_master_send_stop(struct i2c_master_module *const module);

void i2c_master_send_nack(struct i2c_master_module *const module);

enum status_code i2c_master_read_byte(
struct i2c_master_module *const module,
uint8_t *byte);

enum status_code i2c_master_write_byte(
struct i2c_master_module *const module,
uint8_t byte);

enum status_code i2c_master_read_packet_wait_no_nack(
struct i2c_master_module *const module,
struct i2c_master_packet *const packet);

/** @} */

#ifdef FEATURE_I2C_DMA_SUPPORT
/**
* \name SERCOM I2C Master with DMA Interfaces
* @{
*/

/**
* \brief Set I<SUP>2</SUP>C for DMA transfer with slave address and transfer size.
*
* This function will set the slave address, transfer size and enable the auto transfer
* mode for DMA.
*
* \param[in,out] module Pointer to the driver instance to lock
* \param[in] addr I<SUP>2</SUP>C slave address
* \param[in] length I<SUP>2</SUP>C transfer length with DMA
* \param[in] direction I<SUP>2</SUP>C transfer direction
*
*/
static inline void i2c_master_dma_set_transfer(struct i2c_master_module *const module,
uint16_t addr, uint8_t length, enum i2c_transfer_direction direction)
{
module->hw->I2CM.ADDR.reg =
SERCOM_I2CM_ADDR_ADDR(addr<<1) |
SERCOM_I2CM_ADDR_LENEN |
SERCOM_I2CM_ADDR_LEN(length) |
direction;
}

/** @} */
#endif

/** @} */

#ifdef __cplusplus
}
#endif

#endif /* I2C_MASTER_H_INCLUDED */

+ 0
- 1040
firmware/SendcommPeer2P/src/ASF/sam0/drivers/sercom/i2c/i2c_sam0/i2c_master.c
File diff suppressed because it is too large
View File


+ 0
- 108
firmware/SendcommPeer2P/src/ASF/sam0/drivers/sercom/i2c/quick_start_master/qs_i2c_master_basic_use.h View File

@@ -1,108 +0,0 @@
/**
* \file
*
* \brief SAM SERCOM I2C Master Quick Start Guide
*
* Copyright (c) 2012-2018 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/

/**
* \page asfdoc_sam0_sercom_i2c_master_basic_use_case Quick Start Guide for SERCOM I2C Master - Basic
*
* In this use case, the I<SUP>2</SUP>C will used and set up as follows:
* - Master mode
* - 100KHz operation speed
* - Not operational in standby
* - 10000 packet timeout value
* - 65535 unknown bus state timeout value
*
*
* \section asfdoc_sam0_sercom_i2c_master_basic_use_case_prereq Prerequisites
* The device must be connected to an I<SUP>2</SUP>C slave.
*
* \section asfdoc_sam0_sercom_i2c_master_basic_use_setup Setup
*
* \subsection asfdoc_sam0_sercom_i2c_master_basic_use_setup_code Code
* The following must be added to the user application:
*
* - A sample buffer to send, a sample buffer to read:
* \snippet qs_i2c_master_basic_use.c packet_data
*
* - Slave address to access:
* \snippet qs_i2c_master_basic_use.c address
*
* - Number of times to try to send packet if it fails:
* \snippet qs_i2c_master_basic_use.c timeout
*
* - Globally accessible module structure:
* \snippet qs_i2c_master_basic_use.c dev_inst
*
* - Function for setting up the module:
* \snippet qs_i2c_master_basic_use.c initialize_i2c
*
* - Add to user application \c main():
* \snippet qs_i2c_master_basic_use.c init
*
* \subsection asfdoc_sam0_sercom_i2c_master_basic_use_setup_workflow Workflow
* -# Configure and enable module.
* \snippet qs_i2c_master_basic_use.c initialize_i2c
* -# Create and initialize configuration structure.
* \snippet qs_i2c_master_basic_use.c init_conf
* -# Change settings in the configuration.
* \snippet qs_i2c_master_basic_use.c conf_change
* -# Initialize the module with the set configurations.
* \snippet qs_i2c_master_basic_use.c init_module
* -# Enable the module.
* \snippet qs_i2c_master_basic_use.c enable_module
* -# Create a variable to see when we should stop trying to send packet.
* \snippet qs_i2c_master_basic_use.c timeout_counter
* -# Create a packet to send.
* \snippet qs_i2c_master_basic_use.c packet
*
* \section asfdoc_sam0_sercom_i2c_master_basic_use_implemenation Implementation
* \subsection asfdoc_sam0_sercom_i2c_master_basic_use_implemenation_code Code
* Add to user application \c main():
* \snippet qs_i2c_master_basic_use.c main
*
* \subsection asfdoc_sam0_sercom_i2c_master_basic_use_implemenation_workflow Workflow
* -# Write packet to slave.
* \snippet qs_i2c_master_basic_use.c write_packet
* The module will try to send the packet TIMEOUT number of times or until it is
* successfully sent.
* -# Read packet from slave.
* \snippet qs_i2c_master_basic_use.c read_packet
* The module will try to read the packet TIMEOUT number of times or until it is
* successfully read.
*/
/*
* Support and FAQ: visit <a href="https://www.microchip.com/support/">Microchip Support</a>
*/

#include <asf.h>
#include <conf_clocks.h>


+ 0
- 164
firmware/SendcommPeer2P/src/ASF/sam0/drivers/sercom/i2c/quick_start_master_dma/qs_i2c_master_dma.h View File

@@ -1,164 +0,0 @@
/**
* \file
*
* \brief SAM SERCOM I2C Master Driver with DMA Quick Start Guide
*
* Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/

/**
* \page asfdoc_sam0_sercom_i2c_master_dma_use_case Quick Start Guide for Using DMA with SERCOM I2C Master
*
* The supported board list:
* - SAMD21 Xplained Pro
* - SAMR21 Xplained Pro
* - SAML21 Xplained Pro
* - SAML22 Xplained Pro
* - SAMDA1 Xplained Pro
* - SAMC21 Xplained Pro
* - SAMHA1G16A Xplained Pro
*
* In this use case, the I<SUP>2</SUP>C will used and set up as follows:
* - Master mode
* - 100KHz operation speed
* - Not operational in standby
* - 10000 packet timeout value
* - 65535 unknown bus state timeout value
*
*
* \section asfdoc_sam0_sercom_i2c_master_dma_use_case_prereq Prerequisites
* The device must be connected to an I<SUP>2</SUP>C slave.
*
* \section asfdoc_sam0_sercom_i2c_master_dma_use_setup Setup
*
* \subsection asfdoc_sam0_sercom_i2c_master_dma_use_setup_code Code
* The following must be added to the user application:
*
* - A sample buffer to send, number of entries to send and address of slave:
* \snippet qs_i2c_master_dma.c packet_data
*
* Number of times to try to send packet if it fails:
* \snippet qs_i2c_master_dma.c timeout
*
* - Globally accessible module structure:
* \snippet qs_i2c_master_dma.c dev_i2c_inst
*
* - Function for setting up the module:
* \snippet qs_i2c_master_dma.c initialize_i2c
*
* - Globally accessible DMA module structure:
* \snippet qs_i2c_master_dma.c dma_resource
*
* - Globally transfer done flag:
* \snippet qs_i2c_master_dma.c transfer_done_flag
*
* - Globally accessible DMA transfer descriptor:
* \snippet qs_i2c_master_dma.c transfer_descriptor
*
* - Function for transfer done callback:
* \snippet qs_i2c_master_dma.c transfer_done
*
* - Function for setting up the DMA resource:
* \snippet qs_i2c_master_dma.c config_dma_resource
*
* - Function for setting up the DMA transfer descriptor:
* \snippet qs_i2c_master_dma.c setup_dma_transfer_descriptor
* - Add to user application \c main():
* \snippet qs_i2c_master_dma.c init
*
* \subsection asfdoc_sam0_sercom_i2c_master_dma_use_setup_workflow Workflow
* -# Configure and enable module:
* \snippet qs_i2c_master_dma.c config_i2c
* -# Create and initialize configuration structure.
* \snippet qs_i2c_master_dma.c init_conf
* -# Change settings in the configuration.
* \snippet qs_i2c_master_dma.c conf_change
* -# Initialize the module with the set configurations.
* \snippet qs_i2c_master_dma.c init_module
* -# Enable the module.
* \snippet qs_i2c_master_dma.c enable_module
*
* -# Configure DMA
* -# Create a DMA resource configuration structure, which can be filled out to
* adjust the configuration of a single DMA transfer.
* \snippet qs_i2c_master_dma.c dma_setup_1
*
* -# Initialize the DMA resource configuration struct with the module's
* default values.
* \snippet qs_i2c_master_dma.c dma_setup_2
* \note This should always be performed before using the configuration
* struct to ensure that all values are initialized to known default
* settings.
*
* -# Set extra configurations for the DMA resource. It is using peripheral
* trigger. SERCOM TX trigger causes a transaction transfer in
* this example.
* \snippet qs_i2c_master_dma.c dma_setup_3
*
* -# Allocate a DMA resource with the configurations.
* \snippet qs_i2c_master_dma.c dma_setup_4
*
* -# Create a DMA transfer descriptor configuration structure, which can be
* filled out to adjust the configuration of a single DMA transfer.
* \snippet qs_i2c_master_dma.c dma_setup_5
*
* -# Initialize the DMA transfer descriptor configuration struct with the module's
* default values.
* \snippet qs_i2c_master_dma.c dma_setup_6
* \note This should always be performed before using the configuration
* struct to ensure that all values are initialized to known default
* settings.
*
* -# Set the specific parameters for a DMA transfer with transfer size, source
* address, and destination address.
* \snippet qs_i2c_master_dma.c dma_setup_7
*
* -# Create the DMA transfer descriptor.
* \snippet qs_i2c_master_dma.c dma_setup_8
*
* \section asfdoc_sam0_sercom_i2c_master_dma_use_implemenation Implementation
* \subsection asfdoc_sam0_sercom_i2c_master_dma_use_implemenation_code Code
* Add to user application \c main():
* \snippet qs_i2c_master_dma.c main
*
* \subsection asfdoc_sam0_sercom_i2c_master_dma_use_implemenation_workflow Workflow
* -# Start the DMA transfer job.
* \snippet qs_i2c_master_dma.c start_transfer_job
*
* -# Set the auto address length and enable flag.
* \snippet qs_i2c_master_dma.c set_i2c_addr
*
* -# Waiting for transfer complete.
* \snippet qs_i2c_master_dma.c waiting_for_complete
*
* -# Enter an infinite loop once transfer complete.
* \snippet qs_i2c_master_dma.c inf_loop
*/
/*
* Support and FAQ: visit <a href="https://www.microchip.com/support/">Microchip Support</a>
*/

+ 1
- 1
firmware/SendcommPeer2P/src/ASF/sam0/drivers/sercom/sercom_pinout.h View File

@@ -484,7 +484,7 @@
#define SERCOM5_PAD2_DEFAULT PINMUX_PA20C_SERCOM5_PAD2
#define SERCOM5_PAD3_DEFAULT PINMUX_PA21C_SERCOM5_PAD3

#elif (SAML21E) || (SAMR34) || (SAMR35) || (WLR089)
#elif (SAML21E) || (SAMR34) || (SAMR35)

/* SERCOM0 */
#define SERCOM0_PAD0_DEFAULT PINMUX_PA04D_SERCOM0_PAD0


+ 145
- 0
firmware/SendcommPeer2P/src/ASF/sam0/drivers/sercom/spi/quick_start_master_callback/qs_spi_master_callback.h View File

@@ -0,0 +1,145 @@
/**
* \file
*
* \brief SAM SPI Quick Start
*
* Copyright (c) 2012-2018 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/

/**
* \page asfdoc_sam0_sercom_spi_master_callback_use Quick Start Guide for SERCOM SPI Master - Callback
*
* In this use case, the SPI on extension header 1 of the Xplained Pro board
* will be configured with the following settings:
* - Master Mode enabled
* - MSB of the data is transmitted first
* - Transfer mode 0
* - SPI MUX Setting E (see \ref asfdoc_sam0_sercom_spi_mux_settings_master)
* - 8-bit character size
* - Not enabled in sleep mode
* - Baudrate 100000
* - GLCK generator 0
*
*
* \section asfdoc_sam0_sercom_spi_master_callback_use_setup Setup
*
* \subsection asfdoc_sam0_sercom_spi_master_callback_use_prereq Prerequisites
* There are no special setup requirements for this use-case.
*
* \subsection asfdoc_sam0_sercom_spi_master_callback_use_setup_code Code
* The following must be added to the user application.
*
* A sample buffer to send via SPI.
* \snippet qs_spi_master_callback.c buffer
* Number of entries in the sample buffer.
* \snippet qs_spi_master_callback.c buf_length
* GPIO pin to use as Slave Select.
* \snippet qs_spi_master_callback.c slave_select_pin
* A globally available software device instance struct to store the SPI driver
* state while it is in use.
* \snippet qs_spi_master_callback.c dev_inst
* A globally available peripheral slave software device instance struct.
* \snippet qs_spi_master_callback.c slave_dev_inst
* A function for configuring the SPI.
* \snippet qs_spi_master_callback.c configure_spi
* A function for configuring the callback functionality of the SPI.
* \snippet qs_spi_master_callback.c conf_callback
* A global variable that can flag to the application that the buffer has been
* transferred.
* \snippet qs_spi_master_callback.c var
* Callback function.
* \snippet qs_spi_master_callback.c callback
*
* Add to user application \c main().
* \snippet qs_spi_master_callback.c main_start
*
* \section asfdoc_sam0_sercom_spi_master_callback_use_workflow Workflow
* -# Initialize system.
* \snippet qs_spi_master_callback.c system_init
* -# Set-up the SPI.
* \snippet qs_spi_master_callback.c run_config
* -# Create configuration struct.
* \snippet qs_spi_master_callback.c config
* -# Create peripheral slave configuration struct.
* \snippet qs_spi_master_callback.c slave_config
* -# Get default peripheral slave configuration.
* \snippet qs_spi_master_callback.c slave_conf_defaults
* -# Set Slave Select pin.
* \snippet qs_spi_master_callback.c ss_pin
* -# Initialize peripheral slave software instance with configuration.
* \snippet qs_spi_master_callback.c slave_init
* -# Get default configuration to edit.
* \snippet qs_spi_master_callback.c conf_defaults
* -# Set MUX setting E.
* \snippet qs_spi_master_callback.c mux_setting
* -# Set pinmux for pad 0 (data in MISO).
* \snippet qs_spi_master_callback.c di
* -# Set pinmux for pad 1 as unused, so the pin can be used for other purposes.
* \snippet qs_spi_master_callback.c ss
* -# Set pinmux for pad 2 (data out MOSI).
* \snippet qs_spi_master_callback.c do
* -# Set pinmux for pad 3 (SCK).
* \snippet qs_spi_master_callback.c sck
* -# Initialize SPI module with configuration.
* \snippet qs_spi_master_callback.c init
* -# Enable SPI module.
* \snippet qs_spi_master_callback.c enable
* -# Setup the callback functionality.
* \snippet qs_spi_master_callback.c run_callback_config
* -# Register callback function for buffer transmitted.
* \snippet qs_spi_master_callback.c reg_callback
* -# Enable callback for buffer transmitted.
* \snippet qs_spi_master_callback.c en_callback
*
* \section asfdoc_sam0_sercom_spi_master_callback_use_case Use Case
* \subsection asfdoc_sam0_sercom_spi_master_callback_use_case_code Code
* Add the following to your user application \c main().
* \snippet qs_spi_master_callback.c main_use_case
* \subsection asfdoc_sam0_sercom_spi_master_callback_use_case_workflow Workflow
* -# Select slave.
* \snippet qs_spi_master_callback.c select_slave
* -# Write buffer to SPI slave.
* \snippet qs_spi_master_callback.c write and read
* -# Wait for the transfer to be complete.
* \snippet qs_spi_master_callback.c wait
* -# Deselect slave.
* \snippet qs_spi_master_callback.c deselect_slave
* -# Infinite loop.
* \snippet qs_spi_master_callback.c inf_loop
*
* \section asfdoc_sam0_sercom_spi_master_callback_use_callback Callback
* When the buffer is successfully transmitted to the slave, the callback
* function will be called.
* \subsection asfdoc_sam0_sercom_spi_master_callback_use_callback_workflow Workflow
* -# Let the application know that the buffer is transmitted by setting the
* global variable to true.
* \snippet qs_spi_master_callback.c callback_var
*/
/*
* Support and FAQ: visit <a href="https://www.microchip.com/support/">Microchip Support</a>
*/

+ 139
- 0
firmware/SendcommPeer2P/src/ASF/sam0/drivers/sercom/spi/quick_start_slave_callback/qs_spi_slave_callback.h View File

@@ -0,0 +1,139 @@
/**
* \file
*
* \brief SAM SPI Quick Start
*
* Copyright (c) 2012-2018 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/

/**
* \page asfdoc_sam0_sercom_spi_slave_callback_use Quick Start Guide for SERCOM SPI Slave - Callback
*
* In this use case, the SPI on extension header 1 of the Xplained Pro board
* will configured with the following settings:
* - Slave mode enabled
* - Preloading of shift register enabled
* - MSB of the data is transmitted first
* - Transfer mode 0
* - SPI MUX Setting E (see \ref asfdoc_sam0_sercom_spi_mux_settings_slave)
* - 8-bit character size
* - Not enabled in sleep mode
* - GLCK generator 0
*
*
* \section asfdoc_sam0_sercom_spi_slave_callback_use_setup Setup
*
* \subsection asfdoc_sam0_sercom_spi_slave_callback_useprereq Prerequisites
* The device must be connected to a SPI master, which must read from the device.
*
* \subsection asfdoc_sam0_sercom_spi_slave_callback_use_setup_code Code
* The following must be added to the user application source file, outside
* any functions.
*
* A sample buffer to send via SPI.
* \snippet qs_spi_slave_callback.c buffer
* Number of entries in the sample buffer.
* \snippet qs_spi_slave_callback.c buf_length
* A globally available software device instance struct to store the SPI driver
* state while it is in use.
* \snippet qs_spi_slave_callback.c dev_inst
* A function for configuring the SPI.
* \snippet qs_spi_slave_callback.c configure_spi
* A function for configuring the callback functionality of the SPI.
* \snippet qs_spi_slave_callback.c conf_callback
* A global variable that can flag to the application that the buffer has been
* transferred.
* \snippet qs_spi_slave_callback.c var
* Callback function.
* \snippet qs_spi_slave_callback.c callback
*
* Add to user application \c main().
* \snippet qs_spi_slave_callback.c main_start
*
* \subsection asfdoc_sam0_sercom_spi_slave_callback_use_workflow Workflow
* -# Initialize system.
* \snippet qs_spi_slave_callback.c system_init
* -# Set-up the SPI.
* \snippet qs_spi_slave_callback.c run_config
* -# Create configuration struct.
* \snippet qs_spi_slave_callback.c config
* -# Get default configuration to edit.
* \snippet qs_spi_slave_callback.c conf_defaults
* -# Set the SPI in slave mode.
* \snippet qs_spi_slave_callback.c conf_spi_slave_instance
* -# Enable preloading of shift register.
* \snippet qs_spi_slave_callback.c conf_preload
* -# Set frame format to SPI frame.
* \snippet qs_spi_slave_callback.c conf_format
* -# Set MUX setting E.
* \snippet qs_spi_slave_callback.c mux_setting
* -# Set pinmux for pad 0 (data in MOSI).
* \snippet qs_spi_slave_callback.c di
* -# Set pinmux for pad 1 (slave select).
* \snippet qs_spi_slave_callback.c ss
* -# Set pinmux for pad 2 (data out MISO).
* \snippet qs_spi_slave_callback.c do
* -# Set pinmux for pad 3 (SCK).
* \snippet qs_spi_slave_callback.c sck
* -# Initialize SPI module with configuration.
* \snippet qs_spi_slave_callback.c init
* -# Enable SPI module.
* \snippet qs_spi_slave_callback.c enable
* -# Setup of the callback functionality.
* \snippet qs_spi_slave_callback.c run_callback_config
* -# Register callback function for buffer transmitted.
* \snippet qs_spi_slave_callback.c reg_callback
* -# Enable callback for buffer transmitted.
* \snippet qs_spi_slave_callback.c en_callback
*
* \section asfdoc_sam0_sercom_spi_slave_callback_usecase Use Case
* \subsection asfdoc_sam0_sercom_spi_slave_callback_usecase_code Code
* Add the following to your user application \c main().
* \snippet qs_spi_slave_callback.c main_use_case
* \subsection asfdoc_sam0_sercom_spi_slave_callback_usecase_workflow Workflow
* -# Initiate a read buffer job.
* \snippet qs_spi_slave_callback.c read
* -# Wait for the transfer to be complete.
* \snippet qs_spi_slave_callback.c transf_complete
* -# Compare the received data with the transmitted data from SPI master.
* \snippet qs_spi_slave_basic.c compare
* -# Infinite loop. If the data is matched, LED0 will flash slowly. Otherwise,
* LED will flash quickly.
* \snippet qs_spi_slave_callback.c inf_loop
*
* \section asfdoc_sam0_sercom_spi_slave_callback_use_callback Callback
* When the buffer is successfully transmitted from the master, the callback
* function will be called.
* \subsection asfdoc_sam0_sercom_spi_slave_callback_use_callback_workflow Workflow
* -# Let the application know that the buffer is transmitted by setting the
* global variable to true.
* \snippet qs_spi_slave_callback.c callback_var
*/
/*
* Support and FAQ: visit <a href="https://www.microchip.com/support/">Microchip Support</a>
*/

+ 2
- 2
firmware/SendcommPeer2P/src/ASF/sam0/drivers/sercom/spi/spi.c View File

@@ -503,7 +503,7 @@ enum status_code spi_init(

uint32_t sercom_index = _sercom_get_sercom_inst_index(module->hw);
uint32_t pm_index, gclk_index;
#if (SAML21) || (SAMR30) || (SAMR34) || (SAMR35) || (WLR089)
#if (SAML21) || (SAMR30) || (SAMR34) || (SAMR35)
if (sercom_index == 5) {
# ifdef ID_SERCOM5
pm_index = MCLK_APBDMASK_SERCOM5_Pos;
@@ -536,7 +536,7 @@ enum status_code spi_init(
#endif

/* Turn on module in PM */
#if (SAML21) || (SAMR30) || (SAMR34) || (SAMR35) || (WLR089)
#if (SAML21) || (SAMR30) || (SAMR34) || (SAMR35)
if (sercom_index == 5) {
# ifdef ID_SERCOM5
system_apb_clock_set_mask(SYSTEM_CLOCK_APB_APBD, 1 << pm_index);


+ 1
- 1
firmware/SendcommPeer2P/src/ASF/sam0/drivers/sercom/spi/spi.h View File

@@ -382,7 +382,7 @@ extern "C" {
* @{
*/
# if (SAMD21) || (SAMR21) || (SAMD11) || (SAMD10) || (SAML21) || (SAMDA1) || (SAMHA1) ||\
(SAMHA0) || (SAML22) || (SAMC20) || (SAMC21) || (SAMD09) || (SAMR30) || (SAMR34) || (SAMR35) || (WLR089) || defined(__DOXYGEN__)
(SAMHA0) || (SAML22) || (SAMC20) || (SAMC21) || (SAMD09) || (SAMR30) || (SAMR34) || (SAMR35)|| defined(__DOXYGEN__)
/** SPI slave select low detection. */
# define FEATURE_SPI_SLAVE_SELECT_LOW_DETECT
/** Slave select can be controlled by hardware. */


+ 731
- 0
firmware/SendcommPeer2P/src/ASF/sam0/drivers/sercom/spi/spi_interrupt.c View File

@@ -0,0 +1,731 @@
/**
* \file
*
* \brief SAM Serial Peripheral Interface Driver
*
* Copyright (c) 2013-2018 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/
/*
* Support and FAQ: visit <a href="https://www.microchip.com/support/">Microchip Support</a>
*/
#include "spi_interrupt.h"

/**
* \internal
*
* Dummy byte to send when reading in master mode.
*/
uint16_t dummy_write;

/**
* \internal
* Starts transceive of buffers with a given length
*
* \param[in] module Pointer to SPI software instance struct
* \param[in] rx_data Pointer to data to be received
* \param[in] tx_data Pointer to data to be transmitted
* \param[in] length Length of data buffer
*
*/
static void _spi_transceive_buffer(
struct spi_module *const module,
uint8_t *tx_data,
uint8_t *rx_data,
uint16_t length)
{
Assert(module);
Assert(tx_data);

/* Write parameters to the device instance */
module->remaining_tx_buffer_length = length;
module->remaining_rx_buffer_length = length;
module->rx_buffer_ptr = rx_data;
module->tx_buffer_ptr = tx_data;
module->status = STATUS_BUSY;

module->dir = SPI_DIRECTION_BOTH;

/* Get a pointer to the hardware module instance */
SercomSpi *const hw = &(module->hw->SPI);

/* Enable the Data Register Empty and RX Complete Interrupt */
hw->INTENSET.reg = (SPI_INTERRUPT_FLAG_DATA_REGISTER_EMPTY |
SPI_INTERRUPT_FLAG_RX_COMPLETE);

# if CONF_SPI_SLAVE_ENABLE == true
if (module->mode == SPI_MODE_SLAVE) {
/* Clear TXC flag if set */
hw->INTFLAG.reg = SPI_INTERRUPT_FLAG_TX_COMPLETE;
/* Enable transmit complete interrupt for slave */
hw->INTENSET.reg = SPI_INTERRUPT_FLAG_TX_COMPLETE;
}
# endif
}

/**
* \internal
* Starts write of a buffer with a given length
*
* \param[in] module Pointer to SPI software instance struct
* \param[in] tx_data Pointer to data to be transmitted
* \param[in] length Length of data buffer
*
*/
static void _spi_write_buffer(
struct spi_module *const module,
uint8_t *tx_data,
uint16_t length)
{
Assert(module);
Assert(tx_data);

/* Write parameters to the device instance */
module->remaining_tx_buffer_length = length;
module->remaining_dummy_buffer_length = length;
module->tx_buffer_ptr = tx_data;
module->status = STATUS_BUSY;

module->dir = SPI_DIRECTION_WRITE;

/* Get a pointer to the hardware module instance */
SercomSpi *const hw = &(module->hw->SPI);

# if CONF_SPI_SLAVE_ENABLE == true
if (module->mode == SPI_MODE_SLAVE) {
/* Clear TXC flag if set */
hw->INTFLAG.reg = SPI_INTERRUPT_FLAG_TX_COMPLETE;
/* Enable transmit complete interrupt for slave */
hw->INTENSET.reg = SPI_INTERRUPT_FLAG_TX_COMPLETE;
}
# endif

if (module->receiver_enabled) {
/* Enable the Data Register Empty and RX Complete interrupt */
hw->INTENSET.reg = (SPI_INTERRUPT_FLAG_DATA_REGISTER_EMPTY |
SPI_INTERRUPT_FLAG_RX_COMPLETE);
} else {
/* Enable the Data Register Empty interrupt */
hw->INTENSET.reg = SPI_INTERRUPT_FLAG_DATA_REGISTER_EMPTY;
}
}

/**
* \internal
* Setup SPI to read a buffer with a given length
*
* \param[in] module Pointer to SPI software instance struct
* \param[in] rx_data Pointer to data to be received
* \param[in] length Length of data buffer
*
*/
static void _spi_read_buffer(
struct spi_module *const module,
uint8_t *rx_data,
uint16_t length)
{
Assert(module);
Assert(rx_data);

uint8_t tmp_intenset = 0;

/* Set length for the buffer and the pointer, and let
* the interrupt handler do the rest */
module->remaining_rx_buffer_length = length;
module->remaining_dummy_buffer_length = length;
module->rx_buffer_ptr = rx_data;
module->status = STATUS_BUSY;

module->dir = SPI_DIRECTION_READ;

/* Get a pointer to the hardware module instance */
SercomSpi *const hw = &(module->hw->SPI);

/* Enable the RX Complete Interrupt */
tmp_intenset = SPI_INTERRUPT_FLAG_RX_COMPLETE;

# if CONF_SPI_MASTER_ENABLE == true
if (module->mode == SPI_MODE_MASTER && module->dir == SPI_DIRECTION_READ) {
/* Enable Data Register Empty interrupt for master */
tmp_intenset |= SPI_INTERRUPT_FLAG_DATA_REGISTER_EMPTY;
}
# endif
# if CONF_SPI_SLAVE_ENABLE == true
if (module->mode == SPI_MODE_SLAVE) {
/* Clear TXC flag if set */
hw->INTFLAG.reg = SPI_INTERRUPT_FLAG_TX_COMPLETE;
/* Enable transmit complete interrupt for slave */
tmp_intenset |= SPI_INTERRUPT_FLAG_TX_COMPLETE;

/* Workaround for SSL flag enable */
#ifdef FEATURE_SPI_SLAVE_SELECT_LOW_DETECT
/* Clear SSL flag if set */
hw->INTFLAG.reg = SPI_INTERRUPT_FLAG_SLAVE_SELECT_LOW;
/* Enable Slave Select Low Interrupt for slave */
tmp_intenset |= SPI_INTERRUPT_FLAG_SLAVE_SELECT_LOW;
#endif
}
# endif

/* Enable all interrupts simultaneously */
hw->INTENSET.reg = tmp_intenset;
}

/**
* \brief Registers a SPI callback function
*
* Registers a callback function which is implemented by the user.
*
* \note The callback must be enabled by \ref spi_enable_callback, in order
* for the interrupt handler to call it when the conditions for the
* callback type are met.
*
* \param[in] module Pointer to USART software instance struct
* \param[in] callback_func Pointer to callback function
* \param[in] callback_type Callback type given by an enum
*
*/
void spi_register_callback(
struct spi_module *const module,
spi_callback_t callback_func,
enum spi_callback callback_type)
{
/* Sanity check arguments */
Assert(module);
Assert(callback_func);

/* Register callback function */
module->callback[callback_type] = callback_func;

/* Set the bit corresponding to the callback_type */
module->registered_callback |= (1 << callback_type);
}

/**
* \brief Unregisters a SPI callback function
*
* Unregisters a callback function which is implemented by the user.
*
* \param[in] module Pointer to SPI software instance struct
* \param[in] callback_type Callback type given by an enum
*
*/
void spi_unregister_callback(
struct spi_module *const module,
enum spi_callback callback_type)
{
/* Sanity check arguments */
Assert(module);

/* Unregister callback function */
module->callback[callback_type] = NULL;

/* Clear the bit corresponding to the callback_type */
module->registered_callback &= ~(1 << callback_type);
}

/**
* \brief Asynchronous buffer write
*
* Sets up the driver to write to the SPI from a given buffer. If registered
* and enabled, a callback function will be called when the write is finished.
*
* \param[in] module Pointer to SPI software instance struct
* \param[out] tx_data Pointer to data buffer to receive
* \param[in] length Data buffer length
*
* \returns Status of the write request operation.
* \retval STATUS_OK If the operation completed successfully
* \retval STATUS_ERR_BUSY If the SPI was already busy with a write
* operation
* \retval STATUS_ERR_INVALID_ARG If requested write length was zero
*/
enum status_code spi_write_buffer_job(
struct spi_module *const module,
uint8_t *tx_data,
uint16_t length)
{
Assert(module);
Assert(tx_data);

if (length == 0) {
return STATUS_ERR_INVALID_ARG;
}

/* Check if the SPI is busy transmitting or slave waiting for TXC*/
if (module->status == STATUS_BUSY) {
return STATUS_BUSY;
}

/* Issue internal write */
_spi_write_buffer(module, tx_data, length);

return STATUS_OK;
}

/**
* \brief Asynchronous buffer read
*
* Sets up the driver to read from the SPI to a given buffer. If registered
* and enabled, a callback function will be called when the read is finished.
*
* \note If address matching is enabled for the slave, the first character
* received and placed in the RX buffer will be the address.
*
* \param[in] module Pointer to SPI software instance struct
* \param[out] rx_data Pointer to data buffer to receive
* \param[in] length Data buffer length
* \param[in] dummy Dummy character to send when reading in master mode
*
* \returns Status of the operation.
* \retval STATUS_OK If the operation completed successfully
* \retval STATUS_ERR_BUSY If the SPI was already busy with a read
* operation
* \retval STATUS_ERR_DENIED If the receiver is not enabled
* \retval STATUS_ERR_INVALID_ARG If requested read length was zero
*/
enum status_code spi_read_buffer_job(
struct spi_module *const module,
uint8_t *rx_data,
uint16_t length,
uint16_t dummy)
{
/* Sanity check arguments */
Assert(module);
Assert(rx_data);

if (length == 0) {
return STATUS_ERR_INVALID_ARG;
}

if (!(module->receiver_enabled)) {
return STATUS_ERR_DENIED;
}

/* Check if the SPI is busy transmitting or slave waiting for TXC*/
if (module->status == STATUS_BUSY) {
return STATUS_BUSY;
}

dummy_write = dummy;
/* Issue internal read */
_spi_read_buffer(module, rx_data, length);
return STATUS_OK;
}

/**
* \brief Asynchronous buffer write and read
*
* Sets up the driver to write and read to and from given buffers. If registered
* and enabled, a callback function will be called when the transfer is finished.
*
* \note If address matching is enabled for the slave, the first character
* received and placed in the RX buffer will be the address.
*
* \param[in] module Pointer to SPI software instance struct
* \param[in] tx_data Pointer to data buffer to send
* \param[out] rx_data Pointer to data buffer to receive
* \param[in] length Data buffer length
*
* \returns Status of the operation.
* \retval STATUS_OK If the operation completed successfully
* \retval STATUS_ERR_BUSY If the SPI was already busy with a read
* operation
* \retval STATUS_ERR_DENIED If the receiver is not enabled
* \retval STATUS_ERR_INVALID_ARG If requested read length was zero
*/
enum status_code spi_transceive_buffer_job(
struct spi_module *const module,
uint8_t *tx_data,
uint8_t *rx_data,
uint16_t length)
{
/* Sanity check arguments */
Assert(module);
Assert(rx_data);

if (length == 0) {
return STATUS_ERR_INVALID_ARG;
}

if (!(module->receiver_enabled)) {
return STATUS_ERR_DENIED;
}

/* Check if the SPI is busy transmitting or slave waiting for TXC*/
if (module->status == STATUS_BUSY) {
return STATUS_BUSY;
}

/* Issue internal transceive */
_spi_transceive_buffer(module, tx_data, rx_data, length);

return STATUS_OK;
}
/**
* \brief Aborts an ongoing job
*
* This function will abort the specified job type.
*
* \param[in] module Pointer to SPI software instance struct
*/
void spi_abort_job(
struct spi_module *const module)
{
/* Pointer to the hardware module instance */
SercomSpi *const spi_hw
= &(module->hw->SPI);

/* Abort ongoing job */

/* Disable interrupts */
spi_hw->INTENCLR.reg = SPI_INTERRUPT_FLAG_RX_COMPLETE |
SPI_INTERRUPT_FLAG_DATA_REGISTER_EMPTY |
SPI_INTERRUPT_FLAG_TX_COMPLETE;

module->status = STATUS_ABORTED;
module->remaining_rx_buffer_length = 0;
module->remaining_dummy_buffer_length = 0;
module->remaining_tx_buffer_length = 0;

module->dir = SPI_DIRECTION_IDLE;
}

# if CONF_SPI_SLAVE_ENABLE == true || CONF_SPI_MASTER_ENABLE == true
/**
* \internal
* Writes a character from the TX buffer to the Data register.
*
* \param[in,out] module Pointer to SPI software instance struct
*/
static void _spi_write(
struct spi_module *const module)
{
/* Pointer to the hardware module instance */
SercomSpi *const spi_hw = &(module->hw->SPI);

/* Write value will be at least 8-bits long */
uint16_t data_to_send = *(module->tx_buffer_ptr);
/* Increment 8-bit pointer */
(module->tx_buffer_ptr)++;

if (module->character_size == SPI_CHARACTER_SIZE_9BIT) {
data_to_send |= ((*(module->tx_buffer_ptr)) << 8);
/* Increment 8-bit pointer */
(module->tx_buffer_ptr)++;
}

/* Write the data to send*/
spi_hw->DATA.reg = data_to_send & SERCOM_SPI_DATA_MASK;

/* Decrement remaining buffer length */
(module->remaining_tx_buffer_length)--;
}
# endif

# if CONF_SPI_MASTER_ENABLE == true
/**
* \internal
* Writes a dummy character to the Data register.
*
* \param[in,out] module Pointer to SPI software instance struct
*/
static void _spi_write_dummy(
struct spi_module *const module)
{
/* Pointer to the hardware module instance */
SercomSpi *const spi_hw = &(module->hw->SPI);

/* Write dummy byte */
spi_hw->DATA.reg = dummy_write;

/* Decrement remaining dummy buffer length */
module->remaining_dummy_buffer_length--;
}
# endif

/**
* \internal
* Writes a dummy character from the to the Data register.
*
* \param[in,out] module Pointer to SPI software instance struct
*/
static void _spi_read_dummy(
struct spi_module *const module)
{
/* Pointer to the hardware module instance */
SercomSpi *const spi_hw = &(module->hw->SPI);
uint16_t flush = 0;

/* Read dummy byte */
flush = spi_hw->DATA.reg;
UNUSED(flush);

/* Decrement remaining dummy buffer length */
module->remaining_dummy_buffer_length--;
}

/**
* \internal
* Reads a character from the Data register to the RX buffer.
*
* \param[in,out] module Pointer to SPI software instance struct
*/
static void _spi_read(
struct spi_module *const module)
{
/* Pointer to the hardware module instance */
SercomSpi *const spi_hw = &(module->hw->SPI);

uint16_t received_data = (spi_hw->DATA.reg & SERCOM_SPI_DATA_MASK);

/* Read value will be at least 8-bits long */
*(module->rx_buffer_ptr) = received_data;
/* Increment 8-bit pointer */
module->rx_buffer_ptr += 1;

if(module->character_size == SPI_CHARACTER_SIZE_9BIT) {
/* 9-bit data, write next received byte to the buffer */
*(module->rx_buffer_ptr) = (received_data >> 8);
/* Increment 8-bit pointer */
module->rx_buffer_ptr += 1;
}

/* Decrement length of the remaining buffer */
module->remaining_rx_buffer_length--;
}

/**
* \internal
*
* Handles interrupts as they occur, and it will run callback functions
* which are registered and enabled.
*
* \note This function will be called by the Sercom_Handler, and should
* not be called directly from any application code.
*
* \param[in] instance ID of the SERCOM instance calling the interrupt
* handler.
*/
void _spi_interrupt_handler(
uint8_t instance)
{
/* Get device instance from the look-up table */
struct spi_module *module
= (struct spi_module *)_sercom_instances[instance];

/* Pointer to the hardware module instance */
SercomSpi *const spi_hw = &(module->hw->SPI);

/* Combine callback registered and enabled masks. */
uint8_t callback_mask =
module->enabled_callback & module->registered_callback;

/* Read and mask interrupt flag register */
uint16_t interrupt_status = spi_hw->INTFLAG.reg;
interrupt_status &= spi_hw->INTENSET.reg;

/* Data register empty interrupt */
if (interrupt_status & SPI_INTERRUPT_FLAG_DATA_REGISTER_EMPTY) {
# if CONF_SPI_MASTER_ENABLE == true
if ((module->mode == SPI_MODE_MASTER) &&
(module->dir == SPI_DIRECTION_READ)) {
/* Send dummy byte when reading in master mode */
_spi_write_dummy(module);
if (module->remaining_dummy_buffer_length == 0) {
/* Disable the Data Register Empty Interrupt */
spi_hw->INTENCLR.reg
= SPI_INTERRUPT_FLAG_DATA_REGISTER_EMPTY;
}
}
# endif

if (0
# if CONF_SPI_MASTER_ENABLE == true
|| ((module->mode == SPI_MODE_MASTER) &&
(module->dir != SPI_DIRECTION_READ))
# endif
# if CONF_SPI_SLAVE_ENABLE == true
|| ((module->mode == SPI_MODE_SLAVE) &&
(module->dir != SPI_DIRECTION_READ))
# endif
) {
/* Write next byte from buffer */
_spi_write(module);
if (module->remaining_tx_buffer_length == 0) {
/* Disable the Data Register Empty Interrupt */
spi_hw->INTENCLR.reg
= SPI_INTERRUPT_FLAG_DATA_REGISTER_EMPTY;

if (module->dir == SPI_DIRECTION_WRITE &&
!(module->receiver_enabled)) {
/* Enable the Data Register transmit complete Interrupt */
spi_hw->INTENSET.reg = SPI_INTERRUPT_FLAG_TX_COMPLETE;
}
}
}
}

/* Receive complete interrupt*/
if (interrupt_status & SPI_INTERRUPT_FLAG_RX_COMPLETE) {
/* Check for overflow */
if (spi_hw->STATUS.reg & SERCOM_SPI_STATUS_BUFOVF) {
if (module->dir != SPI_DIRECTION_WRITE) {
/* Store the error code */
module->status = STATUS_ERR_OVERFLOW;

/* End transaction */
module->dir = SPI_DIRECTION_IDLE;

spi_hw->INTENCLR.reg = SPI_INTERRUPT_FLAG_RX_COMPLETE |
SPI_INTERRUPT_FLAG_DATA_REGISTER_EMPTY;
/* Run callback if registered and enabled */
if (callback_mask & (1 << SPI_CALLBACK_ERROR)) {
(module->callback[SPI_CALLBACK_ERROR])(module);
}
}
/* Flush */
uint16_t flush = spi_hw->DATA.reg;
UNUSED(flush);
/* Clear overflow flag */
spi_hw->STATUS.reg = SERCOM_SPI_STATUS_BUFOVF;
} else {
if (module->dir == SPI_DIRECTION_WRITE) {
/* Flush receive buffer when writing */
_spi_read_dummy(module);
if (module->remaining_dummy_buffer_length == 0) {
spi_hw->INTENCLR.reg = SPI_INTERRUPT_FLAG_RX_COMPLETE;
module->status = STATUS_OK;
module->dir = SPI_DIRECTION_IDLE;
/* Run callback if registered and enabled */
if (callback_mask &
(1 << SPI_CALLBACK_BUFFER_TRANSMITTED)){
(module->callback[SPI_CALLBACK_BUFFER_TRANSMITTED])(module);
}
}
} else {
/* Read data register */
_spi_read(module);

/* Check if the last character have been received */
if (module->remaining_rx_buffer_length == 0) {
module->status = STATUS_OK;
/* Disable RX Complete Interrupt and set status */
spi_hw->INTENCLR.reg = SPI_INTERRUPT_FLAG_RX_COMPLETE;
if(module->dir == SPI_DIRECTION_BOTH) {
if (callback_mask & (1 << SPI_CALLBACK_BUFFER_TRANSCEIVED)) {
(module->callback[SPI_CALLBACK_BUFFER_TRANSCEIVED])(module);
}
} else if (module->dir == SPI_DIRECTION_READ) {
if (callback_mask & (1 << SPI_CALLBACK_BUFFER_RECEIVED)) {
(module->callback[SPI_CALLBACK_BUFFER_RECEIVED])(module);
}
}
}
}
}
}

/* Transmit complete */
if (interrupt_status & SPI_INTERRUPT_FLAG_TX_COMPLETE) {
# if CONF_SPI_SLAVE_ENABLE == true
if (module->mode == SPI_MODE_SLAVE) {
/* Transaction ended by master */

/* Disable interrupts */
spi_hw->INTENCLR.reg =
SPI_INTERRUPT_FLAG_TX_COMPLETE |
SPI_INTERRUPT_FLAG_RX_COMPLETE |
SPI_INTERRUPT_FLAG_DATA_REGISTER_EMPTY;
/* Clear interrupt flag */
spi_hw->INTFLAG.reg = SPI_INTERRUPT_FLAG_TX_COMPLETE;


/* Reset all status information */
module->dir = SPI_DIRECTION_IDLE;
module->remaining_tx_buffer_length = 0;
module->remaining_rx_buffer_length = 0;
module->status = STATUS_OK;

if (callback_mask &
(1 << SPI_CALLBACK_SLAVE_TRANSMISSION_COMPLETE)) {
(module->callback[SPI_CALLBACK_SLAVE_TRANSMISSION_COMPLETE])
(module);
}

}
# endif
# if CONF_SPI_MASTER_ENABLE == true
if ((module->mode == SPI_MODE_MASTER) &&
(module->dir == SPI_DIRECTION_WRITE) && !(module->receiver_enabled)) {
/* Clear interrupt flag */
spi_hw->INTENCLR.reg
= SPI_INTERRUPT_FLAG_TX_COMPLETE;
/* Buffer sent with receiver disabled */
module->dir = SPI_DIRECTION_IDLE;
module->status = STATUS_OK;
/* Run callback if registered and enabled */
if (callback_mask & (1 << SPI_CALLBACK_BUFFER_TRANSMITTED)){
(module->callback[SPI_CALLBACK_BUFFER_TRANSMITTED])
(module);
}
}
#endif
}

# ifdef FEATURE_SPI_SLAVE_SELECT_LOW_DETECT
# if CONF_SPI_SLAVE_ENABLE == true
/* When a high to low transition is detected on the _SS pin in slave mode */
if (interrupt_status & SPI_INTERRUPT_FLAG_SLAVE_SELECT_LOW) {
if (module->mode == SPI_MODE_SLAVE) {
/* Disable interrupts */
spi_hw->INTENCLR.reg = SPI_INTERRUPT_FLAG_SLAVE_SELECT_LOW;
/* Clear interrupt flag */
spi_hw->INTFLAG.reg = SPI_INTERRUPT_FLAG_SLAVE_SELECT_LOW;

if (callback_mask & (1 << SPI_CALLBACK_SLAVE_SELECT_LOW)) {
(module->callback[SPI_CALLBACK_SLAVE_SELECT_LOW])(module);
}
}
}
# endif
# endif

# ifdef FEATURE_SPI_ERROR_INTERRUPT
/* When combined error happen */
if (interrupt_status & SPI_INTERRUPT_FLAG_COMBINED_ERROR) {
/* Disable interrupts */
spi_hw->INTENCLR.reg = SPI_INTERRUPT_FLAG_COMBINED_ERROR;
/* Clear interrupt flag */
spi_hw->INTFLAG.reg = SPI_INTERRUPT_FLAG_COMBINED_ERROR;

if (callback_mask & (1 << SPI_CALLBACK_COMBINED_ERROR)) {
(module->callback[SPI_CALLBACK_COMBINED_ERROR])(module);
}
}
# endif
}

+ 180
- 0
firmware/SendcommPeer2P/src/ASF/sam0/drivers/sercom/spi/spi_interrupt.h View File

@@ -0,0 +1,180 @@
/**
* \file
*
* \brief SAM Serial Peripheral Interface Driver (Callback Mode)
*
* Copyright (c) 2013-2018 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/
/*
* Support and FAQ: visit <a href="https://www.microchip.com/support/">Microchip Support</a>
*/

#ifndef SPI_INTERRUPT_H_INCLUDED
#define SPI_INTERRUPT_H_INCLUDED

#ifdef __cplusplus
extern "C" {
#endif

/**
* \addtogroup asfdoc_sam0_sercom_spi_group
*
* @{
*/

#include "spi.h"

/**
* \name Callback Management
* @{
*/

void spi_register_callback(
struct spi_module *const module,
spi_callback_t callback_func,
enum spi_callback callback_type);

void spi_unregister_callback(
struct spi_module *module,
enum spi_callback callback_type);

/**
* \brief Enables an SPI callback of a given type
*
* Enables the callback function registered by the \ref spi_register_callback.
* The callback function will be called from the interrupt handler when the
* conditions for the callback type are met.
*
* \param[in] module Pointer to SPI software instance struct
* \param[in] callback_type Callback type given by an enum
*/
static inline void spi_enable_callback(
struct spi_module *const module,
enum spi_callback callback_type)
{
/* Sanity check arguments */
Assert(module);

/* Enable callback */
module->enabled_callback |= (1 << callback_type);
}

/**
* \brief Disables callback
*
* Disables the callback function registered by the \ref spi_register_callback,
* and the callback will not be called from the interrupt routine.
*
* \param[in] module Pointer to SPI software instance struct
* \param[in] callback_type Callback type given by an enum
*/
static inline void spi_disable_callback(
struct spi_module *const module,
enum spi_callback callback_type)
{
/* Sanity check arguments */
Assert(module);

/* Disable callback */
module->enabled_callback &= ~(1 << callback_type);
}

/** @} */


/**
* \name Writing and Reading
* @{
*/
enum status_code spi_write_buffer_job(
struct spi_module *const module,
uint8_t *tx_data,
uint16_t length);

enum status_code spi_read_buffer_job(
struct spi_module *const module,
uint8_t *rx_data,
uint16_t length,
uint16_t dummy);

enum status_code spi_transceive_buffer_job(
struct spi_module *const module,
uint8_t *tx_data,
uint8_t *rx_data,
uint16_t length);

void spi_abort_job(
struct spi_module *const module);

/**
* \brief Retrieves the current status of a job.
*
* Retrieves the current status of a job that was previously issued.
*
* \param[in] module Pointer to SPI software instance struct
*
* \return Current job status.
*/
static inline enum status_code spi_get_job_status(
const struct spi_module *const module)
{
return module->status;
}

/**
* \brief Retrieves the status of job once it ends.
*
* Waits for current job status to become non-busy, then returns its value.
*
* \param[in] module Pointer to SPI software instance struct
*
* \return Current non-busy job status.
*/
static inline enum status_code spi_get_job_status_wait(
const struct spi_module *const module)
{
enum status_code status;

do {
status = spi_get_job_status(module);
} while (status == STATUS_BUSY);

return status;
}

/** @} */

/**
* @}
*/

#ifdef __cplusplus
}
#endif

#endif /* SPI_INTERRUPT_H_INCLUDED */

+ 3
- 13
firmware/SendcommPeer2P/src/ASF/sam0/drivers/sercom/usart/usart.c View File

@@ -56,17 +56,7 @@ static enum status_code _usart_set_config(

/* Index for generic clock */
uint32_t sercom_index = _sercom_get_sercom_inst_index(module->hw);
uint32_t gclk_index;

#if (SAML21) || (SAMR30) || (SAMR34) || (SAMR35) || (SAMC21) || (WLR089)
if (sercom_index == 5) {
gclk_index = SERCOM5_GCLK_ID_CORE;
} else {
gclk_index = sercom_index + SERCOM0_GCLK_ID_CORE;
}
#else
gclk_index = sercom_index + SERCOM0_GCLK_ID_CORE;
#endif
uint32_t gclk_index = sercom_index + SERCOM0_GCLK_ID_CORE;

/* Cache new register values to minimize the number of register writes */
uint32_t ctrla = 0;
@@ -339,7 +329,7 @@ enum status_code usart_init(
#if (SAML22) || (SAMC20)
pm_index = sercom_index + MCLK_APBCMASK_SERCOM0_Pos;
gclk_index = sercom_index + SERCOM0_GCLK_ID_CORE;
#elif (SAML21) || (SAMR30) || (SAMR34) || (SAMR35) || (WLR089)
#elif (SAML21) || (SAMR30) || (SAMR34) || (SAMR35)
if (sercom_index == 5) {
pm_index = MCLK_APBDMASK_SERCOM5_Pos;
gclk_index = SERCOM5_GCLK_ID_CORE;
@@ -371,7 +361,7 @@ enum status_code usart_init(
}

/* Turn on module in PM */
#if (SAML21) || (SAMR30) || (SAMR34) || (SAMR35) || (WLR089)
#if (SAML21) || (SAMR30) || (SAMR34) || (SAMR35)
if (sercom_index == 5) {
system_apb_clock_set_mask(SYSTEM_CLOCK_APB_APBD, 1 << pm_index);
} else {


+ 1
- 1
firmware/SendcommPeer2P/src/ASF/sam0/drivers/sercom/usart/usart.h View File

@@ -277,7 +277,7 @@ extern "C" {

#if (SAMD21) || (SAMR21) || (SAMD09) || (SAMD10) || (SAMD11) || \
(SAML21) || (SAML22) || (SAMDA1) || (SAMC20) || (SAMC21) || \
(SAMR30) || (SAMHA1) || (SAMHA0) || (SAMR34) || (SAMR35) || (WLR089) || defined(__DOXYGEN__)
(SAMR30) || (SAMHA1) || (SAMHA0) || (SAMR34) || (SAMR35) || defined(__DOXYGEN__)
/** USART sync scheme version 2. */
# define FEATURE_USART_SYNC_SCHEME_V2
/** USART oversampling. */


+ 1
- 1
firmware/SendcommPeer2P/src/ASF/sam0/drivers/system/clock/gclk.h View File

@@ -197,7 +197,7 @@ static inline void system_gclk_gen_get_config_defaults(
/* Default configuration values */
config->division_factor = 1;
config->high_when_disabled = false;
#if SAML21 || SAML22 || SAMR30 || SAMR34 || SAMR35 || (WLR089)
#if SAML21 || SAML22 || SAMR30 || SAMR34 || SAMR35
config->source_clock = GCLK_SOURCE_OSC16M;
#elif (SAMC20) || (SAMC21)
config->source_clock = GCLK_SOURCE_OSC48M;


+ 1
- 1
firmware/SendcommPeer2P/src/ASF/sam0/drivers/system/pinmux/pinmux.h View File

@@ -194,7 +194,7 @@ extern "C" {
#endif

/*@{*/
#if (SAML21) || (SAMC20) || (SAMC21) || (SAMD21) || (SAMD10) || (SAMD11) || (SAMR30) || (SAMR34) || (SAMR35) || (WLR089) || defined(__DOXYGEN__)
#if (SAML21) || (SAMC20) || (SAMC21) || (SAMD21) || (SAMD10) || (SAMD11) || (SAMR30) || (SAMR34) || (SAMR35) || defined(__DOXYGEN__)
/** Output Driver Strength Selection feature support */
# define FEATURE_SYSTEM_PINMUX_DRIVE_STRENGTH
#endif


+ 14
- 14
firmware/SendcommPeer2P/src/ASF/sam0/drivers/system/power/power_sam_l/power.h View File

@@ -97,7 +97,7 @@ enum system_ram_back_bias_mode {
SYSTEM_RAM_BACK_BIAS_OFF,
};

#if SAML21 || SAMR30 || (SAMR34) || (SAMR35) || (WLR089)
#if SAML21 || SAMR30 || (SAMR34) || (SAMR35)
/**
* \brief Linked power domain.
*
@@ -116,7 +116,7 @@ enum system_linked_power_domain {
SYSTEM_LINKED_POWER_DOMAIN_PD012 = PM_STDBYCFG_LINKPD_PD012_Val,
};

#if (SAML21XXXB) || (SAMR30) || (SAMR34) || (SAMR35) || (WLR089)
#if (SAML21XXXB) || (SAMR30) || (SAMR34) || (SAMR35)
/**
* \brief VREG switching mode.
*
@@ -269,7 +269,7 @@ enum system_backup_pin {
* Configuration structure for standby mode.
*/
struct system_standby_config {
#if SAML21 || SAMR30 || (SAMR34) || (SAMR35) || (WLR089)
#if SAML21 || SAMR30 || (SAMR34) || (SAMR35)
/** Power domain. */
enum system_power_domain power_domain;
/** Enable dynamic power gating for power domain 0 */
@@ -311,7 +311,7 @@ struct system_voltage_regulator_config {
enum system_voltage_regulator_sel regulator_sel;
/** Low power efficiency */
enum system_voltage_regulator_low_power_efficiency low_power_efficiency;
#if SAML22 || SAML21XXXB || (SAMR34J) || (SAMR35J) || (WLR089U0)
#if SAML22 || SAML21XXXB || (SAMR34J) || (SAMR35J)
/** Run in standby in performance level 0. */
bool run_in_standby_pl0;
#endif
@@ -374,7 +374,7 @@ static inline void system_voltage_regulator_get_config_defaults(
config->run_in_standby = false;
config->regulator_sel = SYSTEM_VOLTAGE_REGULATOR_LDO;
config->low_power_efficiency = SYSTEM_VOLTAGE_REGULATOR_LOW_POWER_EFFICIENCY_DEFAULT;
#if SAML22 || SAML21XXXB || SAMR34J || SAMR35J || (WLR089U0)
#if SAML22 || SAML21XXXB || SAMR34J || SAMR35J
config->run_in_standby_pl0 = false;
#endif
}
@@ -395,10 +395,10 @@ static inline void system_voltage_regulator_set_config(
SUPC->VREG.bit.VSVSTEP = config->voltage_scale_step;
SUPC->VREG.bit.RUNSTDBY = config->run_in_standby;
SUPC->VREG.bit.SEL = config->regulator_sel;
#if (SAML21XXXB) || (SAMR30) || (SAMR34) || (SAMR35) || (WLR089)
#if (SAML21XXXB) || (SAMR30) || (SAMR34) || (SAMR35)
SUPC->VREG.bit.LPEFF = config->low_power_efficiency;
#endif
#if SAML22 || SAML21XXXB || SAMR34J || SAMR35J || (WLR089U0)
#if SAML22 || SAML21XXXB || SAMR34J || SAMR35J
SUPC->VREG.bit.STDBYPL0 = config->run_in_standby_pl0;
#endif
while(!(SUPC->STATUS.reg & SUPC_STATUS_VREGRDY)) {
@@ -799,7 +799,7 @@ static inline enum status_code system_switch_performance_level(
return STATUS_OK;
}

#if SAML22 || SAML21XXXB || SAMR34J || SAMR35J || (WLR089U0)
#if SAML22 || SAML21XXXB || SAMR34J || SAMR35J
if (PM->PLCFG.reg & PM_PLCFG_PLDIS) {
return STATUS_ERR_INVALID_ARG;
}
@@ -818,7 +818,7 @@ static inline enum status_code system_switch_performance_level(
return STATUS_OK;
}

#if SAML22 || SAML21XXXB || SAMR34J || SAMR35J || (WLR089U0)
#if SAML22 || SAML21XXXB || SAMR34J || SAMR35J
/**
* \brief Enable performance level switch.
*
@@ -899,12 +899,12 @@ static inline void system_clear_performance_level_status(void)
static inline void system_standby_get_config_defaults(
struct system_standby_config *const config)
{
Assert(config);
#if SAML21 || SAMR30 || (SAMR34) || (SAMR35) || (WLR089)
Assert(config);
#if SAML21 || SAMR30 || (SAMR34) || (SAMR35)
config->power_domain = SYSTEM_POWER_DOMAIN_DEFAULT;
config->enable_dpgpd0 = false;
config->enable_dpgpd1 = false;
#if (SAML21XXXB) || (SAMR30) || (SAMR34) || (SAMR35) || (WLR089)
#if (SAML21XXXB) || (SAMR30) || (SAMR34) || (SAMR35)
config->vregs_mode = SYSTEM_SYSTEM_VREG_SWITCH_AUTO;
#else
config->disable_avregsd = false;
@@ -929,11 +929,11 @@ static inline void system_standby_set_config(
struct system_standby_config *const config)
{
Assert(config);
#if SAML21 || SAMR30 || (SAMR34) || (SAMR35) || (WLR089)
#if SAML21 || SAMR30 || (SAMR34) || (SAMR35)
PM->STDBYCFG.reg = PM_STDBYCFG_PDCFG(config->power_domain)
| (config->enable_dpgpd0 << PM_STDBYCFG_DPGPD0_Pos)
| (config->enable_dpgpd1 << PM_STDBYCFG_DPGPD1_Pos)
#if (SAML21XXXB) || (SAMR30) || (SAMR34) || (SAMR35) || (WLR089)
#if (SAML21XXXB) || (SAMR30) || (SAMR34) || (SAMR35)
| PM_STDBYCFG_VREGSMOD(config->vregs_mode)
#else
| (config->disable_avregsd << PM_STDBYCFG_AVREGSD_Pos)


+ 3
- 3
firmware/SendcommPeer2P/src/ASF/sam0/drivers/system/reset/reset_sam_l/reset.h View File

@@ -62,7 +62,7 @@ enum system_reset_cause {
SYSTEM_RESET_CAUSE_WDT = RSTC_RCAUSE_WDT,
/** The system was last reset because the external reset line was pulled low */
SYSTEM_RESET_CAUSE_EXTERNAL_RESET = RSTC_RCAUSE_EXT,
#if SAML21 || SAMR30 || (SAMR34) || (SAMR35) || (WLR089)
#if SAML21 || SAMR30 || (SAMR34) || (SAMR35)
/** The system was last reset by the BOD33. */
SYSTEM_RESET_CAUSE_BOD33 = RSTC_RCAUSE_BOD33,
/** The system was last reset by the BOD12 */
@@ -83,7 +83,7 @@ enum system_reset_cause {
* List of possible backup exit source.
*/
enum system_reset_backup_exit_source {
#if SAML21 || SAMR30 || (SAMR34) || (SAMR35) || (WLR089)
#if SAML21 || SAMR30 || (SAMR34) || (SAMR35)
/** The backup exit source was external wakeup. */
SYSTEM_RESET_BACKKUP_EXIT_EXTWAKE = RSTC_BKUPEXIT_EXTWAKE,
#endif
@@ -93,7 +93,7 @@ enum system_reset_backup_exit_source {
SYSTEM_RESET_BACKKUP_EXIT_BBPS = RSTC_BKUPEXIT_BBPS,
};

#if SAML21 || SAMR30 || (SAMR34) || (SAMR35) || (WLR089)
#if SAML21 || SAMR30 || (SAMR34) || (SAMR35)
/**
* \brief Wakeup debounce counter value.
*


+ 12
- 12
firmware/SendcommPeer2P/src/ASF/sam0/drivers/tc/tc.h View File

@@ -458,7 +458,7 @@
* Define port features set according to different device family
* @{
*/
#if (SAML21) || (SAML22) || (SAMC20) || (SAMC21) || (SAMR30)|| (SAMR34) || (SAMR35) || (WLR089) || defined(__DOXYGEN__)
#if (SAML21) || (SAML22) || (SAMC20) || (SAMC21) || (SAMR30)|| (SAMR34) || (SAMR35) || defined(__DOXYGEN__)
/** TC double buffered. */
# define FEATURE_TC_DOUBLE_BUFFERED
/** SYNCBUSY scheme version 2. */
@@ -471,14 +471,14 @@
# define FEATURE_TC_IO_CAPTURE
#endif

#if (SAML21XXXB) || (SAMR30) || (SAMR34) || (SAMR35) || (WLR089) || defined(__DOXYGEN__)
#if (SAML21XXXB) || (SAMR30) || (SAMR34) || (SAMR35) || defined(__DOXYGEN__)
/** Generate Direct Memory Access (DMA) triggers. */
# define FEATURE_TC_GENERATE_DMA_TRIGGER
#endif
/*@}*/

#if !defined(__DOXYGEN__)
#if SAMD20 || SAML21 || SAML22 || SAMC20 || SAMC21 || SAMR30 || (SAMR34) || (SAMR35) || (WLR089)
#if SAMD20 || SAML21 || SAML22 || SAMC20 || SAMC21 || SAMR30 || (SAMR34) || (SAMR35)
# define TC_INSTANCE_OFFSET 0
#endif
#if SAMD21 || SAMR21 || SAMDA1 || (SAMHA1) || (SAMHA0)
@@ -490,7 +490,7 @@

#if SAMD20
# define NUMBER_OF_COMPARE_CAPTURE_CHANNELS TC0_CC8_NUM
#elif SAML21 || SAML22 || SAMC20 || SAMC21 || SAMR30 || (SAMR34) || (SAMR35) || (WLR089)
#elif SAML21 || SAML22 || SAMC20 || SAMC21 || SAMR30 || (SAMR34) || (SAMR35)
# define NUMBER_OF_COMPARE_CAPTURE_CHANNELS TC0_CC_NUM
#elif SAMD09 || SAMD10 || SAMD11
# define NUMBER_OF_COMPARE_CAPTURE_CHANNELS TC1_CC8_NUM
@@ -506,7 +506,7 @@
# else
# define TC_INST_MAX_ID 5
# endif
#elif SAML21 || SAMC20 || SAMC21 || SAMR30 || (SAMR34) || (SAMR35) || (WLR089)
#elif SAML21 || SAMC20 || SAMC21 || SAMR30 || (SAMR34) || (SAMR35)
# define TC_INST_MAX_ID 4
#elif SAML22
# define TC_INST_MAX_ID 3
@@ -607,7 +607,7 @@ enum tc_compare_capture_channel {
*
* @{
*/
#if SAML21 || SAML22 || SAMC20 || SAMC21 || SAMR30 || (SAMR34) || (SAMR35) || (WLR089)
#if SAML21 || SAML22 || SAMC20 || SAMC21 || SAMR30 || (SAMR34) || (SAMR35)
/** TC wave generation mode: normal frequency. */
#define TC_WAVE_GENERATION_NORMAL_FREQ_MODE TC_WAVE_WAVEGEN_NFRQ
/** TC wave generation mode: match frequency. */
@@ -748,7 +748,7 @@ enum tc_count_direction {
*
* @{
*/
#if SAML21 || SAML22 || SAMC20 || SAMC21 || SAMR30 || (SAMR34) || (SAMR35) || (WLR089)
#if SAML21 || SAML22 || SAMC20 || SAMC21 || SAMR30 || (SAMR34) || (SAMR35)
/** Waveform inversion CC0 mode. */
#define TC_WAVEFORM_INVERT_CC0_MODE TC_DRVCTRL_INVEN(1)
/** Waveform inversion CC1 mode. */
@@ -884,7 +884,7 @@ struct tc_config {

/** When \c true the module is enabled during standby */
bool run_in_standby;
#if (SAML21) || (SAML22) || (SAMC20) || (SAMC21) || (SAMR30) || (SAMR34) || (SAMR35) || (WLR089)
#if (SAML21) || (SAML22) || (SAMC20) || (SAMC21) || (SAMR30) || (SAMR34) || (SAMR35)
/** Run on demand */
bool on_demand;
#endif
@@ -1023,7 +1023,7 @@ static inline bool tc_is_syncing(
/* Get a pointer to the module's hardware instance */
TcCount8 *const tc_module = &(module_inst->hw->COUNT8);

#if (SAML21) || (SAML22) || (SAMC20) || (SAMC21) || (SAMR30) || (SAMR34) || (SAMR35) || (WLR089)
#if (SAML21) || (SAML22) || (SAMC20) || (SAMC21) || (SAMR30) || (SAMR34) || (SAMR35)
return (tc_module->SYNCBUSY.reg);
#else
return (tc_module->STATUS.reg & TC_STATUS_SYNCBUSY);
@@ -1077,7 +1077,7 @@ static inline void tc_get_config_defaults(
config->wave_generation = TC_WAVE_GENERATION_NORMAL_FREQ;
config->reload_action = TC_RELOAD_ACTION_GCLK;
config->run_in_standby = false;
#if (SAML21) || (SAML22) || (SAMC20) || (SAMC21) || (SAMR30) || (SAMR34) || (SAMR35) || (WLR089)
#if (SAML21) || (SAML22) || (SAMC20) || (SAMC21) || (SAMR30) || (SAMR34) || (SAMR35)
config->on_demand = false;
#endif
config->waveform_invert_output = TC_WAVEFORM_INVERT_OUTPUT_NONE;
@@ -1440,7 +1440,7 @@ static inline void tc_sync_read_count(

/* Write command to execute */
tc_module->CTRLBSET.reg = TC_CTRLBSET_CMD(TC_CTRLBSET_CMD_READSYNC_Val);
#if (SAMC20) || (SAMC21) || (SAML21) || (SAML22) || (SAMR30) || (SAMR34) || (WLR089)
#if (SAMC20) || (SAMC21) || (SAML21) || (SAML22) || (SAMR30)
/* wait for the CMD bits in CTRLBSET to be cleared, meaning the CMD has been executed */
while(tc_module->CTRLBSET.reg & TC_CTRLBSET_CMD_READSYNC);
#endif
@@ -1482,7 +1482,7 @@ static inline void tc_dma_trigger_command(
/* Wait for sync */
}

#if (SAMC20) || (SAMC21) || (SAML22) || (SAML21XXXB) || (SAMR30) || (SAMR34) || (SAMR35) || (WLR089)
#if (SAMC20) || (SAMC21) || (SAML22) || (SAML21XXXB) || (SAMR30) || (SAMR34) || (SAMR35)
/* Write command to execute */
tc_module->CTRLBSET.reg = TC_CTRLBSET_CMD(TC_CTRLBSET_CMD_DMAOS_Val);
#endif


+ 1
- 1
firmware/SendcommPeer2P/src/ASF/sam0/drivers/tc/tc_interrupt.c View File

@@ -122,7 +122,7 @@ enum status_code tc_unregister_callback(
_tc_interrupt_handler(m); \
}

#if (SAML21E) || (SAML21G) || (SAMR30E) || (SAMR30G) || (SAMR34) || (WLR089)
#if (SAML21E) || (SAML21G) || (SAMR30E) || (SAMR30G)
_TC_INTERRUPT_HANDLER(0,0)
_TC_INTERRUPT_HANDLER(1,1)
_TC_INTERRUPT_HANDLER(4,2)


+ 1
- 1
firmware/SendcommPeer2P/src/ASF/sam0/drivers/tc/tc_interrupt.h View File

@@ -62,7 +62,7 @@ static enum system_interrupt_vector _tc_interrupt_get_interrupt_vector(
{
static uint8_t tc_interrupt_vectors[TC_INST_NUM] =
{
#if (SAML21E) || (SAML21G) || (SAMR30E) || (SAMR30G) || (SAMR34) || (WLR089)
#if (SAML21E) || (SAML21G) || (SAMR30E) || (SAMR30G)
SYSTEM_INTERRUPT_MODULE_TC0,
SYSTEM_INTERRUPT_MODULE_TC1,
SYSTEM_INTERRUPT_MODULE_TC4


+ 1
- 1
firmware/SendcommPeer2P/src/ASF/sam0/drivers/tc/tc_sam_l_c/tc.c View File

@@ -116,7 +116,7 @@ enum status_code tc_init(
SYSTEM_CLOCK_APB_APBC, MCLK_APBCMASK_TC2,
SYSTEM_CLOCK_APB_APBC, MCLK_APBCMASK_TC3,
SYSTEM_CLOCK_APB_APBC, MCLK_APBCMASK_TC4};
#elif (SAML21J) || (SAMR34J) || (SAMR35J) || (WLR089U0)
#elif (SAML21J) || (SAMR34J) || (SAMR35J)
/* Array of GLCK ID for different TC instances */
uint8_t inst_gclk_id[] = {TC0_GCLK_ID, TC1_GCLK_ID, TC2_GCLK_ID, TC3_GCLK_ID, TC4_GCLK_ID};
/* Array of MCLK APB mask bit position for different TC instances */


+ 0
- 4
firmware/SendcommPeer2P/src/ASF/sam0/utils/header_files/io.h View File

@@ -84,10 +84,6 @@
# include "samr35.h"
#endif

#if (WLR089)
# include "wlr089.h"
#endif

#if (SAML22)
# include "saml22.h"
#endif


firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/pds/src/wl/linkerscripts/samr34/gcc/samr34j18b_flash.ld → firmware/SendcommPeer2P/src/ASF/sam0/utils/linker_scripts/samr34/gcc/samr34j18b_flash.ld View File

@@ -3,31 +3,46 @@
*
* \brief Linker script for running in internal FLASH on the SAMR34J18B
*
* Copyright (c) 2017 Microchip Technology Inc.
* Copyright (c) 2015-2018 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* SPDX-License-Identifier: Apache-2.0
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the Licence at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The name of Atmel may not be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* 4. This software may only be redistributed and used in connection with an
* Atmel microcontroller product.
*
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* \asf_license_stop
*
*/



OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
OUTPUT_ARCH(arm)
SEARCH_DIR(.)
@@ -51,24 +66,6 @@ SECTIONS
. = ALIGN(4);
_sfixed = .;
KEEP(*(.vectors .vectors.*))

/* PDS NV memory section */
. = ALIGN(0x400);
PROVIDE(__d_nv_mem_start = .);
FILL(0xFFFFFFFF)
. = ALIGN(0x4400); /* Size of D_Nv memory section is 0x4000 i.e., 16KB */
PROVIDE(__d_nv_mem_end = .);

/* Non-volatile file system PDS_FF section */
PROVIDE(__pds_ff_start = .);
KEEP(*(.pds_ff))
PROVIDE(__pds_ff_end = .);

/* Non-volatile file system PDS_FD section */
PROVIDE(__pds_fd_start = .);
KEEP(*(.pds_fd))
PROVIDE(__pds_fd_end = .);

*(.text .text.* .gnu.linkonce.t.*)
*(.glue_7t) *(.glue_7)
*(.rodata .rodata* .gnu.linkonce.r.*)

+ 0
- 111
firmware/SendcommPeer2P/src/ASF/thirdparty/CMSIS/license.txt View File

@@ -1,111 +0,0 @@
END USER LICENCE AGREEMENT FOR THE CORTEX MICROCONTROLLER SOFTWARE INTERFACE STANDARD (CMSIS) DELIVERABLES

THIS END USER LICENCE AGREEMENT ("LICENCE") IS A LEGAL AGREEMENT BETWEEN YOU (EITHER A SINGLE INDIVIDUAL, OR SINGLE LEGAL ENTITY) AND ARM LIMITED ("ARM") FOR THE USE OF THE CMSIS DELIVERABLES. ARM IS ONLY WILLING TO LICENSE THE CMSIS DELIVERABLES TO YOU ON CONDITION THAT YOU ACCEPT ALL OF THE TERMS IN THIS LICENCE. BY CLICKING "I AGREE", OR BY INSTALLING OR OTHERWISE USING OR COPYING THE CMSIS DELIVERABLES YOU INDICATE THAT YOU AGREE TO BE BOUND BY ALL THE TERMS OF THIS LICENCE. IF YOU DO NOT AGREE TO THE TERMS OF THIS LICENCE, ARM IS UNWILLING TO LICENSE YOU TO USE OF THE CMSIS DELIVERABLES AND YOU MAY NOT INSTALL, USE OR COPY THE CMSIS DELIVERABLES.

“CMSIS Deliverables” means the following components: (i) CMSIS-CORE; (ii) CMSIS-DRIVER; (iii) CMSIS-DSP; (iv) CMSIS-PACK; (v) CMSIS-RTOS API; and (vi) CMSIS-SVD .

“CMSIS-CORE” means the specification defining the application programming interface, naming and coding conventions for the Cortex-M processor cores.

”CMSIS-DRIVER” means the specification defining a generic peripheral driver application programming interface, naming and coding conventions.

“CMSIS-DSP” means the digital signal process (DSP) library specification defining the application programming interface of a DSP library implementation.

“CMSIS-PACK” means the specification defining a software pack file format, verification utility, and the associated XML schema file.

“CMSIS-RTOS API” means the real-time operating system (RTOS) specification defining a generic application programming interface layer for a RTOS system.

Notwithstanding the foregoing, the CMSIS Deliverables shall not include: (i) the implementation of other published specifications referenced in the CMSIS Deliverables ; (ii) any enabling technologies that may be necessary to make or use any product or portion thereof that complies with the CMSIS Deliverables, but are not themselves expressly set forth in the CMSIS Deliverables (e.g. compiler front ends, code generators, back ends, libraries or other compiler, assembler or linker technologies; validation or debug software or hardware; applications, operating system or driver software; RISC architecture; processor microarchitecture); (iii) maskworks and physical layouts of integrated circuit designs; or (iv) RTL or other high level representations of integrated circuit designs.

“CMSIS-SVD” means the specification defining the System View Description (SVD), verification utility, and associated XML schema files.

“Separate Files” means the components in the CMSIS reference implementation identified in the Schedule that demonstrate the usage of the CMSIS-CORE, CMSIS-DRIVER, CMSIS-DSP, CMSIS-PACK and CMSIS-RTOS API, for microprocessors or device specific software applications that are for use with microprocessors.

1. LICENCE GRANTS.

1.1 CMSIS DELIVERABLES

ARM hereby grants to you, subject to the terms and conditions of this Licence, a non-exclusive, non-transferable licence, to use and copy the CMSIS Deliverables for the purpose of:

(i) subject to clause 1.2, developing, having developed, manufacturing, having manufactured, offering to sell, selling, supplying or otherwise distributing products that comply with the CMSIS Deliverables; and

(ii) distributing and having distributed (directly or through your customers and authorised distributors) the CMSIS-Deliverables unmodified, with the products you have developed under Clause 1.1 (i) provided you preserve any copyright notices which are included with the CMSIS Deliverables.

1.2 CONDITIONS ON REDISTRIBUTION.

If you distribute (directly or through your customers and authorised distributors) the products you have created pursuant to Clauses 1.1 (i) you agree: (a) not to use ARM’s name, logo or trademarks to market any or all of the products created under Clause 1.1 (i); (b) to preserve any copyright notices included in the CMSIS Deliverables; and (c) to ensure your customers and authorised distributors comply with this Clause 1.2.

2. RESTRICTIONS ON USE OF THE CMSIS DELIVERABLES.

PERMITTED USERS: The CMSIS Deliverables shall be used only by you (either a single individual, or single legal entity) your employees, or by your on-site bona fide sub-contractors for whose acts and omissions you hereby agree to be responsible to ARM for to the same extent as you are for your employees, and provided always that such sub-contractors: (i) are contractually obligated to use the CMSIS Deliverables only for your benefit; and (ii) agree to assign all their work product and
any rights they create therein in the supply of such work to you.

COPYRIGHT AND RESERVATION OF RIGHTS: The CMSIS Deliverables are owned by ARM or its licensors and are protected by copyright and other intellectual property laws and international treaties. The CMSIS Deliverables are licensed not sold. Except as expressly licensed herein, you acquire no right, title or interest in the CMSIS Deliverables or any intellectual property therein. In no event shall the licences granted herein be construed as granting you, expressly or by implication, estoppels or otherwise, a licence to use any ARM technology except the CMSIS Deliverables.

3. SUPPORT.

ARM is not obligated to support the CMSIS Deliverables but may do so entirely at ARM's discretion.

4. NO WARRANTY.

YOU AGREE THAT THE CMSIS DELIVERABLES ARE LICENSED "AS IS", AND THAT ARM EXPRESSLY DISCLAIMS ALL REPRESENTATIONS, WARRANTIES, CONDITIONS OR OTHER TERMS, EXPRESS, IMPLIED OR STATUTORY, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, SATISFACTORY QUALITY, AND FITNESS FOR A PARTICULAR PURPOSE. THE CMSIS DELIVERABLES MAY CONTAIN ERRORS.

5. LIMITATION OF LIABILITY.

THE MAXIMUM LIABILITY OF ARM TO YOU IN AGGREGATE FOR ALL CLAIMS MADE AGAINST ARM IN CONTRACT, TORT OR OTHERWISE UNDER OR IN CONNECTION WITH THE SUBJECT MATTER OF THIS LICENCE SHALL NOT EXCEED THE GREATER OF (I) THE TOTAL OF SUMS PAID BY YOU TO ARM (IF ANY) FOR THIS LICENCE AND (II) US$10.00. THE LIMITATIONS, EXCLUSIONS AND DISCLAIMERS IN THIS LICENCE SHALL APPLY TO THE MAXIMUM EXTENT ALLOWED BY APPLICABLE LAW.

6. THIRD PARTY RIGHTS.

The Separate Files are delivered subject to and your use is governed by their own separate licence agreements. This Licence does not apply to such Separate Files and they are not included in the term “CMSIS Deliverables” under this Licence. You agree to comply with all terms and conditions imposed on you in respect of such Separate Files including those identified in the Schedule (“Third Party Terms”).

ARM HEREBY DISCLAIMS ANY AND ALL WARRANTIES EXPRESS OR IMPLIED FROM ANY THIRD PARTIES REGARDING ANY SEPARATE FILES, ANY THIRD PARTY MATERIALS INCLUDED IN THE SOFTWARE, ANY THIRD PARTY MATERIALS FROM WHICH THE SOFTWARE IS DERIVED (COLLECTIVELY “OTHER CODE”), AND THE USE OF ANY OR ALL THE OTHER CODE IN CONNECTION WITH THE SOFTWARE, INCLUDING (WITHOUT LIMITATION) ANY WARRANTIES OF SATISFACTORY QUALITY OR FITNESS FOR A PARTICULAR PURPOSE.

NO THIRD PARTY LICENSORS OF OTHER CODE SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND WHETHER MADE UNDER CONTRACT, TORT OR OTHER LEGAL THEORY, ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE OTHER CODE OR THE EXERCISE OF ANY RIGHTS GRANTED UNDER EITHER OR BOTH THIS LICENCE AND THE LEGAL TERMS APPLICABLE TO ANY SEPARATE FILES, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGES.

7. U.S. GOVERNMENT END USERS.

US Government Restrictions: Use, duplication, reproduction, release, modification, disclosure or transfer of this commercial product and accompanying documentation is restricted in accordance with the terms of this Licence.

8. TERM AND TERMINATION.

8.1 This Licence shall remain in force until terminated in accordance with the terms of Clause 8.2 or Clause 8.3 below.

8.2 Without prejudice to any of its other rights if you are in breach of any of the terms and conditions of this Licence then ARM may terminate this Licence immediately upon giving written notice to you. You may terminate this Licence at any time.

8.3 This Licence shall immediately terminate and shall be unavailable to you if you or any party affiliated to you asserts any patents against ARM, ARM affiliates, third parties who have a valid licence from ARM for the CMSIS Deliverables, or any customers or distributors of any of them based upon a claim that your (or your affiliate) patent is Necessary to implement the CMSIS Deliverables. In this Licence: (i) "affiliate" means any entity controlling, controlled by or under
common control with a party (in fact or in law, via voting securities, management control or otherwise) and "affiliated" shall be construed accordingly; (ii) "assert" means to allege infringement in legal or administrative proceedings, or proceedings before any other competent trade, arbitral or international authority; and (iii) “Necessary” means with respect to any claims of any patent, those claims which, without the appropriate permission of the patent owner, will be
infringed when implementing the CMSIS Deliverables because no alternative, commercially reasonable, non-infringing way of implementing the CMSIS Deliverables is known.

8.4 Upon termination of this Licence, you shall stop using the CMSIS Deliverables and destroy all copies of the CMSIS Deliverables in your possession. The provisions of clauses 5, 6, 7, 8 and 9 shall survive termination of this Licence.

9. GENERAL.

This Licence is governed by English Law. Except where ARM agrees otherwise in a written contract signed by you and ARM, this is the only agreement between you and ARM relating to the CMSIS Deliverables and it may only be modified by written agreement between you and ARM. Except as expressly agreed in writing, this Licence may not be modified by purchase orders, advertising or other representation by any person. If any clause or sentence in this Licence is held by a court of law to be
illegal or unenforceable the remaining provisions of this Licence shall not be affected thereby. The failure by ARM to enforce any of the provisions of this Licence, unless waived in writing, shall not constitute a waiver of ARM's rights to enforce such provision or any other provision of this Licence in the future. This Licence may not be assigned without the prior written consent of ARM.

SCHEDULE

Separate Files

The package also includes the components contained in the following directories:
(a) ./CMSIS/DSP_Lib - DSP Library sources and examples;
(b) ./CMSIS/Include - Header files;
(c) ./CMSIS/Lib - DSP Library build for various toolchains;
(d) ./CMSIS/RTOS - Header file template for CMSIS-RTOS implementation; and
(e) ./Device - Template files and implementations for Cortex-M class processors.

All of the above components (a– e) are licensed to you under the terms of the BSD licence, which is incorporated within or alongside the above components.
(f) ./CMSIS/Driver – CMSIS-Driver header files
(g) ./CMSIS/Pack – Example Device Family Pack

The above components (f – g) are licensed to you under the terms of the zlib licence, which is incorporated within or alongside the above components.




ARM contract reference LEC-PRE-00489- v3.0
1 June 2014
CONFIDENTIAL
LEC-PRE-00489
SP-Version: 3.0


+ 0
- 23
firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/EULA.txt View File

@@ -1,23 +0,0 @@
LIMITED LICENSE AGREEMENT

You (“Company” or “You”) must read this Limited License Agreement (this "Agreement") carefully and thoroughly before downloading, installing, and/or using any software or content (“Software”) provided herewith. BY DOWNLOADING, INSTALLING AND/OR USING ANY SOFTWARE OR CONTENT, YOU ARE CONFIRMING YOUR ACCEPTANCE OF THE TERMS OF THIS AGREEMENT. IF YOU DO NOT AGREE TO BE BOUND BY THE TERMS OF THIS AGREEMENT, THEN DO NOT DOWNLOAD, INSTALL/COMPLETE INSTALLATION OF, OR USE THE SOFTWARE OR CONTENT.

1. Grant of License. Atmel grants Company a non-exclusive, non-transferable, limited license: (a) to internally use the Software as a development platform solely in connection with an Atmel microcontroller product (“Atmel Product”), (b) to internally modify the source code version of the Software solely as necessary to implement such Software in products developed by Company that incorporate an Atmel Product (“Company Products”), and (c) to distribute the Software solely as implemented in Company Products. Company shall not use the Software for any purpose other than as specifically authorized herein.
2. Title. As between the parties, Atmel retains full rights, title, and ownership including all patents, copyrights, trade secrets, trade names, trademarks, and other intellectual property rights in and to the Software. Company agrees to take all reasonable steps to prevent unauthorized disclosure of the Software.

3. No Other Rights. Except as expressly stated herein, this Agreement does not grant Company, by implication, estoppels or otherwise, any rights to patents, copyrights, trade secrets, trade names, trademarks (whether registered or unregistered), or any other rights, franchises, or licenses in respect of the Software. Atmel will not provide any support or maintenance for the Software. Company will be solely responsible for supporting its customers, including resellers and end users.

4. No Support and Disclaimer of Warranty. Atmel is not obligated to furnish or make available to Company any further information, software, technical information, know-how, show-how, bug-fixes, or support. Atmel reserves the right to make changes to the Software without further notice. ATMEL IS PROVIDING THE SOFTWARE TO COMPANY “AS IS”, “WITH ALL FAULTS”, AND WITH NO WARRANTY WHATSOEVER. ATMEL MAKES NO WARRANTY THAT THE SOFTWARE IS COMPLETE, VERIFIED, OR VALIDATED. ATMEL IS MAKING NO REPRESENTATION THAT THE SOFTWARE IS FREE FROM ANY CLAIMS OF INFRINGEMENT. ATMEL MAKES NO WARRANTY WHATSOEVER, EXPRESS, IMPLIED, STATUTORY, CONTRACTUAL OR OTHERWISE WITH RESPECT TO THE SOFTWARE, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE OR NON-INFRINGEMENT AND ANY WARRANTIES ARISING BY VIRTUE OF CUSTOM OF TRADE OR COURSE OF DEALING.

5. Notice and Protection. Company agrees not to remove or destroy any proprietary trademark or copyright markings or notices placed upon or contained within the Software or any related documentation.

6. Export. Company acknowledges that the certain laws and regulations may restrict the export and re-export of the Software. Company will not export or re-export any Software (including the diskettes, related documentation and/or any hardware peripherals) in any form without the appropriate United States and foreign governmental approval.

7. Termination. The license will automatically terminate if Company fails to comply with any of the terms and conditions of the license. Upon termination for any reason, Company will immediately destroy or return to Atmel the Software, including all documentation and all whole or partial copies of the Software.

8. LIMITATION OF LIABILITY. IN NO EVENT SHALL ATMEL BE LIABLE TO COMPANY OR ANY THIRD PARTY FOR ANY CONSEQUENTIAL, SPECIAL, INDIRECT OR INCIDENTAL DAMAGES ARISING OUT OF OR RELATING TO THE SOFTWARE OR ANY OTHER ASPECT OF THIS AGREEMENT, EVEN IF ATMEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. IN NO EVENT SHALL THE LIABILITY OF ATMEL ARISING OUT OF OR RELATING TO THIS AGREEMENT EXCEED THE GREATER OF ONE THOUSAND U.S. DOLLARS (US$1,000) OR THE PRICE PAID BY COMPANY TO ATMEL FOR THE SOFTWARE.

9. General. This Agreement and all transactions concluded hereunder shall be governed by the laws of the State of California, as such laws are applied to contracts entered into and performed entirely in California by California residents. Any litigation relating to this Agreement shall be subject to the exclusive jurisdiction of the state courts located in Santa Clara County, California, or the federal courts located in the Northern District of California. If any provision of this Agreement is held to be invalid, illegal or unenforceable, that provision shall be construed in such a manner that it becomes valid and enforceable and so as to reflect most closely the intent of the parties in agreeing upon the provision in the first place, and the remaining provisions of this Agreement shall continue in full force and effect and shall not in any way be affected or impaired by any such determination of invalidity, illegality or unenforceability.

THIS AGREEMENT IS THE ENTIRE AND EXCLUSIVE AGREEMENT BETWEEN ATMEL AND COMPANY AND SUPERSEDES ALL PRIOR ORAL AND WRITTEN AGREEMENTS AND COMMUNICATIONS BETWEEN THE PARTIES PERTAINING TO THE SUBJECT MATTER OF THIS AGREEMENT. NO DIFFERENT OR ADDITIONAL TERMS WILL BE ENFORCEABLE AGAINST ATMEL UNLESS ATMEL GIVES ITS EXPRESS WRITTEN CONSENT, INCLUDING AN EXPRESS WAIVER OF THE TERMS OF THIS AGREEMENT.

+ 0
- 1458
firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/include/miwi_api.h
File diff suppressed because it is too large
View File


+ 0
- 35
firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/license.txt View File

@@ -1,35 +0,0 @@
MICROCHIP IS WILLING TO LICENSE THE ACCOMPANYING SOFTWARE AND DOCUMENTATION TO YOU ONLY ON THE CONDITION THAT YOU ACCEPT ALL OF THE FOLLOWING TERMS. TO ACCEPT THE TERMS OF THIS LICENSE, CLICK "I ACCEPT" AND PROCEED WITH THE DOWNLOAD OR INSTALL. IF YOU DO NOT ACCEPT THESE LICENSE TERMS, CLICK "CANCEL," AND DO NOT DOWNLOAD OR INSTALL THIS SOFTWARE.

MICROCHIP NON-EXCLUSIVE SOFTWARE LICENSE AGREEMENT
FOR MICROCHIP MIWI™ WIRELESS NETWORKING PROTOCOL STACK

This Microchip Nonexclusive Software License Agreement (“Agreement”) is a contract between you, your heirs, successors and assigns (“Licensee” or “you”) and Microchip Technology Incorporated, a Delaware corporation, with a principal place of business at 2355 W. Chandler Blvd., Chandler, AZ 85224-6199, and its subsidiaries including, Microchip Technology (Barbados) II Incorporated (collectively, “Microchip”) for the accompanying Microchip software, including Microchip MiWi™ Wireless Networking Protocol Stack and any personal computer programs, and any modifications or updates thereto (collectively, the “Software”), and accompanying documentation, including images and any other graphic resources provided by Microchip (“Documentation”).

1. Definitions. As used in this Agreement, the following capitalized terms will have the meanings defined below:
a. “Intellectual Property Rights” means any and all rights existing from time to time under patent law, copyright law, trade secret law, trademark law, unfair competition law, and any and all other proprietary rights, and any and all applications, renewals, extensions and restorations thereof, now or hereafter in force and effect worldwide.
b. “Licensee Products” means Licensee products that use or incorporate Microchip Products.
c. “Microchip Products” means Microchip AVR®, MEGA, SAM, XMEGA® devices and other Microchip integrated circuit devices.
d. “Source Code” means the software computer programming code used to create the Software which may be printed out and displayed in human readable form (including related programmer comments and documentation, if any) and error corrections, improvements, modifications and updates.
e. “Third Party” means Licensee’s agents, clients, consultants, customers, contract manufacturers, distributors, or resellers.
2. Software License Grant. Subject to Licensee’s compliance with the terms of this Agreement, Microchip grants strictly to Licensee a non-exclusive, non-transferable, worldwide license:
a. To use the Software in connection with the development of Licensee Products;
b. If Source Code is provided by Microchip to Licensee, to modify the Source Code for the sole purpose of rendering the Software operable with Licensee Products (“Modified Software”); and
c. To distribute the Software or Modified Software to Third Parties solely for use with or incorporation into Licensee Products, provided that Licensee ensures that: (i) such Third Party agrees to be bound by this Agreement (in writing or by “click to accept”), (ii) this Agreement accompanies such distribution; and (iii) Licensee clearly notifies Third Parties regarding the source of such Modified Software.
Except as expressly described in this Section 2 or the Documentation, Licensee cannot: (i) embed the Software or Modified Software on a non-Microchip Product and (ii) distribute Source Code to Third Party(ies).
3. License Restrictions. Licensee agrees:
a. Not to use the Software in any manner that could damage, disable, overburden, or impair the Software (or servers or networks connected to the Software), nor may Licensee use the Software in any manner that could interfere with any other party’s use and enjoyment of the Software (or servers or networks connected to the Software); and
b. That Licensee is solely responsible for (and Microchip has no responsibility to Licensee or to any third party for) Licensee’s use of the Software, any breach of Licensee’s obligations under this License, and for the consequences (including any loss or damage which Microchip may suffer) of any such breach.
4. Documentation License Grant. Subject to Licensee’s compliance with the terms of this Agreement, Microchip grants to Licensee a non-exclusive, non-transferable, worldwide license to use the Documentation in support of the authorized use of the Software as set forth in this Agreement.
5. Licensee Obligations. Licensee will not: (a) engage in unauthorized use, modification, disclosure or distribution of Software or Documentation, or its modifications or derivatives; (b) use all or any portion of the Software, Documentation, or its modifications or derivatives except in conjunction with Microchip Products, or Licensee Products as set forth in this Agreement; or (c) reverse engineer (by disassembly, decompilation or otherwise) Software or any portion thereof. Licensee may not remove or alter any Microchip copyright or other proprietary rights notice posted in any portion of the Software or Documentation. Licensee will defend, indemnify and hold Microchip and its subsidiaries harmless from and against any and all claims, costs, damages, expenses (including reasonable attorney's fees), liabilities, and losses, including without limitation: (x) any claims directly or indirectly arising from or related to the use, modification, disclosure or distribution of the Software, Documentation, or any Intellectual Property Rights related thereto; (y) the use, sale and distribution of Licensee Products; and (z) breach of this Agreement.
6. Confidentiality. Licensee agrees that the Software (including but not limited to the source code, object code and library files) and its modifications or derivatives, Documentation and underlying inventions, algorithms, know-how and ideas relating to the Software and the Documentation are proprietary information belonging to Microchip and its licensors ("Proprietary Information"). Except as expressly and unambiguously allowed herein, Licensee will hold in confidence and not use or disclose any Proprietary Information and will similarly bind its employees and Third Party(ies) in writing. Proprietary Information will not include information that: (i) is in or enters the public domain without breach of this Agreement and through no fault of the receiving party; (ii) the receiving party was legally in possession of prior to receiving it; (iii) the receiving party can demonstrate was developed by the receiving party independently and without use of or reference to the disclosing party's Proprietary Information; or (iv) the receiving party receives from a third party without restriction on disclosure. If Licensee is required to disclose Proprietary Information by law, court order, or government agency, Licensee will give Microchip prompt notice of such requirement in order to allow Microchip to object or limit such disclosure. Licensee agrees that the provisions of this Agreement regarding unauthorized use and nondisclosure of the Software, Documentation and related Proprietary Rights are necessary to protect the legitimate business interests of Microchip and its licensors and that monetary damage alone cannot adequately compensate Microchip or its licensors if such provisions are violated. Licensee, therefore, agrees that if Microchip alleges that Licensee or Third Party has breached or violated such provision then Microchip will have the right to injunctive relief, without the requirement for the posting of a bond, in addition to all other remedies at law or in equity.
7. Ownership of Proprietary Rights. Licensee acknowledges that (a) the Software contains proprietary and confidential information that is protected by applicable intellectual property and other laws, and (b) Microchip and/or third parties own and retain all right, title and interest in and to the Software and content, including Modified Software or any other Software modifications, but excluding your preexisting proprietary and confidential information, that may be presented or accessed through the Software, including without limitation all Intellectual Property Rights therein and thereto. You agree that you will not, and will not allow any third party to, (i) copy, sell, license, distribute, transfer, modify, adapt, translate, prepare derivative works from, decompile, reverse engineer, disassemble or otherwise attempt to derive Source Code from the Software or content that may be presented or accessed through the Software for any purpose, unless otherwise permitted, (ii) take any action to circumvent or defeat the security or content usage rules provided, deployed or enforced by any functionality (including without limitation digital rights management functionality) contained in the Software, (iii) use the Software to access, copy, transfer, transcode or retransmit content in violation of any law or third party rights, or (iv) remove, obscure, or alter Microchip’s or any third party’s copyright notices, trademarks, or other proprietary rights notices affixed to or contained within or accessed in conjunction with or through the Software.
8. Termination of Agreement. Without prejudice to any other rights, this Agreement terminates immediately, without notice by Microchip, upon a failure by Licensee or Third Party to comply with any provision of this Agreement. Microchip may terminate this Agreement immediately, for any reason, by written or verbal notice to Licensee or Third Party. Upon termination, Licensee and Third Party will immediately stop using the Software, Modified Software, Source Code, Documentation, modifications and derivatives thereof, and immediately destroy all such copies.
9. Indemnity. To the maximum extent permitted by law, you agree to defend, indemnify and hold harmless Microchip, its affiliates and their respective directors, officers, employees and agents from and against any and all claims, actions, suits or proceedings, as well as any and all losses, liabilities, damages, costs and expenses (including reasonable attorney’s fees) arising out of or accruing from your use of the Software, including without limitation your downloading, installation, or use of the Software, your violation of these Terms and Conditions, the use, modification, disclosure or distribution of the Software, Documentation or any Intellectual Property Rights related thereto, the sale of Licensee Products, and Licensee and Third Party non-compliance requirements.
10. Warranty Disclaimers. THE SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. MICROCHIP AND ITS LICENSORS ASSUME NO RESPONSIBILITY FOR THE ACCURACY, RELIABILITY OR APPLICATION OF THE SOFTWARE OR DOCUMENTATION. MICROCHIP AND ITS LICENSORS DO NOT WARRANT THAT THE SOFTWARE WILL MEET REQUIREMENTS OF LICENSEE OR THIRD PARTY, BE UNINTERRUPTED OR ERROR-FREE. MICROCHIP AND ITS LICENSORS HAVE NO OBLIGATION TO CORRECT ANY DEFECTS IN THE SOFTWARE.
11. Limited Liability. IN NO EVENT WILL MICROCHIP OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER ANY LEGAL OR EQUITABLE THEORY FOR ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES INCLUDING BUT NOT LIMITED TO INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS. The aggregate and cumulative liability of Microchip and its licensors for damages hereunder will in no event exceed $1000 or the amount Licensee paid Microchip for the Software and Documentation, whichever is greater. Licensee acknowledges that the foregoing limitations are reasonable and an essential part of this Agreement.
12. General. THIS AGREEMENT WILL BE GOVERNED BY AND CONSTRUED UNDER THE LAWS OF THE STATE OF ARIZONA AND THE UNITED STATES WITHOUT REGARD TO CONFLICTS OF LAWS PROVISIONS. Licensee agrees that any disputes arising out of or related to this Agreement, Software or Documentation will be brought exclusively in either the U.S. District Court for the District of Arizona, Phoenix Division, or the Superior Court of Arizona located in Maricopa County, Arizona. This Agreement will constitute the entire agreement between the parties with respect to the subject matter hereof. It will not be modified except by a written agreement signed by an authorized representative of Microchip. If any provision of this Agreement will be held by a court of competent jurisdiction to be illegal, invalid or unenforceable, that provision will be limited or eliminated to the minimum extent necessary so that this Agreement will otherwise remain in full force and effect and enforceable. No waiver of any breach of any provision of this Agreement will constitute a waiver of any prior, concurrent or subsequent breach of the same or any other provisions hereof, and no waiver will be effective unless made in writing and signed by an authorized representative of the waiving party. Licensee agrees to comply with all import and export laws and restrictions and regulations of the Department of Commerce or other United States or foreign agency or authority. The indemnities, obligations of confidentiality, and limitations on liability described herein, and any right of action for breach of this Agreement prior to termination, will survive any termination of this Agreement. Any prohibited assignment will be null and void. The Software and Documentation are “Commercial Items”, as that term is defined at 48 C.F.R. §2.101, consisting of “Commercial Computer Software” and “Commercial Computer Software Documentation”, as such terms are used in 48 C.F.R. §12.212 or 48 C.F.R. §227.7202, as applicable. Consistent with 48 C.F.R. §12.212 or 48 C.F.R. §227.7202-1 through 227.7202-4, as applicable, the Commercial Computer Software and Commercial Computer Software Documentation are being licensed to U.S. Government end users (a) only as Commercial Items and (b) with only those rights as are granted to all other end users pursuant to the terms and conditions of this License. Unpublished-rights reserved under the copyright laws of the United States.
If Licensee has any questions about this Agreement, please write to Microchip Technology Inc., 2355 W. Chandler Blvd., Chandler, AZ 85224-6199 USA. ATTN: Marketing. License Rev. No. 09-04252017

Copyright © 2007-2018, Microchip Technology Incorporated. All rights reserved.


+ 0
- 192
firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/lcd/lcd.c View File

@@ -1,192 +0,0 @@
/**
* \file lcd.c
*
* \brief LCD Abstraction for MiWi Protocol implementation
*
* Copyright (c) 2019 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/
/*
* Support and FAQ: visit <a href="https://www.microchip.com/support/">Microchip Support</a>
*/

#include "system.h"
#include "lcd.h"
#include "delay.h"
#include "port.h"
#include "board.h"
#include "asf.h"

#if defined (ENABLE_LCD)

#include "gfx_mono.h"
#include "gfx_mono_spinctrl.h"
#include "gfx_mono_text.h"
#include "sysfont.h"

// LCDText is a 32 byte shadow of the LCD text. Write to it and
// then call LCDUpdate() to copy the string into the LCD module.
char LCDText[16*4+1];
/*********************************************************************
* Function: void LCD_Initialize(void)
*
* PreCondition: none
*
* Input: none
*
* Output: none
*
* Side Effects: LCD is configured
*
* Overview: Configure the LCD
*
* Note: None
********************************************************************/
void LCD_Initialize(void)
{
gfx_mono_init();
}
/*********************************************************************
* Function: void LCD_Erase(void)
*
* PreCondition: none
*
* Input: none
*
* Output: none
*
* Side Effects: LCD display cleared
*
* Overview: Clears LCD display
*
* Note: None
********************************************************************/
void LCD_Erase(void)
{
/* Clear screen */
gfx_mono_draw_filled_rect(0, 0, GFX_MONO_LCD_WIDTH, GFX_MONO_LCD_HEIGHT,
GFX_PIXEL_CLR);
}
/*********************************************************************
* Function: void LCD_Update(void)
*
* PreCondition: none
*
* Input: none
*
* Output: none
*
* Side Effects: LCD is updated with message
*
* Overview: LCD displays message
*
* Note: None
********************************************************************/
void LCD_Update(void)
{
gfx_mono_draw_string(LCDText, 0, 0, &sysfont);
}

/*********************************************************************
* Function: void LCDTRXCount(uint8_t txCount, uint8_t rxCount)
*
* PreCondition: LCD has been initialized
*
* Input: txCount - the total number of transmitted messages
* rxCount - the total number of received messages
*
* Output: None
*
* Side Effects: None
*
* Overview: This function display the total numbers of TX and
* RX messages on the LCD, if applicable.
*
* Note: This routine is only effective if Explorer16 or
* PIC18 Explorer demo boards are used
********************************************************************/
void LCDTRXCount(uint8_t txCount, uint8_t rxCount)
{
/* Clear screen */
gfx_mono_draw_filled_rect(0, 0, GFX_MONO_LCD_WIDTH, GFX_MONO_LCD_HEIGHT,
GFX_PIXEL_CLR);
snprintf(LCDText, sizeof(LCDText), "TX Messages: %d \nRX Messages: %d", txCount, rxCount);
gfx_mono_draw_string(LCDText, 0, 0, &sysfont);
delay_ms(200);
}



/*********************************************************************
* Function: void LCDDisplay(char *text, uint8_t value, bool delay)
*
* PreCondition: LCD has been initialized
*
* Input: text - text message to be displayed on LCD
* value - the text message allows up to one byte
* of variable in the message
* delay - whether need to display the message for
* 2 second without change
*
* Output: None
*
* Side Effects: None
*
* Overview: This function display the text message on the LCD,
* including up to one uint8_t variable, if applicable.
*
* Note: This routine is only effective if Explorer16 or
* PIC18 Explorer demo boards are used
********************************************************************/
void LCDDisplay(char *text, uint8_t value, bool delay)
{
/* Clear screen */
gfx_mono_draw_filled_rect(0, 0, GFX_MONO_LCD_WIDTH, GFX_MONO_LCD_HEIGHT,
GFX_PIXEL_CLR);

snprintf(LCDText, sizeof(LCDText), text);

if (value)
{
uint8_t char_count = 0;
do {
++char_count;
} while (*(++text));
snprintf(LCDText+char_count, sizeof(LCDText), "%d", value);
}
gfx_mono_draw_string(LCDText, 0, 0, &sysfont);
if(delay)
{
delay_s(2);
}
}

#endif

+ 0
- 126
firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/lcd/lcd.h View File

@@ -1,126 +0,0 @@
/**
* \file lcd.h
*
* \brief LCD Abstraction for MiWi Protocol interface
*
* Copyright (c) 2019 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/
/*
* Support and FAQ: visit <a href="https://www.microchip.com/support/">Microchip Support</a>
*/

#ifndef __LCDBLOCKING_H
#define __LCDBLOCKING_H


extern char LCDText[16*4+1];
/*********************************************************************
* Function: void LCD_Initialize(void)
*
* PreCondition: none
*
* Input: none
*
* Output: none
*
* Side Effects: LCD is configured
*
* Overview: Configure the LCD
*
* Note: None
********************************************************************/
void LCD_Initialize(void);

/*********************************************************************
* Function: void LCD_Update(void)
*
* PreCondition: none
*
* Input: none
*
* Output: none
*
* Side Effects: LCD is updated with message
*
* Overview: LCD displays message
*
* Note: None
********************************************************************/
void LCD_Update(void);

/*********************************************************************
* Function: void LCD_Erase(void)
*
* PreCondition: none
*
* Input: none
*
* Output: none
*
* Side Effects: LCD display cleared
*
* Overview: Clears LCD display
*
* Note: None
********************************************************************/
void LCD_Erase(void);

/*********************************************************************
* Function: void LCDDisplay( char * message, uint8_t value, bool delay )
*
* Overview: Displays the message on the LCD
*
* PreCondition: None
*
* Input: message, variable if needed and delay
*
* Output: Prints the message on the LCD
*
********************************************************************/
void LCDDisplay(char * message, uint8_t value, bool delay);

/*********************************************************************
* Function: void LCDTRXCount(uint8_t txCount, uint8_t rxCount)
*
* PreCondition: LCD has been initialized
*
* Input: txCount - the total number of transmitted messages
* rxCount - the total number of received messages
*
* Output: None
*
* Side Effects: None
*
* Overview: This function display the total numbers of TX and
* RX messages on the LCD, if applicable.
*
* Note:
********************************************************************/
void LCDTRXCount(uint8_t, uint8_t);
#endif

+ 0
- 136
firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/pds/inc/nv/D_Nv.h View File

@@ -1,136 +0,0 @@
/**
* \file D_Nv.h
*
* \brief NV component header
*
* The segment D_NV_MEMORY must be defined and reserved in the linker script
* (.xcl file), for example like this:
*
* -D_D_NV_MEMORY_START=400
* -D_D_NV_MEMORY_SIZE=4000
*
* -Z(CODE)D_NV_MEMORY+_D_NV_MEMORY_SIZE=[_D_NV_MEMORY_START:+_D_NV_MEMORY_SIZE]
*
* Note that nothing should actually be placed in the segment.
* These linker script commands will ensure that the entire range
* is reserved and not programmed (left as 0xff).
*
* The segment should start on a flash page boundary, and the
* size should correspond to the define D_NV_MEMORY_SIZE.
*
* Further, since the device can only erase a whole page and not
* arbitrary locations in flash, the sector size _must_ be an
* integer multiple of the flash page size.
* Otherwise, erasing the first or last page of a sector will
* also erase content in flash locations neighbouring the sector.

* Copyright (c) 2019 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/

#include <compiler.h>

#ifndef D_NV_H
#define D_NV_H


typedef uint16_t D_Nv_Size_t;


#if !defined(D_NV_FIRST_SECTOR)
# define D_NV_FIRST_SECTOR 0
#endif

#if !defined(D_NV_SECTOR_COUNT)
# define D_NV_SECTOR_COUNT 2
#endif

// Sector size must be an integer multiple of flash pages
#if !defined(D_NV_SECTOR_SIZE)
# define D_NV_SECTOR_SIZE (8192U)
#endif

// Size of D_NV_MEMORY segment should equal this
#define D_NV_MEMORY_SIZE (D_NV_SECTOR_COUNT * D_NV_SECTOR_SIZE)

#define GET_FIELD_PTR(structPtr, typeName, fieldName) \
((uint8_t *)(structPtr) + offsetof(typeName, fieldName))

#define GET_PARENT_BY_FIELD(TYPE, FIELD, FIELD_POINTER) \
((TYPE *)(((uint8_t *)FIELD_POINTER) - offsetof(TYPE, FIELD)))
#define GET_CONST_PARENT_BY_FIELD(TYPE, FIELD, FIELD_POINTER) \
((const TYPE *)(((const uint8_t *)FIELD_POINTER) - offsetof(TYPE, FIELD)))

#define GET_STRUCT_BY_FIELD_POINTER(struct_type, field_name, field_pointer)\
((struct_type *) (((uint8_t *) field_pointer) - FIELD_OFFSET(struct_type, field_name)))
#define GET_INDEX_FROM_OFFSET(PTR1, PTR2) (PTR1 - PTR2)

// Size of slice between firstField end lastField of struct (including lastField)
#define SLICE_SIZE(type, firstField, lastField)\
(offsetof(type, lastField) - offsetof(type, firstField) + sizeof(((type *)0)->lastField))

#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))

#define ADD_COMMA(value, n) value,
/* Macro for array initialization */
#define INIT_ARRAY(initValue, size) {REPEAT_MACRO(ADD_COMMA, initValue, size)}

#undef FIELD_OFFSET
#define FIELD_OFFSET(struct_type, field_name)\
(((uint8_t*) &((struct_type *)(NULL))->field_name) - (uint8_t*)NULL)

#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))

#define FIRST_BIT_SET(bitmask) ((bitmask) & (~(bitmask) + 1))
#define FIRST_BIT_CLEARED(bitmask) (~(bitmask) & ((bitmask) + 1))

#define COMPARE_WITH_THRESHOLD(a, b, threshold) \
(abs((a) - (b)) < (threshold) ? ((a) > (b) ? 1 : 0) : ((a) > (b) ? 0 : 1))

#define CEIL(a, b) (((a) - 1U)/(b) + 1U)

#ifndef FLASH_PTR
#define FLASH_PTR
#endif

#ifdef __cplusplus
extern "C" {
#endif

void D_Nv_Read(uint8_t sector, uint16_t offset, uint8_t *pBuffer, D_Nv_Size_t numberOfBytes);
void D_Nv_Write(uint8_t sector, uint16_t offset, uint8_t *pBuffer, D_Nv_Size_t numberOfBytes);
void D_Nv_EraseSector(uint8_t sector);
bool D_Nv_IsEmpty(uint8_t sector, uint16_t offset, D_Nv_Size_t numberOfBytes);
bool D_Nv_IsEqual(uint8_t sector, uint16_t offset, uint8_t *pBuffer, D_Nv_Size_t numberOfBytes);
void D_Nv_SetSystemIntegrityCheckFunction(void (*pf)(void));

#ifdef __cplusplus
}
#endif

#endif // D_NV_H

+ 0
- 40
firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/pds/inc/nv/D_Nv_Bindings.h View File

@@ -1,40 +0,0 @@
/**
* \file
*
* \brief Nv Bindings Interface
*
* Copyright (c) 2019 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/
// implemented interface(s)
#define D_Nv_Read D_Nv_Read_Impl
#define D_Nv_Write D_Nv_Write_Impl
#define D_Nv_EraseSector D_Nv_EraseSector_Impl
#define D_Nv_IsEmpty D_Nv_IsEmpty_Impl
#define D_Nv_IsEqual D_Nv_IsEqual_Impl

// no used interfaces

+ 0
- 46
firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/pds/inc/nv/D_Nv_Init.h View File

@@ -1,46 +0,0 @@
/**
* \file D_Nv_init.h
*
* \brief NV component header
*
* Copyright (c) 2019 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/
#ifndef D_NV_INIT_H
#define D_NV_INIT_H

#ifdef __cplusplus
extern "C" {
#endif

void D_Nv_Init(void);

#ifdef __cplusplus
}
#endif

#endif // D_NV_INIT_H

+ 0
- 127
firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/pds/inc/nv/External/D_XNv.h View File

@@ -1,127 +0,0 @@
/**
* \file D_XNv.h
*
* \brief D_XNv Driver Interface
*
* Copyright (c) 2019 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/

#ifndef D_XNV_H
#define D_XNV_H

/***************************************************************************************************
* INCLUDE FILES
***************************************************************************************************/

#include "N_Types.h"

/***************************************************************************************************
* C++ DECLARATION WRAPPER
***************************************************************************************************/

#ifdef __cplusplus
extern "C" {
#endif

/***************************************************************************************************
* EXPORTED TYPES
***************************************************************************************************/

#if defined BOOTLOADER
typedef uint8_t D_XNv_Size_t;
#else
typedef uint16_t D_XNv_Size_t;
#endif

/***************************************************************************************************
* EXPORTED MACROS AND CONSTANTS
***************************************************************************************************/

#if defined(TESTHARNESS)
#define D_XNV_SECTOR_SIZE (4096uL)
#else
#define D_XNV_SECTOR_SIZE (65536uL)
#endif

/***************************************************************************************************
* EXPORTED FUNCTIONS
***************************************************************************************************/

/** Read bytes from the external NV.
\param sector The sector to use (0..7)
\param offset The offset to start reading at
\param[out] pBuffer The start address of the buffer to store the read data to
\param numberOfBytes The number of bytes to read
\note offset+numberOfBytes must be <=0x10000 (meaning sector crossing is not permitted)
*/
void D_XNv_Read(uint8_t sector, uint16_t offset, uint8_t *pBuffer, D_XNv_Size_t numberOfBytes);

/** Write bytes to the external NV.
\param sector The sector to use (0..7)
\param offset The offset to start writing to
\param[in] pBuffer The start address of the buffer that contains the data to write
\param numberOfBytes The number of bytes to write
\note offset+numberOfBytes must be <=0x10000 (meaning sector crossing is not permitted)
*/
void D_XNv_Write(uint8_t sector, uint16_t offset, const uint8_t *pBuffer, D_XNv_Size_t numberOfBytes);

/** Erases a sector of the external NV.
\note The erase operation can take very long, depending on the actual chip that is used.
Typical erase times are 600-1500 ms. This function will return immediately, however.
The next request to D_XNv will first wait until the erase has finished.
*/
void D_XNv_EraseSector(uint8_t sector);

/** Checks if the requested range is empty (containing all 0xFF).
\param sector The sector to use (0..7)
\param offset The start offset to check
\param numberOfBytes The number of bytes to check
\returns TRUE if the range is empty, FALSE otherwise.
\note A special case is when numberOfBytes==0, which requests to check 0x10000 bytes
\note Sector crossing is not permitted
*/
bool D_XNv_IsEmpty(uint8_t sector, uint16_t offset, D_XNv_Size_t numberOfBytes);

/** Compare bytes with contents of the external NV.
\param sector The sector to use (0..7)
\param offset The offset to start comparing with
\param[in] pBuffer The start address of the buffer that contains the data to compare with
\param numberOfBytes The number of bytes to compare
\note offset+numberOfBytes must be <=0x10000 (meaning sector crossing is not permitted)
*/
bool D_XNv_IsEqual(uint8_t sector, uint16_t offset, uint8_t *pBuffer, D_XNv_Size_t numberOfBytes);

/***************************************************************************************************
* END OF C++ DECLARATION WRAPPER
***************************************************************************************************/

#ifdef __cplusplus
}
#endif

#endif // D_XNV_H

+ 0
- 40
firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/pds/inc/nv/External/D_XNv_Bindings.h View File

@@ -1,40 +0,0 @@
/**
* \file
*
* \brief Bindings interface
*
* Copyright (c) 2019 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/
// implemented interface(s)
#define D_XNv_Read D_XNv_Read_Impl
#define D_XNv_Write D_XNv_Write_Impl
#define D_XNv_EraseSector D_XNv_EraseSector_Impl
#define D_XNv_IsEmpty D_XNv_IsEmpty_Impl
#define D_XNv_IsEqual D_XNv_IsEqual_Impl

// no used interfaces

+ 0
- 81
firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/pds/inc/nv/External/D_XNv_Init.h View File

@@ -1,81 +0,0 @@
/**
* \file D_XNv_Init.h
*
* \brief D_XNv Initialization Interface
*
* Copyright (c) 2019 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/

#ifndef D_XNV_INIT_H
#define D_XNV_INIT_H

/***************************************************************************************************
* INCLUDE FILES
***************************************************************************************************/

#include "N_Types.h"

/***************************************************************************************************
* C++ DECLARATION WRAPPER
***************************************************************************************************/

#ifdef __cplusplus
extern "C" {
#endif

/***************************************************************************************************
* EXPORTED TYPES
***************************************************************************************************/


/***************************************************************************************************
* EXPORTED MACROS AND CONSTANTS
***************************************************************************************************/


/***************************************************************************************************
* EXPORTED FUNCTIONS
***************************************************************************************************/

/** Initializes the component.
*/
void D_XNv_Init(void);

/** D_Xnv Integrity check function.
*/
void D_XNv_SetSystemIntegrityCheckFunction(void (*pf)(void));

/***************************************************************************************************
* END OF C++ DECLARATION WRAPPER
***************************************************************************************************/

#ifdef __cplusplus
}
#endif

#endif // D_XNV_INIT_H

+ 0
- 186
firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/pds/inc/nv/External/S_XNv.h View File

@@ -1,186 +0,0 @@
/**
* \file S_XNv.h
*
* \brief S_XNv Driver Interface
*
* Copyright (c) 2019 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/

#ifndef S_XNV_H
#define S_XNV_H

/***************************************************************************************************
* INCLUDE FILES
***************************************************************************************************/

#include "N_Types.h"

/***************************************************************************************************
* C++ DECLARATION WRAPPER
***************************************************************************************************/

#ifdef __cplusplus
extern "C" {
#endif

/***************************************************************************************************
* EXPORTED TYPES
***************************************************************************************************/

/** Identifier type to an item in Flash. Valid range is 1..32767. */
typedef uint16_t S_XNv_ItemId_t;

/** Return value type of most S_XNv functions. */
typedef enum S_XNv_ReturnValue_t
{
/** The operation succeeded. */
S_XNv_ReturnValue_Ok,

/** Unable to write to flash. */
S_XNv_ReturnValue_Failure,

/** The item didn't exist but was successfully created and initialised. No error. */
S_XNv_ReturnValue_DidNotExist,

/** The item that was attempted to access doesn't exist. */
S_XNv_ReturnValue_DoesNotExist,

/** An attempt was made to read or write beyond the length of the item. */
S_XNv_ReturnValue_BeyondEnd,

/** The power supply voltage was too low to reliably perform the requested operation. The operation has not been executed. */
S_XNv_ReturnValue_PowerSupplyTooLow,

} S_XNv_ReturnValue_t;

/** Function type used to check the external NV's power supply.
Should only return TRUE if the power supply is high enough to reliably perform a write or erase operation.
*/
typedef bool (*S_XNv_PowerSupplyCheckingFunction_t)(void);

/***************************************************************************************************
* EXPORTED MACROS AND CONSTANTS
***************************************************************************************************/


/***************************************************************************************************
* EXPORTED FUNCTIONS
***************************************************************************************************/

/** Initializes an item with default data, but only if it doesn't exit yet.

\param id The item to initialize.
\param itemLength The length of the item.
\param pDefaultData Buffer to 'itemLength' bytes, or NULL.
\returns S_XNv_ReturnValue_Ok, S_XNv_ReturnValue_DidNotExist or S_XNv_ReturnValue_PowerSupplyTooLow.

If the item doesn't exist, it is written with the given default data and the status code
S_XNv_ReturnValue_DidNotExist is returned. Otherwise, the default data is not used, the item
is kept as it was but read into pDefaultData, and S_XNv_ReturnValue_Ok is returned.
If NULL is passed for pDefaultData, and the item doesn't exist all data is initialized to 0xFF.

\note pDefaultData must not point to constant data.
*/
S_XNv_ReturnValue_t S_XNv_ItemInit(S_XNv_ItemId_t id, uint16_t itemLength, void* pDefaultData);

/** Writes an item.

\param id The item to write.
\param offset The offset in the item to start writing to.
\param dataLength The length of the data to write.
\param pData Pointer to 'dataLength' bytes to write.
\returns S_XNv_ReturnValue_Ok, S_XNv_ReturnValue_DoesNotExist, S_XNv_ReturnValue_BeyondEnd or S_XNv_ReturnValue_PowerSupplyTooLow.

If any of the bytes fall outside the item length as passed during S_XNv_ItemInit(), the whole
write operation does not occur and S_XNv_ReturnValue_BeyondEnd is returned.
*/
S_XNv_ReturnValue_t S_XNv_Write(S_XNv_ItemId_t id, uint16_t offset, uint16_t dataLength, void* pData);

/** Reads an item.

\param id The item to read.
\param offset The offset in the item to start reading from.
\param dataLength The length of the data to read.
\param pData Pointer to a buffer where the read bytes are to be written to.
\returns S_XNv_ReturnValue_Ok, S_XNv_ReturnValue_DoesntExist or S_XNv_ReturnValue_BeyondEnd.

If any of the bytes fall outside the item length as passed during S_XNv_ItemInit(), the whole
read operation does not occur and S_XNv_ReturnValue_BeyondEnd is returned.
*/

S_XNv_ReturnValue_t S_XNv_Read(S_XNv_ItemId_t id, uint16_t offset, uint16_t dataLength, void* pData);

/** Returns the item length of an item.

\param id The item to get the length from.
\returns The length of the item, in bytes, as passed during S_XNv_ItemInit(), or 0 if the item doesn't exist.
*/
uint16_t S_XNv_ItemLength(S_XNv_ItemId_t id);

/** Deletes an item from non-volatile storage.

\param id The item to delete.
\returns S_XNv_ReturnValue_Ok, S_XNv_ReturnValue_DoesntExist or S_XNv_ReturnValue_PowerSupplyTooLow.
*/
S_XNv_ReturnValue_t S_XNv_Delete(S_XNv_ItemId_t id);

/** Erases all items (optionally except the persistent ones) from non-volatile storage.

\param includingPersistentItems Whether to also erase the peristent items.
\returns S_XNv_ReturnValue_Ok or S_XNv_ReturnValue_PowerSupplyTooLow.

The persistent items should typically never be erased in an application!
*/
S_XNv_ReturnValue_t S_XNv_EraseAll(bool includingPersistentItems);

/** Sets a function to check the power supply.

\param pf A pointer to a function that S_XNv uses to check the power supply.

If the power supply checking function is not set, the default is to assume that the power
supply is always high enough. This is not suitable for typical applications.
When this function is called again,
*/
void S_XNv_SetPowerSupplyCheckingFunction(S_XNv_PowerSupplyCheckingFunction_t pf);

/** Checks the item is available or not.

\param id The item to check
\returns true if item is available, false if not.
*/
bool S_XNv_IsItemAvailable_Impl(S_XNv_ItemId_t id);

/***************************************************************************************************
* END OF C++ DECLARATION WRAPPER
***************************************************************************************************/

#ifdef __cplusplus
}
#endif

#endif // S_XNV_H

+ 0
- 70
firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/pds/inc/nv/External/S_XNv_Bindings.h View File

@@ -1,70 +0,0 @@
/**
* \file
*
* \brief XNv Bindings Interface
*
* Copyright (c) 2019 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/
// implemented interface(s)
#define S_XNv_ItemInit S_XNv_ItemInit_Impl
#define S_XNv_Write S_XNv_Write_Impl
#define S_XNv_Read S_XNv_Read_Impl
#define S_XNv_EraseAll S_XNv_EraseAll_Impl
#define S_XNv_SetPowerSupplyCheckingFunction S_XNv_SetPowerSupplyCheckingFunction_Impl
#define S_XNv_ItemLength S_XNv_ItemLength_Impl
#define S_XNv_Delete S_XNv_Delete_Impl
#define S_XNv_SetPowerSupplyCheckingFunction S_XNv_SetPowerSupplyCheckingFunction_Impl
#define S_XNv_IsItemAvailable S_XNv_IsItemAvailable_Impl

// used interfaces
#if defined(TESTHARNESS)
// ...bind to stubs...
#define D_XNv_Write D_XNv_Stub_Write
#define D_XNv_Read D_XNv_Stub_Read
#define D_XNv_EraseSector D_XNv_Stub_EraseSector
#define D_XNv_IsEmpty D_XNv_Stub_IsEmpty
#define D_XNv_IsEqual D_XNv_Stub_IsEqual

// Use actual timers
#define N_Timer_Stop N_Timer_Stop_Impl
#define N_Timer_Start16 N_Timer_Start16_Impl
#define N_Timer_IsRunning N_Timer_IsRunning_Impl

#else
// ...bind to implementation...
#define D_XNv_Write D_XNv_Write_Impl
#define D_XNv_Read D_XNv_Read_Impl
#define D_XNv_EraseSector D_XNv_EraseSector_Impl
#define D_XNv_IsEmpty D_XNv_IsEmpty_Impl
#define D_XNv_IsEqual D_XNv_IsEqual_Impl

#define N_Timer_Stop N_Timer_Stop_Impl
#define N_Timer_Start16 N_Timer_Start16_Impl
#define N_Timer_IsRunning N_Timer_IsRunning_Impl

#endif

+ 0
- 92
firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/pds/inc/nv/External/S_XNv_Init.h View File

@@ -1,92 +0,0 @@
/**
* \file S_XNv_Init.h
*
* \brief S_XNv Initializer Driver Interface
*
* Copyright (c) 2019 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/

#ifndef S_XNV_INIT_H
#define S_XNV_INIT_H

/***************************************************************************************************
* INCLUDE FILES
***************************************************************************************************/

#include "N_Task.h"
#include "N_Types.h"

/***************************************************************************************************
* C++ DECLARATION WRAPPER
***************************************************************************************************/

#ifdef __cplusplus
extern "C" {
#endif

/***************************************************************************************************
* EXPORTED TYPES
***************************************************************************************************/


/***************************************************************************************************
* EXPORTED MACROS AND CONSTANTS
***************************************************************************************************/


/***************************************************************************************************
* EXPORTED FUNCTIONS
***************************************************************************************************/

/** Initializes the external flash service for early access.
\note It is not required to call this function if the application does not require early access
to external Nv. Note that the S_XNv component is fully functional after calling S_XNv_EarlyInit(),
but until S_XNv_Init() is called, chances are much higher that the component blocks when a sector
becomes full. Only after S_XNv_Init() is called, compacting the sector is decoupled as much as
possible.
*/
void S_XNv_EarlyInit(void);

/** Initializes the rest of the component (timers and task). Note that N_Task and N_Timer must be
initialised first.
*/
void S_XNv_Init(void);

/** The event handler for the component's task.
*/
bool S_XNv_EventHandler(N_Task_Event_t evt);

/***************************************************************************************************
* END OF C++ DECLARATION WRAPPER
***************************************************************************************************/

#ifdef __cplusplus
}
#endif

#endif // S_XNV_INIT_H

+ 0
- 216
firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/pds/inc/nv/S_Nv.h View File

@@ -1,216 +0,0 @@
/**
* \file S_Nv.h
*
* \brief NV component header
*
* Copyright (c) 2019 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/

#ifndef S_NV_H
#define S_NV_H

/***************************************************************************************************
* INCLUDE FILES
***************************************************************************************************/

#include <compiler.h>

/***************************************************************************************************
* C++ DECLARATION WRAPPER
***************************************************************************************************/

#ifdef __cplusplus
extern "C" {
#endif

/***************************************************************************************************
* EXPORTED TYPES
***************************************************************************************************/

/** Identifier type to an item in Flash. Valid range is 1..32767. */
typedef uint16_t S_Nv_ItemId_t;

/** Return value type of most S_Nv functions. */
typedef enum S_Nv_ReturnValue_t
{
/** The operation succeeded. */
S_Nv_ReturnValue_Ok,

/** Unable to write to flash. */
S_Nv_ReturnValue_Failure,

/** The item didn't exist but was successfully created and initialised. No error. */
S_Nv_ReturnValue_DidNotExist,

/** The item that was attempted to access doesn't exist. */
S_Nv_ReturnValue_DoesNotExist,

/** An attempt was made to read or write beyond the length of the item. */
S_Nv_ReturnValue_BeyondEnd,

/** The power supply voltage was too low to reliably perform the requested operation. The operation has not been executed. */
S_Nv_ReturnValue_PowerSupplyTooLow,

} S_Nv_ReturnValue_t;

/** Function type used to check the external NV's power supply.
Should only return TRUE if the power supply is high enough to reliably perform a write or erase operation.
*/
typedef bool (*S_Nv_PowerSupplyCheckingFunction_t)(void);

/***************************************************************************************************
* EXPORTED MACROS AND CONSTANTS
***************************************************************************************************/

/** The ranges of IDs that can be used by the stack for storing flash data. See \ref wlPdsMemIds.h
*/
#define S_NV_STACK_RANGE_MIN 0x0001u
#define S_NV_STACK_RANGE_MAX 0x07FFu

/** First reserved range for a platform
*/
#define S_NV_PLATFORM_RANGE1_MIN 0x0800u
#define S_NV_PLATFORM_RANGE1_MAX 0x08FFu

/** The ranges of IDs that can be used by the application for storing flash data
*/
#define S_NV_APPLICATION_RANGE_MIN 0x0900u
#define S_NV_APPLICATION_RANGE_MAX 0x3FFFu

/** Reserved range for future use
*/
#define S_NV_RESERVED_RANGE_MIN 0x4000u
#define S_NV_RESERVED_RANGE_MAX 0x6FFFu

/** Second reserved range for a platform
*/
#define S_NV_PLATFORM_RANGE2_MIN 0x7000u
#define S_NV_PLATFORM_RANGE2_MAX 0x7FFFu


/***************************************************************************************************
* EXPORTED FUNCTIONS
***************************************************************************************************/

/** Initializes an item with default data if it doesn't exist yet, or reads it when it does exist.

\param id The item to initialize.
\param itemLength The length of the item.
\param pDefaultData Buffer to 'itemLength' bytes, or NULL.
\returns S_Nv_ReturnValue_Ok, S_Nv_ReturnValue_DidNotExist or S_Nv_ReturnValue_PowerSupplyTooLow.

If the item doesn't exist, it is written with the given default data and the status code
S_Nv_ReturnValue_DidNotExist is returned. Otherwise, the default data is not used, the item
is kept as it was but read into pDefaultData, and S_Nv_ReturnValue_Ok is returned.
If NULL is passed for pDefaultData, and the item doesn't exist all data is initialized to 0xFF.

\note pDefaultData must not point to constant data.
*/
S_Nv_ReturnValue_t S_Nv_ItemInit(S_Nv_ItemId_t id, uint16_t itemLength, void* pDefaultData);

/** Writes an item.

\param id The item to write.
\param offset The offset in the item to start writing to.
\param dataLength The length of the data to write.
\param pData Pointer to 'dataLength' bytes to write.
\returns S_Nv_ReturnValue_Ok, S_Nv_ReturnValue_DoesNotExist, S_Nv_ReturnValue_BeyondEnd or S_Nv_ReturnValue_PowerSupplyTooLow.

If any of the bytes fall outside the item lenght as passed during S_Nv_ItemInit(), the whole
write operation does not occur and S_Nv_ReturnValue_BeyondEnd is returned.
*/
S_Nv_ReturnValue_t S_Nv_Write(S_Nv_ItemId_t id, uint16_t offset, uint16_t dataLength, void* pData);

/** Reads an item.

\param id The item to read.
\param offset The offset in the item to start reading from.
\param dataLength The length of the data to read.
\param pData Pointer to a buffer where the read bytes are to be written to.
\returns S_Nv_ReturnValue_Ok, S_Nv_ReturnValue_DoesntExist or S_Nv_ReturnValue_BeyondEnd.

If any of the bytes fall outside the item lenght as passed during S_Nv_ItemInit(), the whole
read operation does not occur and S_Nv_ReturnValue_BeyondEnd is returned.
*/

S_Nv_ReturnValue_t S_Nv_Read(S_Nv_ItemId_t id, uint16_t offset, uint16_t dataLength, void* pData);

/** Returns the item length of an item.

\param id The item to get the length from.
\returns The length of the item, in bytes, as passed during S_Nv_ItemInit(), or 0 if the item doesn't exist.
*/
uint16_t S_Nv_ItemLength(S_Nv_ItemId_t id);

/** Deletes an item from non-volatile storage.

\param id The item to delete.
\returns S_Nv_ReturnValue_Ok, S_Nv_ReturnValue_DoesntExist or S_Nv_ReturnValue_PowerSupplyTooLow.
*/
S_Nv_ReturnValue_t S_Nv_Delete(S_Nv_ItemId_t id);

/** Erases all items (optionally except the persistent ones) from non-volatile storage.

\param includingPersistentItems Whether to also erase the peristent items.
\returns S_Nv_ReturnValue_Ok or S_Nv_ReturnValue_PowerSupplyTooLow.

The persistent items should typically never be erased in an application!
*/
S_Nv_ReturnValue_t S_Nv_EraseAll(bool includingPersistentItems);

/** This will check whether the item is found in the storage area.

\param id - Id of the item to be checked.
\returns true or false
*/
bool S_Nv_IsItemAvailable(S_Nv_ItemId_t id);

/** Sets a function to check the power supply.

\param pf A pointer to a function that S_Nv uses to check the power supply.

If the power supply checking function is not set, the default is to assume that the power
supply is always high enough. This is not suitable for typical applications.
When this function is called again,
*/
void S_Nv_SetPowerSupplyCheckingFunction(S_Nv_PowerSupplyCheckingFunction_t pf);

/** S_Nv Integrity check function.
*/
void S_Nv_SetSystemIntegrityCheckFunction(void (*pf)(void));

/***************************************************************************************************
* END OF C++ DECLARATION WRAPPER
***************************************************************************************************/

#ifdef __cplusplus
}
#endif

#endif // S_NV_H


+ 0
- 71
firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/pds/inc/nv/S_Nv_Bindings.h View File

@@ -1,71 +0,0 @@
/**
* \file
*
* \brief Nv Bindings Interface
*
* Copyright (c) 2019 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/
// implemented interface(s)
#define S_Nv_ItemInit S_Nv_ItemInit_Impl
#define S_Nv_Write S_Nv_Write_Impl
#define S_Nv_Read S_Nv_Read_Impl
#define S_Nv_EraseAll S_Nv_EraseAll_Impl
#define S_Nv_SetPowerSupplyCheckingFunction S_Nv_SetPowerSupplyCheckingFunction_Impl
#define S_Nv_ItemLength S_Nv_ItemLength_Impl
#define S_Nv_Delete S_Nv_Delete_Impl
#define S_Nv_SetPowerSupplyCheckingFunction S_Nv_SetPowerSupplyCheckingFunction_Impl
#define S_Nv_IsItemAvailable S_Nv_IsItemAvailable_Impl

// used interfaces
#if defined(TESTHARNESS)
// ...bind to stubs...
#define D_Nv_Write D_Nv_Stub_Write
#define D_Nv_Read D_Nv_Stub_Read
#define D_Nv_EraseSector D_Nv_Stub_EraseSector
#define D_Nv_IsEmpty D_Nv_Stub_IsEmpty
#define D_Nv_IsEqual D_Nv_Stub_IsEqual

// Use actual timers
#define N_Timer_Stop N_Timer_Stop_Impl
#define N_Timer_Start16 N_Timer_Start16_Impl
#define N_Timer_IsRunning N_Timer_IsRunning_Impl

#else
// ...bind to implementation...
#define D_Nv_Write D_Nv_Write_Impl
#define D_Nv_Read D_Nv_Read_Impl
#define D_Nv_EraseSector D_Nv_EraseSector_Impl
#define D_Nv_IsEmpty D_Nv_IsEmpty_Impl
#define D_Nv_IsEqual D_Nv_IsEqual_Impl

#define N_Timer_Stop N_Timer_Stop_Impl
#define N_Timer_Start16 N_Timer_Start16_Impl
#define N_Timer_IsRunning N_Timer_IsRunning_Impl

#endif
#define S_XNv_SetPowerSupplyCheckingFunction S_XNv_SetPowerSupplyCheckingFunction_Impl

+ 0
- 91
firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/pds/inc/nv/S_Nv_Init.h View File

@@ -1,91 +0,0 @@
/**
* \file S_Nv_init.h
*
* \brief NV component header
*
* Copyright (c) 2019 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/

#ifndef S_NV_INIT_H
#define S_NV_INIT_H

/***************************************************************************************************
* INCLUDE FILES
***************************************************************************************************/


#include <compiler.h>

/***************************************************************************************************
* C++ DECLARATION WRAPPER
***************************************************************************************************/

#ifdef __cplusplus
extern "C" {
#endif

/***************************************************************************************************
* EXPORTED TYPES
***************************************************************************************************/


/***************************************************************************************************
* EXPORTED MACROS AND CONSTANTS
***************************************************************************************************/


/***************************************************************************************************
* EXPORTED FUNCTIONS
***************************************************************************************************/

/** Initializes the internal flash service for early access.
\note It is not required to call this function if the application does not require early access
to internal Nv. Note that the S_Nv component is fully functional after calling S_Nv_EarlyInit(),
but until S_Nv_Init() is called, chances are much higher that the component blocks when a sector
becomes full. Only after S_Nv_Init() is called, compacting the sector is decoupled as much as
possible.
*/
void S_Nv_EarlyInit(void);

/** Initializes the component and tells which items are persistent against S_Nv_EraseAll(FALSE).
*/
void S_Nv_Init(void);

/** The event handler for the component's task.
*/
// bool S_Nv_EventHandler(N_Task_Event_t evt);

/***************************************************************************************************
* END OF C++ DECLARATION WRAPPER
***************************************************************************************************/

#ifdef __cplusplus
}
#endif

#endif // S_NV_INIT_H

+ 0
- 48
firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/pds/inc/nv/S_Nv_Internal.h View File

@@ -1,48 +0,0 @@
/**
* \file S_NvInternal.h
*
* \brief Contains definition for internal use only.
*
* Copyright (c) 2019 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/
#ifndef S_NV_INTERNAL_H
#define S_NV_INTERNAL_H

/******************************************************************************
Includes section
******************************************************************************/
#include <pdsMemIds.h>
#include <pdsDataServer.h>

/***************************************************************************************************
* EXPORTED MACROS AND CONSTANTS
***************************************************************************************************/
/* PDS directories redefinitions */
#define S_NV_PERSISTENT_ITEMS_MEM_ID APP_DIR1_MEM_ID

#endif // S_NV_INTERNAL_H

+ 0
- 386
firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/pds/inc/pdsDataServer.h View File

@@ -1,386 +0,0 @@
/**
* \file pdsDataServer.h
*
* \brief The header file describes the Persistence Data Server interface
*
* Copyright (c) 2019 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/

#ifndef _PERSISTDATASERVER_H
#define _PERSISTDATASERVER_H

/******************************************************************************
Description section
******************************************************************************/
/*
- PERSISTENT DATA SERVER (PDS)
User can specifiy parameters he(she) wants to backup in a non-volatile memory
and restore in case of power failure. This service is provided by Persistent
Data Server (PDS) module.
The BitCloud (TM) stack also uses the same service for its internal structures.

- FILE and FILE DESCRIPTOR
Each item which user wants to backup in a non-volatile memory and restore in
case of power failure is treated as a FILE - actual item value with associated
service information, FILE DESCRIPTOR. Each file could be accessed by it's ID -
a uniq 16-bit value associated with a file. File descriptor keeps information
about item's size and it's displacement in RAM and inside the NV storage.

The PDS_FILE_DESCR() macro is used to initialize descriptor and
PDS_DECLARE_FILE() macro is used to place descriptor to required segment.

- DIRECTORY and DIRECTORY DESCRIPTOR
PDS is able to operate with separate files or with file lists - DIRECTORIES.
Directory nesting is allowed. Each directory should be provided with
DIRECTORY DESCRIPTOR which keeps information about associated items.
Directories could be accessed by 16-bit ID, different from already associated
with files.

The PDS_DECLARE_DIR() macro is used to place a directory to required segment.
*/

/******************************************************************************
Includes section
******************************************************************************/


#include <pdsMemIds.h>
#include <compiler.h>

/* Includings for PDS with wear leveling support */
#ifdef PDS_ENABLE_WEAR_LEVELING
#include <wlPdsTypes.h>
#endif /* PDS_ENABLE_WEAR_LEVELING == 1 */


/******************************************************************************
Types section
******************************************************************************/
#ifndef PDS_ENABLE_WEAR_LEVELING
/*! Type of PDS file or directory unique identifier. */
typedef uint16_t PDS_MemId_t;
typedef enum
{
PDS_SUCCESS, //!< Command completed successfully
} PDS_DataServerState_t;
#endif
/******************************************************************************
Defines section
******************************************************************************/
/* Highlight non-volatile memory writing with onboard LED */
//#define PDS_HIGHLIGHT_WRITING_PROCESS

/* PDS working status flags */
#define PDS_STOPPED_FLAG (1U << 0U)
#define PDS_WRITING_INPROGRESS_FLAG (1U << 1U)
#define PDS_COMMITMENT_OUT_OFF_DATE_FLAG (1U << 2U)


//! \cond internal
/**************************************************************************//**
\brief Persistent Data Server initialization routine.
******************************************************************************/
void PDS_Init(void);
//! \endcond


/******************************************************************************
\brief PDS item initialization routine
******************************************************************************/
void PDS_InitItems(void);

/******************************************************************************
\brief Erases item under security control
******************************************************************************/
void PDS_EraseSecureItems(void);

/**************************************************************************//**
\brief Restores data from non-volatile storage.

\ingroup pds

PDS files not included in the current build configuration will be ignored.
Restoring process will be performed only if all files, expected for actual
configuration, are presented in NV storage.

\param[in] memoryId - an identifier of PDS file or directory to be restored
from non-volatile memory.

\return true, if all expected files have been restored, false - otherwise.
******************************************************************************/
bool PDS_Restore(PDS_MemId_t memoryId);

/**************************************************************************//**
\brief Stores data in non-volatile memory in background, not blocking other
processes.

\ingroup pds

All PDS files which are absent in the current build configuration will be ignored.

\param[in] memoryId - an identifier of PDS file or directory to be stored
in non-volatile memory.

\return True, if storing process has begun, false - otherwise.
******************************************************************************/
bool PDS_Store(PDS_MemId_t memoryId);

/**************************************************************************//**
\brief Deletes data from non-volatile storage except the Persistant items
depending on the parameter passed.

\param[in] includingPersistentItems - deletes persistant items if TRUE
deletes all other items except persistant
items if FALSE

\return - Whether the operation was successful
******************************************************************************/
bool PDS_DeleteAll(bool includingPersistentItems);

/**************************************************************************//**
\brief Stores data in non-volatile memory in a synchronous way -
the application execution will be blocked until the process is completed.

\ingroup pds

All PDS files which are absent in the current build configuration will be ignored.

\param[in] memoryId - an identifier of PDS file or directory to be stored
in non-volatile memory.

\return True, if storing process has been performed successfully, false - otherwise.
******************************************************************************/
bool PDS_BlockingStore(PDS_MemId_t memoryId);

/**************************************************************************//**
\brief Provides PDS with information about memory that should be kept up-to-date
in the non-volatile storage.

\ingroup pds

Data will be saved im non-volatile memory upon specific events.

\param[in] memoryId - an identifier of PDS file or directory to be stored
in non-volatile memory.
******************************************************************************/
void PDS_StoreByEvents(PDS_MemId_t memoryId);

/**************************************************************************//**
\brief Enables periodic commitment of specified persistent items to a
non-volatile storage.

\ingroup pds

\param[in] interval - period of time between successive commitments
\param[in] memoryId - an identifier of PDS file or directory to be stored
in non-volatile memory.
******************************************************************************/
void PDS_StoreByTimer(uint32_t interval, PDS_MemId_t memoryId);

/*****************************************************************************//**
\brief Removes specified file records from NV Storage

\ingroup pds

\param[in] memoryId - an identifier of PDS file or directory to be removed
from NV memory.

\return - Whether the operation was successful
******************************************************************************/
PDS_DataServerState_t PDS_Delete(PDS_MemId_t memoryId);

/**************************************************************************//**
\brief Continue Persistent Data Server operation the same way as before stopping

\ingroup pds
******************************************************************************/
void PDS_Run(void);

/**************************************************************************//**
\brief Stops the Persistent Data Server

\ingroup pds

This doesn't affect a policy created through PDS_StoreByEvent() of
PDS_StoreByTimer() functions. After calling the PDS_Run() function PDS
continues working as before the stop.
******************************************************************************/
void PDS_Stop(void);

/**************************************************************************//**
\brief Checks if the specified PDS file or directory can be restored
from non-volatile memory

\ingroup pds

PDS files not included in the current build configuration will be ignored.

\param[in] memoryId - an identifier of PDS file or directory to be checked.

\return true, if the specified memory can be restored; false - otherwise.
******************************************************************************/
bool PDS_IsAbleToRestore(PDS_MemId_t memoryId);

/**************************************************************************//**
\brief Checks if the specified PDS file or directory can be stored
in non-volatile memory

\ingroup pds

\param[in] memoryId - an identifier of PDS file or directory to be checked.

\return true, if the specified memory can be stored; false - otherwise.
******************************************************************************/
bool PDS_IsAbleToStore(PDS_MemId_t memoryId);

/**************************************************************************//**
\brief Checks if files specified have been restored from non-volatile memory
during the latest restoring procedure

\ingroup pds

\param[in] memoryId - an identifier of PDS file or directory to be checked.

\return true, if the specified file(s) have been restored; false - otherwise.
******************************************************************************/
bool PDS_IsMemoryRestored(PDS_MemId_t memoryId);

/**************************************************************************//**
\brief Marks the specified restored PDS files to be cleared during a reset phase
(during ZDO_StartNetwork() execution)

\ingroup pds

\param[in] memoryId - an identifier of PDS file or directory to be cleared.
******************************************************************************/
void PDS_ClearRestoredMemory(PDS_MemId_t memoryId);

/******************************************************************************
\brief This function is deprecated - use PDS_BlockingStore() instead
******************************************************************************/
void PDS_FlushData(PDS_MemId_t memoryIds);

/******************************************************************************
\brief This function is deprecated - use PDS_Delete() instead.
******************************************************************************/
PDS_DataServerState_t PDS_ResetStorage(PDS_MemId_t memoryId);

/******************************************************************************
\brief Checks, if PDS is busy with file writing, or not.

\return - True, if PDS is busy with file writing; false - otherwise
******************************************************************************/
bool PDS_IsBusy(void);

#ifdef PDS_ENABLE_WEAR_LEVELING
/**************************************************************************//**
\brief Creates a file in NV memory and initializes it with provided pattern.
If file already exists, no action will be performed and PDS_SUCCESS
status will be returned.

\ingroup pds

\param[in] memoryId - an identifier of PDS file to create
\param[in] initialValue - file data initial value; if NULL provided, then file
will be initialized with all 0xFF. The size of this
pattern should be the same as a file size, specified
in file descriptor.

\return operation status
******************************************************************************/
PDS_Status_t PDS_CreateFile(PDS_MemId_t memoryId, void *initialValue);

/**************************************************************************//**
\brief Writes a portion of data to a file. File could have no permanent entity
in RAM.

\ingroup pds

\param[in] memoryId - an identifier of PDS file to update
\param[in] offset - offset of data part within a file
\param[in] dataLength - length of part to write
\param[in] data - data to write

\return operation status
******************************************************************************/
PDS_Status_t PDS_StoreFilePart(PDS_MemId_t memoryId, uint16_t offset,
PDS_DataSize_t dataLength, void *data);

/**************************************************************************//**
\brief Reads a portion of data from a file. File could have no permanent entity
in RAM.

\ingroup pds

\param[in] memoryId - an identifier of PDS file to read
\param[in] offset - offset of data part within a file
\param[in] dataLength - length of part to read
\param[in] data - buffer to place data part in

\return operation status
******************************************************************************/
PDS_Status_t PDS_RestoreFilePart(PDS_MemId_t memoryId, uint16_t offset,
PDS_DataSize_t dataLength, void *data);

#endif /* PDS_ENABLE_WEAR_LEVELING == 1 */

/**************************************************************************//**
\brief Reads data from the user's area of NV memory.

\ingroup pds

\param[in] offset - offset of data in user's area
\param[in] data - pointer to memory, for reading data into
\param[in] length - data length
\param[in] callback - pointer to a callback function; if callback is NULL,
then data will be read syncronously

\return - PDS state as a result of data reading operation
******************************************************************************/
PDS_DataServerState_t PDS_ReadUserData(uint16_t offset, uint8_t *data,
uint16_t length, void (*callback)(void));

/**************************************************************************//**
\brief Writes data to the user's area of NV memory.

\ingroup pds

\param[in] offset - offset to place data in user's area
\param[in] data - pointer to data
\param[in] length - data length
\param[in] callback - pointer to a callback function; if callback is NULL,
then data will be written syncronously

\return - PDS state as a result of data writing operation
******************************************************************************/
PDS_DataServerState_t PDS_WriteUserData(uint16_t offset, uint8_t *data,
uint16_t length, void (*callback)(void));


#endif //#ifndef _PERSISTDATASERVER_H


+ 0
- 42
firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/pds/inc/pdsMemIds.h View File

@@ -1,42 +0,0 @@
/**
* \file pdsMemIds.h
*
* \brief PDS Memory ID defintions
*
* Copyright (c) 2019 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/

#ifndef FLASH_PTR
#define FLASH_PTR
#endif

#if (defined (PDS_ENABLE_WEAR_LEVELING))
#include <wlPdsMemIds.h>
#else

#endif // PDS_ENABLE_WEAR_LEVELING == 1

+ 0
- 55
firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/pds/inc/wl/wlPdsBindings.h View File

@@ -1,55 +0,0 @@
/**
* \file
*
* \brief PDS Bindings
*
* Copyright (c) 2019 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/
// implemented interface(s)
#ifndef PDS_USE_EXTERNAL_FLASH
#define S_Nv_ItemInit S_Nv_ItemInit_Impl
#define S_Nv_Write S_Nv_Write_Impl
#define S_Nv_ItemLength S_Nv_ItemLength_Impl
#define S_Nv_IsItemAvailable S_Nv_IsItemAvailable_Impl
#define S_Nv_Read S_Nv_Read_Impl
#define S_Nv_Delete S_Nv_Delete_Impl
#define S_Nv_EraseAll S_Nv_EraseAll_Impl
#else

#define S_Nv_ItemInit S_Nv_ItemInit_Impl
#define S_Nv_Write S_Nv_Write_Impl
#define S_Nv_ItemLength S_Nv_ItemLength_Impl
#define S_Nv_IsItemAvailable S_Nv_IsItemAvailable_Impl
#define S_Nv_Read S_Nv_Read_Impl
#define S_Nv_Delete S_Nv_Delete_Impl
#define S_Nv_EraseAll S_Nv_EraseAll_Impl

#define S_Nv_Init S_XNv_Init
#define D_Nv_Init D_XNv_Init

#endif

+ 0
- 110
firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/pds/inc/wl/wlPdsMemIds.h View File

@@ -1,110 +0,0 @@
/**
* \file wlPdsMemIds.h
*
* \brief PDS file and directory memory identificators definitions
*
* Copyright (c) 2019 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/

#ifndef _WLPDSMEMIDS_H_
#define _WLPDSMEMIDS_H_

/******************************************************************************
Includes section
******************************************************************************/
#include "compiler.h"

#if defined(PROTOCOL_MESH)
// Required to be consecutive starting from 0
typedef enum {
PDS_NULL_ID = 0, // To be maintained as the first entry
PDS_GENERAL_INFO_ID,
#ifdef MESH_SECURITY
PDS_SECURITY_KEY_ID,
PDS_SECURITY_COUNTER_ID,
#endif
PDS_BLOOM_VALUE_ID,
#if defined(ENABLE_FREQUENCY_AGILITY)
PDS_CHANNEL_UPDATE_ID,
#endif
#if defined(PAN_COORDINATOR)
PDS_COMM_DEVICE_TABLE_ID,
PDS_COORDINATOR_TABLE_ID,
#endif
#if defined(PAN_COORDINATOR) || defined (COORDINATOR)
PDS_DEVICE_TABLE_NONSLEEP_ID,
PDS_DEVICE_TABLE_SLEEP_ID,
PDS_ROUTE_TABLE_COORD_ID,
PDS_ROUTE_TABLE_HOP_ID,
#endif
PDS_MAX_ID // To be maintained as the last entry
} miwi_mesh_pds_id_t;

#else
// Required to be consecutive starting from 0
typedef enum {
PDS_NULL_ID = 0, // To be maintained as the first entry
PDS_OUTGOING_FRAME_COUNTER_ID,
PDS_PANID_ID,
PDS_CURRENT_CHANNEL_ID,
PDS_CONNECTION_MODE_ID,
PDS_CONNECTION_TABLE_ID,
PDS_EDC_ID,
PDS_MAX_ID // To be maintained as the last entry
} miwi_p2pstar_pds_id_t;

#endif
/* Total files and directories amount supported by PDS */
#define PDS_ITEM_AMOUNT PDS_MAX_ID
#define PDS_DIRECTORIES_AMOUNT 1
#define PDS_ITEM_IDS_AMOUNT (PDS_ITEM_AMOUNT + PDS_DIRECTORIES_AMOUNT)

#define PDS_ITEM_MASK_SIZE (PDS_ITEM_AMOUNT / 8U + (PDS_ITEM_AMOUNT % 8U ? 1U : 0U))

/* Directory mask */
#define PDS_DIRECTORY_MASK 0x4000U
#define MIWI_ALL_MEMORY_MEM_ID 0x4001U

#define PDS_ALL_EXISTENT_MEMORY 0x4002U



/******************************************************************************
Types section
******************************************************************************/


/*! Type of PDS file or directory unique identifier. */
typedef uint16_t PDS_MemId_t;

/* Memory identifier record pointer */
typedef const PDS_MemId_t * PDS_MemIdRec_t;

#endif // _WLPDSMEMIDS_H_
/* eof wlPdsMemIds.h */


+ 0
- 66
firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/pds/inc/wl/wlPdsTaskManager.h View File

@@ -1,66 +0,0 @@
/**
* \file wlPdsTaskManager.h
*
* \brief PDS task manager interface.
*
* Copyright (c) 2019 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/

#ifndef _WLPDSTASKMANAGER_H_
#define _WLPDSTASKMANAGER_H_
/******************************************************************************
Includes section
******************************************************************************/

#include <compiler.h>

/******************************************************************************
Types section
******************************************************************************/
/* PDS task identifiers */
typedef enum _PdsTaskId_t
{
PDS_STORE_ITEM_TASK_ID,
PDS_TASKS_AMOUNT
} PdsTaskId_t;

/******************************************************************************
Prototypes section
******************************************************************************/
/******************************************************************************
\brief Posts PDS task

\param[in] taskId - id of a task
******************************************************************************/
void pdsPostTask(PdsTaskId_t taskId);

void PDS_TaskHandler (void);

#endif /* _WLPDSTASKMANAGER_H_ */
/* eof wlPdsTaskManager.h */


+ 0
- 61
firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/pds/inc/wl/wlPdsTypes.h View File

@@ -1,61 +0,0 @@
/**
* \file wlPdsTypes.h
*
* \brief PDS types declaration.
*
* Copyright (c) 2019 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/
#ifndef _WLPDSTYPES_H_
#define _WLPDSTYPES_H_

/******************************************************************************
Includes section
******************************************************************************/

#include <wlPdsTypesConverter.h>
#include <compiler.h>

/******************************************************************************
Definitions section
******************************************************************************/
#define NO_FILE_MARKS 0U

/******************************************************************************
Types section
******************************************************************************/
typedef enum
{
PDS_SUCCESS, //!< Command completed successfully
} PDS_DataServerState_t;

typedef PDS_DataServerState_t PDS_Status_t;

typedef uint16_t PDS_DataSize_t;

#endif // _WLPDSTYPES_H_
// eof wlPdsTypes.h

+ 0
- 237
firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/pds/inc/wl/wlPdsTypesConverter.h View File

@@ -1,237 +0,0 @@
/**
* \file wlPdsTypesConverter.h
*
* \brief PDS types convertions definition
*
* Copyright (c) 2019 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/
#ifndef _WLPDS_TYPESCONVERTER
#define _WLPDS_TYPESCONVERTER

/******************************************************************************
Includes section
******************************************************************************/

#include <S_Nv.h>
#include <pdsMemIds.h>
#include <compiler.h>

/******************************************************************************
Types section
******************************************************************************/
typedef struct
{
uint64_t extendedAddress;
uint32_t channelMap;
uint16_t panId;
uint16_t networkAddress;
uint8_t logicalChannel;
uint8_t capabilityInfo;
uint8_t nwkSecurityLevel;
} MeshGeneralInfotMem_t;

typedef struct
{
S_Nv_ItemId_t itemId;
uint16_t itemSize;
void *itemData;
void (*filler)(void);
uint8_t flags;
} ItemIdToMemoryMapping_t;

typedef struct
{
PDS_MemIdRec_t list;
uint16_t filesCount;
PDS_MemId_t memoryId;
} PDS_DirDescr_t;

/* Directory descriptor record pointer */
typedef const PDS_DirDescr_t *PDS_DirDescrRec_t;

/******************************************************************************
Definitions section
******************************************************************************/
#ifndef FILE_TO_ITEM_MAPPING
#define FILE_TO_ITEM_MAPPING
#endif

#define NO_ITEM_FLAGS 0x00U
#define SIZE_MODIFICATION_ALLOWED 0x01U
#define ITEM_UNDER_SECURITY_CONTROL 0x02U

#if defined(PROTOCOL_MESH)
#define GENERAL_INFO_ITEM_SIZE (sizeof(MeshGeneralInfotMem_t))
#define PDS_SECURITY_KEY_ITEM_SIZE (SECURITY_KEY_SIZE)
#define PDS_SECURITY_COUNTER_ITEM_SIZE (sizeof(API_UINT32_UNION))
#define PDS_BLOOM_VALUE_ITEM_SIZE (BLOOM_FILTER_SIZE)
#define PDS_CHANNEL_UPDATE_ITEM_SIZE (sizeof(uint8_t))
#define PDS_COMM_DEVICE_TABLE_ITEM_SIZE (sizeof(CommDeviceTable_t))
#define PDS_COORDINATOR_TABLE_ITEM_SIZE (sizeof(CoordinatorTable_t))
#define PDS_DEVICE_TABLE_NONSLEEP_ITEM_SIZE (sizeof(DeviceTable_t))
#define PDS_DEVICE_TABLE_SLEEP_ITEM_SIZE (sizeof(SleepDeviceTable_t))
#define PDS_ROUTE_TABLE_COORD_ITEM_SIZE (sizeof(CoordRouteTable_t))
#define PDS_ROUTE_TABLE_HOP_ITEM_SIZE (sizeof(CoordHopCount_t))
#else
#define PDS_OUTGOING_FRAME_COUNTER_ITEM_SIZE (sizeof(API_UINT32_UNION))
#define PDS_PANID_ITEM_SIZE (sizeof(API_UINT16_UNION))
#define PDS_CURRENT_CHANNEL_ITEM_SIZE (sizeof(uint8_t))
#define PDS_CONNECTION_MODE_ITEM_SIZE (sizeof(uint8_t))
#define PDS_CONNECTION_TABLE_ITEM_SIZE (sizeof(CONNECTION_ENTRY))
#define PDS_EDC_ITEM_SIZE (sizeof(uint8_t))
#if defined (PROTOCOL_STAR)
#define PDS_ROLE_ITEM_SIZE (sizeof(uint8_t))
#define PDS_MYINDEX_ITEM_SIZE (sizeof(uint8_t))
#endif
#endif

#define ITEM_ID_TO_MEM_MAPPING(item, size, pointer, func, flag) \
{.itemId = item, .itemSize = size, .itemData = pointer, .filler = func, .flags = flag}

/* PDS item declaration */
#define PDS_DECLARE_ITEM(item, size, pointer, func, flag) \
PDS_FF_OBJECT(ItemIdToMemoryMapping_t pds_ff_##item) = \
ITEM_ID_TO_MEM_MAPPING(item, size, pointer, func, flag);


#ifdef FILE_TO_ITEM_MAPPING
#define PDS_DECLARE_FILE(id, dataSize, ramAddr, fileMarks) \
PDS_DECLARE_ITEM(id, dataSize, ramAddr, NULL, 0x00)
#else
#define PDS_DECLARE_FILE(id, dataSize, ramAddr, fileMarks)
#endif

#ifdef __IAR_SYSTEMS_ICC__
/* Declaration to place object to PDS_FF (files) segment in MCU Flash */
#define PDS_FF_OBJECT(object) \
_Pragma("location=\"PDS_FF\"") __root PROGMEM_DECLARE (object)
/* Declaration to place object to PDS_FD (directories) segment in MCU Flash */
#define PDS_DECLARE_DIR(object) \
_Pragma("location=\"PDS_FD\"") __root PROGMEM_DECLARE (object)
#elif __GNUC__
#define PDS_FF_OBJECT(object) \
__attribute__((__section__(".pds_ff"))) const object
#define PDS_DECLARE_DIR(object) \
__attribute__((__section__(".pds_fd"))) const object
#else
#error "Unsupported compiler"
#endif

#ifdef __IAR_SYSTEMS_ICC__
#pragma segment="PDS_FF"
#define PDS_FF_START (ItemIdToMemoryMapping_t *) __sfb("PDS_FF")
#define PDS_FF_END (ItemIdToMemoryMapping_t *) __sfe("PDS_FF")
#define PDS_FF_SIZE __sfs("PDS_FF")
#pragma segment="PDS_FD"
#define PDS_FD_START (PDS_DirDescr_t *) __sfb("PDS_FD")
#define PDS_FD_END (PDS_DirDescr_t *) __sfe("PDS_FD")
#define PDS_FD_SIZE __sfs("PDS_FD")
#elif __GNUC__
#define PDS_FF_START (ItemIdToMemoryMapping_t *) &__pds_ff_start
#define PDS_FF_END (ItemIdToMemoryMapping_t *) &__pds_ff_end
#define PDS_FF_SIZE (&__pds_ff_end - &__pds_ff_start)
#define PDS_FD_START (PDS_DirDescrRec_t) &__pds_fd_start
#define PDS_FD_END (PDS_DirDescrRec_t) &__pds_fd_end
#define PDS_FD_SIZE (&__pds_fd_end - &__pds_fd_start)
#else
#error "Unsupported compiler"
#endif

/******************************************************************************
Extern section
******************************************************************************/
extern MeshGeneralInfotMem_t genInfoMem;

#ifdef __GNUC__
extern uint32_t __pds_ff_start;
extern uint32_t __pds_ff_end;
extern uint32_t __pds_fd_start;
extern uint32_t __pds_fd_end;
#endif /* __GNUC__ */

/******************************************************************************
Prototypes section
******************************************************************************/
/******************************************************************************
\brief Checks whether item is under security control

\param[in] id - item id

\returns true if item is under security control, false - otherwise
******************************************************************************/
bool pdsIsItemUnderSecurityControl(S_Nv_ItemId_t id);

/******************************************************************************
\brief Updates BC parameters after restoring taking into account possible size
changes

\param[in] id - item id;
\param[in] data - pointer to data;
\param[in] size - current item size;
\param[in] oldSize - last size of item

returns true if memory was updated successfully, false - otherwise
******************************************************************************/
bool pdsUpdateMemory(S_Nv_ItemId_t id, void *data, uint16_t size, uint16_t oldSize);

/******************************************************************************
\brief To get the directory descriptor for the given dir ID

\param[in] itemId - item id;
\param[in] dirDescrToGet - pointer to dir descriptor to be loaded;

returns true if descriptor is found out for the given dir ID, false - otherwise
******************************************************************************/
bool pdsGetDirDescr(S_Nv_ItemId_t itemId, PDS_DirDescr_t *dirDescrToGet );

/******************************************************************************
\brief To get the item descriptor for the given item ID

\param[in] itemId - item id;
\param[in] itemDescrToGet - pointer to item descriptor to be loaded;

returns true if descriptor is found out for the given item ID, false - otherwise
******************************************************************************/
bool pdsGetItemDescr(S_Nv_ItemId_t itemId, ItemIdToMemoryMapping_t *itemDescrToGet );

/**************************************************************************//**
\brief Observes which all item id's are stored and raise the event

\ingroup pds

\param[in] memoryId - memoryId which is stored in flash
\return - None
******************************************************************************/
void pdsDataStoreIndicator(PDS_MemId_t memoryId);
/******************************************************************************
\brief Fills General Information
******************************************************************************/
void fillGeneralInformation(void);
#endif // _WLPDS_TYPESCONVERTER
/* eof wlPdsTypesConverter.h */

+ 0
- 262
firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/pds/src/nv/D_Nv.c View File

@@ -1,262 +0,0 @@
/**
* \file D_Nv.c
*
* \brief NV component implementation.
*
* Copyright (c) 2019 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/

#if PDS_ENABLE_WEAR_LEVELING

/******************************************************************************
Includes section
******************************************************************************/
#include <D_Nv_Bindings.h>
#include <D_Nv.h>
#include <D_Nv_Init.h>
#include "nvm.h"
#include "common_nvm.h"
#include "compiler.h"
#include "system_interrupt.h"
#include "string.h"
#include "assert.h"

/******************************************************************************
Definitions section
******************************************************************************/
#define COMPID "D_Nv"

#ifdef __IAR_SYSTEMS_ICC__
#pragma segment="D_NV_MEMORY"
#define D_NV_MEMORY_START ((uint32_t)__sfb("D_NV_MEMORY"))
// Location of last memory element, NOT the first memory location after it
#define D_NV_MEMORY_END ((uint32_t)__sfe("D_NV_MEMORY") - 1U)
#elif __GNUC__
#define D_NV_MEMORY_START (uint32_t)&__d_nv_mem_start
#define D_NV_MEMORY_END (((uint32_t)&__d_nv_mem_end) - 1U)
#else
#error "Unsupported compiler"
#endif

/******************************************************************************
Extern section
******************************************************************************/
#ifdef __GNUC__
extern uint32_t __d_nv_mem_start;
extern uint32_t __d_nv_mem_end;
#endif

/***************************************************************************************************
* LOCAL FUNCTION DECLARATIONS
***************************************************************************************************/
static bool CompareData(uint8_t sector, uint16_t offset, uint8_t *pBuffer, D_Nv_Size_t numberOfBytes);
// The Callback function to handle system integrity checks
static void (*s_pfSystemCheckCallback)(void) = NULL;

/******************************************************************************
Implementations section
******************************************************************************/
/** Initializes the component -- checks that parameters are correct.
*/
void D_Nv_Init(void)
{
// Ensure that the memory range starts on a page boundary
assert ((D_NV_MEMORY_START % NVMCTRL_ROW_SIZE) == 0U);
// Ensure that sector size is an integer number of pages
assert((D_NV_SECTOR_SIZE % NVMCTRL_ROW_SIZE) == 0U);
// Ensure that segment is as large as we need
assert((D_NV_MEMORY_END - D_NV_MEMORY_START + 1U) == D_NV_MEMORY_SIZE);
}

/** The function to set system integrity check callback function */
void D_Nv_SetSystemIntegrityCheckFunction(void (*pf)(void))
{
/* Set callback function */
s_pfSystemCheckCallback = pf;
}

/** Read bytes from the internal NV.
\param sector The sector to use (0..D_NV_SECTOR_COUNT)
\param offset The offset to start reading at
\param[out] pBuffer The start address of the buffer to store the read data to
\param numberOfBytes The number of bytes to read
\note offset+numberOfBytes must be <= D_NV_SECTOR_SIZE (meaning sector crossing is not permitted)
*/
void D_Nv_Read(uint8_t sector, uint16_t offset, uint8_t *pBuffer, D_Nv_Size_t numberOfBytes)
{
uint32_t address = D_NV_MEMORY_START + (uint32_t)(sector - D_NV_FIRST_SECTOR) * D_NV_SECTOR_SIZE + offset;

assert(address <= D_NV_MEMORY_END);
assert((address + numberOfBytes) <= (D_NV_MEMORY_END + 1U));
assert((offset + numberOfBytes) <= D_NV_SECTOR_SIZE);

memcpy(pBuffer, (uint8_t FLASH_PTR *)address, numberOfBytes);
}

/** Write bytes to the internal NV.
\param sector The sector to use (0..D_NV_SECTOR_COUNT)
\param offset The offset to start writing to
\param[in] pBuffer The start address of the buffer that contains the data to write
\param numberOfBytes The number of bytes to write
\note offset+numberOfBytes must be <= D_NV_SECTOR_SIZE (meaning sector crossing is not permitted)
\note pBuffer cannot be const because it is passed to HAL_FillFlashPageBuffer()
*/
void D_Nv_Write(uint8_t sector, uint16_t offset, uint8_t *pBuffer, D_Nv_Size_t numberOfBytes)
{
uint32_t address = D_NV_MEMORY_START + (uint32_t)(sector - D_NV_FIRST_SECTOR) * D_NV_SECTOR_SIZE + offset;
uint16_t pageOffset;
uint32_t pageStart;
D_Nv_Size_t numberOfPageBytes;
uint8_t page_buf[NVMCTRL_PAGE_SIZE];
enum status_code error_code = STATUS_OK;

assert(numberOfBytes);
assert(address <= D_NV_MEMORY_END);
assert((address + numberOfBytes) <= (D_NV_MEMORY_END + 1U));
assert((offset + numberOfBytes) <= D_NV_SECTOR_SIZE);

// Let's check the system integrity before accessing the flash chip to prevent NV corruption
if (s_pfSystemCheckCallback != NULL)
{
s_pfSystemCheckCallback();
}

pageOffset = address % NVMCTRL_PAGE_SIZE;
pageStart = address - pageOffset;
numberOfPageBytes = MIN((NVMCTRL_PAGE_SIZE - pageOffset), numberOfBytes);

memset (page_buf, 0xFF, NVMCTRL_PAGE_SIZE);
memcpy (&page_buf[pageOffset], pBuffer, numberOfPageBytes);

system_interrupt_enter_critical_section();
do {
error_code = nvm_write_buffer(pageStart, page_buf, NVMCTRL_PAGE_SIZE);
} while (error_code == STATUS_BUSY);
system_interrupt_leave_critical_section();

numberOfBytes -= numberOfPageBytes;
address += numberOfPageBytes;
pBuffer += numberOfPageBytes;

while (0U < numberOfBytes)
{
numberOfPageBytes = MIN(NVMCTRL_PAGE_SIZE, numberOfBytes);

memset (page_buf, 0xFF, NVMCTRL_PAGE_SIZE);
memcpy (&page_buf[pageOffset], pBuffer, numberOfPageBytes);

system_interrupt_enter_critical_section();
do {
error_code = nvm_write_buffer(address, page_buf, NVMCTRL_PAGE_SIZE);
} while (error_code == STATUS_BUSY);
system_interrupt_leave_critical_section();

numberOfBytes -= numberOfPageBytes;
address += numberOfPageBytes;
pBuffer += numberOfPageBytes;
}
}

/** Erases a sector of the internal NV.
\param sector The sector to erase (0..D_NV_SECTOR_COUNT)
*/
void D_Nv_EraseSector(uint8_t sector)
{
uint32_t address = D_NV_MEMORY_START + (uint32_t)(sector - D_NV_FIRST_SECTOR) * D_NV_SECTOR_SIZE;

address &= ~(NVMCTRL_ROW_SIZE - 1);

assert(address <= D_NV_MEMORY_END);

for (uint8_t i = 0U; i < (D_NV_SECTOR_SIZE / NVMCTRL_ROW_SIZE); i++)
{
nvm_erase_row (address);
address += NVMCTRL_ROW_SIZE;
}

}

/** Compare bytes with contents of the internal NV.
\param sector The sector to use (0..D_NV_SECTOR_COUNT)
\param offset The offset to start comparing with
\param[in] pBuffer If NULL then read buffer will be compared with 0xFF
Otherwise it is the start address of the buffer that contains the data to compare with
\param numberOfBytes The number of bytes to compare
\note offset+numberOfBytes must be <= D_NV_SECTOR_SIZE (meaning sector crossing is not permitted)
*/
static bool CompareData(uint8_t sector, uint16_t offset, uint8_t *pBuffer, D_Nv_Size_t numberOfBytes)
{
uint32_t address = D_NV_MEMORY_START + (uint32_t)(sector - D_NV_FIRST_SECTOR) * D_NV_SECTOR_SIZE + offset;
uint8_t buffer[16U];

assert(numberOfBytes);
assert(address <= D_NV_MEMORY_END);
assert((address + numberOfBytes) <= (D_NV_MEMORY_END + 1U));
assert((offset + numberOfBytes) <= D_NV_SECTOR_SIZE);

while(numberOfBytes)
{
uint16_t bytesToRead = MIN(sizeof(buffer), numberOfBytes);

memcpy(buffer, (uint8_t FLASH_PTR *)address, bytesToRead);
for (uint8_t i = 0U; i < bytesToRead; i++)
if (buffer[i] != ((pBuffer != NULL) ? *(pBuffer++) : 0xFF))
return false;

numberOfBytes -= bytesToRead;
address += bytesToRead;
}

return true;
}

/** Checks if the requested range is empty (containing all 0xFF).
\param sector The sector to use (0..D_NV_SECTOR_COUNT)
\param offset The start offset to check
\param numberOfBytes The number of bytes to check
\returns true if the range is empty, FALSE otherwise.
\note Sector crossing is not permitted
*/
bool D_Nv_IsEmpty(uint8_t sector, uint16_t offset, D_Nv_Size_t numberOfBytes)
{
return CompareData(sector, offset, NULL, numberOfBytes);
}

/** Compare bytes with contents of the internal NV.
\param sector The sector to use (0..D_NV_SECTOR_COUNT)
\param offset The offset to start comparing with
\param[in] pBuffer The start address of the buffer that contains the data to compare with
\param numberOfBytes The number of bytes to compare
\note offset+numberOfBytes must be <= D_NV_SECTOR_SIZE (meaning sector crossing is not permitted)
*/
bool D_Nv_IsEqual(uint8_t sector, uint16_t offset, uint8_t *pBuffer, D_Nv_Size_t numberOfBytes)
{
return CompareData(sector, offset, pBuffer, numberOfBytes);
}

#endif

+ 0
- 425
firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/pds/src/nv/External/D_XNv-SamR21.c View File

@@ -1,425 +0,0 @@
/**
* \file D_XNv-SamR21.c
*
* \brief D_XNv Drivers Implementation.
*
* Copyright (c) 2019 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/

#ifdef PDS_USE_EXTERNAL_FLASH

/***************************************************************************************************
* LOCAL INCLUDE FILES
***************************************************************************************************/

#include "D_XNv_Bindings.h"
#include "D_XNv_Init.h"
#include "D_XNv.h"
#include "N_Types.h"
#include <appTimer.h>
#include <atsamr21.h>
#include <atomic.h>
#include <spi.h>

/***************************************************************************************************
* EXTERNAL INCLUDE FILES
***************************************************************************************************/

#if defined(ENABLE_NV_USAGE_SIMULATION)
#include "N_Log.h"
#endif

/***************************************************************************************************
* LOCAL MACROS AND CONSTANTS
***************************************************************************************************/

#define COMPID "D_XNv"

#if defined(ATSAMR21E19A)

#define D_XNV_PAGE_PROGRAM_CMD 0x02u
#define D_XNV_READ_CMD 0x03u
#define D_XNV_READ_STATUS_CMD 0x05u
#define D_XNV_WRITE_ENABLE_CMD 0x06u
// since block size of ext memory is 64 KB which is matching
// with existing implementation, using block erase cmd(0x52)
// for erasing D_Xnv sector
#define D_XNV_SECTOR_ERASE_CMD 0x52u

#define D_XNV_STATUS_WIP 0x01u

#define EXTFLASH_SPI_CS (1 << 23)
#define EXTFLASH_SPI_SCK (1 << 23)
#define EXTFLASH_SPI_MOSI (1 << 22)
#define EXTFLASH_SPI_MISO (1 << 22)
#define EXTFLASH_SPI_HOLD (1 << 0)
#define EXTFLASH_SPI_WRITE_PROCTECT (1 << 12)

#define SC_SPI_DATA SC5_SPI_DATA
#define SC_SPI_INTFLAG SC5_SPI_INTFLAG
#define SC_SPI_INTFLAG_RXC SC5_SPI_INTFLAG_RXC

#else

#define D_XNV_PAGE_PROGRAM_CMD 0x02u
#define D_XNV_READ_CMD 0x03u
#define D_XNV_READ_STATUS_CMD 0x05u
#define D_XNV_WRITE_ENABLE_CMD 0x06u
#define D_XNV_SECTOR_ERASE_CMD 0xD8u

#define D_XNV_STATUS_WIP 0x01u

#define EXTFLASH_SPI_CS (1 << 14)
#define EXTFLASH_SPI_SCK (1 << 9)
#define EXTFLASH_SPI_MOSI (1 << 8)
#define EXTFLASH_SPI_MISO (1 << 15)

#define SC_SPI_DATA SC2_SPI_DATA
#define SC_SPI_INTFLAG SC2_SPI_INTFLAG
#define SC_SPI_INTFLAG_RXC SC2_SPI_INTFLAG_RXC

#endif

/***************************************************************************************************
* LOCAL VARIABLES
***************************************************************************************************/
// The Callback function to handle system integrity checks
static void (*s_pfSystemCheckCallback)(void);

/***************************************************************************************************
* LOCAL FUNCTIONS
***************************************************************************************************/

static inline void Delay100ns(void)
{
// At 48 MHz, 5 nops is just above 100ns.
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
}

static inline void SelectFlash(void)
{
// Let's check the system integrity before acessing the flash chip to prevent NV corruption
if (s_pfSystemCheckCallback != NULL)
{
s_pfSystemCheckCallback();
}

Delay100ns(); // for tSHSL (a.k.a. tCPH or tCEH): >= 100ns
// (also for tCHSL (a.k.a. tCSH): >= 10ns.)

// Make CSn low
PORTA_OUTCLR = EXTFLASH_SPI_CS;

// tSLCH (a.k.a. tCSS or tCS): >= 10ns. But at 48 MHz, 2 different instructions are already 20ns apart.
}

static void DeselectFlash(void)
{
// tCHSH (a.k.a. tCSH or tCH) : >= 10ns. But at 48 MHz, 2 different instructions are already 20ns apart.

// Make CSn high
PORTA_OUTSET = EXTFLASH_SPI_CS;

// tSHCH (a.k.a. tCSS): >= 10ns. But at 48 MHz, 2 different instructions are already 20ns apart.
}

static inline void SpiTxByte(uint8_t value)
{
SC_SPI_DATA = value;
}

static inline void SpiTxWaitReady(void)
{
// Wait for transmission complete
while ( !(SC_SPI_INTFLAG & SC_SPI_INTFLAG_RXC) )
{
// no action
}
}

/** Receive a byte that was transferred during a transmit */
static inline uint8_t SpiRxByte(void)
{
return SC_SPI_DATA;
}

static inline void SpiTxByteAndWait(uint8_t value)
{
ATOMIC_SECTION_ENTER
SpiTxByte(value);
SpiTxWaitReady();
ATOMIC_SECTION_LEAVE
}

static inline void SpiTxByteWaitAndDummyReadByte(uint8_t value)
{
SpiTxByteAndWait(value);
SpiRxByte();
}

/** Wait unit a previous write or sector erase has finished. This can take really long! */
static void WaitUntilWriteFinished(void)
{
uint8_t status;
do
{
SelectFlash();
SpiTxByteWaitAndDummyReadByte(D_XNV_READ_STATUS_CMD);
SpiTxByteAndWait(0u);
status = SpiRxByte();
DeselectFlash();
}
while ( status & D_XNV_STATUS_WIP );
}

static inline uint8_t ReadSingleByte(void)
{
SpiTxByteAndWait(0u);
return SpiRxByte();
}

/***************************************************************************************************
* EXPORTED FUNCTIONS
***************************************************************************************************/
#if defined(ATSAMR21E19A)
void D_XNv_Init(void)
{
/* Configure PIOs for SPI */
PORTA_OUTSET = EXTFLASH_SPI_CS;
PORTA_DIRSET = EXTFLASH_SPI_CS;
PORTB_DIRCLR = EXTFLASH_SPI_SCK | EXTFLASH_SPI_MISO;
PORTA_DIRCLR = EXTFLASH_SPI_MOSI;

/* Configure SPI in peripheral multiplexing */
PORTA_PMUX11 |= PORTA_PMUX7_PMUXE(3);
PORTB_PMUX11 = PORTB_PMUX11_PMUXE(3) | PORTA_PMUX4_PMUXO(3);

/* Pin configurations */
PORTA_PINCFG22 |= PORTA_PINCFG22_PMUXEN; //MOSI A22
PORTB_PINCFG22 |= PORTB_PINCFG22_PMUXEN; //MISO B22
PORTB_PINCFG23 |= PORTB_PINCFG23_PMUXEN; //SCK B23

//Write protect and hold pins have to be pulled up
//to enable and access flash.
PORTA_DIRSET = EXTFLASH_SPI_HOLD;
PORTA_DIRSET = EXTFLASH_SPI_WRITE_PROCTECT;
PORTA_OUTSET = EXTFLASH_SPI_HOLD;
PORTA_OUTSET = EXTFLASH_SPI_WRITE_PROCTECT;

/* Enable the clock of SPI */
PM_APBCMASK |= PM_APBCMASK_SERCOM5;

/* Configure the generic clk settings */
GCLK_CLKCTRL_s.id = 0x19; // enabling clock for SERCOM5
GCLK_CLKCTRL_s.gen = 0;
GCLK_CLKCTRL_s.clken = 1;

/* Reset */
SC5_SPI_CTRLA = SC5_SPI_CTRLA_SWRST;
while((SC5_SPI_SYNCBUSY & SC5_SPI_SYNCBUSY_SWRST));

/* Receiver Enable*/
SC5_SPI_CTRLB = SC5_SPI_CTRLB_RXEN;
while(SC5_SPI_SYNCBUSY & SC5_SPI_SYNCBUSY_CTRLB);

/* Baud Rate Configuration */
SC5_SPI_BAUD = SPI_CLOCK_RATE_2000;

/* setup spi mode master, pad & enable it */
SC5_SPI_CTRLA |= SC5_SPI_CTRLA_MODE(3) | SC5_SPI_CTRLA_DIPO(2)| SC5_SPI_CTRLA_DOPO(3) | SC5_SPI_CTRLA_ENABLE;
while(SC5_SPI_SYNCBUSY & SC5_SPI_SYNCBUSY_ENABLE);

}

#else /* #if defined(ATSAMR21E19A) */
void D_XNv_Init(void)
{
/* Configure PIOs for SPI */
PORTA_OUTSET = EXTFLASH_SPI_CS;
PORTA_DIRSET = EXTFLASH_SPI_CS;
PORTA_DIRCLR = EXTFLASH_SPI_SCK | EXTFLASH_SPI_MISO | EXTFLASH_SPI_MOSI;

/* Configure SPI in peripheral multiplexing */
PORTA_PMUX7 |= PORTA_PMUX7_PMUXO(2);
PORTA_PMUX4 = PORTA_PMUX4_PMUXE(3) | PORTA_PMUX4_PMUXO(3);

/* Pin configurations */
PORTA_PINCFG15 |= PORTA_PINCFG15_PMUXEN; //MISO A15
PORTA_PINCFG8 |= PORTA_PINCFG8_PMUXEN; //MOSI A8
PORTA_PINCFG9 |= PORTA_PINCFG9_PMUXEN; //SCK A9

/* Enable the clock of SPI */
PM_APBCMASK |= PM_APBCMASK_SERCOM2;

/* Configure the generic clk settings */
GCLK_CLKCTRL_s.id = 0x16; // enabling clock for SERCOM2
GCLK_CLKCTRL_s.gen = 0;
GCLK_CLKCTRL_s.clken = 1;

/* Reset */
SC2_SPI_CTRLA = SC2_SPI_CTRLA_SWRST;
while((SC2_SPI_SYNCBUSY & SC2_SPI_SYNCBUSY_SWRST));

/* Receiver Enable*/
SC2_SPI_CTRLB = SC2_SPI_CTRLB_RXEN;
while(SC2_SPI_SYNCBUSY & SC2_SPI_SYNCBUSY_CTRLB);

/* Baud Rate Configuration */
SC2_SPI_BAUD = SPI_CLOCK_RATE_2000;

/* setup spi mode master, pad & enable it */
SC2_SPI_CTRLA |= SC2_SPI_CTRLA_MODE(3) | SC2_SPI_CTRLA_DIPO(3)| SC2_SPI_CTRLA_DOPO(0) | SC2_SPI_CTRLA_ENABLE;
while(SC2_SPI_SYNCBUSY & SC2_SPI_SYNCBUSY_ENABLE);

}
#endif /* #if defined(ATSAMR21E19A) */

/** The function to set system integrity check callback function */
void D_XNv_SetSystemIntegrityCheckFunction(void (*pf)(void))
{
/* Set callback function */
s_pfSystemCheckCallback = pf;
}

void D_XNv_Read_Impl(uint8_t sector, uint16_t offset, uint8_t *pBuffer, D_XNv_Size_t numberOfBytes)
{
WaitUntilWriteFinished();

SelectFlash();
SpiTxByteWaitAndDummyReadByte(D_XNV_READ_CMD);
SpiTxByteWaitAndDummyReadByte(sector);
SpiTxByteWaitAndDummyReadByte((uint8_t)(offset >> 8));
SpiTxByteWaitAndDummyReadByte((uint8_t)offset);

while ( numberOfBytes != 0u )
{
*pBuffer = ReadSingleByte();
pBuffer++;
numberOfBytes--;
}

DeselectFlash();
}

void D_XNv_Write_Impl(uint8_t sector, uint16_t offset, const uint8_t *pBuffer, D_XNv_Size_t numberOfBytes)
{
while (numberOfBytes != 0u)
{
WaitUntilWriteFinished();
SelectFlash();
SpiTxByteWaitAndDummyReadByte(D_XNV_WRITE_ENABLE_CMD);
DeselectFlash();

SelectFlash();
SpiTxByteWaitAndDummyReadByte(D_XNV_PAGE_PROGRAM_CMD);
SpiTxByteWaitAndDummyReadByte(sector);
SpiTxByteWaitAndDummyReadByte((uint8_t)(offset >> 8));
SpiTxByteWaitAndDummyReadByte((uint8_t)offset);
do
{
SpiTxByteWaitAndDummyReadByte(*pBuffer);
pBuffer++;
numberOfBytes--;
offset++;
}
while ( ( numberOfBytes != 0u ) && ( (offset & 0x00FFu) != 0x0000u ) );
DeselectFlash();
}
}

void D_XNv_EraseSector_Impl(uint8_t sector)
{
#if defined(ENABLE_NV_USAGE_SIMULATION)
N_LOG_ALWAYS(("EraseSector,%hu", sector));
#endif
WaitUntilWriteFinished();
SelectFlash();
SpiTxByteWaitAndDummyReadByte(D_XNV_WRITE_ENABLE_CMD);
DeselectFlash();

SelectFlash();
SpiTxByteWaitAndDummyReadByte(D_XNV_SECTOR_ERASE_CMD);
SpiTxByteWaitAndDummyReadByte(sector);
SpiTxByteWaitAndDummyReadByte(0x00u);
SpiTxByteWaitAndDummyReadByte(0x00u);
DeselectFlash();
}

bool D_XNv_IsEmpty_Impl(uint8_t sector, uint16_t offset, D_XNv_Size_t numberOfBytes)
{
WaitUntilWriteFinished();

SelectFlash();
SpiTxByteWaitAndDummyReadByte(D_XNV_READ_CMD);
SpiTxByteWaitAndDummyReadByte(sector);
SpiTxByteWaitAndDummyReadByte((uint8_t)(offset >> 8));
SpiTxByteWaitAndDummyReadByte((uint8_t)offset);

uint8_t andedContent = 0xFFu;
do
{
andedContent &= ReadSingleByte();
numberOfBytes--; // will wrap from 0 to 0xFFFF when numberOfBytes equals 0 on entry
}
while ((andedContent == 0xFFu) && (numberOfBytes != 0u));

DeselectFlash();
return (andedContent == 0xFFu);
}

bool D_XNv_IsEqual_Impl(uint8_t sector, uint16_t offset, uint8_t *pBuffer, D_XNv_Size_t numberOfBytes)
{
bool isEqual = TRUE;

WaitUntilWriteFinished();

SelectFlash();
SpiTxByteWaitAndDummyReadByte(D_XNV_READ_CMD);
SpiTxByteWaitAndDummyReadByte(sector);
SpiTxByteWaitAndDummyReadByte((uint8_t)(offset >> 8));
SpiTxByteWaitAndDummyReadByte((uint8_t)offset);

while ((isEqual) && (numberOfBytes != 0u))
{
isEqual = (*pBuffer == ReadSingleByte());
pBuffer++;

numberOfBytes--;
}

DeselectFlash();

return isEqual;
}


#endif // #ifdef PDS_USE_EXTERNAL_FLASH

+ 0
- 113
firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/pds/src/nv/External/S_Nv-External.c View File

@@ -1,113 +0,0 @@
/**
* \file S_Nv-External.c
*
* \brief S_Nv External Flash Driver implementation
*
* Copyright (c) 2019 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/
#if PDS_ENABLE_WEAR_LEVELING
#ifdef PDS_USE_EXTERNAL_FLASH
/***************************************************************************************************
* LOCAL INCLUDE FILES
***************************************************************************************************/

#include "S_Nv_Bindings.h"

#include "S_Nv_Init.h"
#include "S_Nv_Stack_Ids.h"
#include "S_Nv.h"
#include "pdsDataServer.h"

/***************************************************************************************************
* EXTERNAL INCLUDE FILES
***************************************************************************************************/

#include "N_ErrH.h"
#include "N_Log.h"
#include "N_Util.h"
#include "N_Types.h"

#include "S_XNv_Bindings.h"
#include "S_XNv.h"

/***************************************************************************************************
* LOCAL MACROS AND CONSTANTS
***************************************************************************************************/

#define COMPID "S_Nv-External"

/***************************************************************************************************
* EXPORTED FUNCTIONS
***************************************************************************************************/

S_Nv_ReturnValue_t S_Nv_ItemInit_Impl(S_Nv_ItemId_t id, uint16_t itemLength, void* pDefaultData)
{
return (S_Nv_ReturnValue_t)S_XNv_ItemInit((S_XNv_ItemId_t)id, itemLength, pDefaultData);
}

S_Nv_ReturnValue_t S_Nv_Read_Impl(S_Nv_ItemId_t id, uint16_t offset, uint16_t dataLength, void* pData)
{
return (S_Nv_ReturnValue_t)S_XNv_Read((S_XNv_ItemId_t)id, offset, dataLength, pData);
}

S_Nv_ReturnValue_t S_Nv_Write_Impl(S_Nv_ItemId_t id, uint16_t offset, uint16_t dataLength, void* pData)
{
return (S_Nv_ReturnValue_t)S_XNv_Write((S_XNv_ItemId_t)id, offset, dataLength, pData);
}

S_Nv_ReturnValue_t S_Nv_Delete_Impl(S_Nv_ItemId_t id)
{
return (S_Nv_ReturnValue_t)S_XNv_Delete((S_XNv_ItemId_t)id);
}

uint16_t S_Nv_ItemLength_Impl(S_Nv_ItemId_t id)
{
return S_XNv_ItemLength((S_XNv_ItemId_t)id);
}

S_Nv_ReturnValue_t S_Nv_EraseAll_Impl(bool includingPersistentItems)
{
PDS_EraseSecureItems();
return (S_Nv_ReturnValue_t)S_XNv_EraseAll(includingPersistentItems);
}

void S_Nv_SetPowerSupplyCheckingFunction_Impl(S_Nv_PowerSupplyCheckingFunction_t pf)
{
S_XNv_SetPowerSupplyCheckingFunction(pf);
}

bool S_Nv_IsItemAvailable_Impl(S_Nv_ItemId_t id)
{
return S_XNv_IsItemAvailable((S_XNv_ItemId_t)id);
}

void S_Nv_Init(void)
{
}
#endif //#ifdef PDS_USE_EXTERNAL_FLASH
#endif

+ 0
- 1713
firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/pds/src/nv/External/S_XNv.c
File diff suppressed because it is too large
View File


+ 0
- 1742
firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/pds/src/nv/S_Nv-SamR21.c
File diff suppressed because it is too large
View File


+ 0
- 410
firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/pds/src/wl/wlPdsDataServer.c View File

@@ -1,410 +0,0 @@
/**
* \file wlPdsDataServer.c
*
* \brief PDS data server implementation.
*
* Copyright (c) 2019 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/

#if PDS_ENABLE_WEAR_LEVELING

/******************************************************************************
Includes section
******************************************************************************/
#include <wlPdsMemIds.h>
#include <wlPdsBindings.h>
#include <S_Nv_Init.h>
#include <S_Nv.h>
#include <wlPdsTaskManager.h>
#include <wlPdsTypesConverter.h>
#include "assert.h"
#include <D_Nv_Init.h>
#include <wlPdsTypes.h>
#include <string.h>
#include "pdsDataServer.h"

/******************************************************************************
Defines section
******************************************************************************/
#define EVENT_TO_MEM_ID_MAPPING(event, id) {.eventId = event, .itemId = id}
#define COMPID "wlPdsDataServer"

/******************************************************************************
Types section
******************************************************************************/
typedef struct _EventToMemoryIdMapping_t
{
uint8_t eventId;
S_Nv_ItemId_t itemId;
} EventToMemoryIdMapping_t;

typedef uint8_t PDS_MemMask_t[PDS_ITEM_MASK_SIZE];

/******************************************************************************
Prototypes section
******************************************************************************/

static void pdsStoreItem(S_Nv_ItemId_t id);
static bool pdsRestoreItem(S_Nv_ItemId_t id);
static bool pdsInitItemMask(S_Nv_ItemId_t memoryId, uint8_t *itemMask);

/******************************************************************************
Static variables section
******************************************************************************/

static uint8_t itemsToStore[PDS_ITEM_MASK_SIZE];

/******************************************************************************
Prototype section
******************************************************************************/
void pdsStoreItemTaskHandler(void);


/******************************************************************************
Implementation section
******************************************************************************/
/**************************************************************************//**
\brief Restores data from non-volatile storage

PDS files not included in the current build configuration will be ignored.
Restoring process will be performed only if all files, expected for actual
configuration, are presented in NV storage

\param[in] memoryId - an identifier of PDS file or directory to be restored
from non-volatile memory

\return true, if all expected files have been restored, false - otherwise
******************************************************************************/
bool PDS_Restore(PDS_MemId_t memoryId)
{
uint8_t itemsToRestore[PDS_ITEM_MASK_SIZE] = {0U};
uint8_t i, j;

if (!pdsInitItemMask(memoryId, itemsToRestore))
return false;

for (i = 0U; i < PDS_ITEM_MASK_SIZE; i++)
for (j = 0U; j < 8U; j++)
if (itemsToRestore[i] & (1U << j))
if (!pdsRestoreItem(((S_Nv_ItemId_t)i << 3U) + j))
return false;

return true;
}

/**************************************************************************//**
\brief Deletes data from non-volatile storage

\param[in] memoryId - an identifier of PDS item or directory to be deleted
from non-volatile memory

\return PDS_DataServerState_t - status of PDS delete
******************************************************************************/
PDS_DataServerState_t PDS_Delete(PDS_MemId_t memoryId)
{
uint8_t itemsToDelete[PDS_ITEM_MASK_SIZE] = {0U};
uint8_t i, j;

if (!pdsInitItemMask(memoryId, itemsToDelete))
return false;

for (i = 0U; i < PDS_ITEM_MASK_SIZE; i++)
for (j = 0U; j < 8U; j++)
if (itemsToDelete[i] & (1U << j))
S_Nv_Delete(((S_Nv_ItemId_t)i << 3U) + j);

return PDS_SUCCESS;
}
/**************************************************************************//**
\brief Stores data in non-volatile memory in background, not blocking other
processes.

\ingroup pds

All PDS files which are absent in the current build configuration will be ignored.

\param[in] memoryId - an identifier of PDS file or directory to be stored
in non-volatile memory.

\return True, if storing process has begun, false - otherwise.
******************************************************************************/
bool PDS_Store(PDS_MemId_t memoryId)
{
if (!pdsInitItemMask(memoryId, itemsToStore))
return false;
pdsPostTask(PDS_STORE_ITEM_TASK_ID);

return true;
}

/**************************************************************************//**
\brief Deletes data from non-volatile storage except the Persistant items
depending on the parameter passed.

\param[in] includingPersistentItems - deletes persistant items if TRUE
deletes all other items except persistant
items if false

\return bool - Whether the operation went successfully
******************************************************************************/
bool PDS_DeleteAll(bool includingPersistentItems)
{
if (S_Nv_ReturnValue_Ok == S_Nv_EraseAll(includingPersistentItems))
return true;
else
return false;

}

/******************************************************************************
\brief PDS store item hadler
******************************************************************************/
void pdsStoreItemTaskHandler(void)
{
uint8_t i, j;
static uint8_t i_found, j_found;
bool breakLoop = false;
uint8_t byte_index, bit_index;

// run through all items and store the first item
for (i = 0U, byte_index = i_found + 1; i < PDS_ITEM_MASK_SIZE; i++, byte_index++)
{
byte_index %= PDS_ITEM_MASK_SIZE;

for (j = 0U, bit_index = j_found + 1; j < 8U; j++, bit_index++) {
bit_index %= 8;

if (itemsToStore[byte_index] & (1U << bit_index))
{
itemsToStore[byte_index] &= ~(1U << bit_index);
breakLoop = true;
i_found = byte_index;
j_found = bit_index;
break;
}
}
if (breakLoop)
break;
}

#ifdef PDS_SECURITY_CONTROL_ENABLE
if (!pdsIsItemUnderSecurityControl(((S_Nv_ItemId_t)byte_index << 3U) + bit_index)
&& !S_Nv_IsItemAvailable(((S_Nv_ItemId_t)byte_index << 3U) + bit_index))
#else
if (!S_Nv_IsItemAvailable(((S_Nv_ItemId_t)byte_index << 3U) + bit_index))
#endif
{
ItemIdToMemoryMapping_t itemDescr;

if(pdsGetItemDescr(((S_Nv_ItemId_t)byte_index << 3U) + bit_index, &itemDescr))
{
// Not finding item so initialize it
S_Nv_ReturnValue_t ret;
if (itemDescr.filler)
itemDescr.filler();
ret = S_Nv_ItemInit(((S_Nv_ItemId_t)byte_index << 3U) + bit_index, itemDescr.itemSize, itemDescr.itemData);
assert((S_Nv_ReturnValue_DidNotExist == ret) || (S_Nv_ReturnValue_Ok == ret));
}
}
else
{
// store found item
pdsStoreItem((((S_Nv_ItemId_t)byte_index) << 3U) + bit_index);
}

// check whether there is any item to store
for (i = 0U; i < PDS_ITEM_MASK_SIZE; i++)
if (itemsToStore[i])
{
pdsPostTask(PDS_STORE_ITEM_TASK_ID);
break;
}
}



/**************************************************************************//**
\brief Checks if the specified PDS file or directory can be restored
from non-volatile memory
PDS files not included in the current build configuration will be ignored

\param[in] memoryId - an identifier of PDS file or directory to be checked

\return true, if the specified memory can be restored; false - otherwise
******************************************************************************/
bool PDS_IsAbleToRestore(PDS_MemId_t memoryId)
{
uint8_t itemsToBeAbleRestore[PDS_ITEM_MASK_SIZE] = {0U};
uint8_t i, j;

if (!pdsInitItemMask(memoryId, itemsToBeAbleRestore))
return false;

for (i = 0U; i < PDS_ITEM_MASK_SIZE; i++)
for (j = 0U; j < 8U; j++)
if (itemsToBeAbleRestore[i] & (1U << j))
#ifdef PDS_SECURITY_CONTROL_ENABLE
{
if (pdsIsItemUnderSecurityControl(((S_Nv_ItemId_t)i << 3U) + j))
{
if (!pdsIsSecureItemAvailable(((S_Nv_ItemId_t)i << 3U) + j))
return false;
}
else
{
if (!S_Nv_IsItemAvailable(((S_Nv_ItemId_t)i << 3U) + j))
return false;
}
}
#else
if (!S_Nv_IsItemAvailable(((S_Nv_ItemId_t)i << 3U) + j))
return false;
#endif

return true;
}


/******************************************************************************
\brief Stores item

\param[in] id - item id to store
******************************************************************************/
static void pdsStoreItem(S_Nv_ItemId_t id)
{
ItemIdToMemoryMapping_t itemDescr;

if (pdsGetItemDescr(id, &itemDescr))
{
assert((0U != itemDescr.itemSize) && (NULL != itemDescr.itemData));
if (itemDescr.filler)
itemDescr.filler();

#ifdef PDS_SECURITY_CONTROL_ENABLE
if (pdsIsItemUnderSecurityControl(id))
pdsStoreSecuredItem(id, itemDescr.itemSize, itemDescr.itemData);
else
#endif
{
S_Nv_ReturnValue_t ret;

ret = S_Nv_Write(id, 0U, itemDescr.itemSize, itemDescr.itemData);
assert(ret == S_Nv_ReturnValue_Ok);
//pdsDataStoreIndicator(id);
}
}
}

/******************************************************************************
\brief Restores item

\param[in] id - item id to store

\return true item was restored, false otherwise
******************************************************************************/
static bool pdsRestoreItem(S_Nv_ItemId_t id)
{
ItemIdToMemoryMapping_t itemDescr;
uint16_t oldSize;
if (pdsGetItemDescr(id, &itemDescr))
{
assert((0U != itemDescr.itemSize) && (NULL != itemDescr.itemData));

if (itemDescr.filler)
itemDescr.filler();

#ifdef PDS_SECURITY_CONTROL_ENABLE
if (pdsIsItemUnderSecurityControl(id))
{
/* No update of the item is required since it is taken care in the migration */
return pdsRestoreSecuredItem(id, itemDescr.itemSize, itemDescr.itemData, NULL);
}
else
#endif
{
oldSize = S_Nv_ItemLength(id);
S_Nv_ReturnValue_t ret = S_Nv_ItemInit(id, itemDescr.itemSize, itemDescr.itemData);

assert((S_Nv_ReturnValue_DidNotExist == ret) || (S_Nv_ReturnValue_Ok == ret));

if (S_Nv_ReturnValue_Ok == ret)
if (!pdsUpdateMemory(id, itemDescr.itemData, itemDescr.itemSize, oldSize))
return false;
return (S_Nv_ReturnValue_Ok == ret);
}
}
return false;
}

/******************************************************************************
\brief To init the itemmask for the given memory ID

\param[in] memoryId - memeory id to initialize itemMask
\param[in] itemMask - itemMask to be initialized

\return true itemMask is initialized, false otherwise
******************************************************************************/
static bool pdsInitItemMask(S_Nv_ItemId_t memoryId, uint8_t *itemMask)
{
if (PDS_ALL_EXISTENT_MEMORY == memoryId)
{
memset(itemMask, 0xFFU, PDS_ITEM_MASK_SIZE);
itemMask[0] &= 0xFEU;
}
else if (PDS_DIRECTORY_MASK & memoryId)
{
PDS_DirDescr_t dirDescr;
PDS_MemId_t memId;

if (pdsGetDirDescr(memoryId, &dirDescr))
{
for (uint8_t index=0U; index < dirDescr.filesCount; index++)
{
memcpy(&memId, (void const FLASH_PTR*)(dirDescr.list + index), sizeof(uint16_t));
itemMask[memId / 8U] |= 1U << (memId % 8U);
}
}
else
return false;
}
else
{
itemMask[memoryId / 8] |= 1 << (memoryId % 8);
}

return true;
}

#endif

// eof wlpdsDataServer.c

+ 0
- 99
firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/pds/src/wl/wlPdsInit.c View File

@@ -1,99 +0,0 @@
/**
* \file wlpdsInit.c
*
* \brief Persistent Data Server initialization module
*
* Copyright (c) 2019 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/
#if PDS_ENABLE_WEAR_LEVELING

/******************************************************************************
Includes section
******************************************************************************/
#include <wlPdsBindings.h>
#include <S_Nv_Init.h>
#include <S_Nv.h>
#include "assert.h"
#include <D_Nv_Init.h>
#include <wlPdsTypesConverter.h>
#include <wlPdsMemIds.h>
//#include <flash.h>
#include <pdsDataServer.h>

/******************************************************************************
Definitions section
******************************************************************************/
#define COMPID "pwlPdsInit"

/******************************************************************************
Implementations section
******************************************************************************/
/******************************************************************************
\brief Persistent Data Server initialization routine.
******************************************************************************/


void PDS_Init (void)
{
D_Nv_Init();
S_Nv_Init();
}

/******************************************************************************
\brief PDS item initialization routine
******************************************************************************/
void PDS_InitItems(void)
{
S_Nv_ReturnValue_t ret;
ItemIdToMemoryMapping_t itemDesc;

for (S_Nv_ItemId_t i = 1U; i < PDS_ITEM_AMOUNT; i++)
{
if (pdsGetItemDescr(i, &itemDesc))
{
assert(itemDesc.itemSize);

#ifdef PDS_SECURITY_CONTROL_ENABLE
if (pdsIsItemUnderSecurityControl(i))
{
pdsSecureItemInit(i,itemDesc.itemSize);
}
else
#endif
{
ret = S_Nv_ItemInit(i, itemDesc.itemSize, NULL);
assert((S_Nv_ReturnValue_DidNotExist == ret) || (S_Nv_ReturnValue_Ok == ret));
}
}
}
}

#endif

/* eof pdsInit.c */


+ 0
- 99
firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/pds/src/wl/wlPdsTaskManager.c View File

@@ -1,99 +0,0 @@
/**
* \file wlPdsTaskManager.c
*
* \brief PDS task manager implementation.
*
* Copyright (c) 2019 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/

#if PDS_ENABLE_WEAR_LEVELING

/******************************************************************************
Includes section
******************************************************************************/

#include <wlPdsTaskManager.h>

/******************************************************************************
Types section
******************************************************************************/
typedef uint8_t PdsTaskBitMask_t;
typedef void (*PdsTaskHandler_t)(void);

/******************************************************************************
Prototypes section
******************************************************************************/
void pdsStoreItemTaskHandler(void);

/******************************************************************************
Static variables section
******************************************************************************/
static PdsTaskHandler_t pdsTaskHandlers[PDS_TASKS_AMOUNT] =
{
[PDS_STORE_ITEM_TASK_ID] = pdsStoreItemTaskHandler,
};

static PdsTaskBitMask_t pendingTasks;

/******************************************************************************
Implementation section
******************************************************************************/
/******************************************************************************
\brief Posts PDS task

\param[in] taskId - id of a task
******************************************************************************/

void pdsPostTask(PdsTaskId_t taskId)
{
pendingTasks |= (1U << taskId);
// SYS_PostTask(PDS_TASK_ID);
}

/******************************************************************************
\brief General PDS task handler
******************************************************************************/
void PDS_TaskHandler(void)
{
if (pendingTasks)
{
uint8_t taskId = 0U;

while (!(pendingTasks & (1U << taskId)))
taskId++;

pendingTasks ^= (1U << taskId);
pdsTaskHandlers[taskId]();
}
}

#endif

/* eof wlPdsTaskManager.c */


+ 0
- 182
firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/services/pds/src/wl/wlPdsTypesConverter.c View File

@@ -1,182 +0,0 @@
/**
* \file wlPdsTypesConverter.c
*
* \brief PDS types converter implementation.
*
* Copyright (c) 2019 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/
#if PDS_ENABLE_WEAR_LEVELING

/******************************************************************************
Includes section
******************************************************************************/
#include <wlPdsBindings.h>
#include <wlPdsMemIds.h>
#include <wlPdsTypesConverter.h>
#include <string.h>
#include <assert.h>
//#include "thread_pds.h"
#include "assert.h"
#include "miwi_api.h"

/******************************************************************************
Definitions section
******************************************************************************/
#define COMPID "wlPdsTypesConverter"

/******************************************************************************
Types section
******************************************************************************/


/******************************************************************************
Externals section
******************************************************************************/
MeshGeneralInfotMem_t genInfoMem;

/******************************************************************************
Prototypes section
******************************************************************************/

static void verifyItemSizes (S_Nv_ItemId_t id, uint16_t size, uint16_t oldSize);

/******************************************************************************
Static variables section
******************************************************************************/


/******************************************************************************
Implementation section
******************************************************************************/

/******************************************************************************
\brief Updates BC parameters after restoring taking into account possible size
changes

\param[in] id - item id;
\param[in] data - pointer to data;
\param[in] size - current item size;
\param[in] oldSize - last size of item

returns true if memory was updated successfully, false - otherwise
******************************************************************************/
bool pdsUpdateMemory(S_Nv_ItemId_t id, void *data, uint16_t size, uint16_t oldSize)
{
verifyItemSizes(id, size, oldSize);
switch (id)
{
default:
break;
}

return true;
}

/******************************************************************************
\brief Verifies whether size change is allowed for given item

\param[in] id - item id;
\param[in] size - current item size;
\param[in] oldSize - last size of item
******************************************************************************/
static void verifyItemSizes(S_Nv_ItemId_t id, uint16_t size, uint16_t oldSize)
{
ItemIdToMemoryMapping_t mapItem;

if (size == oldSize)
return;

if (pdsGetItemDescr(id, &mapItem))
{
assert (mapItem.flags & SIZE_MODIFICATION_ALLOWED);
}
}


/******************************************************************************
\brief To get the item descriptor for the given item ID

\param[in] itemId - item id;
\param[in] itemDescrToGet - pointer to item descriptor to be loaded;

returns true if descriptor is found out for the given item ID, false - otherwise
******************************************************************************/
bool pdsGetItemDescr(S_Nv_ItemId_t itemId, ItemIdToMemoryMapping_t *itemDescrToGet )
{
ItemIdToMemoryMapping_t *itemDescrPtr = (ItemIdToMemoryMapping_t *)PDS_FF_START;

/* Calculate raw data size */
for (uint8_t fileIdx = 0; fileIdx < PDS_ITEM_AMOUNT; fileIdx++)
{
ItemIdToMemoryMapping_t itemDescr;

memcpy(&itemDescr, (void const *)itemDescrPtr, sizeof(ItemIdToMemoryMapping_t));

if(itemDescr.itemId == itemId)
{
memcpy(itemDescrToGet, &itemDescr, sizeof(ItemIdToMemoryMapping_t));
return true;
}
itemDescrPtr++;

}
return false;
}
/******************************************************************************
\brief To get the directory descriptor for the given dir ID

\param[in] itemId - item id;
\param[in] dirDescrToGet - pointer to dir descriptor to be loaded;

returns true if descriptor is found out for the given dir ID, false - otherwise
******************************************************************************/
bool pdsGetDirDescr(S_Nv_ItemId_t itemId, PDS_DirDescr_t *dirDescrToGet )
{
PDS_DirDescr_t *dirDescrPtr = (PDS_DirDescr_t *)PDS_FD_START;

/* Calculate raw data size */
for (uint8_t fileIdx = 0; fileIdx < PDS_DIRECTORIES_AMOUNT; fileIdx++)
{
PDS_DirDescr_t dirDescr;

memcpy(&dirDescr, (void const *)dirDescrPtr, sizeof(PDS_DirDescr_t));
if(dirDescr.memoryId == itemId)
{
memcpy(dirDescrToGet, &dirDescr, sizeof(PDS_DirDescr_t));
return true;
}
dirDescrPtr++;
}
return false;
}
#endif

// eof wlPdsTypesConverter.c

+ 0
- 1534
firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/source/mimac/mimac.c
File diff suppressed because it is too large
View File


+ 0
- 624
firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/source/mimac/mimac.h View File

@@ -1,624 +0,0 @@
/**
* \file mimac.h
*
* \brief MAC Layer Abstraction for AT86RFx interface
*
* Copyright (c) 2019 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/
/*
* Support and FAQ: visit <a href="https://www.microchip.com/support/">Microchip Support</a>
*/

#ifndef __MIMAC_AT86RF_H
#define __MIMAC_AT86RF_H

#include "miwi_config.h"
#include "sysTimer.h"


#if defined(PROTOCOL_P2P)
#include "miwi_p2p.h"
#include "miwi_config_p2p.h"
#endif

#define FULL_CHANNEL_MAP 0x3
#define FIRST_CHANNEL_NUM 0
#define LAST_CHANNEL_NUM 25 //38
#define ANUMSUPERFRAMESLOTS (16)
#define ABASESLOTDURATION (60)
#define ABASESUPERFRAMEDURATION (ABASESLOTDURATION * ANUMSUPERFRAMESLOTS )
//SF 7 symbol is 128 chips long
//= 1.024 ms @125kHz modulation bandwidth
//= 512 µs @250kHz modulation bandwidth
//= 256 µs @500kHz modulation bandwidth
#define SYMBOLS_TO_TICKS(a) ((a)*(1*ONE_MILI_SECOND)) //((currentChannel == 0)?((a)*(50*ONE_MICRO_SECOND)):((a)*(25*ONE_MICRO_SECOND)))
#define TICKS_TO_SYMBOLS(a) ((a)/(1*ONE_MILI_SECOND)) // ((currentChannel == 0)?((a)/(50*ONE_MICRO_SECOND)):((a)/(25*ONE_MICRO_SECOND)))

#define CHANNEL_ASSESSMENT_CARRIER_SENSE 0x00
#define CHANNEL_ASSESSMENT_ENERGY_DETECT 0x01

#define POWER_STATE_DEEP_SLEEP 0x00
#define POWER_STATE_OPERATE 0xFF


#define PACKET_TYPE_MASK 0x03
#define BROADCAST_MASK 0x04
#define SECURITY_MASK 0x08
#define REPEAT_MASK 0x10
#define ACK_MASK 0x20
#define DSTPRSNT_MASK 0x40
#define SRCPRSNT_MASK 0x80

#define PACKET_TYPE_DATA 0x00
#define PACKET_TYPE_COMMAND 0x01
#define PACKET_TYPE_ACK 0x02
#define PACKET_TYPE_RESERVE 0x03


// DOM-IGNORE-BEGIN
/*********************************************************************
Overview: Data types for drivers. This will facilitate easy
access smaller chunks of larger data types when sending
or receiving data (for example byte sized send/receive
over parallel 8-bit interface.
*********************************************************************/
// DOM-IGNORE-END


typedef union _DRIVER_UINT8_UNION_
{
uint8_t Val;
struct
{
uint8_t b0:1;
uint8_t b1:1;
uint8_t b2:1;
uint8_t b3:1;
uint8_t b4:1;
uint8_t b5:1;
uint8_t b6:1;
uint8_t b7:1;
} bits;

} DRIVER_UINT8_UNION;



/*- Types ------------------------------------------------------------------*/
typedef struct PHY_DataInd_t {
uint8_t *data; // Pointer to Data
uint8_t size; // Size of the frame
uint8_t lqi; // Link Quality Index
int8_t rssi; // RSSI
} PHY_DataInd_t;


/***************************************************************************
* Parameters to Transmit a Packet
*
* This structure contains configurations to transmit a packet
**************************************************************************/
typedef struct
{
union
{
uint8_t Val;
struct
{
uint8_t packetType : 2; // type of packet. Possible types are
// * PACKET_TYPE_DATA - Data type
// * PACKET_TYPE_COMMAND - Command type
// * PACKET_TYPE_ACK - Acknowledgement type
// * PACKET_TYPE_RESERVE - Reserved type
uint8_t broadcast : 1; // 1: broadcast, 0: unicast
uint8_t secEn : 1; // 1: secure the MAC payload, 0: send plain text
uint8_t repeat : 1; // 1: allow repeaters to forward the message, 0: send message directly
uint8_t ackReq : 1; // 1: acknowledgement required, 0: no acknowldgement
uint8_t destPrsnt : 1; // 1: destination address in the packet, 0: destination address not in the packet
uint8_t sourcePrsnt : 1; // 1: source address in the packet, 0: source address not in the packet
} bits;
} flags;

uint8_t *DestAddress; // destination address
#if defined(IEEE_802_15_4)
bool altDestAddr; // use the alternative network address as destination in the packet
bool altSrcAddr; // use the alternative network address as source in the packet
API_UINT16_UNION DestPANID; // PAN identifier of the destination
#endif

} MAC_TRANS_PARAM;


/***************************************************************************
* Content of the Received Message
*
* This structure contains all information of the received message
**************************************************************************/
typedef struct
{
union
{
uint8_t Val;
struct
{
uint8_t packetType :2; // type of packet. Possible types are
// * PACKET_TYPE_DATA - Data type
// * PACKET_TYPE_COMMAND - Command type
// * PACKET_TYPE_ACK - Acknowledgement type
// * PACKET_TYPE_RESERVE - Reserved type
uint8_t broadcast :1; // 1: broadcast, 0: unicast
uint8_t secEn :1; // 1: secure the MAC payload, 0: send plain text
uint8_t repeat :1; // 1: allow repeaters to forward the message, 0: send message directly
uint8_t ackReq :1; // 1: acknowledgement required, 0: no acknowldgement
uint8_t destPrsnt :1; // 1: destination address in the packet, 0: destination address not in the packet
uint8_t sourcePrsnt :1; // 1: source address in the packet, 0: source address not in the packet
} bits;
} flags;

uint8_t * SourceAddress; // Address of the Sender
uint8_t * Payload; // Pointer to the payload
uint8_t PayloadLen; // Payload size
uint8_t RSSIValue; // RSSI value for the received packet
uint8_t LQIValue; // LQI value for the received packet
#if defined(IEEE_802_15_4)
bool altSourceAddress; // Source address is the alternative network address
API_UINT16_UNION SourcePANID; // PAN ID of the sender
#endif
} MAC_RECEIVED_PACKET;

/***************************************************************************
* Initialization Parameters for MAC
*
* This structure contains parameters in the initialization
**************************************************************************/
typedef struct
{
union
{
uint8_t Val;
struct
{
uint8_t RepeaterMode :1; // 1: Allow to act as repeater, 0: disable repeater function
uint8_t CCAEnable :1; // 1: Enable Clear Channel Assessment, 0: Disable CCA
uint8_t NetworkFreezer :1;
uint8_t PAddrLength :4; // Length of the permanent address, range from 1 to 8.
} bits;
} actionFlags;

uint8_t *PAddress; // Permenet transceiver address

} MACINIT_PARAM;

extern MAC_RECEIVED_PACKET MACRxPacket;

enum mac_set_params
{
MAC_CHANNEL
};

typedef enum mac_set_params mac_set_params_t;

/************************************************************************************
* Function:
* bool MiMAC_Set(mac_set_params_t id, uint8_t *value);
*
* Summary:
* This function sets the values
*
* Description:
* This is the primary MiMAC interface for the protocol layer to
* set the valuesr. for ex:Valid channel
* number are from 0 to 31. For different frequency band, data rate
* and other RF settings, some channels from 0 to 31 might be
* unavailable. Paramater offsetFreq is used to fine tune the center
* frequency across the frequency band. For transceivers that follow
* strict definition of channels, this parameter may be discarded.
* The center frequency is calculated as
* (LowestFrequency + Channel * ChannelGap + offsetFreq)
*
* PreCondition:
* Hardware initialization on MCU has been done.
*
* Parameters:
* set_params id - The identifier of the value to be set
* value - value to be set
*
* Returns:
* A boolean to indicates if channel setting is successful.
*
* Example:
* <code>
* // Set center frequency to be exactly channel 12
* MiMAC_Set(CHANNEL, &channel);
* </code>
*
* Remarks:
* None
*
*****************************************************************************************/
bool MiMAC_Set(mac_set_params_t id, uint8_t *value);


/************************************************************************************
* Function:
* bool MiMAC_SetPower(uint8_t outputPower)
*
* Summary:
* This function set the output power for the RF transceiver
*
* Description:
* This is the primary MiMAC interface for the protocol layer to
* set the output power for the RF transceiver. Whether the RF
* transceiver can adjust output power depends on the hardware
* implementation.
*
* PreCondition:
* MiMAC initialization has been done.
*
* Parameters:
* uint8_t outputPower - RF transceiver output power.
*
* Returns:
* A boolean to indicates if setting output power is successful.
*
* Example:
* <code>
* // Set output power to be 0dBm
* MiMAC_SetPower(TX_POWER_0_DB);
* </code>
*
* Remarks:
* None
*
*****************************************************************************************/
bool MiMAC_SetPower(uint8_t outputPower);


/************************************************************************************
* Function:
* bool MiMAC_SetAltAddress(uint8_t *Address, uint8_t *PANID)
*
* Summary:
* This function set the alternative network address and PAN identifier if
* applicable
*
* Description:
* This is the primary MiMAC interface for the protocol layer to
* set alternative network address and/or PAN identifier. This function
* call applies to only IEEE 802.15.4 compliant RF transceivers. In case
* alternative network address is not supported, this function will return
* FALSE.
*
* PreCondition:
* MiMAC initialization has been done.
*
* Parameters:
* uint8_t * Address - The alternative network address of the host device.
* uint8_t * PANID - The PAN identifier of the host device
*
* Returns:
* A boolean to indicates if setting alternative network address is successful.
*
* Example:
* <code>
* uint16_t NetworkAddress = 0x0000;
* uint16_t PANID = 0x1234;
* MiMAC_SetAltAddress(&NetworkAddress, &PANID);
* </code>
*
* Remarks:
* None
*
*****************************************************************************************/
bool MiMAC_SetAltAddress(uint8_t *Address, uint8_t *PANID);

/************************************************************************************
* Function:
* bool MiMAC_Init(MACINIT_PARAM initValue)
*
* Summary:
* This function initialize MiMAC layer
*
* Description:
* This is the primary MiMAC interface for the protocol layer to
* initialize the MiMAC layer. The initialization parameter is
* assigned in the format of structure MACINIT_PARAM.
*
* PreCondition:
* MCU initialization has been done.
*
* Parameters:
* MACINIT_PARAM initValue - Initialization value for MiMAC layer
*
* Returns:
* A boolean to indicates if initialization is successful.
*
* Example:
* <code>
* MiMAC_Init(initParameter);
* </code>
*
* Remarks:
* None
*
*****************************************************************************************/
bool MiMAC_Init(MACINIT_PARAM initValue);

/************************************************************************************
* Function:
* uint8_t MiMAC_ChannelAssessment(uint8_t AssessmentMode)
*
* Summary:
* This function perform the noise detection on current operating channel
*
* Description:
* This is the primary MiMAC interface for the protocol layer to
* perform the noise detection scan. Not all assessment modes are supported
* for all RF transceivers.
*
* PreCondition:
* MiMAC initialization has been done.
*
* Parameters:
* uint8_t AssessmentMode - The mode to perform noise assessment. The possible
* assessment modes are
* * CHANNEL_ASSESSMENT_CARRIER_SENSE Carrier sense detection mode
* * CHANNEL_ASSESSMENT_ENERGY_DETECT Energy detection mode
*
* Returns:
* A byte to indicate the noise level at current channel.
*
* Example:
* <code>
* NoiseLevel = MiMAC_ChannelAssessment(CHANNEL_ASSESSMENT_CARRIER_SENSE);
* </code>
*
* Remarks:
* None
*
*****************************************************************************************/
uint8_t MiMAC_ChannelAssessment(uint8_t AssessmentMode);

/************************************************************************************
* Function:
* uint32_t MiMAC_SymbolToTicks(uint32_t symbols)
*
* Summary:
* This function converts symbol to ticks
*
* Description:
* This is the primary MiMAC interface for the protocol layer to
* convert symbol to ticks for all RF transceivers.
*
* Parameters:
* uint8_t symbols - The number of symbols to convert
*
* Returns:
* converted value in uint32.
*****************************************************************************************/
uint32_t MiMAC_SymbolToTicks(uint32_t symbols);
/************************************************************************************
* Function:
* uint32_t MiMAC_GetPHYChannelInfo(uint32_t supportedChannelMap)
*
* Summary:
* This function gets the supported channel map
*
* Description:
* This is the primary MiMAC interface for the protocol layer to
* get the supported channel mask
*
* Parameters:
* None
*
* Returns:
* channel map uint32.
*****************************************************************************************/
uint32_t MiMAC_GetPHYChannelInfo(void);


/************************************************************************************
* Function:
* void MiMAC_DiscardPacket(void)
*
* Summary:
* This function discard the current packet received from the RF transceiver
*
* Description:
* This is the primary MiMAC interface for the protocol layer to
* discard the current packet received from the RF transceiver.
*
* PreCondition:
* MiMAC initialization has been done.
*
* Parameters:
* None
*
* Returns:
* None
*
* Example:
* <code>
* if( TRUE == MiMAC_ReceivedPacket() )
* {
* // handle the raw data from RF transceiver
*
* // discard the current packet
* MiMAC_DiscardPacket();
* }
* </code>
*
* Remarks:
* None
*
*****************************************************************************************/
void MiMAC_DiscardPacket(void);


/************************************************************************************
* Function:
* bool MiMAC_ReceivedPacket(void)
*
* Summary:
* This function check if a new packet has been received by the RF transceiver
*
* Description:
* This is the primary MiMAC interface for the protocol layer to
* check if a packet has been received by the RF transceiver. When a packet has
* been received, all information will be stored in the global variable
* MACRxPacket in the format of MAC_RECEIVED_PACKET;
*
* PreCondition:
* MiMAC initialization has been done.
*
* Parameters:
* None
*
* Returns:
* A boolean to indicate if a packet has been received by the RF transceiver.
*
* Example:
* <code>
* if( true == MiMAC_ReceivedPacket() )
* {
* // handle the raw data from RF transceiver
*
* // discard the current packet
* MiMAC_DiscardPacket();
* }
* </code>
*
* Remarks:
* None
*
*****************************************************************************************/
bool MiMAC_ReceivedPacket(void);


/************************************************************************************
* Function:
* BOOL MiMAC_SendPacket( MAC_TRANS_PARAM transParam,
* uint8_t *MACPayload, uint8_t MACPayloadLen,
uint8_t msghandle,MiMacDataConf_callback_t ConfCallback)
*
* Summary:
* This function transmit a packet
*
* Description:
* This is the primary MiMAC interface for the protocol layer to
* send a packet. Input parameter transParam configure the way
* to transmit the packet.
*
* PreCondition:
* MiMAC initialization has been done.
*
* Parameters:
* MAC_TRANS_PARAM transParam - The struture to configure the transmission way
* uint8_t * MACPaylaod - Pointer to the buffer of MAC payload
* uint8_t MACPayloadLen - The size of the MAC payload
* uint8_t msghandle Message handle
* MiMacDataConf_callback_t ConfCallback Callback function to be called once packet is sent
*
* Returns:
* A boolean to indicate if a packet has been received by the RF transceiver.
*
* Example:
* <code>
* MiMAC_SendPacket(transParam, MACPayload, MACPayloadLen, 6, callback);
* </code>
*
* Remarks:
* None
*
*****************************************************************************************/
bool MiMAC_SendPacket(MAC_TRANS_PARAM transParam, uint8_t *MACPayload, uint8_t MACPayloadLen, uint8_t msghandle,
DataConf_callback_t ConfCallback);


/************************************************************************************
* Function:
* bool MiMAC_PowerState(uint8_t PowerState)
*
* Summary:
* This function puts the RF transceiver into sleep or wake it up
*
* Description:
* This is the primary MiMAC interface for the protocol layer to
* set different power state for the RF transceiver. There are minimal
* power states defined as deep sleep and operating mode. Additional
* power states can be defined for individual RF transceiver depends
* on hardware design.
*
* PreCondition:
* MiMAC initialization has been done.
*
* Parameters:
* uint8_t PowerState - The power state of the RF transceiver to be set to.
* The minimum definitions for all RF transceivers are
* * POWER_STATE_DEEP_SLEEP RF transceiver deep sleep mode.
* * POWER_STATE_OPERATE RF transceiver operating mode.
* Returns:
* A boolean to indicate if chaning power state of RF transceiver is successful.
*
* Example:
* <code>
* // Put RF transceiver into sleep
* MiMAC_PowerState(POWER_STATE_DEEP_SLEEP);
* // Put MCU to sleep
* Sleep();
* // Wake up the MCU by WDT, external interrupt or any other means
*
* // Wake up the RF transceiver
* MiMAC_PowerState(POWER_STATE_OPERATE);
* </code>
*
* Remarks:
* None
*
*****************************************************************************************/
bool MiMAC_PowerState(uint8_t PowerState);
bool MiMAC_RetryPacket(void);

#if defined(IEEE_802_15_4)
#undef MY_ADDRESS_LENGTH
#define MY_ADDRESS_LENGTH 8
#endif

#if defined(ENABLE_SECURITY)
extern API_UINT32_UNION IncomingFrameCounter[CONNECTION_SIZE];
#endif

void UserInterruptHandler(void);

void MiMAC_Task(void);

#endif


+ 0
- 337
firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/source/mimac/phy/phy.h View File

@@ -1,337 +0,0 @@
/**
* \file phy.c
*
* \brief Physical Layer Abstraction for AT86RF212B interface
*
* Copyright (c) 2019 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/
/*
* Support and FAQ: visit <a href="https://www.microchip.com/support/">Microchip Support</a>
*/

#ifndef _PHY_H_
#define _PHY_H_

#include "miwi_config.h"
#if defined(PROTOCOL_P2P)
#include "miwi_config_p2p.h" //MiWi Protocol layer configuration file
#endif
#include "radio_interface.h"
#include "miwi_api.h"

#define SEC_LEVEL_CBC_MAC_32 7
#define SEC_LEVEL_CBC_MAC_64 6
#define SEC_LEVEL_CBC_MAC_128 5
#define SEC_LEVEL_CCM_32 4
#define SEC_LEVEL_CCM_64 3
#define SEC_LEVEL_CCM_128 2
#define SEC_LEVEL_CTR 1

/*********************************************************************/
// BANK_SIZE defines the number of packet can be received and stored
// to wait for handling in MiMAC layer.
/*********************************************************************/
#define BANK_SIZE 4

/*********************************************************************/
// SECURITY_KEY_xx defines xxth byte of security key used in the
// block cipher
/*********************************************************************/
#define SECURITY_KEY_00 0x00
#define SECURITY_KEY_01 0x01
#define SECURITY_KEY_02 0x02
#define SECURITY_KEY_03 0x03
#define SECURITY_KEY_04 0x04
#define SECURITY_KEY_05 0x05
#define SECURITY_KEY_06 0x06
#define SECURITY_KEY_07 0x07
#define SECURITY_KEY_08 0x08
#define SECURITY_KEY_09 0x09
#define SECURITY_KEY_10 0x0a
#define SECURITY_KEY_11 0x0b
#define SECURITY_KEY_12 0x0c
#define SECURITY_KEY_13 0x0d
#define SECURITY_KEY_14 0x0e
#define SECURITY_KEY_15 0x0f

/*********************************************************************/
// KEY_SEQUENCE_NUMBER defines the sequence number that is used to
// identify the key. Different key should have different sequence
// number, if multiple security keys are used in the application.
/*********************************************************************/
#define KEY_SEQUENCE_NUMBER 0x00

/*********************************************************************/
// SECURITY_LEVEL defines the security mode used in the application
/*********************************************************************/
#define SECURITY_LEVEL SEC_LEVEL_CCM_32

#define TRX_STATUS_REG 0x01
#define TRX_STATE_REG 0x02
#define TRX_CTRL_0_REG 0x03
#define TRX_CTRL_1_REG 0x04
#define PHY_TX_PWR_REG 0x05
#define PHY_RSSI_REG 0x06
#define PHY_ED_LEVEL_REG 0x07
#define PHY_CC_CCA_REG 0x08
#define CCA_THRES_REG 0x09
#define RX_CTRL_REG 0x0a
#define SFD_VALUE_REG 0x0b
#define TRX_CTRL_2_REG 0x0c
#define ANT_DIV_REG 0x0d
#define IRQ_MASK_REG 0x0e
#define IRQ_STATUS_REG 0x0f
#define VREG_CTRL_REG 0x10
#define BATMON_REG 0x11
#define XOSC_CTRL_REG 0x12
#define RX_SYN_REG 0x15
#define TRX_RPC_REG 0x16
#define XAH_CTRL_1_REG 0x17
#define FTN_CTRL_REG 0x18
#define XAH_CTRL_2_REG 0x19
#define PLL_CF_REG 0x1a
#define PLL_DCU_REG 0x1b
#define PART_NUM_REG 0x1c
#define VERSION_NUM_REG 0x1d
#define MAN_ID_0_REG 0x1e
#define MAN_ID_1_REG 0x1f
#define SHORT_ADDR_0_REG 0x20
#define SHORT_ADDR_1_REG 0x21
#define PAN_ID_0_REG 0x22
#define PAN_ID_1_REG 0x23
#define IEEE_ADDR_0_REG 0x24
#define IEEE_ADDR_1_REG 0x25
#define IEEE_ADDR_2_REG 0x26
#define IEEE_ADDR_3_REG 0x27
#define IEEE_ADDR_4_REG 0x28
#define IEEE_ADDR_5_REG 0x29
#define IEEE_ADDR_6_REG 0x2a
#define IEEE_ADDR_7_REG 0x2b
#define XAH_CTRL_0_REG 0x2c
#define CSMA_SEED_0_REG 0x2d
#define CSMA_SEED_1_REG 0x2e
#define CSMA_BE_REG 0x2f
#define TST_CTRL_DIGI_REG 0x36
#define PHY_TX_TIME_REG 0x3b
#define PHY_PMU_VALUE_REG 0x3b
#define TST_AGC_REG 0x3c
#define TST_SDM_REG 0x3d


#define TRX_CMD_NOP 0
#define TRX_CMD_TX_START 2
#define TRX_CMD_FORCE_TRX_OFF 3
#define TRX_CMD_FORCE_PLL_ON 4
#define TRX_CMD_RX_ON 6
#define TRX_CMD_TRX_OFF 8
#define TRX_CMD_PLL_ON 9
#define TRX_CMD_RX_AACK_ON 22
#define TRX_CMD_TX_ARET_ON 25

#define TRX_STATUS_P_ON 0
#define TRX_STATUS_BUSY_RX 1
#define TRX_STATUS_BUSY_TX 2
#define TRX_STATUS_RX_ON 6
#define TRX_STATUS_TRX_OFF 8
#define TRX_STATUS_PLL_ON 9
#define TRX_STATUS_SLEEP 15
#define TRX_STATUS_BUSY_RX_AACK 17
#define TRX_STATUS_BUSY_TX_ARET 18
#define TRX_STATUS_RX_AACK_ON 22
#define TRX_STATUS_TX_ARET_ON 25
#define TRX_STATUS_RX_ON_NOCLK 28
#define TRX_STATUS_RX_AACK_ON_NOCLK 29
#define TRX_STATUS_BUSY_RX_AACK_NOCLK 30
#define TRX_STATUS_STATE_TRANSITION 31
#define TRX_STATUS_MASK 0x1f

#define PHY_CC_CCA_REG 0x08

#define TRAC_STATUS_SUCCESS 0
#define TRAC_STATUS_SUCCESS_DATA_PENDING 1
#define TRAC_STATUS_SUCCESS_WAIT_FOR_ACK 2
#define TRAC_STATUS_CHANNEL_ACCESS_FAILURE 3
#define TRAC_STATUS_NO_ACK 5
#define TRAC_STATUS_INVALID 7

/* IRQ_MASK, IRQ_STATUS */
#define BAT_LOW 7
#define TRX_UR 6
#define AMI 5
#define CCA_ED_DONE 4
#define TRX_END 3
#define RX_START 2
#define PLL_UNLOCK 1
#define PLL_LOCK 0

/* TRX_CTRL_2 */
#define RX_SAFE_MODE 7
#define OQPSK_SCRAM_EN 5
#define OQPSK_DATA_RATE 0

/* TRX_CTRL_1 */
#define PA_EXT_EN 7
#define IRQ_2_EXT_EN 6
#define TX_AUTO_CRC_ON 5
#define RX_BL_CTRL 4
#define SPI_CMD_MODE 2
#define IRQ_MASK_MODE 1
#define IRQ_POLARITY 0

/* TRX_STATE */
#define TRAC_STATUS 5
#define TRX_CMD 0

/* PHY_RSSI */
#define RX_CRC_VALID 7
#define RND_VALUE 5
#define RSSI 0

/* PHY_STATUS */
#define PHY_STATUS_SUCCESS 0
#define PHY_STATUS_ERROR 1
#define PHY_STATUS_CHANNEL_ACCESS_FAILURE 2
#define PHY_STATUS_NO_ACK 3

/*- Prototypes -------------------------------------------------------------*/
void PHY_Init(void);
void PHY_SetRxState(bool rx);
void PHY_SetChannel(uint8_t channel);
void PHY_SetBand(uint8_t band);
void PHY_SetModulation(uint8_t modulation);
void PHY_SetPanId(uint16_t panId);
void PHY_SetShortAddr(uint16_t addr);
void PHY_SetTxPower(uint8_t txPower);
RadioError_t PHY_SetAttribute(RadioAttribute_t RadioAttr,uint8_t* AttrVal);
RadioError_t PHY_GetAttribute(RadioAttribute_t RadioAttr,uint8_t* AttrVal);
void PHY_Sleep(void);
void PHY_Wakeup(void);
uint8_t PHY_DataReq(uint8_t *data);
void PHY_DataConf(uint8_t status);
void print_rx_message(void);
void CONSOLE_PrintHex(uint8_t toPrint);
void CONSOLE_PutString(char* str);
void PHY_TaskHandler(void);
void PHY_SetIEEEAddr(uint8_t *ieee_addr);
uint16_t PHY_RandomReq(void);
uint8_t PHY_EdReq(void);
void PHY_EncryptReq(uint8_t *text, uint8_t *key);
void PHY_EncryptReqCBC(uint8_t *text, uint8_t *key);
void PHY_DecryptReq(uint8_t *text, uint8_t *key);
bool DataEncrypt(uint8_t *, uint8_t *, API_UINT32_UNION,
uint8_t );
bool DataDecrypt(uint8_t *Payload, uint8_t *PayloadLen, uint8_t *SourceIEEEAddress,
API_UINT32_UNION FrameCounter, uint8_t FrameControl);
void mic_generator (uint8_t *Payloadinfo, uint8_t , uint8_t frame_control , API_UINT32_UNION FrameCounter , uint8_t * Address);
bool validate_mic(void);

typedef union
{
uint8_t Val; // value of interrupts
struct
{
uint8_t RF_TXIF :1; // transmission finish interrupt
uint8_t :2;
uint8_t RF_RXIF :1; // receiving a packet interrupt
uint8_t SECIF :1; // receiving a secured packet interrupt
uint8_t :4;
}bits; // bit map of interrupts
} AT86RF233_IFREG;

typedef union
{
uint8_t Val;
struct
{
uint8_t TX_BUSY : 1;
uint8_t TX_PENDING_ACK : 1;
uint8_t TX_FAIL : 1;
uint8_t RX_SECURITY : 1;
uint8_t RX_IGNORE_SECURITY : 1;
uint8_t RX_BUFFERED : 1;
uint8_t SEC_IF : 1;
} bits;
} RADIO_STATUS;


#define SEC_LEVEL_CBC_MAC_32 7
#define SEC_LEVEL_CBC_MAC_64 6
#define SEC_LEVEL_CBC_MAC_128 5
#define SEC_LEVEL_CCM_32 4
#define SEC_LEVEL_CCM_64 3
#define SEC_LEVEL_CCM_128 2
#define SEC_LEVEL_CTR 1


#if defined(PROTOCOL_P2P)
#define PROTOCOL_HEADER_SIZE 0
#endif

#if defined(ENABLE_SECURITY)

#if SECURITY_LEVEL == 0x01
#define MIC_SIZE 0
#elif (SECURITY_LEVEL == 0x02) || (SECURITY_LEVEL == 0x05)
#define MIC_SIZE 16
#elif (SECURITY_LEVEL == 0x03) || (SECURITY_LEVEL == 0x06)
#define MIC_SIZE 8
#elif (SECURITY_LEVEL == 0x04) || (SECURITY_LEVEL == 0x07)
#define MIC_SIZE 4
#endif

#define RX_PACKET_SIZE (RX_BUFFER_SIZE+PROTOCOL_HEADER_SIZE+MY_ADDRESS_LENGTH+MY_ADDRESS_LENGTH+MIC_SIZE+17)

#if (RX_PACKET_SIZE > 255)
#warning "Maximum application payload RX BUFFER SIZE is 218"
#endif

#else

#define RX_PACKET_SIZE (RX_BUFFER_SIZE+PROTOCOL_HEADER_SIZE+MY_ADDRESS_LENGTH+MY_ADDRESS_LENGTH+12)

#if (RX_PACKET_SIZE > 255)
#warning "Maximum application payload RX BUFFER SIZE is 227"
#endif

#endif

#if RX_PACKET_SIZE > 255
#undef RX_PACKET_SIZE
#define RX_PACKET_SIZE 255
#endif

typedef struct
{
uint8_t PayloadLen;
uint8_t radioRSSI;
uint8_t Payload[RX_PACKET_SIZE];
} RxBuffer_t;

extern RxBuffer_t RxBuffer[];

#endif

+ 0
- 589
firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/source/mimac/phy/sx1276/phy.c View File

@@ -1,589 +0,0 @@
/**
* \file phy.c
*
* \brief Physical Layer Abstraction for AT86RF212B implementation
*
* Copyright (c) 2019 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/
/*
* Support and FAQ: visit <a href="https://www.microchip.com/support/">Microchip Support</a>
*/

#include <string.h>
#include <stdbool.h>
#include <trx_access_1.h>

#include "miwi_config.h"
#if defined(PROTOCOL_P2P)
#include "miwi_config_p2p.h" //MiWi Protocol layer configuration file
#endif

#include "delay.h"
#include "sal.h"
#include "phy.h"

#include "radio_registers_SX1276.h"
#include "radio_driver_hal.h"
#include "radio_interface.h"
#include "power.h"
#include "radio_get_set.h"
#include "radio_driver_SX1276.h"
#include "radio_transaction.h"
#include "stack_common.h"
#include "radio_task_manager.h"

#include "aes_engine.h"

extern void Radio_WritePower(int8_t power);


/*- Definitions ------------------------------------------------------------*/
#define PHY_CRC_SIZE 2

/*- Types ------------------------------------------------------------------*/
typedef enum {
PHY_STATE_INITIAL,
PHY_STATE_IDLE,
PHY_STATE_SLEEP,
PHY_STATE_TX_WAIT_END,
} PhyState_t;

/*- Prototypes -------------------------------------------------------------*/
static void phySetChannel(void);
static void phySetRxState(void);

/*- Variables --------------------------------------------------------------*/
static PhyState_t phyState = PHY_STATE_INITIAL;
static bool phyRxState;
static uint8_t phyBand;
static uint8_t phyChannel;// TODO
static uint8_t phyModulation;
RxBuffer_t RxBuffer[BANK_SIZE];

volatile uint8_t DevPanId[2];
volatile uint8_t DevShortAddress[2];
volatile uint8_t DevIEEEaddr[8];

void radioCallback(RadioCallbackID_t callback, void *param);
/*************************************************************************//**
*****************************************************************************/
void PHY_Init(void)
{
/* Initialize the Radio Hardware */
HAL_RadioInit();
/* Initialize the AES Hardware Engine */
AESInit();
RADIO_Init();
RADIO_SetAttr(RADIO_CALLBACK, (void *)&radioCallback);
RADIO_InitDefaultAttributes();
}


/*************************************************************************//**
*****************************************************************************/
// Set Radio to Receive State
void PHY_SetRxState(bool rx)
{
phyRxState = rx;
phySetRxState();
}

/*************************************************************************//**
*****************************************************************************/
// Set Channel
void PHY_SetChannel(uint8_t channel)
{
phyChannel = channel;
if (PHY_STATE_SLEEP == phyState)
{
PHY_Wakeup();
}
phySetChannel();
}

/*************************************************************************//**
*****************************************************************************/
void PHY_SetBand(uint8_t band)
{
phyBand = band;
phySetChannel();
}

/*************************************************************************//**
*****************************************************************************/
void PHY_SetModulation(uint8_t modulation)
{
phyModulation = modulation;
phySetChannel();
}

/*************************************************************************/


/*****************************************************************************/
void PHY_SetPanId(uint16_t panId)
{
uint8_t *d = (uint8_t *)&panId;
DevPanId[0]=d[0];
DevPanId[1]=d[1];
}

/*************************************************************************//**
*****************************************************************************/


// Set Short Address
void PHY_SetShortAddr(uint16_t addr)
{
uint8_t *d = (uint8_t *)&addr;
DevShortAddress[0]=d[0];
DevShortAddress[1]=d[1];
}

/*************************************************************************//**
*****************************************************************************/

void PHY_SetTxPower(uint8_t txPower)
{
uint8_t reg;
uint8_t PaBoost ;
reg = txPower;

if(reg > 15)
{
PaBoost = ENABLED;
RADIO_SetAttr(PABOOST, (void *)&PaBoost);
}
else
{
PaBoost = DISABLED;
RADIO_SetAttr(PABOOST, (void *)&PaBoost);
reg &= 0x0F ;
}
RADIO_SetAttr(OUTPUT_POWER, &reg);
}

RadioError_t PHY_SetAttribute(RadioAttribute_t RadioAttr,uint8_t* AttrVal)
{
RadioError_t Status;
switch(RadioAttr)
{
case SPREADING_FACTOR:
case BANDWIDTH:
Status = RADIO_SetAttr(RadioAttr,AttrVal);
break;
default:
// Do nothing
Status = ERR_INVALID_REQ;
break;
}
return Status;
}

RadioError_t PHY_GetAttribute(RadioAttribute_t RadioAttr,uint8_t* AttrVal)
{
RadioError_t Status;
switch(RadioAttr)
{
case SPREADING_FACTOR:
case BANDWIDTH:
Status = RADIO_GetAttr(RadioAttr,AttrVal);
break;
default:
// Do nothing
Status = ERR_INVALID_REQ;
break;
}
return Status;
}
/*************************************************************************//**
*****************************************************************************/
// Radio Sleep
void PHY_Sleep(void)
{
if (PHY_STATE_SLEEP != phyState)
{
Radio_WriteMode(MODE_SLEEP, radioConfiguration.modulation, 0);
HAL_TCXOPowerOff();
/* Disable the SPI interface */
HAL_RadioDeInit();
phyState = PHY_STATE_SLEEP;
}
}

/*************************************************************************//**
*****************************************************************************/
// Radio Wake Up
void PHY_Wakeup(void)
{
if (PHY_STATE_SLEEP == phyState)
{
HAL_TCXOPowerOn();
/* Initialize the Radio Hardware */
HAL_RadioInit();
/* Reset the radio */
RADIO_Reset();
Radio_WriteMode(MODE_STANDBY, radioConfiguration.modulation, 0);
phySetRxState();
phyState = PHY_STATE_IDLE;
}
}

/*************************************************************************//**
*****************************************************************************/
extern uint8_t AckReqData;
extern MIWI_TICK DataTxAckTimer;
volatile RadioCallbackID_t callbackBackup;
void radioCallback(RadioCallbackID_t callback, void *param)
{
uint8_t i,RxBank=0xFF;
RadioCallbackParam_t * callbackRx;
callbackBackup = callback;
RadioReceiveParam_t RadioReceiveParam;
callbackRx = param;
int16_t rssi_readVal=0;
Radio_ReadRssi(&rssi_readVal);
switch (callback)
{
case RADIO_TX_DONE_CALLBACK:
case RADIO_TX_TIMEOUT_CALLBACK:
if((!AckReqData)||(callbackRx->status != ERR_NONE))
PHY_DataConf(callbackRx->status); // Need to convert LoRa status to MiWi status
else
DataTxAckTimer.Val = MiWi_TickGet();

RadioReceiveParam.action = RECEIVE_START;
RadioReceiveParam.rxWindowSize = 0;
RADIO_Receive(&RadioReceiveParam);
break;

case RADIO_RX_DONE_CALLBACK:
case RADIO_RX_TIMEOUT_CALLBACK:
for (i = 0; i < BANK_SIZE; i++)
{
if (RxBuffer[i].PayloadLen == 0)
{
RxBank = i;
break;
}
}
callbackRx = (RadioCallbackParam_t *)param;

RxBuffer[RxBank].PayloadLen = callbackRx->RX.bufferLength;
if (RxBuffer[RxBank].PayloadLen < (RX_PACKET_SIZE - 4))
{

//copy all of the data from the FIFO into the TxBuffer, plus RSSI and LQI
//TODO Where are we copying rssi and lqi?
for (i = 0; i <= callbackRx->RX.bufferLength; i++)
{
RxBuffer[RxBank].Payload[i] = callbackRx->RX.buffer[i];
}
}
RxBuffer[RxBank].PayloadLen +=4;
rssi_readVal = radioConfiguration.packetRSSI;
RxBuffer[RxBank].radioRSSI = rssi_readVal;
//If Ack request bit in FCF is set send Ack or Make Radio Receive
if(RxBuffer[RxBank].Payload[0] & 0x20)
{
// Create Ack Packet and send Ack using PHY_DataReq
RadioReceiveParam.action = RECEIVE_STOP;
RadioReceiveParam.rxWindowSize = 0;
RADIO_Receive(&RadioReceiveParam);
}
else
{
RadioReceiveParam.action = RECEIVE_START;
RadioReceiveParam.rxWindowSize = 0;
RADIO_Receive(&RadioReceiveParam);
}
break;
case RADIO_RX_ERROR_CALLBACK:
RadioReceiveParam.action = RECEIVE_START;
RadioReceiveParam.rxWindowSize = 0;
PHY_DataConf(FAILURE);
RADIO_Receive(&RadioReceiveParam);
break;
case RADIO_FHSS_NEXT_FREQ_CALLBACK:
/*TODO : Add api to register function*/
//if(fhssCallback)
//{
//*(uint32_t *)param = fhssCallback();
//}
break;

default:
break;
}
}

uint8_t DataRequestBuffer[255];
uint8_t PHY_DataReq(uint8_t *data)
{
RadioTransmitParam_t RadioTransmitParam;
RadioError_t status;
uint8_t count = 0;
RadioTransmitParam.bufferLen = data[0];
for (count = 0; count < data[0]; count++)
{
DataRequestBuffer[count] = data[1+count];
}
RadioTransmitParam.bufferPtr = (uint8_t *)&DataRequestBuffer;
RadioSetState(RADIO_STATE_IDLE);
phySetChannel();

RadioLBTParams_t localRadioLBTParams;
localRadioLBTParams.lbtScanPeriod = 15;
localRadioLBTParams.lbtThreshold = 255;
localRadioLBTParams.lbtNumOfSamples = 5;
localRadioLBTParams.lbtTransmitOn = 1;
status = RADIO_SetAttr(RADIO_LBT_PARAMS, &localRadioLBTParams);
status = RADIO_Transmit (&RadioTransmitParam);
return (!status);
}

/*************************************************************************//**
*****************************************************************************/
uint16_t PHY_RandomReq(void)
{
uint16_t rnd = 0;

rnd = RADIO_ReadRandom();
phySetRxState();

return rnd;
}

/*************************************************************************//**
*****************************************************************************/
void PHY_EncryptReq(uint8_t *text, uint8_t *key)
{
AESEncode(text,key);
}

void PHY_EncryptReqCBC(uint8_t *text, uint8_t *key)
{
AESEncode(text,key);
}

/*************************************************************************//**
*****************************************************************************/
// Decrypt Block
void PHY_DecryptReq(uint8_t *text, uint8_t *key)
{
AESEncode(text,key);
}


/*************************************************************************//**
*****************************************************************************/
uint8_t PHY_EdReq(void) //TODO datatype int8 or uint8
{
int16_t rssi_value;
Radio_ReadFSKRssi(&rssi_value);
phySetRxState();
return ((uint8_t)rssi_value);
}

/*************************************************************************//**
*****************************************************************************/
static void phySetChannel(void)
{
uint32_t frequncy_set;
if(phyChannel) // Based on channel we need to set frequency
{
switch(phyChannel)
{
//case 0:
//frequncy_set = FREQ_200KHZ;
//break;
//case 1:
//frequncy_set = FREQ_500KHZ;
//break;
//case 2:
//frequncy_set = FREQ_600KHZ;
//break;
//case 3:
//frequncy_set = FREQ_1600KHZ;
//break;
//case 0:
//frequncy_set = FREQ_137000KHZ;
//break;
//case 1:
//frequncy_set = FREQ_175000KHZ;
//break;
//case 2:
//frequncy_set = FREQ_410000KHZ;
//break;
//case 3:
//frequncy_set = FREQ_433050KHZ;
//break;
//case 4:
//frequncy_set = FREQ_433300KHZ;
//break;
//case 5:
//frequncy_set = FREQ_434665KHZ;
//break;
//case 6:
//frequncy_set = FREQ_434790KHZ;
//break;
//case 7:
//frequncy_set = FREQ_525000KHZ;
//break;
//case 8:
//frequncy_set = FREQ_786000KHZ;
//break;
case 0:
frequncy_set = FREQ_862000KHZ;
break;
case 1:
frequncy_set = FREQ_863000KHZ;
break;
case 2:
frequncy_set = FREQ_865000KHZ;
break;
case 3:
frequncy_set = FREQ_866550KHZ;
break;
case 4:
frequncy_set = FREQ_867000KHZ;
break;
case 5:
frequncy_set = FREQ_868100KHZ;
break;
case 6:
frequncy_set = FREQ_869525KHZ;
break;
case 7:
frequncy_set = FREQ_870000KHZ;
break;
case 8:
frequncy_set = FREQ_902300KHZ;
break;
case 9:
frequncy_set = FREQ_903000KHZ;
break;
case 10:
frequncy_set = FREQ_915000KHZ;
break;
case 11:
frequncy_set = FREQ_915200KHZ;
break;
case 12:
frequncy_set = FREQ_915900KHZ;
break;
case 13:
frequncy_set = FREQ_920000KHZ;
break;
case 14:
frequncy_set = FREQ_920900KHZ;
break;
case 15:
frequncy_set = FREQ_921900KHZ;
break;
case 16:
frequncy_set = FREQ_922000KHZ;
break;
case 17:
frequncy_set = FREQ_922100KHZ;
break;
case 18:
frequncy_set = FREQ_923000KHZ;
break;
case 19:
frequncy_set = FREQ_923200KHZ;
break;
case 20:
frequncy_set = FREQ_923300KHZ;
break;
case 21:
frequncy_set = FREQ_925000KHZ;
break;
case 22:
frequncy_set = FREQ_927500KHZ;
break;
case 23:
frequncy_set = FREQ_928000KHZ;
break;
case 24:
frequncy_set = FREQ_928500KHZ;
break;
case 25:
frequncy_set = FREQ_1020000KHZ;
break;
default:
frequncy_set = FREQ_868100KHZ;
break;
}
}
if(RADIO_SetAttr(CHANNEL_FREQUENCY,(void *)&frequncy_set) == 0)
{
}
}

/*************************************************************************//**
*****************************************************************************/
static void phySetRxState(void)
{
RADIO_RxHandler();
}

/*************************************************************************//**
*****************************************************************************/
void PHY_SetIEEEAddr(uint8_t *ieee_addr)
{
uint8_t *ptr_to_reg = ieee_addr;

for (uint8_t i = 0; i < 8; i++)
{
DevIEEEaddr[i] = ptr_to_reg[i];
}
}


/*************************************************************************//**
*****************************************************************************/
// Handle Packet Received
void PHY_TaskHandler(void)
{
if (PHY_STATE_SLEEP == phyState)
{
return;
}
// Handled in DIO interrupts
}

+ 0
- 85
firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/source/miwi_p2p_star/miwi_nvm.h View File

@@ -1,85 +0,0 @@
/**
* \file miwi_nvm.h
*
* \brief MiWi NVM Configuration interface
*
* Copyright (c) 2019 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/
/*
* Support and FAQ: visit <a href="https://www.microchip.com/support/">Microchip Support</a>
*/

#ifndef __MIWI_NVM_H
#define __MIWI_NVM_H

#include "compiler.h"
#include "common_nvm.h"

#if defined(ENABLE_NVM)
#include "miwi_config.h"
#include "miwi_api.h"

COMPILER_PACK_SET(1)
typedef struct nvmParameters{
API_UINT32_UNION nvmOutFrameCounter;
API_UINT16_UNION nvmMyPANID;
uint8_t nvmCurrentChannel;
uint8_t nvmConnMode;
CONNECTION_ENTRY nvmConnectionTable[CONNECTION_SIZE];
uint8_t nvmEdc;
}nvmParameters_t;
COMPILER_PACK_RESET()

extern nvmParameters_t *nvmParam;

#define START_ADDR (((FLASH_ADDR + FLASH_SIZE - 1) - sizeof(nvmParameters_t)) & 0xFFFFFFC0)

#define CONNECTION_ELEMENT_SIZE (MY_ADDRESS_LENGTH + ADDITIONAL_NODE_ID_SIZE + 1)


#define nvmGetMyPANID( x ) nvm_read(INT_FLASH, &(nvmParam->nvmMyPANID), (uint8_t *)x, 2)
#define nvmPutMyPANID( x ) nvm_write(INT_FLASH, &(nvmParam->nvmMyPANID), (uint8_t *)x, 2)

#define nvmGetCurrentChannel( x ) nvm_read(INT_FLASH, &(nvmParam->nvmCurrentChannel), (uint8_t *)x, 1)
#define nvmPutCurrentChannel( x ) nvm_write(INT_FLASH, &(nvmParam->nvmCurrentChannel), (uint8_t *)x, 1)

#define nvmGetConnMode( x ) nvm_read(INT_FLASH, &(nvmParam->nvmConnMode), (uint8_t *)x, 1)
#define nvmPutConnMode( x ) nvm_write(INT_FLASH, &(nvmParam->nvmConnMode), (uint8_t *)x, 1)

#define nvmGetConnectionTable( x ) nvm_read(INT_FLASH, &(nvmParam->nvmConnectionTable), (uint8_t *)x, (uint16_t)CONNECTION_SIZE * sizeof(CONNECTION_ENTRY))
#define nvmPutConnectionTable( x ) nvm_write(INT_FLASH, &(nvmParam->nvmConnectionTable), (uint8_t *)x, (uint16_t)CONNECTION_SIZE * sizeof(CONNECTION_ENTRY))
#define nvmPutConnectionTableIndex(x, y) nvm_write(INT_FLASH, &(nvmParam->nvmConnectionTable[y]), (uint8_t *)x, sizeof(CONNECTION_ENTRY))

#define nvmGetOutFrameCounter( x ) nvm_read(INT_FLASH, &(nvmParam->nvmOutFrameCounter), (uint8_t *)x, 4)
#define nvmPutOutFrameCounter( x ) nvm_write(INT_FLASH, &(nvmParam->nvmOutFrameCounter), (uint8_t *)x, 4);

#define nvmGetMyDC(x) nvm_read(INT_FLASH, &(nvmParam->nvmEdc), (uint8_t *)x, 1)
#define nvmPutMyDC(x) nvm_write(INT_FLASH, &(nvmParam->nvmEdc), (uint8_t *)x, 1)

#endif
#endif

+ 0
- 2947
firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/source/miwi_p2p_star/miwi_p2p.c
File diff suppressed because it is too large
View File


+ 0
- 212
firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/source/miwi_p2p_star/miwi_p2p.h View File

@@ -1,212 +0,0 @@
/**
* \file miwi_p2p.h
*
* \brief MiWi P2P & Star Protocol interface
*
* Copyright (c) 2019 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/
/*
* Support and FAQ: visit <a href="https://www.microchip.com/support/">Microchip Support</a>
*/

#ifndef __MIWI_P2P_H_
#define __MIWI_P2P_H_

#define INPUT
#define OUTPUT
#define IOPUT

#include "system.h"
#include "miwi_config.h" //MiWi Application layer configuration file
#include "miwi_config_p2p.h" //MiWi Protocol layer configuration file

#if defined(PROTOCOL_P2P)
/************************ HEADERS **********************************/
#include "sysTimer.h"
#include "miwi_api.h"


/************************ DEFINITIONS ******************************/

#define PAYLOAD_START 0

#define STATUS_SUCCESS 0x00
#define STATUS_EXISTS 0x01
#define STATUS_ACTIVE_SCAN 0x02
#define STATUS_ENTRY_NOT_EXIST 0xF0
#define STATUS_NOT_ENOUGH_SPACE 0xF1
#define STATUS_NOT_SAME_PAN 0xF2
#define STATUS_NOT_PERMITTED 0xF3

#define CMD_P2P_CONNECTION_REQUEST 0x81
#define CMD_P2P_CONNECTION_REMOVAL_REQUEST 0x82
#define CMD_DATA_REQUEST 0x83
#define CMD_CHANNEL_HOPPING 0x84
#define CMD_TIME_SYNCHRONIZATION_REQUEST 0x85
#define CMD_TIME_SYNCHRONIZATION_NOTIFICATION 0x86
#define CMD_P2P_ACTIVE_SCAN_REQUEST 0x87

#define CMD_TIME_SYNC_DATA_PACKET 0x8A
#define CMD_TIME_SYNC_COMMAND_PACKET 0x8B

#define CMD_P2P_CONNECTION_RESPONSE 0x91
#define CMD_P2P_CONNECTION_REMOVAL_RESPONSE 0x92
#define CMD_P2P_ACTIVE_SCAN_RESPONSE 0x97

#define CMD_MAC_DATA_REQUEST 0x04

#define PACKETLEN_P2P_ACTIVE_SCAN_RESPONSE (2 + ADDITIONAL_NODE_ID_SIZE)
#define PACKETLEN_P2P_CONNECTION_REMOVAL_RESPONSE 2
#define PACKETLEN_TIME_SYNC_DATA_PACKET TX_BUFFER_SIZE
#define PACKETLEN_MAC_DATA_REQUEST TX_BUFFER_SIZE
#define PACKETLEN_P2P_CONNECTION_REMOVAL_REQUEST 1
#define PACKETLEN_CMD_IAM_ALIVE 1
#define PACKETLEN_CMD_DATA_TO_ENDDEV_SUCCESS 1
#define PACKETLEN_P2P_CONNECTION_REQUEST (4 + ADDITIONAL_NODE_ID_SIZE)
#define PACKETLEN_P2P_ACTIVE_SCAN_REQUEST 2
#define PACKETLEN_CMD_CHANNEL_HOPPING 3

#define PACKETLEN_ACK 22 // No of bytes in ACK at radio layer
#define TOTAL_ACK_PROCESSING_DELAY 106 + 64 + 1 + 650 // ACK processing delay + 64 ms buffer delay + 1ms ToA calculation delay + ~650 OLED display update

#if defined(ENABLE_ED_SCAN) && defined(ENABLE_FREQUENCY_AGILITY)
#define FREQUENCY_AGILITY_STARTER
#endif

#define MICRO_SECOND_PER_COUNTER_TICK (1000000ul / ( COUNTER_CRYSTAL_FREQ / 8 ))


/******************************************************************
* Overview: The capacity information for a MiWi(TM) P2P device. It is the
* definition of the first byte of PeerInfo defined in
* P2P_CONNECTION_ENTRY. The highest bit also be used to indicate
* if the P2P connection entry is a valid entry
*****************************************************************/
typedef union
{
uint8_t Val; // the value of the P2P capacitity
struct _P2P_CAPACITY_BITS
{
uint8_t RXOnWhileIdel : 1; // if device turns on radio when idle
uint8_t DataRequestNeeded : 1; // if data request is required when device turns off radio when
// idle. It is used to decide if an indirect message is necessary
// to be stored.
uint8_t TimeSynchronization : 1; // reserved bit for future development
uint8_t SecurityCapacity : 1; // if the device is capable of handling encrypted information
uint8_t ConnectionMode : 2;
uint8_t filler : 1;
uint8_t isValid : 1; // use this bit to indicate that this entry is a valid entry
} bits;
} P2P_CAPACITY;

/******************************************************************
* Overview: The structure to store indirect messages for devices turn off
* radio when idle
*****************************************************************/
typedef struct
{
MIWI_TICK TickStart; // start time of the indirect message. Used for checking
// indirect message time out
#if defined(IEEE_802_15_4)
API_UINT16_UNION DestPANID; // the PAN identifier for the destination node
#endif
union
{
uint8_t DestLongAddress[MY_ADDRESS_LENGTH]; // unicast destination long address
uint8_t DestIndex[CONNECTION_SIZE]; // broadcast index of the P2P Connection Entries
// for destination RFD devices
} DestAddress; // destination address for the indirect message. Can either for unicast or broadcast
union
{
uint8_t Val; // value for the flags
struct
{
uint8_t isValid : 1; // if this indirect message is valid
uint8_t isBroadcast : 1; // if this indirect message is for broadcasting
uint8_t isCommand : 1; // if this indirect message a command
uint8_t isSecured : 1; // if this indirect message requires encryption
uint8_t ackReq : 1; // if this indirect message requires acknowledgement
} bits; // bit map of the flags
} flags; // flags for indirect message
uint8_t PayLoadSize; // the indirect message pay load size
uint8_t PayLoad[255]; // the indirect message pay load
uint8_t indirectDataHandle;
DataConf_callback_t indirectConfCallback;
} INDIRECT_MESSAGE;


/******************************************************************
* Overview: structure to indicate the status of P2P stack
*****************************************************************/
typedef union
{
uint8_t Val; // The value of the P2P status flags
struct
{
uint8_t Sleeping :1; // indicate if the device in sleeping state
uint8_t SaveConnection :1; // indicate if it is time for Network Freezer module to
// save valid connections. Important because there may be
// more than one response coming back and NVM operation is
// blocking
uint8_t DataRequesting :1; // indicate that device is in the process of data request
// from its parent. Only effective if device enables sleeping
uint8_t RxHasUserData :1; // indicate if the received frame needs processing from
// the application layer
uint8_t SearchConnection :1; // indicate if the stack is currently in the process of
// looking for new connection
uint8_t Resync :1; // indicate if the stack is currently in the process of
// resynchronizing connection with the peer device
uint8_t Enhanced_DR_SecEn :1;
}bits; // bit map of the P2P status
} P2P_STATUS;


/************************ EXTERNAL VARIABLES **********************/
extern volatile P2P_STATUS P2PStatus;
#if defined(IEEE_802_15_4)
extern API_UINT16_UNION myPANID;
#endif
extern API_UINT16_UNION CounterVal;

extern volatile uint16_t myShortAddress;

/************************ FUNCTION PROTOTYPES **********************/
bool isSameAddress(INPUT uint8_t *Address1, INPUT uint8_t *Address2);

/*********************************************************************/
// calculate_ToA() calculates time on air(ToA) for input payload length
// Input : uint8_t payload_length (bytes , max = 255)
// Output : uint16_t totalTimeOnAir (ms)
/*********************************************************************/
uint16_t calculate_ToA(uint8_t payload_length);

#endif

#endif

+ 0
- 68
firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/source/miwi_p2p_star/miwi_p2p_pds.c View File

@@ -1,68 +0,0 @@
/**
* \file miwi_p2p_pds.c
*
* \brief MiWi P2P & Star PDS Definitions
*
* Copyright (c) 2019 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/
/*
* Support and FAQ: visit <a href="https://www.microchip.com/support/">Microchip Support</a>
*/

#if defined(ENABLE_NETWORK_FREEZER)
/************************ HEADERS **********************************/
#include "system.h"
#include "string.h"
#include "miwi_config.h" //MiWi Application layer configuration file
#include "miwi_config_p2p.h" //MiWi Protocol layer configuration file
#include "miwi_api.h"
#include <pdsDataServer.h>
#include <wlPdsTypesConverter.h>
#include <wlPdsMemIds.h>
#include <D_Nv.h>

#define PROGMEM_DECLARE(x) const x

#ifdef ENABLE_SECURITY
extern API_UINT32_UNION OutgoingFrameCounter;
#endif
#if defined(IEEE_802_15_4)
extern API_UINT16_UNION myPANID;
#endif
extern uint8_t ConnMode;
extern uint8_t LatestConnection;

#ifdef ENABLE_SECURITY
PDS_DECLARE_ITEM(PDS_OUTGOING_FRAME_COUNTER_ID, PDS_OUTGOING_FRAME_COUNTER_ITEM_SIZE, &OutgoingFrameCounter, NULL, NO_ITEM_FLAGS);
#endif
PDS_DECLARE_ITEM(PDS_PANID_ID, PDS_PANID_ITEM_SIZE, &myPANID, NULL, NO_ITEM_FLAGS);
PDS_DECLARE_ITEM(PDS_CURRENT_CHANNEL_ID, PDS_CURRENT_CHANNEL_ITEM_SIZE, &currentChannel, NULL, NO_ITEM_FLAGS);
PDS_DECLARE_ITEM(PDS_CONNECTION_MODE_ID, PDS_CONNECTION_MODE_ITEM_SIZE, &ConnMode, NULL, NO_ITEM_FLAGS);
PDS_DECLARE_ITEM(PDS_CONNECTION_TABLE_ID, PDS_CONNECTION_TABLE_ITEM_SIZE * CONNECTION_SIZE, ConnectionTable, NULL, NO_ITEM_FLAGS);
PDS_DECLARE_ITEM(PDS_EDC_ID, PDS_EDC_ITEM_SIZE, &conn_size, NULL, NO_ITEM_FLAGS);
#endif

+ 0
- 233
firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/source/sys/mimem.c View File

@@ -1,233 +0,0 @@
/**
* \file mimem.c
*
* \brief Memory Buffer handling for MiWi Protocol implementation
*
* Copyright (c) 2019 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/

/************************ HEADERS **********************************/
#include <string.h>
#include "compiler.h"
#include "mimem.h"

/************************ MACRO DEFINITIONS ******************************/
#define BYTE_ALIGNMENT 4U
#define ALIGNMENT_FACTOR 2U

#define HEAP_SIZE (6144UL)

#define ALIGN(X) ((((X-1) >> ALIGNMENT_FACTOR) << ALIGNMENT_FACTOR) + BYTE_ALIGNMENT)

#define HEAP_MINIMUM_BLOCK_SIZE (( size_t )( blockMetaDataSize + 4U)) //4 is min bytes being allocated with alignment

/************************ TYPE DEFINITIONS ******************************/
typedef struct _Block_t
{
struct _Block_t* next;
struct _Block_t* prev;
size_t size;
bool free;
} Block_t;

/************************ FUNCTION PROTOTYPES **********************/
static void splitBlock (Block_t* blockTobeSplitted, size_t size);

/************************ VARIABLES ********************************/
static uint8_t heapMem[HEAP_SIZE];
static Block_t* base = NULL;
static size_t totalFreeBytesRemaining;
static const size_t blockMetaDataSize = ALIGN(sizeof(Block_t));

/************************ FUNCTIONS ********************************/

/*********************************************************************
* Function: void MiMem_Init()
*
* PreCondition: none
*
* Input: none
*
* Output: none
*
* Overview: This function will initialize the Mimem buffers
********************************************************************/
void MiMem_Init(void)
{
size_t startAddress = ALIGN((size_t)heapMem);

/*Aligned heap is the base */
base = (Block_t*) startAddress;
base->size = totalFreeBytesRemaining = HEAP_SIZE - (startAddress - (size_t)heapMem);
base->free = true;
base->next = NULL;
base->prev = NULL;
}

/*********************************************************************
* Function: void* MiMem_Alloc(uint8_t size)
*
* PreCondition: none
*
* Input: size - Required number of bytes
*
* Output: uint8_t*_t - Pointer to the allocated memory or NULL
*
* Side Effects: none
*
* Overview: This function returns valid pointer if memory is allocated
* or returns NULL if no memory available
*
* Note: none
********************************************************************/
void* MiMem_Alloc(uint8_t size)
{
size_t requestedSize = 0U;
void* requestedMemPtr = NULL;

/* Initialize the Heap */
if (!base)
{
MiMem_Init();
}
/* if requested size is of non zero */
if (size)
{
requestedSize = size + blockMetaDataSize;
requestedSize = ALIGN(requestedSize);
if (requestedSize <= totalFreeBytesRemaining)
{
size_t receivedSize = (size_t)~0U;
Block_t *requestedBlock = NULL;
Block_t *blockPtr = base;

/* Find best fit free Block */
while (blockPtr)
{
if ((blockPtr->free) && (blockPtr->size >= requestedSize) && (blockPtr->size < receivedSize))
{
receivedSize = blockPtr->size;
requestedBlock = blockPtr;
}
blockPtr = blockPtr->next;
}

if (requestedBlock)
{
if ((requestedBlock->size - requestedSize) > HEAP_MINIMUM_BLOCK_SIZE)
splitBlock (requestedBlock, requestedSize);
requestedBlock->free = false;
totalFreeBytesRemaining -= requestedBlock->size;
requestedMemPtr = ( void* )(((uint8_t*)requestedBlock) + blockMetaDataSize);
}
}
}
if (NULL != requestedMemPtr)
{
memset(requestedMemPtr, 0, size);
}
return requestedMemPtr;
}

/*********************************************************************
* Function: uint8_t MiMem_Free(uint8_t* buffPtr)
*
* PreCondition: none
*
* Input: buffPtr - Pointer to memory to be deallocated
*
* Output: void
*
* Side Effects: none
*
* Overview: This function returns SUCCESS if it deallocates
* the given memory else returns error
*
* Note: none
********************************************************************/
void MiMem_Free(void *ptr)
{
Block_t* blockPtr = base;
Block_t* freeBlockPtr = (Block_t*)((uint8_t*)ptr - (uint8_t*)blockMetaDataSize);

for(; ((blockPtr != NULL) && (blockPtr != freeBlockPtr)); blockPtr = blockPtr->next);

if (blockPtr)
{
blockPtr->free = true;
totalFreeBytesRemaining += blockPtr->size;

/* if the previous block this freed block is free, merge them */
if (blockPtr->prev && blockPtr->prev->free)
{
blockPtr->prev->size += blockPtr->size;
if (blockPtr->next)
blockPtr->next->prev = blockPtr->prev;
blockPtr->prev->next = blockPtr->next;
blockPtr = blockPtr->prev;
}
/* if the next block of this freed block is free, merge them */
if (blockPtr->next && blockPtr->next->free)
{
blockPtr->size += blockPtr->next->size ;
blockPtr->next = blockPtr->next->next;
if (blockPtr->next)
blockPtr->next->prev = blockPtr;
}
}
}

/******************************************************************************
\brief Split the large chunk into two if the existing memory is larger than
the requested size
\param[in] blockTobeSplitted - block to be splited
\param[in] size size of the memory chunk requested
\return None.
******************************************************************************/
static void splitBlock(Block_t* blockTobeSplitted, size_t size)
{
uint8_t* ptr = (uint8_t*)blockTobeSplitted + size;
Block_t* newBlock = (Block_t*)ptr;

newBlock->size = blockTobeSplitted->size - size;

if (blockTobeSplitted->next)
blockTobeSplitted->next->prev = newBlock;

newBlock->next = blockTobeSplitted->next;
newBlock->prev = blockTobeSplitted;
newBlock->free = true;

blockTobeSplitted->next = newBlock;
blockTobeSplitted->size = size;
}

uint8_t MiMem_PercentageOfFreeBuffers(void)
{
return (totalFreeBytesRemaining * 100) / HEAP_SIZE;;
}

+ 0
- 50
firmware/SendcommPeer2P/src/ASF/thirdparty/wireless/LoRa_P2P/source/sys/mimem.h View File

@@ -1,50 +0,0 @@
/**
* \file mimem.h
*
* \brief Memory Buffer handling for MiWi Protocol interface
*
* Copyright (c) 2019 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/

#ifndef __MIMEM_H_
#define __MIMEM_H_

/************************ HEADERS **********************************/


/************************ DEFINITIONS ******************************/

/************************ DATA TYPES *******************************/

/************************ Prototypes ********************************/
void MiMem_Init(void);
void* MiMem_Alloc(uint8_t size);
void MiMem_Free(void* buffPtr);
uint8_t MiMem_PercentageOfFreeBuffers(void);
#endif


Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save