Commit f7c9a8e1b5acc0ada6cb6ceaeb4560f3d0e456d2

Authored by jdenecha
1 parent eee7ec71

Feat : Firt dump

Showing 271 changed files with 87975 additions and 0 deletions   Show diff stats

Too many changes.

To preserve performance only 100 of 271 files are displayed.

GettingStarted.html 0 → 100644
... ... @@ -0,0 +1,16 @@
  1 +<!DOCTYPE HTML>
  2 +<html lang="en-US">
  3 + <head>
  4 + <meta charset="UTF-8">
  5 + <meta http-equiv="refresh"
  6 + content="1;url="https://developer.mbed.org/handbook/Getting-Started-mbed-Exporters>
  7 + <script type="text/javascript">
  8 + window.location.href = "https://developer.mbed.org/handbook/Getting-Started-mbed-Exporters"
  9 + </script>
  10 + <title>Page Redirection</title>
  11 + </head>
  12 + <body>
  13 + If you are not redirected automatically, please follow the
  14 + <a href='https://developer.mbed.org/handbook/Getting-Started-mbed-Exporters'>link to the online exporter documentation</a>
  15 + </body>
  16 +</html>
... ...
Makefile 0 → 100644
... ... @@ -0,0 +1,337 @@
  1 +# This file was automagically generated by mbed.org. For more information,
  2 +# see http://mbed.org/handbook/Exporting-to-GCC-ARM-Embedded
  3 +
  4 +###############################################################################
  5 +# Boiler-plate
  6 +
  7 +# cross-platform directory manipulation
  8 +ifeq ($(shell echo $$OS),$$OS)
  9 + MAKEDIR = if not exist "$(1)" mkdir "$(1)"
  10 + RM = rmdir /S /Q "$(1)"
  11 +else
  12 + MAKEDIR = '$(SHELL)' -c "mkdir -p \"$(1)\""
  13 + RM = '$(SHELL)' -c "rm -rf \"$(1)\""
  14 +endif
  15 +
  16 +OBJDIR := BUILD
  17 +# Move to the build directory
  18 +ifeq (,$(filter $(OBJDIR),$(notdir $(CURDIR))))
  19 +.SUFFIXES:
  20 +mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
  21 +MAKETARGET = '$(MAKE)' --no-print-directory -C $(OBJDIR) -f '$(mkfile_path)' \
  22 + 'SRCDIR=$(CURDIR)' $(MAKECMDGOALS)
  23 +.PHONY: $(OBJDIR) clean
  24 +all:
  25 + +@$(call MAKEDIR,$(OBJDIR))
  26 + +@$(MAKETARGET)
  27 +$(OBJDIR): all
  28 +Makefile : ;
  29 +% :: $(OBJDIR) ; :
  30 +clean :
  31 + $(call RM,$(OBJDIR))
  32 +
  33 +else
  34 +
  35 +# trick rules into thinking we are in the root, when we are in the bulid dir
  36 +VPATH = ..
  37 +
  38 +# Boiler-plate
  39 +###############################################################################
  40 +# Project settings
  41 +
  42 +PROJECT := SX1276PingPong_copy
  43 +
  44 +
  45 +# Project settings
  46 +###############################################################################
  47 +# Objects and Paths
  48 +
  49 +OBJECTS += SX1276Lib/radio/radio.o
  50 +OBJECTS += SX1276Lib/sx1276/sx1276-hal.o
  51 +OBJECTS += SX1276Lib/sx1276/sx1276.o
  52 +OBJECTS += main.o
  53 +
  54 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_flash_ramfunc.o
  55 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/board.o
  56 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/cmsis_nvic.o
  57 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/hal_tick.o
  58 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/mbed_overrides.o
  59 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/retarget.o
  60 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/startup_stm32f401xe.o
  61 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal.o
  62 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_adc.o
  63 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_adc_ex.o
  64 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_can.o
  65 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_cec.o
  66 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_cortex.o
  67 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_crc.o
  68 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_cryp.o
  69 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_cryp_ex.o
  70 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_dac.o
  71 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_dac_ex.o
  72 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_dcmi.o
  73 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_dcmi_ex.o
  74 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_dma.o
  75 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_dma2d.o
  76 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_dma_ex.o
  77 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_dsi.o
  78 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_eth.o
  79 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_flash.o
  80 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_flash_ex.o
  81 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_fmpi2c_ex.o
  82 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_fmpi2c.o
  83 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_msp_template.o
  84 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_gpio.o
  85 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_hash.o
  86 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_hash_ex.o
  87 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_hcd.o
  88 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_i2c.o
  89 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_i2c_ex.o
  90 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_i2s.o
  91 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_i2s_ex.o
  92 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_irda.o
  93 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_iwdg.o
  94 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_lptim.o
  95 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_ltdc.o
  96 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_ltdc_ex.o
  97 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_smartcard.o
  98 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_nand.o
  99 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_nor.o
  100 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_pccard.o
  101 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_pcd.o
  102 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_pcd_ex.o
  103 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_pwr.o
  104 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_pwr_ex.o
  105 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_qspi.o
  106 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_rcc.o
  107 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_rcc_ex.o
  108 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_rng.o
  109 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_rtc.o
  110 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_rtc_ex.o
  111 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_sai.o
  112 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_sai_ex.o
  113 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_sd.o
  114 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_sdram.o
  115 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_spdifrx.o
  116 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_spi.o
  117 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_sram.o
  118 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_tim.o
  119 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_tim_ex.o
  120 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_uart.o
  121 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_usart.o
  122 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_wwdg.o
  123 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_ll_fmc.o
  124 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_ll_fsmc.o
  125 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_ll_sdmmc.o
  126 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_ll_usb.o
  127 + SYS_OBJECTS += mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/system_stm32f4xx.o
  128 +
  129 +INCLUDE_PATHS += -I../
  130 +INCLUDE_PATHS += -I../.
  131 +INCLUDE_PATHS += -I../SX1276Lib
  132 +INCLUDE_PATHS += -I../SX1276Lib/debug
  133 +INCLUDE_PATHS += -I../SX1276Lib/enums
  134 +INCLUDE_PATHS += -I../SX1276Lib/radio
  135 +INCLUDE_PATHS += -I../SX1276Lib/registers
  136 +INCLUDE_PATHS += -I../SX1276Lib/sx1276
  137 +INCLUDE_PATHS += -I../SX1276Lib/typedefs
  138 +INCLUDE_PATHS += -I../mbed/.
  139 +INCLUDE_PATHS += -I../mbed/TARGET_NUCLEO_F401RE
  140 +INCLUDE_PATHS += -I../mbed/TARGET_NUCLEO_F401RE/TARGET_STM
  141 +INCLUDE_PATHS += -I../mbed/TARGET_NUCLEO_F401RE/TARGET_STM/TARGET_STM32F4
  142 +INCLUDE_PATHS += -I../mbed/TARGET_NUCLEO_F401RE/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F401RE
  143 +INCLUDE_PATHS += -I../mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM
  144 +
  145 +LIBRARY_PATHS := -L../mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM
  146 +LIBRARIES := -l:libmbed.a
  147 +LINKER_SCRIPT := ../mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/STM32F401XE.ld
  148 +
  149 +# Objects and Paths
  150 +###############################################################################
  151 +# Tools and Flags
  152 +
  153 +AS = 'arm-none-eabi-gcc' '-x' 'assembler-with-cpp' '-c' '-Wall' '-Wextra' '-Wno-unused-parameter' '-Wno-missing-field-initializers' '-fmessage-length=0' '-fno-exceptions' '-fno-builtin' '-ffunction-sections' '-fdata-sections' '-funsigned-char' '-MMD' '-fno-delete-null-pointer-checks' '-fomit-frame-pointer' '-Os' '-mcpu=cortex-m4' '-mthumb' '-mfpu=fpv4-sp-d16' '-mfloat-abi=softfp'
  154 +CC = 'arm-none-eabi-gcc' '-std=gnu99' '-c' '-Wall' '-Wextra' '-Wno-unused-parameter' '-Wno-missing-field-initializers' '-fmessage-length=0' '-fno-exceptions' '-fno-builtin' '-ffunction-sections' '-fdata-sections' '-funsigned-char' '-MMD' '-fno-delete-null-pointer-checks' '-fomit-frame-pointer' '-Os' '-mcpu=cortex-m4' '-mthumb' '-mfpu=fpv4-sp-d16' '-mfloat-abi=softfp'
  155 +CPP = 'arm-none-eabi-g++' '-std=gnu++98' '-fno-rtti' '-Wvla' '-c' '-Wall' '-Wextra' '-Wno-unused-parameter' '-Wno-missing-field-initializers' '-fmessage-length=0' '-fno-exceptions' '-fno-builtin' '-ffunction-sections' '-fdata-sections' '-funsigned-char' '-MMD' '-fno-delete-null-pointer-checks' '-fomit-frame-pointer' '-Os' '-mcpu=cortex-m4' '-mthumb' '-mfpu=fpv4-sp-d16' '-mfloat-abi=softfp'
  156 +LD = 'arm-none-eabi-gcc' '-Wl,--gc-sections' '-Wl,--wrap,main' '-mcpu=cortex-m4' '-mthumb' '-mfpu=fpv4-sp-d16' '-mfloat-abi=softfp'
  157 +ELF2BIN = 'arm-none-eabi-objcopy'
  158 +
  159 +
  160 +C_FLAGS += -std=gnu99
  161 +C_FLAGS += -D__MBED__=1
  162 +C_FLAGS += -DDEVICE_I2CSLAVE=1
  163 +C_FLAGS += -DTARGET_LIKE_MBED
  164 +C_FLAGS += -DDEVICE_PORTOUT=1
  165 +C_FLAGS += -DTARGET_NUCLEO_F401RE
  166 +C_FLAGS += -DTARGET_RTOS_M4_M7
  167 +C_FLAGS += -DDEVICE_RTC=1
  168 +C_FLAGS += -DTOOLCHAIN_object
  169 +C_FLAGS += -DDEVICE_SERIAL_ASYNCH=1
  170 +C_FLAGS += -DTARGET_STM32F4
  171 +C_FLAGS += -D__CMSIS_RTOS
  172 +C_FLAGS += -DTOOLCHAIN_GCC
  173 +C_FLAGS += -DDEVICE_I2C_ASYNCH=1
  174 +C_FLAGS += -DTARGET_CORTEX_M
  175 +C_FLAGS += -DTARGET_LIKE_CORTEX_M4
  176 +C_FLAGS += -DTARGET_M4
  177 +C_FLAGS += -DTARGET_UVISOR_UNSUPPORTED
  178 +C_FLAGS += -DDEVICE_SPI_ASYNCH=1
  179 +C_FLAGS += -DDEVICE_SERIAL=1
  180 +C_FLAGS += -DDEVICE_INTERRUPTIN=1
  181 +C_FLAGS += -DDEVICE_I2C=1
  182 +C_FLAGS += -DTRANSACTION_QUEUE_SIZE_SPI=2
  183 +C_FLAGS += -D__CORTEX_M4
  184 +C_FLAGS += -DDEVICE_STDIO_MESSAGES=1
  185 +C_FLAGS += -DTARGET_STM32F401RE
  186 +C_FLAGS += -DTARGET_FF_MORPHO
  187 +C_FLAGS += -D__FPU_PRESENT=1
  188 +C_FLAGS += -DTARGET_FF_ARDUINO
  189 +C_FLAGS += -DDEVICE_PORTIN=1
  190 +C_FLAGS += -DTARGET_RELEASE
  191 +C_FLAGS += -DTARGET_STM
  192 +C_FLAGS += -DDEVICE_SERIAL_FC=1
  193 +C_FLAGS += -DDEVICE_PORTINOUT=1
  194 +C_FLAGS += -D__MBED_CMSIS_RTOS_CM
  195 +C_FLAGS += -DDEVICE_SLEEP=1
  196 +C_FLAGS += -DTOOLCHAIN_GCC_ARM
  197 +C_FLAGS += -DDEVICE_SPI=1
  198 +C_FLAGS += -DUSB_STM_HAL
  199 +C_FLAGS += -DDEVICE_ERROR_RED=1
  200 +C_FLAGS += -DDEVICE_SPISLAVE=1
  201 +C_FLAGS += -DMBED_BUILD_TIMESTAMP=1488367825.38
  202 +C_FLAGS += -DDEVICE_ANALOGIN=1
  203 +C_FLAGS += -DDEVICE_PWMOUT=1
  204 +C_FLAGS += -DARM_MATH_CM4
  205 +C_FLAGS += -include
  206 +C_FLAGS += mbed_config.h
  207 +
  208 +CXX_FLAGS += -std=gnu++98
  209 +CXX_FLAGS += -fno-rtti
  210 +CXX_FLAGS += -Wvla
  211 +CXX_FLAGS += -D__MBED__=1
  212 +CXX_FLAGS += -DDEVICE_I2CSLAVE=1
  213 +CXX_FLAGS += -DTARGET_LIKE_MBED
  214 +CXX_FLAGS += -DDEVICE_PORTOUT=1
  215 +CXX_FLAGS += -DTARGET_NUCLEO_F401RE
  216 +CXX_FLAGS += -DTARGET_RTOS_M4_M7
  217 +CXX_FLAGS += -DDEVICE_RTC=1
  218 +CXX_FLAGS += -DTOOLCHAIN_object
  219 +CXX_FLAGS += -DDEVICE_SERIAL_ASYNCH=1
  220 +CXX_FLAGS += -DTARGET_STM32F4
  221 +CXX_FLAGS += -D__CMSIS_RTOS
  222 +CXX_FLAGS += -DTOOLCHAIN_GCC
  223 +CXX_FLAGS += -DDEVICE_I2C_ASYNCH=1
  224 +CXX_FLAGS += -DTARGET_CORTEX_M
  225 +CXX_FLAGS += -DTARGET_LIKE_CORTEX_M4
  226 +CXX_FLAGS += -DTARGET_M4
  227 +CXX_FLAGS += -DTARGET_UVISOR_UNSUPPORTED
  228 +CXX_FLAGS += -DDEVICE_SPI_ASYNCH=1
  229 +CXX_FLAGS += -DDEVICE_SERIAL=1
  230 +CXX_FLAGS += -DDEVICE_INTERRUPTIN=1
  231 +CXX_FLAGS += -DDEVICE_I2C=1
  232 +CXX_FLAGS += -DTRANSACTION_QUEUE_SIZE_SPI=2
  233 +CXX_FLAGS += -D__CORTEX_M4
  234 +CXX_FLAGS += -DDEVICE_STDIO_MESSAGES=1
  235 +CXX_FLAGS += -DTARGET_STM32F401RE
  236 +CXX_FLAGS += -DTARGET_FF_MORPHO
  237 +CXX_FLAGS += -D__FPU_PRESENT=1
  238 +CXX_FLAGS += -DTARGET_FF_ARDUINO
  239 +CXX_FLAGS += -DDEVICE_PORTIN=1
  240 +CXX_FLAGS += -DTARGET_RELEASE
  241 +CXX_FLAGS += -DTARGET_STM
  242 +CXX_FLAGS += -DDEVICE_SERIAL_FC=1
  243 +CXX_FLAGS += -DDEVICE_PORTINOUT=1
  244 +CXX_FLAGS += -D__MBED_CMSIS_RTOS_CM
  245 +CXX_FLAGS += -DDEVICE_SLEEP=1
  246 +CXX_FLAGS += -DTOOLCHAIN_GCC_ARM
  247 +CXX_FLAGS += -DDEVICE_SPI=1
  248 +CXX_FLAGS += -DUSB_STM_HAL
  249 +CXX_FLAGS += -DDEVICE_ERROR_RED=1
  250 +CXX_FLAGS += -DDEVICE_SPISLAVE=1
  251 +CXX_FLAGS += -DMBED_BUILD_TIMESTAMP=1488367825.38
  252 +CXX_FLAGS += -DDEVICE_ANALOGIN=1
  253 +CXX_FLAGS += -DDEVICE_PWMOUT=1
  254 +CXX_FLAGS += -DARM_MATH_CM4
  255 +CXX_FLAGS += -include
  256 +CXX_FLAGS += mbed_config.h
  257 +
  258 +ASM_FLAGS += -x
  259 +ASM_FLAGS += assembler-with-cpp
  260 +ASM_FLAGS += -DTRANSACTION_QUEUE_SIZE_SPI=2
  261 +ASM_FLAGS += -D__CORTEX_M4
  262 +ASM_FLAGS += -DUSB_STM_HAL
  263 +ASM_FLAGS += -DARM_MATH_CM4
  264 +ASM_FLAGS += -D__FPU_PRESENT=1
  265 +ASM_FLAGS += -D__MBED_CMSIS_RTOS_CM
  266 +ASM_FLAGS += -D__CMSIS_RTOS
  267 +
  268 +
  269 +LD_FLAGS :=-Wl,--gc-sections -Wl,--wrap,main -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=softfp
  270 +
  271 +LD_SYS_LIBS += -lstdc++
  272 +LD_SYS_LIBS += -lsupc++
  273 +LD_SYS_LIBS += -lm
  274 +LD_SYS_LIBS += -lc
  275 +LD_SYS_LIBS += -lgcc
  276 +LD_SYS_LIBS += -lnosys
  277 +
  278 +
  279 +# Tools and Flags
  280 +###############################################################################
  281 +# Rules
  282 +
  283 +.PHONY: all lst size
  284 +
  285 +
  286 +all: $(PROJECT).bin $(PROJECT).hex size
  287 +
  288 +
  289 +.asm.o:
  290 + +@$(call MAKEDIR,$(dir $@))
  291 + +@echo "Assemble: $(notdir $<)"
  292 + @$(AS) -c $(ASM_FLAGS) $(INCLUDE_PATHS) -o $@ $<
  293 +
  294 +.s.o:
  295 + +@$(call MAKEDIR,$(dir $@))
  296 + +@echo "Assemble: $(notdir $<)"
  297 + @$(AS) -c $(ASM_FLAGS) $(INCLUDE_PATHS) -o $@ $<
  298 +
  299 +.S.o:
  300 + +@$(call MAKEDIR,$(dir $@))
  301 + +@echo "Assemble: $(notdir $<)"
  302 + @$(AS) -c $(ASM_FLAGS) $(INCLUDE_PATHS) -o $@ $<
  303 +
  304 +.c.o:
  305 + +@$(call MAKEDIR,$(dir $@))
  306 + +@echo "Compile: $(notdir $<)"
  307 + @$(CC) $(C_FLAGS) $(INCLUDE_PATHS) -o $@ $<
  308 +
  309 +.cpp.o:
  310 + +@$(call MAKEDIR,$(dir $@))
  311 + +@echo "Compile: $(notdir $<)"
  312 + @$(CPP) $(CXX_FLAGS) $(INCLUDE_PATHS) -o $@ $<
  313 +
  314 +
  315 +$(PROJECT).elf: $(OBJECTS) $(SYS_OBJECTS) $(LINKER_SCRIPT)
  316 + +@echo "link: $(notdir $@)"
  317 + @$(LD) $(LD_FLAGS) -T $(filter %.ld, $^) $(LIBRARY_PATHS) --output $@ $(filter %.o, $^) $(LIBRARIES) $(LD_SYS_LIBS)
  318 +
  319 +
  320 +$(PROJECT).bin: $(PROJECT).elf
  321 + $(ELF2BIN) -O binary $< $@
  322 + +@echo "===== bin file ready to flash: $(OBJDIR)/$@ ====="
  323 +
  324 +$(PROJECT).hex: $(PROJECT).elf
  325 + $(ELF2BIN) -O ihex $< $@
  326 +
  327 +
  328 +# Rules
  329 +###############################################################################
  330 +# Dependencies
  331 +
  332 +DEPS = $(OBJECTS:.o=.d) $(SYS_OBJECTS:.o=.d)
  333 +-include $(DEPS)
  334 +endif
  335 +
  336 +# Dependencies
  337 +###############################################################################
... ...
SX1276Lib.lib 0 → 100644
... ... @@ -0,0 +1 @@
  1 +http://developer.mbed.org/teams/Semtech/code/SX1276Lib/#7f3aab69cca9
... ...
SX1276Lib/debug/debug.h 0 → 100644
... ... @@ -0,0 +1,61 @@
  1 +/* Copyright (c) 2012 mbed.org, MIT License
  2 + *
  3 + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
  4 + * and associated documentation files (the "Software"), to deal in the Software without restriction,
  5 + * including without limitation the rights to use, copy, modify, merge, publish, distribute,
  6 + * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
  7 + * furnished to do so, subject to the following conditions:
  8 + *
  9 + * The above copyright notice and this permission notice shall be included in all copies or
  10 + * substantial portions of the Software.
  11 + *
  12 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
  13 + * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  14 + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  15 + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16 + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  17 + */
  18 +
  19 +#ifndef DEBUG_H
  20 +#define DEBUG_H
  21 +
  22 +/** @file debug.h */
  23 +
  24 +#ifndef NDEBUG
  25 +
  26 +#include <stdarg.h>
  27 +#include <stdio.h>
  28 +
  29 +/** Output a debug message
  30 + *
  31 + * @param format printf-style format string, followed by variables
  32 + */
  33 +static inline void debug(const char *format, ...) {
  34 + va_list args;
  35 + va_start(args, format);
  36 + vfprintf(stderr, format, args);
  37 + va_end(args);
  38 +}
  39 +
  40 +/** Conditionally output a debug message
  41 + *
  42 + * @param condition output only if condition is true
  43 + * @param format printf-style format string, followed by variables
  44 + */
  45 +static inline void debug_if(bool condition, const char *format, ...) {
  46 + if(condition) {
  47 + va_list args;
  48 + va_start(args, format);
  49 + vfprintf(stderr, format, args);
  50 + va_end(args);
  51 + }
  52 +}
  53 +
  54 +#else
  55 +
  56 +static inline void debug(const char *format, ...) {}
  57 +static inline void debug(bool condition, const char *format, ...) {}
  58 +
  59 +#endif
  60 +
  61 +#endif
... ...
SX1276Lib/enums/enums.h 0 → 100644
... ... @@ -0,0 +1,129 @@
  1 +/*
  2 + / _____) _ | |
  3 +( (____ _____ ____ _| |_ _____ ____| |__
  4 + \____ \| ___ | (_ _) ___ |/ ___) _ \
  5 + _____) ) ____| | | || |_| ____( (___| | | |
  6 +(______/|_____)_|_|_| \__)_____)\____)_| |_|
  7 + (C) 2014 Semtech
  8 +
  9 +Description: -
  10 +
  11 +License: Revised BSD License, see LICENSE.TXT file include in the project
  12 +
  13 +Maintainers: Miguel Luis, Gregory Cristian and Nicolas Huguenin
  14 +*/
  15 +#ifndef __ENUMS_H__
  16 +#define __ENUMS_H__
  17 +
  18 +/*!
  19 + * Radio driver internal state machine states definition
  20 + */
  21 +typedef enum RadioState
  22 +{
  23 + RF_IDLE = 0,
  24 + RF_RX_RUNNING,
  25 + RF_TX_RUNNING,
  26 + RF_CAD,
  27 +}RadioState_t;
  28 +
  29 +/*!
  30 + * Type of the modem. [LORA / FSK]
  31 + */
  32 +typedef enum ModemType
  33 +{
  34 + MODEM_FSK = 0,
  35 + MODEM_LORA
  36 +}RadioModems_t;
  37 +
  38 +/*!
  39 + * Type of the supported board. [SX1276MB1MAS / SX1276MB1LAS]
  40 + */
  41 +typedef enum BoardType
  42 +{
  43 + SX1276MB1MAS = 0,
  44 + SX1276MB1LAS,
  45 + UNKNOWN
  46 +}BoardType_t;
  47 +
  48 +/*!
  49 + * Radio FSK modem parameters
  50 + */
  51 +typedef struct
  52 +{
  53 + int8_t Power;
  54 + uint32_t Fdev;
  55 + uint32_t Bandwidth;
  56 + uint32_t BandwidthAfc;
  57 + uint32_t Datarate;
  58 + uint16_t PreambleLen;
  59 + bool FixLen;
  60 + uint8_t PayloadLen;
  61 + bool CrcOn;
  62 + bool IqInverted;
  63 + bool RxContinuous;
  64 + uint32_t TxTimeout;
  65 +}RadioFskSettings_t;
  66 +
  67 +/*!
  68 + * Radio FSK packet handler state
  69 + */
  70 +typedef struct
  71 +{
  72 + uint8_t PreambleDetected;
  73 + uint8_t SyncWordDetected;
  74 + int8_t RssiValue;
  75 + int32_t AfcValue;
  76 + uint8_t RxGain;
  77 + uint16_t Size;
  78 + uint16_t NbBytes;
  79 + uint8_t FifoThresh;
  80 + uint8_t ChunkSize;
  81 +}RadioFskPacketHandler_t;
  82 +
  83 +/*!
  84 + * Radio LoRa modem parameters
  85 + */
  86 +typedef struct
  87 +{
  88 + int8_t Power;
  89 + uint32_t Bandwidth;
  90 + uint32_t Datarate;
  91 + bool LowDatarateOptimize;
  92 + uint8_t Coderate;
  93 + uint16_t PreambleLen;
  94 + bool FixLen;
  95 + uint8_t PayloadLen;
  96 + bool CrcOn;
  97 + bool FreqHopOn;
  98 + uint8_t HopPeriod;
  99 + bool IqInverted;
  100 + bool RxContinuous;
  101 + uint32_t TxTimeout;
  102 +}RadioLoRaSettings_t;
  103 +
  104 +/*!
  105 + * Radio LoRa packet handler state
  106 + */
  107 +typedef struct
  108 +{
  109 + int8_t SnrValue;
  110 + int8_t RssiValue;
  111 + uint8_t Size;
  112 +}RadioLoRaPacketHandler_t;
  113 +
  114 +/*!
  115 + * Radio Settings
  116 + */
  117 +typedef struct
  118 +{
  119 + RadioState State;
  120 + ModemType Modem;
  121 + uint32_t Channel;
  122 + RadioFskSettings_t Fsk;
  123 + RadioFskPacketHandler_t FskPacketHandler;
  124 + RadioLoRaSettings_t LoRa;
  125 + RadioLoRaPacketHandler_t LoRaPacketHandler;
  126 +}RadioSettings_t;
  127 +
  128 +
  129 +#endif //__ENUMS_H__
... ...
SX1276Lib/radio/radio.cpp 0 → 100644
... ... @@ -0,0 +1,20 @@
  1 +/*
  2 + / _____) _ | |
  3 +( (____ _____ ____ _| |_ _____ ____| |__
  4 + \____ \| ___ | (_ _) ___ |/ ___) _ \
  5 + _____) ) ____| | | || |_| ____( (___| | | |
  6 +(______/|_____)_|_|_| \__)_____)\____)_| |_|
  7 + (C) 2014 Semtech
  8 +
  9 +Description: Interface for the radios, contains the main functions that a radio needs, and 5 callback functions
  10 +
  11 +License: Revised BSD License, see LICENSE.TXT file include in the project
  12 +
  13 +Maintainers: Miguel Luis, Gregory Cristian and Nicolas Huguenin
  14 +*/
  15 +#include "radio.h"
  16 +
  17 +Radio::Radio( RadioEvents_t *events )
  18 +{
  19 + this->RadioEvents = events;
  20 +}
... ...
SX1276Lib/radio/radio.h 0 → 100644
... ... @@ -0,0 +1,346 @@
  1 +/*
  2 + / _____) _ | |
  3 +( (____ _____ ____ _| |_ _____ ____| |__
  4 + \____ \| ___ | (_ _) ___ |/ ___) _ \
  5 + _____) ) ____| | | || |_| ____( (___| | | |
  6 +(______/|_____)_|_|_| \__)_____)\____)_| |_|
  7 + (C) 2014 Semtech
  8 +
  9 +Description: Interface for the radios, contains the main functions that a radio needs, and 5 callback functions
  10 +
  11 +License: Revised BSD License, see LICENSE.TXT file include in the project
  12 +
  13 +Maintainers: Miguel Luis, Gregory Cristian and Nicolas Huguenin
  14 +*/
  15 +#ifndef __RADIO_H__
  16 +#define __RADIO_H__
  17 +
  18 +#include "mbed.h"
  19 +
  20 +#include "./enums/enums.h"
  21 +
  22 +/*!
  23 + * @brief Radio driver callback functions
  24 + */
  25 +typedef struct
  26 +{
  27 + /*!
  28 + * @brief Tx Done callback prototype.
  29 + */
  30 + void ( *TxDone )( void );
  31 + /*!
  32 + * @brief Tx Timeout callback prototype.
  33 + */
  34 + void ( *TxTimeout )( void );
  35 + /*!
  36 + * @brief Rx Done callback prototype.
  37 + *
  38 + * @param [IN] payload Received buffer pointer
  39 + * @param [IN] size Received buffer size
  40 + * @param [IN] rssi RSSI value computed while receiving the frame [dBm]
  41 + * @param [IN] snr Raw SNR value given by the radio hardware
  42 + * FSK : N/A ( set to 0 )
  43 + * LoRa: SNR value in dB
  44 + */
  45 + void ( *RxDone )( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr );
  46 + /*!
  47 + * @brief Rx Timeout callback prototype.
  48 + */
  49 + void ( *RxTimeout )( void );
  50 + /*!
  51 + * @brief Rx Error callback prototype.
  52 + */
  53 + void ( *RxError )( void );
  54 + /*!
  55 + * \brief FHSS Change Channel callback prototype.
  56 + *
  57 + * \param [IN] currentChannel Index number of the current channel
  58 + */
  59 + void ( *FhssChangeChannel )( uint8_t currentChannel );
  60 +
  61 + /*!
  62 + * @brief CAD Done callback prototype.
  63 + *
  64 + * @param [IN] channelDetected Channel Activity detected during the CAD
  65 + */
  66 + void ( *CadDone ) ( bool channelActivityDetected );
  67 +}RadioEvents_t;
  68 +
  69 +/*!
  70 + * Interface for the radios, contains the main functions that a radio needs, and 5 callback functions
  71 + */
  72 +class Radio
  73 +{
  74 +protected:
  75 + RadioEvents_t* RadioEvents;
  76 +
  77 +public:
  78 + //-------------------------------------------------------------------------
  79 + // Constructor
  80 + //-------------------------------------------------------------------------
  81 + /*!
  82 + * @brief Constructor of the radio object, the parameters are the callback functions described in the header.
  83 + *
  84 + * @param [IN] events Structure containing the driver callback functions
  85 + */
  86 + Radio( RadioEvents_t *events );
  87 + virtual ~Radio( ) {};
  88 +
  89 + //-------------------------------------------------------------------------
  90 + // Pure virtual functions
  91 + //-------------------------------------------------------------------------
  92 +
  93 + /*!
  94 + * @brief Initializes the radio
  95 + *
  96 + * @param [IN] events Structure containing the driver callback functions
  97 + */
  98 + virtual void Init( RadioEvents_t *events ) = 0;
  99 +
  100 + /*!
  101 + * @brief Return current radio status
  102 + *
  103 + * @param status Radio status.[RF_IDLE, RF_RX_RUNNING, RF_TX_RUNNING]
  104 + */
  105 + virtual RadioState GetStatus( void ) = 0;
  106 +
  107 + /*!
  108 + * @brief Configures the radio with the given modem
  109 + *
  110 + * @param [IN] modem Modem to be used [0: FSK, 1: LoRa]
  111 + */
  112 + virtual void SetModem( RadioModems_t modem ) = 0;
  113 +
  114 + /*!
  115 + * @brief Sets the channel frequency
  116 + *
  117 + * @param [IN] freq Channel RF frequency
  118 + */
  119 + virtual void SetChannel( uint32_t freq ) = 0;
  120 +
  121 + /*!
  122 + * @brief Sets the channels configuration
  123 + *
  124 + * @param [IN] modem Radio modem to be used [0: FSK, 1: LoRa]
  125 + * @param [IN] freq Channel RF frequency
  126 + * @param [IN] rssiThresh RSSI threshold
  127 + *
  128 + * @retval isFree [true: Channel is free, false: Channel is not free]
  129 + */
  130 + virtual bool IsChannelFree( RadioModems_t modem, uint32_t freq, int16_t rssiThresh ) = 0;
  131 +
  132 + /*!
  133 + * @brief Generates a 32 bits random value based on the RSSI readings
  134 + *
  135 + * \remark This function sets the radio in LoRa modem mode and disables
  136 + * all interrupts.
  137 + * After calling this function either Radio.SetRxConfig or
  138 + * Radio.SetTxConfig functions must be called.
  139 + *
  140 + * @retval randomValue 32 bits random value
  141 + */
  142 + virtual uint32_t Random( void )= 0;
  143 +
  144 + /*!
  145 + * @brief Sets the reception parameters
  146 + *
  147 + * @param [IN] modem Radio modem to be used [0: FSK, 1: LoRa]
  148 + * @param [IN] bandwidth Sets the bandwidth
  149 + * FSK : >= 2600 and <= 250000 Hz
  150 + * LoRa: [0: 125 kHz, 1: 250 kHz,
  151 + * 2: 500 kHz, 3: Reserved]
  152 + * @param [IN] datarate Sets the Datarate
  153 + * FSK : 600..300000 bits/s
  154 + * LoRa: [6: 64, 7: 128, 8: 256, 9: 512,
  155 + * 10: 1024, 11: 2048, 12: 4096 chips]
  156 + * @param [IN] coderate Sets the coding rate ( LoRa only )
  157 + * FSK : N/A ( set to 0 )
  158 + * LoRa: [1: 4/5, 2: 4/6, 3: 4/7, 4: 4/8]
  159 + * @param [IN] bandwidthAfc Sets the AFC Bandwidth ( FSK only )
  160 + * FSK : >= 2600 and <= 250000 Hz
  161 + * LoRa: N/A ( set to 0 )
  162 + * @param [IN] preambleLen Sets the Preamble length ( LoRa only )
  163 + * FSK : N/A ( set to 0 )
  164 + * LoRa: Length in symbols ( the hardware adds 4 more symbols )
  165 + * @param [IN] symbTimeout Sets the RxSingle timeout value ( LoRa only )
  166 + * FSK : N/A ( set to 0 )
  167 + * LoRa: timeout in symbols
  168 + * @param [IN] fixLen Fixed length packets [0: variable, 1: fixed]
  169 + * @param [IN] payloadLen Sets payload length when fixed lenght is used
  170 + * @param [IN] crcOn Enables/Disables the CRC [0: OFF, 1: ON]
  171 + * @param [IN] freqHopOn Enables disables the intra-packet frequency hopping [0: OFF, 1: ON] (LoRa only)
  172 + * @param [IN] hopPeriod Number of symbols bewteen each hop (LoRa only)
  173 + * @param [IN] iqInverted Inverts IQ signals ( LoRa only )
  174 + * FSK : N/A ( set to 0 )
  175 + * LoRa: [0: not inverted, 1: inverted]
  176 + * @param [IN] rxContinuous Sets the reception in continuous mode
  177 + * [false: single mode, true: continuous mode]
  178 + */
  179 + virtual void SetRxConfig ( RadioModems_t modem, uint32_t bandwidth,
  180 + uint32_t datarate, uint8_t coderate,
  181 + uint32_t bandwidthAfc, uint16_t preambleLen,
  182 + uint16_t symbTimeout, bool fixLen,
  183 + uint8_t payloadLen,
  184 + bool crcOn, bool freqHopOn, uint8_t hopPeriod,
  185 + bool iqInverted, bool rxContinuous ) = 0;
  186 +
  187 + /*!
  188 + * @brief Sets the transmission parameters
  189 + *
  190 + * @param [IN] modem Radio modem to be used [0: FSK, 1: LoRa]
  191 + * @param [IN] power Sets the output power [dBm]
  192 + * @param [IN] fdev Sets the frequency deviation ( FSK only )
  193 + * FSK : [Hz]
  194 + * LoRa: 0
  195 + * @param [IN] bandwidth Sets the bandwidth ( LoRa only )
  196 + * FSK : 0
  197 + * LoRa: [0: 125 kHz, 1: 250 kHz,
  198 + * 2: 500 kHz, 3: Reserved]
  199 + * @param [IN] datarate Sets the Datarate
  200 + * FSK : 600..300000 bits/s
  201 + * LoRa: [6: 64, 7: 128, 8: 256, 9: 512,
  202 + * 10: 1024, 11: 2048, 12: 4096 chips]
  203 + * @param [IN] coderate Sets the coding rate ( LoRa only )
  204 + * FSK : N/A ( set to 0 )
  205 + * LoRa: [1: 4/5, 2: 4/6, 3: 4/7, 4: 4/8]
  206 + * @param [IN] preambleLen Sets the preamble length
  207 + * @param [IN] fixLen Fixed length packets [0: variable, 1: fixed]
  208 + * @param [IN] crcOn Enables disables the CRC [0: OFF, 1: ON]
  209 + * @param [IN] freqHopOn Enables disables the intra-packet frequency hopping [0: OFF, 1: ON] (LoRa only)
  210 + * @param [IN] hopPeriod Number of symbols bewteen each hop (LoRa only)
  211 + * @param [IN] iqInverted Inverts IQ signals ( LoRa only )
  212 + * FSK : N/A ( set to 0 )
  213 + * LoRa: [0: not inverted, 1: inverted]
  214 + * @param [IN] timeout Transmission timeout [us]
  215 + */
  216 + virtual void SetTxConfig( RadioModems_t modem, int8_t power, uint32_t fdev,
  217 + uint32_t bandwidth, uint32_t datarate,
  218 + uint8_t coderate, uint16_t preambleLen,
  219 + bool fixLen, bool crcOn, bool freqHopOn,
  220 + uint8_t hopPeriod, bool iqInverted, uint32_t timeout ) = 0;
  221 +
  222 + /*!
  223 + * @brief Checks if the given RF frequency is supported by the hardware
  224 + *
  225 + * @param [IN] frequency RF frequency to be checked
  226 + * @retval isSupported [true: supported, false: unsupported]
  227 + */
  228 + virtual bool CheckRfFrequency( uint32_t frequency ) = 0;
  229 +
  230 + /*!
  231 + * @brief Computes the packet time on air for the given payload
  232 + *
  233 + * \Remark Can only be called once SetRxConfig or SetTxConfig have been called
  234 + *
  235 + * @param [IN] modem Radio modem to be used [0: FSK, 1: LoRa]
  236 + * @param [IN] pktLen Packet payload length
  237 + *
  238 + * @retval airTime Computed airTime for the given packet payload length
  239 + */
  240 + virtual double TimeOnAir ( RadioModems_t modem, uint8_t pktLen ) = 0;
  241 +
  242 + /*!
  243 + * @brief Sends the buffer of size. Prepares the packet to be sent and sets
  244 + * the radio in transmission
  245 + *
  246 + * @param [IN]: buffer Buffer pointer
  247 + * @param [IN]: size Buffer size
  248 + */
  249 + virtual void Send( uint8_t *buffer, uint8_t size ) = 0;
  250 +
  251 + /*!
  252 + * @brief Sets the radio in sleep mode
  253 + */
  254 + virtual void Sleep( void ) = 0;
  255 +
  256 + /*!
  257 + * @brief Sets the radio in standby mode
  258 + */
  259 + virtual void Standby( void ) = 0;
  260 +
  261 + /*!
  262 + * @brief Sets the radio in CAD mode
  263 + */
  264 + virtual void StartCad( void ) = 0;
  265 +
  266 + /*!
  267 + * @brief Sets the radio in reception mode for the given time
  268 + * @param [IN] timeout Reception timeout [us]
  269 + * [0: continuous, others timeout]
  270 + */
  271 + virtual void Rx( uint32_t timeout ) = 0;
  272 +
  273 + /*!
  274 + * @brief Sets the radio in transmission mode for the given time
  275 + * @param [IN] timeout Transmission timeout [us]
  276 + * [0: continuous, others timeout]
  277 + */
  278 + virtual void Tx( uint32_t timeout ) = 0;
  279 +
  280 + /*!
  281 + * @brief Reads the current RSSI value
  282 + *
  283 + * @retval rssiValue Current RSSI value in [dBm]
  284 + */
  285 + virtual int16_t GetRssi ( RadioModems_t modem ) = 0;
  286 +
  287 + /*!
  288 + * @brief Writes the radio register at the specified address
  289 + *
  290 + * @param [IN]: addr Register address
  291 + * @param [IN]: data New register value
  292 + */
  293 + virtual void Write ( uint8_t addr, uint8_t data ) = 0;
  294 +
  295 + /*!
  296 + * @brief Reads the radio register at the specified address
  297 + *
  298 + * @param [IN]: addr Register address
  299 + * @retval data Register value
  300 + */
  301 + virtual uint8_t Read ( uint8_t addr ) = 0;
  302 +
  303 + /*!
  304 + * @brief Writes multiple radio registers starting at address
  305 + *
  306 + * @param [IN] addr First Radio register address
  307 + * @param [IN] buffer Buffer containing the new register's values
  308 + * @param [IN] size Number of registers to be written
  309 + */
  310 + virtual void Write( uint8_t addr, uint8_t *buffer, uint8_t size ) = 0;
  311 +
  312 + /*!
  313 + * @brief Reads multiple radio registers starting at address
  314 + *
  315 + * @param [IN] addr First Radio register address
  316 + * @param [OUT] buffer Buffer where to copy the registers data
  317 + * @param [IN] size Number of registers to be read
  318 + */
  319 + virtual void Read ( uint8_t addr, uint8_t *buffer, uint8_t size ) = 0;
  320 +
  321 + /*!
  322 + * @brief Writes the buffer contents to the SX1276 FIFO
  323 + *
  324 + * @param [IN] buffer Buffer containing data to be put on the FIFO.
  325 + * @param [IN] size Number of bytes to be written to the FIFO
  326 + */
  327 + virtual void WriteFifo( uint8_t *buffer, uint8_t size ) = 0;
  328 +
  329 + /*!
  330 + * @brief Reads the contents of the SX1276 FIFO
  331 + *
  332 + * @param [OUT] buffer Buffer where to copy the FIFO read data.
  333 + * @param [IN] size Number of bytes to be read from the FIFO
  334 + */
  335 + virtual void ReadFifo( uint8_t *buffer, uint8_t size ) = 0;
  336 +
  337 + /*!
  338 + * @brief Sets the maximum payload length.
  339 + *
  340 + * @param [IN] modem Radio modem to be used [0: FSK, 1: LoRa]
  341 + * @param [IN] max Maximum payload length in bytes
  342 + */
  343 + virtual void SetMaxPayloadLength( RadioModems_t modem, uint8_t max ) = 0;
  344 +};
  345 +
  346 +#endif // __RADIO_H__
... ...
SX1276Lib/registers/sx1276Regs-Fsk.h 0 → 100644
... ... @@ -0,0 +1,1128 @@
  1 +/*
  2 + / _____) _ | |
  3 +( (____ _____ ____ _| |_ _____ ____| |__
  4 + \____ \| ___ | (_ _) ___ |/ ___) _ \
  5 + _____) ) ____| | | || |_| ____( (___| | | |
  6 +(______/|_____)_|_|_| \__)_____)\____)_| |_|
  7 + (C) 2014 Semtech
  8 +
  9 +Description: SX1276 FSK modem registers and bits definitions
  10 +
  11 +License: Revised BSD License, see LICENSE.TXT file include in the project
  12 +
  13 +Maintainer: Miguel Luis and Gregory Cristian
  14 +*/
  15 +#ifndef __SX1276_REGS_FSK_H__
  16 +#define __SX1276_REGS_FSK_H__
  17 +
  18 +/*!
  19 + * ============================================================================
  20 + * SX1276 Internal registers Address
  21 + * ============================================================================
  22 + */
  23 +#define REG_FIFO 0x00
  24 +// Common settings
  25 +#define REG_OPMODE 0x01
  26 +#define REG_BITRATEMSB 0x02
  27 +#define REG_BITRATELSB 0x03
  28 +#define REG_FDEVMSB 0x04
  29 +#define REG_FDEVLSB 0x05
  30 +#define REG_FRFMSB 0x06
  31 +#define REG_FRFMID 0x07
  32 +#define REG_FRFLSB 0x08
  33 +// Tx settings
  34 +#define REG_PACONFIG 0x09
  35 +#define REG_PARAMP 0x0A
  36 +#define REG_OCP 0x0B
  37 +// Rx settings
  38 +#define REG_LNA 0x0C
  39 +#define REG_RXCONFIG 0x0D
  40 +#define REG_RSSICONFIG 0x0E
  41 +#define REG_RSSICOLLISION 0x0F
  42 +#define REG_RSSITHRESH 0x10
  43 +#define REG_RSSIVALUE 0x11
  44 +#define REG_RXBW 0x12
  45 +#define REG_AFCBW 0x13
  46 +#define REG_OOKPEAK 0x14
  47 +#define REG_OOKFIX 0x15
  48 +#define REG_OOKAVG 0x16
  49 +#define REG_RES17 0x17
  50 +#define REG_RES18 0x18
  51 +#define REG_RES19 0x19
  52 +#define REG_AFCFEI 0x1A
  53 +#define REG_AFCMSB 0x1B
  54 +#define REG_AFCLSB 0x1C
  55 +#define REG_FEIMSB 0x1D
  56 +#define REG_FEILSB 0x1E
  57 +#define REG_PREAMBLEDETECT 0x1F
  58 +#define REG_RXTIMEOUT1 0x20
  59 +#define REG_RXTIMEOUT2 0x21
  60 +#define REG_RXTIMEOUT3 0x22
  61 +#define REG_RXDELAY 0x23
  62 +// Oscillator settings
  63 +#define REG_OSC 0x24
  64 +// Packet handler settings
  65 +#define REG_PREAMBLEMSB 0x25
  66 +#define REG_PREAMBLELSB 0x26
  67 +#define REG_SYNCCONFIG 0x27
  68 +#define REG_SYNCVALUE1 0x28
  69 +#define REG_SYNCVALUE2 0x29
  70 +#define REG_SYNCVALUE3 0x2A
  71 +#define REG_SYNCVALUE4 0x2B
  72 +#define REG_SYNCVALUE5 0x2C
  73 +#define REG_SYNCVALUE6 0x2D
  74 +#define REG_SYNCVALUE7 0x2E
  75 +#define REG_SYNCVALUE8 0x2F
  76 +#define REG_PACKETCONFIG1 0x30
  77 +#define REG_PACKETCONFIG2 0x31
  78 +#define REG_PAYLOADLENGTH 0x32
  79 +#define REG_NODEADRS 0x33
  80 +#define REG_BROADCASTADRS 0x34
  81 +#define REG_FIFOTHRESH 0x35
  82 +// SM settings
  83 +#define REG_SEQCONFIG1 0x36
  84 +#define REG_SEQCONFIG2 0x37
  85 +#define REG_TIMERRESOL 0x38
  86 +#define REG_TIMER1COEF 0x39
  87 +#define REG_TIMER2COEF 0x3A
  88 +// Service settings
  89 +#define REG_IMAGECAL 0x3B
  90 +#define REG_TEMP 0x3C
  91 +#define REG_LOWBAT 0x3D
  92 +// Status
  93 +#define REG_IRQFLAGS1 0x3E
  94 +#define REG_IRQFLAGS2 0x3F
  95 +// I/O settings
  96 +#define REG_DIOMAPPING1 0x40
  97 +#define REG_DIOMAPPING2 0x41
  98 +// Version
  99 +#define REG_VERSION 0x42
  100 +// Additional settings
  101 +#define REG_PLLHOP 0x44
  102 +#define REG_TCXO 0x4B
  103 +#define REG_PADAC 0x4D
  104 +#define REG_FORMERTEMP 0x5B
  105 +#define REG_BITRATEFRAC 0x5D
  106 +#define REG_AGCREF 0x61
  107 +#define REG_AGCTHRESH1 0x62
  108 +#define REG_AGCTHRESH2 0x63
  109 +#define REG_AGCTHRESH3 0x64
  110 +#define REG_PLL 0x70
  111 +
  112 +/*!
  113 + * ============================================================================
  114 + * SX1276 FSK bits control definition
  115 + * ============================================================================
  116 + */
  117 +
  118 +/*!
  119 + * RegFifo
  120 + */
  121 +
  122 +/*!
  123 + * RegOpMode
  124 + */
  125 +#define RF_OPMODE_LONGRANGEMODE_MASK 0x7F
  126 +#define RF_OPMODE_LONGRANGEMODE_OFF 0x00
  127 +#define RF_OPMODE_LONGRANGEMODE_ON 0x80
  128 +
  129 +#define RF_OPMODE_MODULATIONTYPE_MASK 0x9F
  130 +#define RF_OPMODE_MODULATIONTYPE_FSK 0x00 // Default
  131 +#define RF_OPMODE_MODULATIONTYPE_OOK 0x20
  132 +
  133 +#define RF_OPMODE_MODULATIONSHAPING_MASK 0xE7
  134 +#define RF_OPMODE_MODULATIONSHAPING_00 0x00 // Default
  135 +#define RF_OPMODE_MODULATIONSHAPING_01 0x08
  136 +#define RF_OPMODE_MODULATIONSHAPING_10 0x10
  137 +#define RF_OPMODE_MODULATIONSHAPING_11 0x18
  138 +
  139 +#define RF_OPMODE_MASK 0xF8
  140 +#define RF_OPMODE_SLEEP 0x00
  141 +#define RF_OPMODE_STANDBY 0x01 // Default
  142 +#define RF_OPMODE_SYNTHESIZER_TX 0x02
  143 +#define RF_OPMODE_TRANSMITTER 0x03
  144 +#define RF_OPMODE_SYNTHESIZER_RX 0x04
  145 +#define RF_OPMODE_RECEIVER 0x05
  146 +
  147 +/*!
  148 + * RegBitRate (bits/sec)
  149 + */
  150 +#define RF_BITRATEMSB_1200_BPS 0x68
  151 +#define RF_BITRATELSB_1200_BPS 0x2B
  152 +#define RF_BITRATEMSB_2400_BPS 0x34
  153 +#define RF_BITRATELSB_2400_BPS 0x15
  154 +#define RF_BITRATEMSB_4800_BPS 0x1A // Default
  155 +#define RF_BITRATELSB_4800_BPS 0x0B // Default
  156 +#define RF_BITRATEMSB_9600_BPS 0x0D
  157 +#define RF_BITRATELSB_9600_BPS 0x05
  158 +#define RF_BITRATEMSB_15000_BPS 0x08
  159 +#define RF_BITRATELSB_15000_BPS 0x55
  160 +#define RF_BITRATEMSB_19200_BPS 0x06
  161 +#define RF_BITRATELSB_19200_BPS 0x83
  162 +#define RF_BITRATEMSB_38400_BPS 0x03
  163 +#define RF_BITRATELSB_38400_BPS 0x41
  164 +#define RF_BITRATEMSB_76800_BPS 0x01
  165 +#define RF_BITRATELSB_76800_BPS 0xA1
  166 +#define RF_BITRATEMSB_153600_BPS 0x00
  167 +#define RF_BITRATELSB_153600_BPS 0xD0
  168 +#define RF_BITRATEMSB_57600_BPS 0x02
  169 +#define RF_BITRATELSB_57600_BPS 0x2C
  170 +#define RF_BITRATEMSB_115200_BPS 0x01
  171 +#define RF_BITRATELSB_115200_BPS 0x16
  172 +#define RF_BITRATEMSB_12500_BPS 0x0A
  173 +#define RF_BITRATELSB_12500_BPS 0x00
  174 +#define RF_BITRATEMSB_25000_BPS 0x05
  175 +#define RF_BITRATELSB_25000_BPS 0x00
  176 +#define RF_BITRATEMSB_50000_BPS 0x02
  177 +#define RF_BITRATELSB_50000_BPS 0x80
  178 +#define RF_BITRATEMSB_100000_BPS 0x01
  179 +#define RF_BITRATELSB_100000_BPS 0x40
  180 +#define RF_BITRATEMSB_150000_BPS 0x00
  181 +#define RF_BITRATELSB_150000_BPS 0xD5
  182 +#define RF_BITRATEMSB_200000_BPS 0x00
  183 +#define RF_BITRATELSB_200000_BPS 0xA0
  184 +#define RF_BITRATEMSB_250000_BPS 0x00
  185 +#define RF_BITRATELSB_250000_BPS 0x80
  186 +#define RF_BITRATEMSB_32768_BPS 0x03
  187 +#define RF_BITRATELSB_32768_BPS 0xD1
  188 +
  189 +/*!
  190 + * RegFdev (Hz)
  191 + */
  192 +#define RF_FDEVMSB_2000_HZ 0x00
  193 +#define RF_FDEVLSB_2000_HZ 0x21
  194 +#define RF_FDEVMSB_5000_HZ 0x00 // Default
  195 +#define RF_FDEVLSB_5000_HZ 0x52 // Default
  196 +#define RF_FDEVMSB_10000_HZ 0x00
  197 +#define RF_FDEVLSB_10000_HZ 0xA4
  198 +#define RF_FDEVMSB_15000_HZ 0x00
  199 +#define RF_FDEVLSB_15000_HZ 0xF6
  200 +#define RF_FDEVMSB_20000_HZ 0x01
  201 +#define RF_FDEVLSB_20000_HZ 0x48
  202 +#define RF_FDEVMSB_25000_HZ 0x01
  203 +#define RF_FDEVLSB_25000_HZ 0x9A
  204 +#define RF_FDEVMSB_30000_HZ 0x01
  205 +#define RF_FDEVLSB_30000_HZ 0xEC
  206 +#define RF_FDEVMSB_35000_HZ 0x02
  207 +#define RF_FDEVLSB_35000_HZ 0x3D
  208 +#define RF_FDEVMSB_40000_HZ 0x02
  209 +#define RF_FDEVLSB_40000_HZ 0x8F
  210 +#define RF_FDEVMSB_45000_HZ 0x02
  211 +#define RF_FDEVLSB_45000_HZ 0xE1
  212 +#define RF_FDEVMSB_50000_HZ 0x03
  213 +#define RF_FDEVLSB_50000_HZ 0x33
  214 +#define RF_FDEVMSB_55000_HZ 0x03
  215 +#define RF_FDEVLSB_55000_HZ 0x85
  216 +#define RF_FDEVMSB_60000_HZ 0x03
  217 +#define RF_FDEVLSB_60000_HZ 0xD7
  218 +#define RF_FDEVMSB_65000_HZ 0x04
  219 +#define RF_FDEVLSB_65000_HZ 0x29
  220 +#define RF_FDEVMSB_70000_HZ 0x04
  221 +#define RF_FDEVLSB_70000_HZ 0x7B
  222 +#define RF_FDEVMSB_75000_HZ 0x04
  223 +#define RF_FDEVLSB_75000_HZ 0xCD
  224 +#define RF_FDEVMSB_80000_HZ 0x05
  225 +#define RF_FDEVLSB_80000_HZ 0x1F
  226 +#define RF_FDEVMSB_85000_HZ 0x05
  227 +#define RF_FDEVLSB_85000_HZ 0x71
  228 +#define RF_FDEVMSB_90000_HZ 0x05
  229 +#define RF_FDEVLSB_90000_HZ 0xC3
  230 +#define RF_FDEVMSB_95000_HZ 0x06
  231 +#define RF_FDEVLSB_95000_HZ 0x14
  232 +#define RF_FDEVMSB_100000_HZ 0x06
  233 +#define RF_FDEVLSB_100000_HZ 0x66
  234 +#define RF_FDEVMSB_110000_HZ 0x07
  235 +#define RF_FDEVLSB_110000_HZ 0x0A
  236 +#define RF_FDEVMSB_120000_HZ 0x07
  237 +#define RF_FDEVLSB_120000_HZ 0xAE
  238 +#define RF_FDEVMSB_130000_HZ 0x08
  239 +#define RF_FDEVLSB_130000_HZ 0x52
  240 +#define RF_FDEVMSB_140000_HZ 0x08
  241 +#define RF_FDEVLSB_140000_HZ 0xF6
  242 +#define RF_FDEVMSB_150000_HZ 0x09
  243 +#define RF_FDEVLSB_150000_HZ 0x9A
  244 +#define RF_FDEVMSB_160000_HZ 0x0A
  245 +#define RF_FDEVLSB_160000_HZ 0x3D
  246 +#define RF_FDEVMSB_170000_HZ 0x0A
  247 +#define RF_FDEVLSB_170000_HZ 0xE1
  248 +#define RF_FDEVMSB_180000_HZ 0x0B
  249 +#define RF_FDEVLSB_180000_HZ 0x85
  250 +#define RF_FDEVMSB_190000_HZ 0x0C
  251 +#define RF_FDEVLSB_190000_HZ 0x29
  252 +#define RF_FDEVMSB_200000_HZ 0x0C
  253 +#define RF_FDEVLSB_200000_HZ 0xCD
  254 +
  255 +/*!
  256 + * RegFrf (MHz)
  257 + */
  258 +#define RF_FRFMSB_863_MHZ 0xD7
  259 +#define RF_FRFMID_863_MHZ 0xC0
  260 +#define RF_FRFLSB_863_MHZ 0x00
  261 +#define RF_FRFMSB_864_MHZ 0xD8
  262 +#define RF_FRFMID_864_MHZ 0x00
  263 +#define RF_FRFLSB_864_MHZ 0x00
  264 +#define RF_FRFMSB_865_MHZ 0xD8
  265 +#define RF_FRFMID_865_MHZ 0x40
  266 +#define RF_FRFLSB_865_MHZ 0x00
  267 +#define RF_FRFMSB_866_MHZ 0xD8
  268 +#define RF_FRFMID_866_MHZ 0x80
  269 +#define RF_FRFLSB_866_MHZ 0x00
  270 +#define RF_FRFMSB_867_MHZ 0xD8
  271 +#define RF_FRFMID_867_MHZ 0xC0
  272 +#define RF_FRFLSB_867_MHZ 0x00
  273 +#define RF_FRFMSB_868_MHZ 0xD9
  274 +#define RF_FRFMID_868_MHZ 0x00
  275 +#define RF_FRFLSB_868_MHZ 0x00
  276 +#define RF_FRFMSB_869_MHZ 0xD9
  277 +#define RF_FRFMID_869_MHZ 0x40
  278 +#define RF_FRFLSB_869_MHZ 0x00
  279 +#define RF_FRFMSB_870_MHZ 0xD9
  280 +#define RF_FRFMID_870_MHZ 0x80
  281 +#define RF_FRFLSB_870_MHZ 0x00
  282 +
  283 +#define RF_FRFMSB_902_MHZ 0xE1
  284 +#define RF_FRFMID_902_MHZ 0x80
  285 +#define RF_FRFLSB_902_MHZ 0x00
  286 +#define RF_FRFMSB_903_MHZ 0xE1
  287 +#define RF_FRFMID_903_MHZ 0xC0
  288 +#define RF_FRFLSB_903_MHZ 0x00
  289 +#define RF_FRFMSB_904_MHZ 0xE2
  290 +#define RF_FRFMID_904_MHZ 0x00
  291 +#define RF_FRFLSB_904_MHZ 0x00
  292 +#define RF_FRFMSB_905_MHZ 0xE2
  293 +#define RF_FRFMID_905_MHZ 0x40
  294 +#define RF_FRFLSB_905_MHZ 0x00
  295 +#define RF_FRFMSB_906_MHZ 0xE2
  296 +#define RF_FRFMID_906_MHZ 0x80
  297 +#define RF_FRFLSB_906_MHZ 0x00
  298 +#define RF_FRFMSB_907_MHZ 0xE2
  299 +#define RF_FRFMID_907_MHZ 0xC0
  300 +#define RF_FRFLSB_907_MHZ 0x00
  301 +#define RF_FRFMSB_908_MHZ 0xE3
  302 +#define RF_FRFMID_908_MHZ 0x00
  303 +#define RF_FRFLSB_908_MHZ 0x00
  304 +#define RF_FRFMSB_909_MHZ 0xE3
  305 +#define RF_FRFMID_909_MHZ 0x40
  306 +#define RF_FRFLSB_909_MHZ 0x00
  307 +#define RF_FRFMSB_910_MHZ 0xE3
  308 +#define RF_FRFMID_910_MHZ 0x80
  309 +#define RF_FRFLSB_910_MHZ 0x00
  310 +#define RF_FRFMSB_911_MHZ 0xE3
  311 +#define RF_FRFMID_911_MHZ 0xC0
  312 +#define RF_FRFLSB_911_MHZ 0x00
  313 +#define RF_FRFMSB_912_MHZ 0xE4
  314 +#define RF_FRFMID_912_MHZ 0x00
  315 +#define RF_FRFLSB_912_MHZ 0x00
  316 +#define RF_FRFMSB_913_MHZ 0xE4
  317 +#define RF_FRFMID_913_MHZ 0x40
  318 +#define RF_FRFLSB_913_MHZ 0x00
  319 +#define RF_FRFMSB_914_MHZ 0xE4
  320 +#define RF_FRFMID_914_MHZ 0x80
  321 +#define RF_FRFLSB_914_MHZ 0x00
  322 +#define RF_FRFMSB_915_MHZ 0xE4 // Default
  323 +#define RF_FRFMID_915_MHZ 0xC0 // Default
  324 +#define RF_FRFLSB_915_MHZ 0x00 // Default
  325 +#define RF_FRFMSB_916_MHZ 0xE5
  326 +#define RF_FRFMID_916_MHZ 0x00
  327 +#define RF_FRFLSB_916_MHZ 0x00
  328 +#define RF_FRFMSB_917_MHZ 0xE5
  329 +#define RF_FRFMID_917_MHZ 0x40
  330 +#define RF_FRFLSB_917_MHZ 0x00
  331 +#define RF_FRFMSB_918_MHZ 0xE5
  332 +#define RF_FRFMID_918_MHZ 0x80
  333 +#define RF_FRFLSB_918_MHZ 0x00
  334 +#define RF_FRFMSB_919_MHZ 0xE5
  335 +#define RF_FRFMID_919_MHZ 0xC0
  336 +#define RF_FRFLSB_919_MHZ 0x00
  337 +#define RF_FRFMSB_920_MHZ 0xE6
  338 +#define RF_FRFMID_920_MHZ 0x00
  339 +#define RF_FRFLSB_920_MHZ 0x00
  340 +#define RF_FRFMSB_921_MHZ 0xE6
  341 +#define RF_FRFMID_921_MHZ 0x40
  342 +#define RF_FRFLSB_921_MHZ 0x00
  343 +#define RF_FRFMSB_922_MHZ 0xE6
  344 +#define RF_FRFMID_922_MHZ 0x80
  345 +#define RF_FRFLSB_922_MHZ 0x00
  346 +#define RF_FRFMSB_923_MHZ 0xE6
  347 +#define RF_FRFMID_923_MHZ 0xC0
  348 +#define RF_FRFLSB_923_MHZ 0x00
  349 +#define RF_FRFMSB_924_MHZ 0xE7
  350 +#define RF_FRFMID_924_MHZ 0x00
  351 +#define RF_FRFLSB_924_MHZ 0x00
  352 +#define RF_FRFMSB_925_MHZ 0xE7
  353 +#define RF_FRFMID_925_MHZ 0x40
  354 +#define RF_FRFLSB_925_MHZ 0x00
  355 +#define RF_FRFMSB_926_MHZ 0xE7
  356 +#define RF_FRFMID_926_MHZ 0x80
  357 +#define RF_FRFLSB_926_MHZ 0x00
  358 +#define RF_FRFMSB_927_MHZ 0xE7
  359 +#define RF_FRFMID_927_MHZ 0xC0
  360 +#define RF_FRFLSB_927_MHZ 0x00
  361 +#define RF_FRFMSB_928_MHZ 0xE8
  362 +#define RF_FRFMID_928_MHZ 0x00
  363 +#define RF_FRFLSB_928_MHZ 0x00
  364 +
  365 +/*!
  366 + * RegPaConfig
  367 + */
  368 +#define RF_PACONFIG_PASELECT_MASK 0x7F
  369 +#define RF_PACONFIG_PASELECT_PABOOST 0x80
  370 +#define RF_PACONFIG_PASELECT_RFO 0x00 // Default
  371 +
  372 +#define RF_PACONFIG_MAX_POWER_MASK 0x8F
  373 +
  374 +#define RF_PACONFIG_OUTPUTPOWER_MASK 0xF0
  375 +
  376 +/*!
  377 + * RegPaRamp
  378 + */
  379 +#define RF_PARAMP_LOWPNTXPLL_MASK 0xE0
  380 +#define RF_PARAMP_LOWPNTXPLL_OFF 0x10 // Default
  381 +#define RF_PARAMP_LOWPNTXPLL_ON 0x00
  382 +
  383 +#define RF_PARAMP_MASK 0xF0
  384 +#define RF_PARAMP_3400_US 0x00
  385 +#define RF_PARAMP_2000_US 0x01
  386 +#define RF_PARAMP_1000_US 0x02
  387 +#define RF_PARAMP_0500_US 0x03
  388 +#define RF_PARAMP_0250_US 0x04
  389 +#define RF_PARAMP_0125_US 0x05
  390 +#define RF_PARAMP_0100_US 0x06
  391 +#define RF_PARAMP_0062_US 0x07
  392 +#define RF_PARAMP_0050_US 0x08
  393 +#define RF_PARAMP_0040_US 0x09 // Default
  394 +#define RF_PARAMP_0031_US 0x0A
  395 +#define RF_PARAMP_0025_US 0x0B
  396 +#define RF_PARAMP_0020_US 0x0C
  397 +#define RF_PARAMP_0015_US 0x0D
  398 +#define RF_PARAMP_0012_US 0x0E
  399 +#define RF_PARAMP_0010_US 0x0F
  400 +
  401 +/*!
  402 + * RegOcp
  403 + */
  404 +#define RF_OCP_MASK 0xDF
  405 +#define RF_OCP_ON 0x20 // Default
  406 +#define RF_OCP_OFF 0x00
  407 +
  408 +#define RF_OCP_TRIM_MASK 0xE0
  409 +#define RF_OCP_TRIM_045_MA 0x00
  410 +#define RF_OCP_TRIM_050_MA 0x01
  411 +#define RF_OCP_TRIM_055_MA 0x02
  412 +#define RF_OCP_TRIM_060_MA 0x03
  413 +#define RF_OCP_TRIM_065_MA 0x04
  414 +#define RF_OCP_TRIM_070_MA 0x05
  415 +#define RF_OCP_TRIM_075_MA 0x06
  416 +#define RF_OCP_TRIM_080_MA 0x07
  417 +#define RF_OCP_TRIM_085_MA 0x08
  418 +#define RF_OCP_TRIM_090_MA 0x09
  419 +#define RF_OCP_TRIM_095_MA 0x0A
  420 +#define RF_OCP_TRIM_100_MA 0x0B // Default
  421 +#define RF_OCP_TRIM_105_MA 0x0C
  422 +#define RF_OCP_TRIM_110_MA 0x0D
  423 +#define RF_OCP_TRIM_115_MA 0x0E
  424 +#define RF_OCP_TRIM_120_MA 0x0F
  425 +#define RF_OCP_TRIM_130_MA 0x10
  426 +#define RF_OCP_TRIM_140_MA 0x11
  427 +#define RF_OCP_TRIM_150_MA 0x12
  428 +#define RF_OCP_TRIM_160_MA 0x13
  429 +#define RF_OCP_TRIM_170_MA 0x14
  430 +#define RF_OCP_TRIM_180_MA 0x15
  431 +#define RF_OCP_TRIM_190_MA 0x16
  432 +#define RF_OCP_TRIM_200_MA 0x17
  433 +#define RF_OCP_TRIM_210_MA 0x18
  434 +#define RF_OCP_TRIM_220_MA 0x19
  435 +#define RF_OCP_TRIM_230_MA 0x1A
  436 +#define RF_OCP_TRIM_240_MA 0x1B
  437 +
  438 +/*!
  439 + * RegLna
  440 + */
  441 +#define RF_LNA_GAIN_MASK 0x1F
  442 +#define RF_LNA_GAIN_G1 0x20 // Default
  443 +#define RF_LNA_GAIN_G2 0x40
  444 +#define RF_LNA_GAIN_G3 0x60
  445 +#define RF_LNA_GAIN_G4 0x80
  446 +#define RF_LNA_GAIN_G5 0xA0
  447 +#define RF_LNA_GAIN_G6 0xC0
  448 +
  449 +#define RF_LNA_BOOST_MASK 0xFC
  450 +#define RF_LNA_BOOST_OFF 0x00 // Default
  451 +#define RF_LNA_BOOST_ON 0x03
  452 +
  453 +/*!
  454 + * RegRxConfig
  455 + */
  456 +#define RF_RXCONFIG_RESTARTRXONCOLLISION_MASK 0x7F
  457 +#define RF_RXCONFIG_RESTARTRXONCOLLISION_ON 0x80
  458 +#define RF_RXCONFIG_RESTARTRXONCOLLISION_OFF 0x00 // Default
  459 +
  460 +#define RF_RXCONFIG_RESTARTRXWITHOUTPLLLOCK 0x40 // Write only
  461 +
  462 +#define RF_RXCONFIG_RESTARTRXWITHPLLLOCK 0x20 // Write only
  463 +
  464 +#define RF_RXCONFIG_AFCAUTO_MASK 0xEF
  465 +#define RF_RXCONFIG_AFCAUTO_ON 0x10
  466 +#define RF_RXCONFIG_AFCAUTO_OFF 0x00 // Default
  467 +
  468 +#define RF_RXCONFIG_AGCAUTO_MASK 0xF7
  469 +#define RF_RXCONFIG_AGCAUTO_ON 0x08 // Default
  470 +#define RF_RXCONFIG_AGCAUTO_OFF 0x00
  471 +
  472 +#define RF_RXCONFIG_RXTRIGER_MASK 0xF8
  473 +#define RF_RXCONFIG_RXTRIGER_OFF 0x00
  474 +#define RF_RXCONFIG_RXTRIGER_RSSI 0x01
  475 +#define RF_RXCONFIG_RXTRIGER_PREAMBLEDETECT 0x06 // Default
  476 +#define RF_RXCONFIG_RXTRIGER_RSSI_PREAMBLEDETECT 0x07
  477 +
  478 +/*!
  479 + * RegRssiConfig
  480 + */
  481 +#define RF_RSSICONFIG_OFFSET_MASK 0x07
  482 +#define RF_RSSICONFIG_OFFSET_P_00_DB 0x00 // Default
  483 +#define RF_RSSICONFIG_OFFSET_P_01_DB 0x08
  484 +#define RF_RSSICONFIG_OFFSET_P_02_DB 0x10
  485 +#define RF_RSSICONFIG_OFFSET_P_03_DB 0x18
  486 +#define RF_RSSICONFIG_OFFSET_P_04_DB 0x20
  487 +#define RF_RSSICONFIG_OFFSET_P_05_DB 0x28
  488 +#define RF_RSSICONFIG_OFFSET_P_06_DB 0x30
  489 +#define RF_RSSICONFIG_OFFSET_P_07_DB 0x38
  490 +#define RF_RSSICONFIG_OFFSET_P_08_DB 0x40
  491 +#define RF_RSSICONFIG_OFFSET_P_09_DB 0x48
  492 +#define RF_RSSICONFIG_OFFSET_P_10_DB 0x50
  493 +#define RF_RSSICONFIG_OFFSET_P_11_DB 0x58
  494 +#define RF_RSSICONFIG_OFFSET_P_12_DB 0x60
  495 +#define RF_RSSICONFIG_OFFSET_P_13_DB 0x68
  496 +#define RF_RSSICONFIG_OFFSET_P_14_DB 0x70
  497 +#define RF_RSSICONFIG_OFFSET_P_15_DB 0x78
  498 +#define RF_RSSICONFIG_OFFSET_M_16_DB 0x80
  499 +#define RF_RSSICONFIG_OFFSET_M_15_DB 0x88
  500 +#define RF_RSSICONFIG_OFFSET_M_14_DB 0x90
  501 +#define RF_RSSICONFIG_OFFSET_M_13_DB 0x98
  502 +#define RF_RSSICONFIG_OFFSET_M_12_DB 0xA0
  503 +#define RF_RSSICONFIG_OFFSET_M_11_DB 0xA8
  504 +#define RF_RSSICONFIG_OFFSET_M_10_DB 0xB0
  505 +#define RF_RSSICONFIG_OFFSET_M_09_DB 0xB8
  506 +#define RF_RSSICONFIG_OFFSET_M_08_DB 0xC0
  507 +#define RF_RSSICONFIG_OFFSET_M_07_DB 0xC8
  508 +#define RF_RSSICONFIG_OFFSET_M_06_DB 0xD0
  509 +#define RF_RSSICONFIG_OFFSET_M_05_DB 0xD8
  510 +#define RF_RSSICONFIG_OFFSET_M_04_DB 0xE0
  511 +#define RF_RSSICONFIG_OFFSET_M_03_DB 0xE8
  512 +#define RF_RSSICONFIG_OFFSET_M_02_DB 0xF0
  513 +#define RF_RSSICONFIG_OFFSET_M_01_DB 0xF8
  514 +
  515 +#define RF_RSSICONFIG_SMOOTHING_MASK 0xF8
  516 +#define RF_RSSICONFIG_SMOOTHING_2 0x00
  517 +#define RF_RSSICONFIG_SMOOTHING_4 0x01
  518 +#define RF_RSSICONFIG_SMOOTHING_8 0x02 // Default
  519 +#define RF_RSSICONFIG_SMOOTHING_16 0x03
  520 +#define RF_RSSICONFIG_SMOOTHING_32 0x04
  521 +#define RF_RSSICONFIG_SMOOTHING_64 0x05
  522 +#define RF_RSSICONFIG_SMOOTHING_128 0x06
  523 +#define RF_RSSICONFIG_SMOOTHING_256 0x07
  524 +
  525 +/*!
  526 + * RegRssiCollision
  527 + */
  528 +#define RF_RSSICOLISION_THRESHOLD 0x0A // Default
  529 +
  530 +/*!
  531 + * RegRssiThresh
  532 + */
  533 +#define RF_RSSITHRESH_THRESHOLD 0xFF // Default
  534 +
  535 +/*!
  536 + * RegRssiValue (Read Only)
  537 + */
  538 +
  539 +/*!
  540 + * RegRxBw
  541 + */
  542 +#define RF_RXBW_MANT_MASK 0xE7
  543 +#define RF_RXBW_MANT_16 0x00
  544 +#define RF_RXBW_MANT_20 0x08
  545 +#define RF_RXBW_MANT_24 0x10 // Default
  546 +
  547 +#define RF_RXBW_EXP_MASK 0xF8
  548 +#define RF_RXBW_EXP_0 0x00
  549 +#define RF_RXBW_EXP_1 0x01
  550 +#define RF_RXBW_EXP_2 0x02
  551 +#define RF_RXBW_EXP_3 0x03
  552 +#define RF_RXBW_EXP_4 0x04
  553 +#define RF_RXBW_EXP_5 0x05 // Default
  554 +#define RF_RXBW_EXP_6 0x06
  555 +#define RF_RXBW_EXP_7 0x07
  556 +
  557 +/*!
  558 + * RegAfcBw
  559 + */
  560 +#define RF_AFCBW_MANTAFC_MASK 0xE7
  561 +#define RF_AFCBW_MANTAFC_16 0x00
  562 +#define RF_AFCBW_MANTAFC_20 0x08 // Default
  563 +#define RF_AFCBW_MANTAFC_24 0x10
  564 +
  565 +#define RF_AFCBW_EXPAFC_MASK 0xF8
  566 +#define RF_AFCBW_EXPAFC_0 0x00
  567 +#define RF_AFCBW_EXPAFC_1 0x01
  568 +#define RF_AFCBW_EXPAFC_2 0x02
  569 +#define RF_AFCBW_EXPAFC_3 0x03 // Default
  570 +#define RF_AFCBW_EXPAFC_4 0x04
  571 +#define RF_AFCBW_EXPAFC_5 0x05
  572 +#define RF_AFCBW_EXPAFC_6 0x06
  573 +#define RF_AFCBW_EXPAFC_7 0x07
  574 +
  575 +/*!
  576 + * RegOokPeak
  577 + */
  578 +#define RF_OOKPEAK_BITSYNC_MASK 0xDF // Default
  579 +#define RF_OOKPEAK_BITSYNC_ON 0x20 // Default
  580 +#define RF_OOKPEAK_BITSYNC_OFF 0x00
  581 +
  582 +#define RF_OOKPEAK_OOKTHRESHTYPE_MASK 0xE7
  583 +#define RF_OOKPEAK_OOKTHRESHTYPE_FIXED 0x00
  584 +#define RF_OOKPEAK_OOKTHRESHTYPE_PEAK 0x08 // Default
  585 +#define RF_OOKPEAK_OOKTHRESHTYPE_AVERAGE 0x10
  586 +
  587 +#define RF_OOKPEAK_OOKPEAKTHRESHSTEP_MASK 0xF8
  588 +#define RF_OOKPEAK_OOKPEAKTHRESHSTEP_0_5_DB 0x00 // Default
  589 +#define RF_OOKPEAK_OOKPEAKTHRESHSTEP_1_0_DB 0x01
  590 +#define RF_OOKPEAK_OOKPEAKTHRESHSTEP_1_5_DB 0x02
  591 +#define RF_OOKPEAK_OOKPEAKTHRESHSTEP_2_0_DB 0x03
  592 +#define RF_OOKPEAK_OOKPEAKTHRESHSTEP_3_0_DB 0x04
  593 +#define RF_OOKPEAK_OOKPEAKTHRESHSTEP_4_0_DB 0x05
  594 +#define RF_OOKPEAK_OOKPEAKTHRESHSTEP_5_0_DB 0x06
  595 +#define RF_OOKPEAK_OOKPEAKTHRESHSTEP_6_0_DB 0x07
  596 +
  597 +/*!
  598 + * RegOokFix
  599 + */
  600 +#define RF_OOKFIX_OOKFIXEDTHRESHOLD 0x0C // Default
  601 +
  602 +/*!
  603 + * RegOokAvg
  604 + */
  605 +#define RF_OOKAVG_OOKPEAKTHRESHDEC_MASK 0x1F
  606 +#define RF_OOKAVG_OOKPEAKTHRESHDEC_000 0x00 // Default
  607 +#define RF_OOKAVG_OOKPEAKTHRESHDEC_001 0x20
  608 +#define RF_OOKAVG_OOKPEAKTHRESHDEC_010 0x40
  609 +#define RF_OOKAVG_OOKPEAKTHRESHDEC_011 0x60
  610 +#define RF_OOKAVG_OOKPEAKTHRESHDEC_100 0x80
  611 +#define RF_OOKAVG_OOKPEAKTHRESHDEC_101 0xA0
  612 +#define RF_OOKAVG_OOKPEAKTHRESHDEC_110 0xC0
  613 +#define RF_OOKAVG_OOKPEAKTHRESHDEC_111 0xE0
  614 +
  615 +#define RF_OOKAVG_AVERAGEOFFSET_MASK 0xF3
  616 +#define RF_OOKAVG_AVERAGEOFFSET_0_DB 0x00 // Default
  617 +#define RF_OOKAVG_AVERAGEOFFSET_2_DB 0x04
  618 +#define RF_OOKAVG_AVERAGEOFFSET_4_DB 0x08
  619 +#define RF_OOKAVG_AVERAGEOFFSET_6_DB 0x0C
  620 +
  621 +#define RF_OOKAVG_OOKAVERAGETHRESHFILT_MASK 0xFC
  622 +#define RF_OOKAVG_OOKAVERAGETHRESHFILT_00 0x00
  623 +#define RF_OOKAVG_OOKAVERAGETHRESHFILT_01 0x01
  624 +#define RF_OOKAVG_OOKAVERAGETHRESHFILT_10 0x02 // Default
  625 +#define RF_OOKAVG_OOKAVERAGETHRESHFILT_11 0x03
  626 +
  627 +/*!
  628 + * RegAfcFei
  629 + */
  630 +#define RF_AFCFEI_AGCSTART 0x10
  631 +
  632 +#define RF_AFCFEI_AFCCLEAR 0x02
  633 +
  634 +#define RF_AFCFEI_AFCAUTOCLEAR_MASK 0xFE
  635 +#define RF_AFCFEI_AFCAUTOCLEAR_ON 0x01
  636 +#define RF_AFCFEI_AFCAUTOCLEAR_OFF 0x00 // Default
  637 +
  638 +/*!
  639 + * RegAfcMsb (Read Only)
  640 + */
  641 +
  642 +/*!
  643 + * RegAfcLsb (Read Only)
  644 + */
  645 +
  646 +/*!
  647 + * RegFeiMsb (Read Only)
  648 + */
  649 +
  650 +/*!
  651 + * RegFeiLsb (Read Only)
  652 + */
  653 +
  654 +/*!
  655 + * RegPreambleDetect
  656 + */
  657 +#define RF_PREAMBLEDETECT_DETECTOR_MASK 0x7F
  658 +#define RF_PREAMBLEDETECT_DETECTOR_ON 0x80 // Default
  659 +#define RF_PREAMBLEDETECT_DETECTOR_OFF 0x00
  660 +
  661 +#define RF_PREAMBLEDETECT_DETECTORSIZE_MASK 0x9F
  662 +#define RF_PREAMBLEDETECT_DETECTORSIZE_1 0x00
  663 +#define RF_PREAMBLEDETECT_DETECTORSIZE_2 0x20 // Default
  664 +#define RF_PREAMBLEDETECT_DETECTORSIZE_3 0x40
  665 +#define RF_PREAMBLEDETECT_DETECTORSIZE_4 0x60
  666 +
  667 +#define RF_PREAMBLEDETECT_DETECTORTOL_MASK 0xE0
  668 +#define RF_PREAMBLEDETECT_DETECTORTOL_0 0x00
  669 +#define RF_PREAMBLEDETECT_DETECTORTOL_1 0x01
  670 +#define RF_PREAMBLEDETECT_DETECTORTOL_2 0x02
  671 +#define RF_PREAMBLEDETECT_DETECTORTOL_3 0x03
  672 +#define RF_PREAMBLEDETECT_DETECTORTOL_4 0x04
  673 +#define RF_PREAMBLEDETECT_DETECTORTOL_5 0x05
  674 +#define RF_PREAMBLEDETECT_DETECTORTOL_6 0x06
  675 +#define RF_PREAMBLEDETECT_DETECTORTOL_7 0x07
  676 +#define RF_PREAMBLEDETECT_DETECTORTOL_8 0x08
  677 +#define RF_PREAMBLEDETECT_DETECTORTOL_9 0x09
  678 +#define RF_PREAMBLEDETECT_DETECTORTOL_10 0x0A // Default
  679 +#define RF_PREAMBLEDETECT_DETECTORTOL_11 0x0B
  680 +#define RF_PREAMBLEDETECT_DETECTORTOL_12 0x0C
  681 +#define RF_PREAMBLEDETECT_DETECTORTOL_13 0x0D
  682 +#define RF_PREAMBLEDETECT_DETECTORTOL_14 0x0E
  683 +#define RF_PREAMBLEDETECT_DETECTORTOL_15 0x0F
  684 +#define RF_PREAMBLEDETECT_DETECTORTOL_16 0x10
  685 +#define RF_PREAMBLEDETECT_DETECTORTOL_17 0x11
  686 +#define RF_PREAMBLEDETECT_DETECTORTOL_18 0x12
  687 +#define RF_PREAMBLEDETECT_DETECTORTOL_19 0x13
  688 +#define RF_PREAMBLEDETECT_DETECTORTOL_20 0x14
  689 +#define RF_PREAMBLEDETECT_DETECTORTOL_21 0x15
  690 +#define RF_PREAMBLEDETECT_DETECTORTOL_22 0x16
  691 +#define RF_PREAMBLEDETECT_DETECTORTOL_23 0x17
  692 +#define RF_PREAMBLEDETECT_DETECTORTOL_24 0x18
  693 +#define RF_PREAMBLEDETECT_DETECTORTOL_25 0x19
  694 +#define RF_PREAMBLEDETECT_DETECTORTOL_26 0x1A
  695 +#define RF_PREAMBLEDETECT_DETECTORTOL_27 0x1B
  696 +#define RF_PREAMBLEDETECT_DETECTORTOL_28 0x1C
  697 +#define RF_PREAMBLEDETECT_DETECTORTOL_29 0x1D
  698 +#define RF_PREAMBLEDETECT_DETECTORTOL_30 0x1E
  699 +#define RF_PREAMBLEDETECT_DETECTORTOL_31 0x1F
  700 +
  701 +/*!
  702 + * RegRxTimeout1
  703 + */
  704 +#define RF_RXTIMEOUT1_TIMEOUTRXRSSI 0x00 // Default
  705 +
  706 +/*!
  707 + * RegRxTimeout2
  708 + */
  709 +#define RF_RXTIMEOUT2_TIMEOUTRXPREAMBLE 0x00 // Default
  710 +
  711 +/*!
  712 + * RegRxTimeout3
  713 + */
  714 +#define RF_RXTIMEOUT3_TIMEOUTSIGNALSYNC 0x00 // Default
  715 +
  716 +/*!
  717 + * RegRxDelay
  718 + */
  719 +#define RF_RXDELAY_INTERPACKETRXDELAY 0x00 // Default
  720 +
  721 +/*!
  722 + * RegOsc
  723 + */
  724 +#define RF_OSC_RCCALSTART 0x08
  725 +
  726 +#define RF_OSC_CLKOUT_MASK 0xF8
  727 +#define RF_OSC_CLKOUT_32_MHZ 0x00
  728 +#define RF_OSC_CLKOUT_16_MHZ 0x01
  729 +#define RF_OSC_CLKOUT_8_MHZ 0x02
  730 +#define RF_OSC_CLKOUT_4_MHZ 0x03
  731 +#define RF_OSC_CLKOUT_2_MHZ 0x04
  732 +#define RF_OSC_CLKOUT_1_MHZ 0x05 // Default
  733 +#define RF_OSC_CLKOUT_RC 0x06
  734 +#define RF_OSC_CLKOUT_OFF 0x07
  735 +
  736 +/*!
  737 + * RegPreambleMsb/RegPreambleLsb
  738 + */
  739 +#define RF_PREAMBLEMSB_SIZE 0x00 // Default
  740 +#define RF_PREAMBLELSB_SIZE 0x03 // Default
  741 +
  742 +/*!
  743 + * RegSyncConfig
  744 + */
  745 +#define RF_SYNCCONFIG_AUTORESTARTRXMODE_MASK 0x3F
  746 +#define RF_SYNCCONFIG_AUTORESTARTRXMODE_WAITPLL_ON 0x80 // Default
  747 +#define RF_SYNCCONFIG_AUTORESTARTRXMODE_WAITPLL_OFF 0x40
  748 +#define RF_SYNCCONFIG_AUTORESTARTRXMODE_OFF 0x00
  749 +
  750 +
  751 +#define RF_SYNCCONFIG_PREAMBLEPOLARITY_MASK 0xDF
  752 +#define RF_SYNCCONFIG_PREAMBLEPOLARITY_55 0x20
  753 +#define RF_SYNCCONFIG_PREAMBLEPOLARITY_AA 0x00 // Default
  754 +
  755 +#define RF_SYNCCONFIG_SYNC_MASK 0xEF
  756 +#define RF_SYNCCONFIG_SYNC_ON 0x10 // Default
  757 +#define RF_SYNCCONFIG_SYNC_OFF 0x00
  758 +
  759 +
  760 +#define RF_SYNCCONFIG_SYNCSIZE_MASK 0xF8
  761 +#define RF_SYNCCONFIG_SYNCSIZE_1 0x00
  762 +#define RF_SYNCCONFIG_SYNCSIZE_2 0x01
  763 +#define RF_SYNCCONFIG_SYNCSIZE_3 0x02
  764 +#define RF_SYNCCONFIG_SYNCSIZE_4 0x03 // Default
  765 +#define RF_SYNCCONFIG_SYNCSIZE_5 0x04
  766 +#define RF_SYNCCONFIG_SYNCSIZE_6 0x05
  767 +#define RF_SYNCCONFIG_SYNCSIZE_7 0x06
  768 +#define RF_SYNCCONFIG_SYNCSIZE_8 0x07
  769 +
  770 +/*!
  771 + * RegSyncValue1-8
  772 + */
  773 +#define RF_SYNCVALUE1_SYNCVALUE 0x01 // Default
  774 +#define RF_SYNCVALUE2_SYNCVALUE 0x01 // Default
  775 +#define RF_SYNCVALUE3_SYNCVALUE 0x01 // Default
  776 +#define RF_SYNCVALUE4_SYNCVALUE 0x01 // Default
  777 +#define RF_SYNCVALUE5_SYNCVALUE 0x01 // Default
  778 +#define RF_SYNCVALUE6_SYNCVALUE 0x01 // Default
  779 +#define RF_SYNCVALUE7_SYNCVALUE 0x01 // Default
  780 +#define RF_SYNCVALUE8_SYNCVALUE 0x01 // Default
  781 +
  782 +/*!
  783 + * RegPacketConfig1
  784 + */
  785 +#define RF_PACKETCONFIG1_PACKETFORMAT_MASK 0x7F
  786 +#define RF_PACKETCONFIG1_PACKETFORMAT_FIXED 0x00
  787 +#define RF_PACKETCONFIG1_PACKETFORMAT_VARIABLE 0x80 // Default
  788 +
  789 +#define RF_PACKETCONFIG1_DCFREE_MASK 0x9F
  790 +#define RF_PACKETCONFIG1_DCFREE_OFF 0x00 // Default
  791 +#define RF_PACKETCONFIG1_DCFREE_MANCHESTER 0x20
  792 +#define RF_PACKETCONFIG1_DCFREE_WHITENING 0x40
  793 +
  794 +#define RF_PACKETCONFIG1_CRC_MASK 0xEF
  795 +#define RF_PACKETCONFIG1_CRC_ON 0x10 // Default
  796 +#define RF_PACKETCONFIG1_CRC_OFF 0x00
  797 +
  798 +#define RF_PACKETCONFIG1_CRCAUTOCLEAR_MASK 0xF7
  799 +#define RF_PACKETCONFIG1_CRCAUTOCLEAR_ON 0x00 // Default
  800 +#define RF_PACKETCONFIG1_CRCAUTOCLEAR_OFF 0x08
  801 +
  802 +#define RF_PACKETCONFIG1_ADDRSFILTERING_MASK 0xF9
  803 +#define RF_PACKETCONFIG1_ADDRSFILTERING_OFF 0x00 // Default
  804 +#define RF_PACKETCONFIG1_ADDRSFILTERING_NODE 0x02
  805 +#define RF_PACKETCONFIG1_ADDRSFILTERING_NODEBROADCAST 0x04
  806 +
  807 +#define RF_PACKETCONFIG1_CRCWHITENINGTYPE_MASK 0xFE
  808 +#define RF_PACKETCONFIG1_CRCWHITENINGTYPE_CCITT 0x00 // Default
  809 +#define RF_PACKETCONFIG1_CRCWHITENINGTYPE_IBM 0x01
  810 +
  811 +/*!
  812 + * RegPacketConfig2
  813 + */
  814 +
  815 +#define RF_PACKETCONFIG2_WMBUS_CRC_ENABLE_MASK 0x7F
  816 +#define RF_PACKETCONFIG2_WMBUS_CRC_ENABLE 0x80
  817 +#define RF_PACKETCONFIG2_WMBUS_CRC_DISABLE 0x00 // Default
  818 +
  819 +#define RF_PACKETCONFIG2_DATAMODE_MASK 0xBF
  820 +#define RF_PACKETCONFIG2_DATAMODE_CONTINUOUS 0x00
  821 +#define RF_PACKETCONFIG2_DATAMODE_PACKET 0x40 // Default
  822 +
  823 +#define RF_PACKETCONFIG2_IOHOME_MASK 0xDF
  824 +#define RF_PACKETCONFIG2_IOHOME_ON 0x20
  825 +#define RF_PACKETCONFIG2_IOHOME_OFF 0x00 // Default
  826 +
  827 +#define RF_PACKETCONFIG2_BEACON_MASK 0xF7
  828 +#define RF_PACKETCONFIG2_BEACON_ON 0x08
  829 +#define RF_PACKETCONFIG2_BEACON_OFF 0x00 // Default
  830 +
  831 +#define RF_PACKETCONFIG2_PAYLOADLENGTH_MSB_MASK 0xF8
  832 +
  833 +/*!
  834 + * RegPayloadLength
  835 + */
  836 +#define RF_PAYLOADLENGTH_LENGTH 0x40 // Default
  837 +
  838 +/*!
  839 + * RegNodeAdrs
  840 + */
  841 +#define RF_NODEADDRESS_ADDRESS 0x00
  842 +
  843 +/*!
  844 + * RegBroadcastAdrs
  845 + */
  846 +#define RF_BROADCASTADDRESS_ADDRESS 0x00
  847 +
  848 +/*!
  849 + * RegFifoThresh
  850 + */
  851 +#define RF_FIFOTHRESH_TXSTARTCONDITION_MASK 0x7F
  852 +#define RF_FIFOTHRESH_TXSTARTCONDITION_FIFOTHRESH 0x00 // Default
  853 +#define RF_FIFOTHRESH_TXSTARTCONDITION_FIFONOTEMPTY 0x80
  854 +
  855 +#define RF_FIFOTHRESH_FIFOTHRESHOLD_MASK 0xC0
  856 +#define RF_FIFOTHRESH_FIFOTHRESHOLD_THRESHOLD 0x0F // Default
  857 +
  858 +/*!
  859 + * RegSeqConfig1
  860 + */
  861 +#define RF_SEQCONFIG1_SEQUENCER_START 0x80
  862 +
  863 +#define RF_SEQCONFIG1_SEQUENCER_STOP 0x40
  864 +
  865 +#define RF_SEQCONFIG1_IDLEMODE_MASK 0xDF
  866 +#define RF_SEQCONFIG1_IDLEMODE_SLEEP 0x20
  867 +#define RF_SEQCONFIG1_IDLEMODE_STANDBY 0x00 // Default
  868 +
  869 +#define RF_SEQCONFIG1_FROMSTART_MASK 0xE7
  870 +#define RF_SEQCONFIG1_FROMSTART_TOLPS 0x00 // Default
  871 +#define RF_SEQCONFIG1_FROMSTART_TORX 0x08
  872 +#define RF_SEQCONFIG1_FROMSTART_TOTX 0x10
  873 +#define RF_SEQCONFIG1_FROMSTART_TOTX_ONFIFOLEVEL 0x18
  874 +
  875 +#define RF_SEQCONFIG1_LPS_MASK 0xFB
  876 +#define RF_SEQCONFIG1_LPS_SEQUENCER_OFF 0x00 // Default
  877 +#define RF_SEQCONFIG1_LPS_IDLE 0x04
  878 +
  879 +#define RF_SEQCONFIG1_FROMIDLE_MASK 0xFD
  880 +#define RF_SEQCONFIG1_FROMIDLE_TOTX 0x00 // Default
  881 +#define RF_SEQCONFIG1_FROMIDLE_TORX 0x02
  882 +
  883 +#define RF_SEQCONFIG1_FROMTX_MASK 0xFE
  884 +#define RF_SEQCONFIG1_FROMTX_TOLPS 0x00 // Default
  885 +#define RF_SEQCONFIG1_FROMTX_TORX 0x01
  886 +
  887 +/*!
  888 + * RegSeqConfig2
  889 + */
  890 +#define RF_SEQCONFIG2_FROMRX_MASK 0x1F
  891 +#define RF_SEQCONFIG2_FROMRX_TOUNUSED_000 0x00 // Default
  892 +#define RF_SEQCONFIG2_FROMRX_TORXPKT_ONPLDRDY 0x20
  893 +#define RF_SEQCONFIG2_FROMRX_TOLPS_ONPLDRDY 0x40
  894 +#define RF_SEQCONFIG2_FROMRX_TORXPKT_ONCRCOK 0x60
  895 +#define RF_SEQCONFIG2_FROMRX_TOSEQUENCEROFF_ONRSSI 0x80
  896 +#define RF_SEQCONFIG2_FROMRX_TOSEQUENCEROFF_ONSYNC 0xA0
  897 +#define RF_SEQCONFIG2_FROMRX_TOSEQUENCEROFF_ONPREAMBLE 0xC0
  898 +#define RF_SEQCONFIG2_FROMRX_TOUNUSED_111 0xE0
  899 +
  900 +#define RF_SEQCONFIG2_FROMRXTIMEOUT_MASK 0xE7
  901 +#define RF_SEQCONFIG2_FROMRXTIMEOUT_TORXRESTART 0x00 // Default
  902 +#define RF_SEQCONFIG2_FROMRXTIMEOUT_TOTX 0x08
  903 +#define RF_SEQCONFIG2_FROMRXTIMEOUT_TOLPS 0x10
  904 +#define RF_SEQCONFIG2_FROMRXTIMEOUT_TOSEQUENCEROFF 0x18
  905 +
  906 +#define RF_SEQCONFIG2_FROMRXPKT_MASK 0xF8
  907 +#define RF_SEQCONFIG2_FROMRXPKT_TOSEQUENCEROFF 0x00 // Default
  908 +#define RF_SEQCONFIG2_FROMRXPKT_TOTX_ONFIFOEMPTY 0x01
  909 +#define RF_SEQCONFIG2_FROMRXPKT_TOLPS 0x02
  910 +#define RF_SEQCONFIG2_FROMRXPKT_TOSYNTHESIZERRX 0x03
  911 +#define RF_SEQCONFIG2_FROMRXPKT_TORX 0x04
  912 +
  913 +/*!
  914 + * RegTimerResol
  915 + */
  916 +#define RF_TIMERRESOL_TIMER1RESOL_MASK 0xF3
  917 +#define RF_TIMERRESOL_TIMER1RESOL_OFF 0x00 // Default
  918 +#define RF_TIMERRESOL_TIMER1RESOL_000064_US 0x04
  919 +#define RF_TIMERRESOL_TIMER1RESOL_004100_US 0x08
  920 +#define RF_TIMERRESOL_TIMER1RESOL_262000_US 0x0C
  921 +
  922 +#define RF_TIMERRESOL_TIMER2RESOL_MASK 0xFC
  923 +#define RF_TIMERRESOL_TIMER2RESOL_OFF 0x00 // Default
  924 +#define RF_TIMERRESOL_TIMER2RESOL_000064_US 0x01
  925 +#define RF_TIMERRESOL_TIMER2RESOL_004100_US 0x02
  926 +#define RF_TIMERRESOL_TIMER2RESOL_262000_US 0x03
  927 +
  928 +/*!
  929 + * RegTimer1Coef
  930 + */
  931 +#define RF_TIMER1COEF_TIMER1COEFFICIENT 0xF5 // Default
  932 +
  933 +/*!
  934 + * RegTimer2Coef
  935 + */
  936 +#define RF_TIMER2COEF_TIMER2COEFFICIENT 0x20 // Default
  937 +
  938 +/*!
  939 + * RegImageCal
  940 + */
  941 +#define RF_IMAGECAL_AUTOIMAGECAL_MASK 0x7F
  942 +#define RF_IMAGECAL_AUTOIMAGECAL_ON 0x80
  943 +#define RF_IMAGECAL_AUTOIMAGECAL_OFF 0x00 // Default
  944 +
  945 +#define RF_IMAGECAL_IMAGECAL_MASK 0xBF
  946 +#define RF_IMAGECAL_IMAGECAL_START 0x40
  947 +
  948 +#define RF_IMAGECAL_IMAGECAL_RUNNING 0x20
  949 +#define RF_IMAGECAL_IMAGECAL_DONE 0x00 // Default
  950 +
  951 +#define RF_IMAGECAL_TEMPCHANGE_HIGHER 0x08
  952 +#define RF_IMAGECAL_TEMPCHANGE_LOWER 0x00
  953 +
  954 +#define RF_IMAGECAL_TEMPTHRESHOLD_MASK 0xF9
  955 +#define RF_IMAGECAL_TEMPTHRESHOLD_05 0x00
  956 +#define RF_IMAGECAL_TEMPTHRESHOLD_10 0x02 // Default
  957 +#define RF_IMAGECAL_TEMPTHRESHOLD_15 0x04
  958 +#define RF_IMAGECAL_TEMPTHRESHOLD_20 0x06
  959 +
  960 +#define RF_IMAGECAL_TEMPMONITOR_MASK 0xFE
  961 +#define RF_IMAGECAL_TEMPMONITOR_ON 0x00 // Default
  962 +#define RF_IMAGECAL_TEMPMONITOR_OFF 0x01
  963 +
  964 +/*!
  965 + * RegTemp (Read Only)
  966 + */
  967 +
  968 +/*!
  969 + * RegLowBat
  970 + */
  971 +#define RF_LOWBAT_MASK 0xF7
  972 +#define RF_LOWBAT_ON 0x08
  973 +#define RF_LOWBAT_OFF 0x00 // Default
  974 +
  975 +#define RF_LOWBAT_TRIM_MASK 0xF8
  976 +#define RF_LOWBAT_TRIM_1695 0x00
  977 +#define RF_LOWBAT_TRIM_1764 0x01
  978 +#define RF_LOWBAT_TRIM_1835 0x02 // Default
  979 +#define RF_LOWBAT_TRIM_1905 0x03
  980 +#define RF_LOWBAT_TRIM_1976 0x04
  981 +#define RF_LOWBAT_TRIM_2045 0x05
  982 +#define RF_LOWBAT_TRIM_2116 0x06
  983 +#define RF_LOWBAT_TRIM_2185 0x07
  984 +
  985 +/*!
  986 + * RegIrqFlags1
  987 + */
  988 +#define RF_IRQFLAGS1_MODEREADY 0x80
  989 +
  990 +#define RF_IRQFLAGS1_RXREADY 0x40
  991 +
  992 +#define RF_IRQFLAGS1_TXREADY 0x20
  993 +
  994 +#define RF_IRQFLAGS1_PLLLOCK 0x10
  995 +
  996 +#define RF_IRQFLAGS1_RSSI 0x08
  997 +
  998 +#define RF_IRQFLAGS1_TIMEOUT 0x04
  999 +
  1000 +#define RF_IRQFLAGS1_PREAMBLEDETECT 0x02
  1001 +
  1002 +#define RF_IRQFLAGS1_SYNCADDRESSMATCH 0x01
  1003 +
  1004 +/*!
  1005 + * RegIrqFlags2
  1006 + */
  1007 +#define RF_IRQFLAGS2_FIFOFULL 0x80
  1008 +
  1009 +#define RF_IRQFLAGS2_FIFOEMPTY 0x40
  1010 +
  1011 +#define RF_IRQFLAGS2_FIFOLEVEL 0x20
  1012 +
  1013 +#define RF_IRQFLAGS2_FIFOOVERRUN 0x10
  1014 +
  1015 +#define RF_IRQFLAGS2_PACKETSENT 0x08
  1016 +
  1017 +#define RF_IRQFLAGS2_PAYLOADREADY 0x04
  1018 +
  1019 +#define RF_IRQFLAGS2_CRCOK 0x02
  1020 +
  1021 +#define RF_IRQFLAGS2_LOWBAT 0x01
  1022 +
  1023 +/*!
  1024 + * RegDioMapping1
  1025 + */
  1026 +#define RF_DIOMAPPING1_DIO0_MASK 0x3F
  1027 +#define RF_DIOMAPPING1_DIO0_00 0x00 // Default
  1028 +#define RF_DIOMAPPING1_DIO0_01 0x40
  1029 +#define RF_DIOMAPPING1_DIO0_10 0x80
  1030 +#define RF_DIOMAPPING1_DIO0_11 0xC0
  1031 +
  1032 +#define RF_DIOMAPPING1_DIO1_MASK 0xCF
  1033 +#define RF_DIOMAPPING1_DIO1_00 0x00 // Default
  1034 +#define RF_DIOMAPPING1_DIO1_01 0x10
  1035 +#define RF_DIOMAPPING1_DIO1_10 0x20
  1036 +#define RF_DIOMAPPING1_DIO1_11 0x30
  1037 +
  1038 +#define RF_DIOMAPPING1_DIO2_MASK 0xF3
  1039 +#define RF_DIOMAPPING1_DIO2_00 0x00 // Default
  1040 +#define RF_DIOMAPPING1_DIO2_01 0x04
  1041 +#define RF_DIOMAPPING1_DIO2_10 0x08
  1042 +#define RF_DIOMAPPING1_DIO2_11 0x0C
  1043 +
  1044 +#define RF_DIOMAPPING1_DIO3_MASK 0xFC
  1045 +#define RF_DIOMAPPING1_DIO3_00 0x00 // Default
  1046 +#define RF_DIOMAPPING1_DIO3_01 0x01
  1047 +#define RF_DIOMAPPING1_DIO3_10 0x02
  1048 +#define RF_DIOMAPPING1_DIO3_11 0x03
  1049 +
  1050 +/*!
  1051 + * RegDioMapping2
  1052 + */
  1053 +#define RF_DIOMAPPING2_DIO4_MASK 0x3F
  1054 +#define RF_DIOMAPPING2_DIO4_00 0x00 // Default
  1055 +#define RF_DIOMAPPING2_DIO4_01 0x40
  1056 +#define RF_DIOMAPPING2_DIO4_10 0x80
  1057 +#define RF_DIOMAPPING2_DIO4_11 0xC0
  1058 +
  1059 +#define RF_DIOMAPPING2_DIO5_MASK 0xCF
  1060 +#define RF_DIOMAPPING2_DIO5_00 0x00 // Default
  1061 +#define RF_DIOMAPPING2_DIO5_01 0x10
  1062 +#define RF_DIOMAPPING2_DIO5_10 0x20
  1063 +#define RF_DIOMAPPING2_DIO5_11 0x30
  1064 +
  1065 +#define RF_DIOMAPPING2_MAP_MASK 0xFE
  1066 +#define RF_DIOMAPPING2_MAP_PREAMBLEDETECT 0x01
  1067 +#define RF_DIOMAPPING2_MAP_RSSI 0x00 // Default
  1068 +
  1069 +/*!
  1070 + * RegVersion (Read Only)
  1071 + */
  1072 +
  1073 +/*!
  1074 + * RegPllHop
  1075 + */
  1076 +#define RF_PLLHOP_FASTHOP_MASK 0x7F
  1077 +#define RF_PLLHOP_FASTHOP_ON 0x80
  1078 +#define RF_PLLHOP_FASTHOP_OFF 0x00 // Default
  1079 +
  1080 +/*!
  1081 + * RegTcxo
  1082 + */
  1083 +#define RF_TCXO_TCXOINPUT_MASK 0xEF
  1084 +#define RF_TCXO_TCXOINPUT_ON 0x10
  1085 +#define RF_TCXO_TCXOINPUT_OFF 0x00 // Default
  1086 +
  1087 +/*!
  1088 + * RegPaDac
  1089 + */
  1090 +#define RF_PADAC_20DBM_MASK 0xF8
  1091 +#define RF_PADAC_20DBM_ON 0x07
  1092 +#define RF_PADAC_20DBM_OFF 0x04 // Default
  1093 +
  1094 +/*!
  1095 + * RegFormerTemp
  1096 + */
  1097 +
  1098 +/*!
  1099 + * RegBitrateFrac
  1100 + */
  1101 +#define RF_BITRATEFRAC_MASK 0xF0
  1102 +
  1103 +/*!
  1104 + * RegAgcRef
  1105 + */
  1106 +
  1107 +/*!
  1108 + * RegAgcThresh1
  1109 + */
  1110 +
  1111 +/*!
  1112 + * RegAgcThresh2
  1113 + */
  1114 +
  1115 +/*!
  1116 + * RegAgcThresh3
  1117 + */
  1118 +
  1119 +/*!
  1120 + * RegPll
  1121 + */
  1122 +#define RF_PLL_BANDWIDTH_MASK 0x3F
  1123 +#define RF_PLL_BANDWIDTH_75 0x00
  1124 +#define RF_PLL_BANDWIDTH_150 0x40
  1125 +#define RF_PLL_BANDWIDTH_225 0x80
  1126 +#define RF_PLL_BANDWIDTH_300 0xC0 // Default
  1127 +
  1128 +#endif // __SX1276_REGS_FSK_H__
... ...
SX1276Lib/registers/sx1276Regs-LoRa.h 0 → 100644
... ... @@ -0,0 +1,565 @@
  1 +/*
  2 + / _____) _ | |
  3 +( (____ _____ ____ _| |_ _____ ____| |__
  4 + \____ \| ___ | (_ _) ___ |/ ___) _ \
  5 + _____) ) ____| | | || |_| ____( (___| | | |
  6 +(______/|_____)_|_|_| \__)_____)\____)_| |_|
  7 + (C) 2014 Semtech
  8 +
  9 +Description: SX1276 LoRa modem registers and bits definitions
  10 +
  11 +License: Revised BSD License, see LICENSE.TXT file include in the project
  12 +
  13 +Maintainer: Miguel Luis and Gregory Cristian
  14 +*/
  15 +#ifndef __SX1276_REGS_LORA_H__
  16 +#define __SX1276_REGS_LORA_H__
  17 +
  18 +/*!
  19 + * ============================================================================
  20 + * SX1276 Internal registers Address
  21 + * ============================================================================
  22 + */
  23 +#define REG_LR_FIFO 0x00
  24 +// Common settings
  25 +#define REG_LR_OPMODE 0x01
  26 +#define REG_LR_FRFMSB 0x06
  27 +#define REG_LR_FRFMID 0x07
  28 +#define REG_LR_FRFLSB 0x08
  29 +// Tx settings
  30 +#define REG_LR_PACONFIG 0x09
  31 +#define REG_LR_PARAMP 0x0A
  32 +#define REG_LR_OCP 0x0B
  33 +// Rx settings
  34 +#define REG_LR_LNA 0x0C
  35 +// LoRa registers
  36 +#define REG_LR_FIFOADDRPTR 0x0D
  37 +#define REG_LR_FIFOTXBASEADDR 0x0E
  38 +#define REG_LR_FIFORXBASEADDR 0x0F
  39 +#define REG_LR_FIFORXCURRENTADDR 0x10
  40 +#define REG_LR_IRQFLAGSMASK 0x11
  41 +#define REG_LR_IRQFLAGS 0x12
  42 +#define REG_LR_RXNBBYTES 0x13
  43 +#define REG_LR_RXHEADERCNTVALUEMSB 0x14
  44 +#define REG_LR_RXHEADERCNTVALUELSB 0x15
  45 +#define REG_LR_RXPACKETCNTVALUEMSB 0x16
  46 +#define REG_LR_RXPACKETCNTVALUELSB 0x17
  47 +#define REG_LR_MODEMSTAT 0x18
  48 +#define REG_LR_PKTSNRVALUE 0x19
  49 +#define REG_LR_PKTRSSIVALUE 0x1A
  50 +#define REG_LR_RSSIVALUE 0x1B
  51 +#define REG_LR_HOPCHANNEL 0x1C
  52 +#define REG_LR_MODEMCONFIG1 0x1D
  53 +#define REG_LR_MODEMCONFIG2 0x1E
  54 +#define REG_LR_SYMBTIMEOUTLSB 0x1F
  55 +#define REG_LR_PREAMBLEMSB 0x20
  56 +#define REG_LR_PREAMBLELSB 0x21
  57 +#define REG_LR_PAYLOADLENGTH 0x22
  58 +#define REG_LR_PAYLOADMAXLENGTH 0x23
  59 +#define REG_LR_HOPPERIOD 0x24
  60 +#define REG_LR_FIFORXBYTEADDR 0x25
  61 +#define REG_LR_MODEMCONFIG3 0x26
  62 +#define REG_LR_FEIMSB 0x28
  63 +#define REG_LR_FEIMID 0x29
  64 +#define REG_LR_FEILSB 0x2A
  65 +#define REG_LR_RSSIWIDEBAND 0x2C
  66 +#define REG_LR_TEST2F 0x2F
  67 +#define REG_LR_TEST30 0x30
  68 +#define REG_LR_DETECTOPTIMIZE 0x31
  69 +#define REG_LR_INVERTIQ 0x33
  70 +#define REG_LR_TEST36 0x36
  71 +#define REG_LR_DETECTIONTHRESHOLD 0x37
  72 +#define REG_LR_SYNCWORD 0x39
  73 +#define REG_LR_TEST3A 0x3A
  74 +#define REG_LR_INVERTIQ2 0x3B
  75 +
  76 +// end of documented register in datasheet
  77 +// I/O settings
  78 +#define REG_LR_DIOMAPPING1 0x40
  79 +#define REG_LR_DIOMAPPING2 0x41
  80 +// Version
  81 +#define REG_LR_VERSION 0x42
  82 +// Additional settings
  83 +#define REG_LR_PLLHOP 0x44
  84 +#define REG_LR_TCXO 0x4B
  85 +#define REG_LR_PADAC 0x4D
  86 +#define REG_LR_FORMERTEMP 0x5B
  87 +#define REG_LR_BITRATEFRAC 0x5D
  88 +#define REG_LR_AGCREF 0x61
  89 +#define REG_LR_AGCTHRESH1 0x62
  90 +#define REG_LR_AGCTHRESH2 0x63
  91 +#define REG_LR_AGCTHRESH3 0x64
  92 +#define REG_LR_PLL 0x70
  93 +
  94 +/*!
  95 + * ============================================================================
  96 + * SX1276 LoRa bits control definition
  97 + * ============================================================================
  98 + */
  99 +
  100 +/*!
  101 + * RegFifo
  102 + */
  103 +
  104 +/*!
  105 + * RegOpMode
  106 + */
  107 +#define RFLR_OPMODE_LONGRANGEMODE_MASK 0x7F
  108 +#define RFLR_OPMODE_LONGRANGEMODE_OFF 0x00 // Default
  109 +#define RFLR_OPMODE_LONGRANGEMODE_ON 0x80
  110 +
  111 +#define RFLR_OPMODE_ACCESSSHAREDREG_MASK 0xBF
  112 +#define RFLR_OPMODE_ACCESSSHAREDREG_ENABLE 0x40
  113 +#define RFLR_OPMODE_ACCESSSHAREDREG_DISABLE 0x00 // Default
  114 +
  115 +#define RFLR_OPMODE_FREQMODE_ACCESS_MASK 0xF7
  116 +#define RFLR_OPMODE_FREQMODE_ACCESS_LF 0x08 // Default
  117 +#define RFLR_OPMODE_FREQMODE_ACCESS_HF 0x00
  118 +
  119 +#define RFLR_OPMODE_MASK 0xF8
  120 +#define RFLR_OPMODE_SLEEP 0x00
  121 +#define RFLR_OPMODE_STANDBY 0x01 // Default
  122 +#define RFLR_OPMODE_SYNTHESIZER_TX 0x02
  123 +#define RFLR_OPMODE_TRANSMITTER 0x03
  124 +#define RFLR_OPMODE_SYNTHESIZER_RX 0x04
  125 +#define RFLR_OPMODE_RECEIVER 0x05
  126 +// LoRa specific modes
  127 +#define RFLR_OPMODE_RECEIVER_SINGLE 0x06
  128 +#define RFLR_OPMODE_CAD 0x07
  129 +
  130 +/*!
  131 + * RegFrf (MHz)
  132 + */
  133 +#define RFLR_FRFMSB_434_MHZ 0x6C // Default
  134 +#define RFLR_FRFMID_434_MHZ 0x80 // Default
  135 +#define RFLR_FRFLSB_434_MHZ 0x00 // Default
  136 +
  137 +/*!
  138 + * RegPaConfig
  139 + */
  140 +#define RFLR_PACONFIG_PASELECT_MASK 0x7F
  141 +#define RFLR_PACONFIG_PASELECT_PABOOST 0x80
  142 +#define RFLR_PACONFIG_PASELECT_RFO 0x00 // Default
  143 +
  144 +#define RFLR_PACONFIG_MAX_POWER_MASK 0x8F
  145 +
  146 +#define RFLR_PACONFIG_OUTPUTPOWER_MASK 0xF0
  147 +
  148 +/*!
  149 + * RegPaRamp
  150 + */
  151 +#define RFLR_PARAMP_TXBANDFORCE_MASK 0xEF
  152 +#define RFLR_PARAMP_TXBANDFORCE_BAND_SEL 0x10
  153 +#define RFLR_PARAMP_TXBANDFORCE_AUTO 0x00 // Default
  154 +
  155 +#define RFLR_PARAMP_MASK 0xF0
  156 +#define RFLR_PARAMP_3400_US 0x00
  157 +#define RFLR_PARAMP_2000_US 0x01
  158 +#define RFLR_PARAMP_1000_US 0x02
  159 +#define RFLR_PARAMP_0500_US 0x03
  160 +#define RFLR_PARAMP_0250_US 0x04
  161 +#define RFLR_PARAMP_0125_US 0x05
  162 +#define RFLR_PARAMP_0100_US 0x06
  163 +#define RFLR_PARAMP_0062_US 0x07
  164 +#define RFLR_PARAMP_0050_US 0x08
  165 +#define RFLR_PARAMP_0040_US 0x09 // Default
  166 +#define RFLR_PARAMP_0031_US 0x0A
  167 +#define RFLR_PARAMP_0025_US 0x0B
  168 +#define RFLR_PARAMP_0020_US 0x0C
  169 +#define RFLR_PARAMP_0015_US 0x0D
  170 +#define RFLR_PARAMP_0012_US 0x0E
  171 +#define RFLR_PARAMP_0010_US 0x0F
  172 +
  173 +/*!
  174 + * RegOcp
  175 + */
  176 +#define RFLR_OCP_MASK 0xDF
  177 +#define RFLR_OCP_ON 0x20 // Default
  178 +#define RFLR_OCP_OFF 0x00
  179 +
  180 +#define RFLR_OCP_TRIM_MASK 0xE0
  181 +#define RFLR_OCP_TRIM_045_MA 0x00
  182 +#define RFLR_OCP_TRIM_050_MA 0x01
  183 +#define RFLR_OCP_TRIM_055_MA 0x02
  184 +#define RFLR_OCP_TRIM_060_MA 0x03
  185 +#define RFLR_OCP_TRIM_065_MA 0x04
  186 +#define RFLR_OCP_TRIM_070_MA 0x05
  187 +#define RFLR_OCP_TRIM_075_MA 0x06
  188 +#define RFLR_OCP_TRIM_080_MA 0x07
  189 +#define RFLR_OCP_TRIM_085_MA 0x08
  190 +#define RFLR_OCP_TRIM_090_MA 0x09
  191 +#define RFLR_OCP_TRIM_095_MA 0x0A
  192 +#define RFLR_OCP_TRIM_100_MA 0x0B // Default
  193 +#define RFLR_OCP_TRIM_105_MA 0x0C
  194 +#define RFLR_OCP_TRIM_110_MA 0x0D
  195 +#define RFLR_OCP_TRIM_115_MA 0x0E
  196 +#define RFLR_OCP_TRIM_120_MA 0x0F
  197 +#define RFLR_OCP_TRIM_130_MA 0x10
  198 +#define RFLR_OCP_TRIM_140_MA 0x11
  199 +#define RFLR_OCP_TRIM_150_MA 0x12
  200 +#define RFLR_OCP_TRIM_160_MA 0x13
  201 +#define RFLR_OCP_TRIM_170_MA 0x14
  202 +#define RFLR_OCP_TRIM_180_MA 0x15
  203 +#define RFLR_OCP_TRIM_190_MA 0x16
  204 +#define RFLR_OCP_TRIM_200_MA 0x17
  205 +#define RFLR_OCP_TRIM_210_MA 0x18
  206 +#define RFLR_OCP_TRIM_220_MA 0x19
  207 +#define RFLR_OCP_TRIM_230_MA 0x1A
  208 +#define RFLR_OCP_TRIM_240_MA 0x1B
  209 +
  210 +/*!
  211 + * RegLna
  212 + */
  213 +#define RFLR_LNA_GAIN_MASK 0x1F
  214 +#define RFLR_LNA_GAIN_G1 0x20 // Default
  215 +#define RFLR_LNA_GAIN_G2 0x40
  216 +#define RFLR_LNA_GAIN_G3 0x60
  217 +#define RFLR_LNA_GAIN_G4 0x80
  218 +#define RFLR_LNA_GAIN_G5 0xA0
  219 +#define RFLR_LNA_GAIN_G6 0xC0
  220 +
  221 +#define RFLR_LNA_BOOST_LF_MASK 0xE7
  222 +#define RFLR_LNA_BOOST_LF_DEFAULT 0x00 // Default
  223 +
  224 +#define RFLR_LNA_BOOST_HF_MASK 0xFC
  225 +#define RFLR_LNA_BOOST_HF_OFF 0x00 // Default
  226 +#define RFLR_LNA_BOOST_HF_ON 0x03
  227 +
  228 +/*!
  229 + * RegFifoAddrPtr
  230 + */
  231 +#define RFLR_FIFOADDRPTR 0x00 // Default
  232 +
  233 +/*!
  234 + * RegFifoTxBaseAddr
  235 + */
  236 +#define RFLR_FIFOTXBASEADDR 0x80 // Default
  237 +
  238 +/*!
  239 + * RegFifoTxBaseAddr
  240 + */
  241 +#define RFLR_FIFORXBASEADDR 0x00 // Default
  242 +
  243 +/*!
  244 + * RegFifoRxCurrentAddr (Read Only)
  245 + */
  246 +
  247 +/*!
  248 + * RegIrqFlagsMask
  249 + */
  250 +#define RFLR_IRQFLAGS_RXTIMEOUT_MASK 0x80
  251 +#define RFLR_IRQFLAGS_RXDONE_MASK 0x40
  252 +#define RFLR_IRQFLAGS_PAYLOADCRCERROR_MASK 0x20
  253 +#define RFLR_IRQFLAGS_VALIDHEADER_MASK 0x10
  254 +#define RFLR_IRQFLAGS_TXDONE_MASK 0x08
  255 +#define RFLR_IRQFLAGS_CADDONE_MASK 0x04
  256 +#define RFLR_IRQFLAGS_FHSSCHANGEDCHANNEL_MASK 0x02
  257 +#define RFLR_IRQFLAGS_CADDETECTED_MASK 0x01
  258 +
  259 +/*!
  260 + * RegIrqFlags
  261 + */
  262 +#define RFLR_IRQFLAGS_RXTIMEOUT 0x80
  263 +#define RFLR_IRQFLAGS_RXDONE 0x40
  264 +#define RFLR_IRQFLAGS_PAYLOADCRCERROR 0x20
  265 +#define RFLR_IRQFLAGS_VALIDHEADER 0x10
  266 +#define RFLR_IRQFLAGS_TXDONE 0x08
  267 +#define RFLR_IRQFLAGS_CADDONE 0x04
  268 +#define RFLR_IRQFLAGS_FHSSCHANGEDCHANNEL 0x02
  269 +#define RFLR_IRQFLAGS_CADDETECTED 0x01
  270 +
  271 +/*!
  272 + * RegFifoRxNbBytes (Read Only)
  273 + */
  274 +
  275 +/*!
  276 + * RegRxHeaderCntValueMsb (Read Only)
  277 + */
  278 +
  279 +/*!
  280 + * RegRxHeaderCntValueLsb (Read Only)
  281 + */
  282 +
  283 +/*!
  284 + * RegRxPacketCntValueMsb (Read Only)
  285 + */
  286 +
  287 +/*!
  288 + * RegRxPacketCntValueLsb (Read Only)
  289 + */
  290 +
  291 +/*!
  292 + * RegModemStat (Read Only)
  293 + */
  294 +#define RFLR_MODEMSTAT_RX_CR_MASK 0x1F
  295 +#define RFLR_MODEMSTAT_MODEM_STATUS_MASK 0xE0
  296 +
  297 +/*!
  298 + * RegPktSnrValue (Read Only)
  299 + */
  300 +
  301 +/*!
  302 + * RegPktRssiValue (Read Only)
  303 + */
  304 +
  305 +/*!
  306 + * RegRssiValue (Read Only)
  307 + */
  308 +
  309 +/*!
  310 + * RegHopChannel (Read Only)
  311 + */
  312 +#define RFLR_HOPCHANNEL_PLL_LOCK_TIMEOUT_MASK 0x7F
  313 +#define RFLR_HOPCHANNEL_PLL_LOCK_FAIL 0x80
  314 +#define RFLR_HOPCHANNEL_PLL_LOCK_SUCCEED 0x00 // Default
  315 +
  316 +#define RFLR_HOPCHANNEL_CRCONPAYLOAD_MASK 0xBF
  317 +#define RFLR_HOPCHANNEL_CRCONPAYLOAD_ON 0x40
  318 +#define RFLR_HOPCHANNEL_CRCONPAYLOAD_OFF 0x00 // Default
  319 +
  320 +#define RFLR_HOPCHANNEL_CHANNEL_MASK 0x3F
  321 +
  322 +/*!
  323 + * RegModemConfig1
  324 + */
  325 +#define RFLR_MODEMCONFIG1_BW_MASK 0x0F
  326 +#define RFLR_MODEMCONFIG1_BW_7_81_KHZ 0x00
  327 +#define RFLR_MODEMCONFIG1_BW_10_41_KHZ 0x10
  328 +#define RFLR_MODEMCONFIG1_BW_15_62_KHZ 0x20
  329 +#define RFLR_MODEMCONFIG1_BW_20_83_KHZ 0x30
  330 +#define RFLR_MODEMCONFIG1_BW_31_25_KHZ 0x40
  331 +#define RFLR_MODEMCONFIG1_BW_41_66_KHZ 0x50
  332 +#define RFLR_MODEMCONFIG1_BW_62_50_KHZ 0x60
  333 +#define RFLR_MODEMCONFIG1_BW_125_KHZ 0x70 // Default
  334 +#define RFLR_MODEMCONFIG1_BW_250_KHZ 0x80
  335 +#define RFLR_MODEMCONFIG1_BW_500_KHZ 0x90
  336 +
  337 +#define RFLR_MODEMCONFIG1_CODINGRATE_MASK 0xF1
  338 +#define RFLR_MODEMCONFIG1_CODINGRATE_4_5 0x02
  339 +#define RFLR_MODEMCONFIG1_CODINGRATE_4_6 0x04 // Default
  340 +#define RFLR_MODEMCONFIG1_CODINGRATE_4_7 0x06
  341 +#define RFLR_MODEMCONFIG1_CODINGRATE_4_8 0x08
  342 +
  343 +#define RFLR_MODEMCONFIG1_IMPLICITHEADER_MASK 0xFE
  344 +#define RFLR_MODEMCONFIG1_IMPLICITHEADER_ON 0x01
  345 +#define RFLR_MODEMCONFIG1_IMPLICITHEADER_OFF 0x00 // Default
  346 +
  347 +/*!
  348 + * RegModemConfig2
  349 + */
  350 +#define RFLR_MODEMCONFIG2_SF_MASK 0x0F
  351 +#define RFLR_MODEMCONFIG2_SF_6 0x60
  352 +#define RFLR_MODEMCONFIG2_SF_7 0x70 // Default
  353 +#define RFLR_MODEMCONFIG2_SF_8 0x80
  354 +#define RFLR_MODEMCONFIG2_SF_9 0x90
  355 +#define RFLR_MODEMCONFIG2_SF_10 0xA0
  356 +#define RFLR_MODEMCONFIG2_SF_11 0xB0
  357 +#define RFLR_MODEMCONFIG2_SF_12 0xC0
  358 +
  359 +#define RFLR_MODEMCONFIG2_TXCONTINUOUSMODE_MASK 0xF7
  360 +#define RFLR_MODEMCONFIG2_TXCONTINUOUSMODE_ON 0x08
  361 +#define RFLR_MODEMCONFIG2_TXCONTINUOUSMODE_OFF 0x00
  362 +
  363 +#define RFLR_MODEMCONFIG2_RXPAYLOADCRC_MASK 0xFB
  364 +#define RFLR_MODEMCONFIG2_RXPAYLOADCRC_ON 0x04
  365 +#define RFLR_MODEMCONFIG2_RXPAYLOADCRC_OFF 0x00 // Default
  366 +
  367 +#define RFLR_MODEMCONFIG2_SYMBTIMEOUTMSB_MASK 0xFC
  368 +#define RFLR_MODEMCONFIG2_SYMBTIMEOUTMSB 0x00 // Default
  369 +
  370 +/*!
  371 + * RegSymbTimeoutLsb
  372 + */
  373 +#define RFLR_SYMBTIMEOUTLSB_SYMBTIMEOUT 0x64 // Default
  374 +
  375 +/*!
  376 + * RegPreambleLengthMsb
  377 + */
  378 +#define RFLR_PREAMBLELENGTHMSB 0x00 // Default
  379 +
  380 +/*!
  381 + * RegPreambleLengthLsb
  382 + */
  383 +#define RFLR_PREAMBLELENGTHLSB 0x08 // Default
  384 +
  385 +/*!
  386 + * RegPayloadLength
  387 + */
  388 +#define RFLR_PAYLOADLENGTH 0x0E // Default
  389 +
  390 +/*!
  391 + * RegPayloadMaxLength
  392 + */
  393 +#define RFLR_PAYLOADMAXLENGTH 0xFF // Default
  394 +
  395 +/*!
  396 + * RegHopPeriod
  397 + */
  398 +#define RFLR_HOPPERIOD_FREQFOPPINGPERIOD 0x00 // Default
  399 +
  400 +/*!
  401 + * RegFifoRxByteAddr (Read Only)
  402 + */
  403 +
  404 +/*!
  405 + * RegModemConfig3
  406 + */
  407 +#define RFLR_MODEMCONFIG3_LOWDATARATEOPTIMIZE_MASK 0xF7
  408 +#define RFLR_MODEMCONFIG3_LOWDATARATEOPTIMIZE_ON 0x08
  409 +#define RFLR_MODEMCONFIG3_LOWDATARATEOPTIMIZE_OFF 0x00 // Default
  410 +
  411 +#define RFLR_MODEMCONFIG3_AGCAUTO_MASK 0xFB
  412 +#define RFLR_MODEMCONFIG3_AGCAUTO_ON 0x04 // Default
  413 +#define RFLR_MODEMCONFIG3_AGCAUTO_OFF 0x00
  414 +
  415 +/*!
  416 + * RegFeiMsb (Read Only)
  417 + */
  418 +
  419 +/*!
  420 + * RegFeiMid (Read Only)
  421 + */
  422 +
  423 +/*!
  424 + * RegFeiLsb (Read Only)
  425 + */
  426 +
  427 +/*!
  428 + * RegRssiWideband (Read Only)
  429 + */
  430 +
  431 +/*!
  432 + * RegDetectOptimize
  433 + */
  434 +#define RFLR_DETECTIONOPTIMIZE_MASK 0xF8
  435 +#define RFLR_DETECTIONOPTIMIZE_SF7_TO_SF12 0x03 // Default
  436 +#define RFLR_DETECTIONOPTIMIZE_SF6 0x05
  437 +
  438 +/*!
  439 + * RegInvertIQ
  440 + */
  441 +#define RFLR_INVERTIQ_RX_MASK 0xBF
  442 +#define RFLR_INVERTIQ_RX_OFF 0x00
  443 +#define RFLR_INVERTIQ_RX_ON 0x40
  444 +#define RFLR_INVERTIQ_TX_MASK 0xFE
  445 +#define RFLR_INVERTIQ_TX_OFF 0x01
  446 +#define RFLR_INVERTIQ_TX_ON 0x00
  447 +
  448 +/*!
  449 + * RegDetectionThreshold
  450 + */
  451 +#define RFLR_DETECTIONTHRESH_SF7_TO_SF12 0x0A // Default
  452 +#define RFLR_DETECTIONTHRESH_SF6 0x0C
  453 +
  454 +/*!
  455 + * RegInvertIQ2
  456 + */
  457 +#define RFLR_INVERTIQ2_ON 0x19
  458 +#define RFLR_INVERTIQ2_OFF 0x1D
  459 +
  460 +/*!
  461 + * RegDioMapping1
  462 + */
  463 +#define RFLR_DIOMAPPING1_DIO0_MASK 0x3F
  464 +#define RFLR_DIOMAPPING1_DIO0_00 0x00 // Default
  465 +#define RFLR_DIOMAPPING1_DIO0_01 0x40
  466 +#define RFLR_DIOMAPPING1_DIO0_10 0x80
  467 +#define RFLR_DIOMAPPING1_DIO0_11 0xC0
  468 +
  469 +#define RFLR_DIOMAPPING1_DIO1_MASK 0xCF
  470 +#define RFLR_DIOMAPPING1_DIO1_00 0x00 // Default
  471 +#define RFLR_DIOMAPPING1_DIO1_01 0x10
  472 +#define RFLR_DIOMAPPING1_DIO1_10 0x20
  473 +#define RFLR_DIOMAPPING1_DIO1_11 0x30
  474 +
  475 +#define RFLR_DIOMAPPING1_DIO2_MASK 0xF3
  476 +#define RFLR_DIOMAPPING1_DIO2_00 0x00 // Default
  477 +#define RFLR_DIOMAPPING1_DIO2_01 0x04
  478 +#define RFLR_DIOMAPPING1_DIO2_10 0x08
  479 +#define RFLR_DIOMAPPING1_DIO2_11 0x0C
  480 +
  481 +#define RFLR_DIOMAPPING1_DIO3_MASK 0xFC
  482 +#define RFLR_DIOMAPPING1_DIO3_00 0x00 // Default
  483 +#define RFLR_DIOMAPPING1_DIO3_01 0x01
  484 +#define RFLR_DIOMAPPING1_DIO3_10 0x02
  485 +#define RFLR_DIOMAPPING1_DIO3_11 0x03
  486 +
  487 +/*!
  488 + * RegDioMapping2
  489 + */
  490 +#define RFLR_DIOMAPPING2_DIO4_MASK 0x3F
  491 +#define RFLR_DIOMAPPING2_DIO4_00 0x00 // Default
  492 +#define RFLR_DIOMAPPING2_DIO4_01 0x40
  493 +#define RFLR_DIOMAPPING2_DIO4_10 0x80
  494 +#define RFLR_DIOMAPPING2_DIO4_11 0xC0
  495 +
  496 +#define RFLR_DIOMAPPING2_DIO5_MASK 0xCF
  497 +#define RFLR_DIOMAPPING2_DIO5_00 0x00 // Default
  498 +#define RFLR_DIOMAPPING2_DIO5_01 0x10
  499 +#define RFLR_DIOMAPPING2_DIO5_10 0x20
  500 +#define RFLR_DIOMAPPING2_DIO5_11 0x30
  501 +
  502 +#define RFLR_DIOMAPPING2_MAP_MASK 0xFE
  503 +#define RFLR_DIOMAPPING2_MAP_PREAMBLEDETECT 0x01
  504 +#define RFLR_DIOMAPPING2_MAP_RSSI 0x00 // Default
  505 +
  506 +/*!
  507 + * RegVersion (Read Only)
  508 + */
  509 +
  510 +/*!
  511 + * RegPllHop
  512 + */
  513 +#define RFLR_PLLHOP_FASTHOP_MASK 0x7F
  514 +#define RFLR_PLLHOP_FASTHOP_ON 0x80
  515 +#define RFLR_PLLHOP_FASTHOP_OFF 0x00 // Default
  516 +
  517 +/*!
  518 + * RegTcxo
  519 + */
  520 +#define RFLR_TCXO_TCXOINPUT_MASK 0xEF
  521 +#define RFLR_TCXO_TCXOINPUT_ON 0x10
  522 +#define RFLR_TCXO_TCXOINPUT_OFF 0x00 // Default
  523 +
  524 +/*!
  525 + * RegPaDac
  526 + */
  527 +#define RFLR_PADAC_20DBM_MASK 0xF8
  528 +#define RFLR_PADAC_20DBM_ON 0x07
  529 +#define RFLR_PADAC_20DBM_OFF 0x04 // Default
  530 +
  531 +/*!
  532 + * RegFormerTemp
  533 + */
  534 +
  535 +/*!
  536 + * RegBitrateFrac
  537 + */
  538 +#define RF_BITRATEFRAC_MASK 0xF0
  539 +
  540 +/*!
  541 + * RegAgcRef
  542 + */
  543 +
  544 +/*!
  545 + * RegAgcThresh1
  546 + */
  547 +
  548 +/*!
  549 + * RegAgcThresh2
  550 + */
  551 +
  552 +/*!
  553 + * RegAgcThresh3
  554 + */
  555 +
  556 +/*!
  557 + * RegPll
  558 + */
  559 +#define RF_PLL_BANDWIDTH_MASK 0x3F
  560 +#define RF_PLL_BANDWIDTH_75 0x00
  561 +#define RF_PLL_BANDWIDTH_150 0x40
  562 +#define RF_PLL_BANDWIDTH_225 0x80
  563 +#define RF_PLL_BANDWIDTH_300 0xC0 // Default
  564 +
  565 +#endif // __SX1276_REGS_LORA_H__
... ...
SX1276Lib/sx1276/sx1276-hal.cpp 0 → 100644
... ... @@ -0,0 +1,290 @@
  1 +/*
  2 + / _____) _ | |
  3 +( (____ _____ ____ _| |_ _____ ____| |__
  4 + \____ \| ___ | (_ _) ___ |/ ___) _ \
  5 + _____) ) ____| | | || |_| ____( (___| | | |
  6 +(______/|_____)_|_|_| \__)_____)\____)_| |_|
  7 + (C) 2014 Semtech
  8 +
  9 +Description: -
  10 +
  11 +License: Revised BSD License, see LICENSE.TXT file include in the project
  12 +
  13 +Maintainers: Miguel Luis, Gregory Cristian and Nicolas Huguenin
  14 +*/
  15 +#include "sx1276-hal.h"
  16 +
  17 +const RadioRegisters_t SX1276MB1xAS::RadioRegsInit[] = RADIO_INIT_REGISTERS_VALUE;
  18 +
  19 +SX1276MB1xAS::SX1276MB1xAS( RadioEvents_t *events,
  20 + PinName mosi, PinName miso, PinName sclk, PinName nss, PinName reset,
  21 + PinName dio0, PinName dio1, PinName dio2, PinName dio3, PinName dio4, PinName dio5,
  22 + PinName antSwitch )
  23 + : SX1276( events, mosi, miso, sclk, nss, reset, dio0, dio1, dio2, dio3, dio4, dio5 ),
  24 + antSwitch( antSwitch ),
  25 + #if( defined ( TARGET_NUCLEO_L152RE ) )
  26 + fake( D8 )
  27 + #else
  28 + fake( A3 )
  29 + #endif
  30 +{
  31 + this->RadioEvents = events;
  32 +
  33 + Reset( );
  34 +
  35 + RxChainCalibration( );
  36 +
  37 + IoInit( );
  38 +
  39 + SetOpMode( RF_OPMODE_SLEEP );
  40 +
  41 + IoIrqInit( dioIrq );
  42 +
  43 + RadioRegistersInit( );
  44 +
  45 + SetModem( MODEM_FSK );
  46 +
  47 + this->settings.State = RF_IDLE ;
  48 +}
  49 +
  50 +SX1276MB1xAS::SX1276MB1xAS( RadioEvents_t *events )
  51 + #if defined ( TARGET_NUCLEO_L152RE )
  52 + : SX1276( events, D11, D12, D13, D10, A0, D2, D3, D4, D5, A3, D9 ), // For NUCLEO L152RE dio4 is on port A3
  53 + antSwitch( A4 ),
  54 + fake( D8 )
  55 + #elif defined( TARGET_LPC11U6X )
  56 + : SX1276( events, D11, D12, D13, D10, A0, D2, D3, D4, D5, D8, D9 ),
  57 + antSwitch( P0_23 ),
  58 + fake( A3 )
  59 + #else
  60 + : SX1276( events, D11, D12, D13, D10, A0, D2, D3, D4, D5, D8, D9 ),
  61 + antSwitch( A4 ),
  62 + fake( A3 )
  63 + #endif
  64 +{
  65 + this->RadioEvents = events;
  66 +
  67 + Reset( );
  68 +
  69 + boardConnected = UNKNOWN;
  70 +
  71 + DetectBoardType( );
  72 +
  73 + RxChainCalibration( );
  74 +
  75 + IoInit( );
  76 +
  77 + SetOpMode( RF_OPMODE_SLEEP );
  78 + IoIrqInit( dioIrq );
  79 +
  80 + RadioRegistersInit( );
  81 +
  82 + SetModem( MODEM_FSK );
  83 +
  84 + this->settings.State = RF_IDLE ;
  85 +}
  86 +
  87 +//-------------------------------------------------------------------------
  88 +// Board relative functions
  89 +//-------------------------------------------------------------------------
  90 +uint8_t SX1276MB1xAS::DetectBoardType( void )
  91 +{
  92 + if( boardConnected == UNKNOWN )
  93 + {
  94 + antSwitch.input( );
  95 + wait_ms( 1 );
  96 + if( antSwitch == 1 )
  97 + {
  98 + boardConnected = SX1276MB1LAS;
  99 + }
  100 + else
  101 + {
  102 + boardConnected = SX1276MB1MAS;
  103 + }
  104 + antSwitch.output( );
  105 + wait_ms( 1 );
  106 + }
  107 + return ( boardConnected );
  108 +}
  109 +
  110 +void SX1276MB1xAS::IoInit( void )
  111 +{
  112 + AntSwInit( );
  113 + SpiInit( );
  114 +}
  115 +
  116 +void SX1276MB1xAS::RadioRegistersInit( )
  117 +{
  118 + uint8_t i = 0;
  119 + for( i = 0; i < sizeof( RadioRegsInit ) / sizeof( RadioRegisters_t ); i++ )
  120 + {
  121 + SetModem( RadioRegsInit[i].Modem );
  122 + Write( RadioRegsInit[i].Addr, RadioRegsInit[i].Value );
  123 + }
  124 +}
  125 +
  126 +void SX1276MB1xAS::SpiInit( void )
  127 +{
  128 + nss = 1;
  129 + spi.format( 8,0 );
  130 + uint32_t frequencyToSet = 8000000;
  131 + #if( defined ( TARGET_NUCLEO_L152RE ) || defined ( TARGET_LPC11U6X ) )
  132 + spi.frequency( frequencyToSet );
  133 + #elif( defined ( TARGET_KL25Z ) ) //busclock frequency is halved -> double the spi frequency to compensate
  134 + spi.frequency( frequencyToSet * 2 );
  135 + #else
  136 + #warning "Check the board's SPI frequency"
  137 + #endif
  138 + wait(0.1);
  139 +}
  140 +
  141 +void SX1276MB1xAS::IoIrqInit( DioIrqHandler *irqHandlers )
  142 +{
  143 +#if( defined ( TARGET_NUCLEO_L152RE ) || defined ( TARGET_LPC11U6X ) )
  144 + dio0.mode(PullDown);
  145 + dio1.mode(PullDown);
  146 + dio2.mode(PullDown);
  147 + dio3.mode(PullDown);
  148 + dio4.mode(PullDown);
  149 +#endif
  150 + dio0.rise( this, static_cast< TriggerMB1xAS > ( irqHandlers[0] ) );
  151 + dio1.rise( this, static_cast< TriggerMB1xAS > ( irqHandlers[1] ) );
  152 + dio2.rise( this, static_cast< TriggerMB1xAS > ( irqHandlers[2] ) );
  153 + dio3.rise( this, static_cast< TriggerMB1xAS > ( irqHandlers[3] ) );
  154 + dio4.rise( this, static_cast< TriggerMB1xAS > ( irqHandlers[4] ) );
  155 +}
  156 +
  157 +void SX1276MB1xAS::IoDeInit( void )
  158 +{
  159 + //nothing
  160 +}
  161 +
  162 +uint8_t SX1276MB1xAS::GetPaSelect( uint32_t channel )
  163 +{
  164 + if( channel > RF_MID_BAND_THRESH )
  165 + {
  166 + if( boardConnected == SX1276MB1LAS )
  167 + {
  168 + return RF_PACONFIG_PASELECT_PABOOST;
  169 + }
  170 + else
  171 + {
  172 + return RF_PACONFIG_PASELECT_RFO;
  173 + }
  174 + }
  175 + else
  176 + {
  177 + return RF_PACONFIG_PASELECT_RFO;
  178 + }
  179 +}
  180 +
  181 +void SX1276MB1xAS::SetAntSwLowPower( bool status )
  182 +{
  183 + if( isRadioActive != status )
  184 + {
  185 + isRadioActive = status;
  186 +
  187 + if( status == false )
  188 + {
  189 + AntSwInit( );
  190 + }
  191 + else
  192 + {
  193 + AntSwDeInit( );
  194 + }
  195 + }
  196 +}
  197 +
  198 +void SX1276MB1xAS::AntSwInit( void )
  199 +{
  200 + antSwitch = 0;
  201 +}
  202 +
  203 +void SX1276MB1xAS::AntSwDeInit( void )
  204 +{
  205 + antSwitch = 0;
  206 +}
  207 +
  208 +void SX1276MB1xAS::SetAntSw( uint8_t rxTx )
  209 +{
  210 + if( this->rxTx == rxTx )
  211 + {
  212 + //no need to go further
  213 + return;
  214 + }
  215 +
  216 + this->rxTx = rxTx;
  217 +
  218 + if( rxTx != 0 )
  219 + {
  220 + antSwitch = 1;
  221 + }
  222 + else
  223 + {
  224 + antSwitch = 0;
  225 + }
  226 +}
  227 +
  228 +bool SX1276MB1xAS::CheckRfFrequency( uint32_t frequency )
  229 +{
  230 + //TODO: Implement check, currently all frequencies are supported
  231 + return true;
  232 +}
  233 +
  234 +
  235 +void SX1276MB1xAS::Reset( void )
  236 +{
  237 + reset.output();
  238 + reset = 0;
  239 + wait_ms( 1 );
  240 + reset.input();
  241 + wait_ms( 6 );
  242 +}
  243 +
  244 +void SX1276MB1xAS::Write( uint8_t addr, uint8_t data )
  245 +{
  246 + Write( addr, &data, 1 );
  247 +}
  248 +
  249 +uint8_t SX1276MB1xAS::Read( uint8_t addr )
  250 +{
  251 + uint8_t data;
  252 + Read( addr, &data, 1 );
  253 + return data;
  254 +}
  255 +
  256 +void SX1276MB1xAS::Write( uint8_t addr, uint8_t *buffer, uint8_t size )
  257 +{
  258 + uint8_t i;
  259 +
  260 + nss = 0;
  261 + spi.write( addr | 0x80 );
  262 + for( i = 0; i < size; i++ )
  263 + {
  264 + spi.write( buffer[i] );
  265 + }
  266 + nss = 1;
  267 +}
  268 +
  269 +void SX1276MB1xAS::Read( uint8_t addr, uint8_t *buffer, uint8_t size )
  270 +{
  271 + uint8_t i;
  272 +
  273 + nss = 0;
  274 + spi.write( addr & 0x7F );
  275 + for( i = 0; i < size; i++ )
  276 + {
  277 + buffer[i] = spi.write( 0 );
  278 + }
  279 + nss = 1;
  280 +}
  281 +
  282 +void SX1276MB1xAS::WriteFifo( uint8_t *buffer, uint8_t size )
  283 +{
  284 + Write( 0, buffer, size );
  285 +}
  286 +
  287 +void SX1276MB1xAS::ReadFifo( uint8_t *buffer, uint8_t size )
  288 +{
  289 + Read( 0, buffer, size );
  290 +}
... ...
SX1276Lib/sx1276/sx1276-hal.h 0 → 100644
... ... @@ -0,0 +1,205 @@
  1 +/*
  2 + / _____) _ | |
  3 +( (____ _____ ____ _| |_ _____ ____| |__
  4 + \____ \| ___ | (_ _) ___ |/ ___) _ \
  5 + _____) ) ____| | | || |_| ____( (___| | | |
  6 +(______/|_____)_|_|_| \__)_____)\____)_| |_|
  7 + (C) 2014 Semtech
  8 +
  9 +Description: -
  10 +
  11 +License: Revised BSD License, see LICENSE.TXT file include in the project
  12 +
  13 +Maintainers: Miguel Luis, Gregory Cristian and Nicolas Huguenin
  14 +*/
  15 +#ifndef __SX1276_HAL_H__
  16 +#define __SX1276_HAL_H__
  17 +#include "sx1276.h"
  18 +
  19 +/*!
  20 + * \brief Radio hardware registers initialization definition
  21 + *
  22 + * \remark Can be automatically generated by the SX1276 GUI (not yet implemented)
  23 + */
  24 +#define RADIO_INIT_REGISTERS_VALUE \
  25 +{ \
  26 + { MODEM_FSK , REG_LNA , 0x23 },\
  27 + { MODEM_FSK , REG_RXCONFIG , 0x1E },\
  28 + { MODEM_FSK , REG_RSSICONFIG , 0xD2 },\
  29 + { MODEM_FSK , REG_PREAMBLEDETECT , 0xAA },\
  30 + { MODEM_FSK , REG_OSC , 0x07 },\
  31 + { MODEM_FSK , REG_SYNCCONFIG , 0x12 },\
  32 + { MODEM_FSK , REG_SYNCVALUE1 , 0xC1 },\
  33 + { MODEM_FSK , REG_SYNCVALUE2 , 0x94 },\
  34 + { MODEM_FSK , REG_SYNCVALUE3 , 0xC1 },\
  35 + { MODEM_FSK , REG_PACKETCONFIG1 , 0xD8 },\
  36 + { MODEM_FSK , REG_FIFOTHRESH , 0x8F },\
  37 + { MODEM_FSK , REG_IMAGECAL , 0x02 },\
  38 + { MODEM_FSK , REG_DIOMAPPING1 , 0x00 },\
  39 + { MODEM_FSK , REG_DIOMAPPING2 , 0x30 },\
  40 + { MODEM_LORA, REG_LR_PAYLOADMAXLENGTH, 0x40 },\
  41 +} \
  42 +
  43 +/*!
  44 + * Actual implementation of a SX1276 radio, includes some modifications to make it compatible with the MB1 LAS board
  45 + */
  46 +class SX1276MB1xAS : public SX1276
  47 +{
  48 +protected:
  49 + /*!
  50 + * Antenna switch GPIO pins objects
  51 + */
  52 + DigitalInOut antSwitch;
  53 +
  54 + DigitalIn fake;
  55 +
  56 +private:
  57 + static const RadioRegisters_t RadioRegsInit[];
  58 +
  59 +public:
  60 + SX1276MB1xAS( RadioEvents_t *events,
  61 + PinName mosi, PinName miso, PinName sclk, PinName nss, PinName reset,
  62 + PinName dio0, PinName dio1, PinName dio2, PinName dio3, PinName dio4, PinName dio5,
  63 + PinName antSwitch );
  64 +
  65 + SX1276MB1xAS( RadioEvents_t *events );
  66 +
  67 + virtual ~SX1276MB1xAS( ) { };
  68 +
  69 + protected:
  70 + /*!
  71 + * @brief Initializes the radio I/Os pins interface
  72 + */
  73 + virtual void IoInit( void );
  74 +
  75 + /*!
  76 + * @brief Initializes the radio registers
  77 + */
  78 + virtual void RadioRegistersInit( );
  79 +
  80 + /*!
  81 + * @brief Initializes the radio SPI
  82 + */
  83 + virtual void SpiInit( void );
  84 +
  85 + /*!
  86 + * @brief Initializes DIO IRQ handlers
  87 + *
  88 + * @param [IN] irqHandlers Array containing the IRQ callback functions
  89 + */
  90 + virtual void IoIrqInit( DioIrqHandler *irqHandlers );
  91 +
  92 + /*!
  93 + * @brief De-initializes the radio I/Os pins interface.
  94 + *
  95 + * \remark Useful when going in MCU lowpower modes
  96 + */
  97 + virtual void IoDeInit( void );
  98 +
  99 + /*!
  100 + * @brief Gets the board PA selection configuration
  101 + *
  102 + * @param [IN] channel Channel frequency in Hz
  103 + * @retval PaSelect RegPaConfig PaSelect value
  104 + */
  105 + virtual uint8_t GetPaSelect( uint32_t channel );
  106 +
  107 + /*!
  108 + * @brief Set the RF Switch I/Os pins in Low Power mode
  109 + *
  110 + * @param [IN] status enable or disable
  111 + */
  112 + virtual void SetAntSwLowPower( bool status );
  113 +
  114 + /*!
  115 + * @brief Initializes the RF Switch I/Os pins interface
  116 + */
  117 + virtual void AntSwInit( void );
  118 +
  119 + /*!
  120 + * @brief De-initializes the RF Switch I/Os pins interface
  121 + *
  122 + * \remark Needed to decrease the power consumption in MCU lowpower modes
  123 + */
  124 + virtual void AntSwDeInit( void );
  125 +
  126 + /*!
  127 + * @brief Controls the antena switch if necessary.
  128 + *
  129 + * \remark see errata note
  130 + *
  131 + * @param [IN] rxTx [1: Tx, 0: Rx]
  132 + */
  133 + virtual void SetAntSw( uint8_t rxTx );
  134 +
  135 + public:
  136 + /*!
  137 + * @brief Detect the board connected by reading the value of the antenna switch pin
  138 + */
  139 + virtual uint8_t DetectBoardType( void );
  140 +
  141 + /*!
  142 + * @brief Checks if the given RF frequency is supported by the hardware
  143 + *
  144 + * @param [IN] frequency RF frequency to be checked
  145 + * @retval isSupported [true: supported, false: unsupported]
  146 + */
  147 + virtual bool CheckRfFrequency( uint32_t frequency );
  148 +
  149 + /*!
  150 + * @brief Writes the radio register at the specified address
  151 + *
  152 + * @param [IN]: addr Register address
  153 + * @param [IN]: data New register value
  154 + */
  155 + virtual void Write ( uint8_t addr, uint8_t data ) ;
  156 +
  157 + /*!
  158 + * @brief Reads the radio register at the specified address
  159 + *
  160 + * @param [IN]: addr Register address
  161 + * @retval data Register value
  162 + */
  163 + virtual uint8_t Read ( uint8_t addr ) ;
  164 +
  165 + /*!
  166 + * @brief Writes multiple radio registers starting at address
  167 + *
  168 + * @param [IN] addr First Radio register address
  169 + * @param [IN] buffer Buffer containing the new register's values
  170 + * @param [IN] size Number of registers to be written
  171 + */
  172 + virtual void Write( uint8_t addr, uint8_t *buffer, uint8_t size ) ;
  173 +
  174 + /*!
  175 + * @brief Reads multiple radio registers starting at address
  176 + *
  177 + * @param [IN] addr First Radio register address
  178 + * @param [OUT] buffer Buffer where to copy the registers data
  179 + * @param [IN] size Number of registers to be read
  180 + */
  181 + virtual void Read ( uint8_t addr, uint8_t *buffer, uint8_t size ) ;
  182 +
  183 + /*!
  184 + * @brief Writes the buffer contents to the SX1276 FIFO
  185 + *
  186 + * @param [IN] buffer Buffer containing data to be put on the FIFO.
  187 + * @param [IN] size Number of bytes to be written to the FIFO
  188 + */
  189 + virtual void WriteFifo( uint8_t *buffer, uint8_t size ) ;
  190 +
  191 + /*!
  192 + * @brief Reads the contents of the SX1276 FIFO
  193 + *
  194 + * @param [OUT] buffer Buffer where to copy the FIFO read data.
  195 + * @param [IN] size Number of bytes to be read from the FIFO
  196 + */
  197 + virtual void ReadFifo( uint8_t *buffer, uint8_t size ) ;
  198 +
  199 + /*!
  200 + * @brief Reset the SX1276
  201 + */
  202 + virtual void Reset( void );
  203 +};
  204 +
  205 +#endif // __SX1276_HAL_H__
... ...
SX1276Lib/sx1276/sx1276.cpp 0 → 100644
... ... @@ -0,0 +1,1545 @@
  1 +/*
  2 + / _____) _ | |
  3 +( (____ _____ ____ _| |_ _____ ____| |__
  4 + \____ \| ___ | (_ _) ___ |/ ___) _ \
  5 + _____) ) ____| | | || |_| ____( (___| | | |
  6 +(______/|_____)_|_|_| \__)_____)\____)_| |_|
  7 + (C) 2014 Semtech
  8 +
  9 +Description: Actual implementation of a SX1276 radio, inherits Radio
  10 +
  11 +License: Revised BSD License, see LICENSE.TXT file include in the project
  12 +
  13 +Maintainers: Miguel Luis, Gregory Cristian and Nicolas Huguenin
  14 +*/
  15 +#include "sx1276.h"
  16 +
  17 +const FskBandwidth_t SX1276::FskBandwidths[] =
  18 +{
  19 + { 2600 , 0x17 },
  20 + { 3100 , 0x0F },
  21 + { 3900 , 0x07 },
  22 + { 5200 , 0x16 },
  23 + { 6300 , 0x0E },
  24 + { 7800 , 0x06 },
  25 + { 10400 , 0x15 },
  26 + { 12500 , 0x0D },
  27 + { 15600 , 0x05 },
  28 + { 20800 , 0x14 },
  29 + { 25000 , 0x0C },
  30 + { 31300 , 0x04 },
  31 + { 41700 , 0x13 },
  32 + { 50000 , 0x0B },
  33 + { 62500 , 0x03 },
  34 + { 83333 , 0x12 },
  35 + { 100000, 0x0A },
  36 + { 125000, 0x02 },
  37 + { 166700, 0x11 },
  38 + { 200000, 0x09 },
  39 + { 250000, 0x01 },
  40 + { 300000, 0x00 }, // Invalid Badwidth
  41 +};
  42 +
  43 +
  44 +SX1276::SX1276( RadioEvents_t *events,
  45 + PinName mosi, PinName miso, PinName sclk, PinName nss, PinName reset,
  46 + PinName dio0, PinName dio1, PinName dio2, PinName dio3, PinName dio4, PinName dio5 )
  47 + : Radio( events ),
  48 + spi( mosi, miso, sclk ),
  49 + nss( nss ),
  50 + reset( reset ),
  51 + dio0( dio0 ), dio1( dio1 ), dio2( dio2 ), dio3( dio3 ), dio4( dio4 ), dio5( dio5 ),
  52 + isRadioActive( false )
  53 +{
  54 + wait_ms( 10 );
  55 + this->rxTx = 0;
  56 + this->rxBuffer = new uint8_t[RX_BUFFER_SIZE];
  57 + previousOpMode = RF_OPMODE_STANDBY;
  58 +
  59 + this->RadioEvents = events;
  60 +
  61 + this->dioIrq = new DioIrqHandler[6];
  62 +
  63 + this->dioIrq[0] = &SX1276::OnDio0Irq;
  64 + this->dioIrq[1] = &SX1276::OnDio1Irq;
  65 + this->dioIrq[2] = &SX1276::OnDio2Irq;
  66 + this->dioIrq[3] = &SX1276::OnDio3Irq;
  67 + this->dioIrq[4] = &SX1276::OnDio4Irq;
  68 + this->dioIrq[5] = NULL;
  69 +
  70 + this->settings.State = RF_IDLE;
  71 +}
  72 +
  73 +SX1276::~SX1276( )
  74 +{
  75 + delete this->rxBuffer;
  76 + delete this->dioIrq;
  77 +}
  78 +
  79 +void SX1276::Init( RadioEvents_t *events )
  80 +{
  81 + this->RadioEvents = events;
  82 +}
  83 +
  84 +RadioState SX1276::GetStatus( void )
  85 +{
  86 + return this->settings.State;
  87 +}
  88 +
  89 +void SX1276::SetChannel( uint32_t freq )
  90 +{
  91 + this->settings.Channel = freq;
  92 + freq = ( uint32_t )( ( double )freq / ( double )FREQ_STEP );
  93 + Write( REG_FRFMSB, ( uint8_t )( ( freq >> 16 ) & 0xFF ) );
  94 + Write( REG_FRFMID, ( uint8_t )( ( freq >> 8 ) & 0xFF ) );
  95 + Write( REG_FRFLSB, ( uint8_t )( freq & 0xFF ) );
  96 +}
  97 +
  98 +bool SX1276::IsChannelFree( RadioModems_t modem, uint32_t freq, int16_t rssiThresh )
  99 +{
  100 + int16_t rssi = 0;
  101 +
  102 + SetModem( modem );
  103 +
  104 + SetChannel( freq );
  105 +
  106 + SetOpMode( RF_OPMODE_RECEIVER );
  107 +
  108 + wait_ms( 1 );
  109 +
  110 + rssi = GetRssi( modem );
  111 +
  112 + Sleep( );
  113 +
  114 + if( rssi > rssiThresh )
  115 + {
  116 + return false;
  117 + }
  118 + return true;
  119 +}
  120 +
  121 +uint32_t SX1276::Random( void )
  122 +{
  123 + uint8_t i;
  124 + uint32_t rnd = 0;
  125 +
  126 + /*
  127 + * Radio setup for random number generation
  128 + */
  129 + // Set LoRa modem ON
  130 + SetModem( MODEM_LORA );
  131 +
  132 + // Disable LoRa modem interrupts
  133 + Write( REG_LR_IRQFLAGSMASK, RFLR_IRQFLAGS_RXTIMEOUT |
  134 + RFLR_IRQFLAGS_RXDONE |
  135 + RFLR_IRQFLAGS_PAYLOADCRCERROR |
  136 + RFLR_IRQFLAGS_VALIDHEADER |
  137 + RFLR_IRQFLAGS_TXDONE |
  138 + RFLR_IRQFLAGS_CADDONE |
  139 + RFLR_IRQFLAGS_FHSSCHANGEDCHANNEL |
  140 + RFLR_IRQFLAGS_CADDETECTED );
  141 +
  142 + // Set radio in continuous reception
  143 + SetOpMode( RF_OPMODE_RECEIVER );
  144 +
  145 + for( i = 0; i < 32; i++ )
  146 + {
  147 + wait_ms( 1 );
  148 + // Unfiltered RSSI value reading. Only takes the LSB value
  149 + rnd |= ( ( uint32_t )Read( REG_LR_RSSIWIDEBAND ) & 0x01 ) << i;
  150 + }
  151 +
  152 + Sleep( );
  153 +
  154 + return rnd;
  155 +}
  156 +
  157 +/*!
  158 + * Performs the Rx chain calibration for LF and HF bands
  159 + * \remark Must be called just after the reset so all registers are at their
  160 + * default values
  161 + */
  162 +void SX1276::RxChainCalibration( void )
  163 +{
  164 + uint8_t regPaConfigInitVal;
  165 + uint32_t initialFreq;
  166 +
  167 + // Save context
  168 + regPaConfigInitVal = this->Read( REG_PACONFIG );
  169 + initialFreq = ( double )( ( ( uint32_t )this->Read( REG_FRFMSB ) << 16 ) |
  170 + ( ( uint32_t )this->Read( REG_FRFMID ) << 8 ) |
  171 + ( ( uint32_t )this->Read( REG_FRFLSB ) ) ) * ( double )FREQ_STEP;
  172 +
  173 + // Cut the PA just in case, RFO output, power = -1 dBm
  174 + this->Write( REG_PACONFIG, 0x00 );
  175 +
  176 + // Launch Rx chain calibration for LF band
  177 + Write ( REG_IMAGECAL, ( Read( REG_IMAGECAL ) & RF_IMAGECAL_IMAGECAL_MASK ) | RF_IMAGECAL_IMAGECAL_START );
  178 + while( ( Read( REG_IMAGECAL ) & RF_IMAGECAL_IMAGECAL_RUNNING ) == RF_IMAGECAL_IMAGECAL_RUNNING )
  179 + {
  180 + }
  181 +
  182 + // Sets a Frequency in HF band
  183 + SetChannel( 868000000 );
  184 +
  185 + // Launch Rx chain calibration for HF band
  186 + Write ( REG_IMAGECAL, ( Read( REG_IMAGECAL ) & RF_IMAGECAL_IMAGECAL_MASK ) | RF_IMAGECAL_IMAGECAL_START );
  187 + while( ( Read( REG_IMAGECAL ) & RF_IMAGECAL_IMAGECAL_RUNNING ) == RF_IMAGECAL_IMAGECAL_RUNNING )
  188 + {
  189 + }
  190 +
  191 + // Restore context
  192 + this->Write( REG_PACONFIG, regPaConfigInitVal );
  193 + SetChannel( initialFreq );
  194 +}
  195 +
  196 +/*!
  197 + * Returns the known FSK bandwidth registers value
  198 + *
  199 + * \param [IN] bandwidth Bandwidth value in Hz
  200 + * \retval regValue Bandwidth register value.
  201 + */
  202 +uint8_t SX1276::GetFskBandwidthRegValue( uint32_t bandwidth )
  203 +{
  204 + uint8_t i;
  205 +
  206 + for( i = 0; i < ( sizeof( FskBandwidths ) / sizeof( FskBandwidth_t ) ) - 1; i++ )
  207 + {
  208 + if( ( bandwidth >= FskBandwidths[i].bandwidth ) && ( bandwidth < FskBandwidths[i + 1].bandwidth ) )
  209 + {
  210 + return FskBandwidths[i].RegValue;
  211 + }
  212 + }
  213 + // ERROR: Value not found
  214 + while( 1 );
  215 +}
  216 +
  217 +void SX1276::SetRxConfig( RadioModems_t modem, uint32_t bandwidth,
  218 + uint32_t datarate, uint8_t coderate,
  219 + uint32_t bandwidthAfc, uint16_t preambleLen,
  220 + uint16_t symbTimeout, bool fixLen,
  221 + uint8_t payloadLen,
  222 + bool crcOn, bool freqHopOn, uint8_t hopPeriod,
  223 + bool iqInverted, bool rxContinuous )
  224 +{
  225 + SetModem( modem );
  226 +
  227 + switch( modem )
  228 + {
  229 + case MODEM_FSK:
  230 + {
  231 + this->settings.Fsk.Bandwidth = bandwidth;
  232 + this->settings.Fsk.Datarate = datarate;
  233 + this->settings.Fsk.BandwidthAfc = bandwidthAfc;
  234 + this->settings.Fsk.FixLen = fixLen;
  235 + this->settings.Fsk.PayloadLen = payloadLen;
  236 + this->settings.Fsk.CrcOn = crcOn;
  237 + this->settings.Fsk.IqInverted = iqInverted;
  238 + this->settings.Fsk.RxContinuous = rxContinuous;
  239 + this->settings.Fsk.PreambleLen = preambleLen;
  240 +
  241 + datarate = ( uint16_t )( ( double )XTAL_FREQ / ( double )datarate );
  242 + Write( REG_BITRATEMSB, ( uint8_t )( datarate >> 8 ) );
  243 + Write( REG_BITRATELSB, ( uint8_t )( datarate & 0xFF ) );
  244 +
  245 + Write( REG_RXBW, GetFskBandwidthRegValue( bandwidth ) );
  246 + Write( REG_AFCBW, GetFskBandwidthRegValue( bandwidthAfc ) );
  247 +
  248 + Write( REG_PREAMBLEMSB, ( uint8_t )( ( preambleLen >> 8 ) & 0xFF ) );
  249 + Write( REG_PREAMBLELSB, ( uint8_t )( preambleLen & 0xFF ) );
  250 +
  251 + if( fixLen == 1 )
  252 + {
  253 + Write( REG_PAYLOADLENGTH, payloadLen );
  254 + }
  255 +
  256 + Write( REG_PACKETCONFIG1,
  257 + ( Read( REG_PACKETCONFIG1 ) &
  258 + RF_PACKETCONFIG1_CRC_MASK &
  259 + RF_PACKETCONFIG1_PACKETFORMAT_MASK ) |
  260 + ( ( fixLen == 1 ) ? RF_PACKETCONFIG1_PACKETFORMAT_FIXED : RF_PACKETCONFIG1_PACKETFORMAT_VARIABLE ) |
  261 + ( crcOn << 4 ) );
  262 + }
  263 + break;
  264 + case MODEM_LORA:
  265 + {
  266 + if( bandwidth > 2 )
  267 + {
  268 + // Fatal error: When using LoRa modem only bandwidths 125, 250 and 500 kHz are supported
  269 + while( 1 );
  270 + }
  271 + bandwidth += 7;
  272 + this->settings.LoRa.Bandwidth = bandwidth;
  273 + this->settings.LoRa.Datarate = datarate;
  274 + this->settings.LoRa.Coderate = coderate;
  275 + this->settings.LoRa.PreambleLen = preambleLen;
  276 + this->settings.LoRa.FixLen = fixLen;
  277 + this->settings.LoRa.PayloadLen = payloadLen;
  278 + this->settings.LoRa.CrcOn = crcOn;
  279 + this->settings.LoRa.FreqHopOn = freqHopOn;
  280 + this->settings.LoRa.HopPeriod = hopPeriod;
  281 + this->settings.LoRa.IqInverted = iqInverted;
  282 + this->settings.LoRa.RxContinuous = rxContinuous;
  283 +
  284 + if( datarate > 12 )
  285 + {
  286 + datarate = 12;
  287 + }
  288 + else if( datarate < 6 )
  289 + {
  290 + datarate = 6;
  291 + }
  292 +
  293 + if( ( ( bandwidth == 7 ) && ( ( datarate == 11 ) || ( datarate == 12 ) ) ) ||
  294 + ( ( bandwidth == 8 ) && ( datarate == 12 ) ) )
  295 + {
  296 + this->settings.LoRa.LowDatarateOptimize = 0x01;
  297 + }
  298 + else
  299 + {
  300 + this->settings.LoRa.LowDatarateOptimize = 0x00;
  301 + }
  302 +
  303 + Write( REG_LR_MODEMCONFIG1,
  304 + ( Read( REG_LR_MODEMCONFIG1 ) &
  305 + RFLR_MODEMCONFIG1_BW_MASK &
  306 + RFLR_MODEMCONFIG1_CODINGRATE_MASK &
  307 + RFLR_MODEMCONFIG1_IMPLICITHEADER_MASK ) |
  308 + ( bandwidth << 4 ) | ( coderate << 1 ) |
  309 + fixLen );
  310 +
  311 + Write( REG_LR_MODEMCONFIG2,
  312 + ( Read( REG_LR_MODEMCONFIG2 ) &
  313 + RFLR_MODEMCONFIG2_SF_MASK &
  314 + RFLR_MODEMCONFIG2_RXPAYLOADCRC_MASK &
  315 + RFLR_MODEMCONFIG2_SYMBTIMEOUTMSB_MASK ) |
  316 + ( datarate << 4 ) | ( crcOn << 2 ) |
  317 + ( ( symbTimeout >> 8 ) & ~RFLR_MODEMCONFIG2_SYMBTIMEOUTMSB_MASK ) );
  318 +
  319 + Write( REG_LR_MODEMCONFIG3,
  320 + ( Read( REG_LR_MODEMCONFIG3 ) &
  321 + RFLR_MODEMCONFIG3_LOWDATARATEOPTIMIZE_MASK ) |
  322 + ( this->settings.LoRa.LowDatarateOptimize << 3 ) );
  323 +
  324 + Write( REG_LR_SYMBTIMEOUTLSB, ( uint8_t )( symbTimeout & 0xFF ) );
  325 +
  326 + Write( REG_LR_PREAMBLEMSB, ( uint8_t )( ( preambleLen >> 8 ) & 0xFF ) );
  327 + Write( REG_LR_PREAMBLELSB, ( uint8_t )( preambleLen & 0xFF ) );
  328 +
  329 + if( fixLen == 1 )
  330 + {
  331 + Write( REG_LR_PAYLOADLENGTH, payloadLen );
  332 + }
  333 +
  334 + if( this->settings.LoRa.FreqHopOn == true )
  335 + {
  336 + Write( REG_LR_PLLHOP, ( Read( REG_LR_PLLHOP ) & RFLR_PLLHOP_FASTHOP_MASK ) | RFLR_PLLHOP_FASTHOP_ON );
  337 + Write( REG_LR_HOPPERIOD, this->settings.LoRa.HopPeriod );
  338 + }
  339 +
  340 + if( ( bandwidth == 9 ) && ( RF_MID_BAND_THRESH ) )
  341 + {
  342 + // ERRATA 2.1 - Sensitivity Optimization with a 500 kHz Bandwidth
  343 + Write( REG_LR_TEST36, 0x02 );
  344 + Write( REG_LR_TEST3A, 0x64 );
  345 + }
  346 + else if( bandwidth == 9 )
  347 + {
  348 + // ERRATA 2.1 - Sensitivity Optimization with a 500 kHz Bandwidth
  349 + Write( REG_LR_TEST36, 0x02 );
  350 + Write( REG_LR_TEST3A, 0x7F );
  351 + }
  352 + else
  353 + {
  354 + // ERRATA 2.1 - Sensitivity Optimization with a 500 kHz Bandwidth
  355 + Write( REG_LR_TEST36, 0x03 );
  356 + }
  357 +
  358 + if( datarate == 6 )
  359 + {
  360 + Write( REG_LR_DETECTOPTIMIZE,
  361 + ( Read( REG_LR_DETECTOPTIMIZE ) &
  362 + RFLR_DETECTIONOPTIMIZE_MASK ) |
  363 + RFLR_DETECTIONOPTIMIZE_SF6 );
  364 + Write( REG_LR_DETECTIONTHRESHOLD,
  365 + RFLR_DETECTIONTHRESH_SF6 );
  366 + }
  367 + else
  368 + {
  369 + Write( REG_LR_DETECTOPTIMIZE,
  370 + ( Read( REG_LR_DETECTOPTIMIZE ) &
  371 + RFLR_DETECTIONOPTIMIZE_MASK ) |
  372 + RFLR_DETECTIONOPTIMIZE_SF7_TO_SF12 );
  373 + Write( REG_LR_DETECTIONTHRESHOLD,
  374 + RFLR_DETECTIONTHRESH_SF7_TO_SF12 );
  375 + }
  376 + }
  377 + break;
  378 + }
  379 +}
  380 +
  381 +void SX1276::SetTxConfig( RadioModems_t modem, int8_t power, uint32_t fdev,
  382 + uint32_t bandwidth, uint32_t datarate,
  383 + uint8_t coderate, uint16_t preambleLen,
  384 + bool fixLen, bool crcOn, bool freqHopOn,
  385 + uint8_t hopPeriod, bool iqInverted, uint32_t timeout )
  386 +{
  387 + uint8_t paConfig = 0;
  388 + uint8_t paDac = 0;
  389 +
  390 + SetModem( modem );
  391 +
  392 + paConfig = Read( REG_PACONFIG );
  393 + paDac = Read( REG_PADAC );
  394 +
  395 + paConfig = ( paConfig & RF_PACONFIG_PASELECT_MASK ) | GetPaSelect( this->settings.Channel );
  396 + paConfig = ( paConfig & RF_PACONFIG_MAX_POWER_MASK ) | 0x70;
  397 +
  398 + if( ( paConfig & RF_PACONFIG_PASELECT_PABOOST ) == RF_PACONFIG_PASELECT_PABOOST )
  399 + {
  400 + if( power > 17 )
  401 + {
  402 + paDac = ( paDac & RF_PADAC_20DBM_MASK ) | RF_PADAC_20DBM_ON;
  403 + }
  404 + else
  405 + {
  406 + paDac = ( paDac & RF_PADAC_20DBM_MASK ) | RF_PADAC_20DBM_OFF;
  407 + }
  408 + if( ( paDac & RF_PADAC_20DBM_ON ) == RF_PADAC_20DBM_ON )
  409 + {
  410 + if( power < 5 )
  411 + {
  412 + power = 5;
  413 + }
  414 + if( power > 20 )
  415 + {
  416 + power = 20;
  417 + }
  418 + paConfig = ( paConfig & RF_PACONFIG_OUTPUTPOWER_MASK ) | ( uint8_t )( ( uint16_t )( power - 5 ) & 0x0F );
  419 + }
  420 + else
  421 + {
  422 + if( power < 2 )
  423 + {
  424 + power = 2;
  425 + }
  426 + if( power > 17 )
  427 + {
  428 + power = 17;
  429 + }
  430 + paConfig = ( paConfig & RF_PACONFIG_OUTPUTPOWER_MASK ) | ( uint8_t )( ( uint16_t )( power - 2 ) & 0x0F );
  431 + }
  432 + }
  433 + else
  434 + {
  435 + if( power < -1 )
  436 + {
  437 + power = -1;
  438 + }
  439 + if( power > 14 )
  440 + {
  441 + power = 14;
  442 + }
  443 + paConfig = ( paConfig & RF_PACONFIG_OUTPUTPOWER_MASK ) | ( uint8_t )( ( uint16_t )( power + 1 ) & 0x0F );
  444 + }
  445 + Write( REG_PACONFIG, paConfig );
  446 + Write( REG_PADAC, paDac );
  447 +
  448 + switch( modem )
  449 + {
  450 + case MODEM_FSK:
  451 + {
  452 + this->settings.Fsk.Power = power;
  453 + this->settings.Fsk.Fdev = fdev;
  454 + this->settings.Fsk.Bandwidth = bandwidth;
  455 + this->settings.Fsk.Datarate = datarate;
  456 + this->settings.Fsk.PreambleLen = preambleLen;
  457 + this->settings.Fsk.FixLen = fixLen;
  458 + this->settings.Fsk.CrcOn = crcOn;
  459 + this->settings.Fsk.IqInverted = iqInverted;
  460 + this->settings.Fsk.TxTimeout = timeout;
  461 +
  462 + fdev = ( uint16_t )( ( double )fdev / ( double )FREQ_STEP );
  463 + Write( REG_FDEVMSB, ( uint8_t )( fdev >> 8 ) );
  464 + Write( REG_FDEVLSB, ( uint8_t )( fdev & 0xFF ) );
  465 +
  466 + datarate = ( uint16_t )( ( double )XTAL_FREQ / ( double )datarate );
  467 + Write( REG_BITRATEMSB, ( uint8_t )( datarate >> 8 ) );
  468 + Write( REG_BITRATELSB, ( uint8_t )( datarate & 0xFF ) );
  469 +
  470 + Write( REG_PREAMBLEMSB, ( preambleLen >> 8 ) & 0x00FF );
  471 + Write( REG_PREAMBLELSB, preambleLen & 0xFF );
  472 +
  473 + Write( REG_PACKETCONFIG1,
  474 + ( Read( REG_PACKETCONFIG1 ) &
  475 + RF_PACKETCONFIG1_CRC_MASK &
  476 + RF_PACKETCONFIG1_PACKETFORMAT_MASK ) |
  477 + ( ( fixLen == 1 ) ? RF_PACKETCONFIG1_PACKETFORMAT_FIXED : RF_PACKETCONFIG1_PACKETFORMAT_VARIABLE ) |
  478 + ( crcOn << 4 ) );
  479 +
  480 + }
  481 + break;
  482 + case MODEM_LORA:
  483 + {
  484 + this->settings.LoRa.Power = power;
  485 + if( bandwidth > 2 )
  486 + {
  487 + // Fatal error: When using LoRa modem only bandwidths 125, 250 and 500 kHz are supported
  488 + while( 1 );
  489 + }
  490 + bandwidth += 7;
  491 + this->settings.LoRa.Bandwidth = bandwidth;
  492 + this->settings.LoRa.Datarate = datarate;
  493 + this->settings.LoRa.Coderate = coderate;
  494 + this->settings.LoRa.PreambleLen = preambleLen;
  495 + this->settings.LoRa.FixLen = fixLen;
  496 + this->settings.LoRa.FreqHopOn = freqHopOn;
  497 + this->settings.LoRa.HopPeriod = hopPeriod;
  498 + this->settings.LoRa.CrcOn = crcOn;
  499 + this->settings.LoRa.IqInverted = iqInverted;
  500 + this->settings.LoRa.TxTimeout = timeout;
  501 +
  502 + if( datarate > 12 )
  503 + {
  504 + datarate = 12;
  505 + }
  506 + else if( datarate < 6 )
  507 + {
  508 + datarate = 6;
  509 + }
  510 + if( ( ( bandwidth == 7 ) && ( ( datarate == 11 ) || ( datarate == 12 ) ) ) ||
  511 + ( ( bandwidth == 8 ) && ( datarate == 12 ) ) )
  512 + {
  513 + this->settings.LoRa.LowDatarateOptimize = 0x01;
  514 + }
  515 + else
  516 + {
  517 + this->settings.LoRa.LowDatarateOptimize = 0x00;
  518 + }
  519 +
  520 + if( this->settings.LoRa.FreqHopOn == true )
  521 + {
  522 + Write( REG_LR_PLLHOP, ( Read( REG_LR_PLLHOP ) & RFLR_PLLHOP_FASTHOP_MASK ) | RFLR_PLLHOP_FASTHOP_ON );
  523 + Write( REG_LR_HOPPERIOD, this->settings.LoRa.HopPeriod );
  524 + }
  525 +
  526 + Write( REG_LR_MODEMCONFIG1,
  527 + ( Read( REG_LR_MODEMCONFIG1 ) &
  528 + RFLR_MODEMCONFIG1_BW_MASK &
  529 + RFLR_MODEMCONFIG1_CODINGRATE_MASK &
  530 + RFLR_MODEMCONFIG1_IMPLICITHEADER_MASK ) |
  531 + ( bandwidth << 4 ) | ( coderate << 1 ) |
  532 + fixLen );
  533 +
  534 + Write( REG_LR_MODEMCONFIG2,
  535 + ( Read( REG_LR_MODEMCONFIG2 ) &
  536 + RFLR_MODEMCONFIG2_SF_MASK &
  537 + RFLR_MODEMCONFIG2_RXPAYLOADCRC_MASK ) |
  538 + ( datarate << 4 ) | ( crcOn << 2 ) );
  539 +
  540 + Write( REG_LR_MODEMCONFIG3,
  541 + ( Read( REG_LR_MODEMCONFIG3 ) &
  542 + RFLR_MODEMCONFIG3_LOWDATARATEOPTIMIZE_MASK ) |
  543 + ( this->settings.LoRa.LowDatarateOptimize << 3 ) );
  544 +
  545 + Write( REG_LR_PREAMBLEMSB, ( preambleLen >> 8 ) & 0x00FF );
  546 + Write( REG_LR_PREAMBLELSB, preambleLen & 0xFF );
  547 +
  548 + if( datarate == 6 )
  549 + {
  550 + Write( REG_LR_DETECTOPTIMIZE,
  551 + ( Read( REG_LR_DETECTOPTIMIZE ) &
  552 + RFLR_DETECTIONOPTIMIZE_MASK ) |
  553 + RFLR_DETECTIONOPTIMIZE_SF6 );
  554 + Write( REG_LR_DETECTIONTHRESHOLD,
  555 + RFLR_DETECTIONTHRESH_SF6 );
  556 + }
  557 + else
  558 + {
  559 + Write( REG_LR_DETECTOPTIMIZE,
  560 + ( Read( REG_LR_DETECTOPTIMIZE ) &
  561 + RFLR_DETECTIONOPTIMIZE_MASK ) |
  562 + RFLR_DETECTIONOPTIMIZE_SF7_TO_SF12 );
  563 + Write( REG_LR_DETECTIONTHRESHOLD,
  564 + RFLR_DETECTIONTHRESH_SF7_TO_SF12 );
  565 + }
  566 + }
  567 + break;
  568 + }
  569 +}
  570 +
  571 +double SX1276::TimeOnAir( RadioModems_t modem, uint8_t pktLen )
  572 +{
  573 + uint32_t airTime = 0;
  574 +
  575 + switch( modem )
  576 + {
  577 + case MODEM_FSK:
  578 + {
  579 + airTime = rint( ( 8 * ( this->settings.Fsk.PreambleLen +
  580 + ( ( Read( REG_SYNCCONFIG ) & ~RF_SYNCCONFIG_SYNCSIZE_MASK ) + 1 ) +
  581 + ( ( this->settings.Fsk.FixLen == 0x01 ) ? 0.0 : 1.0 ) +
  582 + ( ( ( Read( REG_PACKETCONFIG1 ) & ~RF_PACKETCONFIG1_ADDRSFILTERING_MASK ) != 0x00 ) ? 1.0 : 0 ) +
  583 + pktLen +
  584 + ( ( this->settings.Fsk.CrcOn == 0x01 ) ? 2.0 : 0 ) ) /
  585 + this->settings.Fsk.Datarate ) * 1e6 );
  586 + }
  587 + break;
  588 + case MODEM_LORA:
  589 + {
  590 + double bw = 0.0;
  591 + // REMARK: When using LoRa modem only bandwidths 125, 250 and 500 kHz are supported
  592 + switch( this->settings.LoRa.Bandwidth )
  593 + {
  594 + //case 0: // 7.8 kHz
  595 + // bw = 78e2;
  596 + // break;
  597 + //case 1: // 10.4 kHz
  598 + // bw = 104e2;
  599 + // break;
  600 + //case 2: // 15.6 kHz
  601 + // bw = 156e2;
  602 + // break;
  603 + //case 3: // 20.8 kHz
  604 + // bw = 208e2;
  605 + // break;
  606 + //case 4: // 31.2 kHz
  607 + // bw = 312e2;
  608 + // break;
  609 + //case 5: // 41.4 kHz
  610 + // bw = 414e2;
  611 + // break;
  612 + //case 6: // 62.5 kHz
  613 + // bw = 625e2;
  614 + // break;
  615 + case 7: // 125 kHz
  616 + bw = 125e3;
  617 + break;
  618 + case 8: // 250 kHz
  619 + bw = 250e3;
  620 + break;
  621 + case 9: // 500 kHz
  622 + bw = 500e3;
  623 + break;
  624 + }
  625 +
  626 + // Symbol rate : time for one symbol (secs)
  627 + double rs = bw / ( 1 << this->settings.LoRa.Datarate );
  628 + double ts = 1 / rs;
  629 + // time of preamble
  630 + double tPreamble = ( this->settings.LoRa.PreambleLen + 4.25 ) * ts;
  631 + // Symbol length of payload and time
  632 + double tmp = ceil( ( 8 * pktLen - 4 * this->settings.LoRa.Datarate +
  633 + 28 + 16 * this->settings.LoRa.CrcOn -
  634 + ( this->settings.LoRa.FixLen ? 20 : 0 ) ) /
  635 + ( double )( 4 * this->settings.LoRa.Datarate -
  636 + ( ( this->settings.LoRa.LowDatarateOptimize > 0 ) ? 2 : 0 ) ) ) *
  637 + ( this->settings.LoRa.Coderate + 4 );
  638 + double nPayload = 8 + ( ( tmp > 0 ) ? tmp : 0 );
  639 + double tPayload = nPayload * ts;
  640 + // Time on air
  641 + double tOnAir = tPreamble + tPayload;
  642 + // return us secs
  643 + airTime = floor( tOnAir * 1e6 + 0.999 );
  644 + }
  645 + break;
  646 + }
  647 + return airTime;
  648 +}
  649 +
  650 +void SX1276::Send( uint8_t *buffer, uint8_t size )
  651 +{
  652 + uint32_t txTimeout = 0;
  653 +
  654 + switch( this->settings.Modem )
  655 + {
  656 + case MODEM_FSK:
  657 + {
  658 + this->settings.FskPacketHandler.NbBytes = 0;
  659 + this->settings.FskPacketHandler.Size = size;
  660 +
  661 + if( this->settings.Fsk.FixLen == false )
  662 + {
  663 + WriteFifo( ( uint8_t* )&size, 1 );
  664 + }
  665 + else
  666 + {
  667 + Write( REG_PAYLOADLENGTH, size );
  668 + }
  669 +
  670 + if( ( size > 0 ) && ( size <= 64 ) )
  671 + {
  672 + this->settings.FskPacketHandler.ChunkSize = size;
  673 + }
  674 + else
  675 + {
  676 + this->settings.FskPacketHandler.ChunkSize = 32;
  677 + }
  678 +
  679 + // Write payload buffer
  680 + WriteFifo( buffer, this->settings.FskPacketHandler.ChunkSize );
  681 + this->settings.FskPacketHandler.NbBytes += this->settings.FskPacketHandler.ChunkSize;
  682 + txTimeout = this->settings.Fsk.TxTimeout;
  683 + }
  684 + break;
  685 + case MODEM_LORA:
  686 + {
  687 + if( this->settings.LoRa.IqInverted == true )
  688 + {
  689 + Write( REG_LR_INVERTIQ, ( ( Read( REG_LR_INVERTIQ ) & RFLR_INVERTIQ_TX_MASK & RFLR_INVERTIQ_RX_MASK ) | RFLR_INVERTIQ_RX_OFF | RFLR_INVERTIQ_TX_ON ) );
  690 + Write( REG_LR_INVERTIQ2, RFLR_INVERTIQ2_ON );
  691 + }
  692 + else
  693 + {
  694 + Write( REG_LR_INVERTIQ, ( ( Read( REG_LR_INVERTIQ ) & RFLR_INVERTIQ_TX_MASK & RFLR_INVERTIQ_RX_MASK ) | RFLR_INVERTIQ_RX_OFF | RFLR_INVERTIQ_TX_OFF ) );
  695 + Write( REG_LR_INVERTIQ2, RFLR_INVERTIQ2_OFF );
  696 + }
  697 +
  698 + this->settings.LoRaPacketHandler.Size = size;
  699 +
  700 + // Initializes the payload size
  701 + Write( REG_LR_PAYLOADLENGTH, size );
  702 +
  703 + // Full buffer used for Tx
  704 + Write( REG_LR_FIFOTXBASEADDR, 0 );
  705 + Write( REG_LR_FIFOADDRPTR, 0 );
  706 +
  707 + // FIFO operations can not take place in Sleep mode
  708 + if( ( Read( REG_OPMODE ) & ~RF_OPMODE_MASK ) == RF_OPMODE_SLEEP )
  709 + {
  710 + Standby( );
  711 + wait_ms( 1 );
  712 + }
  713 + // Write payload buffer
  714 + WriteFifo( buffer, size );
  715 + txTimeout = this->settings.LoRa.TxTimeout;
  716 + }
  717 + break;
  718 + }
  719 +
  720 + Tx( txTimeout );
  721 +}
  722 +
  723 +void SX1276::Sleep( void )
  724 +{
  725 + txTimeoutTimer.detach( );
  726 + rxTimeoutTimer.detach( );
  727 +
  728 + SetOpMode( RF_OPMODE_SLEEP );
  729 + this->settings.State = RF_IDLE;
  730 +}
  731 +
  732 +void SX1276::Standby( void )
  733 +{
  734 + txTimeoutTimer.detach( );
  735 + rxTimeoutTimer.detach( );
  736 +
  737 + SetOpMode( RF_OPMODE_STANDBY );
  738 + this->settings.State = RF_IDLE;
  739 +}
  740 +
  741 +void SX1276::Rx( uint32_t timeout )
  742 +{
  743 + bool rxContinuous = false;
  744 +
  745 + switch( this->settings.Modem )
  746 + {
  747 + case MODEM_FSK:
  748 + {
  749 + rxContinuous = this->settings.Fsk.RxContinuous;
  750 +
  751 + // DIO0=PayloadReady
  752 + // DIO1=FifoLevel
  753 + // DIO2=SyncAddr
  754 + // DIO3=FifoEmpty
  755 + // DIO4=Preamble
  756 + // DIO5=ModeReady
  757 + Write( REG_DIOMAPPING1, ( Read( REG_DIOMAPPING1 ) & RF_DIOMAPPING1_DIO0_MASK &
  758 + RF_DIOMAPPING1_DIO2_MASK ) |
  759 + RF_DIOMAPPING1_DIO0_00 |
  760 + RF_DIOMAPPING1_DIO2_11 );
  761 +
  762 + Write( REG_DIOMAPPING2, ( Read( REG_DIOMAPPING2 ) & RF_DIOMAPPING2_DIO4_MASK &
  763 + RF_DIOMAPPING2_MAP_MASK ) |
  764 + RF_DIOMAPPING2_DIO4_11 |
  765 + RF_DIOMAPPING2_MAP_PREAMBLEDETECT );
  766 +
  767 + this->settings.FskPacketHandler.FifoThresh = Read( REG_FIFOTHRESH ) & 0x3F;
  768 +
  769 + this->settings.FskPacketHandler.PreambleDetected = false;
  770 + this->settings.FskPacketHandler.SyncWordDetected = false;
  771 + this->settings.FskPacketHandler.NbBytes = 0;
  772 + this->settings.FskPacketHandler.Size = 0;
  773 + }
  774 + break;
  775 + case MODEM_LORA:
  776 + {
  777 + if( this->settings.LoRa.IqInverted == true )
  778 + {
  779 + Write( REG_LR_INVERTIQ, ( ( Read( REG_LR_INVERTIQ ) & RFLR_INVERTIQ_TX_MASK & RFLR_INVERTIQ_RX_MASK ) | RFLR_INVERTIQ_RX_ON | RFLR_INVERTIQ_TX_OFF ) );
  780 + Write( REG_LR_INVERTIQ2, RFLR_INVERTIQ2_ON );
  781 + }
  782 + else
  783 + {
  784 + Write( REG_LR_INVERTIQ, ( ( Read( REG_LR_INVERTIQ ) & RFLR_INVERTIQ_TX_MASK & RFLR_INVERTIQ_RX_MASK ) | RFLR_INVERTIQ_RX_OFF | RFLR_INVERTIQ_TX_OFF ) );
  785 + Write( REG_LR_INVERTIQ2, RFLR_INVERTIQ2_OFF );
  786 + }
  787 +
  788 +
  789 + // ERRATA 2.3 - Receiver Spurious Reception of a LoRa Signal
  790 + if( this->settings.LoRa.Bandwidth < 9 )
  791 + {
  792 + Write( REG_LR_DETECTOPTIMIZE, Read( REG_LR_DETECTOPTIMIZE ) & 0x7F );
  793 + Write( REG_LR_TEST30, 0x00 );
  794 + switch( this->settings.LoRa.Bandwidth )
  795 + {
  796 + case 0: // 7.8 kHz
  797 + Write( REG_LR_TEST2F, 0x48 );
  798 + SetChannel(this->settings.Channel + 7.81e3 );
  799 + break;
  800 + case 1: // 10.4 kHz
  801 + Write( REG_LR_TEST2F, 0x44 );
  802 + SetChannel(this->settings.Channel + 10.42e3 );
  803 + break;
  804 + case 2: // 15.6 kHz
  805 + Write( REG_LR_TEST2F, 0x44 );
  806 + SetChannel(this->settings.Channel + 15.62e3 );
  807 + break;
  808 + case 3: // 20.8 kHz
  809 + Write( REG_LR_TEST2F, 0x44 );
  810 + SetChannel(this->settings.Channel + 20.83e3 );
  811 + break;
  812 + case 4: // 31.2 kHz
  813 + Write( REG_LR_TEST2F, 0x44 );
  814 + SetChannel(this->settings.Channel + 31.25e3 );
  815 + break;
  816 + case 5: // 41.4 kHz
  817 + Write( REG_LR_TEST2F, 0x44 );
  818 + SetChannel(this->settings.Channel + 41.67e3 );
  819 + break;
  820 + case 6: // 62.5 kHz
  821 + Write( REG_LR_TEST2F, 0x40 );
  822 + break;
  823 + case 7: // 125 kHz
  824 + Write( REG_LR_TEST2F, 0x40 );
  825 + break;
  826 + case 8: // 250 kHz
  827 + Write( REG_LR_TEST2F, 0x40 );
  828 + break;
  829 + }
  830 + }
  831 + else
  832 + {
  833 + Write( REG_LR_DETECTOPTIMIZE, Read( REG_LR_DETECTOPTIMIZE ) | 0x80 );
  834 + }
  835 +
  836 + rxContinuous = this->settings.LoRa.RxContinuous;
  837 +
  838 + if( this->settings.LoRa.FreqHopOn == true )
  839 + {
  840 + Write( REG_LR_IRQFLAGSMASK, //RFLR_IRQFLAGS_RXTIMEOUT |
  841 + //RFLR_IRQFLAGS_RXDONE |
  842 + //RFLR_IRQFLAGS_PAYLOADCRCERROR |
  843 + RFLR_IRQFLAGS_VALIDHEADER |
  844 + RFLR_IRQFLAGS_TXDONE |
  845 + RFLR_IRQFLAGS_CADDONE |
  846 + //RFLR_IRQFLAGS_FHSSCHANGEDCHANNEL |
  847 + RFLR_IRQFLAGS_CADDETECTED );
  848 +
  849 + // DIO0=RxDone, DIO2=FhssChangeChannel
  850 + Write( REG_DIOMAPPING1, ( Read( REG_DIOMAPPING1 ) & RFLR_DIOMAPPING1_DIO0_MASK & RFLR_DIOMAPPING1_DIO2_MASK ) | RFLR_DIOMAPPING1_DIO0_00 | RFLR_DIOMAPPING1_DIO2_00 );
  851 + }
  852 + else
  853 + {
  854 + Write( REG_LR_IRQFLAGSMASK, //RFLR_IRQFLAGS_RXTIMEOUT |
  855 + //RFLR_IRQFLAGS_RXDONE |
  856 + //RFLR_IRQFLAGS_PAYLOADCRCERROR |
  857 + RFLR_IRQFLAGS_VALIDHEADER |
  858 + RFLR_IRQFLAGS_TXDONE |
  859 + RFLR_IRQFLAGS_CADDONE |
  860 + RFLR_IRQFLAGS_FHSSCHANGEDCHANNEL |
  861 + RFLR_IRQFLAGS_CADDETECTED );
  862 +
  863 + // DIO0=RxDone
  864 + Write( REG_DIOMAPPING1, ( Read( REG_DIOMAPPING1 ) & RFLR_DIOMAPPING1_DIO0_MASK ) | RFLR_DIOMAPPING1_DIO0_00 );
  865 + }
  866 + Write( REG_LR_FIFORXBASEADDR, 0 );
  867 + Write( REG_LR_FIFOADDRPTR, 0 );
  868 + }
  869 + break;
  870 + }
  871 +
  872 + memset( rxBuffer, 0, ( size_t )RX_BUFFER_SIZE );
  873 +
  874 + this->settings.State = RF_RX_RUNNING;
  875 + if( timeout != 0 )
  876 + {
  877 + rxTimeoutTimer.attach_us( this, &SX1276::OnTimeoutIrq, timeout );
  878 + }
  879 +
  880 + if( this->settings.Modem == MODEM_FSK )
  881 + {
  882 + SetOpMode( RF_OPMODE_RECEIVER );
  883 +
  884 + if( rxContinuous == false )
  885 + {
  886 + rxTimeoutSyncWord.attach_us( this, &SX1276::OnTimeoutIrq, ( 8.0 * ( this->settings.Fsk.PreambleLen +
  887 + ( ( Read( REG_SYNCCONFIG ) &
  888 + ~RF_SYNCCONFIG_SYNCSIZE_MASK ) +
  889 + 1.0 ) + 10.0 ) /
  890 + ( double )this->settings.Fsk.Datarate ) * 1e6 );
  891 + }
  892 + }
  893 + else
  894 + {
  895 + if( rxContinuous == true )
  896 + {
  897 + SetOpMode( RFLR_OPMODE_RECEIVER );
  898 + }
  899 + else
  900 + {
  901 + SetOpMode( RFLR_OPMODE_RECEIVER_SINGLE );
  902 + }
  903 + }
  904 +}
  905 +
  906 +void SX1276::Tx( uint32_t timeout )
  907 +{
  908 +
  909 + switch( this->settings.Modem )
  910 + {
  911 + case MODEM_FSK:
  912 + {
  913 + // DIO0=PacketSent
  914 + // DIO1=FifoLevel
  915 + // DIO2=FifoFull
  916 + // DIO3=FifoEmpty
  917 + // DIO4=LowBat
  918 + // DIO5=ModeReady
  919 + Write( REG_DIOMAPPING1, ( Read( REG_DIOMAPPING1 ) & RF_DIOMAPPING1_DIO0_MASK &
  920 + RF_DIOMAPPING1_DIO2_MASK ) );
  921 +
  922 + Write( REG_DIOMAPPING2, ( Read( REG_DIOMAPPING2 ) & RF_DIOMAPPING2_DIO4_MASK &
  923 + RF_DIOMAPPING2_MAP_MASK ) );
  924 + this->settings.FskPacketHandler.FifoThresh = Read( REG_FIFOTHRESH ) & 0x3F;
  925 + }
  926 + break;
  927 + case MODEM_LORA:
  928 + {
  929 + if( this->settings.LoRa.FreqHopOn == true )
  930 + {
  931 + Write( REG_LR_IRQFLAGSMASK, RFLR_IRQFLAGS_RXTIMEOUT |
  932 + RFLR_IRQFLAGS_RXDONE |
  933 + RFLR_IRQFLAGS_PAYLOADCRCERROR |
  934 + RFLR_IRQFLAGS_VALIDHEADER |
  935 + //RFLR_IRQFLAGS_TXDONE |
  936 + RFLR_IRQFLAGS_CADDONE |
  937 + //RFLR_IRQFLAGS_FHSSCHANGEDCHANNEL |
  938 + RFLR_IRQFLAGS_CADDETECTED );
  939 +
  940 + // DIO0=TxDone, DIO2=FhssChangeChannel
  941 + Write( REG_DIOMAPPING1, ( Read( REG_DIOMAPPING1 ) & RFLR_DIOMAPPING1_DIO0_MASK & RFLR_DIOMAPPING1_DIO2_MASK ) | RFLR_DIOMAPPING1_DIO0_01 | RFLR_DIOMAPPING1_DIO2_00 );
  942 + }
  943 + else
  944 + {
  945 + Write( REG_LR_IRQFLAGSMASK, RFLR_IRQFLAGS_RXTIMEOUT |
  946 + RFLR_IRQFLAGS_RXDONE |
  947 + RFLR_IRQFLAGS_PAYLOADCRCERROR |
  948 + RFLR_IRQFLAGS_VALIDHEADER |
  949 + //RFLR_IRQFLAGS_TXDONE |
  950 + RFLR_IRQFLAGS_CADDONE |
  951 + RFLR_IRQFLAGS_FHSSCHANGEDCHANNEL |
  952 + RFLR_IRQFLAGS_CADDETECTED );
  953 +
  954 + // DIO0=TxDone
  955 + Write( REG_DIOMAPPING1, ( Read( REG_DIOMAPPING1 ) & RFLR_DIOMAPPING1_DIO0_MASK ) | RFLR_DIOMAPPING1_DIO0_01 );
  956 + }
  957 + }
  958 + break;
  959 + }
  960 +
  961 + this->settings.State = RF_TX_RUNNING;
  962 + txTimeoutTimer.attach_us( this, &SX1276::OnTimeoutIrq, timeout );
  963 + SetOpMode( RF_OPMODE_TRANSMITTER );
  964 +}
  965 +
  966 +void SX1276::StartCad( void )
  967 +{
  968 + switch( this->settings.Modem )
  969 + {
  970 + case MODEM_FSK:
  971 + {
  972 +
  973 + }
  974 + break;
  975 + case MODEM_LORA:
  976 + {
  977 + Write( REG_LR_IRQFLAGSMASK, RFLR_IRQFLAGS_RXTIMEOUT |
  978 + RFLR_IRQFLAGS_RXDONE |
  979 + RFLR_IRQFLAGS_PAYLOADCRCERROR |
  980 + RFLR_IRQFLAGS_VALIDHEADER |
  981 + RFLR_IRQFLAGS_TXDONE |
  982 + //RFLR_IRQFLAGS_CADDONE |
  983 + RFLR_IRQFLAGS_FHSSCHANGEDCHANNEL // |
  984 + //RFLR_IRQFLAGS_CADDETECTED
  985 + );
  986 +
  987 + // DIO3=CADDone
  988 + Write( REG_DIOMAPPING1, ( Read( REG_DIOMAPPING1 ) & RFLR_DIOMAPPING1_DIO0_MASK ) | RFLR_DIOMAPPING1_DIO0_00 );
  989 +
  990 + this->settings.State = RF_CAD;
  991 + SetOpMode( RFLR_OPMODE_CAD );
  992 + }
  993 + break;
  994 + default:
  995 + break;
  996 + }
  997 +}
  998 +
  999 +int16_t SX1276::GetRssi( RadioModems_t modem )
  1000 +{
  1001 + int16_t rssi = 0;
  1002 +
  1003 + switch( modem )
  1004 + {
  1005 + case MODEM_FSK:
  1006 + rssi = -( Read( REG_RSSIVALUE ) >> 1 );
  1007 + break;
  1008 + case MODEM_LORA:
  1009 + if( this->settings.Channel > RF_MID_BAND_THRESH )
  1010 + {
  1011 + rssi = RSSI_OFFSET_HF + Read( REG_LR_RSSIVALUE );
  1012 + }
  1013 + else
  1014 + {
  1015 + rssi = RSSI_OFFSET_LF + Read( REG_LR_RSSIVALUE );
  1016 + }
  1017 + break;
  1018 + default:
  1019 + rssi = -1;
  1020 + break;
  1021 + }
  1022 + return rssi;
  1023 +}
  1024 +
  1025 +void SX1276::SetOpMode( uint8_t opMode )
  1026 +{
  1027 + if( opMode != previousOpMode )
  1028 + {
  1029 + previousOpMode = opMode;
  1030 + if( opMode == RF_OPMODE_SLEEP )
  1031 + {
  1032 + SetAntSwLowPower( true );
  1033 + }
  1034 + else
  1035 + {
  1036 + SetAntSwLowPower( false );
  1037 + if( opMode == RF_OPMODE_TRANSMITTER )
  1038 + {
  1039 + SetAntSw( 1 );
  1040 + }
  1041 + else
  1042 + {
  1043 + SetAntSw( 0 );
  1044 + }
  1045 + }
  1046 + Write( REG_OPMODE, ( Read( REG_OPMODE ) & RF_OPMODE_MASK ) | opMode );
  1047 + }
  1048 +}
  1049 +
  1050 +void SX1276::SetModem( RadioModems_t modem )
  1051 +{
  1052 + if( this->settings.Modem == modem )
  1053 + {
  1054 + return;
  1055 + }
  1056 +
  1057 + this->settings.Modem = modem;
  1058 + switch( this->settings.Modem )
  1059 + {
  1060 + default:
  1061 + case MODEM_FSK:
  1062 + SetOpMode( RF_OPMODE_SLEEP );
  1063 + Write( REG_OPMODE, ( Read( REG_OPMODE ) & RFLR_OPMODE_LONGRANGEMODE_MASK ) | RFLR_OPMODE_LONGRANGEMODE_OFF );
  1064 +
  1065 + Write( REG_DIOMAPPING1, 0x00 );
  1066 + Write( REG_DIOMAPPING2, 0x30 ); // DIO5=ModeReady
  1067 + break;
  1068 + case MODEM_LORA:
  1069 + SetOpMode( RF_OPMODE_SLEEP );
  1070 + Write( REG_OPMODE, ( Read( REG_OPMODE ) & RFLR_OPMODE_LONGRANGEMODE_MASK ) | RFLR_OPMODE_LONGRANGEMODE_ON );
  1071 +
  1072 + Write( REG_DIOMAPPING1, 0x00 );
  1073 + Write( REG_DIOMAPPING2, 0x00 );
  1074 + break;
  1075 + }
  1076 +}
  1077 +
  1078 +void SX1276::SetMaxPayloadLength( RadioModems_t modem, uint8_t max )
  1079 +{
  1080 + this->SetModem( modem );
  1081 +
  1082 + switch( modem )
  1083 + {
  1084 + case MODEM_FSK:
  1085 + if( this->settings.Fsk.FixLen == false )
  1086 + {
  1087 + this->Write( REG_PAYLOADLENGTH, max );
  1088 + }
  1089 + break;
  1090 + case MODEM_LORA:
  1091 + this->Write( REG_LR_PAYLOADMAXLENGTH, max );
  1092 + break;
  1093 + }
  1094 +}
  1095 +
  1096 +void SX1276::OnTimeoutIrq( void )
  1097 +{
  1098 + switch( this->settings.State )
  1099 + {
  1100 + case RF_RX_RUNNING:
  1101 + if( this->settings.Modem == MODEM_FSK )
  1102 + {
  1103 + this->settings.FskPacketHandler.PreambleDetected = false;
  1104 + this->settings.FskPacketHandler.SyncWordDetected = false;
  1105 + this->settings.FskPacketHandler.NbBytes = 0;
  1106 + this->settings.FskPacketHandler.Size = 0;
  1107 +
  1108 + // Clear Irqs
  1109 + Write( REG_IRQFLAGS1, RF_IRQFLAGS1_RSSI |
  1110 + RF_IRQFLAGS1_PREAMBLEDETECT |
  1111 + RF_IRQFLAGS1_SYNCADDRESSMATCH );
  1112 + Write( REG_IRQFLAGS2, RF_IRQFLAGS2_FIFOOVERRUN );
  1113 +
  1114 + if( this->settings.Fsk.RxContinuous == true )
  1115 + {
  1116 + // Continuous mode restart Rx chain
  1117 + Write( REG_RXCONFIG, Read( REG_RXCONFIG ) | RF_RXCONFIG_RESTARTRXWITHOUTPLLLOCK );
  1118 + }
  1119 + else
  1120 + {
  1121 + this->settings.State = RF_IDLE;
  1122 + rxTimeoutSyncWord.detach( );
  1123 + }
  1124 + }
  1125 + if( ( this->RadioEvents != NULL ) && ( this->RadioEvents->RxTimeout != NULL ) )
  1126 + {
  1127 + this->RadioEvents->RxTimeout( );
  1128 + }
  1129 + break;
  1130 + case RF_TX_RUNNING:
  1131 + this->settings.State = RF_IDLE;
  1132 + if( ( this->RadioEvents != NULL ) && ( this->RadioEvents->TxTimeout != NULL ) )
  1133 + {
  1134 + this->RadioEvents->TxTimeout( );
  1135 + }
  1136 + break;
  1137 + default:
  1138 + break;
  1139 + }
  1140 +}
  1141 +
  1142 +void SX1276::OnDio0Irq( void )
  1143 +{
  1144 + volatile uint8_t irqFlags = 0;
  1145 +
  1146 + switch( this->settings.State )
  1147 + {
  1148 + case RF_RX_RUNNING:
  1149 + //TimerStop( &RxTimeoutTimer );
  1150 + // RxDone interrupt
  1151 + switch( this->settings.Modem )
  1152 + {
  1153 + case MODEM_FSK:
  1154 + if( this->settings.Fsk.CrcOn == true )
  1155 + {
  1156 + irqFlags = Read( REG_IRQFLAGS2 );
  1157 + if( ( irqFlags & RF_IRQFLAGS2_CRCOK ) != RF_IRQFLAGS2_CRCOK )
  1158 + {
  1159 + // Clear Irqs
  1160 + Write( REG_IRQFLAGS1, RF_IRQFLAGS1_RSSI |
  1161 + RF_IRQFLAGS1_PREAMBLEDETECT |
  1162 + RF_IRQFLAGS1_SYNCADDRESSMATCH );
  1163 + Write( REG_IRQFLAGS2, RF_IRQFLAGS2_FIFOOVERRUN );
  1164 +
  1165 + if( this->settings.Fsk.RxContinuous == false )
  1166 + {
  1167 + this->settings.State = RF_IDLE;
  1168 + rxTimeoutSyncWord.attach_us( this, &SX1276::OnTimeoutIrq, ( 8.0 * ( this->settings.Fsk.PreambleLen +
  1169 + ( ( Read( REG_SYNCCONFIG ) &
  1170 + ~RF_SYNCCONFIG_SYNCSIZE_MASK ) +
  1171 + 1.0 ) + 10.0 ) /
  1172 + ( double )this->settings.Fsk.Datarate ) * 1e6 ) ;
  1173 + }
  1174 + else
  1175 + {
  1176 + // Continuous mode restart Rx chain
  1177 + Write( REG_RXCONFIG, Read( REG_RXCONFIG ) | RF_RXCONFIG_RESTARTRXWITHOUTPLLLOCK );
  1178 + }
  1179 + rxTimeoutTimer.detach( );
  1180 +
  1181 + if( ( this->RadioEvents != NULL ) && ( this->RadioEvents->RxError != NULL ) )
  1182 + {
  1183 + this->RadioEvents->RxError( );
  1184 + }
  1185 + this->settings.FskPacketHandler.PreambleDetected = false;
  1186 + this->settings.FskPacketHandler.SyncWordDetected = false;
  1187 + this->settings.FskPacketHandler.NbBytes = 0;
  1188 + this->settings.FskPacketHandler.Size = 0;
  1189 + break;
  1190 + }
  1191 + }
  1192 +
  1193 + // Read received packet size
  1194 + if( ( this->settings.FskPacketHandler.Size == 0 ) && ( this->settings.FskPacketHandler.NbBytes == 0 ) )
  1195 + {
  1196 + if( this->settings.Fsk.FixLen == false )
  1197 + {
  1198 + ReadFifo( ( uint8_t* )&this->settings.FskPacketHandler.Size, 1 );
  1199 + }
  1200 + else
  1201 + {
  1202 + this->settings.FskPacketHandler.Size = Read( REG_PAYLOADLENGTH );
  1203 + }
  1204 + ReadFifo( rxBuffer + this->settings.FskPacketHandler.NbBytes, this->settings.FskPacketHandler.Size - this->settings.FskPacketHandler.NbBytes );
  1205 + this->settings.FskPacketHandler.NbBytes += ( this->settings.FskPacketHandler.Size - this->settings.FskPacketHandler.NbBytes );
  1206 + }
  1207 + else
  1208 + {
  1209 + ReadFifo( rxBuffer + this->settings.FskPacketHandler.NbBytes, this->settings.FskPacketHandler.Size - this->settings.FskPacketHandler.NbBytes );
  1210 + this->settings.FskPacketHandler.NbBytes += ( this->settings.FskPacketHandler.Size - this->settings.FskPacketHandler.NbBytes );
  1211 + }
  1212 +
  1213 + if( this->settings.Fsk.RxContinuous == false )
  1214 + {
  1215 + this->settings.State = RF_IDLE;
  1216 + rxTimeoutSyncWord.attach_us( this, &SX1276::OnTimeoutIrq, ( 8.0 * ( this->settings.Fsk.PreambleLen +
  1217 + ( ( Read( REG_SYNCCONFIG ) &
  1218 + ~RF_SYNCCONFIG_SYNCSIZE_MASK ) +
  1219 + 1.0 ) + 10.0 ) /
  1220 + ( double )this->settings.Fsk.Datarate ) * 1e6 ) ;
  1221 + }
  1222 + else
  1223 + {
  1224 + // Continuous mode restart Rx chain
  1225 + Write( REG_RXCONFIG, Read( REG_RXCONFIG ) | RF_RXCONFIG_RESTARTRXWITHOUTPLLLOCK );
  1226 + }
  1227 + rxTimeoutTimer.detach( );
  1228 +
  1229 + if( ( this->RadioEvents != NULL ) && ( this->RadioEvents->RxDone != NULL ) )
  1230 + {
  1231 + this->RadioEvents->RxDone( rxBuffer, this->settings.FskPacketHandler.Size, this->settings.FskPacketHandler.RssiValue, 0 );
  1232 + }
  1233 + this->settings.FskPacketHandler.PreambleDetected = false;
  1234 + this->settings.FskPacketHandler.SyncWordDetected = false;
  1235 + this->settings.FskPacketHandler.NbBytes = 0;
  1236 + this->settings.FskPacketHandler.Size = 0;
  1237 + break;
  1238 + case MODEM_LORA:
  1239 + {
  1240 + int8_t snr = 0;
  1241 +
  1242 + // Clear Irq
  1243 + Write( REG_LR_IRQFLAGS, RFLR_IRQFLAGS_RXDONE );
  1244 +
  1245 + irqFlags = Read( REG_LR_IRQFLAGS );
  1246 + if( ( irqFlags & RFLR_IRQFLAGS_PAYLOADCRCERROR_MASK ) == RFLR_IRQFLAGS_PAYLOADCRCERROR )
  1247 + {
  1248 + // Clear Irq
  1249 + Write( REG_LR_IRQFLAGS, RFLR_IRQFLAGS_PAYLOADCRCERROR );
  1250 +
  1251 + if( this->settings.LoRa.RxContinuous == false )
  1252 + {
  1253 + this->settings.State = RF_IDLE;
  1254 + }
  1255 + rxTimeoutTimer.detach( );
  1256 +
  1257 + if( ( this->RadioEvents != NULL ) && ( this->RadioEvents->RxError != NULL ) )
  1258 + {
  1259 + this->RadioEvents->RxError( );
  1260 + }
  1261 + break;
  1262 + }
  1263 +
  1264 + this->settings.LoRaPacketHandler.SnrValue = Read( REG_LR_PKTSNRVALUE );
  1265 + if( this->settings.LoRaPacketHandler.SnrValue & 0x80 ) // The SNR sign bit is 1
  1266 + {
  1267 + // Invert and divide by 4
  1268 + snr = ( ( ~this->settings.LoRaPacketHandler.SnrValue + 1 ) & 0xFF ) >> 2;
  1269 + snr = -snr;
  1270 + }
  1271 + else
  1272 + {
  1273 + // Divide by 4
  1274 + snr = ( this->settings.LoRaPacketHandler.SnrValue & 0xFF ) >> 2;
  1275 + }
  1276 +
  1277 + int16_t rssi = Read( REG_LR_PKTRSSIVALUE );
  1278 + if( snr < 0 )
  1279 + {
  1280 + if( this->settings.Channel > RF_MID_BAND_THRESH )
  1281 + {
  1282 + this->settings.LoRaPacketHandler.RssiValue = RSSI_OFFSET_HF + rssi + ( rssi >> 4 ) +
  1283 + snr;
  1284 + }
  1285 + else
  1286 + {
  1287 + this->settings.LoRaPacketHandler.RssiValue = RSSI_OFFSET_LF + rssi + ( rssi >> 4 ) +
  1288 + snr;
  1289 + }
  1290 + }
  1291 + else
  1292 + {
  1293 + if( this->settings.Channel > RF_MID_BAND_THRESH )
  1294 + {
  1295 + this->settings.LoRaPacketHandler.RssiValue = RSSI_OFFSET_HF + rssi + ( rssi >> 4 );
  1296 + }
  1297 + else
  1298 + {
  1299 + this->settings.LoRaPacketHandler.RssiValue = RSSI_OFFSET_LF + rssi + ( rssi >> 4 );
  1300 + }
  1301 + }
  1302 +
  1303 + this->settings.LoRaPacketHandler.Size = Read( REG_LR_RXNBBYTES );
  1304 + ReadFifo( rxBuffer, this->settings.LoRaPacketHandler.Size );
  1305 +
  1306 + if( this->settings.LoRa.RxContinuous == false )
  1307 + {
  1308 + this->settings.State = RF_IDLE;
  1309 + }
  1310 + rxTimeoutTimer.detach( );
  1311 +
  1312 + if( ( this->RadioEvents != NULL ) && ( this->RadioEvents->RxDone != NULL ) )
  1313 + {
  1314 + this->RadioEvents->RxDone( rxBuffer, this->settings.LoRaPacketHandler.Size, this->settings.LoRaPacketHandler.RssiValue, this->settings.LoRaPacketHandler.SnrValue );
  1315 + }
  1316 + }
  1317 + break;
  1318 + default:
  1319 + break;
  1320 + }
  1321 + break;
  1322 + case RF_TX_RUNNING:
  1323 + txTimeoutTimer.detach( );
  1324 + // TxDone interrupt
  1325 + switch( this->settings.Modem )
  1326 + {
  1327 + case MODEM_LORA:
  1328 + // Clear Irq
  1329 + Write( REG_LR_IRQFLAGS, RFLR_IRQFLAGS_TXDONE );
  1330 + // Intentional fall through
  1331 + case MODEM_FSK:
  1332 + default:
  1333 + this->settings.State = RF_IDLE;
  1334 + if( ( this->RadioEvents != NULL ) && ( this->RadioEvents->TxDone != NULL ) )
  1335 + {
  1336 + this->RadioEvents->TxDone( );
  1337 + }
  1338 + break;
  1339 + }
  1340 + break;
  1341 + default:
  1342 + break;
  1343 + }
  1344 +}
  1345 +
  1346 +void SX1276::OnDio1Irq( void )
  1347 +{
  1348 + switch( this->settings.State )
  1349 + {
  1350 + case RF_RX_RUNNING:
  1351 + switch( this->settings.Modem )
  1352 + {
  1353 + case MODEM_FSK:
  1354 + // FifoLevel interrupt
  1355 + // Read received packet size
  1356 + if( ( this->settings.FskPacketHandler.Size == 0 ) && ( this->settings.FskPacketHandler.NbBytes == 0 ) )
  1357 + {
  1358 + if( this->settings.Fsk.FixLen == false )
  1359 + {
  1360 + ReadFifo( ( uint8_t* )&this->settings.FskPacketHandler.Size, 1 );
  1361 + }
  1362 + else
  1363 + {
  1364 + this->settings.FskPacketHandler.Size = Read( REG_PAYLOADLENGTH );
  1365 + }
  1366 + }
  1367 +
  1368 + if( ( this->settings.FskPacketHandler.Size - this->settings.FskPacketHandler.NbBytes ) > this->settings.FskPacketHandler.FifoThresh )
  1369 + {
  1370 + ReadFifo( ( rxBuffer + this->settings.FskPacketHandler.NbBytes ), this->settings.FskPacketHandler.FifoThresh );
  1371 + this->settings.FskPacketHandler.NbBytes += this->settings.FskPacketHandler.FifoThresh;
  1372 + }
  1373 + else
  1374 + {
  1375 + ReadFifo( ( rxBuffer + this->settings.FskPacketHandler.NbBytes ), this->settings.FskPacketHandler.Size - this->settings.FskPacketHandler.NbBytes );
  1376 + this->settings.FskPacketHandler.NbBytes += ( this->settings.FskPacketHandler.Size - this->settings.FskPacketHandler.NbBytes );
  1377 + }
  1378 + break;
  1379 + case MODEM_LORA:
  1380 + // Sync time out
  1381 + rxTimeoutTimer.detach( );
  1382 + this->settings.State = RF_IDLE;
  1383 + if( ( this->RadioEvents != NULL ) && ( this->RadioEvents->RxTimeout != NULL ) )
  1384 + {
  1385 + this->RadioEvents->RxTimeout( );
  1386 + }
  1387 + break;
  1388 + default:
  1389 + break;
  1390 + }
  1391 + break;
  1392 + case RF_TX_RUNNING:
  1393 + switch( this->settings.Modem )
  1394 + {
  1395 + case MODEM_FSK:
  1396 + // FifoLevel interrupt
  1397 + if( ( this->settings.FskPacketHandler.Size - this->settings.FskPacketHandler.NbBytes ) > this->settings.FskPacketHandler.ChunkSize )
  1398 + {
  1399 + WriteFifo( ( rxBuffer + this->settings.FskPacketHandler.NbBytes ), this->settings.FskPacketHandler.ChunkSize );
  1400 + this->settings.FskPacketHandler.NbBytes += this->settings.FskPacketHandler.ChunkSize;
  1401 + }
  1402 + else
  1403 + {
  1404 + // Write the last chunk of data
  1405 + WriteFifo( rxBuffer + this->settings.FskPacketHandler.NbBytes, this->settings.FskPacketHandler.Size - this->settings.FskPacketHandler.NbBytes );
  1406 + this->settings.FskPacketHandler.NbBytes += this->settings.FskPacketHandler.Size - this->settings.FskPacketHandler.NbBytes;
  1407 + }
  1408 + break;
  1409 + case MODEM_LORA:
  1410 + break;
  1411 + default:
  1412 + break;
  1413 + }
  1414 + break;
  1415 + default:
  1416 + break;
  1417 + }
  1418 +}
  1419 +
  1420 +void SX1276::OnDio2Irq( void )
  1421 +{
  1422 + switch( this->settings.State )
  1423 + {
  1424 + case RF_RX_RUNNING:
  1425 + switch( this->settings.Modem )
  1426 + {
  1427 + case MODEM_FSK:
  1428 + if( ( this->settings.FskPacketHandler.PreambleDetected == true ) && ( this->settings.FskPacketHandler.SyncWordDetected == false ) )
  1429 + {
  1430 + rxTimeoutSyncWord.detach( );
  1431 +
  1432 + this->settings.FskPacketHandler.SyncWordDetected = true;
  1433 +
  1434 + this->settings.FskPacketHandler.RssiValue = -( Read( REG_RSSIVALUE ) >> 1 );
  1435 +
  1436 + this->settings.FskPacketHandler.AfcValue = ( int32_t )( double )( ( ( uint16_t )Read( REG_AFCMSB ) << 8 ) |
  1437 + ( uint16_t )Read( REG_AFCLSB ) ) *
  1438 + ( double )FREQ_STEP;
  1439 + this->settings.FskPacketHandler.RxGain = ( Read( REG_LNA ) >> 5 ) & 0x07;
  1440 + }
  1441 + break;
  1442 + case MODEM_LORA:
  1443 + if( this->settings.LoRa.FreqHopOn == true )
  1444 + {
  1445 + // Clear Irq
  1446 + Write( REG_LR_IRQFLAGS, RFLR_IRQFLAGS_FHSSCHANGEDCHANNEL );
  1447 +
  1448 + if( ( this->RadioEvents != NULL ) && ( this->RadioEvents->FhssChangeChannel != NULL ) )
  1449 + {
  1450 + this->RadioEvents->FhssChangeChannel( ( Read( REG_LR_HOPCHANNEL ) & RFLR_HOPCHANNEL_CHANNEL_MASK ) );
  1451 + }
  1452 + }
  1453 + break;
  1454 + default:
  1455 + break;
  1456 + }
  1457 + break;
  1458 + case RF_TX_RUNNING:
  1459 + switch( this->settings.Modem )
  1460 + {
  1461 + case MODEM_FSK:
  1462 + break;
  1463 + case MODEM_LORA:
  1464 + if( this->settings.LoRa.FreqHopOn == true )
  1465 + {
  1466 + // Clear Irq
  1467 + Write( REG_LR_IRQFLAGS, RFLR_IRQFLAGS_FHSSCHANGEDCHANNEL );
  1468 +
  1469 + if( ( this->RadioEvents != NULL ) && ( this->RadioEvents->FhssChangeChannel != NULL ) )
  1470 + {
  1471 + this->RadioEvents->FhssChangeChannel( ( Read( REG_LR_HOPCHANNEL ) & RFLR_HOPCHANNEL_CHANNEL_MASK ) );
  1472 + }
  1473 + }
  1474 + break;
  1475 + default:
  1476 + break;
  1477 + }
  1478 + break;
  1479 + default:
  1480 + break;
  1481 + }
  1482 +}
  1483 +
  1484 +void SX1276::OnDio3Irq( void )
  1485 +{
  1486 + switch( this->settings.Modem )
  1487 + {
  1488 + case MODEM_FSK:
  1489 + break;
  1490 + case MODEM_LORA:
  1491 + if( ( Read( REG_LR_IRQFLAGS ) & RFLR_IRQFLAGS_CADDETECTED ) == RFLR_IRQFLAGS_CADDETECTED )
  1492 + {
  1493 + // Clear Irq
  1494 + Write( REG_LR_IRQFLAGS, RFLR_IRQFLAGS_CADDETECTED | RFLR_IRQFLAGS_CADDONE );
  1495 + if( ( this->RadioEvents != NULL ) && ( this->RadioEvents->CadDone != NULL ) )
  1496 + {
  1497 + this->RadioEvents->CadDone( true );
  1498 + }
  1499 + }
  1500 + else
  1501 + {
  1502 + // Clear Irq
  1503 + Write( REG_LR_IRQFLAGS, RFLR_IRQFLAGS_CADDONE );
  1504 + if( ( this->RadioEvents != NULL ) && ( this->RadioEvents->CadDone != NULL ) )
  1505 + {
  1506 + this->RadioEvents->CadDone( false );
  1507 + }
  1508 + }
  1509 + break;
  1510 + default:
  1511 + break;
  1512 + }
  1513 +}
  1514 +
  1515 +void SX1276::OnDio4Irq( void )
  1516 +{
  1517 + switch( this->settings.Modem )
  1518 + {
  1519 + case MODEM_FSK:
  1520 + {
  1521 + if( this->settings.FskPacketHandler.PreambleDetected == false )
  1522 + {
  1523 + this->settings.FskPacketHandler.PreambleDetected = true;
  1524 + }
  1525 + }
  1526 + break;
  1527 + case MODEM_LORA:
  1528 + break;
  1529 + default:
  1530 + break;
  1531 + }
  1532 +}
  1533 +
  1534 +void SX1276::OnDio5Irq( void )
  1535 +{
  1536 + switch( this->settings.Modem )
  1537 + {
  1538 + case MODEM_FSK:
  1539 + break;
  1540 + case MODEM_LORA:
  1541 + break;
  1542 + default:
  1543 + break;
  1544 + }
  1545 +}
... ...
SX1276Lib/sx1276/sx1276.h 0 → 100644
... ... @@ -0,0 +1,499 @@
  1 +/*
  2 + / _____) _ | |
  3 +( (____ _____ ____ _| |_ _____ ____| |__
  4 + \____ \| ___ | (_ _) ___ |/ ___) _ \
  5 + _____) ) ____| | | || |_| ____( (___| | | |
  6 +(______/|_____)_|_|_| \__)_____)\____)_| |_|
  7 + (C) 2014 Semtech
  8 +
  9 +Description: Actual implementation of a SX1276 radio, inherits Radio
  10 +
  11 +License: Revised BSD License, see LICENSE.TXT file include in the project
  12 +
  13 +Maintainers: Miguel Luis, Gregory Cristian and Nicolas Huguenin
  14 +*/
  15 +#ifndef __SX1276_H__
  16 +#define __SX1276_H__
  17 +
  18 +#include "radio.h"
  19 +#include "./registers/sx1276Regs-Fsk.h"
  20 +#include "./registers/sx1276Regs-LoRa.h"
  21 +#include "./typedefs/typedefs.h"
  22 +
  23 +/*!
  24 + * Radio wakeup time from SLEEP mode
  25 + */
  26 +#define RADIO_WAKEUP_TIME 1000 // [us]
  27 +
  28 +/*!
  29 + * SX1276 definitions
  30 + */
  31 +#define XTAL_FREQ 32000000
  32 +#define FREQ_STEP 61.03515625
  33 +
  34 +#define RX_BUFFER_SIZE 256
  35 +
  36 +/*!
  37 + * Constant values need to compute the RSSI value
  38 + */
  39 +#define RSSI_OFFSET_LF -164.0
  40 +#define RSSI_OFFSET_HF -157.0
  41 +
  42 +#define RF_MID_BAND_THRESH 525000000
  43 +
  44 +/*!
  45 + * Actual implementation of a SX1276 radio, inherits Radio
  46 + */
  47 +class SX1276 : public Radio
  48 +{
  49 +protected:
  50 + /*!
  51 + * SPI Interface
  52 + */
  53 + SPI spi; // mosi, miso, sclk
  54 + DigitalOut nss;
  55 +
  56 + /*!
  57 + * SX1276 Reset pin
  58 + */
  59 + DigitalInOut reset;
  60 +
  61 + /*!
  62 + * SX1276 DIO pins
  63 + */
  64 + InterruptIn dio0;
  65 + InterruptIn dio1;
  66 + InterruptIn dio2;
  67 + InterruptIn dio3;
  68 + InterruptIn dio4;
  69 + DigitalIn dio5;
  70 +
  71 + bool isRadioActive;
  72 +
  73 + uint8_t boardConnected; //1 = SX1276MB1LAS; 0 = SX1276MB1MAS
  74 +
  75 + uint8_t *rxBuffer;
  76 +
  77 + uint8_t previousOpMode;
  78 +
  79 + /*!
  80 + * Hardware DIO IRQ functions
  81 + */
  82 + DioIrqHandler *dioIrq;
  83 +
  84 + /*!
  85 + * Tx and Rx timers
  86 + */
  87 + Timeout txTimeoutTimer;
  88 + Timeout rxTimeoutTimer;
  89 + Timeout rxTimeoutSyncWord;
  90 +
  91 + /*!
  92 + * rxTx: [1: Tx, 0: Rx]
  93 + */
  94 + uint8_t rxTx;
  95 +
  96 + RadioSettings_t settings;
  97 +
  98 + static const FskBandwidth_t FskBandwidths[] ;
  99 +protected:
  100 +
  101 + /*!
  102 + * Performs the Rx chain calibration for LF and HF bands
  103 + * \remark Must be called just after the reset so all registers are at their
  104 + * default values
  105 + */
  106 + void RxChainCalibration( void );
  107 +
  108 +public:
  109 + SX1276( RadioEvents_t *events,
  110 + PinName mosi, PinName miso, PinName sclk, PinName nss, PinName reset,
  111 + PinName dio0, PinName dio1, PinName dio2, PinName dio3, PinName dio4, PinName dio5 );
  112 + SX1276( RadioEvents_t *events );
  113 + virtual ~SX1276( );
  114 +
  115 + //-------------------------------------------------------------------------
  116 + // Redefined Radio functions
  117 + //-------------------------------------------------------------------------
  118 + /*!
  119 + * @brief Initializes the radio
  120 + *
  121 + * @param [IN] events Structure containing the driver callback functions
  122 + */
  123 + virtual void Init( RadioEvents_t *events );
  124 + /*!
  125 + * Return current radio status
  126 + *
  127 + * @param status Radio status. [RF_IDLE, RX_RUNNING, TX_RUNNING]
  128 + */
  129 + virtual RadioState GetStatus( void );
  130 +
  131 + /*!
  132 + * @brief Configures the SX1276 with the given modem
  133 + *
  134 + * @param [IN] modem Modem to be used [0: FSK, 1: LoRa]
  135 + */
  136 + virtual void SetModem( RadioModems_t modem );
  137 +
  138 + /*!
  139 + * @brief Sets the channel frequency
  140 + *
  141 + * @param [IN] freq Channel RF frequency
  142 + */
  143 + virtual void SetChannel( uint32_t freq );
  144 +
  145 + /*!
  146 + * @brief Sets the channels configuration
  147 + *
  148 + * @param [IN] modem Radio modem to be used [0: FSK, 1: LoRa]
  149 + * @param [IN] freq Channel RF frequency
  150 + * @param [IN] rssiThresh RSSI threshold
  151 + *
  152 + * @retval isFree [true: Channel is free, false: Channel is not free]
  153 + */
  154 + virtual bool IsChannelFree( RadioModems_t modem, uint32_t freq, int16_t rssiThresh );
  155 +
  156 + /*!
  157 + * @brief Generates a 32 bits random value based on the RSSI readings
  158 + *
  159 + * \remark This function sets the radio in LoRa modem mode and disables
  160 + * all interrupts.
  161 + * After calling this function either Radio.SetRxConfig or
  162 + * Radio.SetTxConfig functions must be called.
  163 + *
  164 + * @retval randomValue 32 bits random value
  165 + */
  166 + virtual uint32_t Random( void );
  167 +
  168 + /*!
  169 + * @brief Sets the reception parameters
  170 + *
  171 + * @param [IN] modem Radio modem to be used [0: FSK, 1: LoRa]
  172 + * @param [IN] bandwidth Sets the bandwidth
  173 + * FSK : >= 2600 and <= 250000 Hz
  174 + * LoRa: [0: 125 kHz, 1: 250 kHz,
  175 + * 2: 500 kHz, 3: Reserved]
  176 + * @param [IN] datarate Sets the Datarate
  177 + * FSK : 600..300000 bits/s
  178 + * LoRa: [6: 64, 7: 128, 8: 256, 9: 512,
  179 + * 10: 1024, 11: 2048, 12: 4096 chips]
  180 + * @param [IN] coderate Sets the coding rate ( LoRa only )
  181 + * FSK : N/A ( set to 0 )
  182 + * LoRa: [1: 4/5, 2: 4/6, 3: 4/7, 4: 4/8]
  183 + * @param [IN] bandwidthAfc Sets the AFC Bandwidth ( FSK only )
  184 + * FSK : >= 2600 and <= 250000 Hz
  185 + * LoRa: N/A ( set to 0 )
  186 + * @param [IN] preambleLen Sets the Preamble length ( LoRa only )
  187 + * FSK : N/A ( set to 0 )
  188 + * LoRa: Length in symbols ( the hardware adds 4 more symbols )
  189 + * @param [IN] symbTimeout Sets the RxSingle timeout value ( LoRa only )
  190 + * FSK : N/A ( set to 0 )
  191 + * LoRa: timeout in symbols
  192 + * @param [IN] fixLen Fixed length packets [0: variable, 1: fixed]
  193 + * @param [IN] payloadLen Sets payload length when fixed lenght is used
  194 + * @param [IN] crcOn Enables/Disables the CRC [0: OFF, 1: ON]
  195 + * @param [IN] freqHopOn Enables disables the intra-packet frequency hopping [0: OFF, 1: ON] (LoRa only)
  196 + * @param [IN] hopPeriod Number of symbols bewteen each hop (LoRa only)
  197 + * @param [IN] iqInverted Inverts IQ signals ( LoRa only )
  198 + * FSK : N/A ( set to 0 )
  199 + * LoRa: [0: not inverted, 1: inverted]
  200 + * @param [IN] rxContinuous Sets the reception in continuous mode
  201 + * [false: single mode, true: continuous mode]
  202 + */
  203 + virtual void SetRxConfig ( RadioModems_t modem, uint32_t bandwidth,
  204 + uint32_t datarate, uint8_t coderate,
  205 + uint32_t bandwidthAfc, uint16_t preambleLen,
  206 + uint16_t symbTimeout, bool fixLen,
  207 + uint8_t payloadLen,
  208 + bool crcOn, bool freqHopOn, uint8_t hopPeriod,
  209 + bool iqInverted, bool rxContinuous );
  210 +
  211 + /*!
  212 + * @brief Sets the transmission parameters
  213 + *
  214 + * @param [IN] modem Radio modem to be used [0: FSK, 1: LoRa]
  215 + * @param [IN] power Sets the output power [dBm]
  216 + * @param [IN] fdev Sets the frequency deviation ( FSK only )
  217 + * FSK : [Hz]
  218 + * LoRa: 0
  219 + * @param [IN] bandwidth Sets the bandwidth ( LoRa only )
  220 + * FSK : 0
  221 + * LoRa: [0: 125 kHz, 1: 250 kHz,
  222 + * 2: 500 kHz, 3: Reserved]
  223 + * @param [IN] datarate Sets the Datarate
  224 + * FSK : 600..300000 bits/s
  225 + * LoRa: [6: 64, 7: 128, 8: 256, 9: 512,
  226 + * 10: 1024, 11: 2048, 12: 4096 chips]
  227 + * @param [IN] coderate Sets the coding rate ( LoRa only )
  228 + * FSK : N/A ( set to 0 )
  229 + * LoRa: [1: 4/5, 2: 4/6, 3: 4/7, 4: 4/8]
  230 + * @param [IN] preambleLen Sets the preamble length
  231 + * @param [IN] fixLen Fixed length packets [0: variable, 1: fixed]
  232 + * @param [IN] crcOn Enables disables the CRC [0: OFF, 1: ON]
  233 + * @param [IN] freqHopOn Enables disables the intra-packet frequency hopping [0: OFF, 1: ON] (LoRa only)
  234 + * @param [IN] hopPeriod Number of symbols bewteen each hop (LoRa only)
  235 + * @param [IN] iqInverted Inverts IQ signals ( LoRa only )
  236 + * FSK : N/A ( set to 0 )
  237 + * LoRa: [0: not inverted, 1: inverted]
  238 + * @param [IN] timeout Transmission timeout [us]
  239 + */
  240 + virtual void SetTxConfig( RadioModems_t modem, int8_t power, uint32_t fdev,
  241 + uint32_t bandwidth, uint32_t datarate,
  242 + uint8_t coderate, uint16_t preambleLen,
  243 + bool fixLen, bool crcOn, bool freqHopOn,
  244 + uint8_t hopPeriod, bool iqInverted, uint32_t timeout );
  245 +
  246 + /*!
  247 + * @brief Computes the packet time on air for the given payload
  248 + *
  249 + * \Remark Can only be called once SetRxConfig or SetTxConfig have been called
  250 + *
  251 + * @param [IN] modem Radio modem to be used [0: FSK, 1: LoRa]
  252 + * @param [IN] pktLen Packet payload length
  253 + *
  254 + * @retval airTime Computed airTime for the given packet payload length
  255 + */
  256 + virtual double TimeOnAir ( RadioModems_t modem, uint8_t pktLen );
  257 +
  258 + /*!
  259 + * @brief Sends the buffer of size. Prepares the packet to be sent and sets
  260 + * the radio in transmission
  261 + *
  262 + * @param [IN]: buffer Buffer pointer
  263 + * @param [IN]: size Buffer size
  264 + */
  265 + virtual void Send( uint8_t *buffer, uint8_t size );
  266 +
  267 + /*!
  268 + * @brief Sets the radio in sleep mode
  269 + */
  270 + virtual void Sleep( void );
  271 +
  272 + /*!
  273 + * @brief Sets the radio in standby mode
  274 + */
  275 + virtual void Standby( void );
  276 +
  277 + /*!
  278 + * @brief Sets the radio in reception mode for the given time
  279 + * @param [IN] timeout Reception timeout [us]
  280 + * [0: continuous, others timeout]
  281 + */
  282 + virtual void Rx( uint32_t timeout );
  283 +
  284 + /*!
  285 + * @brief Sets the radio in transmission mode for the given time
  286 + * @param [IN] timeout Transmission timeout [us]
  287 + * [0: continuous, others timeout]
  288 + */
  289 + virtual void Tx( uint32_t timeout );
  290 +
  291 + /*!
  292 + * @brief Start a Channel Activity Detection
  293 + */
  294 + virtual void StartCad( void );
  295 +
  296 + /*!
  297 + * @brief Reads the current RSSI value
  298 + *
  299 + * @retval rssiValue Current RSSI value in [dBm]
  300 + */
  301 + virtual int16_t GetRssi ( RadioModems_t modem );
  302 +
  303 + /*!
  304 + * @brief Writes the radio register at the specified address
  305 + *
  306 + * @param [IN]: addr Register address
  307 + * @param [IN]: data New register value
  308 + */
  309 + virtual void Write ( uint8_t addr, uint8_t data ) = 0;
  310 +
  311 + /*!
  312 + * @brief Reads the radio register at the specified address
  313 + *
  314 + * @param [IN]: addr Register address
  315 + * @retval data Register value
  316 + */
  317 + virtual uint8_t Read ( uint8_t addr ) = 0;
  318 +
  319 + /*!
  320 + * @brief Writes multiple radio registers starting at address
  321 + *
  322 + * @param [IN] addr First Radio register address
  323 + * @param [IN] buffer Buffer containing the new register's values
  324 + * @param [IN] size Number of registers to be written
  325 + */
  326 + virtual void Write( uint8_t addr, uint8_t *buffer, uint8_t size ) = 0;
  327 +
  328 + /*!
  329 + * @brief Reads multiple radio registers starting at address
  330 + *
  331 + * @param [IN] addr First Radio register address
  332 + * @param [OUT] buffer Buffer where to copy the registers data
  333 + * @param [IN] size Number of registers to be read
  334 + */
  335 + virtual void Read ( uint8_t addr, uint8_t *buffer, uint8_t size ) = 0;
  336 +
  337 + /*!
  338 + * @brief Writes the buffer contents to the SX1276 FIFO
  339 + *
  340 + * @param [IN] buffer Buffer containing data to be put on the FIFO.
  341 + * @param [IN] size Number of bytes to be written to the FIFO
  342 + */
  343 + virtual void WriteFifo( uint8_t *buffer, uint8_t size ) = 0;
  344 +
  345 + /*!
  346 + * @brief Reads the contents of the SX1276 FIFO
  347 + *
  348 + * @param [OUT] buffer Buffer where to copy the FIFO read data.
  349 + * @param [IN] size Number of bytes to be read from the FIFO
  350 + */
  351 + virtual void ReadFifo( uint8_t *buffer, uint8_t size ) = 0;
  352 + /*!
  353 + * @brief Resets the SX1276
  354 + */
  355 + virtual void Reset( void ) = 0;
  356 +
  357 + /*!
  358 + * @brief Sets the maximum payload length.
  359 + *
  360 + * @param [IN] modem Radio modem to be used [0: FSK, 1: LoRa]
  361 + * @param [IN] max Maximum payload length in bytes
  362 + */
  363 + virtual void SetMaxPayloadLength( RadioModems_t modem, uint8_t max );
  364 +
  365 + //-------------------------------------------------------------------------
  366 + // Board relative functions
  367 + //-------------------------------------------------------------------------
  368 +
  369 +protected:
  370 + /*!
  371 + * @brief Initializes the radio I/Os pins interface
  372 + */
  373 + virtual void IoInit( void ) = 0;
  374 +
  375 + /*!
  376 + * @brief Initializes the radio registers
  377 + */
  378 + virtual void RadioRegistersInit( ) = 0;
  379 +
  380 + /*!
  381 + * @brief Initializes the radio SPI
  382 + */
  383 + virtual void SpiInit( void ) = 0;
  384 +
  385 + /*!
  386 + * @brief Initializes DIO IRQ handlers
  387 + *
  388 + * @param [IN] irqHandlers Array containing the IRQ callback functions
  389 + */
  390 + virtual void IoIrqInit( DioIrqHandler *irqHandlers ) = 0;
  391 +
  392 + /*!
  393 + * @brief De-initializes the radio I/Os pins interface.
  394 + *
  395 + * \remark Useful when going in MCU lowpower modes
  396 + */
  397 + virtual void IoDeInit( void ) = 0;
  398 +
  399 + /*!
  400 + * @brief Gets the board PA selection configuration
  401 + *
  402 + * @param [IN] channel Channel frequency in Hz
  403 + * @retval PaSelect RegPaConfig PaSelect value
  404 + */
  405 + virtual uint8_t GetPaSelect( uint32_t channel ) = 0;
  406 +
  407 + /*!
  408 + * @brief Set the RF Switch I/Os pins in Low Power mode
  409 + *
  410 + * @param [IN] status enable or disable
  411 + */
  412 + virtual void SetAntSwLowPower( bool status ) = 0;
  413 +
  414 + /*!
  415 + * @brief Initializes the RF Switch I/Os pins interface
  416 + */
  417 + virtual void AntSwInit( void ) = 0;
  418 +
  419 + /*!
  420 + * @brief De-initializes the RF Switch I/Os pins interface
  421 + *
  422 + * \remark Needed to decrease the power consumption in MCU lowpower modes
  423 + */
  424 + virtual void AntSwDeInit( void ) = 0;
  425 +
  426 + /*!
  427 + * @brief Controls the antena switch if necessary.
  428 + *
  429 + * \remark see errata note
  430 + *
  431 + * @param [IN] rxTx [1: Tx, 0: Rx]
  432 + */
  433 + virtual void SetAntSw( uint8_t rxTx ) = 0;
  434 +
  435 + /*!
  436 + * @brief Checks if the given RF frequency is supported by the hardware
  437 + *
  438 + * @param [IN] frequency RF frequency to be checked
  439 + * @retval isSupported [true: supported, false: unsupported]
  440 + */
  441 + virtual bool CheckRfFrequency( uint32_t frequency ) = 0;
  442 +protected:
  443 +
  444 + /*!
  445 + * @brief Sets the SX1276 operating mode
  446 + *
  447 + * @param [IN] opMode New operating mode
  448 + */
  449 + virtual void SetOpMode( uint8_t opMode );
  450 +
  451 + /*
  452 + * SX1276 DIO IRQ callback functions prototype
  453 + */
  454 +
  455 + /*!
  456 + * @brief DIO 0 IRQ callback
  457 + */
  458 + virtual void OnDio0Irq( void );
  459 +
  460 + /*!
  461 + * @brief DIO 1 IRQ callback
  462 + */
  463 + virtual void OnDio1Irq( void );
  464 +
  465 + /*!
  466 + * @brief DIO 2 IRQ callback
  467 + */
  468 + virtual void OnDio2Irq( void );
  469 +
  470 + /*!
  471 + * @brief DIO 3 IRQ callback
  472 + */
  473 + virtual void OnDio3Irq( void );
  474 +
  475 + /*!
  476 + * @brief DIO 4 IRQ callback
  477 + */
  478 + virtual void OnDio4Irq( void );
  479 +
  480 + /*!
  481 + * @brief DIO 5 IRQ callback
  482 + */
  483 + virtual void OnDio5Irq( void );
  484 +
  485 + /*!
  486 + * @brief Tx & Rx timeout timer callback
  487 + */
  488 + virtual void OnTimeoutIrq( void );
  489 +
  490 + /*!
  491 + * Returns the known FSK bandwidth registers value
  492 + *
  493 + * \param [IN] bandwidth Bandwidth value in Hz
  494 + * \retval regValue Bandwidth register value.
  495 + */
  496 + static uint8_t GetFskBandwidthRegValue( uint32_t bandwidth );
  497 +};
  498 +
  499 +#endif // __SX1276_H__
... ...
SX1276Lib/typedefs/typedefs.h 0 → 100644
... ... @@ -0,0 +1,53 @@
  1 +/*
  2 + / _____) _ | |
  3 +( (____ _____ ____ _| |_ _____ ____| |__
  4 + \____ \| ___ | (_ _) ___ |/ ___) _ \
  5 + _____) ) ____| | | || |_| ____( (___| | | |
  6 +(______/|_____)_|_|_| \__)_____)\____)_| |_|
  7 + (C) 2014 Semtech
  8 +
  9 +Description: -
  10 +
  11 +License: Revised BSD License, see LICENSE.TXT file include in the project
  12 +
  13 +Maintainers: Miguel Luis, Gregory Cristian and Nicolas Huguenin
  14 +*/
  15 +#ifndef __TYPEDEFS_H__
  16 +#define __TYPEDEFS_H__
  17 +
  18 +#include "mbed.h"
  19 +#include "./enums/enums.h"
  20 +
  21 +class SX1276;
  22 +class SX1276MB1xAS;
  23 +/*!
  24 + * Hardware IO IRQ callback function definition
  25 + */
  26 +typedef void ( SX1276::*DioIrqHandler )( void );
  27 +
  28 +/*!
  29 + * triggers definition
  30 + */
  31 +typedef void ( SX1276::*Trigger )( void );
  32 +typedef void ( SX1276MB1xAS::*TriggerMB1xAS )( void );
  33 +
  34 +/*!
  35 + * FSK bandwidth definition
  36 + */
  37 +typedef struct
  38 +{
  39 + uint32_t bandwidth;
  40 + uint8_t RegValue;
  41 +}FskBandwidth_t;
  42 +
  43 +/*!
  44 + * Radio registers definition
  45 + */
  46 +typedef struct
  47 +{
  48 + ModemType Modem;
  49 + uint8_t Addr;
  50 + uint8_t Value;
  51 +}RadioRegisters_t;
  52 +
  53 +#endif //__TYPEDEFS_H__
... ...
main.cpp 0 → 100644
... ... @@ -0,0 +1,370 @@
  1 +#include "mbed.h"
  2 +#include "main.h"
  3 +#include "sx1276-hal.h"
  4 +#include "debug.h"
  5 +
  6 +#include "vt100.h"
  7 +VT100 pc(USBTX,USBRX);
  8 +
  9 +/* Set this flag to '1' to display debug messages on the console */
  10 +#define DEBUG_MESSAGE 1
  11 +
  12 +/* Set this flag to '1' to use the LoRa modulation or to '0' to use FSK modulation */
  13 +#define USE_MODEM_LORA 1
  14 +#define USE_MODEM_FSK !USE_MODEM_LORA
  15 +
  16 +#define RF_FREQUENCY 868100000 // Hz
  17 +#define TX_OUTPUT_POWER 14 // 14 dBm
  18 +
  19 +#if USE_MODEM_LORA == 1
  20 +
  21 + #define LORA_BANDWIDTH 2 // [0: 125 kHz,
  22 + // 1: 250 kHz,
  23 + // 2: 500 kHz,
  24 + // 3: Reserved]
  25 + #define LORA_SPREADING_FACTOR 12 // [SF7..SF12]
  26 + #define LORA_CODINGRATE 1 // [1: 4/5,
  27 + // 2: 4/6,
  28 + // 3: 4/7,
  29 + // 4: 4/8]
  30 + #define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx
  31 + #define LORA_SYMBOL_TIMEOUT 5 // Symbols
  32 + #define LORA_FIX_LENGTH_PAYLOAD_ON false
  33 + #define LORA_FHSS_ENABLED false
  34 + #define LORA_NB_SYMB_HOP 4
  35 + #define LORA_IQ_INVERSION_ON false
  36 + #define LORA_CRC_ENABLED true
  37 +
  38 +#elif USE_MODEM_FSK == 1
  39 +
  40 + #define FSK_FDEV 25000 // Hz
  41 + #define FSK_DATARATE 19200 // bps
  42 + #define FSK_BANDWIDTH 50000 // Hz
  43 + #define FSK_AFC_BANDWIDTH 83333 // Hz
  44 + #define FSK_PREAMBLE_LENGTH 5 // Same for Tx and Rx
  45 + #define FSK_FIX_LENGTH_PAYLOAD_ON false
  46 + #define FSK_CRC_ENABLED true
  47 +
  48 +#else
  49 + #error "Please define a modem in the compiler options."
  50 +#endif
  51 +
  52 +#define RX_TIMEOUT_VALUE 3500000 // in us
  53 +#define BUFFER_SIZE 32 // Define the payload size here
  54 +
  55 +#if( defined ( TARGET_KL25Z ) || defined ( TARGET_LPC11U6X ) )
  56 +DigitalOut led(LED2);
  57 +#else
  58 +DigitalOut led(LED1);
  59 +#endif
  60 +
  61 +/*
  62 + * Global variables declarations
  63 + */
  64 +typedef enum
  65 +{
  66 + LOWPOWER = 0,
  67 + IDLE,
  68 +
  69 + RX,
  70 + RX_TIMEOUT,
  71 + RX_ERROR,
  72 +
  73 + TX,
  74 + TX_TIMEOUT,
  75 +
  76 + CAD,
  77 + CAD_DONE
  78 +}AppStates_t;
  79 +
  80 +volatile AppStates_t State = LOWPOWER;
  81 +
  82 +/*!
  83 + * Radio events function pointer
  84 + */
  85 +static RadioEvents_t RadioEvents;
  86 +
  87 +/*
  88 + * Global variables declarations
  89 + */
  90 +SX1276MB1xAS Radio( NULL );
  91 +
  92 +const uint8_t PingMsg[] = "PING";
  93 +const uint8_t PongMsg[] = "PONG";
  94 +
  95 +uint16_t BufferSize = BUFFER_SIZE;
  96 +uint8_t Buffer[BUFFER_SIZE];
  97 +
  98 +int16_t RssiValue = 0.0;
  99 +int8_t SnrValue = 0.0;
  100 +
  101 +int main()
  102 +{
  103 + uint8_t i;
  104 + bool isMaster = true;
  105 +
  106 + pc.printf( "\n\n\r SX1276 Ping Pong Demo Application \n\n\r" );
  107 +
  108 + // Initialize Radio driver
  109 + RadioEvents.TxDone = OnTxDone;
  110 + RadioEvents.RxDone = OnRxDone;
  111 + RadioEvents.RxError = OnRxError;
  112 + RadioEvents.TxTimeout = OnTxTimeout;
  113 + RadioEvents.RxTimeout = OnRxTimeout;
  114 + Radio.Init( &RadioEvents );
  115 +
  116 + // verify the connection with the board
  117 + while( Radio.Read( REG_VERSION ) == 0x00 )
  118 + {
  119 + pc.printf( "Radio could not be detected!\n\r", NULL );
  120 + wait( 1 );
  121 + }
  122 +
  123 + if( ( DEBUG_MESSAGE & ( Radio.DetectBoardType( ) == SX1276MB1LAS ) ))
  124 + {
  125 + pc.printf( "\n\r > Board Type: SX1276MB1LAS < \n\r" );
  126 + }
  127 + else
  128 + {
  129 + pc.printf( "\n\r > Board Type: SX1276MB1MAS < \n\r" );
  130 + }
  131 +
  132 + Radio.SetChannel( RF_FREQUENCY );
  133 +
  134 +#if USE_MODEM_LORA == 1
  135 +
  136 + pc.printf( "\n\n\r > LORA FHSS Mode < \n\n\r");
  137 + pc.printf( "\n\n\r > LORA Mode < \n\n\r");
  138 +
  139 + Radio.SetTxConfig( MODEM_LORA, TX_OUTPUT_POWER, 0, LORA_BANDWIDTH,
  140 + LORA_SPREADING_FACTOR, LORA_CODINGRATE,
  141 + LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON,
  142 + LORA_CRC_ENABLED, LORA_FHSS_ENABLED, LORA_NB_SYMB_HOP,
  143 + LORA_IQ_INVERSION_ON, 2000000 );
  144 +
  145 + Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR,
  146 + LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH,
  147 + LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON, 0,
  148 + LORA_CRC_ENABLED, LORA_FHSS_ENABLED, LORA_NB_SYMB_HOP,
  149 + LORA_IQ_INVERSION_ON, true );
  150 +
  151 +#elif USE_MODEM_FSK == 1
  152 +
  153 + pc.printf("\n\n\r > FSK Mode < \n\n\r");
  154 + Radio.SetTxConfig( MODEM_FSK, TX_OUTPUT_POWER, FSK_FDEV, 0,
  155 + FSK_DATARATE, 0,
  156 + FSK_PREAMBLE_LENGTH, FSK_FIX_LENGTH_PAYLOAD_ON,
  157 + FSK_CRC_ENABLED, 0, 0, 0, 2000000 );
  158 +
  159 + Radio.SetRxConfig( MODEM_FSK, FSK_BANDWIDTH, FSK_DATARATE,
  160 + 0, FSK_AFC_BANDWIDTH, FSK_PREAMBLE_LENGTH,
  161 + 0, FSK_FIX_LENGTH_PAYLOAD_ON, 0, FSK_CRC_ENABLED,
  162 + 0, 0, false, true );
  163 +
  164 +#else
  165 +
  166 +#error "Please define a modem in the compiler options."
  167 +
  168 +#endif
  169 +
  170 + pc.printf( "Starting Ping-Pong loop\r\n" );
  171 +
  172 + led = 0;
  173 +
  174 + Radio.Rx( RX_TIMEOUT_VALUE );
  175 +
  176 + while( 1 )
  177 + {
  178 + switch( State )
  179 + {
  180 + case RX:
  181 + if( isMaster == true )
  182 + {
  183 + if( BufferSize > 0 )
  184 + {
  185 + if( strncmp( ( const char* )Buffer, ( const char* )PongMsg, 4 ) == 0 )
  186 + {
  187 + led = !led;
  188 + pc.printf( "...Pong\r\n" );
  189 + // Send the next PING frame
  190 + strcpy( ( char* )Buffer, ( char* )PingMsg );
  191 + // We fill the buffer with numbers for the payload
  192 + for( i = 4; i < BufferSize; i++ )
  193 + {
  194 + Buffer[i] = i - 4;
  195 + }
  196 + wait_ms( 100 );
  197 + Radio.Send( Buffer, BufferSize );
  198 + }
  199 + else if( strncmp( ( const char* )Buffer, ( const char* )PingMsg, 4 ) == 0 )
  200 + { // A master already exists then become a slave
  201 + pc.printf( "...Ping\r\n" );
  202 + led = !led;
  203 + isMaster = false;
  204 + // Send the next PONG frame
  205 + strcpy( ( char* )Buffer, ( char* )PongMsg );
  206 + // We fill the buffer with numbers for the payload
  207 + for( i = 4; i < BufferSize; i++ )
  208 + {
  209 + Buffer[i] = i - 4;
  210 + }
  211 + wait_ms( 100 );
  212 + Radio.Send( Buffer, BufferSize );
  213 + }
  214 + else // valid reception but neither a PING or a PONG message
  215 + { // Set device as master ans start again
  216 + isMaster = true;
  217 + pc.printf( "RSSI : %d -- SNR : %d)\r\n", RssiValue,SnrValue );
  218 + pc.printf( ">>>>>\r\n" );
  219 + pc.printf( "%s\r\n", Buffer );
  220 + //serialDisplayHex( Buffer, BufferSize ); //hexa
  221 + pc.printf( "<<<<<\r\n");
  222 +
  223 + Radio.Rx( RX_TIMEOUT_VALUE );
  224 + }
  225 + }
  226 + }
  227 + else
  228 + {
  229 + if( BufferSize > 0 )
  230 + {
  231 + if( strncmp( ( const char* )Buffer, ( const char* )PingMsg, 4 ) == 0 )
  232 + {
  233 + led = !led;
  234 + pc.printf( "...Ping\r\n" );
  235 + // Send the reply to the PING string
  236 + strcpy( ( char* )Buffer, ( char* )PongMsg );
  237 + // We fill the buffer with numbers for the payload
  238 + for( i = 4; i < BufferSize; i++ )
  239 + {
  240 + Buffer[i] = i - 4;
  241 + }
  242 + wait_ms( 100 );
  243 + Radio.Send( Buffer, BufferSize );
  244 + }
  245 + else // valid reception but not a PING as expected
  246 + { // Set device as master and start again
  247 + isMaster = true;
  248 +
  249 + pc.printf( "RSSI : %d -- SNR : %d)\r\n", RssiValue,SnrValue );
  250 + pc.printf( ">>>>>\r\n" );
  251 + pc.printf( "%s\r\n", Buffer );
  252 + //serialDisplayHex( Buffer, BufferSize ); //hexa
  253 + pc.printf( "<<<<<\r\n");
  254 +
  255 + Radio.Rx( RX_TIMEOUT_VALUE );
  256 + }
  257 + }
  258 + }
  259 + State = LOWPOWER;
  260 + break;
  261 + case TX:
  262 + led = !led;
  263 + if( isMaster == true )
  264 + {
  265 + pc.printf( "Ping...\r\n" );
  266 + }
  267 + else
  268 + {
  269 + pc.printf( "Pong...\r\n" );
  270 + }
  271 + Radio.Rx( RX_TIMEOUT_VALUE );
  272 + State = LOWPOWER;
  273 + break;
  274 + case RX_TIMEOUT:
  275 + if( isMaster == true )
  276 + {
  277 + // Send the next PING frame
  278 + strcpy( ( char* )Buffer, ( char* )PingMsg );
  279 + for( i = 4; i < BufferSize; i++ )
  280 + {
  281 + Buffer[i] = i - 4;
  282 + }
  283 + wait_ms( 100 );
  284 + Radio.Send( Buffer, BufferSize );
  285 + }
  286 + else
  287 + {
  288 + Radio.Rx( RX_TIMEOUT_VALUE );
  289 + }
  290 + State = LOWPOWER;
  291 + break;
  292 + case RX_ERROR:
  293 + // We have received a Packet with a CRC error, send reply as if packet was correct
  294 + if( isMaster == true )
  295 + {
  296 + // Send the next PING frame
  297 + strcpy( ( char* )Buffer, ( char* )PingMsg );
  298 + for( i = 4; i < BufferSize; i++ )
  299 + {
  300 + Buffer[i] = i - 4;
  301 + }
  302 + wait_ms( 100 );
  303 + Radio.Send( Buffer, BufferSize );
  304 + }
  305 + else
  306 + {
  307 + // Send the next PONG frame
  308 + strcpy( ( char* )Buffer, ( char* )PongMsg );
  309 + for( i = 4; i < BufferSize; i++ )
  310 + {
  311 + Buffer[i] = i - 4;
  312 + }
  313 + wait_ms( 100 );
  314 + Radio.Send( Buffer, BufferSize );
  315 + }
  316 + State = LOWPOWER;
  317 + break;
  318 + case TX_TIMEOUT:
  319 + Radio.Rx( RX_TIMEOUT_VALUE );
  320 + State = LOWPOWER;
  321 + break;
  322 + case LOWPOWER:
  323 + break;
  324 + default:
  325 + State = LOWPOWER;
  326 + break;
  327 + }
  328 + }
  329 +}
  330 +
  331 +void OnTxDone( void )
  332 +{
  333 + Radio.Sleep( );
  334 + State = TX;
  335 + pc.printf( "> OnTxDone\n\r" );
  336 +}
  337 +
  338 +void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr)
  339 +{
  340 + Radio.Sleep( );
  341 + BufferSize = size;
  342 + memcpy( Buffer, payload, BufferSize );
  343 + RssiValue = rssi;
  344 + SnrValue = snr;
  345 + State = RX;
  346 + pc.printf( "> OnRxDone\n\r" );
  347 +}
  348 +
  349 +void OnTxTimeout( void )
  350 +{
  351 + Radio.Sleep( );
  352 + State = TX_TIMEOUT;
  353 + pc.printf( "> OnTxTimeout\n\r" );
  354 +}
  355 +
  356 +void OnRxTimeout( void )
  357 +{
  358 + Radio.Sleep( );
  359 + Buffer[ BufferSize ] = 0;
  360 + State = RX_TIMEOUT;
  361 + pc.printf( "> OnRxTimeout\n\r" );
  362 +}
  363 +
  364 +void OnRxError( void )
  365 +{
  366 + Radio.Sleep( );
  367 + State = RX_ERROR;
  368 + pc.printf( "> OnRxError\n\r" );
  369 +}
  370 +
... ...
main.h 0 → 100644
... ... @@ -0,0 +1,56 @@
  1 +/*
  2 + / _____) _ | |
  3 +( (____ _____ ____ _| |_ _____ ____| |__
  4 + \____ \| ___ | (_ _) ___ |/ ___) _ \
  5 + _____) ) ____| | | || |_| ____( (___| | | |
  6 +(______/|_____)_|_|_| \__)_____)\____)_| |_|
  7 + ( C )2014 Semtech
  8 +
  9 +Description: Contains the callbacks for the IRQs and any application related details
  10 +
  11 +License: Revised BSD License, see LICENSE.TXT file include in the project
  12 +
  13 +Maintainer: Miguel Luis and Gregory Cristian
  14 +*/
  15 +#ifndef __MAIN_H__
  16 +#define __MAIN_H__
  17 +
  18 +/*
  19 + * Callback functions prototypes
  20 + */
  21 +/*!
  22 + * @brief Function to be executed on Radio Tx Done event
  23 + */
  24 +void OnTxDone( void );
  25 +
  26 +/*!
  27 + * @brief Function to be executed on Radio Rx Done event
  28 + */
  29 +void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr );
  30 +
  31 +/*!
  32 + * @brief Function executed on Radio Tx Timeout event
  33 + */
  34 +void OnTxTimeout( void );
  35 +
  36 +/*!
  37 + * @brief Function executed on Radio Rx Timeout event
  38 + */
  39 +void OnRxTimeout( void );
  40 +
  41 +/*!
  42 + * @brief Function executed on Radio Rx Error event
  43 + */
  44 +void OnRxError( void );
  45 +
  46 +/*!
  47 + * @brief Function executed on Radio Fhss Change Channel event
  48 + */
  49 +void OnFhssChangeChannel( uint8_t channelIndex );
  50 +
  51 +/*!
  52 + * @brief Function executed on CAD Done event
  53 + */
  54 +void OnCadDone( void );
  55 +
  56 +#endif // __MAIN_H__
0 57 \ No newline at end of file
... ...
mbed.bld 0 → 100644
... ... @@ -0,0 +1 @@
  1 +http://mbed.org/users/mbed_official/code/mbed/builds/165afa46840b
0 2 \ No newline at end of file
... ...
mbed/.bld/bldrc 0 → 100644
... ... @@ -0,0 +1 @@
  1 +http://mbed.org/users/mbed_official/code/mbed/builds/165afa46840b
0 2 \ No newline at end of file
... ...
mbed/AnalogIn.h 0 → 100644
... ... @@ -0,0 +1,103 @@
  1 +/* mbed Microcontroller Library
  2 + * Copyright (c) 2006-2013 ARM Limited
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +#ifndef MBED_ANALOGIN_H
  17 +#define MBED_ANALOGIN_H
  18 +
  19 +#include "platform.h"
  20 +
  21 +#if DEVICE_ANALOGIN
  22 +
  23 +#include "analogin_api.h"
  24 +
  25 +namespace mbed {
  26 +
  27 +/** An analog input, used for reading the voltage on a pin
  28 + *
  29 + * Example:
  30 + * @code
  31 + * // Print messages when the AnalogIn is greater than 50%
  32 + *
  33 + * #include "mbed.h"
  34 + *
  35 + * AnalogIn temperature(p20);
  36 + *
  37 + * int main() {
  38 + * while(1) {
  39 + * if(temperature > 0.5) {
  40 + * printf("Too hot! (%f)", temperature.read());
  41 + * }
  42 + * }
  43 + * }
  44 + * @endcode
  45 + */
  46 +class AnalogIn {
  47 +
  48 +public:
  49 +
  50 + /** Create an AnalogIn, connected to the specified pin
  51 + *
  52 + * @param pin AnalogIn pin to connect to
  53 + * @param name (optional) A string to identify the object
  54 + */
  55 + AnalogIn(PinName pin) {
  56 + analogin_init(&_adc, pin);
  57 + }
  58 +
  59 + /** Read the input voltage, represented as a float in the range [0.0, 1.0]
  60 + *
  61 + * @returns A floating-point value representing the current input voltage, measured as a percentage
  62 + */
  63 + float read() {
  64 + return analogin_read(&_adc);
  65 + }
  66 +
  67 + /** Read the input voltage, represented as an unsigned short in the range [0x0, 0xFFFF]
  68 + *
  69 + * @returns
  70 + * 16-bit unsigned short representing the current input voltage, normalised to a 16-bit value
  71 + */
  72 + unsigned short read_u16() {
  73 + return analogin_read_u16(&_adc);
  74 + }
  75 +
  76 +#ifdef MBED_OPERATORS
  77 + /** An operator shorthand for read()
  78 + *
  79 + * The float() operator can be used as a shorthand for read() to simplify common code sequences
  80 + *
  81 + * Example:
  82 + * @code
  83 + * float x = volume.read();
  84 + * float x = volume;
  85 + *
  86 + * if(volume.read() > 0.25) { ... }
  87 + * if(volume > 0.25) { ... }
  88 + * @endcode
  89 + */
  90 + operator float() {
  91 + return read();
  92 + }
  93 +#endif
  94 +
  95 +protected:
  96 + analogin_t _adc;
  97 +};
  98 +
  99 +} // namespace mbed
  100 +
  101 +#endif
  102 +
  103 +#endif
... ...
mbed/AnalogOut.h 0 → 100644
... ... @@ -0,0 +1,121 @@
  1 +/* mbed Microcontroller Library
  2 + * Copyright (c) 2006-2013 ARM Limited
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +#ifndef MBED_ANALOGOUT_H
  17 +#define MBED_ANALOGOUT_H
  18 +
  19 +#include "platform.h"
  20 +
  21 +#if DEVICE_ANALOGOUT
  22 +
  23 +#include "analogout_api.h"
  24 +
  25 +namespace mbed {
  26 +
  27 +/** An analog output, used for setting the voltage on a pin
  28 + *
  29 + * Example:
  30 + * @code
  31 + * // Make a sawtooth output
  32 + *
  33 + * #include "mbed.h"
  34 + *
  35 + * AnalogOut tri(p18);
  36 + * int main() {
  37 + * while(1) {
  38 + * tri = tri + 0.01;
  39 + * wait_us(1);
  40 + * if(tri == 1) {
  41 + * tri = 0;
  42 + * }
  43 + * }
  44 + * }
  45 + * @endcode
  46 + */
  47 +class AnalogOut {
  48 +
  49 +public:
  50 +
  51 + /** Create an AnalogOut connected to the specified pin
  52 + *
  53 + * @param AnalogOut pin to connect to (18)
  54 + */
  55 + AnalogOut(PinName pin) {
  56 + analogout_init(&_dac, pin);
  57 + }
  58 +
  59 + /** Set the output voltage, specified as a percentage (float)
  60 + *
  61 + * @param value A floating-point value representing the output voltage,
  62 + * specified as a percentage. The value should lie between
  63 + * 0.0f (representing 0v / 0%) and 1.0f (representing 3.3v / 100%).
  64 + * Values outside this range will be saturated to 0.0f or 1.0f.
  65 + */
  66 + void write(float value) {
  67 + analogout_write(&_dac, value);
  68 + }
  69 +
  70 + /** Set the output voltage, represented as an unsigned short in the range [0x0, 0xFFFF]
  71 + *
  72 + * @param value 16-bit unsigned short representing the output voltage,
  73 + * normalised to a 16-bit value (0x0000 = 0v, 0xFFFF = 3.3v)
  74 + */
  75 + void write_u16(unsigned short value) {
  76 + analogout_write_u16(&_dac, value);
  77 + }
  78 +
  79 + /** Return the current output voltage setting, measured as a percentage (float)
  80 + *
  81 + * @returns
  82 + * A floating-point value representing the current voltage being output on the pin,
  83 + * measured as a percentage. The returned value will lie between
  84 + * 0.0f (representing 0v / 0%) and 1.0f (representing 3.3v / 100%).
  85 + *
  86 + * @note
  87 + * This value may not match exactly the value set by a previous write().
  88 + */
  89 + float read() {
  90 + return analogout_read(&_dac);
  91 + }
  92 +
  93 +#ifdef MBED_OPERATORS
  94 + /** An operator shorthand for write()
  95 + */
  96 + AnalogOut& operator= (float percent) {
  97 + write(percent);
  98 + return *this;
  99 + }
  100 +
  101 + AnalogOut& operator= (AnalogOut& rhs) {
  102 + write(rhs.read());
  103 + return *this;
  104 + }
  105 +
  106 + /** An operator shorthand for read()
  107 + */
  108 + operator float() {
  109 + return read();
  110 + }
  111 +#endif
  112 +
  113 +protected:
  114 + dac_t _dac;
  115 +};
  116 +
  117 +} // namespace mbed
  118 +
  119 +#endif
  120 +
  121 +#endif
... ...
mbed/BusIn.h 0 → 100644
... ... @@ -0,0 +1,98 @@
  1 +/* mbed Microcontroller Library
  2 + * Copyright (c) 2006-2013 ARM Limited
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +#ifndef MBED_BUSIN_H
  17 +#define MBED_BUSIN_H
  18 +
  19 +#include "platform.h"
  20 +#include "DigitalIn.h"
  21 +
  22 +namespace mbed {
  23 +
  24 +/** A digital input bus, used for reading the state of a collection of pins
  25 + */
  26 +class BusIn {
  27 +
  28 +public:
  29 + /* Group: Configuration Methods */
  30 +
  31 + /** Create an BusIn, connected to the specified pins
  32 + *
  33 + * @param <n> DigitalIn pin to connect to bus bit <n> (p5-p30, NC)
  34 + *
  35 + * @note
  36 + * It is only required to specify as many pin variables as is required
  37 + * for the bus; the rest will default to NC (not connected)
  38 + */
  39 + BusIn(PinName p0, PinName p1 = NC, PinName p2 = NC, PinName p3 = NC,
  40 + PinName p4 = NC, PinName p5 = NC, PinName p6 = NC, PinName p7 = NC,
  41 + PinName p8 = NC, PinName p9 = NC, PinName p10 = NC, PinName p11 = NC,
  42 + PinName p12 = NC, PinName p13 = NC, PinName p14 = NC, PinName p15 = NC);
  43 +
  44 + BusIn(PinName pins[16]);
  45 +
  46 + virtual ~BusIn();
  47 +
  48 + /** Read the value of the input bus
  49 + *
  50 + * @returns
  51 + * An integer with each bit corresponding to the value read from the associated DigitalIn pin
  52 + */
  53 + int read();
  54 +
  55 + /** Set the input pin mode
  56 + *
  57 + * @param mode PullUp, PullDown, PullNone
  58 + */
  59 + void mode(PinMode pull);
  60 +
  61 + /** Binary mask of bus pins connected to actual pins (not NC pins)
  62 + * If bus pin is in NC state make corresponding bit will be cleared (set to 0), else bit will be set to 1
  63 + *
  64 + * @returns
  65 + * Binary mask of connected pins
  66 + */
  67 + int mask() {
  68 + return _nc_mask;
  69 + }
  70 +
  71 +#ifdef MBED_OPERATORS
  72 + /** A shorthand for read()
  73 + */
  74 + operator int();
  75 +
  76 + /** Access to particular bit in random-iterator fashion
  77 + */
  78 + DigitalIn & operator[] (int index);
  79 +#endif
  80 +
  81 +protected:
  82 + DigitalIn* _pin[16];
  83 +
  84 + /** Mask of bus's NC pins
  85 + * If bit[n] is set to 1 - pin is connected
  86 + * if bit[n] is cleared - pin is not connected (NC)
  87 + */
  88 + int _nc_mask;
  89 +
  90 + /* disallow copy constructor and assignment operators */
  91 +private:
  92 + BusIn(const BusIn&);
  93 + BusIn & operator = (const BusIn&);
  94 +};
  95 +
  96 +} // namespace mbed
  97 +
  98 +#endif
... ...
mbed/BusInOut.h 0 → 100644
... ... @@ -0,0 +1,117 @@
  1 +/* mbed Microcontroller Library
  2 + * Copyright (c) 2006-2013 ARM Limited
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +#ifndef MBED_BUSINOUT_H
  17 +#define MBED_BUSINOUT_H
  18 +
  19 +#include "DigitalInOut.h"
  20 +
  21 +namespace mbed {
  22 +
  23 +/** A digital input output bus, used for setting the state of a collection of pins
  24 + */
  25 +class BusInOut {
  26 +
  27 +public:
  28 +
  29 + /** Create an BusInOut, connected to the specified pins
  30 + *
  31 + * @param p<n> DigitalInOut pin to connect to bus bit p<n> (p5-p30, NC)
  32 + *
  33 + * @note
  34 + * It is only required to specify as many pin variables as is required
  35 + * for the bus; the rest will default to NC (not connected)
  36 + */
  37 + BusInOut(PinName p0, PinName p1 = NC, PinName p2 = NC, PinName p3 = NC,
  38 + PinName p4 = NC, PinName p5 = NC, PinName p6 = NC, PinName p7 = NC,
  39 + PinName p8 = NC, PinName p9 = NC, PinName p10 = NC, PinName p11 = NC,
  40 + PinName p12 = NC, PinName p13 = NC, PinName p14 = NC, PinName p15 = NC);
  41 +
  42 + BusInOut(PinName pins[16]);
  43 +
  44 + virtual ~BusInOut();
  45 +
  46 + /* Group: Access Methods */
  47 +
  48 + /** Write the value to the output bus
  49 + *
  50 + * @param value An integer specifying a bit to write for every corresponding DigitalInOut pin
  51 + */
  52 + void write(int value);
  53 +
  54 + /** Read the value currently output on the bus
  55 + *
  56 + * @returns
  57 + * An integer with each bit corresponding to associated DigitalInOut pin setting
  58 + */
  59 + int read();
  60 +
  61 + /** Set as an output
  62 + */
  63 + void output();
  64 +
  65 + /** Set as an input
  66 + */
  67 + void input();
  68 +
  69 + /** Set the input pin mode
  70 + *
  71 + * @param mode PullUp, PullDown, PullNone
  72 + */
  73 + void mode(PinMode pull);
  74 +
  75 + /** Binary mask of bus pins connected to actual pins (not NC pins)
  76 + * If bus pin is in NC state make corresponding bit will be cleared (set to 0), else bit will be set to 1
  77 + *
  78 + * @returns
  79 + * Binary mask of connected pins
  80 + */
  81 + int mask() {
  82 + return _nc_mask;
  83 + }
  84 +
  85 +#ifdef MBED_OPERATORS
  86 + /** A shorthand for write()
  87 + */
  88 + BusInOut& operator= (int v);
  89 + BusInOut& operator= (BusInOut& rhs);
  90 +
  91 + /** Access to particular bit in random-iterator fashion
  92 + */
  93 + DigitalInOut& operator[] (int index);
  94 +
  95 + /** A shorthand for read()
  96 + */
  97 + operator int();
  98 +#endif
  99 +
  100 +protected:
  101 + DigitalInOut* _pin[16];
  102 +
  103 + /** Mask of bus's NC pins
  104 + * If bit[n] is set to 1 - pin is connected
  105 + * if bit[n] is cleared - pin is not connected (NC)
  106 + */
  107 + int _nc_mask;
  108 +
  109 + /* disallow copy constructor and assignment operators */
  110 +private:
  111 + BusInOut(const BusInOut&);
  112 + BusInOut & operator = (const BusInOut&);
  113 +};
  114 +
  115 +} // namespace mbed
  116 +
  117 +#endif
... ...
mbed/BusOut.h 0 → 100644
... ... @@ -0,0 +1,101 @@
  1 +/* mbed Microcontroller Library
  2 + * Copyright (c) 2006-2013 ARM Limited
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +#ifndef MBED_BUSOUT_H
  17 +#define MBED_BUSOUT_H
  18 +
  19 +#include "DigitalOut.h"
  20 +
  21 +namespace mbed {
  22 +
  23 +/** A digital output bus, used for setting the state of a collection of pins
  24 + */
  25 +class BusOut {
  26 +
  27 +public:
  28 +
  29 + /** Create an BusOut, connected to the specified pins
  30 + *
  31 + * @param p<n> DigitalOut pin to connect to bus bit <n> (p5-p30, NC)
  32 + *
  33 + * @note
  34 + * It is only required to specify as many pin variables as is required
  35 + * for the bus; the rest will default to NC (not connected)
  36 + */
  37 + BusOut(PinName p0, PinName p1 = NC, PinName p2 = NC, PinName p3 = NC,
  38 + PinName p4 = NC, PinName p5 = NC, PinName p6 = NC, PinName p7 = NC,
  39 + PinName p8 = NC, PinName p9 = NC, PinName p10 = NC, PinName p11 = NC,
  40 + PinName p12 = NC, PinName p13 = NC, PinName p14 = NC, PinName p15 = NC);
  41 +
  42 + BusOut(PinName pins[16]);
  43 +
  44 + virtual ~BusOut();
  45 +
  46 + /** Write the value to the output bus
  47 + *
  48 + * @param value An integer specifying a bit to write for every corresponding DigitalOut pin
  49 + */
  50 + void write(int value);
  51 +
  52 + /** Read the value currently output on the bus
  53 + *
  54 + * @returns
  55 + * An integer with each bit corresponding to associated DigitalOut pin setting
  56 + */
  57 + int read();
  58 +
  59 + /** Binary mask of bus pins connected to actual pins (not NC pins)
  60 + * If bus pin is in NC state make corresponding bit will be cleared (set to 0), else bit will be set to 1
  61 + *
  62 + * @returns
  63 + * Binary mask of connected pins
  64 + */
  65 + int mask() {
  66 + return _nc_mask;
  67 + }
  68 +
  69 +#ifdef MBED_OPERATORS
  70 + /** A shorthand for write()
  71 + */
  72 + BusOut& operator= (int v);
  73 + BusOut& operator= (BusOut& rhs);
  74 +
  75 + /** Access to particular bit in random-iterator fashion
  76 + */
  77 + DigitalOut& operator[] (int index);
  78 +
  79 + /** A shorthand for read()
  80 + */
  81 + operator int();
  82 +#endif
  83 +
  84 +protected:
  85 + DigitalOut* _pin[16];
  86 +
  87 + /** Mask of bus's NC pins
  88 + * If bit[n] is set to 1 - pin is connected
  89 + * if bit[n] is cleared - pin is not connected (NC)
  90 + */
  91 + int _nc_mask;
  92 +
  93 + /* disallow copy constructor and assignment operators */
  94 +private:
  95 + BusOut(const BusOut&);
  96 + BusOut & operator = (const BusOut&);
  97 +};
  98 +
  99 +} // namespace mbed
  100 +
  101 +#endif
... ...
mbed/CAN.h 0 → 100644
... ... @@ -0,0 +1,243 @@
  1 +/* mbed Microcontroller Library
  2 + * Copyright (c) 2006-2013 ARM Limited
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +#ifndef MBED_CAN_H
  17 +#define MBED_CAN_H
  18 +
  19 +#include "platform.h"
  20 +
  21 +#if DEVICE_CAN
  22 +
  23 +#include "can_api.h"
  24 +#include "can_helper.h"
  25 +#include "FunctionPointer.h"
  26 +
  27 +namespace mbed {
  28 +
  29 +/** CANMessage class
  30 + */
  31 +class CANMessage : public CAN_Message {
  32 +
  33 +public:
  34 + /** Creates empty CAN message.
  35 + */
  36 + CANMessage() : CAN_Message() {
  37 + len = 8;
  38 + type = CANData;
  39 + format = CANStandard;
  40 + id = 0;
  41 + memset(data, 0, 8);
  42 + }
  43 +
  44 + /** Creates CAN message with specific content.
  45 + */
  46 + CANMessage(int _id, const char *_data, char _len = 8, CANType _type = CANData, CANFormat _format = CANStandard) {
  47 + len = _len & 0xF;
  48 + type = _type;
  49 + format = _format;
  50 + id = _id;
  51 + memcpy(data, _data, _len);
  52 + }
  53 +
  54 + /** Creates CAN remote message.
  55 + */
  56 + CANMessage(int _id, CANFormat _format = CANStandard) {
  57 + len = 0;
  58 + type = CANRemote;
  59 + format = _format;
  60 + id = _id;
  61 + memset(data, 0, 8);
  62 + }
  63 +};
  64 +
  65 +/** A can bus client, used for communicating with can devices
  66 + */
  67 +class CAN {
  68 +
  69 +public:
  70 + /** Creates an CAN interface connected to specific pins.
  71 + *
  72 + * @param rd read from transmitter
  73 + * @param td transmit to transmitter
  74 + *
  75 + * Example:
  76 + * @code
  77 + * #include "mbed.h"
  78 + *
  79 + * Ticker ticker;
  80 + * DigitalOut led1(LED1);
  81 + * DigitalOut led2(LED2);
  82 + * CAN can1(p9, p10);
  83 + * CAN can2(p30, p29);
  84 + *
  85 + * char counter = 0;
  86 + *
  87 + * void send() {
  88 + * if(can1.write(CANMessage(1337, &counter, 1))) {
  89 + * printf("Message sent: %d\n", counter);
  90 + * counter++;
  91 + * }
  92 + * led1 = !led1;
  93 + * }
  94 + *
  95 + * int main() {
  96 + * ticker.attach(&send, 1);
  97 + * CANMessage msg;
  98 + * while(1) {
  99 + * if(can2.read(msg)) {
  100 + * printf("Message received: %d\n\n", msg.data[0]);
  101 + * led2 = !led2;
  102 + * }
  103 + * wait(0.2);
  104 + * }
  105 + * }
  106 + * @endcode
  107 + */
  108 + CAN(PinName rd, PinName td);
  109 + virtual ~CAN();
  110 +
  111 + /** Set the frequency of the CAN interface
  112 + *
  113 + * @param hz The bus frequency in hertz
  114 + *
  115 + * @returns
  116 + * 1 if successful,
  117 + * 0 otherwise
  118 + */
  119 + int frequency(int hz);
  120 +
  121 + /** Write a CANMessage to the bus.
  122 + *
  123 + * @param msg The CANMessage to write.
  124 + *
  125 + * @returns
  126 + * 0 if write failed,
  127 + * 1 if write was successful
  128 + */
  129 + int write(CANMessage msg);
  130 +
  131 + /** Read a CANMessage from the bus.
  132 + *
  133 + * @param msg A CANMessage to read to.
  134 + * @param handle message filter handle (0 for any message)
  135 + *
  136 + * @returns
  137 + * 0 if no message arrived,
  138 + * 1 if message arrived
  139 + */
  140 + int read(CANMessage &msg, int handle = 0);
  141 +
  142 + /** Reset CAN interface.
  143 + *
  144 + * To use after error overflow.
  145 + */
  146 + void reset();
  147 +
  148 + /** Puts or removes the CAN interface into silent monitoring mode
  149 + *
  150 + * @param silent boolean indicating whether to go into silent mode or not
  151 + */
  152 + void monitor(bool silent);
  153 +
  154 + enum Mode {
  155 + Reset = 0,
  156 + Normal,
  157 + Silent,
  158 + LocalTest,
  159 + GlobalTest,
  160 + SilentTest
  161 + };
  162 +
  163 + /** Change CAN operation to the specified mode
  164 + *
  165 + * @param mode The new operation mode (CAN::Normal, CAN::Silent, CAN::LocalTest, CAN::GlobalTest, CAN::SilentTest)
  166 + *
  167 + * @returns
  168 + * 0 if mode change failed or unsupported,
  169 + * 1 if mode change was successful
  170 + */
  171 + int mode(Mode mode);
  172 +
  173 + /** Filter out incomming messages
  174 + *
  175 + * @param id the id to filter on
  176 + * @param mask the mask applied to the id
  177 + * @param format format to filter on (Default CANAny)
  178 + * @param handle message filter handle (Optional)
  179 + *
  180 + * @returns
  181 + * 0 if filter change failed or unsupported,
  182 + * new filter handle if successful
  183 + */
  184 + int filter(unsigned int id, unsigned int mask, CANFormat format = CANAny, int handle = 0);
  185 +
  186 + /** Returns number of read errors to detect read overflow errors.
  187 + */
  188 + unsigned char rderror();
  189 +
  190 + /** Returns number of write errors to detect write overflow errors.
  191 + */
  192 + unsigned char tderror();
  193 +
  194 + enum IrqType {
  195 + RxIrq = 0,
  196 + TxIrq,
  197 + EwIrq,
  198 + DoIrq,
  199 + WuIrq,
  200 + EpIrq,
  201 + AlIrq,
  202 + BeIrq,
  203 + IdIrq
  204 + };
  205 +
  206 + /** Attach a function to call whenever a CAN frame received interrupt is
  207 + * generated.
  208 + *
  209 + * @param fptr A pointer to a void function, or 0 to set as none
  210 + * @param event Which CAN interrupt to attach the member function to (CAN::RxIrq for message received, CAN::TxIrq for transmitted or aborted, CAN::EwIrq for error warning, CAN::DoIrq for data overrun, CAN::WuIrq for wake-up, CAN::EpIrq for error passive, CAN::AlIrq for arbitration lost, CAN::BeIrq for bus error)
  211 + */
  212 + void attach(void (*fptr)(void), IrqType type=RxIrq);
  213 +
  214 + /** Attach a member function to call whenever a CAN frame received interrupt
  215 + * is generated.
  216 + *
  217 + * @param tptr pointer to the object to call the member function on
  218 + * @param mptr pointer to the member function to be called
  219 + * @param event Which CAN interrupt to attach the member function to (CAN::RxIrq for message received, TxIrq for transmitted or aborted, EwIrq for error warning, DoIrq for data overrun, WuIrq for wake-up, EpIrq for error passive, AlIrq for arbitration lost, BeIrq for bus error)
  220 + */
  221 + template<typename T>
  222 + void attach(T* tptr, void (T::*mptr)(void), IrqType type=RxIrq) {
  223 + if((mptr != NULL) && (tptr != NULL)) {
  224 + _irq[type].attach(tptr, mptr);
  225 + can_irq_set(&_can, (CanIrqType)type, 1);
  226 + }
  227 + else {
  228 + can_irq_set(&_can, (CanIrqType)type, 0);
  229 + }
  230 + }
  231 +
  232 + static void _irq_handler(uint32_t id, CanIrqType type);
  233 +
  234 +protected:
  235 + can_t _can;
  236 + FunctionPointer _irq[9];
  237 +};
  238 +
  239 +} // namespace mbed
  240 +
  241 +#endif
  242 +
  243 +#endif // MBED_CAN_H
... ...
mbed/CThunk.h 0 → 100644
... ... @@ -0,0 +1,202 @@
  1 +/* General C++ Object Thunking class
  2 + *
  3 + * - allows direct callbacks to non-static C++ class functions
  4 + * - keeps track for the corresponding class instance
  5 + * - supports an optional context parameter for the called function
  6 + * - ideally suited for class object receiving interrupts (NVIC_SetVector)
  7 + *
  8 + * Copyright (c) 2014-2015 ARM Limited
  9 + *
  10 + * Licensed under the Apache License, Version 2.0 (the "License");
  11 + * you may not use this file except in compliance with the License.
  12 + * You may obtain a copy of the License at
  13 + *
  14 + * http://www.apache.org/licenses/LICENSE-2.0
  15 + *
  16 + * Unless required by applicable law or agreed to in writing, software
  17 + * distributed under the License is distributed on an "AS IS" BASIS,
  18 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19 + * See the License for the specific language governing permissions and
  20 + * limitations under the License.
  21 + */
  22 +#ifndef __CTHUNK_H__
  23 +#define __CTHUNK_H__
  24 +
  25 +#define CTHUNK_ADDRESS 1
  26 +
  27 +#if defined(__CORTEX_M3) || defined(__CORTEX_M4) || defined(__thumb2__)
  28 +#define CTHUNK_VARIABLES volatile uint32_t code[1]
  29 +/**
  30 +* CTHUNK disassembly for Cortex-M3/M4 (thumb2):
  31 +* * ldm.w pc,{r0,r1,r2,pc}
  32 +*
  33 +* This instruction loads the arguments for the static thunking function to r0-r2, and
  34 +* branches to that function by loading its address into PC.
  35 +*
  36 +* This is safe for both regular calling and interrupt calling, since it only touches scratch registers
  37 +* which should be saved by the caller, and are automatically saved as part of the IRQ context switch.
  38 +*/
  39 +#define CTHUNK_ASSIGMENT m_thunk.code[0] = 0x8007E89F
  40 +
  41 +#elif defined(__CORTEX_M0PLUS) || defined(__CORTEX_M0)
  42 +/*
  43 +* CTHUNK disassembly for Cortex M0 (thumb):
  44 +* * push {r0,r1,r2,r3,r4,lr} save touched registers and return address
  45 +* * movs r4,#4 set up address to load arguments from (immediately following this code block) (1)
  46 +* * add r4,pc set up address to load arguments from (immediately following this code block) (2)
  47 +* * ldm r4!,{r0,r1,r2,r3} load arguments for static thunk function
  48 +* * blx r3 call static thunk function
  49 +* * pop {r0,r1,r2,r3,r4,pc} restore scratch registers and return from function
  50 +*/
  51 +#define CTHUNK_VARIABLES volatile uint32_t code[3]
  52 +#define CTHUNK_ASSIGMENT do { \
  53 + m_thunk.code[0] = 0x2404B51F; \
  54 + m_thunk.code[1] = 0xCC0F447C; \
  55 + m_thunk.code[2] = 0xBD1F4798; \
  56 + } while (0)
  57 +
  58 +#else
  59 +#error "Target is not currently suported."
  60 +#endif
  61 +
  62 +/* IRQ/Exception compatible thunk entry function */
  63 +typedef void (*CThunkEntry)(void);
  64 +
  65 +template<class T>
  66 +class CThunk
  67 +{
  68 + public:
  69 + typedef void (T::*CCallbackSimple)(void);
  70 + typedef void (T::*CCallback)(void* context);
  71 +
  72 + inline CThunk(T *instance)
  73 + {
  74 + init(instance, NULL, NULL);
  75 + }
  76 +
  77 + inline CThunk(T *instance, CCallback callback)
  78 + {
  79 + init(instance, callback, NULL);
  80 + }
  81 +
  82 + ~CThunk() {
  83 +
  84 + }
  85 +
  86 + inline CThunk(T *instance, CCallbackSimple callback)
  87 + {
  88 + init(instance, (CCallback)callback, NULL);
  89 + }
  90 +
  91 + inline CThunk(T &instance, CCallback callback)
  92 + {
  93 + init(instance, callback, NULL);
  94 + }
  95 +
  96 + inline CThunk(T &instance, CCallbackSimple callback)
  97 + {
  98 + init(instance, (CCallback)callback, NULL);
  99 + }
  100 +
  101 + inline CThunk(T &instance, CCallback callback, void* context)
  102 + {
  103 + init(instance, callback, context);
  104 + }
  105 +
  106 + inline void callback(CCallback callback)
  107 + {
  108 + m_callback = callback;
  109 + }
  110 +
  111 + inline void callback(CCallbackSimple callback)
  112 + {
  113 + m_callback = (CCallback)callback;
  114 + }
  115 +
  116 + inline void context(void* context)
  117 + {
  118 + m_thunk.context = (uint32_t)context;
  119 + }
  120 +
  121 + inline void context(uint32_t context)
  122 + {
  123 + m_thunk.context = context;
  124 + }
  125 +
  126 + inline uint32_t entry(void)
  127 + {
  128 + return (((uint32_t)&m_thunk)|CTHUNK_ADDRESS);
  129 + }
  130 +
  131 + /* get thunk entry point for connecting rhunk to an IRQ table */
  132 + inline operator CThunkEntry(void)
  133 + {
  134 + return (CThunkEntry)entry();
  135 + }
  136 +
  137 + /* get thunk entry point for connecting rhunk to an IRQ table */
  138 + inline operator uint32_t(void)
  139 + {
  140 + return entry();
  141 + }
  142 +
  143 + /* simple test function */
  144 + inline void call(void)
  145 + {
  146 + (((CThunkEntry)(entry()))());
  147 + }
  148 +
  149 + private:
  150 + T* m_instance;
  151 + volatile CCallback m_callback;
  152 +
  153 +// TODO: this needs proper fix, to refactor toolchain header file and all its use
  154 +// PACKED there is not defined properly for IAR
  155 +#if defined (__ICCARM__)
  156 + typedef __packed struct
  157 + {
  158 + CTHUNK_VARIABLES;
  159 + volatile uint32_t instance;
  160 + volatile uint32_t context;
  161 + volatile uint32_t callback;
  162 + volatile uint32_t trampoline;
  163 + } CThunkTrampoline;
  164 +#else
  165 + typedef struct
  166 + {
  167 + CTHUNK_VARIABLES;
  168 + volatile uint32_t instance;
  169 + volatile uint32_t context;
  170 + volatile uint32_t callback;
  171 + volatile uint32_t trampoline;
  172 + } __attribute__((__packed__)) CThunkTrampoline;
  173 +#endif
  174 +
  175 + static void trampoline(T* instance, void* context, CCallback* callback)
  176 + {
  177 + if(instance && *callback) {
  178 + (static_cast<T*>(instance)->**callback)(context);
  179 + }
  180 + }
  181 +
  182 + volatile CThunkTrampoline m_thunk;
  183 +
  184 + inline void init(T *instance, CCallback callback, void* context)
  185 + {
  186 + /* remember callback - need to add this level of redirection
  187 + as pointer size for member functions differs between platforms */
  188 + m_callback = callback;
  189 +
  190 + /* populate thunking trampoline */
  191 + CTHUNK_ASSIGMENT;
  192 + m_thunk.context = (uint32_t)context;
  193 + m_thunk.instance = (uint32_t)instance;
  194 + m_thunk.callback = (uint32_t)&m_callback;
  195 + m_thunk.trampoline = (uint32_t)&trampoline;
  196 +
  197 + __ISB();
  198 + __DSB();
  199 + }
  200 +};
  201 +
  202 +#endif/*__CTHUNK_H__*/
... ...
mbed/CallChain.h 0 → 100644
... ... @@ -0,0 +1,181 @@
  1 +/* mbed Microcontroller Library
  2 + * Copyright (c) 2006-2013 ARM Limited
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +#ifndef MBED_CALLCHAIN_H
  17 +#define MBED_CALLCHAIN_H
  18 +
  19 +#include "FunctionPointer.h"
  20 +#include <string.h>
  21 +
  22 +namespace mbed {
  23 +
  24 +/** Group one or more functions in an instance of a CallChain, then call them in
  25 + * sequence using CallChain::call(). Used mostly by the interrupt chaining code,
  26 + * but can be used for other purposes.
  27 + *
  28 + * Example:
  29 + * @code
  30 + * #include "mbed.h"
  31 + *
  32 + * CallChain chain;
  33 + *
  34 + * void first(void) {
  35 + * printf("'first' function.\n");
  36 + * }
  37 + *
  38 + * void second(void) {
  39 + * printf("'second' function.\n");
  40 + * }
  41 + *
  42 + * class Test {
  43 + * public:
  44 + * void f(void) {
  45 + * printf("A::f (class member).\n");
  46 + * }
  47 + * };
  48 + *
  49 + * int main() {
  50 + * Test test;
  51 + *
  52 + * chain.add(second);
  53 + * chain.add_front(first);
  54 + * chain.add(&test, &Test::f);
  55 + * chain.call();
  56 + * }
  57 + * @endcode
  58 + */
  59 +
  60 +typedef FunctionPointer* pFunctionPointer_t;
  61 +
  62 +class CallChain {
  63 +public:
  64 + /** Create an empty chain
  65 + *
  66 + * @param size (optional) Initial size of the chain
  67 + */
  68 + CallChain(int size = 4);
  69 + virtual ~CallChain();
  70 +
  71 + /** Add a function at the end of the chain
  72 + *
  73 + * @param function A pointer to a void function
  74 + *
  75 + * @returns
  76 + * The function object created for 'function'
  77 + */
  78 + pFunctionPointer_t add(void (*function)(void));
  79 +
  80 + /** Add a function at the end of the chain
  81 + *
  82 + * @param tptr pointer to the object to call the member function on
  83 + * @param mptr pointer to the member function to be called
  84 + *
  85 + * @returns
  86 + * The function object created for 'tptr' and 'mptr'
  87 + */
  88 + template<typename T>
  89 + pFunctionPointer_t add(T *tptr, void (T::*mptr)(void)) {
  90 + return common_add(new FunctionPointer(tptr, mptr));
  91 + }
  92 +
  93 + /** Add a function at the beginning of the chain
  94 + *
  95 + * @param function A pointer to a void function
  96 + *
  97 + * @returns
  98 + * The function object created for 'function'
  99 + */
  100 + pFunctionPointer_t add_front(void (*function)(void));
  101 +
  102 + /** Add a function at the beginning of the chain
  103 + *
  104 + * @param tptr pointer to the object to call the member function on
  105 + * @param mptr pointer to the member function to be called
  106 + *
  107 + * @returns
  108 + * The function object created for 'tptr' and 'mptr'
  109 + */
  110 + template<typename T>
  111 + pFunctionPointer_t add_front(T *tptr, void (T::*mptr)(void)) {
  112 + return common_add_front(new FunctionPointer(tptr, mptr));
  113 + }
  114 +
  115 + /** Get the number of functions in the chain
  116 + */
  117 + int size() const;
  118 +
  119 + /** Get a function object from the chain
  120 + *
  121 + * @param i function object index
  122 + *
  123 + * @returns
  124 + * The function object at position 'i' in the chain
  125 + */
  126 + pFunctionPointer_t get(int i) const;
  127 +
  128 + /** Look for a function object in the call chain
  129 + *
  130 + * @param f the function object to search
  131 + *
  132 + * @returns
  133 + * The index of the function object if found, -1 otherwise.
  134 + */
  135 + int find(pFunctionPointer_t f) const;
  136 +
  137 + /** Clear the call chain (remove all functions in the chain).
  138 + */
  139 + void clear();
  140 +
  141 + /** Remove a function object from the chain
  142 + *
  143 + * @arg f the function object to remove
  144 + *
  145 + * @returns
  146 + * true if the function object was found and removed, false otherwise.
  147 + */
  148 + bool remove(pFunctionPointer_t f);
  149 +
  150 + /** Call all the functions in the chain in sequence
  151 + */
  152 + void call();
  153 +
  154 +#ifdef MBED_OPERATORS
  155 + void operator ()(void) {
  156 + call();
  157 + }
  158 + pFunctionPointer_t operator [](int i) const {
  159 + return get(i);
  160 + }
  161 +#endif
  162 +
  163 +private:
  164 + void _check_size();
  165 + pFunctionPointer_t common_add(pFunctionPointer_t pf);
  166 + pFunctionPointer_t common_add_front(pFunctionPointer_t pf);
  167 +
  168 + pFunctionPointer_t* _chain;
  169 + int _size;
  170 + int _elements;
  171 +
  172 + /* disallow copy constructor and assignment operators */
  173 +private:
  174 + CallChain(const CallChain&);
  175 + CallChain & operator = (const CallChain&);
  176 +};
  177 +
  178 +} // namespace mbed
  179 +
  180 +#endif
  181 +
... ...
mbed/CircularBuffer.h 0 → 100644
... ... @@ -0,0 +1,98 @@
  1 +/* mbed Microcontroller Library
  2 + * Copyright (c) 2015 ARM Limited
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +#ifndef MBED_CIRCULARBUFFER_H
  17 +#define MBED_CIRCULARBUFFER_H
  18 +
  19 +namespace mbed {
  20 +
  21 +/** Templated Circular buffer class
  22 + */
  23 +template<typename T, uint32_t BufferSize, typename CounterType = uint32_t>
  24 +class CircularBuffer {
  25 +public:
  26 + CircularBuffer() : _head(0), _tail(0), _full(false) {
  27 + }
  28 +
  29 + ~CircularBuffer() {
  30 + }
  31 +
  32 + /** Push the transaction to the buffer. This overwrites the buffer if it's
  33 + * full
  34 + *
  35 + * @param data Data to be pushed to the buffer
  36 + */
  37 + void push(const T& data) {
  38 + if (full()) {
  39 + _tail++;
  40 + _tail %= BufferSize;
  41 + }
  42 + _pool[_head++] = data;
  43 + _head %= BufferSize;
  44 + if (_head == _tail) {
  45 + _full = true;
  46 + }
  47 + }
  48 +
  49 + /** Pop the transaction from the buffer
  50 + *
  51 + * @param data Data to be pushed to the buffer
  52 + * @return True if the buffer is not empty and data contains a transaction, false otherwise
  53 + */
  54 + bool pop(T& data) {
  55 + if (!empty()) {
  56 + data = _pool[_tail++];
  57 + _tail %= BufferSize;
  58 + _full = false;
  59 + return true;
  60 + }
  61 + return false;
  62 + }
  63 +
  64 + /** Check if the buffer is empty
  65 + *
  66 + * @return True if the buffer is empty, false if not
  67 + */
  68 + bool empty() {
  69 + return (_head == _tail) && !_full;
  70 + }
  71 +
  72 + /** Check if the buffer is full
  73 + *
  74 + * @return True if the buffer is full, false if not
  75 + */
  76 + bool full() {
  77 + return _full;
  78 + }
  79 +
  80 + /** Reset the buffer
  81 + *
  82 + */
  83 + void reset() {
  84 + _head = 0;
  85 + _tail = 0;
  86 + _full = false;
  87 + }
  88 +
  89 +private:
  90 + T _pool[BufferSize];
  91 + volatile CounterType _head;
  92 + volatile CounterType _tail;
  93 + volatile bool _full;
  94 +};
  95 +
  96 +}
  97 +
  98 +#endif
... ...
mbed/DigitalIn.h 0 → 100644
... ... @@ -0,0 +1,107 @@
  1 +/* mbed Microcontroller Library
  2 + * Copyright (c) 2006-2013 ARM Limited
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +#ifndef MBED_DIGITALIN_H
  17 +#define MBED_DIGITALIN_H
  18 +
  19 +#include "platform.h"
  20 +
  21 +#include "gpio_api.h"
  22 +
  23 +namespace mbed {
  24 +
  25 +/** A digital input, used for reading the state of a pin
  26 + *
  27 + * Example:
  28 + * @code
  29 + * // Flash an LED while a DigitalIn is true
  30 + *
  31 + * #include "mbed.h"
  32 + *
  33 + * DigitalIn enable(p5);
  34 + * DigitalOut led(LED1);
  35 + *
  36 + * int main() {
  37 + * while(1) {
  38 + * if(enable) {
  39 + * led = !led;
  40 + * }
  41 + * wait(0.25);
  42 + * }
  43 + * }
  44 + * @endcode
  45 + */
  46 +class DigitalIn {
  47 +
  48 +public:
  49 + /** Create a DigitalIn connected to the specified pin
  50 + *
  51 + * @param pin DigitalIn pin to connect to
  52 + */
  53 + DigitalIn(PinName pin) : gpio() {
  54 + gpio_init_in(&gpio, pin);
  55 + }
  56 +
  57 + /** Create a DigitalIn connected to the specified pin
  58 + *
  59 + * @param pin DigitalIn pin to connect to
  60 + * @param mode the initial mode of the pin
  61 + */
  62 + DigitalIn(PinName pin, PinMode mode) : gpio() {
  63 + gpio_init_in_ex(&gpio, pin, mode);
  64 + }
  65 + /** Read the input, represented as 0 or 1 (int)
  66 + *
  67 + * @returns
  68 + * An integer representing the state of the input pin,
  69 + * 0 for logical 0, 1 for logical 1
  70 + */
  71 + int read() {
  72 + return gpio_read(&gpio);
  73 + }
  74 +
  75 + /** Set the input pin mode
  76 + *
  77 + * @param mode PullUp, PullDown, PullNone, OpenDrain
  78 + */
  79 + void mode(PinMode pull) {
  80 + gpio_mode(&gpio, pull);
  81 + }
  82 +
  83 + /** Return the output setting, represented as 0 or 1 (int)
  84 + *
  85 + * @returns
  86 + * Non zero value if pin is connected to uc GPIO
  87 + * 0 if gpio object was initialized with NC
  88 + */
  89 + int is_connected() {
  90 + return gpio_is_connected(&gpio);
  91 + }
  92 +
  93 +#ifdef MBED_OPERATORS
  94 + /** An operator shorthand for read()
  95 + */
  96 + operator int() {
  97 + return read();
  98 + }
  99 +#endif
  100 +
  101 +protected:
  102 + gpio_t gpio;
  103 +};
  104 +
  105 +} // namespace mbed
  106 +
  107 +#endif
... ...
mbed/DigitalInOut.h 0 → 100644
... ... @@ -0,0 +1,124 @@
  1 +/* mbed Microcontroller Library
  2 + * Copyright (c) 2006-2013 ARM Limited
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +#ifndef MBED_DIGITALINOUT_H
  17 +#define MBED_DIGITALINOUT_H
  18 +
  19 +#include "platform.h"
  20 +
  21 +#include "gpio_api.h"
  22 +
  23 +namespace mbed {
  24 +
  25 +/** A digital input/output, used for setting or reading a bi-directional pin
  26 + */
  27 +class DigitalInOut {
  28 +
  29 +public:
  30 + /** Create a DigitalInOut connected to the specified pin
  31 + *
  32 + * @param pin DigitalInOut pin to connect to
  33 + */
  34 + DigitalInOut(PinName pin) : gpio() {
  35 + gpio_init_in(&gpio, pin);
  36 + }
  37 +
  38 + /** Create a DigitalInOut connected to the specified pin
  39 + *
  40 + * @param pin DigitalInOut pin to connect to
  41 + * @param direction the initial direction of the pin
  42 + * @param mode the initial mode of the pin
  43 + * @param value the initial value of the pin if is an output
  44 + */
  45 + DigitalInOut(PinName pin, PinDirection direction, PinMode mode, int value) : gpio() {
  46 + gpio_init_inout(&gpio, pin, direction, mode, value);
  47 + }
  48 +
  49 + /** Set the output, specified as 0 or 1 (int)
  50 + *
  51 + * @param value An integer specifying the pin output value,
  52 + * 0 for logical 0, 1 (or any other non-zero value) for logical 1
  53 + */
  54 + void write(int value) {
  55 + gpio_write(&gpio, value);
  56 + }
  57 +
  58 + /** Return the output setting, represented as 0 or 1 (int)
  59 + *
  60 + * @returns
  61 + * an integer representing the output setting of the pin if it is an output,
  62 + * or read the input if set as an input
  63 + */
  64 + int read() {
  65 + return gpio_read(&gpio);
  66 + }
  67 +
  68 + /** Set as an output
  69 + */
  70 + void output() {
  71 + gpio_dir(&gpio, PIN_OUTPUT);
  72 + }
  73 +
  74 + /** Set as an input
  75 + */
  76 + void input() {
  77 + gpio_dir(&gpio, PIN_INPUT);
  78 + }
  79 +
  80 + /** Set the input pin mode
  81 + *
  82 + * @param mode PullUp, PullDown, PullNone, OpenDrain
  83 + */
  84 + void mode(PinMode pull) {
  85 + gpio_mode(&gpio, pull);
  86 + }
  87 +
  88 + /** Return the output setting, represented as 0 or 1 (int)
  89 + *
  90 + * @returns
  91 + * Non zero value if pin is connected to uc GPIO
  92 + * 0 if gpio object was initialized with NC
  93 + */
  94 + int is_connected() {
  95 + return gpio_is_connected(&gpio);
  96 + }
  97 +
  98 +#ifdef MBED_OPERATORS
  99 + /** A shorthand for write()
  100 + */
  101 + DigitalInOut& operator= (int value) {
  102 + write(value);
  103 + return *this;
  104 + }
  105 +
  106 + DigitalInOut& operator= (DigitalInOut& rhs) {
  107 + write(rhs.read());
  108 + return *this;
  109 + }
  110 +
  111 + /** A shorthand for read()
  112 + */
  113 + operator int() {
  114 + return read();
  115 + }
  116 +#endif
  117 +
  118 +protected:
  119 + gpio_t gpio;
  120 +};
  121 +
  122 +} // namespace mbed
  123 +
  124 +#endif
... ...
mbed/DigitalOut.h 0 → 100644
... ... @@ -0,0 +1,116 @@
  1 +/* mbed Microcontroller Library
  2 + * Copyright (c) 2006-2013 ARM Limited
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +#ifndef MBED_DIGITALOUT_H
  17 +#define MBED_DIGITALOUT_H
  18 +
  19 +#include "platform.h"
  20 +#include "gpio_api.h"
  21 +
  22 +namespace mbed {
  23 +
  24 +/** A digital output, used for setting the state of a pin
  25 + *
  26 + * Example:
  27 + * @code
  28 + * // Toggle a LED
  29 + * #include "mbed.h"
  30 + *
  31 + * DigitalOut led(LED1);
  32 + *
  33 + * int main() {
  34 + * while(1) {
  35 + * led = !led;
  36 + * wait(0.2);
  37 + * }
  38 + * }
  39 + * @endcode
  40 + */
  41 +class DigitalOut {
  42 +
  43 +public:
  44 + /** Create a DigitalOut connected to the specified pin
  45 + *
  46 + * @param pin DigitalOut pin to connect to
  47 + */
  48 + DigitalOut(PinName pin) : gpio() {
  49 + gpio_init_out(&gpio, pin);
  50 + }
  51 +
  52 + /** Create a DigitalOut connected to the specified pin
  53 + *
  54 + * @param pin DigitalOut pin to connect to
  55 + * @param value the initial pin value
  56 + */
  57 + DigitalOut(PinName pin, int value) : gpio() {
  58 + gpio_init_out_ex(&gpio, pin, value);
  59 + }
  60 +
  61 + /** Set the output, specified as 0 or 1 (int)
  62 + *
  63 + * @param value An integer specifying the pin output value,
  64 + * 0 for logical 0, 1 (or any other non-zero value) for logical 1
  65 + */
  66 + void write(int value) {
  67 + gpio_write(&gpio, value);
  68 + }
  69 +
  70 + /** Return the output setting, represented as 0 or 1 (int)
  71 + *
  72 + * @returns
  73 + * an integer representing the output setting of the pin,
  74 + * 0 for logical 0, 1 for logical 1
  75 + */
  76 + int read() {
  77 + return gpio_read(&gpio);
  78 + }
  79 +
  80 + /** Return the output setting, represented as 0 or 1 (int)
  81 + *
  82 + * @returns
  83 + * Non zero value if pin is connected to uc GPIO
  84 + * 0 if gpio object was initialized with NC
  85 + */
  86 + int is_connected() {
  87 + return gpio_is_connected(&gpio);
  88 + }
  89 +
  90 +#ifdef MBED_OPERATORS
  91 + /** A shorthand for write()
  92 + */
  93 + DigitalOut& operator= (int value) {
  94 + write(value);
  95 + return *this;
  96 + }
  97 +
  98 + DigitalOut& operator= (DigitalOut& rhs) {
  99 + write(rhs.read());
  100 + return *this;
  101 + }
  102 +
  103 + /** A shorthand for read()
  104 + */
  105 + operator int() {
  106 + return read();
  107 + }
  108 +#endif
  109 +
  110 +protected:
  111 + gpio_t gpio;
  112 +};
  113 +
  114 +} // namespace mbed
  115 +
  116 +#endif
... ...
mbed/DirHandle.h 0 → 100644
... ... @@ -0,0 +1,104 @@
  1 +/* mbed Microcontroller Library
  2 + * Copyright (c) 2006-2013 ARM Limited
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +#ifndef MBED_DIRHANDLE_H
  17 +#define MBED_DIRHANDLE_H
  18 +
  19 +#if defined(__ARMCC_VERSION) || defined(__ICCARM__)
  20 +# define NAME_MAX 255
  21 +typedef int mode_t;
  22 +
  23 +#else
  24 +# include <sys/syslimits.h>
  25 +#endif
  26 +
  27 +#include "FileHandle.h"
  28 +
  29 +struct dirent {
  30 + char d_name[NAME_MAX+1];
  31 +};
  32 +
  33 +namespace mbed {
  34 +
  35 +/** Represents a directory stream. Objects of this type are returned
  36 + * by a FileSystemLike's opendir method. Implementations must define
  37 + * at least closedir, readdir and rewinddir.
  38 + *
  39 + * If a FileSystemLike class defines the opendir method, then the
  40 + * directories of an object of that type can be accessed by
  41 + * DIR *d = opendir("/example/directory") (or opendir("/example")
  42 + * to open the root of the filesystem), and then using readdir(d) etc.
  43 + *
  44 + * The root directory is considered to contain all FileLike and
  45 + * FileSystemLike objects, so the DIR* returned by opendir("/") will
  46 + * reflect this.
  47 + */
  48 +class DirHandle {
  49 +
  50 +public:
  51 + /** Closes the directory.
  52 + *
  53 + * @returns
  54 + * 0 on success,
  55 + * -1 on error.
  56 + */
  57 + virtual int closedir()=0;
  58 +
  59 + /** Return the directory entry at the current position, and
  60 + * advances the position to the next entry.
  61 + *
  62 + * @returns
  63 + * A pointer to a dirent structure representing the
  64 + * directory entry at the current position, or NULL on reaching
  65 + * end of directory or error.
  66 + */
  67 + virtual struct dirent *readdir()=0;
  68 +
  69 + /** Resets the position to the beginning of the directory.
  70 + */
  71 + virtual void rewinddir()=0;
  72 +
  73 + /** Returns the current position of the DirHandle.
  74 + *
  75 + * @returns
  76 + * the current position,
  77 + * -1 on error.
  78 + */
  79 + virtual off_t telldir() { return -1; }
  80 +
  81 + /** Sets the position of the DirHandle.
  82 + *
  83 + * @param location The location to seek to. Must be a value returned by telldir.
  84 + */
  85 + virtual void seekdir(off_t location) { }
  86 +
  87 + virtual ~DirHandle() {}
  88 +};
  89 +
  90 +} // namespace mbed
  91 +
  92 +typedef mbed::DirHandle DIR;
  93 +
  94 +extern "C" {
  95 + DIR *opendir(const char*);
  96 + struct dirent *readdir(DIR *);
  97 + int closedir(DIR*);
  98 + void rewinddir(DIR*);
  99 + long telldir(DIR*);
  100 + void seekdir(DIR*, long);
  101 + int mkdir(const char *name, mode_t n);
  102 +};
  103 +
  104 +#endif /* MBED_DIRHANDLE_H */
... ...
mbed/Ethernet.h 0 → 100644
... ... @@ -0,0 +1,170 @@
  1 +/* mbed Microcontroller Library
  2 + * Copyright (c) 2006-2013 ARM Limited
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +#ifndef MBED_ETHERNET_H
  17 +#define MBED_ETHERNET_H
  18 +
  19 +#include "platform.h"
  20 +
  21 +#if DEVICE_ETHERNET
  22 +
  23 +namespace mbed {
  24 +
  25 +/** An ethernet interface, to use with the ethernet pins.
  26 + *
  27 + * Example:
  28 + * @code
  29 + * // Read destination and source from every ethernet packet
  30 + *
  31 + * #include "mbed.h"
  32 + *
  33 + * Ethernet eth;
  34 + *
  35 + * int main() {
  36 + * char buf[0x600];
  37 + *
  38 + * while(1) {
  39 + * int size = eth.receive();
  40 + * if(size > 0) {
  41 + * eth.read(buf, size);
  42 + * printf("Destination: %02X:%02X:%02X:%02X:%02X:%02X\n",
  43 + * buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
  44 + * printf("Source: %02X:%02X:%02X:%02X:%02X:%02X\n",
  45 + * buf[6], buf[7], buf[8], buf[9], buf[10], buf[11]);
  46 + * }
  47 + *
  48 + * wait(1);
  49 + * }
  50 + * }
  51 + * @endcode
  52 + */
  53 +class Ethernet {
  54 +
  55 +public:
  56 +
  57 + /** Initialise the ethernet interface.
  58 + */
  59 + Ethernet();
  60 +
  61 + /** Powers the hardware down.
  62 + */
  63 + virtual ~Ethernet();
  64 +
  65 + enum Mode {
  66 + AutoNegotiate,
  67 + HalfDuplex10,
  68 + FullDuplex10,
  69 + HalfDuplex100,
  70 + FullDuplex100
  71 + };
  72 +
  73 + /** Writes into an outgoing ethernet packet.
  74 + *
  75 + * It will append size bytes of data to the previously written bytes.
  76 + *
  77 + * @param data An array to write.
  78 + * @param size The size of data.
  79 + *
  80 + * @returns
  81 + * The number of written bytes.
  82 + */
  83 + int write(const char *data, int size);
  84 +
  85 + /** Send an outgoing ethernet packet.
  86 + *
  87 + * After filling in the data in an ethernet packet it must be send.
  88 + * Send will provide a new packet to write to.
  89 + *
  90 + * @returns
  91 + * 0 if the sending was failed,
  92 + * or the size of the packet successfully sent.
  93 + */
  94 + int send();
  95 +
  96 + /** Recevies an arrived ethernet packet.
  97 + *
  98 + * Receiving an ethernet packet will drop the last received ethernet packet
  99 + * and make a new ethernet packet ready to read.
  100 + * If no ethernet packet is arrived it will return 0.
  101 + *
  102 + * @returns
  103 + * 0 if no ethernet packet is arrived,
  104 + * or the size of the arrived packet.
  105 + */
  106 + int receive();
  107 +
  108 + /** Read from an recevied ethernet packet.
  109 + *
  110 + * After receive returnd a number bigger than 0it is
  111 + * possible to read bytes from this packet.
  112 + * Read will write up to size bytes into data.
  113 + *
  114 + * It is possible to use read multible times.
  115 + * Each time read will start reading after the last read byte before.
  116 + *
  117 + * @returns
  118 + * The number of byte read.
  119 + */
  120 + int read(char *data, int size);
  121 +
  122 + /** Gives the ethernet address of the mbed.
  123 + *
  124 + * @param mac Must be a pointer to a 6 byte char array to copy the ethernet address in.
  125 + */
  126 + void address(char *mac);
  127 +
  128 + /** Returns if an ethernet link is pressent or not. It takes a wile after Ethernet initializion to show up.
  129 + *
  130 + * @returns
  131 + * 0 if no ethernet link is pressent,
  132 + * 1 if an ethernet link is pressent.
  133 + *
  134 + * Example:
  135 + * @code
  136 + * // Using the Ethernet link function
  137 + * #include "mbed.h"
  138 + *
  139 + * Ethernet eth;
  140 + *
  141 + * int main() {
  142 + * wait(1); // Needed after startup.
  143 + * if (eth.link()) {
  144 + * printf("online\n");
  145 + * } else {
  146 + * printf("offline\n");
  147 + * }
  148 + * }
  149 + * @endcode
  150 + */
  151 + int link();
  152 +
  153 + /** Sets the speed and duplex parameters of an ethernet link
  154 + *
  155 + * - AutoNegotiate Auto negotiate speed and duplex
  156 + * - HalfDuplex10 10 Mbit, half duplex
  157 + * - FullDuplex10 10 Mbit, full duplex
  158 + * - HalfDuplex100 100 Mbit, half duplex
  159 + * - FullDuplex100 100 Mbit, full duplex
  160 + *
  161 + * @param mode the speed and duplex mode to set the link to:
  162 + */
  163 + void set_link(Mode mode);
  164 +};
  165 +
  166 +} // namespace mbed
  167 +
  168 +#endif
  169 +
  170 +#endif
... ...
mbed/FileBase.h 0 → 100644
... ... @@ -0,0 +1,80 @@
  1 +/* mbed Microcontroller Library
  2 + * Copyright (c) 2006-2013 ARM Limited
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +#ifndef MBED_FILEBASE_H
  17 +#define MBED_FILEBASE_H
  18 +
  19 +typedef int FILEHANDLE;
  20 +
  21 +#include <stdio.h>
  22 +
  23 +#if defined(__ARMCC_VERSION) || defined(__ICCARM__)
  24 +# define O_RDONLY 0
  25 +# define O_WRONLY 1
  26 +# define O_RDWR 2
  27 +# define O_CREAT 0x0200
  28 +# define O_TRUNC 0x0400
  29 +# define O_APPEND 0x0008
  30 +
  31 +# define NAME_MAX 255
  32 +
  33 +typedef int mode_t;
  34 +typedef int ssize_t;
  35 +typedef long off_t;
  36 +
  37 +#else
  38 +# include <sys/fcntl.h>
  39 +# include <sys/types.h>
  40 +# include <sys/syslimits.h>
  41 +#endif
  42 +
  43 +#include "platform.h"
  44 +
  45 +namespace mbed {
  46 +
  47 +typedef enum {
  48 + FilePathType,
  49 + FileSystemPathType
  50 +} PathType;
  51 +
  52 +class FileBase {
  53 +public:
  54 + FileBase(const char *name, PathType t);
  55 +
  56 + virtual ~FileBase();
  57 +
  58 + const char* getName(void);
  59 + PathType getPathType(void);
  60 +
  61 + static FileBase *lookup(const char *name, unsigned int len);
  62 +
  63 + static FileBase *get(int n);
  64 +
  65 +protected:
  66 + static FileBase *_head;
  67 +
  68 + FileBase *_next;
  69 + const char *_name;
  70 + PathType _path_type;
  71 +
  72 + /* disallow copy constructor and assignment operators */
  73 +private:
  74 + FileBase(const FileBase&);
  75 + FileBase & operator = (const FileBase&);
  76 +};
  77 +
  78 +} // namespace mbed
  79 +
  80 +#endif
... ...
mbed/FileHandle.h 0 → 100644
... ... @@ -0,0 +1,119 @@
  1 +/* mbed Microcontroller Library
  2 + * Copyright (c) 2006-2013 ARM Limited
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +#ifndef MBED_FILEHANDLE_H
  17 +#define MBED_FILEHANDLE_H
  18 +
  19 +typedef int FILEHANDLE;
  20 +
  21 +#include <stdio.h>
  22 +
  23 +#if defined(__ARMCC_VERSION) || defined(__ICCARM__)
  24 +typedef int ssize_t;
  25 +typedef long off_t;
  26 +
  27 +#else
  28 +# include <sys/types.h>
  29 +#endif
  30 +
  31 +namespace mbed {
  32 +
  33 +/** An OO equivalent of the internal FILEHANDLE variable
  34 + * and associated _sys_* functions.
  35 + *
  36 + * FileHandle is an abstract class, needing at least sys_write and
  37 + * sys_read to be implmented for a simple interactive device.
  38 + *
  39 + * No one ever directly tals to/instanciates a FileHandle - it gets
  40 + * created by FileSystem, and wrapped up by stdio.
  41 + */
  42 +class FileHandle {
  43 +
  44 +public:
  45 + /** Write the contents of a buffer to the file
  46 + *
  47 + * @param buffer the buffer to write from
  48 + * @param length the number of characters to write
  49 + *
  50 + * @returns
  51 + * The number of characters written (possibly 0) on success, -1 on error.
  52 + */
  53 + virtual ssize_t write(const void* buffer, size_t length) = 0;
  54 +
  55 + /** Close the file
  56 + *
  57 + * @returns
  58 + * Zero on success, -1 on error.
  59 + */
  60 + virtual int close() = 0;
  61 +
  62 + /** Function read
  63 + * Reads the contents of the file into a buffer
  64 + *
  65 + * @param buffer the buffer to read in to
  66 + * @param length the number of characters to read
  67 + *
  68 + * @returns
  69 + * The number of characters read (zero at end of file) on success, -1 on error.
  70 + */
  71 + virtual ssize_t read(void* buffer, size_t length) = 0;
  72 +
  73 + /** Check if the handle is for a interactive terminal device.
  74 + * If so, line buffered behaviour is used by default
  75 + *
  76 + * @returns
  77 + * 1 if it is a terminal,
  78 + * 0 otherwise
  79 + */
  80 + virtual int isatty() = 0;
  81 +
  82 + /** Move the file position to a given offset from a given location.
  83 + *
  84 + * @param offset The offset from whence to move to
  85 + * @param whence SEEK_SET for the start of the file, SEEK_CUR for the
  86 + * current file position, or SEEK_END for the end of the file.
  87 + *
  88 + * @returns
  89 + * new file position on success,
  90 + * -1 on failure or unsupported
  91 + */
  92 + virtual off_t lseek(off_t offset, int whence) = 0;
  93 +
  94 + /** Flush any buffers associated with the FileHandle, ensuring it
  95 + * is up to date on disk
  96 + *
  97 + * @returns
  98 + * 0 on success or un-needed,
  99 + * -1 on error
  100 + */
  101 + virtual int fsync() = 0;
  102 +
  103 + virtual off_t flen() {
  104 + /* remember our current position */
  105 + off_t pos = lseek(0, SEEK_CUR);
  106 + if(pos == -1) return -1;
  107 + /* seek to the end to get the file length */
  108 + off_t res = lseek(0, SEEK_END);
  109 + /* return to our old position */
  110 + lseek(pos, SEEK_SET);
  111 + return res;
  112 + }
  113 +
  114 + virtual ~FileHandle();
  115 +};
  116 +
  117 +} // namespace mbed
  118 +
  119 +#endif
... ...
mbed/FileLike.h 0 → 100644
... ... @@ -0,0 +1,44 @@
  1 +/* mbed Microcontroller Library
  2 + * Copyright (c) 2006-2013 ARM Limited
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +#ifndef MBED_FILELIKE_H
  17 +#define MBED_FILELIKE_H
  18 +
  19 +#include "FileBase.h"
  20 +#include "FileHandle.h"
  21 +
  22 +namespace mbed {
  23 +
  24 +/* Class FileLike
  25 + * A file-like object is one that can be opened with fopen by
  26 + * fopen("/name", mode). It is intersection of the classes Base and
  27 + * FileHandle.
  28 + */
  29 +class FileLike : public FileHandle, public FileBase {
  30 +
  31 +public:
  32 + /* Constructor FileLike
  33 + *
  34 + * Variables
  35 + * name - The name to use to open the file.
  36 + */
  37 + FileLike(const char *name);
  38 +
  39 + virtual ~FileLike();
  40 +};
  41 +
  42 +} // namespace mbed
  43 +
  44 +#endif
... ...
mbed/FilePath.h 0 → 100644
... ... @@ -0,0 +1,46 @@
  1 +/* mbed Microcontroller Library
  2 + * Copyright (c) 2006-2013 ARM Limited
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +#ifndef MBED_FILEPATH_H
  17 +#define MBED_FILEPATH_H
  18 +
  19 +#include "platform.h"
  20 +
  21 +#include "FileSystemLike.h"
  22 +#include "FileLike.h"
  23 +
  24 +namespace mbed {
  25 +
  26 +class FilePath {
  27 +public:
  28 + FilePath(const char* file_path);
  29 +
  30 + const char* fileName(void);
  31 +
  32 + bool isFileSystem(void);
  33 + FileSystemLike* fileSystem(void);
  34 +
  35 + bool isFile(void);
  36 + FileLike* file(void);
  37 + bool exists(void);
  38 +
  39 +private:
  40 + const char* file_name;
  41 + FileBase* fb;
  42 +};
  43 +
  44 +} // namespace mbed
  45 +
  46 +#endif
... ...
mbed/FileSystemLike.h 0 → 100644
... ... @@ -0,0 +1,104 @@
  1 +/* mbed Microcontroller Library
  2 + * Copyright (c) 2006-2013 ARM Limited
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +#ifndef MBED_FILESYSTEMLIKE_H
  17 +#define MBED_FILESYSTEMLIKE_H
  18 +
  19 +#include "platform.h"
  20 +
  21 +#include "FileBase.h"
  22 +#include "FileHandle.h"
  23 +#include "DirHandle.h"
  24 +
  25 +namespace mbed {
  26 +
  27 +/** A filesystem-like object is one that can be used to open files
  28 + * though it by fopen("/name/filename", mode)
  29 + *
  30 + * Implementations must define at least open (the default definitions
  31 + * of the rest of the functions just return error values).
  32 + */
  33 +class FileSystemLike : public FileBase {
  34 +
  35 +public:
  36 + /** FileSystemLike constructor
  37 + *
  38 + * @param name The name to use for the filesystem.
  39 + */
  40 + FileSystemLike(const char *name);
  41 +
  42 + virtual ~FileSystemLike();
  43 +
  44 + static DirHandle *opendir();
  45 + friend class BaseDirHandle;
  46 +
  47 + /** Opens a file from the filesystem
  48 + *
  49 + * @param filename The name of the file to open.
  50 + * @param flags One of O_RDONLY, O_WRONLY, or O_RDWR, OR'd with
  51 + * zero or more of O_CREAT, O_TRUNC, or O_APPEND.
  52 + *
  53 + * @returns
  54 + * A pointer to a FileHandle object representing the
  55 + * file on success, or NULL on failure.
  56 + */
  57 + virtual FileHandle *open(const char *filename, int flags) = 0;
  58 +
  59 + /** Remove a file from the filesystem.
  60 + *
  61 + * @param filename the name of the file to remove.
  62 + * @param returns 0 on success, -1 on failure.
  63 + */
  64 + virtual int remove(const char *filename) { return -1; };
  65 +
  66 + /** Rename a file in the filesystem.
  67 + *
  68 + * @param oldname the name of the file to rename.
  69 + * @param newname the name to rename it to.
  70 + *
  71 + * @returns
  72 + * 0 on success,
  73 + * -1 on failure.
  74 + */
  75 + virtual int rename(const char *oldname, const char *newname) { return -1; };
  76 +
  77 + /** Opens a directory in the filesystem and returns a DirHandle
  78 + * representing the directory stream.
  79 + *
  80 + * @param name The name of the directory to open.
  81 + *
  82 + * @returns
  83 + * A DirHandle representing the directory stream, or
  84 + * NULL on failure.
  85 + */
  86 + virtual DirHandle *opendir(const char *name) { return NULL; };
  87 +
  88 + /** Creates a directory in the filesystem.
  89 + *
  90 + * @param name The name of the directory to create.
  91 + * @param mode The permissions to create the directory with.
  92 + *
  93 + * @returns
  94 + * 0 on success,
  95 + * -1 on failure.
  96 + */
  97 + virtual int mkdir(const char *name, mode_t mode) { return -1; }
  98 +
  99 + // TODO other filesystem functions (mkdir, rm, rn, ls etc)
  100 +};
  101 +
  102 +} // namespace mbed
  103 +
  104 +#endif
... ...
mbed/FunctionPointer.h 0 → 100644
... ... @@ -0,0 +1,202 @@
  1 +/* mbed Microcontroller Library
  2 + * Copyright (c) 2006-2015 ARM Limited
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +#ifndef MBED_FUNCTIONPOINTER_H
  17 +#define MBED_FUNCTIONPOINTER_H
  18 +
  19 +#include <string.h>
  20 +#include <stdint.h>
  21 +
  22 +namespace mbed {
  23 +
  24 +/* If we had variaditic templates, this wouldn't be a problem, but until C++11 is enabled, we are stuck with multiple classes... */
  25 +
  26 +/** A class for storing and calling a pointer to a static or member function
  27 + */
  28 +template <typename R, typename A1>
  29 +class FunctionPointerArg1{
  30 +public:
  31 + /** Create a FunctionPointer, attaching a static function
  32 + *
  33 + * @param function The static function to attach (default is none)
  34 + */
  35 + FunctionPointerArg1(R (*function)(A1) = 0) {
  36 + attach(function);
  37 + }
  38 +
  39 + /** Create a FunctionPointer, attaching a member function
  40 + *
  41 + * @param object The object pointer to invoke the member function on (i.e. the this pointer)
  42 + * @param function The address of the member function to attach
  43 + */
  44 + template<typename T>
  45 + FunctionPointerArg1(T *object, R (T::*member)(A1)) {
  46 + attach(object, member);
  47 + }
  48 +
  49 + /** Attach a static function
  50 + *
  51 + * @param function The static function to attach (default is none)
  52 + */
  53 + void attach(R (*function)(A1)) {
  54 + _p.function = function;
  55 + _membercaller = 0;
  56 + }
  57 +
  58 + /** Attach a member function
  59 + *
  60 + * @param object The object pointer to invoke the member function on (i.e. the this pointer)
  61 + * @param function The address of the member function to attach
  62 + */
  63 + template<typename T>
  64 + void attach(T *object, R (T::*member)(A1)) {
  65 + _p.object = static_cast<void*>(object);
  66 + *reinterpret_cast<R (T::**)(A1)>(_member) = member;
  67 + _membercaller = &FunctionPointerArg1::membercaller<T>;
  68 + }
  69 +
  70 + /** Call the attached static or member function
  71 + */
  72 + R call(A1 a) {
  73 + if (_membercaller == 0 && _p.function) {
  74 + return _p.function(a);
  75 + } else if (_membercaller && _p.object) {
  76 + return _membercaller(_p.object, _member, a);
  77 + }
  78 + return (R)0;
  79 + }
  80 +
  81 + /** Get registered static function
  82 + */
  83 + R(*get_function(A1))() {
  84 + return _membercaller ? (R(*)(A1))0 : (R(*)(A1))_p.function;
  85 + }
  86 +
  87 +#ifdef MBED_OPERATORS
  88 + R operator ()(A1 a) {
  89 + return call(a);
  90 + }
  91 + operator bool(void) const {
  92 + return (_membercaller != NULL ? _p.object : (void*)_p.function) != NULL;
  93 + }
  94 +#endif
  95 +private:
  96 + template<typename T>
  97 + static R membercaller(void *object, uintptr_t *member, A1 a) {
  98 + T* o = static_cast<T*>(object);
  99 + R (T::**m)(A1) = reinterpret_cast<R (T::**)(A1)>(member);
  100 + return (o->**m)(a);
  101 + }
  102 +
  103 + union {
  104 + R (*function)(A1); // static function pointer
  105 + void *object; // object this pointer
  106 + } _p;
  107 + uintptr_t _member[4]; // aligned raw member function pointer storage - converted back by registered _membercaller
  108 + R (*_membercaller)(void*, uintptr_t*, A1); // registered membercaller function to convert back and call _m.member on _object
  109 +};
  110 +
  111 +/** A class for storing and calling a pointer to a static or member function (R ()(void))
  112 + */
  113 +template <typename R>
  114 +class FunctionPointerArg1<R, void>{
  115 +public:
  116 + /** Create a FunctionPointer, attaching a static function
  117 + *
  118 + * @param function The static function to attach (default is none)
  119 + */
  120 + FunctionPointerArg1(R (*function)(void) = 0) {
  121 + attach(function);
  122 + }
  123 +
  124 + /** Create a FunctionPointer, attaching a member function
  125 + *
  126 + * @param object The object pointer to invoke the member function on (i.e. the this pointer)
  127 + * @param function The address of the void member function to attach
  128 + */
  129 + template<typename T>
  130 + FunctionPointerArg1(T *object, R (T::*member)(void)) {
  131 + attach(object, member);
  132 + }
  133 +
  134 + /** Attach a static function
  135 + *
  136 + * @param function The void static function to attach (default is none)
  137 + */
  138 + void attach(R (*function)(void)) {
  139 + _p.function = function;
  140 + _membercaller = 0;
  141 + }
  142 +
  143 + /** Attach a member function
  144 + *
  145 + * @param object The object pointer to invoke the member function on (i.e. the this pointer)
  146 + * @param function The address of the void member function to attach
  147 + */
  148 + template<typename T>
  149 + void attach(T *object, R (T::*member)(void)) {
  150 + _p.object = static_cast<void*>(object);
  151 + *reinterpret_cast<R (T::**)(void)>(_member) = member;
  152 + _membercaller = &FunctionPointerArg1::membercaller<T>;
  153 + }
  154 +
  155 + /** Call the attached static or member function
  156 + */
  157 + R call(){
  158 + if (_membercaller == 0 && _p.function) {
  159 + return _p.function();
  160 + } else if (_membercaller && _p.object) {
  161 + return _membercaller(_p.object, _member);
  162 + }
  163 + return (R)0;
  164 + }
  165 +
  166 + /** Get registered static function
  167 + */
  168 + R(*get_function())() {
  169 + return _membercaller ? (R(*)())0 : (R(*)())_p.function;
  170 + }
  171 +
  172 +#ifdef MBED_OPERATORS
  173 + R operator ()(void) {
  174 + return call();
  175 + }
  176 + operator bool(void) const {
  177 + return (_membercaller != NULL ? _p.object : (void*)_p.function) != NULL;
  178 + }
  179 +#endif
  180 +
  181 +private:
  182 + template<typename T>
  183 + static R membercaller(void *object, uintptr_t *member) {
  184 + T* o = static_cast<T*>(object);
  185 + R (T::**m)(void) = reinterpret_cast<R (T::**)(void)>(member);
  186 + return (o->**m)();
  187 + }
  188 +
  189 + union {
  190 + R (*function)(void); // static function pointer
  191 + void *object; // object this pointer
  192 + } _p;
  193 + uintptr_t _member[4]; // aligned raw member function pointer storage - converted back by registered _membercaller
  194 + R (*_membercaller)(void*, uintptr_t*); // registered membercaller function to convert back and call _m.member on _object
  195 +};
  196 +
  197 +typedef FunctionPointerArg1<void, void> FunctionPointer;
  198 +typedef FunctionPointerArg1<void, int> event_callback_t;
  199 +
  200 +} // namespace mbed
  201 +
  202 +#endif
... ...
mbed/I2C.h 0 → 100644
... ... @@ -0,0 +1,176 @@
  1 +/* mbed Microcontroller Library
  2 + * Copyright (c) 2006-2015 ARM Limited
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +#ifndef MBED_I2C_H
  17 +#define MBED_I2C_H
  18 +
  19 +#include "platform.h"
  20 +
  21 +#if DEVICE_I2C
  22 +
  23 +#include "i2c_api.h"
  24 +
  25 +#if DEVICE_I2C_ASYNCH
  26 +#include "CThunk.h"
  27 +#include "dma_api.h"
  28 +#include "FunctionPointer.h"
  29 +#endif
  30 +
  31 +namespace mbed {
  32 +
  33 +/** An I2C Master, used for communicating with I2C slave devices
  34 + *
  35 + * Example:
  36 + * @code
  37 + * // Read from I2C slave at address 0x62
  38 + *
  39 + * #include "mbed.h"
  40 + *
  41 + * I2C i2c(p28, p27);
  42 + *
  43 + * int main() {
  44 + * int address = 0x62;
  45 + * char data[2];
  46 + * i2c.read(address, data, 2);
  47 + * }
  48 + * @endcode
  49 + */
  50 +class I2C {
  51 +
  52 +public:
  53 + enum RxStatus {
  54 + NoData,
  55 + MasterGeneralCall,
  56 + MasterWrite,
  57 + MasterRead
  58 + };
  59 +
  60 + enum Acknowledge {
  61 + NoACK = 0,
  62 + ACK = 1
  63 + };
  64 +
  65 + /** Create an I2C Master interface, connected to the specified pins
  66 + *
  67 + * @param sda I2C data line pin
  68 + * @param scl I2C clock line pin
  69 + */
  70 + I2C(PinName sda, PinName scl);
  71 +
  72 + /** Set the frequency of the I2C interface
  73 + *
  74 + * @param hz The bus frequency in hertz
  75 + */
  76 + void frequency(int hz);
  77 +
  78 + /** Read from an I2C slave
  79 + *
  80 + * Performs a complete read transaction. The bottom bit of
  81 + * the address is forced to 1 to indicate a read.
  82 + *
  83 + * @param address 8-bit I2C slave address [ addr | 1 ]
  84 + * @param data Pointer to the byte-array to read data in to
  85 + * @param length Number of bytes to read
  86 + * @param repeated Repeated start, true - don't send stop at end
  87 + *
  88 + * @returns
  89 + * 0 on success (ack),
  90 + * non-0 on failure (nack)
  91 + */
  92 + int read(int address, char *data, int length, bool repeated = false);
  93 +
  94 + /** Read a single byte from the I2C bus
  95 + *
  96 + * @param ack indicates if the byte is to be acknowledged (1 = acknowledge)
  97 + *
  98 + * @returns
  99 + * the byte read
  100 + */
  101 + int read(int ack);
  102 +
  103 + /** Write to an I2C slave
  104 + *
  105 + * Performs a complete write transaction. The bottom bit of
  106 + * the address is forced to 0 to indicate a write.
  107 + *
  108 + * @param address 8-bit I2C slave address [ addr | 0 ]
  109 + * @param data Pointer to the byte-array data to send
  110 + * @param length Number of bytes to send
  111 + * @param repeated Repeated start, true - do not send stop at end
  112 + *
  113 + * @returns
  114 + * 0 on success (ack),
  115 + * non-0 on failure (nack)
  116 + */
  117 + int write(int address, const char *data, int length, bool repeated = false);
  118 +
  119 + /** Write single byte out on the I2C bus
  120 + *
  121 + * @param data data to write out on bus
  122 + *
  123 + * @returns
  124 + * '1' if an ACK was received,
  125 + * '0' otherwise
  126 + */
  127 + int write(int data);
  128 +
  129 + /** Creates a start condition on the I2C bus
  130 + */
  131 +
  132 + void start(void);
  133 +
  134 + /** Creates a stop condition on the I2C bus
  135 + */
  136 + void stop(void);
  137 +
  138 +#if DEVICE_I2C_ASYNCH
  139 +
  140 + /** Start non-blocking I2C transfer.
  141 + *
  142 + * @param address 8/10 bit I2c slave address
  143 + * @param tx_buffer The TX buffer with data to be transfered
  144 + * @param tx_length The length of TX buffer in bytes
  145 + * @param rx_buffer The RX buffer which is used for received data
  146 + * @param rx_length The length of RX buffer in bytes
  147 + * @param event The logical OR of events to modify
  148 + * @param callback The event callback function
  149 + * @param repeated Repeated start, true - do not send stop at end
  150 + * @return Zero if the transfer has started, or -1 if I2C peripheral is busy
  151 + */
  152 + int transfer(int address, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length, const event_callback_t& callback, int event = I2C_EVENT_TRANSFER_COMPLETE, bool repeated = false);
  153 +
  154 + /** Abort the on-going I2C transfer
  155 + */
  156 + void abort_transfer();
  157 +protected:
  158 + void irq_handler_asynch(void);
  159 + event_callback_t _callback;
  160 + CThunk<I2C> _irq;
  161 + DMAUsage _usage;
  162 +#endif
  163 +
  164 +protected:
  165 + void aquire();
  166 +
  167 + i2c_t _i2c;
  168 + static I2C *_owner;
  169 + int _hz;
  170 +};
  171 +
  172 +} // namespace mbed
  173 +
  174 +#endif
  175 +
  176 +#endif
... ...
mbed/I2CSlave.h 0 → 100644
... ... @@ -0,0 +1,154 @@
  1 +/* mbed Microcontroller Library
  2 + * Copyright (c) 2006-2013 ARM Limited
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +#ifndef MBED_I2C_SLAVE_H
  17 +#define MBED_I2C_SLAVE_H
  18 +
  19 +#include "platform.h"
  20 +
  21 +#if DEVICE_I2CSLAVE
  22 +
  23 +#include "i2c_api.h"
  24 +
  25 +namespace mbed {
  26 +
  27 +/** An I2C Slave, used for communicating with an I2C Master device
  28 + *
  29 + * Example:
  30 + * @code
  31 + * // Simple I2C responder
  32 + * #include <mbed.h>
  33 + *
  34 + * I2CSlave slave(p9, p10);
  35 + *
  36 + * int main() {
  37 + * char buf[10];
  38 + * char msg[] = "Slave!";
  39 + *
  40 + * slave.address(0xA0);
  41 + * while (1) {
  42 + * int i = slave.receive();
  43 + * switch (i) {
  44 + * case I2CSlave::ReadAddressed:
  45 + * slave.write(msg, strlen(msg) + 1); // Includes null char
  46 + * break;
  47 + * case I2CSlave::WriteGeneral:
  48 + * slave.read(buf, 10);
  49 + * printf("Read G: %s\n", buf);
  50 + * break;
  51 + * case I2CSlave::WriteAddressed:
  52 + * slave.read(buf, 10);
  53 + * printf("Read A: %s\n", buf);
  54 + * break;
  55 + * }
  56 + * for(int i = 0; i < 10; i++) buf[i] = 0; // Clear buffer
  57 + * }
  58 + * }
  59 + * @endcode
  60 + */
  61 +class I2CSlave {
  62 +
  63 +public:
  64 + enum RxStatus {
  65 + NoData = 0,
  66 + ReadAddressed = 1,
  67 + WriteGeneral = 2,
  68 + WriteAddressed = 3
  69 + };
  70 +
  71 + /** Create an I2C Slave interface, connected to the specified pins.
  72 + *
  73 + * @param sda I2C data line pin
  74 + * @param scl I2C clock line pin
  75 + */
  76 + I2CSlave(PinName sda, PinName scl);
  77 +
  78 + /** Set the frequency of the I2C interface
  79 + *
  80 + * @param hz The bus frequency in hertz
  81 + */
  82 + void frequency(int hz);
  83 +
  84 + /** Checks to see if this I2C Slave has been addressed.
  85 + *
  86 + * @returns
  87 + * A status indicating if the device has been addressed, and how
  88 + * - NoData - the slave has not been addressed
  89 + * - ReadAddressed - the master has requested a read from this slave
  90 + * - WriteAddressed - the master is writing to this slave
  91 + * - WriteGeneral - the master is writing to all slave
  92 + */
  93 + int receive(void);
  94 +
  95 + /** Read from an I2C master.
  96 + *
  97 + * @param data pointer to the byte array to read data in to
  98 + * @param length maximum number of bytes to read
  99 + *
  100 + * @returns
  101 + * 0 on success,
  102 + * non-0 otherwise
  103 + */
  104 + int read(char *data, int length);
  105 +
  106 + /** Read a single byte from an I2C master.
  107 + *
  108 + * @returns
  109 + * the byte read
  110 + */
  111 + int read(void);
  112 +
  113 + /** Write to an I2C master.
  114 + *
  115 + * @param data pointer to the byte array to be transmitted
  116 + * @param length the number of bytes to transmite
  117 + *
  118 + * @returns
  119 + * 0 on success,
  120 + * non-0 otherwise
  121 + */
  122 + int write(const char *data, int length);
  123 +
  124 + /** Write a single byte to an I2C master.
  125 + *
  126 + * @data the byte to write
  127 + *
  128 + * @returns
  129 + * '1' if an ACK was received,
  130 + * '0' otherwise
  131 + */
  132 + int write(int data);
  133 +
  134 + /** Sets the I2C slave address.
  135 + *
  136 + * @param address The address to set for the slave (ignoring the least
  137 + * signifcant bit). If set to 0, the slave will only respond to the
  138 + * general call address.
  139 + */
  140 + void address(int address);
  141 +
  142 + /** Reset the I2C slave back into the known ready receiving state.
  143 + */
  144 + void stop(void);
  145 +
  146 +protected:
  147 + i2c_t _i2c;
  148 +};
  149 +
  150 +} // namespace mbed
  151 +
  152 +#endif
  153 +
  154 +#endif
... ...
mbed/InterruptIn.h 0 → 100644
... ... @@ -0,0 +1,135 @@
  1 +/* mbed Microcontroller Library
  2 + * Copyright (c) 2006-2013 ARM Limited
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +#ifndef MBED_INTERRUPTIN_H
  17 +#define MBED_INTERRUPTIN_H
  18 +
  19 +#include "platform.h"
  20 +
  21 +#if DEVICE_INTERRUPTIN
  22 +
  23 +#include "gpio_api.h"
  24 +#include "gpio_irq_api.h"
  25 +#include "FunctionPointer.h"
  26 +
  27 +namespace mbed {
  28 +
  29 +/** A digital interrupt input, used to call a function on a rising or falling edge
  30 + *
  31 + * Example:
  32 + * @code
  33 + * // Flash an LED while waiting for events
  34 + *
  35 + * #include "mbed.h"
  36 + *
  37 + * InterruptIn event(p16);
  38 + * DigitalOut led(LED1);
  39 + *
  40 + * void trigger() {
  41 + * printf("triggered!\n");
  42 + * }
  43 + *
  44 + * int main() {
  45 + * event.rise(&trigger);
  46 + * while(1) {
  47 + * led = !led;
  48 + * wait(0.25);
  49 + * }
  50 + * }
  51 + * @endcode
  52 + */
  53 +class InterruptIn {
  54 +
  55 +public:
  56 +
  57 + /** Create an InterruptIn connected to the specified pin
  58 + *
  59 + * @param pin InterruptIn pin to connect to
  60 + * @param name (optional) A string to identify the object
  61 + */
  62 + InterruptIn(PinName pin);
  63 + virtual ~InterruptIn();
  64 +
  65 + int read();
  66 +#ifdef MBED_OPERATORS
  67 + operator int();
  68 +
  69 +#endif
  70 +
  71 + /** Attach a function to call when a rising edge occurs on the input
  72 + *
  73 + * @param fptr A pointer to a void function, or 0 to set as none
  74 + */
  75 + void rise(void (*fptr)(void));
  76 +
  77 + /** Attach a member function to call when a rising edge occurs on the input
  78 + *
  79 + * @param tptr pointer to the object to call the member function on
  80 + * @param mptr pointer to the member function to be called
  81 + */
  82 + template<typename T>
  83 + void rise(T* tptr, void (T::*mptr)(void)) {
  84 + _rise.attach(tptr, mptr);
  85 + gpio_irq_set(&gpio_irq, IRQ_RISE, 1);
  86 + }
  87 +
  88 + /** Attach a function to call when a falling edge occurs on the input
  89 + *
  90 + * @param fptr A pointer to a void function, or 0 to set as none
  91 + */
  92 + void fall(void (*fptr)(void));
  93 +
  94 + /** Attach a member function to call when a falling edge occurs on the input
  95 + *
  96 + * @param tptr pointer to the object to call the member function on
  97 + * @param mptr pointer to the member function to be called
  98 + */
  99 + template<typename T>
  100 + void fall(T* tptr, void (T::*mptr)(void)) {
  101 + _fall.attach(tptr, mptr);
  102 + gpio_irq_set(&gpio_irq, IRQ_FALL, 1);
  103 + }
  104 +
  105 + /** Set the input pin mode
  106 + *
  107 + * @param mode PullUp, PullDown, PullNone
  108 + */
  109 + void mode(PinMode pull);
  110 +
  111 + /** Enable IRQ. This method depends on hw implementation, might enable one
  112 + * port interrupts. For further information, check gpio_irq_enable().
  113 + */
  114 + void enable_irq();
  115 +
  116 + /** Disable IRQ. This method depends on hw implementation, might disable one
  117 + * port interrupts. For further information, check gpio_irq_disable().
  118 + */
  119 + void disable_irq();
  120 +
  121 + static void _irq_handler(uint32_t id, gpio_irq_event event);
  122 +
  123 +protected:
  124 + gpio_t gpio;
  125 + gpio_irq_t gpio_irq;
  126 +
  127 + FunctionPointer _rise;
  128 + FunctionPointer _fall;
  129 +};
  130 +
  131 +} // namespace mbed
  132 +
  133 +#endif
  134 +
  135 +#endif
... ...
mbed/InterruptManager.h 0 → 100644
... ... @@ -0,0 +1,143 @@
  1 +#ifndef MBED_INTERRUPTMANAGER_H
  2 +#define MBED_INTERRUPTMANAGER_H
  3 +
  4 +#include "cmsis.h"
  5 +#include "CallChain.h"
  6 +#include <string.h>
  7 +
  8 +namespace mbed {
  9 +
  10 +/** Use this singleton if you need to chain interrupt handlers.
  11 + *
  12 + * Example (for LPC1768):
  13 + * @code
  14 + * #include "InterruptManager.h"
  15 + * #include "mbed.h"
  16 + *
  17 + * Ticker flipper;
  18 + * DigitalOut led1(LED1);
  19 + * DigitalOut led2(LED2);
  20 + *
  21 + * void flip(void) {
  22 + * led1 = !led1;
  23 + * }
  24 + *
  25 + * void handler(void) {
  26 + * led2 = !led1;
  27 + * }
  28 + *
  29 + * int main() {
  30 + * led1 = led2 = 0;
  31 + * flipper.attach(&flip, 1.0);
  32 + * InterruptManager::get()->add_handler(handler, TIMER3_IRQn);
  33 + * }
  34 + * @endcode
  35 + */
  36 +class InterruptManager {
  37 +public:
  38 + /** Return the only instance of this class
  39 + */
  40 + static InterruptManager* get();
  41 +
  42 + /** Destroy the current instance of the interrupt manager
  43 + */
  44 + static void destroy();
  45 +
  46 + /** Add a handler for an interrupt at the end of the handler list
  47 + *
  48 + * @param function the handler to add
  49 + * @param irq interrupt number
  50 + *
  51 + * @returns
  52 + * The function object created for 'function'
  53 + */
  54 + pFunctionPointer_t add_handler(void (*function)(void), IRQn_Type irq) {
  55 + return add_common(function, irq);
  56 + }
  57 +
  58 + /** Add a handler for an interrupt at the beginning of the handler list
  59 + *
  60 + * @param function the handler to add
  61 + * @param irq interrupt number
  62 + *
  63 + * @returns
  64 + * The function object created for 'function'
  65 + */
  66 + pFunctionPointer_t add_handler_front(void (*function)(void), IRQn_Type irq) {
  67 + return add_common(function, irq, true);
  68 + }
  69 +
  70 + /** Add a handler for an interrupt at the end of the handler list
  71 + *
  72 + * @param tptr pointer to the object that has the handler function
  73 + * @param mptr pointer to the actual handler function
  74 + * @param irq interrupt number
  75 + *
  76 + * @returns
  77 + * The function object created for 'tptr' and 'mptr'
  78 + */
  79 + template<typename T>
  80 + pFunctionPointer_t add_handler(T* tptr, void (T::*mptr)(void), IRQn_Type irq) {
  81 + return add_common(tptr, mptr, irq);
  82 + }
  83 +
  84 + /** Add a handler for an interrupt at the beginning of the handler list
  85 + *
  86 + * @param tptr pointer to the object that has the handler function
  87 + * @param mptr pointer to the actual handler function
  88 + * @param irq interrupt number
  89 + *
  90 + * @returns
  91 + * The function object created for 'tptr' and 'mptr'
  92 + */
  93 + template<typename T>
  94 + pFunctionPointer_t add_handler_front(T* tptr, void (T::*mptr)(void), IRQn_Type irq) {
  95 + return add_common(tptr, mptr, irq, true);
  96 + }
  97 +
  98 + /** Remove a handler from an interrupt
  99 + *
  100 + * @param handler the function object for the handler to remove
  101 + * @param irq the interrupt number
  102 + *
  103 + * @returns
  104 + * true if the handler was found and removed, false otherwise
  105 + */
  106 + bool remove_handler(pFunctionPointer_t handler, IRQn_Type irq);
  107 +
  108 +private:
  109 + InterruptManager();
  110 + ~InterruptManager();
  111 +
  112 + // We declare the copy contructor and the assignment operator, but we don't
  113 + // implement them. This way, if someone tries to copy/assign our instance,
  114 + // he will get an error at compile time.
  115 + InterruptManager(const InterruptManager&);
  116 + InterruptManager& operator =(const InterruptManager&);
  117 +
  118 + template<typename T>
  119 + pFunctionPointer_t add_common(T *tptr, void (T::*mptr)(void), IRQn_Type irq, bool front=false) {
  120 + int irq_pos = get_irq_index(irq);
  121 + bool change = must_replace_vector(irq);
  122 +
  123 + pFunctionPointer_t pf = front ? _chains[irq_pos]->add_front(tptr, mptr) : _chains[irq_pos]->add(tptr, mptr);
  124 + if (change)
  125 + NVIC_SetVector(irq, (uint32_t)&InterruptManager::static_irq_helper);
  126 + return pf;
  127 + }
  128 +
  129 + pFunctionPointer_t add_common(void (*function)(void), IRQn_Type irq, bool front=false);
  130 + bool must_replace_vector(IRQn_Type irq);
  131 + int get_irq_index(IRQn_Type irq);
  132 + void irq_helper();
  133 + void add_helper(void (*function)(void), IRQn_Type irq, bool front=false);
  134 + static void static_irq_helper();
  135 +
  136 + CallChain* _chains[NVIC_NUM_VECTORS];
  137 + static InterruptManager* _instance;
  138 +};
  139 +
  140 +} // namespace mbed
  141 +
  142 +#endif
  143 +
... ...
mbed/LocalFileSystem.h 0 → 100644
... ... @@ -0,0 +1,103 @@
  1 +/* mbed Microcontroller Library
  2 + * Copyright (c) 2006-2013 ARM Limited
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +#ifndef MBED_LOCALFILESYSTEM_H
  17 +#define MBED_LOCALFILESYSTEM_H
  18 +
  19 +#include "platform.h"
  20 +
  21 +#if DEVICE_LOCALFILESYSTEM
  22 +
  23 +#include "FileSystemLike.h"
  24 +
  25 +namespace mbed {
  26 +
  27 +FILEHANDLE local_file_open(const char* name, int flags);
  28 +
  29 +class LocalFileHandle : public FileHandle {
  30 +
  31 +public:
  32 + LocalFileHandle(FILEHANDLE fh);
  33 +
  34 + virtual int close();
  35 +
  36 + virtual ssize_t write(const void *buffer, size_t length);
  37 +
  38 + virtual ssize_t read(void *buffer, size_t length);
  39 +
  40 + virtual int isatty();
  41 +
  42 + virtual off_t lseek(off_t position, int whence);
  43 +
  44 + virtual int fsync();
  45 +
  46 + virtual off_t flen();
  47 +
  48 +protected:
  49 + FILEHANDLE _fh;
  50 + int pos;
  51 +};
  52 +
  53 +/** A filesystem for accessing the local mbed Microcontroller USB disk drive
  54 + *
  55 + * This allows programs to read and write files on the same disk drive that is used to program the
  56 + * mbed Microcontroller. Once created, the standard C file access functions are used to open,
  57 + * read and write files.
  58 + *
  59 + * Example:
  60 + * @code
  61 + * #include "mbed.h"
  62 + *
  63 + * LocalFileSystem local("local"); // Create the local filesystem under the name "local"
  64 + *
  65 + * int main() {
  66 + * FILE *fp = fopen("/local/out.txt", "w"); // Open "out.txt" on the local file system for writing
  67 + * fprintf(fp, "Hello World!");
  68 + * fclose(fp);
  69 + * remove("/local/out.txt"); // Removes the file "out.txt" from the local file system
  70 + *
  71 + * DIR *d = opendir("/local"); // Opens the root directory of the local file system
  72 + * struct dirent *p;
  73 + * while((p = readdir(d)) != NULL) { // Print the names of the files in the local file system
  74 + * printf("%s\n", p->d_name); // to stdout.
  75 + * }
  76 + * closedir(d);
  77 + * }
  78 + * @endcode
  79 + *
  80 + * @note
  81 + * If the microcontroller program makes an access to the local drive, it will be marked as "removed"
  82 + * on the Host computer. This means it is no longer accessible from the Host Computer.
  83 + *
  84 + * The drive will only re-appear when the microcontroller program exists. Note that if the program does
  85 + * not exit, you will need to hold down reset on the mbed Microcontroller to be able to see the drive again!
  86 + */
  87 +class LocalFileSystem : public FileSystemLike {
  88 +
  89 +public:
  90 + LocalFileSystem(const char* n) : FileSystemLike(n) {
  91 +
  92 + }
  93 +
  94 + virtual FileHandle *open(const char* name, int flags);
  95 + virtual int remove(const char *filename);
  96 + virtual DirHandle *opendir(const char *name);
  97 +};
  98 +
  99 +} // namespace mbed
  100 +
  101 +#endif
  102 +
  103 +#endif
... ...
mbed/LowPowerTicker.h 0 → 100644
... ... @@ -0,0 +1,44 @@
  1 +/* mbed Microcontroller Library
  2 + * Copyright (c) 2015 ARM Limited
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +#ifndef MBED_LOWPOWERTICKER_H
  17 +#define MBED_LOWPOWERTICKER_H
  18 +
  19 +#include "platform.h"
  20 +#include "Ticker.h"
  21 +
  22 +#if DEVICE_LOWPOWERTIMER
  23 +
  24 +#include "lp_ticker_api.h"
  25 +
  26 +namespace mbed {
  27 +
  28 +/** Low Power Ticker
  29 + */
  30 +class LowPowerTicker : public Ticker {
  31 +
  32 +public:
  33 + LowPowerTicker() : Ticker(get_lp_ticker_data()) {
  34 + }
  35 +
  36 + virtual ~LowPowerTicker() {
  37 + }
  38 +};
  39 +
  40 +} // namespace mbed
  41 +
  42 +#endif
  43 +
  44 +#endif
... ...
mbed/LowPowerTimeout.h 0 → 100644
... ... @@ -0,0 +1,42 @@
  1 +/* mbed Microcontroller Library
  2 + * Copyright (c) 2015 ARM Limited
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +#ifndef MBED_LOWPOWERTIMEOUT_H
  17 +#define MBED_LOWPOWERTIMEOUT_H
  18 +
  19 +#include "platform.h"
  20 +
  21 +#if DEVICE_LOWPOWERTIMER
  22 +
  23 +#include "lp_ticker_api.h"
  24 +#include "LowPowerTicker.h"
  25 +
  26 +namespace mbed {
  27 +
  28 +/** Low Power Timout
  29 + */
  30 +class LowPowerTimeout : public LowPowerTicker {
  31 +
  32 +private:
  33 + virtual void handler(void) {
  34 + _function.call();
  35 + }
  36 +};
  37 +
  38 +}
  39 +
  40 +#endif
  41 +
  42 +#endif
... ...
mbed/LowPowerTimer.h 0 → 100644
... ... @@ -0,0 +1,42 @@
  1 +/* mbed Microcontroller Library
  2 + * Copyright (c) 2015 ARM Limited
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +#ifndef MBED_LOWPOWERTIMER_H
  17 +#define MBED_LOWPOWERTIMER_H
  18 +
  19 +#include "platform.h"
  20 +#include "Timer.h"
  21 +
  22 +#if DEVICE_LOWPOWERTIMER
  23 +
  24 +#include "lp_ticker_api.h"
  25 +
  26 +namespace mbed {
  27 +
  28 +/** Low power timer
  29 + */
  30 +class LowPowerTimer : public Timer {
  31 +
  32 +public:
  33 + LowPowerTimer() : Timer(get_lp_ticker_data()) {
  34 + }
  35 +
  36 +};
  37 +
  38 +} // namespace mbed
  39 +
  40 +#endif
  41 +
  42 +#endif
... ...
mbed/PortIn.h 0 → 100644
... ... @@ -0,0 +1,93 @@
  1 +/* mbed Microcontroller Library
  2 + * Copyright (c) 2006-2013 ARM Limited
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +#ifndef MBED_PORTIN_H
  17 +#define MBED_PORTIN_H
  18 +
  19 +#include "platform.h"
  20 +
  21 +#if DEVICE_PORTIN
  22 +
  23 +#include "port_api.h"
  24 +
  25 +namespace mbed {
  26 +
  27 +/** A multiple pin digital input
  28 + *
  29 + * Example:
  30 + * @code
  31 + * // Switch on an LED if any of mbed pins 21-26 is high
  32 + *
  33 + * #include "mbed.h"
  34 + *
  35 + * PortIn p(Port2, 0x0000003F); // p21-p26
  36 + * DigitalOut ind(LED4);
  37 + *
  38 + * int main() {
  39 + * while(1) {
  40 + * int pins = p.read();
  41 + * if(pins) {
  42 + * ind = 1;
  43 + * } else {
  44 + * ind = 0;
  45 + * }
  46 + * }
  47 + * }
  48 + * @endcode
  49 + */
  50 +class PortIn {
  51 +public:
  52 +
  53 + /** Create an PortIn, connected to the specified port
  54 + *
  55 + * @param port Port to connect to (Port0-Port5)
  56 + * @param mask A bitmask to identify which bits in the port should be included (0 - ignore)
  57 + */
  58 + PortIn(PortName port, int mask = 0xFFFFFFFF) {
  59 + port_init(&_port, port, mask, PIN_INPUT);
  60 + }
  61 +
  62 + /** Read the value currently output on the port
  63 + *
  64 + * @returns
  65 + * An integer with each bit corresponding to associated port pin setting
  66 + */
  67 + int read() {
  68 + return port_read(&_port);
  69 + }
  70 +
  71 + /** Set the input pin mode
  72 + *
  73 + * @param mode PullUp, PullDown, PullNone, OpenDrain
  74 + */
  75 + void mode(PinMode mode) {
  76 + port_mode(&_port, mode);
  77 + }
  78 +
  79 + /** A shorthand for read()
  80 + */
  81 + operator int() {
  82 + return read();
  83 + }
  84 +
  85 +private:
  86 + port_t _port;
  87 +};
  88 +
  89 +} // namespace mbed
  90 +
  91 +#endif
  92 +
  93 +#endif
... ...
mbed/PortInOut.h 0 → 100644
... ... @@ -0,0 +1,104 @@
  1 +/* mbed Microcontroller Library
  2 + * Copyright (c) 2006-2013 ARM Limited
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +#ifndef MBED_PORTINOUT_H
  17 +#define MBED_PORTINOUT_H
  18 +
  19 +#include "platform.h"
  20 +
  21 +#if DEVICE_PORTINOUT
  22 +
  23 +#include "port_api.h"
  24 +
  25 +namespace mbed {
  26 +
  27 +/** A multiple pin digital in/out used to set/read multiple bi-directional pins
  28 + */
  29 +class PortInOut {
  30 +public:
  31 +
  32 + /** Create an PortInOut, connected to the specified port
  33 + *
  34 + * @param port Port to connect to (Port0-Port5)
  35 + * @param mask A bitmask to identify which bits in the port should be included (0 - ignore)
  36 + */
  37 + PortInOut(PortName port, int mask = 0xFFFFFFFF) {
  38 + port_init(&_port, port, mask, PIN_INPUT);
  39 + }
  40 +
  41 + /** Write the value to the output port
  42 + *
  43 + * @param value An integer specifying a bit to write for every corresponding port pin
  44 + */
  45 + void write(int value) {
  46 + port_write(&_port, value);
  47 + }
  48 +
  49 + /** Read the value currently output on the port
  50 + *
  51 + * @returns
  52 + * An integer with each bit corresponding to associated port pin setting
  53 + */
  54 + int read() {
  55 + return port_read(&_port);
  56 + }
  57 +
  58 + /** Set as an output
  59 + */
  60 + void output() {
  61 + port_dir(&_port, PIN_OUTPUT);
  62 + }
  63 +
  64 + /** Set as an input
  65 + */
  66 + void input() {
  67 + port_dir(&_port, PIN_INPUT);
  68 + }
  69 +
  70 + /** Set the input pin mode
  71 + *
  72 + * @param mode PullUp, PullDown, PullNone, OpenDrain
  73 + */
  74 + void mode(PinMode mode) {
  75 + port_mode(&_port, mode);
  76 + }
  77 +
  78 + /** A shorthand for write()
  79 + */
  80 + PortInOut& operator= (int value) {
  81 + write(value);
  82 + return *this;
  83 + }
  84 +
  85 + PortInOut& operator= (PortInOut& rhs) {
  86 + write(rhs.read());
  87 + return *this;
  88 + }
  89 +
  90 + /** A shorthand for read()
  91 + */
  92 + operator int() {
  93 + return read();
  94 + }
  95 +
  96 +private:
  97 + port_t _port;
  98 +};
  99 +
  100 +} // namespace mbed
  101 +
  102 +#endif
  103 +
  104 +#endif
... ...
mbed/PortOut.h 0 → 100644
... ... @@ -0,0 +1,104 @@
  1 +/* mbed Microcontroller Library
  2 + * Copyright (c) 2006-2013 ARM Limited
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +#ifndef MBED_PORTOUT_H
  17 +#define MBED_PORTOUT_H
  18 +
  19 +#include "platform.h"
  20 +
  21 +#if DEVICE_PORTOUT
  22 +
  23 +#include "port_api.h"
  24 +
  25 +namespace mbed {
  26 +/** A multiple pin digital out
  27 + *
  28 + * Example:
  29 + * @code
  30 + * // Toggle all four LEDs
  31 + *
  32 + * #include "mbed.h"
  33 + *
  34 + * // LED1 = P1.18 LED2 = P1.20 LED3 = P1.21 LED4 = P1.23
  35 + * #define LED_MASK 0x00B40000
  36 + *
  37 + * PortOut ledport(Port1, LED_MASK);
  38 + *
  39 + * int main() {
  40 + * while(1) {
  41 + * ledport = LED_MASK;
  42 + * wait(1);
  43 + * ledport = 0;
  44 + * wait(1);
  45 + * }
  46 + * }
  47 + * @endcode
  48 + */
  49 +class PortOut {
  50 +public:
  51 +
  52 + /** Create an PortOut, connected to the specified port
  53 + *
  54 + * @param port Port to connect to (Port0-Port5)
  55 + * @param mask A bitmask to identify which bits in the port should be included (0 - ignore)
  56 + */
  57 + PortOut(PortName port, int mask = 0xFFFFFFFF) {
  58 + port_init(&_port, port, mask, PIN_OUTPUT);
  59 + }
  60 +
  61 + /** Write the value to the output port
  62 + *
  63 + * @param value An integer specifying a bit to write for every corresponding PortOut pin
  64 + */
  65 + void write(int value) {
  66 + port_write(&_port, value);
  67 + }
  68 +
  69 + /** Read the value currently output on the port
  70 + *
  71 + * @returns
  72 + * An integer with each bit corresponding to associated PortOut pin setting
  73 + */
  74 + int read() {
  75 + return port_read(&_port);
  76 + }
  77 +
  78 + /** A shorthand for write()
  79 + */
  80 + PortOut& operator= (int value) {
  81 + write(value);
  82 + return *this;
  83 + }
  84 +
  85 + PortOut& operator= (PortOut& rhs) {
  86 + write(rhs.read());
  87 + return *this;
  88 + }
  89 +
  90 + /** A shorthand for read()
  91 + */
  92 + operator int() {
  93 + return read();
  94 + }
  95 +
  96 +private:
  97 + port_t _port;
  98 +};
  99 +
  100 +} // namespace mbed
  101 +
  102 +#endif
  103 +
  104 +#endif
... ...
mbed/PwmOut.h 0 → 100644
... ... @@ -0,0 +1,158 @@
  1 +/* mbed Microcontroller Library
  2 + * Copyright (c) 2006-2013 ARM Limited
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +#ifndef MBED_PWMOUT_H
  17 +#define MBED_PWMOUT_H
  18 +
  19 +#include "platform.h"
  20 +
  21 +#if DEVICE_PWMOUT
  22 +#include "pwmout_api.h"
  23 +
  24 +namespace mbed {
  25 +
  26 +/** A pulse-width modulation digital output
  27 + *
  28 + * Example
  29 + * @code
  30 + * // Fade a led on.
  31 + * #include "mbed.h"
  32 + *
  33 + * PwmOut led(LED1);
  34 + *
  35 + * int main() {
  36 + * while(1) {
  37 + * led = led + 0.01;
  38 + * wait(0.2);
  39 + * if(led == 1.0) {
  40 + * led = 0;
  41 + * }
  42 + * }
  43 + * }
  44 + * @endcode
  45 + *
  46 + * @note
  47 + * On the LPC1768 and LPC2368, the PWMs all share the same
  48 + * period - if you change the period for one, you change it for all.
  49 + * Although routines that change the period maintain the duty cycle
  50 + * for its PWM, all other PWMs will require their duty cycle to be
  51 + * refreshed.
  52 + */
  53 +class PwmOut {
  54 +
  55 +public:
  56 +
  57 + /** Create a PwmOut connected to the specified pin
  58 + *
  59 + * @param pin PwmOut pin to connect to
  60 + */
  61 + PwmOut(PinName pin) {
  62 + pwmout_init(&_pwm, pin);
  63 + }
  64 +
  65 + /** Set the ouput duty-cycle, specified as a percentage (float)
  66 + *
  67 + * @param value A floating-point value representing the output duty-cycle,
  68 + * specified as a percentage. The value should lie between
  69 + * 0.0f (representing on 0%) and 1.0f (representing on 100%).
  70 + * Values outside this range will be saturated to 0.0f or 1.0f.
  71 + */
  72 + void write(float value) {
  73 + pwmout_write(&_pwm, value);
  74 + }
  75 +
  76 + /** Return the current output duty-cycle setting, measured as a percentage (float)
  77 + *
  78 + * @returns
  79 + * A floating-point value representing the current duty-cycle being output on the pin,
  80 + * measured as a percentage. The returned value will lie between
  81 + * 0.0f (representing on 0%) and 1.0f (representing on 100%).
  82 + *
  83 + * @note
  84 + * This value may not match exactly the value set by a previous <write>.
  85 + */
  86 + float read() {
  87 + return pwmout_read(&_pwm);
  88 + }
  89 +
  90 + /** Set the PWM period, specified in seconds (float), keeping the duty cycle the same.
  91 + *
  92 + * @note
  93 + * The resolution is currently in microseconds; periods smaller than this
  94 + * will be set to zero.
  95 + */
  96 + void period(float seconds) {
  97 + pwmout_period(&_pwm, seconds);
  98 + }
  99 +
  100 + /** Set the PWM period, specified in milli-seconds (int), keeping the duty cycle the same.
  101 + */
  102 + void period_ms(int ms) {
  103 + pwmout_period_ms(&_pwm, ms);
  104 + }
  105 +
  106 + /** Set the PWM period, specified in micro-seconds (int), keeping the duty cycle the same.
  107 + */
  108 + void period_us(int us) {
  109 + pwmout_period_us(&_pwm, us);
  110 + }
  111 +
  112 + /** Set the PWM pulsewidth, specified in seconds (float), keeping the period the same.
  113 + */
  114 + void pulsewidth(float seconds) {
  115 + pwmout_pulsewidth(&_pwm, seconds);
  116 + }
  117 +
  118 + /** Set the PWM pulsewidth, specified in milli-seconds (int), keeping the period the same.
  119 + */
  120 + void pulsewidth_ms(int ms) {
  121 + pwmout_pulsewidth_ms(&_pwm, ms);
  122 + }
  123 +
  124 + /** Set the PWM pulsewidth, specified in micro-seconds (int), keeping the period the same.
  125 + */
  126 + void pulsewidth_us(int us) {
  127 + pwmout_pulsewidth_us(&_pwm, us);
  128 + }
  129 +
  130 +#ifdef MBED_OPERATORS
  131 + /** A operator shorthand for write()
  132 + */
  133 + PwmOut& operator= (float value) {
  134 + write(value);
  135 + return *this;
  136 + }
  137 +
  138 + PwmOut& operator= (PwmOut& rhs) {
  139 + write(rhs.read());
  140 + return *this;
  141 + }
  142 +
  143 + /** An operator shorthand for read()
  144 + */
  145 + operator float() {
  146 + return read();
  147 + }
  148 +#endif
  149 +
  150 +protected:
  151 + pwmout_t _pwm;
  152 +};
  153 +
  154 +} // namespace mbed
  155 +
  156 +#endif
  157 +
  158 +#endif
... ...
mbed/RawSerial.h 0 → 100644
... ... @@ -0,0 +1,90 @@
  1 +/* mbed Microcontroller Library
  2 + * Copyright (c) 2006-2013 ARM Limited
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +#ifndef MBED_RAW_SERIAL_H
  17 +#define MBED_RAW_SERIAL_H
  18 +
  19 +#include "platform.h"
  20 +
  21 +#if DEVICE_SERIAL
  22 +
  23 +#include "SerialBase.h"
  24 +#include "serial_api.h"
  25 +
  26 +namespace mbed {
  27 +
  28 +/** A serial port (UART) for communication with other serial devices
  29 + * This is a variation of the Serial class that doesn't use streams,
  30 + * thus making it safe to use in interrupt handlers with the RTOS.
  31 + *
  32 + * Can be used for Full Duplex communication, or Simplex by specifying
  33 + * one pin as NC (Not Connected)
  34 + *
  35 + * Example:
  36 + * @code
  37 + * // Send a char to the PC
  38 + *
  39 + * #include "mbed.h"
  40 + *
  41 + * RawSerial pc(USBTX, USBRX);
  42 + *
  43 + * int main() {
  44 + * pc.putc('A');
  45 + * }
  46 + * @endcode
  47 + */
  48 +class RawSerial: public SerialBase {
  49 +
  50 +public:
  51 + /** Create a RawSerial port, connected to the specified transmit and receive pins
  52 + *
  53 + * @param tx Transmit pin
  54 + * @param rx Receive pin
  55 + *
  56 + * @note
  57 + * Either tx or rx may be specified as NC if unused
  58 + */
  59 + RawSerial(PinName tx, PinName rx);
  60 +
  61 + /** Write a char to the serial port
  62 + *
  63 + * @param c The char to write
  64 + *
  65 + * @returns The written char or -1 if an error occured
  66 + */
  67 + int putc(int c);
  68 +
  69 + /** Read a char from the serial port
  70 + *
  71 + * @returns The char read from the serial port
  72 + */
  73 + int getc();
  74 +
  75 + /** Write a string to the serial port
  76 + *
  77 + * @param str The string to write
  78 + *
  79 + * @returns 0 if the write succeeds, EOF for error
  80 + */
  81 + int puts(const char *str);
  82 +
  83 + int printf(const char *format, ...);
  84 +};
  85 +
  86 +} // namespace mbed
  87 +
  88 +#endif
  89 +
  90 +#endif
... ...
mbed/SPI.h 0 → 100644
... ... @@ -0,0 +1,245 @@
  1 +/* mbed Microcontroller Library
  2 + * Copyright (c) 2006-2015 ARM Limited
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +#ifndef MBED_SPI_H
  17 +#define MBED_SPI_H
  18 +
  19 +#include "platform.h"
  20 +
  21 +#if DEVICE_SPI
  22 +
  23 +#include "spi_api.h"
  24 +
  25 +#if DEVICE_SPI_ASYNCH
  26 +#include "CThunk.h"
  27 +#include "dma_api.h"
  28 +#include "CircularBuffer.h"
  29 +#include "FunctionPointer.h"
  30 +#include "Transaction.h"
  31 +#endif
  32 +
  33 +namespace mbed {
  34 +
  35 +/** A SPI Master, used for communicating with SPI slave devices
  36 + *
  37 + * The default format is set to 8-bits, mode 0, and a clock frequency of 1MHz
  38 + *
  39 + * Most SPI devices will also require Chip Select and Reset signals. These
  40 + * can be controlled using <DigitalOut> pins
  41 + *
  42 + * Example:
  43 + * @code
  44 + * // Send a byte to a SPI slave, and record the response
  45 + *
  46 + * #include "mbed.h"
  47 + *
  48 + * // hardware ssel (where applicable)
  49 + * //SPI device(p5, p6, p7, p8); // mosi, miso, sclk, ssel
  50 + *
  51 + * // software ssel
  52 + * SPI device(p5, p6, p7); // mosi, miso, sclk
  53 + * DigitalOut cs(p8); // ssel
  54 + *
  55 + * int main() {
  56 + * // hardware ssel (where applicable)
  57 + * //int response = device.write(0xFF);
  58 + *
  59 + * // software ssel
  60 + * cs = 0;
  61 + * int response = device.write(0xFF);
  62 + * cs = 1;
  63 + * }
  64 + * @endcode
  65 + */
  66 +class SPI {
  67 +
  68 +public:
  69 +
  70 + /** Create a SPI master connected to the specified pins
  71 + *
  72 + * mosi or miso can be specfied as NC if not used
  73 + *
  74 + * @param mosi SPI Master Out, Slave In pin
  75 + * @param miso SPI Master In, Slave Out pin
  76 + * @param sclk SPI Clock pin
  77 + * @param ssel SPI chip select pin
  78 + */
  79 + SPI(PinName mosi, PinName miso, PinName sclk, PinName ssel=NC);
  80 +
  81 + /** Configure the data transmission format
  82 + *
  83 + * @param bits Number of bits per SPI frame (4 - 16)
  84 + * @param mode Clock polarity and phase mode (0 - 3)
  85 + *
  86 + * @code
  87 + * mode | POL PHA
  88 + * -----+--------
  89 + * 0 | 0 0
  90 + * 1 | 0 1
  91 + * 2 | 1 0
  92 + * 3 | 1 1
  93 + * @endcode
  94 + */
  95 + void format(int bits, int mode = 0);
  96 +
  97 + /** Set the spi bus clock frequency
  98 + *
  99 + * @param hz SCLK frequency in hz (default = 1MHz)
  100 + */
  101 + void frequency(int hz = 1000000);
  102 +
  103 + /** Write to the SPI Slave and return the response
  104 + *
  105 + * @param value Data to be sent to the SPI slave
  106 + *
  107 + * @returns
  108 + * Response from the SPI slave
  109 + */
  110 + virtual int write(int value);
  111 +
  112 +#if DEVICE_SPI_ASYNCH
  113 +
  114 + /** Start non-blocking SPI transfer using 8bit buffers.
  115 + *
  116 + * @param tx_buffer The TX buffer with data to be transfered. If NULL is passed,
  117 + * the default SPI value is sent
  118 + * @param tx_length The length of TX buffer in bytes
  119 + * @param rx_buffer The RX buffer which is used for received data. If NULL is passed,
  120 + * received data are ignored
  121 + * @param rx_length The length of RX buffer in bytes
  122 + * @param callback The event callback function
  123 + * @param event The logical OR of events to modify. Look at spi hal header file for SPI events.
  124 + * @return Zero if the transfer has started, or -1 if SPI peripheral is busy
  125 + */
  126 + template<typename Type>
  127 + int transfer(const Type *tx_buffer, int tx_length, Type *rx_buffer, int rx_length, const event_callback_t& callback, int event = SPI_EVENT_COMPLETE) {
  128 + if (spi_active(&_spi)) {
  129 + return queue_transfer(tx_buffer, tx_length, rx_buffer, rx_length, sizeof(Type)*8, callback, event);
  130 + }
  131 + start_transfer(tx_buffer, tx_length, rx_buffer, rx_length, sizeof(Type)*8, callback, event);
  132 + return 0;
  133 + }
  134 +
  135 + /** Abort the on-going SPI transfer, and continue with transfer's in the queue if any.
  136 + */
  137 + void abort_transfer();
  138 +
  139 + /** Clear the transaction buffer
  140 + */
  141 + void clear_transfer_buffer();
  142 +
  143 + /** Clear the transaction buffer and abort on-going transfer.
  144 + */
  145 + void abort_all_transfers();
  146 +
  147 + /** Configure DMA usage suggestion for non-blocking transfers
  148 + *
  149 + * @param usage The usage DMA hint for peripheral
  150 + * @return Zero if the usage was set, -1 if a transaction is on-going
  151 + */
  152 + int set_dma_usage(DMAUsage usage);
  153 +
  154 +protected:
  155 + /** SPI IRQ handler
  156 + *
  157 + */
  158 + void irq_handler_asynch(void);
  159 +
  160 + /** Common transfer method
  161 + *
  162 + * @param tx_buffer The TX buffer with data to be transfered. If NULL is passed,
  163 + * the default SPI value is sent
  164 + * @param tx_length The length of TX buffer in bytes
  165 + * @param rx_buffer The RX buffer which is used for received data. If NULL is passed,
  166 + * received data are ignored
  167 + * @param rx_length The length of RX buffer in bytes
  168 + * @param bit_width The buffers element width
  169 + * @param callback The event callback function
  170 + * @param event The logical OR of events to modify
  171 + * @return Zero if the transfer has started or was added to the queue, or -1 if SPI peripheral is busy/buffer is full
  172 + */
  173 + int transfer(const void *tx_buffer, int tx_length, void *rx_buffer, int rx_length, unsigned char bit_width, const event_callback_t& callback, int event);
  174 +
  175 + /**
  176 + *
  177 + * @param tx_buffer The TX buffer with data to be transfered. If NULL is passed,
  178 + * the default SPI value is sent
  179 + * @param tx_length The length of TX buffer in bytes
  180 + * @param rx_buffer The RX buffer which is used for received data. If NULL is passed,
  181 + * received data are ignored
  182 + * @param rx_length The length of RX buffer in bytes
  183 + * @param bit_width The buffers element width
  184 + * @param callback The event callback function
  185 + * @param event The logical OR of events to modify
  186 + * @return Zero if a transfer was added to the queue, or -1 if the queue is full
  187 + */
  188 + int queue_transfer(const void *tx_buffer, int tx_length, void *rx_buffer, int rx_length, unsigned char bit_width, const event_callback_t& callback, int event);
  189 +
  190 + /** Configures a callback, spi peripheral and initiate a new transfer
  191 + *
  192 + * @param tx_buffer The TX buffer with data to be transfered. If NULL is passed,
  193 + * the default SPI value is sent
  194 + * @param tx_length The length of TX buffer in bytes
  195 + * @param rx_buffer The RX buffer which is used for received data. If NULL is passed,
  196 + * received data are ignored
  197 + * @param rx_length The length of RX buffer in bytes
  198 + * @param bit_width The buffers element width
  199 + * @param callback The event callback function
  200 + * @param event The logical OR of events to modify
  201 + */
  202 + void start_transfer(const void *tx_buffer, int tx_length, void *rx_buffer, int rx_length, unsigned char bit_width, const event_callback_t& callback, int event);
  203 +
  204 +#if TRANSACTION_QUEUE_SIZE_SPI
  205 +
  206 + /** Start a new transaction
  207 + *
  208 + * @param data Transaction data
  209 + */
  210 + void start_transaction(transaction_t *data);
  211 +
  212 + /** Dequeue a transaction
  213 + *
  214 + */
  215 + void dequeue_transaction();
  216 + static CircularBuffer<Transaction<SPI>, TRANSACTION_QUEUE_SIZE_SPI> _transaction_buffer;
  217 +#endif
  218 +
  219 +#endif
  220 +
  221 +public:
  222 + virtual ~SPI() {
  223 + }
  224 +
  225 +protected:
  226 + spi_t _spi;
  227 +
  228 +#if DEVICE_SPI_ASYNCH
  229 + CThunk<SPI> _irq;
  230 + event_callback_t _callback;
  231 + DMAUsage _usage;
  232 +#endif
  233 +
  234 + void aquire(void);
  235 + static SPI *_owner;
  236 + int _bits;
  237 + int _mode;
  238 + int _hz;
  239 +};
  240 +
  241 +} // namespace mbed
  242 +
  243 +#endif
  244 +
  245 +#endif
... ...
mbed/SPISlave.h 0 → 100644
... ... @@ -0,0 +1,122 @@
  1 +/* mbed Microcontroller Library
  2 + * Copyright (c) 2006-2013 ARM Limited
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +#ifndef MBED_SPISLAVE_H
  17 +#define MBED_SPISLAVE_H
  18 +
  19 +#include "platform.h"
  20 +
  21 +#if DEVICE_SPISLAVE
  22 +
  23 +#include "spi_api.h"
  24 +
  25 +namespace mbed {
  26 +
  27 +/** A SPI slave, used for communicating with a SPI Master device
  28 + *
  29 + * The default format is set to 8-bits, mode 0, and a clock frequency of 1MHz
  30 + *
  31 + * Example:
  32 + * @code
  33 + * // Reply to a SPI master as slave
  34 + *
  35 + * #include "mbed.h"
  36 + *
  37 + * SPISlave device(p5, p6, p7, p8); // mosi, miso, sclk, ssel
  38 + *
  39 + * int main() {
  40 + * device.reply(0x00); // Prime SPI with first reply
  41 + * while(1) {
  42 + * if(device.receive()) {
  43 + * int v = device.read(); // Read byte from master
  44 + * v = (v + 1) % 0x100; // Add one to it, modulo 256
  45 + * device.reply(v); // Make this the next reply
  46 + * }
  47 + * }
  48 + * }
  49 + * @endcode
  50 + */
  51 +class SPISlave {
  52 +
  53 +public:
  54 +
  55 + /** Create a SPI slave connected to the specified pins
  56 + *
  57 + * mosi or miso can be specfied as NC if not used
  58 + *
  59 + * @param mosi SPI Master Out, Slave In pin
  60 + * @param miso SPI Master In, Slave Out pin
  61 + * @param sclk SPI Clock pin
  62 + * @param ssel SPI chip select pin
  63 + */
  64 + SPISlave(PinName mosi, PinName miso, PinName sclk, PinName ssel);
  65 +
  66 + /** Configure the data transmission format
  67 + *
  68 + * @param bits Number of bits per SPI frame (4 - 16)
  69 + * @param mode Clock polarity and phase mode (0 - 3)
  70 + *
  71 + * @code
  72 + * mode | POL PHA
  73 + * -----+--------
  74 + * 0 | 0 0
  75 + * 1 | 0 1
  76 + * 2 | 1 0
  77 + * 3 | 1 1
  78 + * @endcode
  79 + */
  80 + void format(int bits, int mode = 0);
  81 +
  82 + /** Set the spi bus clock frequency
  83 + *
  84 + * @param hz SCLK frequency in hz (default = 1MHz)
  85 + */
  86 + void frequency(int hz = 1000000);
  87 +
  88 + /** Polls the SPI to see if data has been received
  89 + *
  90 + * @returns
  91 + * 0 if no data,
  92 + * 1 otherwise
  93 + */
  94 + int receive(void);
  95 +
  96 + /** Retrieve data from receive buffer as slave
  97 + *
  98 + * @returns
  99 + * the data in the receive buffer
  100 + */
  101 + int read(void);
  102 +
  103 + /** Fill the transmission buffer with the value to be written out
  104 + * as slave on the next received message from the master.
  105 + *
  106 + * @param value the data to be transmitted next
  107 + */
  108 + void reply(int value);
  109 +
  110 +protected:
  111 + spi_t _spi;
  112 +
  113 + int _bits;
  114 + int _mode;
  115 + int _hz;
  116 +};
  117 +
  118 +} // namespace mbed
  119 +
  120 +#endif
  121 +
  122 +#endif
... ...
mbed/Serial.h 0 → 100644
... ... @@ -0,0 +1,74 @@
  1 +/* mbed Microcontroller Library
  2 + * Copyright (c) 2006-2013 ARM Limited
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +#ifndef MBED_SERIAL_H
  17 +#define MBED_SERIAL_H
  18 +
  19 +#include "platform.h"
  20 +
  21 +#if DEVICE_SERIAL
  22 +
  23 +#include "Stream.h"
  24 +#include "SerialBase.h"
  25 +#include "serial_api.h"
  26 +
  27 +namespace mbed {
  28 +
  29 +/** A serial port (UART) for communication with other serial devices
  30 + *
  31 + * Can be used for Full Duplex communication, or Simplex by specifying
  32 + * one pin as NC (Not Connected)
  33 + *
  34 + * Example:
  35 + * @code
  36 + * // Print "Hello World" to the PC
  37 + *
  38 + * #include "mbed.h"
  39 + *
  40 + * Serial pc(USBTX, USBRX);
  41 + *
  42 + * int main() {
  43 + * pc.printf("Hello World\n");
  44 + * }
  45 + * @endcode
  46 + */
  47 +class Serial : public SerialBase, public Stream {
  48 +
  49 +public:
  50 +#if DEVICE_SERIAL_ASYNCH
  51 + using SerialBase::read;
  52 + using SerialBase::write;
  53 +#endif
  54 +
  55 + /** Create a Serial port, connected to the specified transmit and receive pins
  56 + *
  57 + * @param tx Transmit pin
  58 + * @param rx Receive pin
  59 + *
  60 + * @note
  61 + * Either tx or rx may be specified as NC if unused
  62 + */
  63 + Serial(PinName tx, PinName rx, const char *name=NULL);
  64 +
  65 +protected:
  66 + virtual int _getc();
  67 + virtual int _putc(int c);
  68 +};
  69 +
  70 +} // namespace mbed
  71 +
  72 +#endif
  73 +
  74 +#endif
... ...
mbed/SerialBase.h 0 → 100644
... ... @@ -0,0 +1,223 @@
  1 +/* mbed Microcontroller Library
  2 + * Copyright (c) 2006-2013 ARM Limited
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +#ifndef MBED_SERIALBASE_H
  17 +#define MBED_SERIALBASE_H
  18 +
  19 +#include "platform.h"
  20 +
  21 +#if DEVICE_SERIAL
  22 +
  23 +#include "Stream.h"
  24 +#include "FunctionPointer.h"
  25 +#include "serial_api.h"
  26 +
  27 +#if DEVICE_SERIAL_ASYNCH
  28 +#include "CThunk.h"
  29 +#include "dma_api.h"
  30 +#endif
  31 +
  32 +namespace mbed {
  33 +
  34 +/** A base class for serial port implementations
  35 + * Can't be instantiated directly (use Serial or RawSerial)
  36 + */
  37 +class SerialBase {
  38 +
  39 +public:
  40 + /** Set the baud rate of the serial port
  41 + *
  42 + * @param baudrate The baudrate of the serial port (default = 9600).
  43 + */
  44 + void baud(int baudrate);
  45 +
  46 + enum Parity {
  47 + None = 0,
  48 + Odd,
  49 + Even,
  50 + Forced1,
  51 + Forced0
  52 + };
  53 +
  54 + enum IrqType {
  55 + RxIrq = 0,
  56 + TxIrq
  57 + };
  58 +
  59 + enum Flow {
  60 + Disabled = 0,
  61 + RTS,
  62 + CTS,
  63 + RTSCTS
  64 + };
  65 +
  66 + /** Set the transmission format used by the serial port
  67 + *
  68 + * @param bits The number of bits in a word (5-8; default = 8)
  69 + * @param parity The parity used (SerialBase::None, SerialBase::Odd, SerialBase::Even, SerialBase::Forced1, SerialBase::Forced0; default = SerialBase::None)
  70 + * @param stop The number of stop bits (1 or 2; default = 1)
  71 + */
  72 + void format(int bits=8, Parity parity=SerialBase::None, int stop_bits=1);
  73 +
  74 + /** Determine if there is a character available to read
  75 + *
  76 + * @returns
  77 + * 1 if there is a character available to read,
  78 + * 0 otherwise
  79 + */
  80 + int readable();
  81 +
  82 + /** Determine if there is space available to write a character
  83 + *
  84 + * @returns
  85 + * 1 if there is space to write a character,
  86 + * 0 otherwise
  87 + */
  88 + int writeable();
  89 +
  90 + /** Attach a function to call whenever a serial interrupt is generated
  91 + *
  92 + * @param fptr A pointer to a void function, or 0 to set as none
  93 + * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty)
  94 + */
  95 + void attach(void (*fptr)(void), IrqType type=RxIrq);
  96 +
  97 + /** Attach a member function to call whenever a serial interrupt is generated
  98 + *
  99 + * @param tptr pointer to the object to call the member function on
  100 + * @param mptr pointer to the member function to be called
  101 + * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty)
  102 + */
  103 + template<typename T>
  104 + void attach(T* tptr, void (T::*mptr)(void), IrqType type=RxIrq) {
  105 + if((mptr != NULL) && (tptr != NULL)) {
  106 + _irq[type].attach(tptr, mptr);
  107 + serial_irq_set(&_serial, (SerialIrq)type, 1);
  108 + } else {
  109 + serial_irq_set(&_serial, (SerialIrq)type, 0);
  110 + }
  111 + }
  112 +
  113 + /** Generate a break condition on the serial line
  114 + */
  115 + void send_break();
  116 +
  117 +#if DEVICE_SERIAL_FC
  118 + /** Set the flow control type on the serial port
  119 + *
  120 + * @param type the flow control type (Disabled, RTS, CTS, RTSCTS)
  121 + * @param flow1 the first flow control pin (RTS for RTS or RTSCTS, CTS for CTS)
  122 + * @param flow2 the second flow control pin (CTS for RTSCTS)
  123 + */
  124 + void set_flow_control(Flow type, PinName flow1=NC, PinName flow2=NC);
  125 +#endif
  126 +
  127 + static void _irq_handler(uint32_t id, SerialIrq irq_type);
  128 +
  129 +#if DEVICE_SERIAL_ASYNCH
  130 +
  131 + /** Begin asynchronous write using 8bit buffer. The completition invokes registered TX event callback
  132 + *
  133 + * @param buffer The buffer where received data will be stored
  134 + * @param length The buffer length in bytes
  135 + * @param callback The event callback function
  136 + * @param event The logical OR of TX events
  137 + */
  138 + int write(const uint8_t *buffer, int length, const event_callback_t& callback, int event = SERIAL_EVENT_TX_COMPLETE);
  139 +
  140 + /** Begin asynchronous write using 16bit buffer. The completition invokes registered TX event callback
  141 + *
  142 + * @param buffer The buffer where received data will be stored
  143 + * @param length The buffer length in bytes
  144 + * @param callback The event callback function
  145 + * @param event The logical OR of TX events
  146 + */
  147 + int write(const uint16_t *buffer, int length, const event_callback_t& callback, int event = SERIAL_EVENT_TX_COMPLETE);
  148 +
  149 + /** Abort the on-going write transfer
  150 + */
  151 + void abort_write();
  152 +
  153 + /** Begin asynchronous reading using 8bit buffer. The completition invokes registred RX event callback.
  154 + *
  155 + * @param buffer The buffer where received data will be stored
  156 + * @param length The buffer length in bytes
  157 + * @param callback The event callback function
  158 + * @param event The logical OR of RX events
  159 + * @param char_match The matching character
  160 + */
  161 + int read(uint8_t *buffer, int length, const event_callback_t& callback, int event = SERIAL_EVENT_RX_COMPLETE, unsigned char char_match = SERIAL_RESERVED_CHAR_MATCH);
  162 +
  163 + /** Begin asynchronous reading using 16bit buffer. The completition invokes registred RX event callback.
  164 + *
  165 + * @param buffer The buffer where received data will be stored
  166 + * @param length The buffer length in bytes
  167 + * @param callback The event callback function
  168 + * @param event The logical OR of RX events
  169 + * @param char_match The matching character
  170 + */
  171 + int read(uint16_t *buffer, int length, const event_callback_t& callback, int event = SERIAL_EVENT_RX_COMPLETE, unsigned char char_match = SERIAL_RESERVED_CHAR_MATCH);
  172 +
  173 + /** Abort the on-going read transfer
  174 + */
  175 + void abort_read();
  176 +
  177 + /** Configure DMA usage suggestion for non-blocking TX transfers
  178 + *
  179 + * @param usage The usage DMA hint for peripheral
  180 + * @return Zero if the usage was set, -1 if a transaction is on-going
  181 + */
  182 + int set_dma_usage_tx(DMAUsage usage);
  183 +
  184 + /** Configure DMA usage suggestion for non-blocking RX transfers
  185 + *
  186 + * @param usage The usage DMA hint for peripheral
  187 + * @return Zero if the usage was set, -1 if a transaction is on-going
  188 + */
  189 + int set_dma_usage_rx(DMAUsage usage);
  190 +
  191 +protected:
  192 + void start_read(void *buffer, int buffer_size, char buffer_width, const event_callback_t& callback, int event, unsigned char char_match);
  193 + void start_write(const void *buffer, int buffer_size, char buffer_width, const event_callback_t& callback, int event);
  194 + void interrupt_handler_asynch(void);
  195 +#endif
  196 +
  197 +protected:
  198 + SerialBase(PinName tx, PinName rx);
  199 + virtual ~SerialBase() {
  200 + }
  201 +
  202 + int _base_getc();
  203 + int _base_putc(int c);
  204 +
  205 +#if DEVICE_SERIAL_ASYNCH
  206 + CThunk<SerialBase> _thunk_irq;
  207 + event_callback_t _tx_callback;
  208 + event_callback_t _rx_callback;
  209 + DMAUsage _tx_usage;
  210 + DMAUsage _rx_usage;
  211 +#endif
  212 +
  213 + serial_t _serial;
  214 + FunctionPointer _irq[2];
  215 + int _baud;
  216 +
  217 +};
  218 +
  219 +} // namespace mbed
  220 +
  221 +#endif
  222 +
  223 +#endif
... ...
mbed/Stream.h 0 → 100644
... ... @@ -0,0 +1,65 @@
  1 +/* mbed Microcontroller Library
  2 + * Copyright (c) 2006-2013 ARM Limited
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +#ifndef MBED_STREAM_H
  17 +#define MBED_STREAM_H
  18 +
  19 +#include "platform.h"
  20 +#include "FileLike.h"
  21 +
  22 +namespace mbed {
  23 +
  24 +extern void mbed_set_unbuffered_stream(FILE *_file);
  25 +extern int mbed_getc(FILE *_file);
  26 +extern char* mbed_gets(char *s, int size, FILE *_file);
  27 +
  28 +class Stream : public FileLike {
  29 +
  30 +public:
  31 + Stream(const char *name=NULL);
  32 + virtual ~Stream();
  33 +
  34 + int putc(int c);
  35 + int puts(const char *s);
  36 + int getc();
  37 + char *gets(char *s, int size);
  38 + int printf(const char* format, ...);
  39 + int scanf(const char* format, ...);
  40 +
  41 + operator std::FILE*() {return _file;}
  42 +
  43 +protected:
  44 + virtual int close();
  45 + virtual ssize_t write(const void* buffer, size_t length);
  46 + virtual ssize_t read(void* buffer, size_t length);
  47 + virtual off_t lseek(off_t offset, int whence);
  48 + virtual int isatty();
  49 + virtual int fsync();
  50 + virtual off_t flen();
  51 +
  52 + virtual int _putc(int c) = 0;
  53 + virtual int _getc() = 0;
  54 +
  55 + std::FILE *_file;
  56 +
  57 + /* disallow copy constructor and assignment operators */
  58 +private:
  59 + Stream(const Stream&);
  60 + Stream & operator = (const Stream&);
  61 +};
  62 +
  63 +} // namespace mbed
  64 +
  65 +#endif
... ...
mbed/TARGET_NUCLEO_F401RE/TARGET_STM/TARGET_STM32F4/PeripheralPins.h 0 → 100644
... ... @@ -0,0 +1,66 @@
  1 +/* mbed Microcontroller Library
  2 + *******************************************************************************
  3 + * Copyright (c) 2014, STMicroelectronics
  4 + * All rights reserved.
  5 + *
  6 + * Redistribution and use in source and binary forms, with or without
  7 + * modification, are permitted provided that the following conditions are met:
  8 + *
  9 + * 1. Redistributions of source code must retain the above copyright notice,
  10 + * this list of conditions and the following disclaimer.
  11 + * 2. Redistributions in binary form must reproduce the above copyright notice,
  12 + * this list of conditions and the following disclaimer in the documentation
  13 + * and/or other materials provided with the distribution.
  14 + * 3. Neither the name of STMicroelectronics nor the names of its contributors
  15 + * may be used to endorse or promote products derived from this software
  16 + * without specific prior written permission.
  17 + *
  18 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  19 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21 + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  22 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  23 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  24 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  25 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  26 + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  27 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28 + *******************************************************************************
  29 + */
  30 +
  31 +#ifndef MBED_PERIPHERALPINS_H
  32 +#define MBED_PERIPHERALPINS_H
  33 +
  34 +#include "pinmap.h"
  35 +#include "PeripheralNames.h"
  36 +
  37 +//*** ADC ***
  38 +
  39 +extern const PinMap PinMap_ADC[];
  40 +
  41 +//*** DAC ***
  42 +
  43 +extern const PinMap PinMap_DAC[];
  44 +
  45 +//*** I2C ***
  46 +
  47 +extern const PinMap PinMap_I2C_SDA[];
  48 +extern const PinMap PinMap_I2C_SCL[];
  49 +
  50 +//*** PWM ***
  51 +
  52 +extern const PinMap PinMap_PWM[];
  53 +
  54 +//*** SERIAL ***
  55 +
  56 +extern const PinMap PinMap_UART_TX[];
  57 +extern const PinMap PinMap_UART_RX[];
  58 +
  59 +//*** SPI ***
  60 +
  61 +extern const PinMap PinMap_SPI_MOSI[];
  62 +extern const PinMap PinMap_SPI_MISO[];
  63 +extern const PinMap PinMap_SPI_SCLK[];
  64 +extern const PinMap PinMap_SPI_SSEL[];
  65 +
  66 +#endif
... ...
mbed/TARGET_NUCLEO_F401RE/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F401RE/PeripheralNames.h 0 → 100644
... ... @@ -0,0 +1,81 @@
  1 +/* mbed Microcontroller Library
  2 + *******************************************************************************
  3 + * Copyright (c) 2014, STMicroelectronics
  4 + * All rights reserved.
  5 + *
  6 + * Redistribution and use in source and binary forms, with or without
  7 + * modification, are permitted provided that the following conditions are met:
  8 + *
  9 + * 1. Redistributions of source code must retain the above copyright notice,
  10 + * this list of conditions and the following disclaimer.
  11 + * 2. Redistributions in binary form must reproduce the above copyright notice,
  12 + * this list of conditions and the following disclaimer in the documentation
  13 + * and/or other materials provided with the distribution.
  14 + * 3. Neither the name of STMicroelectronics nor the names of its contributors
  15 + * may be used to endorse or promote products derived from this software
  16 + * without specific prior written permission.
  17 + *
  18 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  19 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21 + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  22 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  23 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  24 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  25 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  26 + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  27 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28 + *******************************************************************************
  29 + */
  30 +#ifndef MBED_PERIPHERALNAMES_H
  31 +#define MBED_PERIPHERALNAMES_H
  32 +
  33 +#include "cmsis.h"
  34 +
  35 +#ifdef __cplusplus
  36 +extern "C" {
  37 +#endif
  38 +
  39 +typedef enum {
  40 + ADC_1 = (int)ADC1_BASE
  41 +} ADCName;
  42 +
  43 +typedef enum {
  44 + UART_1 = (int)USART1_BASE,
  45 + UART_2 = (int)USART2_BASE,
  46 + UART_6 = (int)USART6_BASE
  47 +} UARTName;
  48 +
  49 +#define STDIO_UART_TX PA_2
  50 +#define STDIO_UART_RX PA_3
  51 +#define STDIO_UART UART_2
  52 +
  53 +typedef enum {
  54 + SPI_1 = (int)SPI1_BASE,
  55 + SPI_2 = (int)SPI2_BASE,
  56 + SPI_3 = (int)SPI3_BASE,
  57 + SPI_4 = (int)SPI4_BASE
  58 +} SPIName;
  59 +
  60 +typedef enum {
  61 + I2C_1 = (int)I2C1_BASE,
  62 + I2C_2 = (int)I2C2_BASE,
  63 + I2C_3 = (int)I2C3_BASE
  64 +} I2CName;
  65 +
  66 +typedef enum {
  67 + PWM_1 = (int)TIM1_BASE,
  68 + PWM_2 = (int)TIM2_BASE,
  69 + PWM_3 = (int)TIM3_BASE,
  70 + PWM_4 = (int)TIM4_BASE,
  71 + PWM_5 = (int)TIM5_BASE,
  72 + PWM_9 = (int)TIM9_BASE,
  73 + PWM_10 = (int)TIM10_BASE,
  74 + PWM_11 = (int)TIM11_BASE
  75 +} PWMName;
  76 +
  77 +#ifdef __cplusplus
  78 +}
  79 +#endif
  80 +
  81 +#endif
... ...
mbed/TARGET_NUCLEO_F401RE/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F401RE/PinNames.h 0 → 100644
... ... @@ -0,0 +1,186 @@
  1 +/* mbed Microcontroller Library
  2 + *******************************************************************************
  3 + * Copyright (c) 2014, STMicroelectronics
  4 + * All rights reserved.
  5 + *
  6 + * Redistribution and use in source and binary forms, with or without
  7 + * modification, are permitted provided that the following conditions are met:
  8 + *
  9 + * 1. Redistributions of source code must retain the above copyright notice,
  10 + * this list of conditions and the following disclaimer.
  11 + * 2. Redistributions in binary form must reproduce the above copyright notice,
  12 + * this list of conditions and the following disclaimer in the documentation
  13 + * and/or other materials provided with the distribution.
  14 + * 3. Neither the name of STMicroelectronics nor the names of its contributors
  15 + * may be used to endorse or promote products derived from this software
  16 + * without specific prior written permission.
  17 + *
  18 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  19 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21 + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  22 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  23 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  24 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  25 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  26 + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  27 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28 + *******************************************************************************
  29 + */
  30 +#ifndef MBED_PINNAMES_H
  31 +#define MBED_PINNAMES_H
  32 +
  33 +#include "cmsis.h"
  34 +
  35 +#ifdef __cplusplus
  36 +extern "C" {
  37 +#endif
  38 +
  39 +// See stm32f4xx_hal_gpio.h and stm32f4xx_hal_gpio_ex.h for values of MODE, PUPD and AFNUM
  40 +#define STM_PIN_DATA(MODE, PUPD, AFNUM) ((int)(((AFNUM) << 7) | ((PUPD) << 4) | ((MODE) << 0)))
  41 +#define STM_PIN_DATA_EXT(MODE, PUPD, AFNUM, CHANNEL, INVERTED) ((int)(((INVERTED & 0x01) << 15) | ((CHANNEL & 0x0F) << 11) | ((AFNUM & 0x0F) << 7) | ((PUPD & 0x07) << 4) | ((MODE & 0x0F) << 0)))
  42 +#define STM_PIN_MODE(X) (((X) >> 0) & 0x0F)
  43 +#define STM_PIN_PUPD(X) (((X) >> 4) & 0x07)
  44 +#define STM_PIN_AFNUM(X) (((X) >> 7) & 0x0F)
  45 +#define STM_PIN_AFNUM(X) (((X) >> 7) & 0x0F)
  46 +#define STM_PIN_CHANNEL(X) (((X) >> 11) & 0x0F)
  47 +#define STM_PIN_INVERTED(X) (((X) >> 15) & 0x01)
  48 +#define STM_MODE_INPUT (0)
  49 +#define STM_MODE_OUTPUT_PP (1)
  50 +#define STM_MODE_OUTPUT_OD (2)
  51 +#define STM_MODE_AF_PP (3)
  52 +#define STM_MODE_AF_OD (4)
  53 +#define STM_MODE_ANALOG (5)
  54 +#define STM_MODE_IT_RISING (6)
  55 +#define STM_MODE_IT_FALLING (7)
  56 +#define STM_MODE_IT_RISING_FALLING (8)
  57 +#define STM_MODE_EVT_RISING (9)
  58 +#define STM_MODE_EVT_FALLING (10)
  59 +#define STM_MODE_EVT_RISING_FALLING (11)
  60 +#define STM_MODE_IT_EVT_RESET (12)
  61 +
  62 +// High nibble = port number (0=A, 1=B, 2=C, 3=D, 4=E, 5=F, 6=G, 7=H)
  63 +// Low nibble = pin number
  64 +#define STM_PORT(X) (((uint32_t)(X) >> 4) & 0xF)
  65 +#define STM_PIN(X) ((uint32_t)(X) & 0xF)
  66 +
  67 +typedef enum {
  68 + PIN_INPUT,
  69 + PIN_OUTPUT
  70 +} PinDirection;
  71 +
  72 +typedef enum {
  73 + PA_0 = 0x00,
  74 + PA_1 = 0x01,
  75 + PA_2 = 0x02,
  76 + PA_3 = 0x03,
  77 + PA_4 = 0x04,
  78 + PA_5 = 0x05,
  79 + PA_6 = 0x06,
  80 + PA_7 = 0x07,
  81 + PA_8 = 0x08,
  82 + PA_9 = 0x09,
  83 + PA_10 = 0x0A,
  84 + PA_11 = 0x0B,
  85 + PA_12 = 0x0C,
  86 + PA_13 = 0x0D,
  87 + PA_14 = 0x0E,
  88 + PA_15 = 0x0F,
  89 +
  90 + PB_0 = 0x10,
  91 + PB_1 = 0x11,
  92 + PB_2 = 0x12,
  93 + PB_3 = 0x13,
  94 + PB_4 = 0x14,
  95 + PB_5 = 0x15,
  96 + PB_6 = 0x16,
  97 + PB_7 = 0x17,
  98 + PB_8 = 0x18,
  99 + PB_9 = 0x19,
  100 + PB_10 = 0x1A,
  101 + PB_12 = 0x1C,
  102 + PB_13 = 0x1D,
  103 + PB_14 = 0x1E,
  104 + PB_15 = 0x1F,
  105 +
  106 + PC_0 = 0x20,
  107 + PC_1 = 0x21,
  108 + PC_2 = 0x22,
  109 + PC_3 = 0x23,
  110 + PC_4 = 0x24,
  111 + PC_5 = 0x25,
  112 + PC_6 = 0x26,
  113 + PC_7 = 0x27,
  114 + PC_8 = 0x28,
  115 + PC_9 = 0x29,
  116 + PC_10 = 0x2A,
  117 + PC_11 = 0x2B,
  118 + PC_12 = 0x2C,
  119 + PC_13 = 0x2D,
  120 + PC_14 = 0x2E,
  121 + PC_15 = 0x2F,
  122 +
  123 + PD_2 = 0x32,
  124 +
  125 + PH_0 = 0x70,
  126 + PH_1 = 0x71,
  127 +
  128 + // Arduino connector namings
  129 + A0 = PA_0,
  130 + A1 = PA_1,
  131 + A2 = PA_4,
  132 + A3 = PB_0,
  133 + A4 = PC_1,
  134 + A5 = PC_0,
  135 + D0 = PA_3,
  136 + D1 = PA_2,
  137 + D2 = PA_10,
  138 + D3 = PB_3,
  139 + D4 = PB_5,
  140 + D5 = PB_4,
  141 + D6 = PB_10,
  142 + D7 = PA_8,
  143 + D8 = PA_9,
  144 + D9 = PC_7,
  145 + D10 = PB_6,
  146 + D11 = PA_7,
  147 + D12 = PA_6,
  148 + D13 = PA_5,
  149 + D14 = PB_9,
  150 + D15 = PB_8,
  151 +
  152 + // Generic signals namings
  153 + LED1 = PA_5,
  154 + LED2 = PA_5,
  155 + LED3 = PA_5,
  156 + LED4 = PA_5,
  157 + USER_BUTTON = PC_13,
  158 + SERIAL_TX = PA_2,
  159 + SERIAL_RX = PA_3,
  160 + USBTX = PA_2,
  161 + USBRX = PA_3,
  162 + I2C_SCL = PB_8,
  163 + I2C_SDA = PB_9,
  164 + SPI_MOSI = PA_7,
  165 + SPI_MISO = PA_6,
  166 + SPI_SCK = PA_5,
  167 + SPI_CS = PB_6,
  168 + PWM_OUT = PB_3,
  169 +
  170 + // Not connected
  171 + NC = (int)0xFFFFFFFF
  172 +} PinName;
  173 +
  174 +typedef enum {
  175 + PullNone = 0,
  176 + PullUp = 1,
  177 + PullDown = 2,
  178 + OpenDrain = 3,
  179 + PullDefault = PullNone
  180 +} PinMode;
  181 +
  182 +#ifdef __cplusplus
  183 +}
  184 +#endif
  185 +
  186 +#endif
... ...
mbed/TARGET_NUCLEO_F401RE/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F401RE/PortNames.h 0 → 100644
... ... @@ -0,0 +1,49 @@
  1 +/* mbed Microcontroller Library
  2 + *******************************************************************************
  3 + * Copyright (c) 2014, STMicroelectronics
  4 + * All rights reserved.
  5 + *
  6 + * Redistribution and use in source and binary forms, with or without
  7 + * modification, are permitted provided that the following conditions are met:
  8 + *
  9 + * 1. Redistributions of source code must retain the above copyright notice,
  10 + * this list of conditions and the following disclaimer.
  11 + * 2. Redistributions in binary form must reproduce the above copyright notice,
  12 + * this list of conditions and the following disclaimer in the documentation
  13 + * and/or other materials provided with the distribution.
  14 + * 3. Neither the name of STMicroelectronics nor the names of its contributors
  15 + * may be used to endorse or promote products derived from this software
  16 + * without specific prior written permission.
  17 + *
  18 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  19 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21 + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  22 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  23 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  24 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  25 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  26 + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  27 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28 + *******************************************************************************
  29 + */
  30 +#ifndef MBED_PORTNAMES_H
  31 +#define MBED_PORTNAMES_H
  32 +
  33 +#ifdef __cplusplus
  34 +extern "C" {
  35 +#endif
  36 +
  37 +typedef enum {
  38 + PortA = 0,
  39 + PortB = 1,
  40 + PortC = 2,
  41 + PortD = 3,
  42 + PortE = 4,
  43 + PortH = 7
  44 +} PortName;
  45 +
  46 +#ifdef __cplusplus
  47 +}
  48 +#endif
  49 +#endif
... ...
mbed/TARGET_NUCLEO_F401RE/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F401RE/device.h 0 → 100644
... ... @@ -0,0 +1,71 @@
  1 +/* mbed Microcontroller Library
  2 + *******************************************************************************
  3 + * Copyright (c) 2014, STMicroelectronics
  4 + * All rights reserved.
  5 + *
  6 + * Redistribution and use in source and binary forms, with or without
  7 + * modification, are permitted provided that the following conditions are met:
  8 + *
  9 + * 1. Redistributions of source code must retain the above copyright notice,
  10 + * this list of conditions and the following disclaimer.
  11 + * 2. Redistributions in binary form must reproduce the above copyright notice,
  12 + * this list of conditions and the following disclaimer in the documentation
  13 + * and/or other materials provided with the distribution.
  14 + * 3. Neither the name of STMicroelectronics nor the names of its contributors
  15 + * may be used to endorse or promote products derived from this software
  16 + * without specific prior written permission.
  17 + *
  18 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  19 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21 + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  22 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  23 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  24 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  25 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  26 + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  27 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28 + *******************************************************************************
  29 + */
  30 +#ifndef MBED_DEVICE_H
  31 +#define MBED_DEVICE_H
  32 +
  33 +#define DEVICE_PORTIN 1
  34 +#define DEVICE_PORTOUT 1
  35 +#define DEVICE_PORTINOUT 1
  36 +
  37 +#define DEVICE_INTERRUPTIN 1
  38 +
  39 +#define DEVICE_ANALOGIN 1
  40 +#define DEVICE_ANALOGOUT 0 // Not present on this device
  41 +
  42 +#define DEVICE_SERIAL 1
  43 +
  44 +#define DEVICE_I2C 1
  45 +#define DEVICE_I2CSLAVE 1
  46 +
  47 +#define DEVICE_SPI 1
  48 +#define DEVICE_SPISLAVE 1
  49 +
  50 +#define DEVICE_RTC 1
  51 +
  52 +#define DEVICE_PWMOUT 1
  53 +
  54 +#define DEVICE_SLEEP 1
  55 +
  56 +//=======================================
  57 +
  58 +#define DEVICE_SEMIHOST 0
  59 +#define DEVICE_LOCALFILESYSTEM 0
  60 +#define DEVICE_ID_LENGTH 24
  61 +
  62 +#define DEVICE_DEBUG_AWARENESS 0
  63 +
  64 +#define DEVICE_STDIO_MESSAGES 1
  65 +
  66 +#define DEVICE_ERROR_RED 1
  67 +#define LED_RED LED1
  68 +
  69 +#include "objects.h"
  70 +
  71 +#endif
... ...
mbed/TARGET_NUCLEO_F401RE/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F401RE/objects.h 0 → 100644
... ... @@ -0,0 +1,108 @@
  1 +/* mbed Microcontroller Library
  2 + *******************************************************************************
  3 + * Copyright (c) 2014, STMicroelectronics
  4 + * All rights reserved.
  5 + *
  6 + * Redistribution and use in source and binary forms, with or without
  7 + * modification, are permitted provided that the following conditions are met:
  8 + *
  9 + * 1. Redistributions of source code must retain the above copyright notice,
  10 + * this list of conditions and the following disclaimer.
  11 + * 2. Redistributions in binary form must reproduce the above copyright notice,
  12 + * this list of conditions and the following disclaimer in the documentation
  13 + * and/or other materials provided with the distribution.
  14 + * 3. Neither the name of STMicroelectronics nor the names of its contributors
  15 + * may be used to endorse or promote products derived from this software
  16 + * without specific prior written permission.
  17 + *
  18 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  19 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21 + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  22 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  23 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  24 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  25 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  26 + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  27 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28 + *******************************************************************************
  29 + */
  30 +#ifndef MBED_OBJECTS_H
  31 +#define MBED_OBJECTS_H
  32 +
  33 +#include "cmsis.h"
  34 +#include "PortNames.h"
  35 +#include "PeripheralNames.h"
  36 +#include "PinNames.h"
  37 +
  38 +#ifdef __cplusplus
  39 +extern "C" {
  40 +#endif
  41 +
  42 +struct gpio_irq_s {
  43 + IRQn_Type irq_n;
  44 + uint32_t irq_index;
  45 + uint32_t event;
  46 + PinName pin;
  47 +};
  48 +
  49 +struct port_s {
  50 + PortName port;
  51 + uint32_t mask;
  52 + PinDirection direction;
  53 + __IO uint32_t *reg_in;
  54 + __IO uint32_t *reg_out;
  55 +};
  56 +
  57 +struct analogin_s {
  58 + ADCName adc;
  59 + PinName pin;
  60 + uint8_t channel;
  61 +};
  62 +
  63 +struct serial_s {
  64 + UARTName uart;
  65 + int index; // Used by irq
  66 + uint32_t baudrate;
  67 + uint32_t databits;
  68 + uint32_t stopbits;
  69 + uint32_t parity;
  70 + PinName pin_tx;
  71 + PinName pin_rx;
  72 +};
  73 +
  74 +struct spi_s {
  75 + SPIName spi;
  76 + uint32_t bits;
  77 + uint32_t cpol;
  78 + uint32_t cpha;
  79 + uint32_t mode;
  80 + uint32_t nss;
  81 + uint32_t br_presc;
  82 + PinName pin_miso;
  83 + PinName pin_mosi;
  84 + PinName pin_sclk;
  85 + PinName pin_ssel;
  86 +};
  87 +
  88 +struct i2c_s {
  89 + I2CName i2c;
  90 + uint32_t slave;
  91 +};
  92 +
  93 +struct pwmout_s {
  94 + PWMName pwm;
  95 + PinName pin;
  96 + uint32_t period;
  97 + uint32_t pulse;
  98 + uint8_t channel;
  99 + uint8_t inverted;
  100 +};
  101 +
  102 +#include "gpio_object.h"
  103 +
  104 +#ifdef __cplusplus
  105 +}
  106 +#endif
  107 +
  108 +#endif
... ...
mbed/TARGET_NUCLEO_F401RE/TARGET_STM/TARGET_STM32F4/gpio_object.h 0 → 100644
... ... @@ -0,0 +1,74 @@
  1 +/* mbed Microcontroller Library
  2 + *******************************************************************************
  3 + * Copyright (c) 2014, STMicroelectronics
  4 + * All rights reserved.
  5 + *
  6 + * Redistribution and use in source and binary forms, with or without
  7 + * modification, are permitted provided that the following conditions are met:
  8 + *
  9 + * 1. Redistributions of source code must retain the above copyright notice,
  10 + * this list of conditions and the following disclaimer.
  11 + * 2. Redistributions in binary form must reproduce the above copyright notice,
  12 + * this list of conditions and the following disclaimer in the documentation
  13 + * and/or other materials provided with the distribution.
  14 + * 3. Neither the name of STMicroelectronics nor the names of its contributors
  15 + * may be used to endorse or promote products derived from this software
  16 + * without specific prior written permission.
  17 + *
  18 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  19 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21 + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  22 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  23 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  24 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  25 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  26 + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  27 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28 + *******************************************************************************
  29 + */
  30 +#ifndef MBED_GPIO_OBJECT_H
  31 +#define MBED_GPIO_OBJECT_H
  32 +
  33 +#include "mbed_assert.h"
  34 +#include "cmsis.h"
  35 +#include "PortNames.h"
  36 +#include "PeripheralNames.h"
  37 +#include "PinNames.h"
  38 +
  39 +#ifdef __cplusplus
  40 +extern "C" {
  41 +#endif
  42 +
  43 +typedef struct {
  44 + PinName pin;
  45 + uint32_t mask;
  46 + __IO uint32_t *reg_in;
  47 + __IO uint32_t *reg_set_clr;
  48 +} gpio_t;
  49 +
  50 +static inline void gpio_write(gpio_t *obj, int value)
  51 +{
  52 + MBED_ASSERT(obj->pin != (PinName)NC);
  53 + if (value) {
  54 + *obj->reg_set_clr = obj->mask;
  55 + } else {
  56 + *obj->reg_set_clr = obj->mask << 16;
  57 + }
  58 +}
  59 +
  60 +static inline int gpio_read(gpio_t *obj)
  61 +{
  62 + MBED_ASSERT(obj->pin != (PinName)NC);
  63 + return ((*obj->reg_in & obj->mask) ? 1 : 0);
  64 +}
  65 +
  66 +static inline int gpio_is_connected(const gpio_t *obj) {
  67 + return obj->pin != (PinName)NC;
  68 +}
  69 +
  70 +#ifdef __cplusplus
  71 +}
  72 +#endif
  73 +
  74 +#endif
... ...
mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/STM32F401XE.ld 0 → 100644
... ... @@ -0,0 +1,153 @@
  1 +/* Linker script to configure memory regions. */
  2 +MEMORY
  3 +{
  4 + FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 512K
  5 + RAM (rwx) : ORIGIN = 0x20000194, LENGTH = 96k - 0x194
  6 +}
  7 +
  8 +/* Linker script to place sections and symbol values. Should be used together
  9 + * with other linker script that defines memory regions FLASH and RAM.
  10 + * It references following symbols, which must be defined in code:
  11 + * Reset_Handler : Entry of reset handler
  12 + *
  13 + * It defines following symbols, which code can use without definition:
  14 + * __exidx_start
  15 + * __exidx_end
  16 + * __etext
  17 + * __data_start__
  18 + * __preinit_array_start
  19 + * __preinit_array_end
  20 + * __init_array_start
  21 + * __init_array_end
  22 + * __fini_array_start
  23 + * __fini_array_end
  24 + * __data_end__
  25 + * __bss_start__
  26 + * __bss_end__
  27 + * __end__
  28 + * end
  29 + * __HeapLimit
  30 + * __StackLimit
  31 + * __StackTop
  32 + * __stack
  33 + * _estack
  34 + */
  35 +ENTRY(Reset_Handler)
  36 +
  37 +SECTIONS
  38 +{
  39 + .text :
  40 + {
  41 + KEEP(*(.isr_vector))
  42 + *(.text*)
  43 + KEEP(*(.init))
  44 + KEEP(*(.fini))
  45 +
  46 + /* .ctors */
  47 + *crtbegin.o(.ctors)
  48 + *crtbegin?.o(.ctors)
  49 + *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
  50 + *(SORT(.ctors.*))
  51 + *(.ctors)
  52 +
  53 + /* .dtors */
  54 + *crtbegin.o(.dtors)
  55 + *crtbegin?.o(.dtors)
  56 + *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
  57 + *(SORT(.dtors.*))
  58 + *(.dtors)
  59 +
  60 + *(.rodata*)
  61 +
  62 + KEEP(*(.eh_frame*))
  63 + } > FLASH
  64 +
  65 + .ARM.extab :
  66 + {
  67 + *(.ARM.extab* .gnu.linkonce.armextab.*)
  68 + } > FLASH
  69 +
  70 + __exidx_start = .;
  71 + .ARM.exidx :
  72 + {
  73 + *(.ARM.exidx* .gnu.linkonce.armexidx.*)
  74 + } > FLASH
  75 + __exidx_end = .;
  76 +
  77 + __etext = .;
  78 + _sidata = .;
  79 +
  80 + .data : AT (__etext)
  81 + {
  82 + __data_start__ = .;
  83 + _sdata = .;
  84 + *(vtable)
  85 + *(.data*)
  86 +
  87 + . = ALIGN(4);
  88 + /* preinit data */
  89 + PROVIDE_HIDDEN (__preinit_array_start = .);
  90 + KEEP(*(.preinit_array))
  91 + PROVIDE_HIDDEN (__preinit_array_end = .);
  92 +
  93 + . = ALIGN(4);
  94 + /* init data */
  95 + PROVIDE_HIDDEN (__init_array_start = .);
  96 + KEEP(*(SORT(.init_array.*)))
  97 + KEEP(*(.init_array))
  98 + PROVIDE_HIDDEN (__init_array_end = .);
  99 +
  100 +
  101 + . = ALIGN(4);
  102 + /* finit data */
  103 + PROVIDE_HIDDEN (__fini_array_start = .);
  104 + KEEP(*(SORT(.fini_array.*)))
  105 + KEEP(*(.fini_array))
  106 + PROVIDE_HIDDEN (__fini_array_end = .);
  107 +
  108 + KEEP(*(.jcr*))
  109 + . = ALIGN(4);
  110 + /* All data end */
  111 + __data_end__ = .;
  112 + _edata = .;
  113 +
  114 + } > RAM
  115 +
  116 + .bss :
  117 + {
  118 + . = ALIGN(4);
  119 + __bss_start__ = .;
  120 + _sbss = .;
  121 + *(.bss*)
  122 + *(COMMON)
  123 + . = ALIGN(4);
  124 + __bss_end__ = .;
  125 + _ebss = .;
  126 + } > RAM
  127 +
  128 + .heap (COPY):
  129 + {
  130 + __end__ = .;
  131 + end = __end__;
  132 + *(.heap*)
  133 + __HeapLimit = .;
  134 + } > RAM
  135 +
  136 + /* .stack_dummy section doesn't contains any symbols. It is only
  137 + * used for linker to calculate size of stack sections, and assign
  138 + * values to stack symbols later */
  139 + .stack_dummy (COPY):
  140 + {
  141 + *(.stack*)
  142 + } > RAM
  143 +
  144 + /* Set stack top to end of RAM, and stack limit move down by
  145 + * size of stack_dummy section */
  146 + __StackTop = ORIGIN(RAM) + LENGTH(RAM);
  147 + _estack = __StackTop;
  148 + __StackLimit = __StackTop - SIZEOF(.stack_dummy);
  149 + PROVIDE(__stack = __StackTop);
  150 +
  151 + /* Check if data + heap + stack exceeds RAM limit */
  152 + ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack")
  153 +}
... ...
mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/board.o 0 → 100644
No preview for this file type
mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/cmsis_nvic.o 0 → 100644
No preview for this file type
mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/hal_tick.o 0 → 100644
No preview for this file type
mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/libmbed.a 0 → 100644
No preview for this file type
mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/mbed_overrides.o 0 → 100644
No preview for this file type
mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/retarget.o 0 → 100644
No preview for this file type
mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/startup_stm32f401xe.o 0 → 100644
No preview for this file type
mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal.o 0 → 100644
No preview for this file type
mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_adc.o 0 → 100644
No preview for this file type
mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_adc_ex.o 0 → 100644
No preview for this file type
mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_can.o 0 → 100644
No preview for this file type
mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_cec.o 0 → 100644
No preview for this file type
mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_cortex.o 0 → 100644
No preview for this file type
mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_crc.o 0 → 100644
No preview for this file type
mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_cryp.o 0 → 100644
No preview for this file type
mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_cryp_ex.o 0 → 100644
No preview for this file type
mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_dac.o 0 → 100644
No preview for this file type
mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_dac_ex.o 0 → 100644
No preview for this file type
mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_dcmi.o 0 → 100644
No preview for this file type
mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_dcmi_ex.o 0 → 100644
No preview for this file type
mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_dma.o 0 → 100644
No preview for this file type
mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_dma2d.o 0 → 100644
No preview for this file type
mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_dma_ex.o 0 → 100644
No preview for this file type
mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_dsi.o 0 → 100644
No preview for this file type
mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_eth.o 0 → 100644
No preview for this file type
mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_flash.o 0 → 100644
No preview for this file type
mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_flash_ex.o 0 → 100644
No preview for this file type
mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_flash_ramfunc.o 0 → 100644
No preview for this file type
mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_fmpi2c.o 0 → 100644
No preview for this file type
mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_fmpi2c_ex.o 0 → 100644
No preview for this file type
mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_gpio.o 0 → 100644
No preview for this file type
mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_hash.o 0 → 100644
No preview for this file type
mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_hash_ex.o 0 → 100644
No preview for this file type
mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_hcd.o 0 → 100644
No preview for this file type
mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_i2c.o 0 → 100644
No preview for this file type
mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_i2c_ex.o 0 → 100644
No preview for this file type