├── src ├── rf │ ├── Makefile │ └── src │ │ ├── rf_src.h │ │ ├── rf_spi_configure_enable.c │ │ ├── rf_transmit.c │ │ ├── rf_is_rpd_active.c │ │ ├── rf_set_rf_channel.c │ │ ├── rf_rx_fifo_is_full.c │ │ ├── rf_tx_fifo_is_full.c │ │ ├── rf_irq_clear.c │ │ ├── rf_rx_fifo_is_empty.c │ │ ├── rf_tx_fifo_is_empty.c │ │ ├── rf_set_tx_addr.c │ │ ├── rf_irq_clear_all.c │ │ ├── rf_read_rx_payload.c │ │ ├── rf_read_register_1_byte.c │ │ ├── rf_read_rx_payload_width.c │ │ ├── rf_set_output_power.c │ │ ├── rf_spi_send_read_byte.c │ │ ├── rf_power_down_param.c │ │ ├── rf_power_down.c │ │ ├── rf_write_tx_ack_payload.c │ │ ├── rf_power_up.c │ │ ├── rf_read_register.c │ │ ├── rf_write_register.c │ │ ├── rf_set_data_rate.c │ │ ├── rf_set_rx_addr.c │ │ ├── rf_set_as_tx.c │ │ ├── rf_spi_send_read.c │ │ ├── rf_write_tx_payload_noack.c │ │ └── rf_write_tx_payload.c ├── w2 │ ├── Makefile │ └── src │ │ ├── w2_wait_for_byte_tx_or_rx.c │ │ ├── w2_master_process_stop_request.c │ │ └── w2_master_process_start_request.c ├── acomp │ └── Makefile ├── adc │ ├── Makefile │ └── src │ │ ├── adc_set_input_channel.c │ │ ├── adc_start_single_conversion.c │ │ └── adc_start_single_conversion_get_value.c ├── delay │ ├── Makefile │ └── src │ │ ├── delay_s.c │ │ ├── delay_ms.c │ │ └── delay_us.c ├── gpio │ ├── Makefile │ └── src │ │ ├── gpio_pin_val_write.c │ │ ├── gpio_pin_val_set.c │ │ ├── gpio_pin_val_clear.c │ │ ├── gpio_pin_val_complement.c │ │ └── gpio_pin_val_read.c ├── memory │ ├── Makefile │ └── src │ │ └── memory_flash_erase_page.c ├── mspi │ ├── Makefile │ └── src │ │ ├── mspi_read_write.c │ │ └── mspi_configure.c ├── owi │ ├── Makefile │ └── src │ │ ├── owi_skip_rom.c │ │ ├── owi_crc.c │ │ ├── owi_write_bit_0.c │ │ ├── owi_write_bit_1.c │ │ ├── owi_match_rom.c │ │ ├── owi_read_rom.c │ │ ├── owi_check_rom.c │ │ ├── owi_check_scratchpad.c │ │ ├── owi_send_byte.c │ │ ├── owi_receive_byte.c │ │ ├── owi_pin_configure.c │ │ ├── owi_read_bit.c │ │ └── owi_detect_presence.c ├── pwm │ ├── Makefile │ └── src │ │ ├── pwm_stop.c │ │ ├── pwm_configure.c │ │ └── pwm_start.c ├── rng │ ├── Makefile │ └── src │ │ ├── rng_get_next_byte.c │ │ ├── rng_get_one_byte_and_turn_off.c │ │ └── rng_configure.c ├── rtc2 │ ├── Makefile │ └── src │ │ └── rtc2_set_compare_val.c ├── sspi │ ├── Makefile │ └── src │ │ ├── sspi_configure.c │ │ └── sspi_read_write.c ├── timer0 │ └── Makefile ├── timer1 │ └── Makefile ├── timer2 │ ├── Makefile │ └── src │ │ └── timer2_calc_actual_period.c ├── uart │ ├── Makefile │ └── src │ │ ├── putchar.c │ │ ├── uart_wait_for_rx_and_get.c │ │ ├── uart_send_wait_for_complete.c │ │ ├── uart_calc_th1_value.c │ │ ├── uart_calc_actual_baud_rate_from_th1.c │ │ └── uart_calc_s0rel_value.c ├── interrupt │ └── Makefile ├── pwr_clk_mgmt │ ├── Makefile │ └── src │ │ ├── pwr_clk_mgmt_cclk_configure.c │ │ ├── pwr_clk_mgmt_wakeup_sources_configure.c │ │ ├── pwr_clk_mgmt_wakeup_pins_configure.c │ │ ├── pwr_clk_mgmt_get_cclk_freq_in_hz.c │ │ ├── pwr_clk_mgmt_get_cclk_freq_in_khz.c │ │ ├── pwr_clk_mgmt_clklf_configure.c │ │ ├── pwr_clk_mgmt_op_mode_configure.c │ │ └── pwr_clk_mgmt_pwr_failure_configure.c └── watchdog │ ├── Makefile │ └── src │ └── watchdog_cause_software_reset.c ├── _target_sdcc_nrf24le1_24 ├── Makefile ├── MakefileSrc └── include │ └── target_nrf24le1_sdk.h ├── _target_sdcc_nrf24le1_32 ├── Makefile ├── MakefileSrc └── include │ └── target_nrf24le1_sdk.h ├── _target_sdcc_nrf24le1_48 ├── Makefile ├── MakefileSrc └── include │ └── target_nrf24le1_sdk.h ├── README.md ├── .gitignore ├── Makefile └── include ├── inline ├── watchdog_setup.inc ├── watchdog_calc.inc ├── watchdog_get_wdsv_count.inc └── watchdog_set_wdsv_count.inc ├── delay.h └── watchdog.h /src/rf/Makefile: -------------------------------------------------------------------------------- 1 | include $(TARGETSRCMAKEFILE) 2 | -------------------------------------------------------------------------------- /src/w2/Makefile: -------------------------------------------------------------------------------- 1 | include $(TARGETSRCMAKEFILE) 2 | -------------------------------------------------------------------------------- /src/acomp/Makefile: -------------------------------------------------------------------------------- 1 | include $(TARGETSRCMAKEFILE) 2 | -------------------------------------------------------------------------------- /src/adc/Makefile: -------------------------------------------------------------------------------- 1 | include $(TARGETSRCMAKEFILE) 2 | -------------------------------------------------------------------------------- /src/delay/Makefile: -------------------------------------------------------------------------------- 1 | include $(TARGETSRCMAKEFILE) 2 | -------------------------------------------------------------------------------- /src/gpio/Makefile: -------------------------------------------------------------------------------- 1 | include $(TARGETSRCMAKEFILE) 2 | -------------------------------------------------------------------------------- /src/memory/Makefile: -------------------------------------------------------------------------------- 1 | include $(TARGETSRCMAKEFILE) 2 | -------------------------------------------------------------------------------- /src/mspi/Makefile: -------------------------------------------------------------------------------- 1 | include $(TARGETSRCMAKEFILE) 2 | -------------------------------------------------------------------------------- /src/owi/Makefile: -------------------------------------------------------------------------------- 1 | include $(TARGETSRCMAKEFILE) 2 | -------------------------------------------------------------------------------- /src/pwm/Makefile: -------------------------------------------------------------------------------- 1 | include $(TARGETSRCMAKEFILE) 2 | -------------------------------------------------------------------------------- /src/rng/Makefile: -------------------------------------------------------------------------------- 1 | include $(TARGETSRCMAKEFILE) 2 | -------------------------------------------------------------------------------- /src/rtc2/Makefile: -------------------------------------------------------------------------------- 1 | include $(TARGETSRCMAKEFILE) 2 | -------------------------------------------------------------------------------- /src/sspi/Makefile: -------------------------------------------------------------------------------- 1 | include $(TARGETSRCMAKEFILE) 2 | -------------------------------------------------------------------------------- /src/timer0/Makefile: -------------------------------------------------------------------------------- 1 | include $(TARGETSRCMAKEFILE) 2 | -------------------------------------------------------------------------------- /src/timer1/Makefile: -------------------------------------------------------------------------------- 1 | include $(TARGETSRCMAKEFILE) 2 | -------------------------------------------------------------------------------- /src/timer2/Makefile: -------------------------------------------------------------------------------- 1 | include $(TARGETSRCMAKEFILE) 2 | -------------------------------------------------------------------------------- /src/uart/Makefile: -------------------------------------------------------------------------------- 1 | include $(TARGETSRCMAKEFILE) 2 | -------------------------------------------------------------------------------- /src/interrupt/Makefile: -------------------------------------------------------------------------------- 1 | include $(TARGETSRCMAKEFILE) 2 | -------------------------------------------------------------------------------- /src/pwr_clk_mgmt/Makefile: -------------------------------------------------------------------------------- 1 | include $(TARGETSRCMAKEFILE) 2 | -------------------------------------------------------------------------------- /src/watchdog/Makefile: -------------------------------------------------------------------------------- 1 | include $(TARGETSRCMAKEFILE) 2 | -------------------------------------------------------------------------------- /_target_sdcc_nrf24le1_24/Makefile: -------------------------------------------------------------------------------- 1 | include ../MakefileTarget.mk 2 | -------------------------------------------------------------------------------- /_target_sdcc_nrf24le1_32/Makefile: -------------------------------------------------------------------------------- 1 | include ../MakefileTarget.mk 2 | -------------------------------------------------------------------------------- /_target_sdcc_nrf24le1_48/Makefile: -------------------------------------------------------------------------------- 1 | include ../MakefileTarget.mk 2 | -------------------------------------------------------------------------------- /_target_sdcc_nrf24le1_24/MakefileSrc: -------------------------------------------------------------------------------- 1 | include ../../MakefileSrc.mk 2 | -------------------------------------------------------------------------------- /_target_sdcc_nrf24le1_32/MakefileSrc: -------------------------------------------------------------------------------- 1 | include ../../MakefileSrc.mk 2 | -------------------------------------------------------------------------------- /_target_sdcc_nrf24le1_48/MakefileSrc: -------------------------------------------------------------------------------- 1 | include ../../MakefileSrc.mk 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | nRF24LE1_SDK 2 | ============ 3 | 4 | SDK for the Nordic nRF24LE1 for use with SDCC 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Object files 2 | *.o 3 | *.ko 4 | 5 | # Libraries 6 | *.lib 7 | *.a 8 | 9 | # SDCC stuff 10 | *.lnk 11 | *.lst 12 | *.map 13 | *.mem 14 | *.rel 15 | *.rst 16 | *.sym 17 | *.asm 18 | 19 | */dep/ 20 | */lib/ 21 | */obj/ 22 | 23 | # Shared objects (inc. Windows DLLs) 24 | *.dll 25 | *.so 26 | *.so.* 27 | *.dylib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | 34 | **/.directory 35 | .kateproject 36 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | TARGETS := $(strip $(shell ls -d _target*)) 2 | ifeq ($(TARGETS),) 3 | $(error There are no targets to clean/build) 4 | endif 5 | MAKE_PREFIX = make_ 6 | CLEAN_PREFIX = clean_ 7 | MAKE_TARGETS := $(foreach dir,$(TARGETS),$(MAKE_PREFIX)$(dir)) 8 | CLEAN_TARGETS := $(foreach dir,$(TARGETS),$(CLEAN_PREFIX)$(dir)) 9 | 10 | all: $(MAKE_TARGETS) 11 | 12 | $(MAKE_TARGETS): 13 | $(MAKE) -C ./$(subst $(MAKE_PREFIX),,$@) all 14 | 15 | clean: $(CLEAN_TARGETS) 16 | 17 | $(CLEAN_TARGETS): 18 | $(MAKE) -C ./$(subst $(CLEAN_PREFIX),,$@) clean -------------------------------------------------------------------------------- /_target_sdcc_nrf24le1_24/include/target_nrf24le1_sdk.h: -------------------------------------------------------------------------------- 1 | #ifndef TARGET_NRF24LE1_SDK_H_ 2 | #define TARGET_NRF24LE1_SDK_H_ 3 | 4 | //DO NOT include reg24le1.h here or a circular include will happen 5 | //This header file is included by reg24le1.h to provide it a package variant 6 | #define __TARG_PACKAGE_TYPE NRF24LE1_PACKAGE_24_PIN 7 | 8 | //Encryption/decryption subsystem #defines 9 | #define __TARG_ENC_DEC_ACCEL_ALLOW_INLINING 1 //If non-zero, this allows the enc_dec_accel_galois_multiply() function to be inlined (requires compiler option --std-c99) 10 | 11 | #endif /* TARGET_NRF24LE1_SDK_H_ */ 12 | -------------------------------------------------------------------------------- /_target_sdcc_nrf24le1_32/include/target_nrf24le1_sdk.h: -------------------------------------------------------------------------------- 1 | #ifndef TARGET_NRF24LE1_SDK_H_ 2 | #define TARGET_NRF24LE1_SDK_H_ 3 | 4 | //DO NOT include reg24le1.h here or a circular include will happen 5 | //This header file is included by reg24le1.h to provide it a package variant 6 | #define __TARG_PACKAGE_TYPE NRF24LE1_PACKAGE_32_PIN 7 | 8 | //Encryption/decryption subsystem #defines 9 | #define __TARG_ENC_DEC_ACCEL_ALLOW_INLINING 1 //If non-zero, this allows the enc_dec_accel_galois_multiply() function to be inlined (requires compiler option --std-c99) 10 | 11 | #endif /* TARGET_NRF24LE1_SDK_H_ */ 12 | -------------------------------------------------------------------------------- /_target_sdcc_nrf24le1_48/include/target_nrf24le1_sdk.h: -------------------------------------------------------------------------------- 1 | #ifndef TARGET_NRF24LE1_SDK_H_ 2 | #define TARGET_NRF24LE1_SDK_H_ 3 | 4 | //DO NOT include reg24le1.h here or a circular include will happen 5 | //This header file is included by reg24le1.h to provide it with a package variant 6 | #define __TARG_PACKAGE_TYPE NRF24LE1_PACKAGE_48_PIN 7 | 8 | //Encryption/decryption subsystem #defines 9 | #define __TARG_ENC_DEC_ACCEL_ALLOW_INLINING 1 //If non-zero, this allows the enc_dec_accel_galois_multiply() function to be inlined (requires compiler option --std-c99) 10 | 11 | #endif /* TARGET_NRF24LE1_SDK_H_ */ 12 | -------------------------------------------------------------------------------- /include/inline/watchdog_setup.inc: -------------------------------------------------------------------------------- 1 | #include "pwr_clk_mgmt.h" 2 | 3 | /* Setup the watchdog to start working, this mostly enables the clock source 4 | * and waits until it is initialized. 5 | * 6 | * Please note that this uses the RCOSC32K clock source and it will conflict 7 | * with other clock sources if you intend to use another source. 8 | */ 9 | inline void watchdog_setup(void) 10 | { 11 | if (!pwr_clk_mgmt_is_clklf_enabled()) 12 | { 13 | //CLKLF is not running, so enable RCOSC32K and wait until it is ready 14 | pwr_clk_mgmt_clklf_configure(PWR_CLK_MGMT_CLKLF_CONFIG_OPTION_CLK_SRC_RCOSC32K); 15 | pwr_clk_mgmt_wait_until_clklf_is_ready(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /include/delay.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: delay.h 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #ifndef DELAY_H_ 30 | #define DELAY_H_ 31 | 32 | #include "reg24le1.h" 33 | 34 | 35 | /////////////////////////////////////////// 36 | // Function prototypes 37 | /////////////////////////////////////////// 38 | void delay_us(uint16_t microseconds); 39 | void delay_ms(uint16_t milliseconds); 40 | void delay_s(uint16_t seconds); 41 | 42 | 43 | #endif /*DELAY_H_*/ 44 | -------------------------------------------------------------------------------- /include/inline/watchdog_calc.inc: -------------------------------------------------------------------------------- 1 | /* These functions calculate the watchdog value from time values in either 2 | * seconds or milliseconds. These watchdog values are then fed into 3 | * watchdog_set_wdsv_count. 4 | * 5 | * It is recommended to use it like so: 6 | * #define TIMEOUT_VAL watchdog_calc_timeout_from_sec(30) 7 | * ... 8 | * watchdog_set_wdsv_count(TIMEOUT_VAL); 9 | * 10 | * This will generate the most efficient code of simply loading the WDSV 11 | * register with the right values. 12 | * 13 | * The nRF24LE1 can only handle timeouts of at most 512 seconds, do not try to 14 | * feed higher values. There is no safety mechanism for that in the code as the 15 | * optimizer barfs on the conditional. 16 | */ 17 | 18 | inline uint16_t watchdog_calc_timeout_from_sec(uint16_t sec) 19 | { 20 | return sec * 128U; 21 | } 22 | 23 | inline uint16_t watchdog_calc_timeout_from_ms(uint32_t msec) 24 | { 25 | //From the formula on p. 104 of v1.6 of the nRF24LE1 datasheet, the equation for the watchdog timeout (in seconds) is given as 26 | // 27 | // WDSV * 256 28 | // WD_timeout (s) = ---------- 29 | // 32768 30 | // 31 | // This then reduces to 32 | // 33 | // WDSV 34 | // WD_timeout (s) = ---- 35 | // 128 36 | // 37 | // Then if we want the watchdog timeout to be in units of milliseconds 38 | // 39 | // WDSV * 1000 40 | // WD_timeout (ms) = ----------- 41 | // 128 42 | // 43 | // Solving for WDSV 44 | // 45 | // WD_timeout (ms) * 128 46 | // WDSV = --------------------- 47 | // 1000 48 | // 49 | // By adding 500 to the numerator before performing the division, the result gets rounded (as 500 is half of 1000, the denominator) 50 | msec *= 128U; 51 | msec += 500U; 52 | return (uint16_t)(msec / 1000U); 53 | } 54 | -------------------------------------------------------------------------------- /src/owi/src/owi_skip_rom.c: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: owi_skip_rom.c 4 | // 5 | // Copyright Aleksandr Svalov (Alarus), 2014 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | //////////////////////////////////////////////////////////////////////////////////// 12 | 13 | //////////////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | //////////////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "owi.h" 30 | 31 | 32 | //////////////////////////////////////////////////////////////////////////////////// 33 | // 34 | // void owi_skip_rom(gpio_pin_id_t owi_pin_id) 35 | // 36 | // Description: 37 | // Sends the SKIP ROM command to the OWI 38 | // 39 | // Parameters: 40 | // gpio_pin_id_t owi_pin_id - ID of the OWI pin 41 | // 42 | // Return value: 43 | // None 44 | // 45 | //////////////////////////////////////////////////////////////////////////////////// 46 | void owi_skip_rom(gpio_pin_id_t owi_pin_id) 47 | { 48 | // Send the SKIP ROM command on the OWI. 49 | owi_send_byte(owi_pin_id, OWI_SKIP_ROM); 50 | } 51 | -------------------------------------------------------------------------------- /src/uart/src/putchar.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: putchar.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warranty, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "uart.h" 30 | #include "interrupt.h" 31 | 32 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 33 | // 34 | // void putchar(char c) 35 | // 36 | // Description: 37 | // Allows use of stdio printf to output to uart 38 | // 39 | // Parameters: 40 | // char c - char to send over the UART 41 | // 42 | // Return value: 43 | // None 44 | // 45 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 46 | void putchar(char c) 47 | { 48 | interrupt_wait_for_uart_tx(); 49 | 50 | interrupt_clear_uart_tx(); 51 | 52 | uart_send(c); 53 | } 54 | -------------------------------------------------------------------------------- /src/rf/src/rf_src.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: rf_src.h 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #ifndef RF_SRC_H_ 30 | #define RF_SRC_H_ 31 | 32 | #include "rf.h" 33 | 34 | 35 | /////////////////////////////////////////// 36 | // Function macros 37 | /////////////////////////////////////////// 38 | #define rf_clear_csn() sbit_clear(RFCON_SB_RFCSN) //Clears the CSN pin 39 | #define rf_set_csn() sbit_set(RFCON_SB_RFCSN) //Sets the CSN pin 40 | #define rf_get_csn() RFCON_SB_RFCSN //Gets the value of the CE pin 41 | 42 | 43 | /////////////////////////////////////////// 44 | // Function prototypes 45 | /////////////////////////////////////////// 46 | void rf_spi_send_read(uint8_t * dataptr, uint16_t len, bool copydata); 47 | uint8_t rf_spi_send_read_byte(uint8_t byte); 48 | 49 | 50 | #endif /* RF_SRC_H_ */ 51 | -------------------------------------------------------------------------------- /src/rtc2/src/rtc2_set_compare_val.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: rtc2_set_compare_val.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "rtc2.h" 30 | 31 | 32 | ///////////////////////////////////////////////////////////////////////////////////////////////////////// 33 | // 34 | // void rtc2_set_compare_val(uint16_t compare_value) 35 | // 36 | // Description: 37 | // Sets the compare value for RTC2 38 | // 39 | // Parameters: 40 | // uint8_t compare_value - if using modes 2 or 3, this is the compare value 41 | // 42 | // Return value: 43 | // None 44 | // 45 | ///////////////////////////////////////////////////////////////////////////////////////////////////////// 46 | void rtc2_set_compare_val(uint16_t compare_value) 47 | { 48 | RTC2CMP0 = (uint8_t)compare_value; 49 | RTC2CMP1 = (uint8_t)(compare_value >> 8); 50 | } 51 | -------------------------------------------------------------------------------- /src/rng/src/rng_get_next_byte.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: rng_get_next_byte.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "rng.h" 30 | 31 | 32 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 33 | // 34 | // uint8_t rng_get_next_byte() 35 | // 36 | // Description: 37 | // Waits for the next RNG byte and returns it (function assumes RNG is already running) 38 | // 39 | // Parameters: 40 | // None 41 | // 42 | // Return value: 43 | // A random number 44 | // 45 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 46 | uint8_t rng_get_next_byte() 47 | { 48 | while(!rng_is_result_ready()); 49 | 50 | return rng_get_result(); 51 | } 52 | 53 | -------------------------------------------------------------------------------- /src/rf/src/rf_spi_configure_enable.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: rf_read_register.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "rf.h" 30 | #include "rf_src.h" 31 | 32 | 33 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 34 | // 35 | // void rf_spi_configure_enable() 36 | // 37 | // Description: 38 | // Enables RF SPI 39 | // 40 | // Parameters: 41 | // None 42 | // 43 | // Return value: 44 | // None 45 | // 46 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 47 | void rf_spi_configure_enable() 48 | { 49 | //The errata says you need to first write RFCON with 0x02, then you can enable the SPI pins 50 | RFCON = 0x02; 51 | RFCON = RFCON_RFCKEN; 52 | } 53 | -------------------------------------------------------------------------------- /src/rf/src/rf_transmit.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: rf_transmit.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "rf.h" 30 | #include "rf_src.h" 31 | 32 | 33 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 34 | // 35 | // void rf_transmit() 36 | // 37 | // Description: 38 | // Sets the CE pin to transmit a TX packet, then clears CE pin 39 | // 40 | // Parameters: 41 | // None 42 | // 43 | // Return value: 44 | // None 45 | // 46 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 47 | void rf_transmit() 48 | { 49 | //Set CE, hold for 10 microseconds, then clear CE to transmit only the current packet 50 | rf_set_ce(); 51 | delay_us(100); 52 | rf_clear_ce(); 53 | } 54 | -------------------------------------------------------------------------------- /include/watchdog.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: watchdog.h 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #ifndef WATCHDOG_H_ 30 | #define WATCHDOG_H_ 31 | 32 | #include "reg24le1.h" 33 | 34 | 35 | /////////////////////////////////////////// 36 | // Function prototypes 37 | /////////////////////////////////////////// 38 | //inline uint16_t watchdog_calc_timeout_from_sec(uint16_t sec); 39 | //inline uint16_t watchdog_calc_timeout_from_ms(uint32_t msec); 40 | //inline void watchdog_setup(void); 41 | //void watchdog_set_wdsv_count(uint16_t wdsv_value); 42 | //uint16_t watchdog_get_wdsv_count(); 43 | void watchdog_cause_software_reset(); 44 | 45 | #include "inline/watchdog_setup.inc" 46 | #include "inline/watchdog_calc.inc" 47 | #include "inline/watchdog_set_wdsv_count.inc" 48 | #include "inline/watchdog_get_wdsv_count.inc" 49 | 50 | #endif /* WATCHDOG_H_ */ 51 | -------------------------------------------------------------------------------- /src/rf/src/rf_is_rpd_active.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: rf_is_rpd_active.c 4 | // 5 | // Copyright S. Brennen Ball, 2012 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "rf.h" 30 | #include "rf_src.h" 31 | 32 | 33 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 34 | // 35 | // bool rf_is_rpd_active() 36 | // 37 | // Description: 38 | // Returns whether or not the RPD bit is set 39 | // 40 | // Parameters: 41 | // None 42 | // 43 | // Return value: 44 | // bool - true if RPD bit is set, false otherwise 45 | // 46 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 47 | bool rf_is_rpd_active() 48 | { 49 | uint8_t rpd; 50 | 51 | rf_read_register(RF_RPD, &rpd, 1); 52 | 53 | return (rpd & RF_RPD_RPD) ? true : false; 54 | } 55 | -------------------------------------------------------------------------------- /src/pwr_clk_mgmt/src/pwr_clk_mgmt_cclk_configure.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: pwr_clk_mgmt_cclk_configure.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "pwr_clk_mgmt.h" 30 | 31 | 32 | ///////////////////////////////////////////////////////////////////////////////////////////////////////// 33 | // 34 | // void pwr_clk_mgmt_cclk_configure(uint8_t cclk_config_options) 35 | // 36 | // Description: 37 | // Configures microcontroller system clock (CCLK) 38 | // 39 | // Parameters: 40 | // uint8_t cclk_config_options - CCLK configuration options 41 | // 42 | // Return value: 43 | // None 44 | // 45 | ///////////////////////////////////////////////////////////////////////////////////////////////////////// 46 | void pwr_clk_mgmt_cclk_configure(uint8_t cclk_config_options) 47 | { 48 | //Set up CLKCTRL register from cclk_config_options 49 | CLKCTRL = cclk_config_options; 50 | } 51 | -------------------------------------------------------------------------------- /src/rf/src/rf_set_rf_channel.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: rf_read_register.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "rf.h" 30 | #include "rf_src.h" 31 | 32 | 33 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 34 | // 35 | // void rf_set_rf_channel(uint8_t channel) 36 | // 37 | // Description: 38 | // Sets the RF channel of the device (2400 MHz + (channel * 1 MHz)) 39 | // 40 | // Parameters: 41 | // uint8_t channel - new RF channel 42 | // 43 | // Return value: 44 | // None 45 | // 46 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 47 | void rf_set_rf_channel(uint8_t channel) 48 | { 49 | if(channel <= RF_RF_CH_MAX_CHAN_NUM) 50 | { 51 | rf_write_register(RF_RF_CH, &channel, 1); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/uart/src/uart_wait_for_rx_and_get.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: uart_wait_for_rx_and_get.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "uart.h" 30 | #include "interrupt.h" 31 | 32 | 33 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 34 | // 35 | // uint8_t uart_wait_for_rx_and_get() 36 | // 37 | // Description: 38 | // Waits until a byte is received over the UART and returns the value 39 | // 40 | // Parameters: 41 | // None 42 | // 43 | // Return value: 44 | // Value received over UART 45 | // 46 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 47 | uint8_t uart_wait_for_rx_and_get() 48 | { 49 | while(!uart_rx_data_ready()); 50 | 51 | interrupt_clear_uart_rx(); 52 | 53 | return uart_get(); 54 | } 55 | -------------------------------------------------------------------------------- /src/rf/src/rf_rx_fifo_is_full.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: rf_rx_fifo_is_full.c 4 | // 5 | // Copyright S. Brennen Ball, 2012 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "rf.h" 30 | #include "rf_src.h" 31 | 32 | 33 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 34 | // 35 | // bool rf_rx_fifo_is_full() 36 | // 37 | // Description: 38 | // Returns whether or not the RX FIFO is full 39 | // 40 | // Parameters: 41 | // None 42 | // 43 | // Return value: 44 | // bool - true if RX FIFO is full, false otherwise 45 | // 46 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 47 | bool rf_rx_fifo_is_full() 48 | { 49 | uint8_t fifo_status; 50 | 51 | rf_read_register(RF_FIFO_STATUS, &fifo_status, 1); 52 | 53 | return (fifo_status & RF_FIFO_STATUS_RX_FULL) ? true : false; 54 | } 55 | -------------------------------------------------------------------------------- /src/rf/src/rf_tx_fifo_is_full.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: rf_tx_fifo_is_full.c 4 | // 5 | // Copyright S. Brennen Ball, 2012 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "rf.h" 30 | #include "rf_src.h" 31 | 32 | 33 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 34 | // 35 | // bool rf_tx_fifo_is_full() 36 | // 37 | // Description: 38 | // Returns whether or not the TX FIFO is full 39 | // 40 | // Parameters: 41 | // None 42 | // 43 | // Return value: 44 | // bool - true if TX FIFO is full, false otherwise 45 | // 46 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 47 | bool rf_tx_fifo_is_full() 48 | { 49 | uint8_t fifo_status; 50 | 51 | rf_read_register(RF_FIFO_STATUS, &fifo_status, 1); 52 | 53 | return (fifo_status & RF_FIFO_STATUS_TX_FULL) ? true : false; 54 | } 55 | -------------------------------------------------------------------------------- /src/rf/src/rf_irq_clear.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: rf_irq_clear.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "rf.h" 30 | #include "rf_src.h" 31 | 32 | 33 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 34 | // 35 | // void rf_irq_clear_all(uint8_t irq_mask) 36 | // 37 | // Description: 38 | // Clears selected interrupts 39 | // 40 | // Parameters: 41 | // None 42 | // 43 | // Return value: 44 | // None 45 | // 46 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 47 | void rf_irq_clear(uint8_t irq_mask) 48 | { 49 | //Clear the requested interrupt source(s) by writing a '1' to the appropriate clear bit(s) 50 | rf_write_register(RF_STATUS, &irq_mask, 1); 51 | 52 | sbit_clear(IRCON_SB_RFIRQ); //Clear the master interrupt 53 | } 54 | -------------------------------------------------------------------------------- /src/rf/src/rf_rx_fifo_is_empty.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: rf_rx_fifo_is_empty.c 4 | // 5 | // Copyright S. Brennen Ball, 2012 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "rf.h" 30 | #include "rf_src.h" 31 | 32 | 33 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 34 | // 35 | // bool rf_rx_fifo_is_empty() 36 | // 37 | // Description: 38 | // Returns whether or not the RX FIFO is empty 39 | // 40 | // Parameters: 41 | // None 42 | // 43 | // Return value: 44 | // bool - true if RX FIFO is empty, false otherwise 45 | // 46 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 47 | bool rf_rx_fifo_is_empty() 48 | { 49 | uint8_t fifo_status; 50 | 51 | rf_read_register(RF_FIFO_STATUS, &fifo_status, 1); 52 | 53 | return (fifo_status & RF_FIFO_STATUS_RX_EMPTY) ? true : false; 54 | } 55 | -------------------------------------------------------------------------------- /src/rf/src/rf_tx_fifo_is_empty.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: rf_tx_fifo_is_empty.c 4 | // 5 | // Copyright S. Brennen Ball, 2012 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "rf.h" 30 | #include "rf_src.h" 31 | 32 | 33 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 34 | // 35 | // bool rf_tx_fifo_is_empty() 36 | // 37 | // Description: 38 | // Returns whether or not the TX FIFO is empty 39 | // 40 | // Parameters: 41 | // None 42 | // 43 | // Return value: 44 | // bool - true if TX FIFO is empty, false otherwise 45 | // 46 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 47 | bool rf_tx_fifo_is_empty() 48 | { 49 | uint8_t fifo_status; 50 | 51 | rf_read_register(RF_FIFO_STATUS, &fifo_status, 1); 52 | 53 | return (fifo_status & RF_FIFO_STATUS_TX_EMPTY) ? true : false; 54 | } 55 | -------------------------------------------------------------------------------- /src/delay/src/delay_s.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: delay_s.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "delay.h" 30 | 31 | 32 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 33 | // 34 | // void delay_s(uint16_t microseconds) 35 | // 36 | // Description: 37 | // Waits the specified number of seconds and returns (delay is approximate) 38 | // 39 | // Parameters: 40 | // uint16_t seconds - number of seconds to delay 41 | // 42 | // Return value: 43 | // None 44 | // 45 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 46 | void delay_s(uint16_t seconds) 47 | { 48 | uint16_t count; 49 | 50 | //Wait 1000 ms for each requested second 51 | for(count = 0; count < seconds; count++) 52 | { 53 | delay_ms(1000); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/rf/src/rf_set_tx_addr.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: rf_read_register.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "rf.h" 30 | #include "rf_src.h" 31 | 32 | 33 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 34 | // 35 | // void rf_set_tx_addr(uint8_t * address, uint16_t len) 36 | // 37 | // Description: 38 | // Sets the device's TX address 39 | // 40 | // Parameters: 41 | // uint8_t * address - pointer to the address for the pipe 42 | // uint16_t len - number of bytes for the address 43 | // 44 | // Return value: 45 | // None 46 | // 47 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 48 | void rf_set_tx_addr(uint8_t * address, uint16_t len) 49 | { 50 | rf_write_register(RF_TX_ADDR, address, len); //Write the requested TX address 51 | } 52 | -------------------------------------------------------------------------------- /include/inline/watchdog_get_wdsv_count.inc: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: watchdog_get_wdsv_count.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 30 | // 31 | // uint16_t watchdog_get_wdsv_count(uint16_t wdsv_value) 32 | // 33 | // Description: 34 | // Returns the value of the watchdog counter (WDSV). 35 | // 36 | // Parameters: 37 | // None 38 | // 39 | // Return value: 40 | // The value of the watchdog counter (WDSV). 41 | // 42 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 43 | inline uint16_t watchdog_get_wdsv_count() 44 | { 45 | uint16_t wdsv_value; 46 | 47 | //WDSV is read low byte first, then high byte 48 | wdsv_value = WDSV; 49 | wdsv_value += (WDSV << 8); 50 | 51 | return wdsv_value; 52 | } 53 | -------------------------------------------------------------------------------- /src/delay/src/delay_ms.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: delay_ms.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "delay.h" 30 | 31 | 32 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 33 | // 34 | // void delay_ms(uint16_t microseconds) 35 | // 36 | // Description: 37 | // Waits the specified number of milliseconds and returns (delay is approximate) 38 | // 39 | // Parameters: 40 | // uint16_t milliseconds - number of milliseconds to delay 41 | // 42 | // Return value: 43 | // None 44 | // 45 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 46 | void delay_ms(uint16_t milliseconds) 47 | { 48 | uint16_t count; 49 | 50 | //Wait 1000 us for each requested ms 51 | for(count = 0; count < milliseconds; count++) 52 | { 53 | delay_us(1000); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/uart/src/uart_send_wait_for_complete.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: uart_send_wait_for_complete.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "uart.h" 30 | #include "interrupt.h" 31 | 32 | 33 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 34 | // 35 | // void uart_send_wait_for_complete(uint8_t tx_data) 36 | // 37 | // Description: 38 | // Sends a byte over the UART and waits for it to complete 39 | // 40 | // Parameters: 41 | // uint8_t tx_data - byte to send over the UART 42 | // 43 | // Return value: 44 | // None 45 | // 46 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 47 | void uart_send_wait_for_complete(uint8_t tx_data) 48 | { 49 | interrupt_clear_uart_tx(); 50 | 51 | uart_send(tx_data); 52 | 53 | interrupt_wait_for_uart_tx(); 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/watchdog/src/watchdog_cause_software_reset.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: watchdog_cause_software_reset.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "watchdog.h" 30 | #include "interrupt.h" 31 | 32 | 33 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 34 | // 35 | // void watchdog_cause_software_reset() 36 | // 37 | // Description: 38 | // Restarts the CPU with the watchdog 39 | // 40 | // Parameters: 41 | // None 42 | // 43 | // Return value: 44 | // None 45 | // 46 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 47 | void watchdog_cause_software_reset() 48 | { 49 | //Disable interrupts just in case there's an interrupt that might be restoring the watchdog 50 | interrupt_control_global_disable(); 51 | 52 | watchdog_set_wdsv_count(2); 53 | while(1); 54 | } 55 | -------------------------------------------------------------------------------- /src/rf/src/rf_irq_clear_all.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: rf_irq_clear_all.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "rf.h" 30 | #include "rf_src.h" 31 | 32 | 33 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 34 | // 35 | // void rf_irq_clear_all() 36 | // 37 | // Description: 38 | // Clears all interrupts 39 | // 40 | // Parameters: 41 | // None 42 | // 43 | // Return value: 44 | // None 45 | // 46 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 47 | void rf_irq_clear_all() 48 | { 49 | //Clear all three possible interrupt sources by writing a '1' to their location in STATUS 50 | uint8_t dataptr = RF_STATUS_RX_DR | RF_STATUS_TX_DS | RF_STATUS_MAX_RT; 51 | 52 | rf_write_register(RF_STATUS, &dataptr, 1); 53 | 54 | sbit_clear(IRCON_SB_RFIRQ); //Clear the master interrupt 55 | } 56 | -------------------------------------------------------------------------------- /src/w2/src/w2_wait_for_byte_tx_or_rx.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: w2_wait_for_byte_tx_or_rx.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "w2_src.h" 30 | 31 | 32 | ///////////////////////////////////////////////////////////////////////////////////////////////////////// 33 | // 34 | // uint8_t w2_wait_for_byte_tx_or_rx() 35 | // 36 | // Description: 37 | // Waits for the TX/RX interrupt to occur and returns the last read value of W2CON1 38 | // 39 | // Parameters: 40 | // None 41 | // 42 | // Return value: 43 | // The last read value of W2CON1 44 | // 45 | ///////////////////////////////////////////////////////////////////////////////////////////////////////// 46 | uint8_t w2_wait_for_byte_tx_or_rx() 47 | { 48 | uint8_t local_w2con1; 49 | 50 | //Wait until we get an interrupt and make sure it's TX/RX 51 | do 52 | { 53 | w2_wait_for_irq(); 54 | local_w2con1 = W2CON1; 55 | } while(!w2_data_txed_or_rxed(local_w2con1)); 56 | 57 | return local_w2con1; 58 | } 59 | -------------------------------------------------------------------------------- /src/gpio/src/gpio_pin_val_write.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: gpio_pin_val_write.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "gpio.h" 30 | 31 | 32 | /////////////////////////////////////////////////////////////////////////////////////////////// 33 | // 34 | // void gpio_pin_val_write(gpio_pin_id_t gpio_pin_id, bool value) 35 | // 36 | // Description: 37 | // Writes the specified value to a GPIO pin 38 | // 39 | // Parameters: 40 | // gpio_pin_id_t gpio_pin_id - ID of the GPIO pin to be cleared 41 | // bool value - value to be written to the GPIO pin 42 | // 43 | // Return value: 44 | // None 45 | // 46 | /////////////////////////////////////////////////////////////////////////////////////////////// 47 | void gpio_pin_val_write(gpio_pin_id_t gpio_pin_id, bool value) 48 | { 49 | //Process the request based on the specified value 50 | if(value) 51 | { 52 | gpio_pin_val_set(gpio_pin_id); 53 | } 54 | else 55 | { 56 | gpio_pin_val_clear(gpio_pin_id); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/rf/src/rf_read_rx_payload.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: rf_read_register.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "rf.h" 30 | #include "rf_src.h" 31 | 32 | 33 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 34 | // 35 | // uint8_t rf_read_rx_payload(uint8_t * dataptr, uint16_t len) 36 | // 37 | // Description: 38 | // Reads the next payload from the RX FIFO 39 | // 40 | // Parameters: 41 | // uint8_t * dataptr - pointer to which the read data is stored 42 | // uint16_t len - number of bytes to read from the payload 43 | // 44 | // Return value: 45 | // Read value of the STATUS register 46 | // 47 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 48 | uint8_t rf_read_rx_payload(uint8_t * dataptr, uint16_t len) 49 | { 50 | return rf_spi_execute_command(RF_R_RX_PAYLOAD, dataptr, len, true); 51 | } 52 | -------------------------------------------------------------------------------- /src/pwr_clk_mgmt/src/pwr_clk_mgmt_wakeup_sources_configure.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: pwr_clk_mgmt_wakeup_sources_configure.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "pwr_clk_mgmt.h" 30 | 31 | 32 | ///////////////////////////////////////////////////////////////////////////////////////////////////////// 33 | // 34 | // void pwr_clk_mgmt_wakeup_sources_configure(uint8_t wakeup_sources_config_options, uint16_t wakeup_on_pin_config_options) 35 | // 36 | // Description: 37 | // Configures wakeup sources 38 | // 39 | // Parameters: 40 | // uint8_t wakeup_sources_config_options - wakeup sources configuration options 41 | // 42 | // Return value: 43 | // None 44 | // 45 | ///////////////////////////////////////////////////////////////////////////////////////////////////////// 46 | void pwr_clk_mgmt_wakeup_sources_configure(uint8_t wakeup_sources_config_options) 47 | { 48 | //Set up WUCON register from wakeup_sources_config_options 49 | WUCON = wakeup_sources_config_options; 50 | } 51 | -------------------------------------------------------------------------------- /src/pwr_clk_mgmt/src/pwr_clk_mgmt_wakeup_pins_configure.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: pwr_clk_mgmt_wakeup_pins_configure.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "pwr_clk_mgmt.h" 30 | 31 | 32 | ///////////////////////////////////////////////////////////////////////////////////////////////////////// 33 | // 34 | // void pwr_clk_mgmt_wakeup_pins_configure(uint16_t wakeup_on_pin_config_options) 35 | // 36 | // Description: 37 | // Configures wakeup options 38 | // 39 | // Parameters: 40 | // uint16_t wakeup_on_pin_config_options - set bits to enable wake-on-pin 41 | // 42 | // Return value: 43 | // None 44 | // 45 | ///////////////////////////////////////////////////////////////////////////////////////////////////////// 46 | void pwr_clk_mgmt_wakeup_pins_configure(uint16_t wakeup_on_pin_config_options) 47 | { 48 | //Set up WUOPCx registers from wakeup_on_pin_config_options 49 | WUOPC0 = wakeup_on_pin_config_options & 0xFF; 50 | WUOPC1 = (wakeup_on_pin_config_options >> 8) & 0xFF; 51 | } 52 | -------------------------------------------------------------------------------- /src/pwm/src/pwm_stop.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: pwm_stop.c 4 | // 5 | // Copyright Aleksandr Svalov (Alarus), 2014 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "pwm.h" 30 | 31 | 32 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 33 | // 34 | // void pwm_stop(pwm_channel_t pwm_channel) 35 | // 36 | // Description: 37 | // Stop a PWM conversion on the specified PWM channel 38 | // 39 | // Parameters: 40 | // pwm_channel_t pwm_channel - PWM channel with which to stop the acquisition 41 | // 42 | // Return value: 43 | // None 44 | // 45 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 46 | void pwm_stop(pwm_channel_t pwm_channel) 47 | { 48 | //Disable the PWM for the requested channel 49 | if(pwm_channel == PWM_CHANNEL_0) 50 | { 51 | reg_bits_clear(PWMCON, PWMCON_PWM0_ENABLE); 52 | } 53 | else 54 | { 55 | reg_bits_clear(PWMCON, PWMCON_PWM1_ENABLE); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/rf/src/rf_read_register_1_byte.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: rf_read_register_1_byte.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "rf.h" 30 | #include "rf_src.h" 31 | 32 | 33 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 34 | // 35 | // uint8_t rf_read_register_1_byte(uint8_t regnumber) 36 | // 37 | // Description: 38 | // Reads the value from a single-byte register (or the first byte from a multi-byte register) 39 | // 40 | // Parameters: 41 | // uint8_t regnumber - number of the register to be read 42 | // 43 | // Return value: 44 | // Read value of the requested register 45 | // 46 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 47 | uint8_t rf_read_register_1_byte(uint8_t regnumber) 48 | { 49 | uint8_t reg_val; 50 | 51 | //Read the specified register 52 | rf_read_register(regnumber, ®_val, 1); 53 | 54 | return reg_val; 55 | } 56 | -------------------------------------------------------------------------------- /src/rf/src/rf_read_rx_payload_width.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: rf_read_rx_payload_width.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "rf.h" 30 | #include "rf_src.h" 31 | 32 | 33 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 34 | // 35 | // uint8_t rf_read_rx_payload_width(uint8_t * dataptr) 36 | // 37 | // Description: 38 | // Reads the width of the current RX payload 39 | // 40 | // Parameters: 41 | // uint8_t * dataptr - pointer to which the read payload width is stored (one byte) 42 | // 43 | // Return value: 44 | // Read value of the STATUS register 45 | // 46 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 47 | uint8_t rf_read_rx_payload_width(uint8_t * dataptr) 48 | { 49 | uint8_t status; 50 | 51 | status = rf_spi_execute_command(RF_R_RX_PL_WID, dataptr, 1, true); 52 | 53 | return status; //Return the STATUS register value 54 | } 55 | -------------------------------------------------------------------------------- /src/rf/src/rf_set_output_power.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: rf_output_power.c 4 | // 5 | // Copyright Dean Cording, 2013 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "rf.h" 30 | #include "rf_src.h" 31 | 32 | 33 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 34 | // 35 | // void rf_set_output_power(uint8_t power) 36 | // 37 | // Description: 38 | // Sets the TX power level of the device (0dBm, -6dBm, -12dBm, -18dBm) 39 | // 40 | // Parameters: 41 | // uint8_t power - new power level RF_RF_SETUP_RF_PWR_[0|NEG_6|NEG_12|NEG_18]_DBM 42 | // 43 | // Return value: 44 | // None 45 | // 46 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 47 | void rf_set_output_power(uint8_t power) 48 | { 49 | if (power <= RF_RF_SETUP_RF_PWR_0_DBM) { 50 | uint8_t rf_setup = rf_read_register_1_byte(RF_RF_SETUP); 51 | rf_setup = (rf_setup & ~RF_RF_SETUP_RF_PWR) | power; 52 | rf_write_register(RF_RF_SETUP, &rf_setup, 1); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/owi/src/owi_crc.c: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: owi_crc.c 4 | // 5 | // Copyright Aleksandr Svalov (Alarus), 2014 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | //////////////////////////////////////////////////////////////////////////////////// 12 | 13 | //////////////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | //////////////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "owi.h" 30 | 31 | 32 | //////////////////////////////////////////////////////////////////////////////////// 33 | // 34 | // uint8_t owi_crc(uint8_t data, uint8_t seed) 35 | // 36 | // Description: 37 | // Compute the CRC value of a data set 38 | // 39 | // Parameters: 40 | // uint8_t data - One byte of data to compute CRC from 41 | // uint8_t seed - The starting value of the CRC 42 | // 43 | // Return value: 44 | // uint8_t seed - The CRC of data with seed as initial value 45 | // 46 | //////////////////////////////////////////////////////////////////////////////////// 47 | uint8_t owi_crc(uint8_t data, uint8_t seed) 48 | { 49 | register uint8_t i; 50 | 51 | for (i = 8; i; i--) 52 | { 53 | if (((seed ^ data) & 0x01)) 54 | { 55 | seed ^= 0x18; 56 | seed >>= 1; 57 | seed |= 0x80; 58 | } 59 | else 60 | { 61 | seed >>= 1; 62 | } 63 | data >>= 1; 64 | } 65 | return seed; 66 | } 67 | -------------------------------------------------------------------------------- /src/owi/src/owi_write_bit_0.c: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: owi_write_bit_0.c 4 | // 5 | // Copyright Aleksandr Svalov (Alarus), 2014 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | //////////////////////////////////////////////////////////////////////////////////// 12 | 13 | //////////////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | //////////////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "owi.h" 30 | 31 | 32 | //////////////////////////////////////////////////////////////////////////////////// 33 | // 34 | // void owi_write_bit_0(gpio_pin_id_t owi_pin_id) 35 | // 36 | // Description: 37 | // Generates the waveform for transmission of a '0' bit on the OWI 38 | // 39 | // Parameters: 40 | // gpio_pin_id_t owi_pin_id - ID of the OWI pin 41 | // 42 | // Return value: 43 | // None 44 | // 45 | //////////////////////////////////////////////////////////////////////////////////// 46 | void owi_write_bit_0(gpio_pin_id_t owi_pin_id) 47 | { 48 | // Drive bus low and delay. 49 | gpio_pin_dir_output(owi_pin_id, GPIO_PIN_CONFIG_OPTION_PIN_MODE_OUTPUT_BUFFER_NORMAL_DRIVE_STRENGTH); 50 | delay_us(OWI_DELAY_C); 51 | 52 | // Release bus and delay. 53 | gpio_pin_dir_input(owi_pin_id, GPIO_PIN_CONFIG_OPTION_PIN_MODE_INPUT_BUFFER_ON_PULL_UP_RESISTOR); 54 | delay_us(OWI_DELAY_D); 55 | } 56 | -------------------------------------------------------------------------------- /src/owi/src/owi_write_bit_1.c: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: owi_write_bit_1.c 4 | // 5 | // Copyright Aleksandr Svalov (Alarus), 2014 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | //////////////////////////////////////////////////////////////////////////////////// 12 | 13 | //////////////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | //////////////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "owi.h" 30 | 31 | 32 | //////////////////////////////////////////////////////////////////////////////////// 33 | // 34 | // void owi_write_bit_1(gpio_pin_id_t owi_pin_id) 35 | // 36 | // Description: 37 | // Generates the waveform for transmission of a '1' bit on the OWI 38 | // 39 | // Parameters: 40 | // gpio_pin_id_t owi_pin_id - ID of the OWI pin 41 | // 42 | // Return value: 43 | // None 44 | // 45 | //////////////////////////////////////////////////////////////////////////////////// 46 | void owi_write_bit_1(gpio_pin_id_t owi_pin_id) 47 | { 48 | // Drive bus low and delay. 49 | gpio_pin_dir_output(owi_pin_id, GPIO_PIN_CONFIG_OPTION_PIN_MODE_OUTPUT_BUFFER_NORMAL_DRIVE_STRENGTH); 50 | delay_us(OWI_DELAY_A); 51 | 52 | // Release bus and delay. 53 | gpio_pin_dir_input(owi_pin_id, GPIO_PIN_CONFIG_OPTION_PIN_MODE_INPUT_BUFFER_ON_PULL_UP_RESISTOR); 54 | delay_us(OWI_DELAY_B); 55 | } 56 | -------------------------------------------------------------------------------- /src/delay/src/delay_us.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: delay_us.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "delay.h" 30 | 31 | 32 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 33 | // 34 | // void delay_us(uint16_t microseconds) 35 | // 36 | // Description: 37 | // Waits the specified number of milliseconds and returns (delay is approximate) 38 | // 39 | // Parameters: 40 | // uint16_t microseconds - number of microseconds to delay 41 | // 42 | // Return value: 43 | // None 44 | // 45 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 46 | void delay_us(uint16_t microseconds) 47 | { 48 | uint16_t count; 49 | 50 | //Try to account for the call to and return from this function 51 | if(microseconds == 0) 52 | return; 53 | else 54 | microseconds -= 1; 55 | 56 | for(count = 0; count < microseconds; count++) 57 | { 58 | nop(); 59 | nop(); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/sspi/src/sspi_configure.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: sspi_configure.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "sspi.h" 30 | 31 | /////////////////////////////////////////// 32 | // Internal defines 33 | /////////////////////////////////////////// 34 | #define SSPI_CONFIG_OPTION_SPISCON0_MASK 0x7F //Mask for the options used for SPISCON0 35 | 36 | 37 | //////////////////////////////////////////////////////////////////////////////// 38 | // 39 | // void sspi_configure(uint8_t sspi_config_options) __reentrant 40 | // 41 | // Description: 42 | // Configures the SSPI 43 | // 44 | // Parameters: 45 | // uint8_t sspi_config_options - SSPI configuration options 46 | // 47 | // Return value: 48 | // None 49 | // 50 | //////////////////////////////////////////////////////////////////////////////// 51 | void sspi_configure(uint8_t sspi_config_options) __reentrant 52 | { 53 | //Set up SPISCON0 register from sspi_config_options 54 | SPISCON0 = (SPISCON0 & ~SSPI_CONFIG_OPTION_SPISCON0_MASK) | (sspi_config_options & SSPI_CONFIG_OPTION_SPISCON0_MASK); 55 | } 56 | -------------------------------------------------------------------------------- /src/owi/src/owi_match_rom.c: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: owi_match_rom.c 4 | // 5 | // Copyright Aleksandr Svalov (Alarus), 2014 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | //////////////////////////////////////////////////////////////////////////////////// 12 | 13 | //////////////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | //////////////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "owi.h" 30 | 31 | 32 | //////////////////////////////////////////////////////////////////////////////////// 33 | // 34 | // void owi_match_rom(gpio_pin_id_t owi_pin_id, uint8_t * ptr_rom) 35 | // 36 | // Description: 37 | // Sends the MATCH ROM command and the ROM id to match against 38 | // 39 | // Parameters: 40 | // gpio_pin_id_t owi_pin_id - ID of the OWI pin 41 | // uint8_t * ptr_rom - A pointer to the ROM to match against 42 | // 43 | // Return value: 44 | // None 45 | // 46 | //////////////////////////////////////////////////////////////////////////////////// 47 | void owi_match_rom(gpio_pin_id_t owi_pin_id, uint8_t * ptr_rom) 48 | { 49 | register uint8_t i; 50 | 51 | // Send the MATCH ROM command. 52 | owi_send_byte(owi_pin_id, OWI_MATCH_ROM); 53 | 54 | // Do 8 times. 55 | for (i = 8; i; i--) 56 | { 57 | // Transmit 1 byte of the ROM to match. 58 | owi_send_byte(owi_pin_id, *ptr_rom++); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/owi/src/owi_read_rom.c: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: owi_read_rom.c 4 | // 5 | // Copyright Aleksandr Svalov (Alarus), 2014 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | //////////////////////////////////////////////////////////////////////////////////// 12 | 13 | //////////////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | //////////////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "owi.h" 30 | 31 | 32 | //////////////////////////////////////////////////////////////////////////////////// 33 | // 34 | // void owi_read_rom(gpio_pin_id_t owi_pin_id, uint8_t * ptr_rom) 35 | // 36 | // Description: 37 | // Sends the READ ROM command and reads back the ROM id 38 | // 39 | // Parameters: 40 | // gpio_pin_id_t owi_pin_id - ID of the OWI pin 41 | // uint8_t * ptr_rom - A pointer where the ROM data will be placed 42 | // 43 | // Return value: 44 | // None 45 | // 46 | //////////////////////////////////////////////////////////////////////////////////// 47 | void owi_read_rom(gpio_pin_id_t owi_pin_id, uint8_t * ptr_rom) 48 | { 49 | register uint8_t i; 50 | 51 | // Send the READ ROM command on the bus. 52 | owi_send_byte(owi_pin_id, OWI_READ_ROM); 53 | 54 | // Do 8 times. 55 | for (i = 8; i; i--) 56 | { 57 | // Place the received data in memory. 58 | *ptr_rom++ = owi_receive_byte(owi_pin_id); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/rng/src/rng_get_one_byte_and_turn_off.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: rng_get_one_byte_and_turn_off.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "rng.h" 30 | 31 | 32 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 33 | // 34 | // uint8_t rng_get_one_byte_and_turn_off() 35 | // 36 | // Description: 37 | // Turns on the RNG, waits for a random number, then turns the RNG back off. You do not have to call rng_configure() prior 38 | // to calling this function, as this function does that itself. 39 | // 40 | // Parameters: 41 | // None 42 | // 43 | // Return value: 44 | // A random number 45 | // 46 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 47 | uint8_t rng_get_one_byte_and_turn_off() 48 | { 49 | uint8_t rand_val; 50 | 51 | rng_configure(RNG_CONFIG_OPTION_RUN | RNG_CONFIG_CORRECTOR_ENABLE); 52 | rand_val = rng_get_next_byte(); 53 | rng_stop(); 54 | 55 | return rand_val; 56 | } 57 | 58 | -------------------------------------------------------------------------------- /src/rf/src/rf_spi_send_read_byte.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: rf_read_register.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "rf.h" 30 | #include "rf_src.h" 31 | 32 | 33 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 34 | // 35 | // uint8_t rf_spi_send_read_byte(uint8_t byte) 36 | // 37 | // Description: 38 | // Sends a byte over SPI, waits for the transaction to complete, then returns the byte read over SPI 39 | // 40 | // Parameters: 41 | // uint8_t byte - data byte to be sent over SPI 42 | // 43 | // Return value: 44 | // Value read from SPI 45 | // 46 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 47 | uint8_t rf_spi_send_read_byte(uint8_t byte) 48 | { 49 | SPIRDAT = byte; //Send byte over SPI 50 | 51 | while(!(SPIRSTAT & SPIRSTAT_IRQ_RX_FIFO_READY)); //Wait for the transaction to finish 52 | 53 | IRCON_SB_RFRDY = BIT_FALSE; //Clear the IRQ bit 54 | 55 | return SPIRDAT; //Return the received value 56 | } 57 | -------------------------------------------------------------------------------- /src/adc/src/adc_set_input_channel.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: adc_set_input_channel.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "adc.h" 30 | 31 | 32 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 33 | // 34 | // void adc_set_input_channel(adc_channel_t adc_channel) 35 | // 36 | // Description: 37 | // Sets the A/D's input mux to the specified channel 38 | // 39 | // Parameters: 40 | // adc_channel_t adc_channel - ADC channel with which to set the multiplexer 41 | // 42 | // Return value: 43 | // None 44 | // 45 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 46 | void adc_set_input_channel(adc_channel_t adc_channel) 47 | { 48 | //Remove any unnecessary set bits from adc_channel 49 | adc_channel &= (ADCCON1_CHAN_SEL_MASK >> ADCCON1_CHAN_SEL_SHIFT); 50 | 51 | //Set the mux to the specified channel 52 | ADCCON1 = (ADCCON1 & ~ADCCON1_CHAN_SEL_MASK) | (adc_channel << ADCCON1_CHAN_SEL_SHIFT); 53 | } 54 | -------------------------------------------------------------------------------- /src/owi/src/owi_check_rom.c: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: owi_check_rom.c 4 | // 5 | // Copyright Aleksandr Svalov (Alarus), 2014 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | //////////////////////////////////////////////////////////////////////////////////// 12 | 13 | //////////////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | //////////////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "owi.h" 30 | 31 | 32 | //////////////////////////////////////////////////////////////////////////////////// 33 | // 34 | // uint8_t owi_check_rom(uint8_t * ptr_rom) 35 | // 36 | // Description: 37 | // Calculate and check the CRC of a 64 bit ROM identifier 38 | // 39 | // Parameters: 40 | // uint8_t * ptr_rom - A pointer to an array holding a 64 bit identifier 41 | // 42 | // Return value: 43 | // uint8_t OWI_CRC_OK The CRC's matched 44 | // uint8_t OWI_CRC_ERROR There was a discrepancy between the calculated and the stored CRC 45 | // 46 | //////////////////////////////////////////////////////////////////////////////////// 47 | uint8_t owi_check_rom(uint8_t * ptr_rom) 48 | { 49 | register uint8_t i; 50 | register uint8_t crc = 0; 51 | 52 | for (i = 7; i; i--) 53 | { 54 | crc = owi_crc(*ptr_rom, crc); 55 | ptr_rom++; 56 | } 57 | if (crc == (*ptr_rom)) 58 | { 59 | return OWI_CRC_OK; 60 | } 61 | return OWI_CRC_ERROR; 62 | } 63 | -------------------------------------------------------------------------------- /src/pwr_clk_mgmt/src/pwr_clk_mgmt_get_cclk_freq_in_hz.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: pwr_clk_mgmt_get_cclk_freq_in_hz.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "pwr_clk_mgmt.h" 30 | 31 | 32 | ///////////////////////////////////////////////////////////////////////////////////////////////////////// 33 | // 34 | // uint32_t pwr_clk_mgmt_get_cclk_freq_in_hz() 35 | // 36 | // Description: 37 | // Returns microcontroller system clock (CCLK) frequency in Hz 38 | // 39 | // Parameters: 40 | // uint8_t cclk_config_options - CCLK configuration options 41 | // 42 | // Return value: 43 | // Microcontroller system clock (CCLK) frequency in Hz (default is 16,000,000 Hz) 44 | // 45 | ///////////////////////////////////////////////////////////////////////////////////////////////////////// 46 | uint32_t pwr_clk_mgmt_get_cclk_freq_in_hz() 47 | { 48 | uint8_t divider = (CLKCTRL & CLKCTRL_CLK_FREQ_MASK) >> CLKCTRL_CLK_FREQ_SHIFT; 49 | uint8_t i; 50 | uint32_t cclk_freq_hz = CCLK_MAX_FREQ_HZ; 51 | 52 | for(i = 0; i < divider; i++) 53 | { 54 | cclk_freq_hz /= 2; 55 | } 56 | 57 | return cclk_freq_hz; 58 | } 59 | -------------------------------------------------------------------------------- /src/pwr_clk_mgmt/src/pwr_clk_mgmt_get_cclk_freq_in_khz.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: pwr_clk_mgmt_get_cclk_freq_in_khz.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "pwr_clk_mgmt.h" 30 | 31 | 32 | ///////////////////////////////////////////////////////////////////////////////////////////////////////// 33 | // 34 | // uint32_t pwr_clk_mgmt_get_cclk_freq_in_khz() 35 | // 36 | // Description: 37 | // Returns microcontroller system clock (CCLK) frequency in kHz 38 | // 39 | // Parameters: 40 | // uint8_t cclk_config_options - CCLK configuration options 41 | // 42 | // Return value: 43 | // Microcontroller system clock (CCLK) frequency in kHz (default is 16,000 kHz) 44 | // 45 | ///////////////////////////////////////////////////////////////////////////////////////////////////////// 46 | uint16_t pwr_clk_mgmt_get_cclk_freq_in_khz() 47 | { 48 | uint8_t divider = (CLKCTRL & CLKCTRL_CLK_FREQ_MASK) >> CLKCTRL_CLK_FREQ_SHIFT; 49 | uint8_t i; 50 | uint16_t cclk_freq_khz = CCLK_MAX_FREQ_KHZ; 51 | 52 | for(i = 0; i < divider; i++) 53 | { 54 | cclk_freq_khz /= 2; 55 | } 56 | 57 | return cclk_freq_khz; 58 | } 59 | -------------------------------------------------------------------------------- /src/rf/src/rf_power_down_param.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: rf_power_down_param.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "rf.h" 30 | #include "rf_src.h" 31 | 32 | 33 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 34 | // 35 | // void rf_power_down_param(uint8_t config) 36 | // 37 | // Description: 38 | // Powers down the device, but allows the user to pass in the value sent to the CONFIG register 39 | // 40 | // Parameters: 41 | // uint8_t config - value to be written to the CONFIG register (the PWR_UP bit will obviously be cleared) 42 | // 43 | // Return value: 44 | // None 45 | // 46 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 47 | void rf_power_down_param(uint8_t config) 48 | { 49 | rf_clear_ce(); //Ensure the CE pin is cleared 50 | 51 | config &= (~RF_CONFIG_PWR_UP); //Use the passed in value of CONFIG and ensure the PWR_UP bit is cleared, then write the register 52 | rf_write_register(RF_CONFIG, &config, 1); 53 | } 54 | -------------------------------------------------------------------------------- /src/pwm/src/pwm_configure.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: pwm_configure.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "pwm.h" 30 | 31 | 32 | /////////////////////////////////////////// 33 | // Internal defines 34 | /////////////////////////////////////////// 35 | #define PWM_CONFIG_OPTION_PWMCON_MASK 0xFC //Mask for the options used for PWMCON 36 | 37 | 38 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 39 | // 40 | // void pwm_configure(uint8_t pwm_config_options) 41 | // 42 | // Description: 43 | // Configures the PWM block 44 | // 45 | // Parameters: 46 | // uint8_t pwm_config_options - PWM configuration options 47 | // 48 | // Return value: 49 | // None 50 | // 51 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 52 | void pwm_configure(uint8_t pwm_config_options) 53 | { 54 | //Set up PWMCON register from pwm_config_options 55 | PWMCON = (PWMCON & ~PWM_CONFIG_OPTION_PWMCON_MASK) | (pwm_config_options & PWM_CONFIG_OPTION_PWMCON_MASK); 56 | } 57 | -------------------------------------------------------------------------------- /src/rf/src/rf_power_down.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: rf_power_down.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "rf.h" 30 | #include "rf_src.h" 31 | 32 | 33 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 34 | // 35 | // void rf_power_down_param() 36 | // 37 | // Description: 38 | // Powers down the device 39 | // 40 | // Parameters: 41 | // None 42 | // 43 | // Return value: 44 | // None 45 | // 46 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 47 | void rf_power_down() 48 | { 49 | uint8_t config; 50 | 51 | rf_clear_ce(); //Clear the CE pin 52 | 53 | rf_read_register(RF_CONFIG, &config, 1); //Read the current value of the CONFIG register 54 | 55 | //If the device is already powered down, exit 56 | if((config & RF_CONFIG_PWR_UP) == 0) 57 | { 58 | return; 59 | } 60 | 61 | //Clear the PWR_UP bit, then write the old value of CONFIG back to the device 62 | config &= (~RF_CONFIG_PWR_UP); 63 | rf_write_register(RF_CONFIG, &config, 1); 64 | } 65 | -------------------------------------------------------------------------------- /src/owi/src/owi_check_scratchpad.c: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: owi_check_scratchpad.c 4 | // 5 | // Copyright Aleksandr Svalov (Alarus), 2014 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | //////////////////////////////////////////////////////////////////////////////////// 12 | 13 | //////////////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | //////////////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "owi.h" 30 | 31 | 32 | //////////////////////////////////////////////////////////////////////////////////// 33 | // 34 | // uint8_t owi_check_scratchpad(uint8_t * ptr_scratchpad) 35 | // 36 | // Description: 37 | // Calculate and check the CRC of a Scratchpad 38 | // 39 | // Parameters: 40 | // uint8_t * ptr_rom - A pointer to an array Scratchpad data 41 | // 42 | // Return value: 43 | // uint8_t OWI_CRC_OK The CRC's matched 44 | // uint8_t OWI_CRC_ERROR There was a discrepancy between the calculated and the stored CRC 45 | // 46 | //////////////////////////////////////////////////////////////////////////////////// 47 | uint8_t owi_check_scratchpad(uint8_t * ptr_scratchpad) 48 | { 49 | register uint8_t i; 50 | register uint8_t crc = 0; 51 | 52 | for (i = 8; i; i--) 53 | { 54 | crc = owi_crc(*ptr_scratchpad, crc); 55 | ptr_scratchpad++; 56 | } 57 | if (crc == (*ptr_scratchpad)) 58 | { 59 | return OWI_CRC_OK; 60 | } 61 | return OWI_CRC_ERROR; 62 | } 63 | -------------------------------------------------------------------------------- /src/rf/src/rf_write_tx_ack_payload.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: rf_write_tx_ack_payload.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "rf.h" 30 | #include "rf_src.h" 31 | 32 | 33 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 34 | // 35 | // uint8_t rf_write_tx_ack_payload(uint8_t * dataptr, uint16_t len,) 36 | // 37 | // Description: 38 | // Writes the acknowledge payload for the TX FIFO 39 | // 40 | // Parameters: 41 | // uint8_t * dataptr - pointer from which the acknowledge payload data is read 42 | // uint16_t len - number of bytes to write to the acknowledge payload 43 | // 44 | // Return value: 45 | // Read value of the STATUS register 46 | // 47 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 48 | uint8_t rf_write_tx_ack_payload(uint8_t * dataptr, uint16_t len) 49 | { 50 | uint8_t status; 51 | 52 | status = rf_spi_execute_command(RF_W_ACK_PAYLOAD, dataptr, len, false); //Write the ack payload 53 | 54 | return status; //Return the value of STATUS 55 | } 56 | -------------------------------------------------------------------------------- /src/mspi/src/mspi_read_write.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: mspi_configure.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "mspi.h" 30 | 31 | 32 | //////////////////////////////////////////////////////////////////////////////// 33 | // 34 | // uint8_t mspi_read_write(uint8_t mspi_data) __reentrant 35 | // 36 | // Description: 37 | // Sends a byte of data over MSPI, waits until the transaction is finished, and 38 | // then returns the value received over MSPI. 39 | // 40 | // Parameters: 41 | // uint8_t mspi_data - data to write to the MSPI bus 42 | // 43 | // Return value: 44 | // Data read from the MSPI bus after the transaction has completed 45 | // 46 | //////////////////////////////////////////////////////////////////////////////// 47 | uint8_t mspi_read_write(uint8_t mspi_data) __reentrant 48 | { 49 | //make sure the RX FIFO is clear before sending the byte 50 | while(mspi_is_rx_data_ready()) 51 | { 52 | mspi_get(); 53 | } 54 | 55 | //send the byte 56 | mspi_send(mspi_data); 57 | 58 | //wait until the transaction is complete 59 | while(!mspi_is_rx_data_ready()); 60 | 61 | //return the received byte 62 | return mspi_get(); 63 | } 64 | -------------------------------------------------------------------------------- /src/rf/src/rf_power_up.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: rf_power_up.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "rf.h" 30 | #include "rf_src.h" 31 | #include "pwr_clk_mgmt.h" 32 | 33 | 34 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 35 | // 36 | // void rf_power_up(bool rx_active_mode) 37 | // 38 | // Description: 39 | // Powers up the device, and allows the user to select whether or not to go to RX active mode (if RX is desired) 40 | // 41 | // Parameters: 42 | // bool rx_active_mode - true to take to RX active mode (if RX), false otherwise 43 | // 44 | // Return value: 45 | // None 46 | // 47 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 48 | void rf_power_up(bool rx_active_mode) 49 | { 50 | uint8_t config; 51 | 52 | rf_read_register(RF_CONFIG, &config, 1); //Get the current value of the CONFIG register 53 | 54 | //rf_power_up_param() will set the PWR_UP bit and write the old value of CONFIG back to the device 55 | rf_power_up_param(rx_active_mode, config); 56 | } 57 | -------------------------------------------------------------------------------- /src/rf/src/rf_read_register.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: rf_read_register.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "rf.h" 30 | #include "rf_src.h" 31 | 32 | 33 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 34 | // 35 | // uint8_t rf_read_register(uint8_t regnumber, uint8_t * dataptr, uint16_t len) 36 | // 37 | // Description: 38 | // Reads the value from a register 39 | // 40 | // Parameters: 41 | // uint8_t regnumber - number of the register to be read 42 | // uint8_t * dataptr - pointer to which the read data is stored 43 | // uint16_t len - number of bytes to read from the register 44 | // 45 | // Return value: 46 | // Read value of the STATUS register 47 | // 48 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 49 | uint8_t rf_read_register(uint8_t regnumber, uint8_t * dataptr, uint16_t len) 50 | { 51 | //Read the register specified and return the STATUS register value 52 | return rf_spi_execute_command(regnumber & RF_R_REGISTER_DATA, dataptr, len, true); 53 | } 54 | -------------------------------------------------------------------------------- /include/inline/watchdog_set_wdsv_count.inc: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: watchdog_set_wdsv_count.inc 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 30 | // 31 | // void watchdog_set_wdsv_count(uint16_t wdsv_value) 32 | // 33 | // Description: 34 | // Sets the value of the watchdog counter (WDSV). The value that is returned by watchdog_calc_timeout_from_sec() or 35 | // watchdog_calc_timeout_from_ms() can be used as the argument to this function, since this function takes considerably less time 36 | // to execute once the watchdog has been set up once. 37 | // 38 | // Parameters: 39 | // uint16_t wdsv_value - Value to assign to WDSV 40 | // 41 | // Return value: 42 | // None 43 | // 44 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 45 | inline void watchdog_set_wdsv_count(uint16_t wdsv_value) 46 | { 47 | //WDSV is written low byte first, then high byte 48 | WDSV = (uint8_t)wdsv_value; 49 | WDSV = (uint8_t)(wdsv_value >> 8); 50 | } 51 | -------------------------------------------------------------------------------- /src/rng/src/rng_configure.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: rng_configure.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "rng.h" 30 | 31 | 32 | /////////////////////////////////////////// 33 | // Internal defines 34 | /////////////////////////////////////////// 35 | #define RNG_CONFIG_OPTION_RNGCTL_MASK 0xC0 //Mask for the options used for RNGCTL 36 | 37 | 38 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 39 | // 40 | // void rng_configure(uint16_t rng_config_options) 41 | // 42 | // Description: 43 | // Configures the random number generator 44 | // 45 | // Parameters: 46 | // uint16_t rng_config_options - RNG configuration options 47 | // 48 | // Return value: 49 | // None 50 | // 51 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 52 | void rng_configure(uint8_t rng_config_options) 53 | { 54 | //Set up RNGCTL register from rng_config_options 55 | RNGCTL = (RNGCTL & ~RNG_CONFIG_OPTION_RNGCTL_MASK) | (rng_config_options & RNG_CONFIG_OPTION_RNGCTL_MASK); 56 | } 57 | 58 | -------------------------------------------------------------------------------- /src/w2/src/w2_master_process_stop_request.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: w2_master_process_stop_request.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "w2_src.h" 30 | 31 | 32 | ///////////////////////////////////////////////////////////////////////////////////////////////////////// 33 | // 34 | // void w2_master_process_stop_request(w2_start_stop_condition_t send_start_stop_conditions) 35 | // 36 | // Description: 37 | // Processes stop requests 38 | // 39 | // Parameters: 40 | // w2_start_stop_condition_t send_start_stop_conditions - if set to W2_SEND_ONLY_STOP_CONDITION or 41 | // W2_SEND_BOTH_START_AND_STOP_CONDITIONS, the function will issue a stop condition 42 | // 43 | // Return value: 44 | // None 45 | // 46 | ///////////////////////////////////////////////////////////////////////////////////////////////////////// 47 | void w2_master_process_stop_request(w2_start_stop_condition_t send_start_stop_conditions) 48 | { 49 | switch(send_start_stop_conditions) 50 | { 51 | case W2_SEND_ONLY_STOP_CONDITION: 52 | case W2_SEND_BOTH_START_AND_STOP_CONDITIONS: 53 | w2_send_stop_condition(); 54 | break; 55 | 56 | default: 57 | break; 58 | }; 59 | } 60 | -------------------------------------------------------------------------------- /src/w2/src/w2_master_process_start_request.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: w2_master_process_start_request.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "w2_src.h" 30 | 31 | 32 | ///////////////////////////////////////////////////////////////////////////////////////////////////////// 33 | // 34 | // void w2_master_process_start_request(w2_start_stop_condition_t send_start_stop_conditions) 35 | // 36 | // Description: 37 | // Processes start requests 38 | // 39 | // Parameters: 40 | // w2_start_stop_condition_t send_start_stop_conditions - if set to W2_SEND_ONLY_START_CONDITION or 41 | // W2_SEND_BOTH_START_AND_STOP_CONDITIONS, the function will issue a start condition 42 | // 43 | // Return value: 44 | // None 45 | // 46 | ///////////////////////////////////////////////////////////////////////////////////////////////////////// 47 | void w2_master_process_start_request(w2_start_stop_condition_t send_start_stop_conditions) 48 | { 49 | switch(send_start_stop_conditions) 50 | { 51 | case W2_SEND_ONLY_START_CONDITION: 52 | case W2_SEND_BOTH_START_AND_STOP_CONDITIONS: 53 | w2_send_start_condition(); 54 | break; 55 | 56 | default: 57 | break; 58 | }; 59 | } 60 | -------------------------------------------------------------------------------- /src/rf/src/rf_write_register.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: rf_write_register.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "rf.h" 30 | #include "rf_src.h" 31 | 32 | 33 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 34 | // 35 | // uint8_t rf_write_register(uint8_t regnumber, uint8_t * dataptr, uint16_t len) 36 | // 37 | // Description: 38 | // Writes a value to a register 39 | // 40 | // Parameters: 41 | // uint8_t regnumber - number of the register to be written 42 | // uint8_t * dataptr - pointer to which the write data is stored 43 | // uint16_t len - number of bytes to write to the register 44 | // 45 | // Return value: 46 | // Read value of the STATUS register 47 | // 48 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 49 | uint8_t rf_write_register(uint8_t regnumber, uint8_t * dataptr, uint16_t len) 50 | { 51 | //Write the register specified and return the STATUS register value 52 | return rf_spi_execute_command(RF_W_REGISTER | (regnumber & RF_W_REGISTER_DATA), dataptr, len, false); 53 | } 54 | -------------------------------------------------------------------------------- /src/owi/src/owi_send_byte.c: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: owi_send_byte.c 4 | // 5 | // Copyright Aleksandr Svalov (Alarus), 2014 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | //////////////////////////////////////////////////////////////////////////////////// 12 | 13 | //////////////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | //////////////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "owi.h" 30 | 31 | 32 | //////////////////////////////////////////////////////////////////////////////////// 33 | // 34 | // void owi_send_byte(gpio_pin_id_t owi_pin_id, uint8_t data) 35 | // 36 | // Description: 37 | // This function automates the task of sending a complete byte of data on the OWI 38 | // 39 | // Parameters: 40 | // gpio_pin_id_t owi_pin_id - ID of the OWI pin 41 | // uint8_t data - The data to send on the OWI 42 | // 43 | // Return value: 44 | // None 45 | // 46 | //////////////////////////////////////////////////////////////////////////////////// 47 | void owi_send_byte(gpio_pin_id_t owi_pin_id, uint8_t data) 48 | { 49 | register uint8_t mask = 0x01; 50 | 51 | // Do once for each bit 52 | do 53 | { 54 | // Determine if lsb is '0' or '1' and transmit corresponding 55 | // waveform on the bus. 56 | if (mask & data) 57 | { 58 | owi_write_bit_1(owi_pin_id); 59 | } 60 | else 61 | { 62 | owi_write_bit_0(owi_pin_id); 63 | } 64 | // Left shift the mask. 65 | mask <<= 1; 66 | } 67 | while (mask); 68 | } 69 | -------------------------------------------------------------------------------- /src/sspi/src/sspi_read_write.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: sspi_configure.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "sspi.h" 30 | 31 | 32 | //////////////////////////////////////////////////////////////////////////////// 33 | // 34 | // uint8_t sspi_read_write(uint8_t sspi_data) __reentrant 35 | // 36 | // Description: 37 | // Sends a byte of data over SSPI, waits until the transaction is finished, and 38 | // then returns the value received over SSPI. 39 | // 40 | // Parameters: 41 | // uint8_t sspi_data - data to write to the SSPI bus 42 | // 43 | // Return value: 44 | // Data read from the SSPI bus after the transaction has completed 45 | // 46 | //////////////////////////////////////////////////////////////////////////////// 47 | uint8_t sspi_read_write(uint8_t sspi_data) __reentrant 48 | { 49 | //make sure the RX FIFO is clear before sending the byte 50 | while(sspi_is_spi_slave_done(sspi_get_status())) 51 | { 52 | sspi_get_data(); 53 | } 54 | 55 | //load the byte 56 | sspi_send_data(sspi_data); 57 | 58 | //wait until the transaction is complete 59 | while(!sspi_is_spi_slave_done(sspi_get_status())); 60 | 61 | //return the received byte 62 | return sspi_get_data(); 63 | } 64 | -------------------------------------------------------------------------------- /src/rf/src/rf_set_data_rate.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: rf_set_data_rate.c 4 | // 5 | // Copyright Dean Cording, 2013 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "rf.h" 30 | #include "rf_src.h" 31 | 32 | 33 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 34 | // 35 | // void rf_set_data_rate(uint8_t data_rate) 36 | // 37 | // Description: 38 | // Sets the data transmission rate of the device (250kbps, 1Mbps, 2Mbps) 39 | // 40 | // Parameters: 41 | // uint8_t power - new power level RF_RF_SETUP_RF_DR_[250_KBPS|1_MBPS|2_MBPS] 42 | // 43 | // Return value: 44 | // None 45 | // 46 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 47 | void rf_set_data_rate(uint8_t data_rate) 48 | { 49 | 50 | if ((data_rate == RF_RF_SETUP_RF_DR_250_KBPS) || 51 | (data_rate == RF_RF_SETUP_RF_DR_1_MBPS) || 52 | (data_rate == RF_RF_SETUP_RF_DR_2_MBPS)) { 53 | 54 | uint8_t rf_setup = rf_read_register_1_byte(RF_RF_SETUP) & ~RF_RF_SETUP_RF_DR; 55 | rf_setup = (rf_setup & ~RF_RF_SETUP_RF_PWR) | data_rate; 56 | rf_write_register(RF_RF_SETUP, &rf_setup, 1); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/rf/src/rf_set_rx_addr.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: rf_read_register.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "rf.h" 30 | #include "rf_src.h" 31 | 32 | 33 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 34 | // 35 | // void rf_set_rx_addr(uint8_t * address, uint16_t len, uint8_t rxpipenum) 36 | // 37 | // Description: 38 | // Sets the device's RX address on the specified pipe 39 | // 40 | // Parameters: 41 | // uint8_t * address - pointer to the address for the pipe 42 | // uint16_t len - number of bytes for the address 43 | // uint8_t rxpipenum - pipe number to which the address should be written 44 | // 45 | // Return value: 46 | // None 47 | // 48 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 49 | void rf_set_rx_addr(uint8_t * address, uint16_t len, uint8_t rxpipenum) 50 | { 51 | //Do not allow writes to pipes that don't exist 52 | if(rxpipenum > 5) 53 | { 54 | return; 55 | } 56 | 57 | rf_write_register(RF_RX_ADDR_P0 + rxpipenum, address, len); //Write the requested address to the requested RX pipe 58 | } 59 | -------------------------------------------------------------------------------- /src/pwm/src/pwm_start.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: pwm_start.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "pwm.h" 30 | 31 | 32 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 33 | // 34 | // void pwm_start(pwm_channel_t pwm_channel, uint8_t pwm_duty_cycle) 35 | // 36 | // Description: 37 | // Starts a PWM conversion on the specified PWM channel 38 | // 39 | // Parameters: 40 | // pwm_channel_t pwm_channel - PWM channel with which to run the acquisition 41 | // uint8_t pwm_duty_cycle - duty cycle at which the PWM should run 42 | // 43 | // Return value: 44 | // None 45 | // 46 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 47 | void pwm_start(pwm_channel_t pwm_channel, uint8_t pwm_duty_cycle) 48 | { 49 | //Set the duty cycle and enable the PWM for the requested channel 50 | if(pwm_channel == PWM_CHANNEL_0) 51 | { 52 | PWMDC0 = pwm_duty_cycle; 53 | reg_bits_set(PWMCON, PWMCON_PWM0_ENABLE); 54 | } 55 | else 56 | { 57 | PWMDC1 = pwm_duty_cycle; 58 | reg_bits_set(PWMCON, PWMCON_PWM1_ENABLE); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/gpio/src/gpio_pin_val_set.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: gpio_pin_val_set.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "gpio.h" 30 | 31 | 32 | /////////////////////////////////////////////////////////////////////////////////////////////// 33 | // 34 | // void gpio_pin_val_set(gpio_pin_id_t gpio_pin_id, uint8_t gpio_pin_config_options) 35 | // 36 | // Description: 37 | // Sets a GPIO pin 38 | // 39 | // Parameters: 40 | // gpio_pin_id_t gpio_pin_id - ID of the GPIO pin to be set 41 | // 42 | // Return value: 43 | // None 44 | // 45 | /////////////////////////////////////////////////////////////////////////////////////////////// 46 | void gpio_pin_val_set(gpio_pin_id_t gpio_pin_id) 47 | { 48 | //Process the request based on the pin block 49 | if(gpio_pin_id <= GPIO_PIN_ID_P0_7) 50 | { 51 | gpio_pins_val_set(P0, (1 << (gpio_pin_id % 8))); 52 | } 53 | else if(gpio_pin_id <= GPIO_PIN_ID_P1_7) 54 | { 55 | gpio_pins_val_set(P1, (1 << (gpio_pin_id % 8))); 56 | } 57 | else if(gpio_pin_id <= GPIO_PIN_ID_P2_7) 58 | { 59 | gpio_pins_val_set(P2, (1 << (gpio_pin_id % 8))); 60 | } 61 | else if(gpio_pin_id <= GPIO_PIN_ID_P3_6) 62 | { 63 | gpio_pins_val_set(P3, (1 << (gpio_pin_id % 8))); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/owi/src/owi_receive_byte.c: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: owi_receive_byte.c 4 | // 5 | // Copyright Aleksandr Svalov (Alarus), 2014 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | //////////////////////////////////////////////////////////////////////////////////// 12 | 13 | //////////////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | //////////////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "owi.h" 30 | 31 | 32 | //////////////////////////////////////////////////////////////////////////////////// 33 | // 34 | // uint8_t owi_receive_byte(gpio_pin_id_t owi_pin_id) 35 | // 36 | // Description: 37 | // This function automates the task of receiving a complete byte of data from the OWI 38 | // 39 | // Parameters: 40 | // gpio_pin_id_t owi_pin_id - ID of the OWI pin 41 | // 42 | // Return value: 43 | // uint8_t - The byte read from the OWI 44 | // 45 | //////////////////////////////////////////////////////////////////////////////////// 46 | uint8_t owi_receive_byte(gpio_pin_id_t owi_pin_id) 47 | { 48 | // Clear the input variable. 49 | register uint8_t mask = 0x01; 50 | register uint8_t data = 0x00; 51 | 52 | // Do once for each bit 53 | do 54 | { 55 | // Set the msb if a '1' value is read from the bus. 56 | // Leave as it is ('0') else. 57 | if (owi_read_bit(owi_pin_id)) 58 | { 59 | // Set current bit 60 | data |= mask; 61 | } 62 | // Left shift the mask. 63 | mask <<= 1; 64 | } 65 | while (mask); 66 | return data; 67 | } 68 | -------------------------------------------------------------------------------- /src/gpio/src/gpio_pin_val_clear.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: gpio_pin_val_clear.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "gpio.h" 30 | 31 | 32 | /////////////////////////////////////////////////////////////////////////////////////////////// 33 | // 34 | // void gpio_pin_val_clear(gpio_pin_id_t gpio_pin_id, uint8_t gpio_pin_config_options) 35 | // 36 | // Description: 37 | // Clears a GPIO pin 38 | // 39 | // Parameters: 40 | // gpio_pin_id_t gpio_pin_id - ID of the GPIO pin to be cleared 41 | // 42 | // Return value: 43 | // None 44 | // 45 | /////////////////////////////////////////////////////////////////////////////////////////////// 46 | void gpio_pin_val_clear(gpio_pin_id_t gpio_pin_id) 47 | { 48 | //Process the request based on the pin block 49 | if(gpio_pin_id <= GPIO_PIN_ID_P0_7) 50 | { 51 | gpio_pins_val_clear(P0, (1 << (gpio_pin_id % 8))); 52 | } 53 | else if(gpio_pin_id <= GPIO_PIN_ID_P1_7) 54 | { 55 | gpio_pins_val_clear(P1, (1 << (gpio_pin_id % 8))); 56 | } 57 | else if(gpio_pin_id <= GPIO_PIN_ID_P2_7) 58 | { 59 | gpio_pins_val_clear(P2, (1 << (gpio_pin_id % 8))); 60 | } 61 | else if(gpio_pin_id <= GPIO_PIN_ID_P3_6) 62 | { 63 | gpio_pins_val_clear(P3, (1 << (gpio_pin_id % 8))); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/pwr_clk_mgmt/src/pwr_clk_mgmt_clklf_configure.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: pwr_clk_mgmt_clklf_configure.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "pwr_clk_mgmt.h" 30 | 31 | 32 | /////////////////////////////////////////// 33 | // Internal defines 34 | /////////////////////////////////////////// 35 | #define PWR_CLK_MGMT_CLKLF_CONFIG_OPTION_CLKLFCTRL_MASK 0x07 //Mask for the options used for CLKLFCTRL 36 | 37 | 38 | ///////////////////////////////////////////////////////////////////////////////////////////////////////// 39 | // 40 | // void pwr_clk_mgmt_clklf_configure(uint8_t cclk_config_options) 41 | // 42 | // Description: 43 | // Configures low-frequency clock (CLKLF) 44 | // 45 | // Parameters: 46 | // uint8_t clklf_config_options - CLKLF configuration options 47 | // 48 | // Return value: 49 | // None 50 | // 51 | ///////////////////////////////////////////////////////////////////////////////////////////////////////// 52 | void pwr_clk_mgmt_clklf_configure(uint8_t clklf_config_options) 53 | { 54 | //Set up CLKLFCTRL register from clklf_config_options 55 | CLKLFCTRL = (CLKLFCTRL & ~PWR_CLK_MGMT_CLKLF_CONFIG_OPTION_CLKLFCTRL_MASK) | (clklf_config_options & PWR_CLK_MGMT_CLKLF_CONFIG_OPTION_CLKLFCTRL_MASK); 56 | } 57 | -------------------------------------------------------------------------------- /src/owi/src/owi_pin_configure.c: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: owi_pin_configure.c 4 | // 5 | // Copyright Aleksandr Svalov (Alarus), 2014 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | //////////////////////////////////////////////////////////////////////////////////// 12 | 13 | //////////////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | //////////////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "owi.h" 30 | 31 | 32 | //////////////////////////////////////////////////////////////////////////////////// 33 | // 34 | // void owi_pin_configure(gpio_pin_id_t owi_pin_id) 35 | // 36 | // Description: 37 | // Configures the OWI pin 38 | // 39 | // Parameters: 40 | // gpio_pin_id_t owi_pin_id - ID of the OWI pin to be configured 41 | // 42 | // Return value: 43 | // None 44 | // 45 | //////////////////////////////////////////////////////////////////////////////////// 46 | void owi_pin_configure(gpio_pin_id_t owi_pin_id) 47 | { 48 | gpio_pin_configure(owi_pin_id, GPIO_PIN_CONFIG_OPTION_DIR_OUTPUT | GPIO_PIN_CONFIG_OPTION_OUTPUT_VAL_CLEAR | GPIO_PIN_CONFIG_OPTION_PIN_MODE_OUTPUT_BUFFER_NORMAL_DRIVE_STRENGTH); 49 | gpio_pin_configure(owi_pin_id, GPIO_PIN_CONFIG_OPTION_DIR_INPUT | GPIO_PIN_CONFIG_OPTION_PIN_MODE_INPUT_BUFFER_ON_PULL_UP_RESISTOR); 50 | // The first rising edge can be interpreted by a slave as the end of a reset pulse. 51 | // Delay for the required reset recovery time (H) to be sure that the real reset is interpreted correctly. 52 | delay_us(OWI_DELAY_H); 53 | } 54 | -------------------------------------------------------------------------------- /src/pwr_clk_mgmt/src/pwr_clk_mgmt_op_mode_configure.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: pwr_clk_mgmt_op_mode_configure.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "pwr_clk_mgmt.h" 30 | 31 | 32 | /////////////////////////////////////////// 33 | // Internal defines 34 | /////////////////////////////////////////// 35 | #define PWR_CLK_MGMT_OP_MODE_CONFIG_OPTION_OPMCON_MASK 0x07 //Mask for the options used for OPMCON 36 | 37 | 38 | ///////////////////////////////////////////////////////////////////////////////////////////////////////// 39 | // 40 | // void pwr_clk_mgmt_op_mode_configure(uint8_t op_mode_config_options); 41 | // 42 | // Description: 43 | // Configures special operational modes 44 | // 45 | // Parameters: 46 | // uint8_t op_mode_config_options - operation mode configuration options 47 | // 48 | // Return value: 49 | // None 50 | // 51 | ///////////////////////////////////////////////////////////////////////////////////////////////////////// 52 | void pwr_clk_mgmt_op_mode_configure(uint8_t op_mode_config_options) 53 | { 54 | //Set up OPMCON register from op_mode_config_options 55 | OPMCON = (OPMCON & ~PWR_CLK_MGMT_OP_MODE_CONFIG_OPTION_OPMCON_MASK) | (op_mode_config_options & PWR_CLK_MGMT_OP_MODE_CONFIG_OPTION_OPMCON_MASK); 56 | } 57 | -------------------------------------------------------------------------------- /src/adc/src/adc_start_single_conversion.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: adc_start_conversion.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "adc.h" 30 | 31 | 32 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 33 | // 34 | // void adc_start_conversion(adc_channel_t adc_channel) 35 | // 36 | // Description: 37 | // Starts an ADC conversion on the specified ADC channel. It is unnecessary to call adc_set_input_channel() before using this function, as 38 | // this function does that itself. This function should only be used with single step acquisition mode. 39 | // 40 | // Parameters: 41 | // adc_channel_t adc_channel - ADC channel with which to run the acquisition 42 | // 43 | // Return value: 44 | // None 45 | // 46 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 47 | void adc_start_single_conversion(adc_channel_t adc_channel) 48 | { 49 | adc_set_input_channel(adc_channel); 50 | 51 | //Start the conversion on the specified channel 52 | adc_power_up(); 53 | nop(); nop(); nop(); nop(); //4 clock cycles must elapse before busy flag is set (datasheet v1.3, p. 165) 54 | } 55 | -------------------------------------------------------------------------------- /src/pwr_clk_mgmt/src/pwr_clk_mgmt_pwr_failure_configure.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: pwr_clk_mgmt_pwr_failure_configure.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "pwr_clk_mgmt.h" 30 | 31 | 32 | /////////////////////////////////////////// 33 | // Internal defines 34 | /////////////////////////////////////////// 35 | #define PWR_CLK_MGMT_CLKLF_CONFIG_OPTION_POFCON_MASK 0xF0 //Mask for the options used for POFCON 36 | 37 | 38 | ///////////////////////////////////////////////////////////////////////////////////////////////////////// 39 | // 40 | // void pwr_clk_mgmt_pwr_failure_configure(uint8_t pwr_failure_config_options) 41 | // 42 | // Description: 43 | // Configures power failure options 44 | // 45 | // Parameters: 46 | // uint8_t pwr_failure_config_options - power failure configuration options 47 | // 48 | // Return value: 49 | // None 50 | // 51 | ///////////////////////////////////////////////////////////////////////////////////////////////////////// 52 | void pwr_clk_mgmt_pwr_failure_configure(uint8_t pwr_failure_config_options) 53 | { 54 | //Set up POFCON register from pwr_failure_config_options 55 | POFCON = (POFCON & ~PWR_CLK_MGMT_CLKLF_CONFIG_OPTION_POFCON_MASK) | (pwr_failure_config_options & PWR_CLK_MGMT_CLKLF_CONFIG_OPTION_POFCON_MASK); 56 | } 57 | -------------------------------------------------------------------------------- /src/owi/src/owi_read_bit.c: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: owi_read_bit.c 4 | // 5 | // Copyright Aleksandr Svalov (Alarus), 2014 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | //////////////////////////////////////////////////////////////////////////////////// 12 | 13 | //////////////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | //////////////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "owi.h" 30 | 31 | 32 | //////////////////////////////////////////////////////////////////////////////////// 33 | // 34 | // uint8_t owi_read_bit(gpio_pin_id_t owi_pin_id) 35 | // 36 | // Description: 37 | // Generates the waveform for reception of a bit on the OWI 38 | // 39 | // Parameters: 40 | // gpio_pin_id_t owi_pin_id - ID of the OWI pin 41 | // 42 | // Return value: 43 | // uint8_t - The value of the requested bit 44 | // 45 | //////////////////////////////////////////////////////////////////////////////////// 46 | uint8_t owi_read_bit(gpio_pin_id_t owi_pin_id) 47 | { 48 | // Drive bus low and delay. 49 | gpio_pin_dir_output(owi_pin_id, GPIO_PIN_CONFIG_OPTION_PIN_MODE_OUTPUT_BUFFER_NORMAL_DRIVE_STRENGTH); 50 | delay_us(OWI_DELAY_A); 51 | 52 | // Release bus and delay. 53 | gpio_pin_dir_input(owi_pin_id, GPIO_PIN_CONFIG_OPTION_PIN_MODE_INPUT_BUFFER_ON_PULL_UP_RESISTOR); 54 | delay_us(OWI_DELAY_E); 55 | 56 | // Sample bus and delay. 57 | if (gpio_pin_val_read(owi_pin_id)) 58 | { 59 | delay_us(OWI_DELAY_F); 60 | return 1; 61 | } 62 | else 63 | { 64 | delay_us(OWI_DELAY_F); 65 | return 0; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/gpio/src/gpio_pin_val_complement.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: gpio_pin_val_complement.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "gpio.h" 30 | 31 | 32 | /////////////////////////////////////////////////////////////////////////////////////////////// 33 | // 34 | // void gpio_pin_val_complement(gpio_pin_id_t gpio_pin_id, uint8_t gpio_pin_config_options) 35 | // 36 | // Description: 37 | // Complements a GPIO pin 38 | // 39 | // Parameters: 40 | // gpio_pin_id_t gpio_pin_id - ID of the GPIO pin to be complemented 41 | // 42 | // Return value: 43 | // None 44 | // 45 | /////////////////////////////////////////////////////////////////////////////////////////////// 46 | void gpio_pin_val_complement(gpio_pin_id_t gpio_pin_id) 47 | { 48 | //Process the request based on the pin block 49 | if(gpio_pin_id <= GPIO_PIN_ID_P0_7) 50 | { 51 | gpio_pins_val_complement(P0, (1 << (gpio_pin_id % 8))); 52 | } 53 | else if(gpio_pin_id <= GPIO_PIN_ID_P1_7) 54 | { 55 | gpio_pins_val_complement(P1, (1 << (gpio_pin_id % 8))); 56 | 57 | } 58 | else if(gpio_pin_id <= GPIO_PIN_ID_P2_7) 59 | { 60 | gpio_pins_val_complement(P2, (1 << (gpio_pin_id % 8))); 61 | } 62 | else if(gpio_pin_id <= GPIO_PIN_ID_P3_6) 63 | { 64 | gpio_pins_val_complement(P3, (1 << (gpio_pin_id % 8))); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/rf/src/rf_set_as_tx.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: rf_read_register.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "rf.h" 30 | #include "rf_src.h" 31 | 32 | 33 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 34 | // 35 | // void rf_set_as_tx() 36 | // 37 | // Description: 38 | // Sets the device as a TX 39 | // 40 | // Parameters: 41 | // None 42 | // 43 | // Return value: 44 | // None 45 | // 46 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 47 | void rf_set_as_tx() 48 | { 49 | uint8_t config; 50 | uint8_t ce_status = rf_get_ce(); 51 | 52 | rf_read_register(RF_CONFIG, &config, 1); //Read the current CONFIG value 53 | 54 | //If the device is already configured as a TX, exit 55 | if((config & RF_CONFIG_PRIM_RX) == 0) 56 | { 57 | return; 58 | } 59 | 60 | rf_clear_ce(); //Clear the CE pin to enter TX mode 61 | 62 | //Clear the PRIM_RX bit, then write the old value of CONFIG back to the device 63 | config &= (~RF_CONFIG_PRIM_RX); 64 | rf_write_register(RF_CONFIG, &config, 1); 65 | 66 | //Set the CE pin if it was set coming into this function 67 | if(ce_status) 68 | { 69 | rf_set_ce(); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/adc/src/adc_start_single_conversion_get_value.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: adc_start_conversion_get_value.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "adc.h" 30 | 31 | 32 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 33 | // 34 | // uint8_t adc_start_conversion_get_value(adc_channel_t adc_channel) 35 | // 36 | // Description: 37 | // Starts an ADC conversion on the specified ADC channel and returns the value when finished. It is unnecessary to call adc_set_input_channel() 38 | // or adc_start_conversion() before using this function, as this function does that itself. This function should only be used with single step 39 | // acquisition mode. 40 | // 41 | // Parameters: 42 | // adc_channel_t adc_channel - ADC channel with which to run the acquisition 43 | // 44 | // Return value: 45 | // Value of last conversion 46 | // 47 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 48 | uint16_t adc_start_single_conversion_get_value(adc_channel_t adc_channel) 49 | { 50 | adc_start_single_conversion(adc_channel); 51 | 52 | while(adc_is_conversion_in_progress()); 53 | 54 | return adc_get_result(); 55 | } 56 | -------------------------------------------------------------------------------- /src/gpio/src/gpio_pin_val_read.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: gpio_pin_val_read.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "gpio.h" 30 | 31 | 32 | /////////////////////////////////////////////////////////////////////////////////////////////// 33 | // 34 | // bool gpio_pin_val_read(gpio_pin_id_t gpio_pin_id) 35 | // 36 | // Description: 37 | // Returns the value of the requested GPIO pin 38 | // 39 | // Parameters: 40 | // gpio_pin_id_t gpio_pin_id - ID of the GPIO pin to be read 41 | // 42 | // Return value: 43 | // The value of the requested GPIO pin 44 | // 45 | /////////////////////////////////////////////////////////////////////////////////////////////// 46 | bool gpio_pin_val_read(gpio_pin_id_t gpio_pin_id) 47 | { 48 | bool value = false; 49 | 50 | //Process the request based on the pin block 51 | if(gpio_pin_id <= GPIO_PIN_ID_P0_7) 52 | { 53 | value = P0 & (1 << (gpio_pin_id % 8)); 54 | } 55 | else if(gpio_pin_id <= GPIO_PIN_ID_P1_7) 56 | { 57 | value = P1 & (1 << (gpio_pin_id % 8)); 58 | } 59 | else if(gpio_pin_id <= GPIO_PIN_ID_P2_7) 60 | { 61 | value = P2 & (1 << (gpio_pin_id % 8)); 62 | } 63 | else if(gpio_pin_id <= GPIO_PIN_ID_P3_6) 64 | { 65 | value = P3 & (1 << (gpio_pin_id % 8)); 66 | } 67 | 68 | if(value) 69 | { 70 | return true; 71 | } 72 | else 73 | { 74 | return false; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/timer2/src/timer2_calc_actual_period.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: timer2_calc_crc_val.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "timer2.h" 30 | #include "pwr_clk_mgmt.h" 31 | 32 | 33 | ///////////////////////////////////////////////////////////////////////////////////////////////////////// 34 | // 35 | // uint16_t timer2_calc_actual_period(void) 36 | // 37 | // Description: 38 | // Calculates the timer period based on 39 | // 40 | // Parameters: 41 | // uint16_t crc_val - length of the expected timer period in nanoseconds 42 | // bool t2ps_bit_val - value of the T2CON.T2PS value (timer 2's prescaler) 43 | // 44 | // Return value: 45 | // Actual timer overflow period (subject to rounding errors) calculated given CRC and T2PS values 46 | // 47 | ///////////////////////////////////////////////////////////////////////////////////////////////////////// 48 | float timer2_calc_actual_period(uint16_t crc_val, bool t2ps_bit_val) 49 | { 50 | //Calculates the CRC value from the desired timer overflow period 51 | // 52 | // (65536 - CRC) * (2 ^ PRESCALER) * 12 clocks/timer++ 53 | // period = --------------------------------------------------- 54 | // CCLK_FREQ 55 | return (((((float)65536 - (float)crc_val)) * ((float)(((t2ps_bit_val ? 2 : 1) * 12)))) / ((float)pwr_clk_mgmt_get_cclk_freq_in_hz())); 56 | } 57 | -------------------------------------------------------------------------------- /src/mspi/src/mspi_configure.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: mspi_configure.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "mspi.h" 30 | 31 | /////////////////////////////////////////// 32 | // Internal defines 33 | /////////////////////////////////////////// 34 | #define MSPI_CONFIG_OPTION_SPIMCON0_MASK 0x7F //Mask for the options used for SPIMCON0 35 | #define MSPI_CONFIG_OPTION_SPIMCON1_MASK 0x0F //Mask for the options used for SPIMCON1 36 | 37 | 38 | //////////////////////////////////////////////////////////////////////////////// 39 | // 40 | // void mspi_configure(uint16_t mspi_config_options) 41 | // 42 | // Description: 43 | // Configures the MSPI 44 | // 45 | // Parameters: 46 | // uint16_t mspi_config_options - MSPI configuration options 47 | // 48 | // Return value: 49 | // None 50 | // 51 | //////////////////////////////////////////////////////////////////////////////// 52 | void mspi_configure(uint16_t mspi_config_options) 53 | { 54 | //Set up SPIMCON0 and SPIMCON1 registers from mspi_config_options 55 | SPIMCON0 = (SPIMCON0 & ~MSPI_CONFIG_OPTION_SPIMCON0_MASK) | (((uint8_t)(mspi_config_options >> MSPI_CONFIG_OPTION_SPIMCON0_OFFSET_SHIFT)) & MSPI_CONFIG_OPTION_SPIMCON0_MASK); 56 | SPIMCON1 = (SPIMCON1 & ~MSPI_CONFIG_OPTION_SPIMCON1_MASK) | (((uint8_t)(mspi_config_options >> MSPI_CONFIG_OPTION_SPIMCON1_OFFSET_SHIFT)) & MSPI_CONFIG_OPTION_SPIMCON1_MASK); 57 | } 58 | -------------------------------------------------------------------------------- /src/rf/src/rf_spi_send_read.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: rf_spi_send_read.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "rf.h" 30 | #include "rf_src.h" 31 | 32 | 33 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 34 | // 35 | // void rf_spi_send_read(uint8_t * dataptr, uint16_t len, bool copydata) 36 | // 37 | // Description: 38 | // Sends/reads the requested number of bytes over SPI 39 | // 40 | // Parameters: 41 | // uint8_t * dataptr - pointer to data to be sent and/or read 42 | // uint16_t len - number of bytes of data to be sent and/or read 43 | // bool copydata - true to copy data that is read into dataptr, false otherwise 44 | // 45 | // Return value: 46 | // None 47 | // 48 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 49 | void rf_spi_send_read(uint8_t * dataptr, uint16_t len, bool copydata) 50 | { 51 | uint16_t i; 52 | uint8_t tempbyte; 53 | 54 | //Loop through the values that are to be sent/read 55 | for(i = 0; i < len; i++) 56 | { 57 | tempbyte = rf_spi_send_read_byte(dataptr[i]); //Send the value, and then save the received value 58 | 59 | //If copying of received data is requested, do so 60 | if(copydata != false) 61 | { 62 | dataptr[i] = tempbyte; 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/rf/src/rf_write_tx_payload_noack.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: rf_write_tx_payload_noack.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "rf.h" 30 | #include "rf_src.h" 31 | 32 | 33 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 34 | // 35 | // uint8_t rf_write_tx_payload_noack(uint8_t * dataptr, uint16_t len, bool transmit) 36 | // 37 | // Description: 38 | // Writes the payload to the TX FIFO and forces it to be sent as a no-ack payload 39 | // 40 | // Parameters: 41 | // uint8_t * dataptr - pointer from which the payload data is read 42 | // uint16_t len - number of bytes to write to the payload 43 | // bool transmit - true to transmit the payload immediately, false otherwise 44 | // 45 | // Return value: 46 | // Read value of the STATUS register 47 | // 48 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 49 | uint8_t rf_write_tx_payload_noack(uint8_t * dataptr, uint16_t len, bool transmit) 50 | { 51 | uint8_t status; 52 | 53 | status = rf_spi_execute_command(RF_W_TX_PAYLOAD, dataptr, len, false); //Write the payload 54 | 55 | //Transmit the payload immediately if requested 56 | if(transmit == true) 57 | { 58 | rf_transmit(); 59 | } 60 | 61 | return status; //Return the value of STATUS 62 | } 63 | -------------------------------------------------------------------------------- /src/rf/src/rf_write_tx_payload.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: rf_write_tx_payload.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "rf.h" 30 | #include "rf_src.h" 31 | 32 | 33 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 34 | // 35 | // uint8_t rf_read_rx_payload(uint8_t * dataptr, uint16_t len, bool transmit) 36 | // 37 | // Description: 38 | // Writes the payload to the TX FIFO 39 | // 40 | // Parameters: 41 | // uint8_t * dataptr - pointer from which the payload data is read 42 | // uint16_t len - number of bytes to write to the payload 43 | // bool transmit - true to transmit the payload immediately, false otherwise 44 | // 45 | // Return value: 46 | // Read value of the STATUS register 47 | // 48 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 49 | uint8_t rf_write_tx_payload(uint8_t * dataptr, uint16_t len, bool transmit) 50 | { 51 | uint8_t status; 52 | 53 | status = rf_spi_execute_command(RF_W_TX_PAYLOAD, dataptr, len, false); //Write the payload 54 | 55 | //Transmit the payload immediately if requested (not necessary if CE is already set) 56 | if(transmit) 57 | { 58 | if(!rf_get_ce()) 59 | { 60 | rf_transmit(); 61 | } 62 | } 63 | else 64 | { 65 | rf_clear_ce(); 66 | } 67 | 68 | return status; //Return the value of STATUS 69 | } 70 | -------------------------------------------------------------------------------- /src/owi/src/owi_detect_presence.c: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: owi_detect_presence.c 4 | // 5 | // Copyright Aleksandr Svalov (Alarus), 2014 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | //////////////////////////////////////////////////////////////////////////////////// 12 | 13 | //////////////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | //////////////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "owi.h" 30 | 31 | 32 | //////////////////////////////////////////////////////////////////////////////////// 33 | // 34 | // uint8_t owi_detect_presence(gpio_pin_id_t owi_pin_id) 35 | // 36 | // Description: 37 | // Generates the waveform for transmission of a Reset pulse on the OWI and listens for presence signals. 38 | // 39 | // Parameters: 40 | // gpio_pin_id_t owi_pin_id - ID of the OWI pin 41 | // 42 | // Return value: 43 | // uint8_t "0" - Not detect presence 44 | // uint8_t "1" - Detect presence 45 | // 46 | //////////////////////////////////////////////////////////////////////////////////// 47 | uint8_t owi_detect_presence(gpio_pin_id_t owi_pin_id) 48 | { 49 | // Delay before resetting. 50 | delay_us(OWI_DELAY_G); 51 | 52 | // Drive bus low and delay. 53 | gpio_pin_dir_output(owi_pin_id, GPIO_PIN_CONFIG_OPTION_PIN_MODE_OUTPUT_BUFFER_NORMAL_DRIVE_STRENGTH); 54 | delay_us(OWI_DELAY_H); 55 | 56 | // Release bus and delay. 57 | gpio_pin_dir_input(owi_pin_id, GPIO_PIN_CONFIG_OPTION_PIN_MODE_INPUT_BUFFER_ON_PULL_UP_RESISTOR); 58 | delay_us(OWI_DELAY_I); 59 | 60 | // Sample bus to detect presence signal and delay. 61 | if (gpio_pin_val_read(owi_pin_id)) 62 | { 63 | delay_us(OWI_DELAY_J); 64 | return 1; 65 | } 66 | else 67 | { 68 | delay_us(OWI_DELAY_J); 69 | return 0; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/uart/src/uart_calc_th1_value.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: uart_calc_th1_value.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "uart.h" 30 | #include "pwr_clk_mgmt.h" 31 | 32 | 33 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 34 | // 35 | // uint16_t uart_calc_th1_value(uint32_t desired_baud_rate, bool smod_bit_value) 36 | // 37 | // Description: 38 | // Calculates a value for TH1 from the passed in values for baud rate and SMOD 39 | // 40 | // Parameters: 41 | // uint32_t desired_baud_rate - baud rate use in the calculation 42 | // bool smod_bit_value - value of SMOD to use in the calculation 43 | // 44 | // Return value: 45 | // Value to use for TH1 based on the desired baud rate and SMOD value 46 | // 47 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 48 | uint8_t uart_calc_th1_value(uint32_t desired_baud_rate, bool smod_bit_value) 49 | { 50 | //Calculates the TH1 value from the desired baud rate from the formula 51 | // 52 | // (2 ^ SMOD) * CCLK_FREQ 53 | //TH1 = 256 - ----------------------- 54 | // 384 * desired_baud_rate 55 | // 56 | //The formula below also rounds to the nearest whole number 57 | return (uint8_t)(256 - (((((uint32_t)(2 * ((smod_bit_value != 0) ? 2 : 1) * pwr_clk_mgmt_get_cclk_freq_in_hz())) / ((uint32_t)(384 * desired_baud_rate))) + 1) / 2)); 58 | } 59 | -------------------------------------------------------------------------------- /src/uart/src/uart_calc_actual_baud_rate_from_th1.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: uart_calc_actual_baud_rate_from_th1.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "uart.h" 30 | #include "pwr_clk_mgmt.h" 31 | 32 | 33 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 34 | // 35 | // uint32_t uart_calc_actual_baud_rate_from_th1(uint8_t th1_reg_value, bool smod_bit_value) 36 | // 37 | // Description: 38 | // Calculates a baud rate from the passed in values for TH1 and SMOD 39 | // 40 | // Parameters: 41 | // uint16_t th1_reg_value - value of TH1 to use in the calculation 42 | // bool smod_bit_value - value of SMOD to use in the calculation 43 | // 44 | // Return value: 45 | // Actual baud rate (subject to rounding errors) calculated given TH1 and SMOD values 46 | // 47 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 48 | uint32_t uart_calc_actual_baud_rate_from_th1(uint8_t th1_reg_value, bool smod_bit_value) 49 | { 50 | //Calculates the actual baud rate from the formula 51 | // 52 | // (2 ^ SMOD) * CCLK_FREQ 53 | //BR = ---------------------- 54 | // 384 * (256 - TH1) 55 | // 56 | //The formula below also rounds to the nearest whole number 57 | return (uint32_t)(((((uint32_t)(2 * ((smod_bit_value != 0) ? 2 : 1) * pwr_clk_mgmt_get_cclk_freq_in_hz())) / ((uint32_t)(384 * (256 - th1_reg_value)))) + 1) / 2); 58 | } 59 | -------------------------------------------------------------------------------- /src/memory/src/memory_flash_erase_page.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: memory_flash_erase_page.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "memory.h" 30 | #include "interrupt.h" 31 | 32 | 33 | ///////////////////////////////////////////////////////////////////////////////////////////////////////// 34 | // 35 | // memory_flash_return_t memory_flash_erase_page(uint8_t page_num) 36 | // 37 | // Description: 38 | // Erases the specified page in memory 39 | // 40 | // Parameters: 41 | // uint8_t page_num - the page number to erase 42 | // 43 | // Return value: 44 | // memory_flash_return_t 45 | // 46 | ///////////////////////////////////////////////////////////////////////////////////////////////////////// 47 | memory_flash_return_t memory_flash_erase_page(uint8_t page_num) 48 | { 49 | //Check to make sure that the requested page is valid 50 | if(page_num >= MEMORY_FLASH_NUM_PAGES) 51 | { 52 | return MEMORY_FLASH_BAD_PARAMS; 53 | } 54 | 55 | //Save global interrupt bit and disable 56 | interrupt_save_global_flag(PSW_SB_F0); 57 | interrupt_control_global_disable(); 58 | 59 | //Enable writing 60 | memory_flash_enable_write_access(); 61 | 62 | //Erase the page 63 | FCR = page_num; 64 | 65 | //Wait for the operation to complete and disable write accesses 66 | memory_flash_wait_for_write_complete(); 67 | memory_flash_disable_write_access(); 68 | 69 | //Restore previous value of global interrupt bit 70 | interrupt_restore_global_flag(PSW_SB_F0); 71 | 72 | return MEMORY_FLASH_OK; 73 | } 74 | -------------------------------------------------------------------------------- /src/uart/src/uart_calc_s0rel_value.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // File: uart_calc_s0rel_value.c 4 | // 5 | // Copyright S. Brennen Ball, 2011 6 | // 7 | // The author provides no guarantees, warantees, or promises, implied or 8 | // otherwise. By using this software you agree to indemnify the author 9 | // of any damages incurred by using it. 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // This library is free software; you can redistribute it and/or 15 | // modify it under the terms of the GNU Lesser General Public 16 | // License as published by the Free Software Foundation; either 17 | // version 2.1 of the License, or (at your option) any later version. 18 | // 19 | // This library is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | // Lesser General Public License for more details. 23 | // 24 | // You should have received a copy of the GNU Lesser General Public 25 | // License along with this library; if not, write to the Free Software 26 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | #include "uart.h" 30 | #include "pwr_clk_mgmt.h" 31 | 32 | 33 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 34 | // 35 | // uint16_t uart_calc_s0rel_value(uint32_t desired_baud_rate, bool smod_bit_value) 36 | // 37 | // Description: 38 | // Calculates a value for S0REL from the passed in values for baud rate and SMOD 39 | // 40 | // Parameters: 41 | // uint32_t desired_baud_rate - baud rate use in the calculation 42 | // bool smod_bit_value - value of SMOD to use in the calculation 43 | // 44 | // Return value: 45 | // Value to use for S0REL based on the desired baud rate and SMOD value 46 | // 47 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 48 | uint16_t uart_calc_s0rel_value(uint32_t desired_baud_rate, bool smod_bit_value) 49 | { 50 | //Calculates the S0REL value from the desired baud rate from the formula 51 | // 52 | // (2 ^ SMOD) * CCLK_FREQ 53 | //S0REL = 1024 - ---------------------- 54 | // 64 * desired_baud_rate 55 | // 56 | //The formula below also rounds to the nearest whole number 57 | return (uint16_t)(1024 - (((((uint32_t)(2 * ((smod_bit_value != 0) ? 2 : 1) * pwr_clk_mgmt_get_cclk_freq_in_hz())) / ((uint32_t)(64 * desired_baud_rate))) + 1) / 2)); 58 | } 59 | --------------------------------------------------------------------------------