├── design ├── pcb │ ├── xlyRX.png │ ├── fp-lib-table │ ├── local.pretty │ │ ├── drill_cut.kicad_mod │ │ ├── SMD_conn_edge_1p.kicad_mod │ │ ├── SMD_conn_edge_3.kicad_mod │ │ ├── SMD_conn_edge.kicad_mod │ │ ├── Pin_Header_Angled_2x01_simplified_silk.kicad_mod │ │ ├── Pin_Header_Straight_1x01_Pitch2.54mm_simplified_silk.kicad_mod │ │ ├── SMD_conn_combined_3.kicad_mod │ │ ├── Pin_Header_Straight_1x02_Pitch2.54mm_simplified_silk.kicad_mod │ │ ├── Pin_Header_Straight_1x03_Pitch2.54mm_simplified_silk.kicad_mod │ │ ├── Pin_Header_Edge_1x02.kicad_mod │ │ ├── Pin_Header_Straight_1x04.kicad_mod │ │ ├── Crystal_SMD_5032_4Pads.kicad_mod │ │ ├── module_cc2500_PA_LNA.kicad_mod │ │ └── module_cc2500_PA_LNA_small_pads.kicad_mod │ ├── xlyRX.pro │ └── xlyRX-cache.lib └── case │ └── housing.fcstd ├── code ├── .gitignore ├── systick.h ├── Makefile.compile ├── config.c ├── irq.c ├── adc.h ├── stm32f1xx_ftdi_swd.cfg ├── flash.h ├── spi.h ├── uart.h ├── hardware.h ├── queue.h ├── generic │ ├── generic_stack.h │ ├── generic_stack.c │ ├── generic_circular_buffer.h │ └── generic_circular_buffer.c ├── config.h ├── irq.h ├── uart.c ├── timers.h ├── flash.c ├── spi.c ├── adc.c ├── misc.h ├── systick.c ├── main.c ├── Makefile ├── protocol.h ├── misc.c ├── hardware.c ├── stm32f103.ld ├── timers.c ├── cc2500.c ├── captured │ └── bind ├── startup_stm32f10x.c ├── cc2500.h └── protocol.c ├── README.md └── LICENSE /design/pcb/xlyRX.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/diggit/xlyrx/HEAD/design/pcb/xlyRX.png -------------------------------------------------------------------------------- /design/case/housing.fcstd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/diggit/xlyrx/HEAD/design/case/housing.fcstd -------------------------------------------------------------------------------- /design/pcb/fp-lib-table: -------------------------------------------------------------------------------- 1 | (fp_lib_table 2 | (lib (name local)(type KiCad)(uri "$(KIPRJMOD)/local.pretty")(options "")(descr "")) 3 | ) 4 | -------------------------------------------------------------------------------- /code/.gitignore: -------------------------------------------------------------------------------- 1 | *.elf 2 | *.gck 3 | *.o 4 | *.hex 5 | *.bin 6 | 7 | *.gch 8 | 9 | .gdb_history 10 | .gcc-flags.json 11 | 12 | size.log 13 | 14 | unused/ 15 | -------------------------------------------------------------------------------- /design/pcb/local.pretty/drill_cut.kicad_mod: -------------------------------------------------------------------------------- 1 | (module drill_cut (layer F.Cu) (tedit 5858F3D1) 2 | (fp_text reference MK15 (at 1.3 -2.3) (layer F.SilkS) hide 3 | (effects (font (size 1.5 1.5) (thickness 0.15))) 4 | ) 5 | (fp_text value drill_cut (at 3.5 -2.4) (layer F.Fab) hide 6 | (effects (font (size 1.5 1.5) (thickness 0.15))) 7 | ) 8 | (pad "" np_thru_hole circle (at 0 0) (size 0.5 0.5) (drill 0.5) (layers *.Cu *.Mask)) 9 | ) 10 | -------------------------------------------------------------------------------- /code/systick.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYSTICK_LIB 2 | #define _SYSTICK_LIB 3 | 4 | #include "config.h" 5 | 6 | #define SYSTICK_CALIBRATION (F_CPU/8/SYSTICK_F-1) 7 | #define SYSTICK_1s (SYSTICK_F) 8 | 9 | void systick_init(void); 10 | int8_t systick_blink_set(uint8_t led, uint8_t blinks, uint16_t period); 11 | int8_t systick_blink_stop(uint8_t led); 12 | 13 | #define HARDWARE_BUTTON_HOLD_THRESHOLD 100 //how many ticks of systick timer must be button preseed to change to HOLD state 14 | 15 | enum btn 16 | { 17 | RELEASED, 18 | PRESSED, 19 | HELD 20 | }button_state; 21 | 22 | void (*volatile button_pressed_callback)(void); 23 | void (*volatile button_held_callback)(void); 24 | void (*volatile button_released_callback)(void); 25 | 26 | 27 | #endif -------------------------------------------------------------------------------- /design/pcb/local.pretty/SMD_conn_edge_1p.kicad_mod: -------------------------------------------------------------------------------- 1 | (module SMD_conn_edge_1p (layer F.Cu) (tedit 5858EAED) 2 | (descr "Through hole pin header") 3 | (tags "pin header") 4 | (fp_text reference P3 (at 0 -5.1) (layer F.SilkS) 5 | (effects (font (size 1 1) (thickness 0.15))) 6 | ) 7 | (fp_text value CONN_01X01 (at 0 -3.1) (layer F.Fab) 8 | (effects (font (size 1 1) (thickness 0.15))) 9 | ) 10 | (fp_line (start -2.2 -1.8) (end -2.2 1.8) (layer F.CrtYd) (width 0.05)) 11 | (fp_line (start 2.2 -1.8) (end 2.2 1.8) (layer F.CrtYd) (width 0.05)) 12 | (fp_line (start -2.2 -1.8) (end 2.2 -1.8) (layer F.CrtYd) (width 0.05)) 13 | (fp_line (start -2.2 1.8) (end 2.2 1.8) (layer F.CrtYd) (width 0.05)) 14 | (pad 1 smd rect (at 0 0) (size 3 1.7272) (layers F.Cu F.Paste F.Mask)) 15 | ) 16 | -------------------------------------------------------------------------------- /code/Makefile.compile: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2017 Patrik Bachan 2 | # 3 | # GNU GENERAL PUBLIC LICENSE 4 | # Version 3, 29 June 2007 5 | # 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | 19 | all: $(OBJECTS) 20 | 21 | %.o: %.c 22 | $(CC) $(CFLAGS) $^ -o $@ 23 | 24 | -------------------------------------------------------------------------------- /design/pcb/local.pretty/SMD_conn_edge_3.kicad_mod: -------------------------------------------------------------------------------- 1 | (module SMD_conn_edge_3 (layer F.Cu) (tedit 58727C65) 2 | (descr "Through hole pin header") 3 | (tags "pin header") 4 | (fp_text reference P2 (at 0 -5.1) (layer F.SilkS) hide 5 | (effects (font (size 1 1) (thickness 0.2))) 6 | ) 7 | (fp_text value S_EDGE (at -1.632 0) (layer F.Fab) hide 8 | (effects (font (size 0.5 0.5) (thickness 0.125))) 9 | ) 10 | (fp_line (start -2.2 6.9) (end 2.2 6.9) (layer F.CrtYd) (width 0.05)) 11 | (fp_line (start -2.2 -1.8) (end 2.2 -1.8) (layer F.CrtYd) (width 0.05)) 12 | (fp_line (start 2.2 -1.8) (end 2.2 6.9) (layer F.CrtYd) (width 0.05)) 13 | (fp_line (start -2.2 -1.8) (end -2.2 6.9) (layer F.CrtYd) (width 0.05)) 14 | (pad 3 smd rect (at 0 5.08) (size 3 1.7272) (layers F.Cu F.Paste F.Mask)) 15 | (pad 2 smd rect (at 0 2.54) (size 3 1.7272) (layers F.Cu F.Paste F.Mask)) 16 | (pad 1 smd rect (at 0 0) (size 3 1.7272) (layers F.Cu F.Paste F.Mask)) 17 | ) 18 | -------------------------------------------------------------------------------- /code/config.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Patrik Bachan 2 | // 3 | // GNU GENERAL PUBLIC LICENSE 4 | // Version 3, 29 June 2007 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | #include "config.h" 20 | #include "misc.h" 21 | 22 | const struct SPI_SLAVE SPI_SLAVE_LIST[]={ 23 | [CC2500_SPI_SLAVE_ID]={GPIOB,6}, 24 | // {GPIOA,4} 25 | }; -------------------------------------------------------------------------------- /design/pcb/local.pretty/SMD_conn_edge.kicad_mod: -------------------------------------------------------------------------------- 1 | (module SMD_conn_edge (layer F.Cu) (tedit 5855B758) 2 | (descr "Through hole pin header") 3 | (tags "pin header") 4 | (fp_text reference P3 (at 0 -5.1) (layer F.SilkS) 5 | (effects (font (size 1 1) (thickness 0.15))) 6 | ) 7 | (fp_text value CONN_01X04 (at 0 -3.1) (layer F.Fab) 8 | (effects (font (size 1 1) (thickness 0.15))) 9 | ) 10 | (fp_line (start -2.2 -1.8) (end -2.2 9.4) (layer F.CrtYd) (width 0.05)) 11 | (fp_line (start 2.2 -1.8) (end 2.2 9.4) (layer F.CrtYd) (width 0.05)) 12 | (fp_line (start -2.2 -1.8) (end 2.2 -1.8) (layer F.CrtYd) (width 0.05)) 13 | (fp_line (start -2.2 9.4) (end 2.2 9.4) (layer F.CrtYd) (width 0.05)) 14 | (pad 1 smd rect (at 0 0) (size 3 1.7272) (layers F.Cu F.Paste F.Mask)) 15 | (pad 2 smd rect (at 0 2.54) (size 3 1.7272) (layers F.Cu F.Paste F.Mask)) 16 | (pad 3 smd rect (at 0 5.08) (size 3 1.7272) (layers F.Cu F.Paste F.Mask)) 17 | (pad 4 smd rect (at 0 7.62) (size 3 1.7272) (layers F.Cu F.Paste F.Mask)) 18 | ) 19 | -------------------------------------------------------------------------------- /code/irq.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Patrik Bachan 2 | // 3 | // GNU GENERAL PUBLIC LICENSE 4 | // Version 3, 29 June 2007 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | #include "irq.h" 20 | #include "misc.h" 21 | #include "stm32f103xb.h" 22 | 23 | void irq_NVIC_ISE(int8_t interrupt) 24 | { 25 | if(interrupt<0)//negative are exceptions, ignored 26 | return; 27 | NVIC->ISER[interrupt/32]=BIT(interrupt%32); 28 | } -------------------------------------------------------------------------------- /code/adc.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Patrik Bachan 2 | // 3 | // GNU GENERAL PUBLIC LICENSE 4 | // Version 3, 29 June 2007 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | #ifndef _ADC_LIB 20 | #define _ADC_LIB 21 | #include "config.h" 22 | #include 23 | #include "misc.h" 24 | #include "stm32f103xb.h" 25 | // #include "uart.h" 26 | 27 | void adc_init_single(void); 28 | void adc_calibrate(void); 29 | uint16_t adc_measure_single_blocking(uint8_t input); 30 | 31 | #endif -------------------------------------------------------------------------------- /design/pcb/local.pretty/Pin_Header_Angled_2x01_simplified_silk.kicad_mod: -------------------------------------------------------------------------------- 1 | (module Pin_Header_Angled_2x01_simplified_silk (layer F.Cu) (tedit 58727A89) 2 | (descr "Through hole pin header") 3 | (tags "pin header") 4 | (fp_text reference P12 (at 1.14 -2.4) (layer F.SilkS) hide 5 | (effects (font (size 1 1) (thickness 0.2))) 6 | ) 7 | (fp_text value AIN (at -2.06 0.1 -270) (layer F.SilkS) 8 | (effects (font (size 0.5 0.5) (thickness 0.125))) 9 | ) 10 | (fp_line (start -1.35 -1.75) (end -1.35 1.75) (layer F.CrtYd) (width 0.05)) 11 | (fp_line (start 13.2 -1.75) (end 13.2 1.75) (layer F.CrtYd) (width 0.05)) 12 | (fp_line (start -1.35 -1.75) (end 13.2 -1.75) (layer F.CrtYd) (width 0.05)) 13 | (fp_line (start -1.35 1.75) (end 13.2 1.75) (layer F.CrtYd) (width 0.05)) 14 | (pad 1 thru_hole rect (at 0 0) (size 1.7272 1.7272) (drill 1.016) (layers *.Cu *.Mask)) 15 | (pad 2 thru_hole oval (at 2.54 0) (size 1.7272 1.7272) (drill 1.016) (layers *.Cu *.Mask)) 16 | (model ${KISYS3DMOD}/Pin_Headers.3dshapes/Pin_Header_Angled_2x01_Pitch2.54mm.wrl 17 | (at (xyz 0.05 0 -0.07874015748031496)) 18 | (scale (xyz 1 1 1)) 19 | (rotate (xyz 0 180 90)) 20 | ) 21 | ) 22 | -------------------------------------------------------------------------------- /code/stm32f1xx_ftdi_swd.cfg: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2017 Patrik Bachan 2 | # 3 | # GNU GENERAL PUBLIC LICENSE 4 | # Version 3, 29 June 2007 5 | # 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | 19 | interface ftdi 20 | ftdi_vid_pid 0x0403 0x6010 21 | ftdi_layout_init 0x0038 0x003b 22 | ftdi_layout_signal nTRST -oe 0x0010 -data 0x0010 23 | ftdi_layout_signal nSRST -oe 0x0020 -data 0x0020 24 | 25 | source [find interface/ftdi/swd-resistor-hack.cfg] 26 | source [find target/stm32f1x.cfg] 27 | 28 | reset_config srst_only separate srst_push_pull 29 | adapter_khz 1000 30 | -------------------------------------------------------------------------------- /code/flash.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Patrik Bachan 2 | // 3 | // GNU GENERAL PUBLIC LICENSE 4 | // Version 3, 29 June 2007 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | #ifndef _FLASH 20 | #define _FLASH 21 | 22 | #include "stm32f103xb.h" 23 | #include 24 | 25 | #define FLASH_PAGE_SIZE 1024 26 | #define FLASH_PAGE_COUNT 64 27 | #define FLASH_PAGE_LAST (FLASH_PAGE_COUNT-1) 28 | #define FLASH_PAGE_ADDR(PAGE) (FLASH_BASE+(PAGE)*FLASH_PAGE_SIZE) 29 | 30 | void flash_unlock(void); 31 | void flash_page_erase(uint16_t *destination); 32 | void flash_write(uint16_t *destination, uint16_t data); 33 | 34 | #endif -------------------------------------------------------------------------------- /design/pcb/local.pretty/Pin_Header_Straight_1x01_Pitch2.54mm_simplified_silk.kicad_mod: -------------------------------------------------------------------------------- 1 | (module Pin_Header_Straight_1x01_Pitch2.54mm_simplified_silk (layer F.Cu) (tedit 58726CB3) 2 | (descr "Through hole straight pin header, 1x01, 2.54mm pitch, single row") 3 | (tags "Through hole pin header THT 1x01 2.54mm single row") 4 | (fp_text reference P7 (at 0 -2.39) (layer F.SilkS) hide 5 | (effects (font (size 1 1) (thickness 0.15))) 6 | ) 7 | (fp_text value ALT_PWR (at 0 2.39) (layer F.Fab) 8 | (effects (font (size 1 1) (thickness 0.15))) 9 | ) 10 | (fp_line (start -1.27 -1.27) (end -1.27 1.27) (layer F.Fab) (width 0.1)) 11 | (fp_line (start -1.27 1.27) (end 1.27 1.27) (layer F.Fab) (width 0.1)) 12 | (fp_line (start 1.27 1.27) (end 1.27 -1.27) (layer F.Fab) (width 0.1)) 13 | (fp_line (start 1.27 -1.27) (end -1.27 -1.27) (layer F.Fab) (width 0.1)) 14 | (fp_line (start -1.6 -1.6) (end -1.6 1.6) (layer F.CrtYd) (width 0.05)) 15 | (fp_line (start -1.6 1.6) (end 1.6 1.6) (layer F.CrtYd) (width 0.05)) 16 | (fp_line (start 1.6 1.6) (end 1.6 -1.6) (layer F.CrtYd) (width 0.05)) 17 | (fp_line (start 1.6 -1.6) (end -1.6 -1.6) (layer F.CrtYd) (width 0.05)) 18 | (pad 1 thru_hole rect (at 0 0) (size 1.7 1.7) (drill 1) (layers *.Cu *.Mask)) 19 | (model Pin_Headers.3dshapes/Pin_Header_Straight_1x01_Pitch2.54mm.wrl 20 | (at (xyz 0 0 0)) 21 | (scale (xyz 1 1 1)) 22 | (rotate (xyz 0 0 90)) 23 | ) 24 | ) 25 | -------------------------------------------------------------------------------- /code/spi.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Patrik Bachan 2 | // 3 | // GNU GENERAL PUBLIC LICENSE 4 | // Version 3, 29 June 2007 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | #ifndef _SPI_LIB 20 | #define _SPI_LIB 21 | 22 | #include "config.h" 23 | #include "misc.h" 24 | #include 25 | 26 | int8_t spi_start(uint8_t slave_id); 27 | int8_t spi_end(void); 28 | 29 | void spi_init(uint8_t prescaler); 30 | void spi_exchange(uint8_t operation,uint8_t length ,uint8_t* data); 31 | 32 | #define SPI_W 1 33 | #define SPI_R 2 //do not use as standalone 34 | #define SPI_RW (SPI_R|SPI_W) 35 | 36 | enum{ 37 | SPI_PSC_2=0, 38 | SPI_PSC_4, 39 | SPI_PSC_8, 40 | SPI_PSC_16, 41 | SPI_PSC_32, 42 | SPI_PSC_64, 43 | SPI_PSC_128, 44 | SPI_PSC_256 45 | }; 46 | 47 | 48 | #endif -------------------------------------------------------------------------------- /code/uart.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Patrik Bachan 2 | // 3 | // GNU GENERAL PUBLIC LICENSE 4 | // Version 3, 29 June 2007 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | #ifndef _STM_UART 20 | #define _STM_UART 21 | 22 | #include "config.h" 23 | #include 24 | 25 | #ifndef UART_BAUD 26 | #error "UART_BAUD not defined" 27 | #endif 28 | void uart_init(void (*rx_handler)(uint8_t rxed)); 29 | void uart_rx_handler_set(void (*rx_handler)(uint8_t rxed)); 30 | void uart_send_byte_array_blocking(const uint8_t *data); 31 | void uart_send_byte_blocking(uint8_t data); 32 | void (*uart_rx_handler)(uint8_t rxed); //pointer to function called on RXed character 33 | 34 | //helpers 35 | #define uart_send_string_blocking(str) uart_send_byte_array_blocking((uint8_t*)str) 36 | 37 | #endif -------------------------------------------------------------------------------- /design/pcb/local.pretty/SMD_conn_combined_3.kicad_mod: -------------------------------------------------------------------------------- 1 | (module SMD_conn_combined_3 (layer F.Cu) (tedit 58727F71) 2 | (descr "Through hole pin header") 3 | (tags "pin header") 4 | (fp_text reference P12 (at 0 -5.1) (layer F.SilkS) hide 5 | (effects (font (size 1 1) (thickness 0.2))) 6 | ) 7 | (fp_text value AIN (at -1.632 0) (layer F.Fab) hide 8 | (effects (font (size 0.5 0.5) (thickness 0.125))) 9 | ) 10 | (fp_line (start -2.2 6.9) (end 2.2 6.9) (layer F.CrtYd) (width 0.05)) 11 | (fp_line (start -2.2 -1.8) (end 2.2 -1.8) (layer F.CrtYd) (width 0.05)) 12 | (fp_line (start 2.2 -1.8) (end 2.2 6.9) (layer F.CrtYd) (width 0.05)) 13 | (fp_line (start -2.2 -1.8) (end -2.2 6.9) (layer F.CrtYd) (width 0.05)) 14 | (pad 3 smd rect (at 0 5.08) (size 3 1.7272) (layers F.Cu F.Paste F.Mask)) 15 | (pad 2 smd rect (at 0 2.54) (size 3 1.7272) (layers F.Cu F.Paste F.Mask)) 16 | (pad 1 smd rect (at 0 0) (size 3 1.7272) (layers F.Cu F.Paste F.Mask)) 17 | (pad 1 thru_hole oval (at -0.8 0) (size 1 1.7272) (drill 1) (layers *.Cu *.Mask)) 18 | (pad 2 thru_hole oval (at -0.8 2.54) (size 1 1.7272) (drill 1) (layers *.Cu *.Mask)) 19 | (pad 3 thru_hole oval (at -0.8 5.08) (size 1 1.7272) (drill 1) (layers *.Cu *.Mask)) 20 | (model ${KISYS3DMOD}/Pin_Headers.3dshapes/Pin_Header_Straight_1x03_Pitch2.54mm.wrl 21 | (at (xyz -0.07874015748031496 -0.1 0.01181102362204724)) 22 | (scale (xyz 1 1 1)) 23 | (rotate (xyz -90 0 90)) 24 | ) 25 | ) 26 | -------------------------------------------------------------------------------- /design/pcb/local.pretty/Pin_Header_Straight_1x02_Pitch2.54mm_simplified_silk.kicad_mod: -------------------------------------------------------------------------------- 1 | (module Pin_Header_Straight_1x02_Pitch2.54mm_simplified_silk (layer F.Cu) (tedit 58726C69) 2 | (descr "Through hole straight pin header, 1x02, 2.54mm pitch, single row") 3 | (tags "Through hole pin header THT 1x02 2.54mm single row") 4 | (fp_text reference P8 (at 0 -2.39) (layer F.SilkS) hide 5 | (effects (font (size 1 1) (thickness 0.15))) 6 | ) 7 | (fp_text value PWR_SLCT (at 0 4.93) (layer F.Fab) 8 | (effects (font (size 1 1) (thickness 0.15))) 9 | ) 10 | (fp_line (start -1.27 -1.27) (end -1.27 3.81) (layer F.Fab) (width 0.1)) 11 | (fp_line (start -1.27 3.81) (end 1.27 3.81) (layer F.Fab) (width 0.1)) 12 | (fp_line (start 1.27 3.81) (end 1.27 -1.27) (layer F.Fab) (width 0.1)) 13 | (fp_line (start 1.27 -1.27) (end -1.27 -1.27) (layer F.Fab) (width 0.1)) 14 | (fp_line (start -0.5 -1.3) (end 0.5 -1.3) (layer F.SilkS) (width 0.12)) 15 | (fp_line (start -1.6 -1.6) (end -1.6 4.1) (layer F.CrtYd) (width 0.05)) 16 | (fp_line (start -1.6 4.1) (end 1.6 4.1) (layer F.CrtYd) (width 0.05)) 17 | (fp_line (start 1.6 4.1) (end 1.6 -1.6) (layer F.CrtYd) (width 0.05)) 18 | (fp_line (start 1.6 -1.6) (end -1.6 -1.6) (layer F.CrtYd) (width 0.05)) 19 | (pad 1 thru_hole rect (at 0 0) (size 1.7 1.7) (drill 1) (layers *.Cu *.Mask)) 20 | (pad 2 thru_hole oval (at 0 2.54) (size 1.7 1.7) (drill 1) (layers *.Cu *.Mask)) 21 | (model Pin_Headers.3dshapes/Pin_Header_Straight_1x02_Pitch2.54mm.wrl 22 | (at (xyz 0 -0.05 0)) 23 | (scale (xyz 1 1 1)) 24 | (rotate (xyz 0 0 90)) 25 | ) 26 | ) 27 | -------------------------------------------------------------------------------- /design/pcb/local.pretty/Pin_Header_Straight_1x03_Pitch2.54mm_simplified_silk.kicad_mod: -------------------------------------------------------------------------------- 1 | (module Pin_Header_Straight_1x03_Pitch2.54mm_simplified_silk (layer F.Cu) (tedit 58726BD3) 2 | (descr "Through hole straight pin header, 1x03, 2.54mm pitch, single row") 3 | (tags "Through hole pin header THT 1x03 2.54mm single row") 4 | (fp_text reference S1 (at 0 -2.39) (layer F.SilkS) hide 5 | (effects (font (size 1 1) (thickness 0.15))) 6 | ) 7 | (fp_text value SERVO (at 0 7.47) (layer F.Fab) 8 | (effects (font (size 1 1) (thickness 0.15))) 9 | ) 10 | (fp_line (start 1.6 -1.6) (end -1.6 -1.6) (layer F.CrtYd) (width 0.05)) 11 | (fp_line (start 1.6 6.6) (end 1.6 -1.6) (layer F.CrtYd) (width 0.05)) 12 | (fp_line (start -1.6 6.6) (end 1.6 6.6) (layer F.CrtYd) (width 0.05)) 13 | (fp_line (start -1.6 -1.6) (end -1.6 6.6) (layer F.CrtYd) (width 0.05)) 14 | (fp_line (start -0.7 -1.4) (end 0.6 -1.4) (layer F.SilkS) (width 0.12)) 15 | (fp_line (start 1.27 -1.27) (end -1.27 -1.27) (layer F.Fab) (width 0.1)) 16 | (fp_line (start 1.27 6.35) (end 1.27 -1.27) (layer F.Fab) (width 0.1)) 17 | (fp_line (start -1.27 6.35) (end 1.27 6.35) (layer F.Fab) (width 0.1)) 18 | (fp_line (start -1.27 -1.27) (end -1.27 6.35) (layer F.Fab) (width 0.1)) 19 | (pad 3 thru_hole oval (at 0 5.08) (size 1.7 1.7) (drill 1) (layers *.Cu *.Mask)) 20 | (pad 2 thru_hole oval (at 0 2.54) (size 1.7 1.7) (drill 1) (layers *.Cu *.Mask)) 21 | (pad 1 thru_hole rect (at 0 0) (size 1.7 1.7) (drill 1) (layers *.Cu *.Mask)) 22 | (model Pin_Headers.3dshapes/Pin_Header_Straight_1x03_Pitch2.54mm.wrl 23 | (at (xyz 0 -0.1 0)) 24 | (scale (xyz 1 1 1)) 25 | (rotate (xyz 0 0 90)) 26 | ) 27 | ) 28 | -------------------------------------------------------------------------------- /code/hardware.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Patrik Bachan 2 | // 3 | // GNU GENERAL PUBLIC LICENSE 4 | // Version 3, 29 June 2007 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | #ifndef _HARDWARE_LIB 20 | #define _HARDWARE_LIB 21 | 22 | #include "stm32f103xb.h" 23 | #include "misc.h" 24 | #include 25 | 26 | void gpio_init(void); 27 | 28 | #define HARDWARE_LED_1 0 29 | #define HARDWARE_LED_2 1 30 | #define HARDWARE_LED_COUNT 2 31 | 32 | inline void led_on(uint8_t led) 33 | { 34 | switch(led) 35 | { 36 | case HARDWARE_LED_1: 37 | GPIOC->BSRR=GPIO_BSRR_BR13; 38 | return; 39 | 40 | case HARDWARE_LED_2: 41 | GPIOC->BSRR=GPIO_BSRR_BR14; 42 | return; 43 | } 44 | } 45 | 46 | inline void led_off(uint8_t led) 47 | { 48 | switch(led) 49 | { 50 | case HARDWARE_LED_1: 51 | GPIOC->BSRR=GPIO_BSRR_BS13; 52 | return; 53 | 54 | case HARDWARE_LED_2: 55 | GPIOC->BSRR=GPIO_BSRR_BS14; 56 | return; 57 | } 58 | } 59 | 60 | inline uint8_t button_read(void) 61 | { 62 | if(bit_get(GPIOC->IDR, GPIO_IDR_IDR15)) 63 | return 0; 64 | else 65 | return 1; 66 | } 67 | 68 | #endif -------------------------------------------------------------------------------- /code/queue.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Patrik Bachan 2 | // 3 | // GNU GENERAL PUBLIC LICENSE 4 | // Version 3, 29 June 2007 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | #ifndef _QUEUE 20 | #define _QUEUE 21 | 22 | 23 | #include "misc.h" 24 | #include "irq.h" 25 | 26 | // 0 NULL (mem_start) 27 | // 1 task (first) 28 | // 2 task 29 | // 3 task 30 | // 4 NULL (last) 31 | // 5 NULL 32 | // 6 NULL (mem_end) 33 | 34 | 35 | // void queue_init(struct queue *queue) 36 | // { 37 | // queue->mem_end=&queue->mem_start[QUEUE_SIZE-1]; 38 | // queue->first=queue->mem_start;//not much important as we spin through buffer 39 | // queue->last=queue->mem_start; 40 | // } 41 | 42 | #define CB_NAME queue 43 | #define CB_SIZE 16 44 | #define CB_TYPE struct queue_task 45 | #define CB_ATOMIC 46 | #include "irq.h" 47 | #include "generic/generic_circular_buffer.c" 48 | 49 | int8_t queue_process(void) 50 | { 51 | if(queue_usage==0)//nothind process 52 | return 0; 53 | 54 | struct queue_task task=QUEUE_TASK_EMPTY(); 55 | 56 | if(queue_get(&task)!=CB_OK) 57 | return -1; 58 | 59 | task.handler(task.parameter); 60 | 61 | return 1; 62 | 63 | } 64 | 65 | #endif -------------------------------------------------------------------------------- /design/pcb/local.pretty/Pin_Header_Edge_1x02.kicad_mod: -------------------------------------------------------------------------------- 1 | (module Pin_Header_Edge_1x02 (layer F.Cu) (tedit 583D6972) 2 | (descr "Through hole pin header") 3 | (tags "pin header") 4 | (fp_text reference P? (at 0 -2.6) (layer F.SilkS) 5 | (effects (font (size 1 1) (thickness 0.15))) 6 | ) 7 | (fp_text value Pin_Header_Edge_1x02 (at 10.2 -2.6) (layer F.Fab) 8 | (effects (font (size 1 1) (thickness 0.15))) 9 | ) 10 | (fp_line (start -2 -1.6) (end -2 1.6) (layer F.CrtYd) (width 0.05)) 11 | (fp_line (start 11.2 -1.6) (end 11.2 1.6) (layer F.CrtYd) (width 0.05)) 12 | (fp_line (start -2 -1.6) (end 11.2 -1.6) (layer F.CrtYd) (width 0.05)) 13 | (fp_line (start -2 1.6) (end 11.2 1.6) (layer F.CrtYd) (width 0.05)) 14 | (fp_line (start 2.159 -0.254) (end 1.778 -0.254) (layer Dwgs.User) (width 0.15)) 15 | (fp_line (start 2.159001 0.254) (end 1.778 0.254) (layer Dwgs.User) (width 0.15)) 16 | (fp_line (start 2.159 -1.27) (end 4.699 -1.27) (layer Dwgs.User) (width 0.15)) 17 | (fp_line (start 4.699 1.27) (end 4.699 -1.27) (layer Dwgs.User) (width 0.15)) 18 | (fp_line (start 10.795 0.254) (end 4.699 0.254) (layer Dwgs.User) (width 0.15)) 19 | (fp_line (start 10.795 -0.254) (end 10.795 0.254) (layer Dwgs.User) (width 0.15)) 20 | (fp_line (start 4.699 -0.254) (end 10.795 -0.254) (layer Dwgs.User) (width 0.15)) 21 | (fp_line (start 2.159 -1.27) (end 2.159 1.27) (layer Dwgs.User) (width 0.15)) 22 | (fp_line (start 4.699 1.27) (end 2.159 1.27) (layer Dwgs.User) (width 0.15)) 23 | (pad 1 smd rect (at 0 0) (size 3 2.032) (layers F.Cu F.Paste F.Mask)) 24 | (pad 2 smd rect (at 0 0) (size 3 2.032) (layers B.Cu B.Paste B.Mask)) 25 | (model Pin_Headers.3dshapes/Pin_Header_Straight_1x02.wrl 26 | (at (xyz 0.07874015748031496 0 -0.03543307086614173)) 27 | (scale (xyz 1 1 1)) 28 | (rotate (xyz 0 -90 0)) 29 | ) 30 | ) 31 | -------------------------------------------------------------------------------- /design/pcb/local.pretty/Pin_Header_Straight_1x04.kicad_mod: -------------------------------------------------------------------------------- 1 | (module Pin_Headers:Pin_Header_Straight_1x04 (layer F.Cu) (tedit 0) 2 | (descr "Through hole pin header") 3 | (tags "pin header") 4 | (fp_text reference REF** (at 0 -5.1) (layer F.SilkS) 5 | (effects (font (size 1 1) (thickness 0.15))) 6 | ) 7 | (fp_text value Pin_Header_Straight_1x04 (at 0 -3.1) (layer F.Fab) 8 | (effects (font (size 1 1) (thickness 0.15))) 9 | ) 10 | (fp_line (start -1.75 -1.75) (end -1.75 9.4) (layer F.CrtYd) (width 0.05)) 11 | (fp_line (start 1.75 -1.75) (end 1.75 9.4) (layer F.CrtYd) (width 0.05)) 12 | (fp_line (start -1.75 -1.75) (end 1.75 -1.75) (layer F.CrtYd) (width 0.05)) 13 | (fp_line (start -1.75 9.4) (end 1.75 9.4) (layer F.CrtYd) (width 0.05)) 14 | (fp_line (start -1.27 1.27) (end -1.27 8.89) (layer F.SilkS) (width 0.15)) 15 | (fp_line (start 1.27 1.27) (end 1.27 8.89) (layer F.SilkS) (width 0.15)) 16 | (fp_line (start 1.55 -1.55) (end 1.55 0) (layer F.SilkS) (width 0.15)) 17 | (fp_line (start -1.27 8.89) (end 1.27 8.89) (layer F.SilkS) (width 0.15)) 18 | (fp_line (start 1.27 1.27) (end -1.27 1.27) (layer F.SilkS) (width 0.15)) 19 | (fp_line (start -1.55 0) (end -1.55 -1.55) (layer F.SilkS) (width 0.15)) 20 | (fp_line (start -1.55 -1.55) (end 1.55 -1.55) (layer F.SilkS) (width 0.15)) 21 | (pad 1 thru_hole rect (at 0 0) (size 2.032 1.7272) (drill 1.016) (layers *.Cu *.Mask)) 22 | (pad 2 thru_hole oval (at 0 2.54) (size 2.032 1.7272) (drill 1.016) (layers *.Cu *.Mask)) 23 | (pad 3 thru_hole oval (at 0 5.08) (size 2.032 1.7272) (drill 1.016) (layers *.Cu *.Mask)) 24 | (pad 4 thru_hole oval (at 0 7.62) (size 2.032 1.7272) (drill 1.016) (layers *.Cu *.Mask)) 25 | (model Pin_Headers.3dshapes/Pin_Header_Straight_1x04.wrl 26 | (at (xyz 0 -0.15 0)) 27 | (scale (xyz 1 1 1)) 28 | (rotate (xyz 0 0 90)) 29 | ) 30 | ) 31 | -------------------------------------------------------------------------------- /code/generic/generic_stack.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Patrik Bachan 2 | // 3 | // GNU GENERAL PUBLIC LICENSE 4 | // Version 3, 29 June 2007 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | #ifndef _LIB_GENERIC_STACK 20 | #define _LIB_GENERIC_STACK 21 | 22 | #include 23 | 24 | // #define STACK_TYPE int16_t 25 | // #define STACK_NAME s16 26 | // #define STACK_SIZE 27 | 28 | //OMG! 29 | #define helper2(a,b,c) a##_##b##_##c 30 | #define helper(a,b,c) helper2(a,b,c) 31 | #ifdef STACK_NAME 32 | #define _S(a) helper(stack,STACK_NAME,a) 33 | #else 34 | #define _S(a) stack_##a 35 | #endif 36 | 37 | #define STACK_ERROR_NONE 0 38 | #define STACK_ERROR_OVERFLOW 1 39 | #define STACK_ERROR_UNDERFLOW 2 40 | 41 | //TOP.......<-PTR->......BOTTOM, NULL~EMPTY 42 | 43 | struct stack_t 44 | { 45 | STACK_TYPE *top; 46 | STACK_TYPE *bottom; 47 | STACK_TYPE *pointer; 48 | uint8_t size; 49 | uint8_t used; 50 | uint8_t error; 51 | }; 52 | 53 | 54 | void _S(init) (struct stack_t *stack, STACK_TYPE *buffer, uint8_t size); 55 | void _S(push) (struct stack_t *stack, uint16_t data); 56 | STACK_TYPE _S(pop)(struct stack_t *stack); 57 | 58 | // struct stack_init 59 | #endif 60 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # xlyrx 2 | Hobby RC 2.4GHz receiver based on cc2500 and STM32, supporting FrSky 2 Way D-series protocol 3 | 4 | This project is another opensource receiver for cc2500 based radios. 5 | 6 | ## Features 7 | - FrSky 2-way (telemetry) protocol for D-series 8 | - based on ARM MCU (STM32) 9 | - Hardware generated high resolution ppm signal (~4 times higher, than FrSky can tranfer) 10 | - bind time RX-TX frequency offset elimination 11 | - high power power amplifier and high sensitivity low noise amplifier cc2500 module 12 | - alternative power input for channels 5,6,7,8 13 | - 2 analog inputs 14 | - initial work on fail-safes, when signal is lost, outputs are tuned off now, user config is missing 15 | 16 | *ready, but hardcoded for now* 17 | - configurable ppm frequency 18 | - channels 1,2,5,6 are driven by one HW timer, outputs 4,5,7,8 are driven by another 19 | - ppm frequency is defined by 3rd timer, all channels have same frequency for now, to be able to have different ppm frequency for each group, packet timeout timer must be changed from regular timer to systick, then we'll have free HW timer to drive second group of outputs with different frequency 20 | 21 | *HW ready, SW not yet written* 22 | - UART (3,3V) for loading new firmware (bootloader) and RX user configuration 23 | - UART (3,3V) for external telemetry configuration (raw or FrSky format) 24 | - meaningful usage of LED (we have 2 of them, so use them!) 25 | 26 | ### Known issues 27 | - if TX and RX are too close during binding, binding may not be successful (stuck in binding mode) 28 | - maybe some AGC tuning could help 29 | - workaround would be binding procedure restart 30 | 31 | 32 | ## Why? 33 | If you sum up all that time, materials and work, why (I) build this and not buy regular FrSky receiver? For fun! To explore HW, skills... I like the possibility to modify things to way I like them. Easily add new features and make them better than regular ones... 34 | -------------------------------------------------------------------------------- /design/pcb/local.pretty/Crystal_SMD_5032_4Pads.kicad_mod: -------------------------------------------------------------------------------- 1 | (module Crystal_SMD_5032_4Pads (layer F.Cu) (tedit 5855CE21) 2 | (descr "Ceramic SMD crystal, 5.0x3.2mm, 4 Pads") 3 | (tags "crystal oscillator quartz SMD SMT 5032") 4 | (attr smd) 5 | (fp_text reference Y1 (at 0 -3) (layer F.SilkS) 6 | (effects (font (size 1 1) (thickness 0.15))) 7 | ) 8 | (fp_text value 8MHz (at 0 3.25) (layer F.Fab) 9 | (effects (font (size 1 1) (thickness 0.15))) 10 | ) 11 | (fp_line (start -2.6 0.2) (end -3.3 0.2) (layer F.SilkS) (width 0.15)) 12 | (fp_line (start -0.7 1.7) (end -0.7 2.2) (layer F.SilkS) (width 0.15)) 13 | (fp_line (start 2.5 1.6) (end 2.5 -1.6) (layer F.Fab) (width 0.15)) 14 | (fp_line (start -2.5 1.6) (end 2.5 1.6) (layer F.Fab) (width 0.15)) 15 | (fp_line (start -2.5 -1.6) (end -2.5 1.6) (layer F.Fab) (width 0.15)) 16 | (fp_line (start 2.5 -1.6) (end -2.5 -1.6) (layer F.Fab) (width 0.15)) 17 | (fp_line (start 3.5 2.35) (end 3.5 -2.35) (layer F.CrtYd) (width 0.05)) 18 | (fp_line (start -3.5 2.35) (end 3.5 2.35) (layer F.CrtYd) (width 0.05)) 19 | (fp_line (start -3.5 -2.35) (end -3.5 2.35) (layer F.CrtYd) (width 0.05)) 20 | (fp_line (start 3.5 -2.35) (end -3.5 -2.35) (layer F.CrtYd) (width 0.05)) 21 | (fp_line (start 0.70208 1.7) (end -0.7 1.7) (layer F.SilkS) (width 0.15)) 22 | (fp_line (start -0.70104 -1.7) (end 0.70104 -1.7) (layer F.SilkS) (width 0.15)) 23 | (fp_line (start 2.6 0.2) (end 2.6 -0.2) (layer F.SilkS) (width 0.15)) 24 | (fp_line (start -2.6 0.2) (end -2.6 -0.2) (layer F.SilkS) (width 0.15)) 25 | (pad 1 smd rect (at -2 1.2) (size 2 1.3) (layers F.Cu F.Paste F.Mask)) 26 | (pad 2 smd rect (at 2 1.2) (size 2 1.3) (layers F.Cu F.Paste F.Mask)) 27 | (pad 3 smd rect (at 2 -1.2) (size 2 1.3) (layers F.Cu F.Paste F.Mask)) 28 | (pad 4 smd rect (at -2 -1.2) (size 2 1.3) (layers F.Cu F.Paste F.Mask)) 29 | (model Crystals.3dshapes/Crystal_SMD_5032_4Pads.wrl 30 | (at (xyz 0 0 0)) 31 | (scale (xyz 1 1 1)) 32 | (rotate (xyz 0 0 0)) 33 | ) 34 | ) 35 | -------------------------------------------------------------------------------- /code/generic/generic_stack.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Patrik Bachan 2 | // 3 | // GNU GENERAL PUBLIC LICENSE 4 | // Version 3, 29 June 2007 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | #include 20 | #include "generic_stack.h" 21 | 22 | void _S(init) (struct stack_t *stack, STACK_TYPE *buffer, uint8_t size) 23 | { 24 | stack->top = buffer; 25 | stack->pointer = 0; 26 | stack->bottom = stack->top+size-1; 27 | stack->used = 0; 28 | stack->size = size; 29 | } 30 | void _S(push) (struct stack_t *stack, uint16_t data) 31 | { 32 | if(stack->pointer == 0)//push to empty 33 | { 34 | stack->pointer = stack->bottom; 35 | *stack->pointer=data; 36 | stack->used=1; 37 | } 38 | else if(stack->pointer > stack->top)//push next 39 | { 40 | *--stack->pointer=data; 41 | stack->used++; 42 | } 43 | 44 | else if(stack->pointer == stack->top) 45 | stack->error = STACK_ERROR_OVERFLOW; 46 | 47 | } 48 | STACK_TYPE _S(pop)(struct stack_t *stack) 49 | { 50 | STACK_TYPE buff; 51 | if(stack->pointer == stack->bottom) 52 | { 53 | buff = *stack->pointer; 54 | stack->pointer = 0; 55 | stack->used=0; 56 | return buff; 57 | } 58 | else if(stack->pointer > stack->top)//push next 59 | { 60 | stack->used--; 61 | return *stack->pointer++; 62 | } 63 | else if(stack->pointer == 0)//push to empty 64 | stack->error = STACK_ERROR_OVERFLOW; 65 | return 1; 66 | } 67 | -------------------------------------------------------------------------------- /code/config.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Patrik Bachan 2 | // 3 | // GNU GENERAL PUBLIC LICENSE 4 | // Version 3, 29 June 2007 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | #ifndef _CONFIG 20 | #define _CONFIG 21 | 22 | #include "stm32f103xb.h" 23 | #include 24 | 25 | #define XLY_PCB_VERSION 1 26 | 27 | #define MEM_MAGIC 0x71BA //value in flash storage page to indicate valid data 28 | #define MEM_VERSION 1 //when flash storage format changes, increase this value to prevent loading corrupted data 29 | 30 | #define T_us 1000000U 31 | #define T_ms 1000 32 | 33 | #define F_CPU 72000000U 34 | #define F_APB1 (F_CPU/2) 35 | #define F_APB2 (F_CPU) 36 | 37 | #define SYSTICK_F 100 //how often should system process buttons, LEDs,... 38 | 39 | #define UART_BAUD 115200 40 | 41 | #define CC2500_SPI_SLAVE_ID 0 42 | 43 | #define SWDT_RESOLUTION 100//time units 44 | #define SWDT_F_IN (F_CPU) 45 | 46 | #define PPM_TRIG_F_IN (F_APB1*2) //7.2 last note, LOL 47 | #define PPM_TRIG_F_OUT 200//Hz 48 | #define PPM_TRIG_RESOLUTION_us 10// 49 | 50 | #define PPM_CH_A_F_IN (F_APB1*2) //7.2 last note, LOL 51 | #define PPM_CH_B_F_IN (F_APB1*2) //7.2 last note, LOL 52 | 53 | #define PPM_PULSE_ABS_MAX_us 3000//3ms is acheaveable at least 54 | 55 | 56 | //SPI 57 | struct SPI_SLAVE 58 | { 59 | GPIO_TypeDef *PORT; 60 | const uint8_t pin; 61 | }; 62 | //configure SPI slaves in config.c 63 | extern const struct SPI_SLAVE SPI_SLAVE_LIST[]; 64 | 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /code/irq.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Patrik Bachan 2 | // 3 | // GNU GENERAL PUBLIC LICENSE 4 | // Version 3, 29 June 2007 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | #ifndef _IRQ_LIB 20 | #define _IRQ_LIB 21 | 22 | #include 23 | 24 | inline __attribute__( ( always_inline ) ) void irq_enable(void) 25 | { 26 | __asm__ volatile ("cpsie i" : : : "memory"); 27 | } 28 | 29 | 30 | inline __attribute__( ( always_inline ) ) void irq_disable(void) 31 | { 32 | __asm__ volatile ("cpsid i" : : : "memory"); 33 | } 34 | 35 | inline __attribute__( ( always_inline ) ) uint8_t irq_enable_prev(void) 36 | { 37 | uint32_t result; 38 | __asm__ volatile ("MRS %0, primask" : "=r" (result) ); 39 | __asm__ volatile ("cpsie i" : : : "memory"); 40 | return(result); 41 | } 42 | 43 | 44 | inline __attribute__( ( always_inline ) ) uint8_t irq_disable_prev(void) 45 | { 46 | uint32_t result; 47 | __asm__ volatile ("MRS %0, primask" : "=r" (result) ); 48 | __asm__ volatile ("cpsid i" : : : "memory"); 49 | return(result); 50 | } 51 | 52 | inline __attribute__( ( always_inline ) ) uint8_t irq_is_blocked(void) 53 | { 54 | uint32_t result; 55 | __asm__ volatile ("MRS %0, primask" : "=r" (result) ); 56 | return(result); 57 | } 58 | 59 | #define ATOMIC_START() do{uint32_t irq_was_blocked=irq_disable_prev() 60 | //code... 61 | #define ATOMIC_END_RESTORE()\ 62 | if((irq_was_blocked&0x1U)==0)\ 63 | irq_enable();\ 64 | }while(0) 65 | 66 | void irq_NVIC_ISE(int8_t interrupt); 67 | 68 | #endif -------------------------------------------------------------------------------- /code/uart.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Patrik Bachan 2 | // 3 | // GNU GENERAL PUBLIC LICENSE 4 | // Version 3, 29 June 2007 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | #include "stm32f103xb.h" 20 | #include "uart.h" 21 | #include "misc.h" 22 | #include "irq.h" 23 | 24 | void (*uart_rx_handler)(uint8_t rxed)=NULL; 25 | 26 | void uart_init(void (*rx_handler)(uint8_t rxed)) 27 | { 28 | bit_set(RCC->APB2ENR, RCC_APB2ENR_USART1EN); 29 | // USART1->BRR= 39<BRR= 19<CR1= USART_CR1_UE | USART_CR1_TE | USART_CR1_RE | USART_CR1_RXNEIE; 32 | uart_rx_handler_set(rx_handler); 33 | } 34 | 35 | void uart_rx_handler_set(void (*rx_handler)(uint8_t rxed)) 36 | { 37 | uart_rx_handler=rx_handler; 38 | irq_NVIC_ISE(USART1_IRQn); 39 | } 40 | 41 | void uart_send_byte_array_blocking(const uint8_t *data) 42 | { 43 | for(;*data!=0; data++) 44 | { 45 | uart_send_byte_blocking(*data); 46 | } 47 | } 48 | 49 | void uart_send_byte_blocking(uint8_t data) 50 | { 51 | USART1->DR=data; 52 | while (!bit_get(USART1->SR,USART_SR_TXE))//wait for TX register empty 53 | NOP; 54 | } 55 | 56 | // IRQ handler 57 | void USART1_IRQHandler (void) 58 | { 59 | uint16_t SR=USART1->SR; 60 | uint8_t DR=USART1->DR; 61 | if(SR&USART_SR_RXNE) 62 | { 63 | if(uart_rx_handler!=NULL) 64 | uart_rx_handler(DR); 65 | // uart_send_byte_blocking(DR); 66 | 67 | } 68 | } 69 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /design/pcb/local.pretty/module_cc2500_PA_LNA.kicad_mod: -------------------------------------------------------------------------------- 1 | (module module_cc2500_PA_LNA (layer F.Cu) (tedit 58567028) 2 | (attr virtual) 3 | (fp_text reference P10 (at 11 -1.2) (layer F.SilkS) 4 | (effects (font (size 1.5 1.5) (thickness 0.15))) 5 | ) 6 | (fp_text value cc2500 (at 11 16 90) (layer F.Fab) 7 | (effects (font (size 1.5 1.5) (thickness 0.15))) 8 | ) 9 | (fp_line (start 0 0) (end 21.6 0) (layer F.Fab) (width 0.15)) 10 | (fp_line (start 21.6 0) (end 21.6 34.1) (layer F.Fab) (width 0.15)) 11 | (fp_line (start 0 0) (end 0 34.1) (layer F.Fab) (width 0.15)) 12 | (fp_line (start 0 34.1) (end 21.6 34.1) (layer F.Fab) (width 0.15)) 13 | (fp_line (start 20.1 -0.5) (end 22.1 -0.5) (layer F.SilkS) (width 0.15)) 14 | (fp_line (start 22.1 -0.5) (end 22.1 1.5) (layer F.SilkS) (width 0.15)) 15 | (fp_line (start 1.5 -0.5) (end -0.5 -0.5) (layer F.SilkS) (width 0.15)) 16 | (fp_line (start -0.5 -0.5) (end -0.5 1.5) (layer F.SilkS) (width 0.15)) 17 | (fp_line (start -0.5 32.6) (end -0.5 34.6) (layer F.SilkS) (width 0.15)) 18 | (fp_line (start -0.5 34.6) (end 0.5 34.6) (layer F.SilkS) (width 0.15)) 19 | (fp_line (start 22.1 32.6) (end 22.1 34.6) (layer F.SilkS) (width 0.15)) 20 | (fp_line (start 22.1 34.6) (end 21.1 34.6) (layer F.SilkS) (width 0.15)) 21 | (pad 12 smd oval (at 2.6 0) (size 1.5 3) (layers F.Cu F.Paste F.Mask)) 22 | (pad 11 smd oval (at 17.7 0) (size 1.5 3) (layers F.Cu F.Paste F.Mask)) 23 | (pad 1 smd oval (at 1.7 34.1) (size 1.5 3) (layers F.Cu F.Paste F.Mask)) 24 | (pad 2 smd oval (at 3.7 34.1) (size 1.5 3) (layers F.Cu F.Paste F.Mask)) 25 | (pad 3 smd oval (at 5.7 34.1) (size 1.5 3) (layers F.Cu F.Paste F.Mask)) 26 | (pad 4 smd oval (at 7.7 34.1) (size 1.5 3) (layers F.Cu F.Paste F.Mask)) 27 | (pad 5 smd oval (at 9.7 34.1) (size 1.5 3) (layers F.Cu F.Paste F.Mask)) 28 | (pad 6 smd oval (at 11.7 34.1) (size 1.5 3) (layers F.Cu F.Paste F.Mask)) 29 | (pad 7 smd oval (at 13.7 34.1) (size 1.5 3) (layers F.Cu F.Paste F.Mask)) 30 | (pad 8 smd oval (at 15.7 34.1) (size 1.5 3) (layers F.Cu F.Paste F.Mask)) 31 | (pad 9 smd oval (at 17.7 34.1) (size 1.5 3) (layers F.Cu F.Paste F.Mask)) 32 | (pad 10 smd oval (at 19.7 34.1) (size 1.5 3) (layers F.Cu F.Paste F.Mask)) 33 | ) 34 | -------------------------------------------------------------------------------- /design/pcb/local.pretty/module_cc2500_PA_LNA_small_pads.kicad_mod: -------------------------------------------------------------------------------- 1 | (module module_cc2500_PA_LNA_small_pads (layer F.Cu) (tedit 5872749A) 2 | (attr virtual) 3 | (fp_text reference P10 (at 11 -1.2) (layer F.SilkS) hide 4 | (effects (font (size 1 1) (thickness 0.2))) 5 | ) 6 | (fp_text value cc2500 (at 11 16 90) (layer F.Fab) 7 | (effects (font (size 0.5 0.5) (thickness 0.125))) 8 | ) 9 | (fp_line (start 22.1 34.6) (end 21.1 34.6) (layer F.SilkS) (width 0.15)) 10 | (fp_line (start 22.1 32.6) (end 22.1 34.6) (layer F.SilkS) (width 0.15)) 11 | (fp_line (start -0.5 34.6) (end 0.5 34.6) (layer F.SilkS) (width 0.15)) 12 | (fp_line (start -0.5 32.6) (end -0.5 34.6) (layer F.SilkS) (width 0.15)) 13 | (fp_line (start -0.5 -0.5) (end -0.5 1.5) (layer F.SilkS) (width 0.15)) 14 | (fp_line (start 1.5 -0.5) (end -0.5 -0.5) (layer F.SilkS) (width 0.15)) 15 | (fp_line (start 22.1 -0.5) (end 22.1 1.5) (layer F.SilkS) (width 0.15)) 16 | (fp_line (start 20.1 -0.5) (end 22.1 -0.5) (layer F.SilkS) (width 0.15)) 17 | (fp_line (start 0 34.1) (end 21.6 34.1) (layer F.Fab) (width 0.15)) 18 | (fp_line (start 0 0) (end 0 34.1) (layer F.Fab) (width 0.15)) 19 | (fp_line (start 21.6 0) (end 21.6 34.1) (layer F.Fab) (width 0.15)) 20 | (fp_line (start 0 0) (end 21.6 0) (layer F.Fab) (width 0.15)) 21 | (pad 10 smd oval (at 19.7 34.1) (size 1 2) (layers F.Cu F.Paste F.Mask)) 22 | (pad 9 smd oval (at 17.7 34.1) (size 1 2) (layers F.Cu F.Paste F.Mask)) 23 | (pad 8 smd oval (at 15.7 34.1) (size 1 2) (layers F.Cu F.Paste F.Mask)) 24 | (pad 7 smd oval (at 13.7 34.1) (size 1 2) (layers F.Cu F.Paste F.Mask)) 25 | (pad 6 smd oval (at 11.7 34.1) (size 1 2) (layers F.Cu F.Paste F.Mask)) 26 | (pad 5 smd oval (at 9.7 34.1) (size 1 2) (layers F.Cu F.Paste F.Mask)) 27 | (pad 4 smd oval (at 7.7 34.1) (size 1 2) (layers F.Cu F.Paste F.Mask)) 28 | (pad 3 smd oval (at 5.7 34.1) (size 1 2) (layers F.Cu F.Paste F.Mask)) 29 | (pad 2 smd oval (at 3.7 34.1) (size 1 2) (layers F.Cu F.Paste F.Mask)) 30 | (pad 1 smd oval (at 1.7 34.1) (size 1 2) (layers F.Cu F.Paste F.Mask)) 31 | (pad 11 smd oval (at 17.7 0) (size 1 2) (layers F.Cu F.Paste F.Mask)) 32 | (pad 12 smd oval (at 2.6 0) (size 1 2) (layers F.Cu F.Paste F.Mask)) 33 | ) 34 | -------------------------------------------------------------------------------- /code/generic/generic_circular_buffer.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Patrik Bachan 2 | // 3 | // GNU GENERAL PUBLIC LICENSE 4 | // Version 3, 29 June 2007 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | #include 20 | #include "irq.h" 21 | 22 | #ifndef CB_TYPE 23 | #error "used generic circular buffer, without CB_TYPE being set :(" 24 | #endif 25 | 26 | #ifndef CB_SIZE 27 | #error "used generic circular buffer, without CB_SIZE being set :(" 28 | #endif 29 | 30 | #ifndef CB_NAME 31 | #error "used generic circular buffer, without CB_NAME being set :(" 32 | #endif 33 | 34 | #define CB_OK 0 35 | #define CB_ERROR_UNDERFLOW -1 36 | #define CB_ERROR_OVERFLOW -2 37 | 38 | //OMG! 39 | #define helper2(a,b) a##_##b 40 | #define helper(a,b) helper2(a,b) 41 | #define _CB(keyword) helper(CB_NAME,keyword) //Type Specific naming macro 42 | 43 | extern CB_TYPE _CB(buffer)[]; 44 | extern volatile CB_TYPE *volatile _CB(head); 45 | extern volatile CB_TYPE *volatile _CB(tail); 46 | extern volatile CB_TYPE *const _CB(start); 47 | extern volatile CB_TYPE *const _CB(end); 48 | extern volatile uint8_t _CB(usage); 49 | 50 | inline volatile CB_TYPE *volatile _CB(next)(volatile CB_TYPE *volatile cursor) 51 | { 52 | // #ifdef CB_ATOMIC 53 | // ATOMIC_START(); 54 | // #endif 55 | if(cursor == _CB(end)-1) 56 | return _CB(start); 57 | else 58 | return cursor+1; 59 | // #ifdef CB_ATOMIC 60 | // ATOMIC_END_RESTORE(); 61 | // #endif 62 | } 63 | 64 | int8_t _CB(add)(CB_TYPE data); 65 | int8_t _CB(get)(CB_TYPE *data); 66 | int8_t _CB(peek)(CB_TYPE *data); 67 | int8_t _CB(skip)(void); 68 | void _CB(flush)(void); -------------------------------------------------------------------------------- /code/timers.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Patrik Bachan 2 | // 3 | // GNU GENERAL PUBLIC LICENSE 4 | // Version 3, 29 June 2007 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | #ifndef _TIMERS_LIB 20 | #define _TIMERS_LIB 21 | #include "config.h" 22 | #include "misc.h" 23 | #include 24 | 25 | #define SWDT_1ms (1000/SWDT_RESOLUTION) 26 | 27 | void swdt_init(void); 28 | void swdt_restart(uint16_t timeout); 29 | void swdt_set_callback(void (*callback)(void)); 30 | uint16_t swdt_stop(void); 31 | 32 | inline uint16_t swdt_get(void) 33 | { 34 | return TIM1->CNT; 35 | } 36 | 37 | #ifndef SWDT_F_IN 38 | #error "input frequency SWDT_F_IN not defined" 39 | #endif 40 | 41 | #ifndef SWDT_RESOLUTION 42 | #error SWDT_RESOLUTION not defined, (1~1000us) 43 | #endif 44 | 45 | #if SWDT_RESOLUTION >1000 || SWDT_RESOLUTION<1 46 | #error SWDT_RESOLUTION out of range (1~1000us) 47 | #endif 48 | 49 | #define PPM_TRIG_TMR TIM4 50 | #define PPM_A_TMR TIM2 51 | #define PPM_B_TMR TIM3 52 | 53 | #define PPM_TIMER_MAX 65000U//with this value in CCxR we get minimal length pulse 54 | #define PPM_TIMER_MIN 1//on 1 we get maximal length, 0 does not generate pulses at all, loot into DSH, OPM mode 55 | 56 | #define PPM_CLAMP_MIN 900 57 | #define PPM_CLAMP_MAX 2600 58 | 59 | #define PPM_TIME_TO_TICKS(T) 60 | #define PPM_CH_A_PRESCALER (PPM_CH_A_F_IN/(T_us/PPM_PULSE_ABS_MAX_us *PPM_TIMER_MAX) + 1)//+1 to be sure to be able to achieve PPM_PULSE_ABS_MAX long pulse 61 | 62 | #define PPM_CH_A_TIME_TO_TICKS(T) (PPM_TIMER_MAX-T*(PPM_CH_A_F_IN/(PPM_CH_A_PRESCALER*T_us))) 63 | 64 | #define PPM_OUTPUTS 8 65 | 66 | void ppm_init(void); 67 | void ppm_set_ticks(uint16_t ref1000, uint16_t ref2000, uint16_t *channels); 68 | 69 | #endif -------------------------------------------------------------------------------- /code/flash.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Patrik Bachan 2 | // 3 | // GNU GENERAL PUBLIC LICENSE 4 | // Version 3, 29 June 2007 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | #include "flash.h" 20 | #include "stm32f103xb.h" 21 | #include "misc.h" 22 | #include "uart.h" 23 | 24 | void flash_unlock(void) 25 | { 26 | if(bit_get(FLASH->CR, FLASH_CR_LOCK)!=0) 27 | if(bit_get(FLASH->CR, FLASH_CR_LOCK)!=0) 28 | { 29 | FLASH->KEYR = FLASH_KEY1; 30 | FLASH->KEYR = FLASH_KEY2; 31 | } 32 | } 33 | 34 | void flash_page_erase(uint16_t *destination) 35 | { 36 | flash_unlock(); 37 | while(bit_get(FLASH->SR, FLASH_SR_BSY)!=0)//wait until not BUSY 38 | NOP; 39 | 40 | bit_set(FLASH->CR, FLASH_CR_PER);//we want page erase 41 | FLASH->AR=(uint32_t)destination;//of page containing this address 42 | bit_set(FLASH->CR, FLASH_CR_STRT);//start erasing 43 | while(bit_get(FLASH->SR, FLASH_SR_BSY)!=0)//wait until not BUSY 44 | NOP; 45 | bit_clr(FLASH->CR, FLASH_CR_PER);//we deselect operation 46 | // uart_send_string_blocking("FLASH erase finished!\n"); 47 | } 48 | 49 | void flash_write(uint16_t *destination, uint16_t data) 50 | { 51 | flash_unlock(); 52 | 53 | while(bit_get(FLASH->SR, FLASH_SR_BSY)!=0)//wait until not BUSY 54 | NOP; 55 | 56 | bit_set(FLASH->SR, FLASH_SR_WRPRTERR | FLASH_SR_PGERR );//clear flags 57 | 58 | 59 | bit_set(FLASH->CR, FLASH_CR_PG);//programming mode 60 | 61 | *destination=data; 62 | while(bit_get(FLASH->SR, FLASH_SR_BSY)!=0)//wait until not BUSY 63 | NOP; 64 | 65 | if(bit_get(FLASH->SR, FLASH_SR_EOP)==0) 66 | { 67 | uart_send_string_blocking("FLASH write error!\n"); 68 | } 69 | 70 | 71 | if(*destination != data) 72 | { 73 | uart_send_string_blocking("FLASH witten data MATCH!\n"); 74 | } 75 | bit_clr(FLASH->CR, FLASH_CR_PG);//leave programming mode 76 | } -------------------------------------------------------------------------------- /code/spi.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Patrik Bachan 2 | // 3 | // GNU GENERAL PUBLIC LICENSE 4 | // Version 3, 29 June 2007 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | #include "spi.h" 20 | #include "misc.h" 21 | #include "stm32f103xb.h" 22 | #include "config.h" 23 | 24 | #include "uart.h" 25 | 26 | int8_t spi_selected_slave=-1; 27 | int8_t spi_start(uint8_t slave_id) 28 | { 29 | SPI_SLAVE_LIST[slave_id].PORT->BSRR = BIT(SPI_SLAVE_LIST[slave_id].pin)<<16; 30 | spi_selected_slave=slave_id; 31 | return 0; 32 | } 33 | 34 | int8_t spi_end(void) 35 | { 36 | if(spi_selected_slave<0) 37 | return -1; 38 | 39 | SPI_SLAVE_LIST[spi_selected_slave].PORT->BSRR = BIT(SPI_SLAVE_LIST[spi_selected_slave].pin); 40 | return 0; 41 | } 42 | 43 | void spi_init(uint8_t prescaler) 44 | { 45 | bit_set(RCC->APB2ENR, RCC_APB2ENR_SPI1EN); 46 | SPI1->CR1 = SPI_CR1_SSM | SPI_CR1_SSI | (prescaler&0x07)<SR,SPI_SR_TXE)) 52 | NOP; 53 | SPI1->DR;//clear 54 | 55 | for(uint8_t i=0; iDR=data[i]; 59 | else 60 | SPI1->DR=0; 61 | 62 | while(!bit_get(SPI1->SR,SPI_SR_TXE)) 63 | NOP; 64 | 65 | while(!bit_get(SPI1->SR,SPI_SR_RXNE)) 66 | NOP; 67 | 68 | if(operation&SPI_R) 69 | { 70 | data[i]=SPI1->DR; 71 | } 72 | else 73 | { 74 | SPI1->DR;//read but do not use 75 | } 76 | } 77 | 78 | //TODO: really necessary? 79 | while(bit_get(SPI1->SR, SPI_SR_BSY)); 80 | NOP; 81 | 82 | if(bit_get(SPI1->SR, SPI_SR_OVR | SPI_SR_MODF | SPI_SR_UDR)!=0) 83 | { 84 | uart_send_string_blocking("SPIERR:"); 85 | uart_send_string_blocking(itoa(SPI1->SR,4)); 86 | uart_send_byte_blocking('\n'); 87 | } 88 | } 89 | 90 | //interrupt handler 91 | -------------------------------------------------------------------------------- /design/pcb/xlyRX.pro: -------------------------------------------------------------------------------- 1 | update=Wed 15 Feb 2017 04:20:25 PM CET 2 | version=1 3 | last_client=kicad 4 | [pcbnew] 5 | version=1 6 | LastNetListRead= 7 | UseCmpFile=1 8 | PadDrill=0.600000000000 9 | PadDrillOvalY=0.600000000000 10 | PadSizeH=1.500000000000 11 | PadSizeV=1.500000000000 12 | PcbTextSizeV=1.500000000000 13 | PcbTextSizeH=1.500000000000 14 | PcbTextThickness=0.300000000000 15 | ModuleTextSizeV=1.000000000000 16 | ModuleTextSizeH=1.000000000000 17 | ModuleTextSizeThickness=0.150000000000 18 | SolderMaskClearance=0.000000000000 19 | SolderMaskMinWidth=0.000000000000 20 | DrawSegmentWidth=0.200000000000 21 | BoardOutlineThickness=0.100000000000 22 | ModuleOutlineThickness=0.150000000000 23 | [cvpcb] 24 | version=1 25 | NetIExt=net 26 | [general] 27 | version=1 28 | [eeschema] 29 | version=1 30 | LibDir=/home/diggit/dev/kicad-library/library 31 | [eeschema/libraries] 32 | LibName1=xilinx 33 | LibName2=video 34 | LibName3=valves 35 | LibName4=triac_thyristor 36 | LibName5=transistors 37 | LibName6=transf 38 | LibName7=texas 39 | LibName8=switches 40 | LibName9=supertex 41 | LibName10=stm8 42 | LibName11=stm32 43 | LibName12=silabs 44 | LibName13=sensors 45 | LibName14=rfcom 46 | LibName15=relays 47 | LibName16=regul 48 | LibName17=references 49 | LibName18=powerint 50 | LibName19=power 51 | LibName20=philips 52 | LibName21=opto 53 | LibName22=onsemi 54 | LibName23=nxp_armmcu 55 | LibName24=nxp 56 | LibName25=nordicsemi 57 | LibName26=msp430 58 | LibName27=motors 59 | LibName28=motorola 60 | LibName29=motor_drivers 61 | LibName30=microcontrollers 62 | LibName31=microchip_pic32mcu 63 | LibName32=microchip_pic18mcu 64 | LibName33=microchip_pic16mcu 65 | LibName34=microchip_pic12mcu 66 | LibName35=microchip_pic10mcu 67 | LibName36=microchip_dspic33dsc 68 | LibName37=microchip 69 | LibName38=memory 70 | LibName39=mechanical 71 | LibName40=maxim 72 | LibName41=logo 73 | LibName42=linear 74 | LibName43=leds 75 | LibName44=ir 76 | LibName45=interface 77 | LibName46=intel 78 | LibName47=hc11 79 | LibName48=ftdi 80 | LibName49=dsp 81 | LibName50=display 82 | LibName51=diode 83 | LibName52=digital-audio 84 | LibName53=device 85 | LibName54=dc-dc 86 | LibName55=cypress 87 | LibName56=contrib 88 | LibName57=conn 89 | LibName58=bosch 90 | LibName59=bbd 91 | LibName60=battery_management 92 | LibName61=audio 93 | LibName62=atmel 94 | LibName63=analog_switches 95 | LibName64=analog_devices 96 | LibName65=allegro 97 | LibName66=adc-dac 98 | LibName67=actel 99 | LibName68=ac-dc 100 | LibName69=Zilog 101 | LibName70=Xicor 102 | LibName71=Worldsemi 103 | LibName72=Power_Management 104 | LibName73=Oscillators 105 | LibName74=Lattice 106 | LibName75=ESD_Protection 107 | LibName76=Altera 108 | LibName77=74xx 109 | LibName78=74xgxx 110 | LibName79=zetex 111 | LibName80=wiznet 112 | LibName81=ttl_ieee 113 | LibName82=siliconi 114 | LibName83=graphic 115 | LibName84=gennum 116 | LibName85=elec-unifil 117 | LibName86=cmos_ieee 118 | LibName87=cmos4000 119 | LibName88=brooktre 120 | -------------------------------------------------------------------------------- /code/generic/generic_circular_buffer.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Patrik Bachan 2 | // 3 | // GNU GENERAL PUBLIC LICENSE 4 | // Version 3, 29 June 2007 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | #include "generic_circular_buffer.h" 20 | #include 21 | 22 | CB_TYPE _CB(buffer)[(CB_SIZE)]; 23 | CB_TYPE volatile* volatile _CB(head)=_CB(buffer); 24 | CB_TYPE volatile* volatile _CB(tail)=_CB(buffer); 25 | CB_TYPE volatile *const _CB(start)=_CB(buffer); 26 | CB_TYPE volatile *const _CB(end)=_CB(buffer)+(CB_SIZE);//points after buffer, not usable mem 27 | uint8_t volatile _CB(usage)=0; 28 | 29 | 30 | int8_t _CB(add)(CB_TYPE data) 31 | { 32 | if(_CB(usage) == (CB_SIZE)) 33 | return CB_ERROR_OVERFLOW; 34 | #ifdef CB_ATOMIC 35 | ATOMIC_START(); 36 | #endif 37 | *_CB(tail)=data; 38 | _CB(tail)=_CB(next)(_CB(tail)); 39 | _CB(usage)++; 40 | #ifdef CB_ATOMIC 41 | ATOMIC_END_RESTORE(); 42 | #endif 43 | return CB_OK; 44 | } 45 | 46 | int8_t _CB(get)(CB_TYPE *data) 47 | { 48 | if(_CB(usage) == 0) 49 | return CB_ERROR_UNDERFLOW; 50 | 51 | #ifdef CB_ATOMIC 52 | ATOMIC_START(); 53 | #endif 54 | *data=*_CB(head); 55 | _CB(head)=_CB(next)(_CB(head)); 56 | _CB(usage)--; 57 | #ifdef CB_ATOMIC 58 | ATOMIC_END_RESTORE(); 59 | #endif 60 | return CB_OK; 61 | } 62 | 63 | int8_t _CB(peek)(CB_TYPE *data) 64 | { 65 | if(_CB(usage) == 0) 66 | return CB_ERROR_UNDERFLOW; 67 | 68 | #ifdef CB_ATOMIC 69 | ATOMIC_START(); 70 | #endif 71 | *data=*_CB(head); 72 | #ifdef CB_ATOMIC 73 | ATOMIC_END_RESTORE(); 74 | #endif 75 | return CB_OK; 76 | } 77 | 78 | int8_t _CB(skip)(void) 79 | { 80 | if(_CB(usage) == 0) 81 | return CB_ERROR_UNDERFLOW; 82 | 83 | #ifdef CB_ATOMIC 84 | ATOMIC_START(); 85 | #endif 86 | _CB(head)=_CB(next)(_CB(head)); 87 | _CB(usage)--; 88 | #ifdef CB_ATOMIC 89 | ATOMIC_END_RESTORE(); 90 | #endif 91 | return CB_OK; 92 | } 93 | 94 | 95 | void _CB(flush)(void) 96 | { 97 | #ifdef CB_ATOMIC 98 | ATOMIC_START(); 99 | #endif 100 | _CB(head)=_CB(start); 101 | _CB(tail)=_CB(end); 102 | _CB(usage)=0; 103 | #ifdef CB_ATOMIC 104 | ATOMIC_END_RESTORE(); 105 | #endif 106 | } 107 | 108 | //prevent affection of other CBs 109 | #ifdef CB_NAME 110 | #undef CB_NAME 111 | #endif 112 | 113 | #ifdef CB_SIZE 114 | #undef CB_SIZE 115 | #endif 116 | 117 | #ifdef CB_TYPE 118 | #undef CB_TYPE 119 | #endif 120 | 121 | #ifdef CB_ATOMIC 122 | #undef CB_ATOMIC 123 | #endif 124 | -------------------------------------------------------------------------------- /code/adc.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Patrik Bachan 2 | // 3 | // GNU GENERAL PUBLIC LICENSE 4 | // Version 3, 29 June 2007 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | #include "stm32f103xb.h" 20 | #include "adc.h" 21 | #include "misc.h" 22 | 23 | 24 | #define ADC_SEQ_SMPR 1 25 | 26 | void adc_init_single(void) 27 | { 28 | bit_set(RCC->APB2ENR, RCC_APB2ENR_ADC1EN); 29 | ADC1->CR1=0; 30 | ADC1->CR2=0; 31 | 32 | //discontinoous mode, num of discon. channels 33 | bit_set(ADC1->CR1, ADC_CR1_DISCEN | 0<CR2, ADC_CR2_TSVREFE | ADC_CR2_EXTTRIG | 7<SMPR1 = ADC_SEQ_SMPR <SMPR2 = ADC_SEQ_SMPR <SQR1 = 0U; 60 | ADC1->SQR2 = 0U; 61 | ADC1->SQR3 = 0U; 62 | 63 | // turn on ADC 64 | bit_set(ADC1->CR2, ADC_CR2_ADON); 65 | } 66 | 67 | void adc_calibrate(void) 68 | { 69 | 70 | // uart_send_string_blocking("ADC RSTCAL\n"); 71 | //initialize(reset) calibration regs 72 | bit_set(ADC1->CR2, ADC_CR2_RSTCAL); 73 | //wait for complete 74 | while (bit_get(ADC1->CR2, ADC_CR2_RSTCAL) != 0) 75 | NOP; 76 | 77 | // uart_send_string_blocking("ADC CAL\n"); 78 | //start calibration 79 | bit_set(ADC1->CR2, ADC_CR2_CAL); 80 | //wait for complete 81 | while (bit_get(ADC1->CR2, ADC_CR2_CAL) != 0) 82 | NOP; 83 | } 84 | 85 | #define ADC_AVG 100 86 | uint16_t adc_measure_single_blocking(uint8_t input) 87 | { 88 | bit_mod(ADC1->SQR1, ADC_SQR1_L_Msk, 0<SQR3, ADC_SQR3_SQ1_Msk, input); 90 | 91 | uint32_t buff=0; 92 | //start conversion 93 | // GPIOC->BSRR=GPIO_BSRR_BR13; 94 | for(uint8_t i=0; iCR2, ADC_CR2_SWSTART); 97 | //wait for End Of Conversion 98 | while(bit_get(ADC1->SR,ADC_SR_EOC)==0) 99 | NOP; 100 | buff+=ADC1->DR; 101 | // delay_ms(40); 102 | } 103 | // GPIOC->BSRR=GPIO_BSRR_BS13; 104 | 105 | return buff/ADC_AVG; 106 | } -------------------------------------------------------------------------------- /code/misc.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Patrik Bachan 2 | // 3 | // GNU GENERAL PUBLIC LICENSE 4 | // Version 3, 29 June 2007 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | #ifndef __MISC_LIB 20 | #define __MISC_LIB 21 | 22 | #include 23 | //for build time debug 24 | #define STR_HELPER(x) #x 25 | #define STR(x) STR_HELPER(x) 26 | 27 | #define uabs(x) ( ( (x) < 0) ? -(x) : (x) ) 28 | 29 | //global macros for bitwise manipulation 30 | #define bit_get(p,m) ((p) & (m)) 31 | #define bit_set(p,m) ((p) |= (m)) 32 | #define bit_clr(p,m) ((p) &= ~(m)) 33 | #define bit_flip(p,m) ((p) ^= (m)) 34 | #define bit_con(c,p,m) (c ? bit_set(p,m) : bit_clr(p,m)) //macro for conditional bit set/clr 35 | #define bit_mod(p,m,b) ((p) = ((p)&~(m))|(b) )//mask bits, then orr some 36 | #define BIT(x) (0x1U << (x)) 37 | 38 | //this is epic idea... http://stackoverflow.com/a/7919546 39 | #define FILL_BITS_FROM_LSB(bits) ((1<<(bits))-1) 40 | #define FILL_BITS_FROM_MSB(bits) (~((0x80>>((bits)-1))-1)) //meh, you get it? 41 | 42 | //simple NOP, belongs to empty loops etc. 43 | #define NOP __asm__("NOP"); 44 | 45 | #define array_length(A) sizeof(A)/sizeof(A[0]) 46 | 47 | #define NULL ((void *)0) 48 | 49 | #define BUFF_SIZE 32 50 | 51 | uint32_t reduce(uint32_t value, uint8_t decrease); 52 | char* stoa(const char *str); 53 | char* ctoa(char c); 54 | char* itoa_dec_fill(int32_t val,int min,char filler,int decimals); 55 | char* itoa_fill(int32_t val, int min, char filler); 56 | char* itoa(int32_t val, int min); 57 | char* itoa_dec(int32_t val,int min,int decimals); 58 | // int32_t atoi(char *start); 59 | void delay_us(uint16_t delay); 60 | void delay_ms(uint16_t delay); 61 | // uint8_t wait_timeout(volatile uint8_t *port, uint8_t mask, uint8_t timeout, uint8_t high); 62 | // uint8_t wait_timeout_simple(volatile uint8_t *port, uint8_t mask); 63 | int32_t linear_aproximation(int32_t x, int32_t x0, int32_t y0, int32_t x1, int32_t y1); 64 | 65 | inline uint16_t crop_ui16(uint16_t val, uint16_t min, uint16_t max) 66 | { 67 | if(valmax) 70 | return max; 71 | return val; 72 | } 73 | 74 | inline int16_t crop_i16(int16_t val, int16_t min, int16_t max) 75 | { 76 | if(valmax) 79 | return max; 80 | return val; 81 | } 82 | 83 | inline int32_t crop_i32(int32_t val, int32_t min, int32_t max) 84 | { 85 | if(valmax) 88 | return max; 89 | return val; 90 | } 91 | 92 | //for fun... 93 | union anything 94 | { 95 | uint8_t ui8; 96 | int8_t i8; 97 | uint16_t ui16; 98 | int16_t i16; 99 | uint32_t ui32; 100 | int32_t i32; 101 | 102 | uint8_t *ui8p; 103 | int8_t *i8p; 104 | uint16_t *ui16p; 105 | int16_t *i16p; 106 | uint32_t *ui32p; 107 | int32_t *i32p; 108 | void *voidp; 109 | 110 | struct 111 | { 112 | uint16_t a; 113 | uint16_t b; 114 | }u16_pair; 115 | }; 116 | 117 | struct fixed_point 118 | { 119 | int16_t number; 120 | uint8_t decimals; 121 | }; 122 | 123 | 124 | 125 | 126 | #endif 127 | -------------------------------------------------------------------------------- /code/systick.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Patrik Bachan 2 | // 3 | // GNU GENERAL PUBLIC LICENSE 4 | // Version 3, 29 June 2007 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | #include "systick.h" 20 | #include "irq.h" 21 | #include "hardware.h" 22 | #include "uart.h" 23 | #include "stm32f103xb.h" 24 | 25 | struct led_blink_type 26 | { 27 | volatile uint8_t LED; 28 | volatile uint8_t blinks; 29 | volatile uint16_t period; 30 | volatile uint16_t remains;//here is period counted down, period itself must stay untoucher for reloading 31 | volatile uint8_t state;//remember on/off state 32 | }; 33 | struct led_blink_type leds[HARDWARE_LED_COUNT]; 34 | uint8_t btn_timer; 35 | 36 | void (*volatile button_pressed_callback)(void)=NULL; 37 | void (*volatile button_held_callback)(void)=NULL; 38 | void (*volatile button_released_callback)(void)=NULL; 39 | 40 | 41 | void systick_init(void) 42 | { 43 | btn_timer=0; 44 | for(uint8_t l=0; lLOAD = SYSTICK_CALIBRATION; 48 | STK->CTRL = STK_CTRL_TICKINT | STK_CTRL_ENABLE; 49 | } 50 | 51 | 52 | int8_t systick_blink_set(uint8_t led, uint8_t blinks, uint16_t period) 53 | { 54 | if(led>=HARDWARE_LED_COUNT) 55 | return -1; 56 | 57 | leds[led].LED=led; 58 | if(blinks==0) 59 | leds[led].blinks=0;//0 means blink forever 60 | else 61 | leds[led].blinks=blinks+1;//1 is out stop value, we must add 1 to blink count 62 | leds[led].period=period; 63 | leds[led].remains=0; 64 | leds[led].state=0; 65 | return 0; 66 | } 67 | 68 | int8_t systick_blink_stop(uint8_t led) 69 | { 70 | if(led>=HARDWARE_LED_COUNT) 71 | return -1; 72 | 73 | leds[led].period=0; 74 | led_off(led); 75 | return 0; 76 | } 77 | 78 | void SysTick_Handler (void) 79 | { 80 | 81 | //button handling 82 | if(button_read()) 83 | { 84 | if(btn_timer==0) 85 | { 86 | button_state=PRESSED; 87 | if(button_pressed_callback!=NULL) 88 | button_pressed_callback(); 89 | } 90 | 91 | 92 | if(btn_timer0) 115 | { 116 | //end of on/off part of cycle 117 | if(leds[l].remains==0) 118 | { 119 | if(leds[l].state==0) 120 | { 121 | leds[l].state=1; 122 | led_on(l); 123 | } 124 | else 125 | { 126 | leds[l].state=0; 127 | led_off(l); 128 | 129 | //check if we are in blink counted mode (!=0) 130 | if(leds[l].blinks>1) 131 | leds[l].blinks--; 132 | if(leds[l].blinks==1)//it was last cycle 133 | leds[l].period=0;//disable 134 | } 135 | leds[l].remains=leds[l].period/2-1;//reload for next cycle 136 | } 137 | else 138 | leds[l].remains--;//remaining time of on/off cycle 139 | } 140 | } 141 | } 142 | 143 | -------------------------------------------------------------------------------- /code/main.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Patrik Bachan 2 | // 3 | // GNU GENERAL PUBLIC LICENSE 4 | // Version 3, 29 June 2007 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | #include "stm32f103xb.h" 20 | #include "misc.h" 21 | #include "uart.h" 22 | #include "spi.h" 23 | #include "cc2500.h" 24 | #include "protocol.h" 25 | #include "irq.h" 26 | #include "timers.h" 27 | #include "flash.h" 28 | #include "hardware.h" 29 | #include "adc.h" 30 | #include "systick.h" 31 | 32 | #include 33 | 34 | 35 | void system_clock_init(void) 36 | { 37 | bit_set(RCC->CSR, RCC_CSR_LSION);//enable LSI for IWDG 38 | bit_set(FLASH->ACR, 1<CR, RCC_CR_HSEON | RCC_CR_HSEBYP);//off ext OSC, off ext OSC bypass 41 | bit_set(RCC->CR, RCC_CR_HSEON);//reenable ext OSC 42 | while(bit_get(RCC->CR, RCC_CR_HSERDY)==0)//wait for OSC to settle 43 | NOP; 44 | 45 | RCC->CFGR = RCC_CFGR_PLLSRC | RCC_CFGR_PLLMULL9 | RCC_CFGR_PPRE1_DIV2 | RCC_CFGR_ADCPRE_DIV8; 46 | bit_set(RCC->CR, RCC_CR_PLLON);//enable PLL 47 | while(bit_get(RCC->CR, RCC_CR_PLLRDY)==0)//wat for PLL to stabilize 48 | NOP; 49 | // led_flash(0); 50 | bit_mod(RCC->CFGR, RCC_CFGR_SW_Msk, RCC_CFGR_SW_PLL);//set system clock soutce to PLL 51 | //bit_clr(RCC->CR, RCC_CR_HSION);//off HSI 52 | 53 | } 54 | 55 | void draw_bar(uint8_t length, uint8_t filled, uint8_t ch) 56 | { 57 | uart_send_byte_blocking('['); 58 | uint8_t cursor; 59 | for(cursor=0; cursorBSRR=GPIO_BSRR_BS12;//charge capacitor on BL pin 73 | delay_ms(10); 74 | 75 | //reset using IDWG, I was not successful using system reset 76 | IWDG->KR=0xCCCCU;//start IWDG 77 | IWDG->KR=0x5555U;//enable access to prescaler and preload regs. 78 | IWDG->RLR=1; 79 | IWDG->PR=0; 80 | while(IWDG->SR!=0) 81 | NOP; 82 | IWDG->KR=0xAAAAU;//reload IWDG 83 | 84 | while(1) 85 | NOP; 86 | } 87 | 88 | } 89 | 90 | 91 | uint8_t fifo[64]; 92 | 93 | int main(void) 94 | { 95 | system_clock_init(); 96 | gpio_init(); 97 | swdt_init(); 98 | adc_init_single(); 99 | adc_calibrate(); 100 | 101 | systick_init(); 102 | 103 | // systick_blink_set(HARDWARE_LED_2, 0, SYSTICK_1s*0.1); 104 | 105 | 106 | irq_enable(); 107 | irq_NVIC_ISE(EXTI9_5_IRQn); 108 | 109 | led_on(HARDWARE_LED_2); 110 | 111 | uart_init(NULL); 112 | uart_rx_handler_set(uart_handler); 113 | // uart_send_string_blocking("\x1B[1J\x1B[;H"); 114 | uart_send_string_blocking("\nxlyRX starting...\n"); 115 | uart_send_string_blocking("Build: "); 116 | #ifdef BUILD 117 | uart_send_string_blocking(itoa(BUILD,3)); 118 | uart_send_string_blocking(" @ "); 119 | #endif 120 | uart_send_string_blocking(__DATE__); 121 | uart_send_byte_blocking(' '); 122 | uart_send_string_blocking(__TIME__); 123 | uart_send_byte_blocking('\n'); 124 | 125 | spi_init(3); 126 | ppm_init(); 127 | protocol_frsky_start(button_read()); 128 | 129 | 130 | // led1_flash(100); 131 | 132 | while(1) 133 | { 134 | NOP; 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /code/Makefile: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2017 Patrik Bachan 2 | # 3 | # GNU GENERAL PUBLIC LICENSE 4 | # Version 3, 29 June 2007 5 | # 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | 19 | TOOLCHAIN = arm-none-eabi 20 | export CC = $(TOOLCHAIN)-gcc 21 | LD = $(CC) 22 | OBJCOPY = $(TOOLCHAIN)-objcopy 23 | SIZE = $(TOOLCHAIN)-size 24 | OPTIMIZE = 2 25 | LSCRIPT = stm32f103.ld 26 | JOBS = 9 27 | BLdev = /dev/ttyUSB0 28 | 29 | SIZE_HISTORY = size.log 30 | BUILD_NUM = $(shell wc -l $(SIZE_HISTORY)|cut -d " " -f1) 31 | 32 | export CFLAGS = -D'BUILD=$(BUILD_NUM)' -c -Wunused -Wall -Wstrict-prototypes -Wundef -Werror -pedantic -g -O$(OPTIMIZE) -I./ -mcpu=cortex-m3 -mthumb -funsigned-char -funsigned-bitfields -fpack-struct -fdata-sections -ffunction-sections -fdiagnostics-color=always -std=gnu99 33 | # -mcall-prologues 34 | LDFLAGS = -mcpu=cortex-m3 -mthumb -O$(OPTIMIZE) -nostartfiles -fdiagnostics-color=always -Wl,--gc-sections -T$(LSCRIPT) 35 | TARGET = main 36 | 37 | 38 | export OBJECTS = $(patsubst %.c, %.o, $(wildcard *.c)) 39 | 40 | .NOTPARALLEL: 41 | 42 | all: $(TARGET).hex 43 | 44 | $(TARGET): clean compile_objects 45 | @echo "---------------------LINK-------------------------" 46 | @echo "BUILD $(BUILD_NUM)" 47 | $(LD) -o $@.elf $(OBJECTS) $(LDFLAGS) 48 | @$(SIZE) -B -d $(TARGET).elf | tail -n 1 >> $(SIZE_HISTORY) 49 | 50 | .PHONY: compile_objects 51 | compile_objects: 52 | @echo "--------------------COMPILE-----------------------" 53 | @$(MAKE) -j $(JOBS) -f Makefile.compile 54 | 55 | 56 | %.hex: $(TARGET) size 57 | @echo "---------------------HEX--------------------------" 58 | $(OBJCOPY) -Oihex $<.elf $@ 59 | 60 | .PHONY: clean 61 | clean: 62 | rm -rf *.o $(TARGET).elf $(TARGET).hex 63 | 64 | .PHONY: size 65 | size: $(TARGET) 66 | @echo "---------------------SIZE-------------------------" 67 | @$(SIZE) -B -d $(TARGET).elf 68 | 69 | .PHONY: burn 70 | burn: $(TARGET).hex 71 | @echo "---------------------BURN-------------------------" 72 | openocd -f stm32f1xx_ftdi_swd.cfg -c "init; reset halt; flash write_image erase $<; reset run; ftdi_set_signal nSRST z; exit" 73 | 74 | .PHONY: reset 75 | reset: 76 | openocd -f stm32f1xx_ftdi_swd.cfg -c "init; reset run; ftdi_set_signal nSRST z; exit" 77 | 78 | .PHONY: debug 79 | debug: $(TARGET).hex 80 | openocd -f stm32f1xx_ftdi_swd.cfg -c "init; reset halt; flash write_image erase $<"& 81 | arm-none-eabi-gdb main.elf -ex "target extended-remote localhost:3333" -ex "monitor reset halt" 82 | echo "ftdi_set_signal nSRST z; exit" | nc localhost 4444 83 | 84 | 85 | .PHONY: peek 86 | peek: $(TARGET).hex 87 | openocd -f stm32f1xx_ftdi_swd.cfg -c "init"& 88 | arm-none-eabi-gdb main.elf -ex "target extended-remote localhost:3333" 89 | echo "ftdi_set_signal nSRST z; exit" | nc localhost 4444 90 | 91 | .PHONY: BLburn 92 | BLburn: $(TARGET).hex softreset 93 | @echo "------------------BURN-using-BL-------------------" 94 | $(eval FLASH_OCCUPIED = $(shell $(SIZE) -A $< |grep -i total|cut -c 6-)) @#get flash usage 95 | $(eval PAGES_OCCUPIED = $(shell echo $(FLASH_OCCUPIED)/1024+2 |bc)) @#calculate how many pages are used (+ add some margin) 96 | @echo bytes: $(FLASH_OCCUPIED), pages: $(PAGES_OCCUPIED) 97 | @echo "FLASHING..." 98 | @#erase only necessary amount of flash pages 99 | stm32flash -m 8e1 -b 57600 -e $(PAGES_OCCUPIED) -v -w $< $(BLdev) 100 | @#separate reset command, if previous flashing fails, it leaves device in BL mode, so we can investigate problem afterwards 101 | stm32flash -m 8e1 -b 57600 -c -R $(BLdev) 102 | 103 | .PHONY: softreset 104 | softreset: 105 | @echo "Resetting..." 106 | @stty -F $(BLdev) 230400 107 | @echo -n "B" > $(BLdev) 108 | @sleep 0.2 109 | -------------------------------------------------------------------------------- /code/protocol.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Patrik Bachan 2 | // 3 | // GNU GENERAL PUBLIC LICENSE 4 | // Version 3, 29 June 2007 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | #ifndef _PROTOCOL 20 | #define _PROTOCOL 21 | 22 | #include 23 | 24 | //at least for my TX... 25 | #define FRSKY_CHANNEL_COUNT 47 26 | 27 | //TX->RX BIND packets 28 | #define FRSKY_D_BIND_INX_LENGTH 0 29 | #define FRSKY_D_BIND_INX_ADDR_H 1 30 | #define FRSKY_D_BIND_INX_ADDR_L 2 31 | #define FRSKY_D_BIND_INX_TX_ADDR_H 3 32 | #define FRSKY_D_BIND_INX_TX_ADDR_L 4 33 | #define FRSKY_D_BIND_INX_HTI 5 34 | #define FRSKY_D_BIND_INX_HOP1 6 35 | #define FRSKY_D_BIND_INX_HOP2 7 36 | #define FRSKY_D_BIND_INX_HOP3 8 37 | #define FRSKY_D_BIND_INX_HOP4 9 38 | #define FRSKY_D_BIND_INX_HOP5 10 39 | //unknown/empty 7 bytes 40 | 41 | #define FRSKY_D_BIND_CHANNEL 0 42 | #define FRSKY_D_BIND_ADDRESS 3 43 | 44 | 45 | //RSSI and PQI are not in PKT length (added by RX cc2500) 46 | #define FRSKY_PKT_INX_RSSI(LENGTH) (LENGTH+1) 47 | #define FRSKY_PKT_INX_PQI(LENGTH) (LENGTH+2) 48 | 49 | 50 | //packet TX->RX 51 | #define FRSKY_D_RX_LENGTH 17 52 | #define FRSKY_D_RX_TOTAL_LENGTH (FRSKY_D_RX_LENGTH+1+2)//+ 1 (LENGTH field) +2 RSSI and PQI 53 | #define FRSKY_D_RX_IDX_LENGTH 0 54 | #define FRSKY_D_RX_IDX_TX_ADDR_H 1 55 | #define FRSKY_D_RX_IDX_TX_ADDR_L 2 56 | #define FRSKY_D_RX_IDX_PKT_ID 3 57 | #define FRSKY_D_RX_IDX_UNKNOWN_1 4 58 | #define FRSKY_D_RX_IDX_UNKNOWN_2 5 59 | //ppm data 60 | #define FRSKY_D_RX_IDX_CH1_LSB 6 61 | #define FRSKY_D_RX_IDX_CH2_LSB 7 62 | #define FRSKY_D_RX_IDX_CH3_LSB 8 63 | #define FRSKY_D_RX_IDX_CH4_LSB 9 64 | #define FRSKY_D_RX_IDX_CH12_MSB 10 65 | #define FRSKY_D_RX_IDX_CH34_MSB 11 66 | #define FRSKY_D_RX_IDX_CH5_LSB 12 67 | #define FRSKY_D_RX_IDX_CH6_LSB 13 68 | #define FRSKY_D_RX_IDX_CH7_LSB 14 69 | #define FRSKY_D_RX_IDX_CH8_LSB 15 70 | #define FRSKY_D_RX_IDX_CH56_MSB 16 71 | #define FRSKY_D_RX_IDX_CH78_MSB 17 72 | 73 | //packet RX->TX 74 | #define FRSKY_D_TX_LENGTH 17 75 | #define FRSKY_D_TX_IDX_LENGTH 0 76 | #define FRSKY_D_TX_IDX_TX_ADDR_H 1 77 | #define FRSKY_D_TX_IDX_TX_ADDR_L 2 78 | #define FRSKY_D_TX_IDX_A1 3 79 | #define FRSKY_D_TX_IDX_A2 4 80 | #define FRSKY_D_TX_IDX_RX_RSSI 5 81 | //rest of the packet are telemetry data 82 | 83 | //delay between Rxed packet a Txing start of telemetry packet 84 | #define FRSKY_D_TX_DELAY (1.5*SWDT_1ms) //ms 85 | 86 | //TODO: implement external (UART) telemetry https://www.rcgroups.com/forums/showthread.php?2547257-FrSky-telemetry-hub-protocol-(on-air) 87 | 88 | //to easily get higher and lower nibble from byte 89 | #define FRSKY_EXTRACT_LOWER(A) (A&0x0F) 90 | #define FRSKY_EXTRACT_HIGHER(A) ((A>>4)&0x0F) 91 | 92 | //frsky channel data -> pulse length translation for linear aproximation 93 | #define FRSKY_2ms 3000 94 | #define FRSKY_1ms 1500 95 | 96 | #define FRSKY_PACKETS_LOST_RESYNC_THRESHOLD 10 //number of consecutive packets lost to wait for total resync 97 | #define FRSKY_PACKET_TIMEOUT (10*SWDT_1ms) //ms 98 | #define FRSKY_CYCLE_TIMEOUT (480*SWDT_1ms) //ms 99 | 100 | #define FRSKY_RSSI_MAX 230 //RSSI value above which is LNA turmed off 101 | #define FRSKY_RSSI_MIN 120 //RSSI value below which is LNA turned on 102 | 103 | //exposed functions 104 | void protocol_frsky_init(void);//initializes cc2500 for FrSky protocol (preambles, modulation, PKT length,...) 105 | void protocol_frsky_bind(void); 106 | void protocol_frsky_start(uint8_t force_bind); 107 | // void protocol_frsky_extract(uint8_t *packet,uint16_t *channel_buffer); 108 | 109 | #endif -------------------------------------------------------------------------------- /code/misc.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Patrik Bachan 2 | // 3 | // GNU GENERAL PUBLIC LICENSE 4 | // Version 3, 29 June 2007 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | #include "misc.h" 20 | #include "config.h" 21 | 22 | int32_t linear_aproximation(int32_t x, int32_t x0, int32_t y0, int32_t x1, int32_t y1) 23 | { 24 | if(x1==x0)//prevent division by 0 25 | return 0; 26 | 27 | return (x-x0)*(y1-y0)/(x1-x0) + y0; 28 | } 29 | 30 | // uint8_t wait_timeout(volatile uint8_t *port, uint8_t mask, uint8_t timeout, uint8_t high) 31 | // { 32 | // uint8_t counter; 33 | // for(counter=0; 34 | // ((!(*port & mask) && high ) || //high level stop 35 | // ((*port & mask) && !high )) //low level stop 36 | // && counter!=timeout ;counter++) 37 | // 38 | // NOP; 39 | // if(counter==timeout) 40 | // return 1; 41 | // 42 | // else 43 | // return 0; 44 | // } 45 | // 46 | // uint8_t wait_timeout_simple(volatile uint8_t *port, uint8_t mask) 47 | // { 48 | // return wait_timeout(port,mask,255,1); 49 | // } 50 | 51 | uint32_t reduce(uint32_t value, uint8_t decrease) //correct rounding, not just cropping 52 | { 53 | uint16_t dec=1; 54 | for(;decrease>1;decrease--)//calculate divider 55 | dec*=10; 56 | 57 | if (value/dec%10 > 4)//round 58 | return value/(10*dec)+1; 59 | else 60 | return value/(10*dec); 61 | } 62 | 63 | char char_buffer[BUFF_SIZE] = {0}; 64 | 65 | 66 | char* stoa(const char *str) 67 | { 68 | uint8_t length; 69 | for(length=0;str[length]!='\0' && length30; --i) 122 | char_buffer[i] = filler; 123 | 124 | return &char_buffer[i+1]; 125 | } 126 | 127 | char* itoa_fill(int32_t val, int min, char filler) 128 | { 129 | return itoa_dec_fill(val,min,filler,0); 130 | } 131 | 132 | char* itoa(int32_t val, int min) 133 | { 134 | return itoa_dec_fill(val,min,' ',0); 135 | } 136 | 137 | char* itoa_dec(int32_t val,int min,int decimals)//coverts number to string with defined base and minimal digit, char fillers 138 | { 139 | return itoa_dec_fill(val,min,' ',decimals); 140 | } 141 | 142 | //untedsted 143 | // int32_t atoi(char *start) 144 | // { 145 | // int32_t num=0; 146 | // uint8_t negative=0; 147 | // switch(*start) 148 | // { 149 | // case '-': 150 | // negative=1; 151 | // case '+': 152 | // start++; 153 | // break; 154 | // } 155 | // while(*start>='0' && *start<='9') 156 | // { 157 | // num*=10; 158 | // num+=*start-'0'; 159 | // start++; 160 | // } 161 | // if(negative) 162 | // return -num; 163 | // else 164 | // return num; 165 | // } 166 | 167 | #if F_CPU != 72000000U 168 | #warning "delay_ms and delay_us calibrated for 72MHz" 169 | #endif 170 | void delay_us(uint16_t delay) 171 | { 172 | delay=(delay*8); 173 | while(delay--) {;NOP;NOP;NOP;} 174 | }//dont try to optimize, it's calibrated! (gcc -O2) 175 | 176 | void delay_ms(uint16_t delay) //calibrated using oscope 177 | { 178 | while(delay--) delay_us(1000); 179 | } -------------------------------------------------------------------------------- /code/hardware.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Patrik Bachan 2 | // 3 | // GNU GENERAL PUBLIC LICENSE 4 | // Version 3, 29 June 2007 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | #include "hardware.h" 20 | #include "misc.h" 21 | 22 | 23 | void gpio_init(void) 24 | { 25 | bit_set(RCC->APB2ENR, \ 26 | RCC_APB2ENR_IOPAEN |\ 27 | RCC_APB2ENR_IOPBEN |\ 28 | RCC_APB2ENR_IOPCEN |\ 29 | RCC_APB2ENR_AFIOEN);// enable clock to ports A,B,C, USART1, AFIO 30 | 31 | AFIO->MAPR = AFIO_MAPR_SPI1_REMAP | AFIO_MAPR_SWJ_CFG_JTAGDISABLE; 32 | 33 | GPIOA->CRL = \ 34 | //PA0 S0 (TIM2_CH1) 35 | GPIO_ALTERNATE <CRH = \ 52 | //PA8 GPIO1 (GPIO) 53 | GPIO_INPUT <ODR = \ 70 | //PA10 PUP 71 | GPIO_ODR_ODR10; 72 | 73 | GPIOB->CRL = \ 74 | //PB0 S7 (TIM3_CH3) 75 | GPIO_ALTERNATE <CRH = \ 92 | //PB8 GDO0 (GPIO) 93 | GPIO_INPUT <ODR = \ 110 | //PB6 HIGH 111 | GPIO_ODR_ODR6|\ 112 | //PB11 PUP 113 | GPIO_ODR_ODR11; 114 | 115 | //only pins 13,14,15 present 116 | GPIOC->CRH = \ 117 | //PC13 LED_1 (GPIO) 118 | GPIO_OUTPUT <ODR = \ 125 | //PC13 LED(OFF) 126 | GPIO_ODR_ODR13|\ 127 | //PC14 LED(OFF) 128 | GPIO_ODR_ODR14|\ 129 | //PC15 BTN PUP 130 | GPIO_ODR_ODR15; 131 | 132 | 133 | //enable EXTI inttterupt for GDOs 134 | AFIO->EXTICR[2]=AFIO_EXTICR3_EXTI8_PB | AFIO_EXTICR3_EXTI9_PB; 135 | } 136 | -------------------------------------------------------------------------------- /code/stm32f103.ld: -------------------------------------------------------------------------------- 1 | /* 2 | Linker script for STM32F10x_256K_64K 3 | 4 | modified from 5 | 6 | http://www.codesourcery.com/archives/arm-gnu/msg02972.html 7 | http://communities.mentor.com/community/cs/archives/arm-gnu/msg02972.html 8 | */ 9 | 10 | /* 11 | There will be a link error if there is not this amount of RAM free at the 12 | end. 13 | */ 14 | 15 | _Minimum_Stack_Size = 256; 16 | 17 | ENTRY(Reset_Handler) 18 | 19 | 20 | /* Memory Spaces Definitions */ 21 | 22 | MEMORY 23 | { 24 | RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 20K 25 | FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 64K 26 | } 27 | 28 | __ram_start__ = ORIGIN(RAM); 29 | __ram_size__ = LENGTH(RAM); 30 | __ram_end__ = __ram_start__ + __ram_size__; 31 | _estack = __ram_end__; 32 | /* highest address of the user mode stack */ 33 | 34 | 35 | 36 | PROVIDE ( _Stack_Limit = _estack - _Minimum_Stack_Size ); 37 | 38 | /* Sections Definitions */ 39 | 40 | SECTIONS 41 | { 42 | .text : 43 | { 44 | KEEP(*(.isr_vector)) /* Startup code */ 45 | *(.text) /* code */ 46 | *(.text.*) /* remaining code */ 47 | *(.rodata) /* read-only data (constants) */ 48 | *(.rodata.*) 49 | *(.glue_7) 50 | *(.glue_7t) 51 | *(.vfp11_veneer) 52 | *(.v4_bx) 53 | *(.ARM.extab* .gnu.linkonce.armextab.*) 54 | } >FLASH 55 | 56 | /* for exception handling/unwind - some Newlib functions (in 57 | common with C++ and STDC++) use this. */ 58 | .ARM.extab : 59 | { 60 | *(.ARM.extab* .gnu.linkonce.armextab.*) 61 | 62 | } > FLASH 63 | 64 | __exidx_start = .; 65 | .ARM.exidx : 66 | { 67 | *(.ARM.exidx* .gnu.linkonce.armexidx.*) 68 | } > FLASH 69 | __exidx_end = .; 70 | 71 | . = ALIGN(4); 72 | _etext = .; 73 | /* This is used by the startup in order to initialize the .data secion 74 | */ 75 | _sidata = _etext; 76 | 77 | /* This is the initialized data section 78 | The program executes knowing that the data is in the RAM 79 | but the loader puts the initial values in the FLASH (inidata). 80 | It is one task of the startup to copy the initial values from FLASH to 81 | RAM. */ 82 | .data : AT ( _sidata ) 83 | { 84 | . = ALIGN(4); 85 | /* This is used by the startup in order to initialize the .data 86 | secion */ 87 | _sdata = . ; 88 | 89 | *(.data) 90 | *(.data.*) 91 | 92 | . = ALIGN(4); 93 | /* This is used by the startup in order to initialize the .data 94 | secion */ 95 | _edata = . ; 96 | } >RAM 97 | 98 | 99 | /* This is the uninitialized data section */ 100 | .bss : 101 | { 102 | . = ALIGN(4); 103 | /* This is used by the startup in order to initialize the .bss 104 | secion */ 105 | _sbss = .; 106 | __bss_start__ = _sbss; 107 | *(.bss) 108 | *(.bss.*) 109 | *(COMMON) 110 | 111 | . = ALIGN(4); 112 | /* This is used by the startup in order to initialize the .bss 113 | secion */ 114 | _ebss = . ; 115 | __bss_end__ = _ebss; 116 | } >RAM 117 | 118 | PROVIDE ( end = _ebss ); 119 | PROVIDE ( _end = _ebss ); 120 | PROVIDE ( _exit = _ebss ); 121 | PROVIDE (_stackend = ORIGIN(RAM) + LENGTH(RAM) - _Minimum_Stack_Size); 122 | 123 | /* This is the user stack section 124 | This is just to check that there is enough RAM left for the User mode 125 | stack 126 | It should generate an error if it's full. 127 | */ 128 | ._usrstack : 129 | { 130 | . = ALIGN(4); 131 | _susrstack = . ; 132 | 133 | . = . + _Minimum_Stack_Size ; 134 | 135 | . = ALIGN(4); 136 | _eusrstack = . ; 137 | } >RAM 138 | 139 | 140 | 141 | /* after that it's only debugging information. */ 142 | 143 | /* remove the debugging information from the standard libraries */ 144 | /* 145 | DISCARD : 146 | { 147 | libc.a ( * ) 148 | libm.a ( * ) 149 | libgcc.a ( * ) 150 | } 151 | */ 152 | 153 | /* Stabs debugging sections. */ 154 | .stab 0 : { *(.stab) } 155 | .stabstr 0 : { *(.stabstr) } 156 | .stab.excl 0 : { *(.stab.excl) } 157 | .stab.exclstr 0 : { *(.stab.exclstr) } 158 | .stab.index 0 : { *(.stab.index) } 159 | .stab.indexstr 0 : { *(.stab.indexstr) } 160 | .comment 0 : { *(.comment) } 161 | /* DWARF debug sections. 162 | Symbols in the DWARF debugging sections are relative to the beginning 163 | of the section so we begin them at 0. */ 164 | /* DWARF 1 */ 165 | .debug 0 : { *(.debug) } 166 | .line 0 : { *(.line) } 167 | /* GNU DWARF 1 extensions */ 168 | .debug_srcinfo 0 : { *(.debug_srcinfo) } 169 | .debug_sfnames 0 : { *(.debug_sfnames) } 170 | /* DWARF 1.1 and DWARF 2 */ 171 | .debug_aranges 0 : { *(.debug_aranges) } 172 | .debug_pubnames 0 : { *(.debug_pubnames) } 173 | /* DWARF 2 */ 174 | .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) } 175 | .debug_abbrev 0 : { *(.debug_abbrev) } 176 | .debug_line 0 : { *(.debug_line) } 177 | .debug_frame 0 : { *(.debug_frame) } 178 | .debug_str 0 : { *(.debug_str) } 179 | .debug_loc 0 : { *(.debug_loc) } 180 | .debug_macinfo 0 : { *(.debug_macinfo) } 181 | /* SGI/MIPS DWARF 2 extensions */ 182 | .debug_weaknames 0 : { *(.debug_weaknames) } 183 | .debug_funcnames 0 : { *(.debug_funcnames) } 184 | .debug_typenames 0 : { *(.debug_typenames) } 185 | .debug_varnames 0 : { *(.debug_varnames) } 186 | } 187 | -------------------------------------------------------------------------------- /code/timers.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Patrik Bachan 2 | // 3 | // GNU GENERAL PUBLIC LICENSE 4 | // Version 3, 29 June 2007 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | #include "timers.h" 20 | #include "misc.h" 21 | #include "irq.h" 22 | #include "uart.h" 23 | 24 | void (*swdt_callback)(void)=NULL; 25 | 26 | void swdt_init(void) 27 | { 28 | bit_set(RCC->APB2ENR, RCC_APB2ENR_TIM1EN); 29 | TIM1->PSC = SWDT_F_IN/(1000000/SWDT_RESOLUTION) -1;//100us resolution; 30 | TIM1->CR1 = TIM_CR1_OPM; 31 | TIM1->DIER = TIM_DIER_CC1IE; 32 | TIM1->ARR = INT16_MAX; 33 | TIM1->EGR = TIM_EGR_UG; 34 | irq_NVIC_ISE(TIM1_CC_IRQn); 35 | } 36 | 37 | void swdt_restart(uint16_t timeout) 38 | { 39 | bit_clr(TIM1->CR1, TIM_CR1_CEN);//stop timer 40 | TIM1->CNT=0; 41 | TIM1->CCR1 = timeout; 42 | // TIM1->EGR = TIM_EGR_UG; 43 | if(swdt_callback==NULL) 44 | return; 45 | bit_set(TIM1->CR1, TIM_CR1_CEN); 46 | } 47 | 48 | void swdt_set_callback(void (*callback)(void)) 49 | { 50 | bit_clr(TIM1->CR1, TIM_CR1_CEN); 51 | swdt_callback=callback; 52 | } 53 | 54 | uint16_t swdt_stop(void) 55 | { 56 | bit_clr(TIM1->CR1, TIM_CR1_CEN); 57 | return TIM1->CNT; 58 | } 59 | 60 | void TIM1_CC_IRQHandler (void) 61 | { 62 | bit_clr(TIM1->CR1, TIM_CR1_CEN);//stop timer 63 | // TIM1->CNT=0; 64 | bit_clr(TIM1->SR, TIM_SR_CC1IF);//clear int. flag of CC1 65 | // uart_send_string_blocking("CCR1: "); 66 | // uart_send_string_blocking(itoa(TIM1->CCR1,5)); 67 | // uart_send_byte_blocking('\n'); 68 | 69 | if(swdt_callback!=NULL) 70 | swdt_callback(); 71 | 72 | 73 | } 74 | 75 | // void TIM4_IRQHandler (void) 76 | // { 77 | // bit_clr(TIM4->SR, TIM_SR_UIF);//clear flag 78 | // GPIOC->BSRR=GPIO_BSRR_BR14; 79 | // delay_ms(1); 80 | // GPIOC->BSRR=GPIO_BSRR_BS14; 81 | // } 82 | 83 | void ppm_config_channel(TIM_TypeDef *tim) 84 | { 85 | tim->PSC = PPM_CH_A_PRESCALER-1; 86 | tim->ARR = PPM_TIMER_MAX; 87 | tim->SMCR = 3<CR1 = TIM_CR1_OPM; 89 | 90 | tim->CCMR1 = 7<CCMR2 = 7<CCER = TIM_CCER_CC1E | TIM_CCER_CC2E | TIM_CCER_CC3E | TIM_CCER_CC4E; 93 | 94 | tim->CCR1 = 0; 95 | tim->CCR2 = 0; 96 | tim->CCR3 = 0; 97 | tim->CCR4 = 0; 98 | 99 | tim->EGR = TIM_EGR_UG; 100 | } 101 | 102 | void ppm_init(void) 103 | { 104 | 105 | bit_set(RCC->APB1ENR, RCC_APB1ENR_TIM4EN); 106 | bit_set(RCC->APB1ENR, RCC_APB1ENR_TIM2EN); 107 | bit_set(RCC->APB1ENR, RCC_APB1ENR_TIM3EN); 108 | // 109 | PPM_TRIG_TMR->ARR = (T_us/PPM_TRIG_RESOLUTION_us/PPM_TRIG_F_OUT); 110 | PPM_TRIG_TMR->PSC = PPM_TRIG_F_IN/(T_us/PPM_TRIG_RESOLUTION_us) -1; 111 | PPM_TRIG_TMR->CR2 = 2<EGR = TIM_EGR_UG; 113 | 114 | ppm_config_channel(PPM_A_TMR); 115 | ppm_config_channel(PPM_B_TMR); 116 | 117 | // bit_set(TIM2->CR1, TIM_CR1_CEN); 118 | bit_set(PPM_TRIG_TMR->CR1, TIM_CR1_CEN); 119 | 120 | } 121 | 122 | void ppm_set_ticks(uint16_t ref1000, uint16_t ref2000, uint16_t *channels) 123 | { 124 | volatile uint16_t *target; 125 | for(uint8_t ch=0; ch<8; ch++) 126 | { 127 | switch(ch) 128 | { 129 | case 0: target=&PPM_A_TMR->CCR1; break; 130 | case 1: target=&PPM_A_TMR->CCR2; break; 131 | case 2: target=&PPM_B_TMR->CCR1; break; 132 | case 3: target=&PPM_B_TMR->CCR2; break; 133 | case 4: target=&PPM_A_TMR->CCR3; break; 134 | case 5: target=&PPM_A_TMR->CCR4; break; 135 | case 6: target=&PPM_B_TMR->CCR3; break; 136 | case 7: target=&PPM_B_TMR->CCR4; break; 137 | } 138 | if(channels[ch]!=0) 139 | { 140 | *target = linear_aproximation(\ 141 | channels[ch],\ 142 | ref1000,\ 143 | PPM_CH_A_TIME_TO_TICKS(1000),\ 144 | ref2000,\ 145 | PPM_CH_A_TIME_TO_TICKS(2000)); 146 | // if(ch==4) 147 | // if(*target < 37500 || *target > 38500) 148 | // { 149 | // uart_send_string_blocking(itoa(*target,7)); 150 | // uart_send_byte_blocking('\n'); 151 | // } 152 | } 153 | else 154 | { 155 | *target = 0;//turn off output 156 | } 157 | } 158 | //CH1 159 | // PPM_A_TMR->CCR1=crop_i16(linear_aproximation(channels[0], ref1000, PPM_CH_A_TIME_TO_TICKS(1000), ref2000, PPM_CH_A_TIME_TO_TICKS(2000)), PPM_CLAMP_MIN, PPM_CLAMP_MAX); 160 | // 161 | // //CH2 162 | // PPM_A_TMR->CCR2=crop_i16(linear_aproximation(channels[1], ref1000, PPM_CH_A_TIME_TO_TICKS(1000), ref2000, PPM_CH_A_TIME_TO_TICKS(2000)), PPM_CLAMP_MIN, PPM_CLAMP_MAX); 163 | // 164 | // ///CH3 165 | // PPM_B_TMR->CCR1=crop_i16(linear_aproximation(channels[2], ref1000, PPM_CH_A_TIME_TO_TICKS(1000), ref2000, PPM_CH_A_TIME_TO_TICKS(2000)), PPM_CLAMP_MIN, PPM_CLAMP_MAX); 166 | // 167 | // //CH4 168 | // PPM_B_TMR->CCR2=crop_i16(linear_aproximation(channels[3], ref1000, PPM_CH_A_TIME_TO_TICKS(1000), ref2000, PPM_CH_A_TIME_TO_TICKS(2000)), PPM_CLAMP_MIN, PPM_CLAMP_MAX); 169 | // 170 | // //CH5 171 | // PPM_A_TMR->CCR3=crop_i16(linear_aproximation(channels[4], ref1000, PPM_CH_A_TIME_TO_TICKS(1000), ref2000, PPM_CH_A_TIME_TO_TICKS(2000)), PPM_CLAMP_MIN, PPM_CLAMP_MAX); 172 | // 173 | // //CH6 174 | // PPM_A_TMR->CCR4=crop_i16(linear_aproximation(channels[5], ref1000, PPM_CH_A_TIME_TO_TICKS(1000), ref2000, PPM_CH_A_TIME_TO_TICKS(2000)), PPM_CLAMP_MIN, PPM_CLAMP_MAX); 175 | // 176 | // //CH7 177 | // PPM_B_TMR->CCR3=crop_i16(linear_aproximation(channels[6], ref1000, PPM_CH_A_TIME_TO_TICKS(1000), ref2000, PPM_CH_A_TIME_TO_TICKS(2000)), PPM_CLAMP_MIN, PPM_CLAMP_MAX); 178 | // 179 | // //CH8 180 | // PPM_B_TMR->CCR4=crop_i16(linear_aproximation(channels[7], ref1000, PPM_CH_A_TIME_TO_TICKS(1000), ref2000, PPM_CH_A_TIME_TO_TICKS(2000)), PPM_CLAMP_MIN, PPM_CLAMP_MAX); 181 | } -------------------------------------------------------------------------------- /code/cc2500.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Patrik Bachan 2 | // 3 | // GNU GENERAL PUBLIC LICENSE 4 | // Version 3, 29 June 2007 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | #include "cc2500.h" 20 | #include "spi.h" 21 | #include "stm32f103xb.h" 22 | #include "uart.h" 23 | #include "timers.h" 24 | 25 | 26 | // spi_start(CC2500_SPI_SLAVE_ID); 27 | // spi_end(); 28 | 29 | volatile union cc2500_status cc2500_status; 30 | 31 | void cc2500_wait_for_wake(uint8_t data) 32 | { 33 | spi_start(CC2500_SPI_SLAVE_ID); 34 | //wait until MISO goes low 35 | while( bit_get(GPIOB->IDR,GPIO_IDR_IDR4)!=0) 36 | NOP; 37 | 38 | uint8_t buffer=data; 39 | spi_exchange(SPI_RW, 1, &buffer); 40 | cc2500_status.byte=buffer; 41 | } 42 | 43 | uint8_t cc2500_read_reg(uint8_t address) 44 | { 45 | // spi_start(CC2500_SPI_SLAVE_ID); 46 | cc2500_wait_for_wake(address|CC2500_ACCESS_READ); 47 | //data 48 | uint8_t buffer; 49 | spi_exchange(SPI_R, 1, &buffer); 50 | spi_end(); 51 | return buffer; 52 | } 53 | 54 | void cc2500_read_reg_burst(uint8_t address, uint8_t length, uint8_t *destination) 55 | { 56 | cc2500_wait_for_wake(address|CC2500_ACCESS_READ|CC2500_ACCESS_BURST); 57 | //data 58 | spi_exchange(SPI_R, length, destination); 59 | spi_end(); 60 | } 61 | 62 | void cc2500_write_reg(uint8_t address, uint8_t data) 63 | { 64 | cc2500_wait_for_wake(address|CC2500_ACCESS_WRITE); 65 | //data 66 | spi_exchange(SPI_W, 1, &data); 67 | spi_end(); 68 | } 69 | 70 | void cc2500_write_reg_burst(uint8_t address, uint8_t length, uint8_t *source) 71 | { 72 | cc2500_wait_for_wake(address|CC2500_ACCESS_WRITE|CC2500_ACCESS_BURST); 73 | //data 74 | spi_exchange(SPI_W, length, source); 75 | spi_end(); 76 | } 77 | 78 | void cc2500_strobe(uint8_t address) 79 | { 80 | cc2500_wait_for_wake(address|CC2500_ACCESS_WRITE); 81 | spi_end(); 82 | } 83 | 84 | void cc2500_write_fifo(uint8_t *data, uint8_t length) 85 | { 86 | // uart_send_string_blocking("CC:"); 87 | // uart_send_string_blocking(itoa(length,3)); 88 | // uart_send_byte_blocking('\n'); 89 | cc2500_wait_for_wake(CC2500_FIFO|CC2500_ACCESS_WRITE|CC2500_ACCESS_BURST); 90 | spi_exchange(SPI_W, length, data); 91 | spi_end(); 92 | } 93 | 94 | uint8_t cc2500_read_fifo(uint8_t *data) 95 | { 96 | uint8_t bytes=cc2500_read_reg(CC2500_RXBYTES); 97 | if(bytes==0) 98 | return 0; 99 | 100 | cc2500_wait_for_wake(CC2500_FIFO|CC2500_ACCESS_READ|CC2500_ACCESS_BURST); 101 | 102 | uint8_t length=0; 103 | for(; bytes>0; bytes--) 104 | { 105 | spi_exchange(SPI_R, 1, data); 106 | data++; 107 | length++; 108 | } 109 | spi_end(); 110 | return length; 111 | } 112 | 113 | void cc2500_ex_pa(uint8_t state) 114 | { 115 | if(state) 116 | GPIOB->BSRR = GPIO_BSRR_BS7; 117 | else 118 | GPIOB->BSRR = GPIO_BSRR_BR7; 119 | } 120 | 121 | void cc2500_ex_lna(uint8_t state) 122 | { 123 | if(state) 124 | GPIOA->BSRR = GPIO_BSRR_BS15; 125 | else 126 | GPIOA->BSRR = GPIO_BSRR_BR15; 127 | } 128 | 129 | void cc2500_mode_tx(void) 130 | { 131 | cc2500_ex_lna(0); 132 | cc2500_strobe(CC2500_SIDLE); 133 | cc2500_ex_pa(1); 134 | cc2500_strobe(CC2500_STX); 135 | } 136 | 137 | void cc2500_mode_rx(uint8_t LNA) 138 | { 139 | cc2500_ex_pa(0); 140 | cc2500_strobe(CC2500_SIDLE); 141 | cc2500_ex_lna(LNA); 142 | cc2500_strobe(CC2500_SRX); 143 | // delay_us(90);//time to turn on rx 144 | } 145 | 146 | void cc2500_set_channel(uint8_t channel) 147 | { 148 | cc2500_strobe(CC2500_SIDLE); 149 | cc2500_write_reg(CC2500_CHANNR, channel); 150 | } 151 | 152 | void (*cc2500_GDO0_callback)(void)=NULL; 153 | enum gdo_filter cc2500_GDO0_callback_filter; 154 | void (*cc2500_GDO2_callback)(void)=NULL; 155 | enum gdo_filter cc2500_GDO2_callback_filter; 156 | 157 | void cc2500_reset_callback(enum gdo gdo) 158 | { 159 | switch(gdo) 160 | { 161 | case GDO0: 162 | cc2500_GDO0_callback=NULL;//not necessary 163 | bit_clr(EXTI->IMR, EXTI_IMR_IM8); 164 | bit_clr(EXTI->PR, EXTI_PR_PR8); 165 | bit_clr(EXTI->FTSR, EXTI_FTSR_FT8); 166 | bit_clr(EXTI->RTSR, EXTI_RTSR_RT8); 167 | break; 168 | 169 | case GDO2: 170 | cc2500_GDO2_callback=NULL;//not necessary 171 | bit_clr(EXTI->IMR, EXTI_IMR_IM9);//disable interrupt 172 | bit_set(EXTI->PR, EXTI_PR_PR9);//clean pending requasts 173 | bit_clr(EXTI->RTSR, EXTI_FTSR_FT9);//diable rising adge if there was any 174 | bit_clr(EXTI->FTSR, EXTI_RTSR_RT9);//diable falling adge if there was any 175 | break; 176 | 177 | } 178 | } 179 | void cc2500_set_callback(enum gdo gdo, enum edge edge, void(*callback)(void), uint8_t filter) 180 | { 181 | // uart_send_string_blocking("setting callabck\n"); 182 | 183 | volatile uint32_t *edge_register; 184 | switch(edge) 185 | { 186 | case RISING: 187 | // uart_send_string_blocking("\trising\n"); 188 | edge_register = &EXTI->RTSR; 189 | break; 190 | 191 | case FALLING: 192 | // uart_send_string_blocking("\tfalling\n"); 193 | edge_register = &EXTI->FTSR; 194 | break; 195 | 196 | default: 197 | return; 198 | } 199 | 200 | switch(gdo) 201 | { 202 | case GDO0: 203 | // uart_send_string_blocking("\tGDO0\n"); 204 | cc2500_reset_callback(GDO0);//reset any previous state 205 | bit_set(*edge_register, EXTI_RTSR_TR8); 206 | cc2500_GDO0_callback=callback; 207 | cc2500_GDO0_callback_filter=filter; 208 | bit_set(EXTI->IMR, EXTI_IMR_IM8);//enable interrupt line 209 | break; 210 | 211 | case GDO2: 212 | // uart_send_string_blocking("\tGDO2\n"); 213 | cc2500_reset_callback(GDO2);//reset any previous state 214 | bit_set(*edge_register, EXTI_RTSR_TR9); 215 | cc2500_GDO2_callback=callback; 216 | cc2500_GDO2_callback_filter=filter; 217 | bit_set(EXTI->IMR, EXTI_IMR_IM9);//enable interrupt line 218 | break; 219 | } 220 | } 221 | 222 | 223 | void EXTI9_5_IRQHandler (void) 224 | { 225 | // uart_send_string_blocking("+"); 226 | 227 | // cc2500_strobe(CC2500_SNOP); 228 | // uart_send_string_blocking("S: "); 229 | // uart_send_string_blocking(itoa(cc2500_status.bits.STATE,3)); 230 | // uart_send_byte_blocking('\n'); 231 | 232 | uint8_t buffer; 233 | if(bit_get(EXTI->PR,EXTI_PR_PR8)) 234 | { 235 | bit_set(EXTI->PR,EXTI_PR_PR8); 236 | if(cc2500_GDO0_callback==NULL) 237 | return; 238 | 239 | switch(cc2500_GDO0_callback_filter) 240 | { 241 | case NOT_EMPTY: 242 | buffer=cc2500_read_reg(CC2500_RXBYTES); 243 | if(buffer==0)//no received bytes 244 | { 245 | // uart_send_string_blocking("_"); 246 | return; 247 | } 248 | 249 | case NONE: 250 | break; 251 | } 252 | cc2500_GDO0_callback(); 253 | } 254 | 255 | if(bit_get(EXTI->PR,EXTI_PR_PR9)) 256 | { 257 | bit_set(EXTI->PR,EXTI_PR_PR9); 258 | if(cc2500_GDO2_callback==NULL) 259 | return; 260 | 261 | switch(cc2500_GDO2_callback_filter) 262 | { 263 | case NOT_EMPTY: 264 | buffer=cc2500_read_reg(CC2500_RXBYTES); 265 | if(buffer==0)//no received bytes 266 | return; 267 | 268 | case NONE: 269 | break; 270 | } 271 | cc2500_GDO2_callback(); 272 | } 273 | 274 | } -------------------------------------------------------------------------------- /code/captured/bind: -------------------------------------------------------------------------------- 1 | HTI - Hop Table Index 2 | 3 | LEN|ADR ID|TX ID |HTI| h1| h2| h2| h4| h5| NUL|NUL|NUL|NUL|NUL|NUL| 4 | 5 | 17 3 1 168 237 0 0 145 55 200 110 0 0 0 0 0 0 34 60 195 6 | 17 3 1 168 237 5 20 165 75 221 130 0 0 0 0 0 0 34 59 204 7 | 17 3 1 168 237 10 40 185 95 5 150 0 0 0 0 0 0 34 59 201 8 | 17 3 1 168 237 15 60 205 115 25 170 0 0 0 0 0 0 34 60 201 9 | 17 3 1 168 237 20 80 225 135 45 190 0 0 0 0 0 0 34 60 200 10 | 17 3 1 168 237 25 100 10 155 65 210 0 0 0 0 0 0 34 59 200 11 | 17 3 1 168 237 30 120 30 175 85 230 0 0 0 0 0 0 34 59 197 12 | 17 3 1 168 237 35 140 50 195 105 15 0 0 0 0 0 0 34 59 199 13 | 17 3 1 168 237 40 160 70 215 125 35 0 0 0 0 0 0 34 60 200 14 | 17 3 1 168 237 45 180 91 34 0 0 0 0 0 0 0 0 34 60 206 15 | 16 | 17 3 1 168 237 0 0 145 55 200 110 0 0 0 0 0 0 34 59 191 17 | 17 3 1 168 237 5 20 165 75 221 130 0 0 0 0 0 0 34 59 202 18 | 17 3 1 168 237 10 40 185 95 5 150 0 0 0 0 0 0 34 59 202 19 | 17 3 1 168 237 15 60 205 115 25 170 0 0 0 0 0 0 34 59 199 20 | 17 3 1 168 237 20 80 225 135 45 190 0 0 0 0 0 0 34 59 202 21 | 17 3 1 168 237 25 100 10 155 65 210 0 0 0 0 0 0 34 59 200 22 | 17 3 1 168 237 30 120 30 175 85 230 0 0 0 0 0 0 34 60 196 23 | 17 3 1 168 237 35 140 50 195 105 15 0 0 0 0 0 0 34 60 200 24 | 17 3 1 168 237 40 160 70 215 125 35 0 0 0 0 0 0 34 60 199 25 | 17 3 1 168 237 45 180 91 34 0 0 0 0 0 0 0 0 34 60 208 26 | 27 | 17 3 1 168 237 0 0 145 55 200 110 0 0 0 0 0 0 34 60 194 28 | 17 3 1 168 237 5 20 165 75 221 130 0 0 0 0 0 0 34 60 203 29 | 17 3 1 168 237 10 40 185 95 5 150 0 0 0 0 0 0 34 59 202 30 | 17 3 1 168 237 15 60 205 115 25 170 0 0 0 0 0 0 34 60 200 31 | 17 3 1 168 237 20 80 225 135 45 190 0 0 0 0 0 0 34 60 203 32 | 17 3 1 168 237 25 100 10 155 65 210 0 0 0 0 0 0 34 60 203 33 | 17 3 1 168 237 30 120 30 175 85 230 0 0 0 0 0 0 34 60 195 34 | 17 3 1 168 237 35 140 50 195 105 15 0 0 0 0 0 0 34 60 199 35 | 17 3 1 168 237 40 160 70 215 125 35 0 0 0 0 0 0 34 60 199 36 | 17 3 1 168 237 45 180 91 34 0 0 0 0 0 0 0 0 34 60 207 37 | 38 | 17 3 1 168 237 0 0 145 55 200 110 0 0 0 0 0 0 34 60 193 39 | 17 3 1 168 237 5 20 165 75 221 130 0 0 0 0 0 0 34 60 203 40 | 17 3 1 168 237 10 40 185 95 5 150 0 0 0 0 0 0 34 60 203 41 | 17 3 1 168 237 15 60 205 115 25 170 0 0 0 0 0 0 34 60 199 42 | 17 3 1 168 237 20 80 225 135 45 190 0 0 0 0 0 0 34 60 201 43 | 17 3 1 168 237 25 100 10 155 65 210 0 0 0 0 0 0 34 59 200 44 | 17 3 1 168 237 30 120 30 175 85 230 0 0 0 0 0 0 34 59 194 45 | 17 3 1 168 237 35 140 50 195 105 15 0 0 0 0 0 0 34 60 199 46 | 17 3 1 168 237 40 160 70 215 125 35 0 0 0 0 0 0 34 60 201 47 | 17 3 1 168 237 45 180 91 34 0 0 0 0 0 0 0 0 34 60 207 48 | 49 | 17 3 1 168 237 0 0 145 55 200 110 0 0 0 0 0 0 34 60 193 50 | 17 3 1 168 237 5 20 165 75 221 130 0 0 0 0 0 0 34 60 209 51 | 17 3 1 168 237 10 40 185 95 5 150 0 0 0 0 0 0 34 60 203 52 | 17 3 1 168 237 15 60 205 115 25 170 0 0 0 0 0 0 34 60 200 53 | 17 3 1 168 237 20 80 225 135 45 190 0 0 0 0 0 0 34 60 201 54 | 17 3 1 168 237 25 100 10 155 65 210 0 0 0 0 0 0 34 60 199 55 | 17 3 1 168 237 30 120 30 175 85 230 0 0 0 0 0 0 34 60 196 56 | 17 3 1 168 237 35 140 50 195 105 15 0 0 0 0 0 0 34 60 200 57 | 17 3 1 168 237 40 160 70 215 125 35 0 0 0 0 0 0 34 60 200 58 | 17 3 1 168 237 45 180 91 34 0 0 0 0 0 0 0 0 34 60 206 59 | 60 | 17 3 1 168 237 0 0 145 55 200 110 0 0 0 0 0 0 34 60 189 61 | 17 3 1 168 237 5 20 165 75 221 130 0 0 0 0 0 0 34 59 205 62 | 17 3 1 168 237 10 40 185 95 5 150 0 0 0 0 0 0 34 60 201 63 | 17 3 1 168 237 15 60 205 115 25 170 0 0 0 0 0 0 34 60 199 64 | 17 3 1 168 237 20 80 225 135 45 190 0 0 0 0 0 0 34 59 199 65 | 17 3 1 168 237 25 100 10 155 65 210 0 0 0 0 0 0 34 59 200 66 | 17 3 1 168 237 30 120 30 175 85 230 0 0 0 0 0 0 34 60 195 67 | 17 3 1 168 237 35 140 50 195 105 15 0 0 0 0 0 0 34 59 199 68 | 17 3 1 168 237 40 160 70 215 125 35 0 0 0 0 0 0 34 59 201 69 | 17 3 1 168 237 45 180 91 34 0 0 0 0 0 0 0 0 34 59 207 70 | 71 | 17 3 1 168 237 0 0 145 55 200 110 0 0 0 0 0 0 34 60 192 72 | 17 3 1 168 237 5 20 165 75 221 130 0 0 0 0 0 0 34 60 204 73 | 17 3 1 168 237 10 40 185 95 5 150 0 0 0 0 0 0 34 59 204 74 | 17 3 1 168 237 15 60 205 115 25 170 0 0 0 0 0 0 34 59 201 75 | 17 3 1 168 237 20 80 225 135 45 190 0 0 0 0 0 0 34 59 201 76 | 17 3 1 168 237 25 100 10 155 65 210 0 0 0 0 0 0 34 60 199 77 | 17 3 1 168 237 30 120 30 175 85 230 0 0 0 0 0 0 34 59 196 78 | 17 3 1 168 237 35 140 50 195 105 15 0 0 0 0 0 0 34 59 197 79 | 17 3 1 168 237 40 160 70 215 125 35 0 0 0 0 0 0 34 60 202 80 | 17 3 1 168 237 45 180 91 34 0 0 0 0 0 0 0 0 34 59 206 81 | 82 | 17 3 1 168 237 0 0 145 55 200 110 0 0 0 0 0 0 34 59 194 83 | 17 3 1 168 237 5 20 165 75 221 130 0 0 0 0 0 0 34 59 200 84 | 17 3 1 168 237 10 40 185 95 5 150 0 0 0 0 0 0 34 59 203 85 | 17 3 1 168 237 15 60 205 115 25 170 0 0 0 0 0 0 34 60 199 86 | 17 3 1 168 237 20 80 225 135 45 190 0 0 0 0 0 0 34 60 200 87 | 17 3 1 168 237 25 100 10 155 65 210 0 0 0 0 0 0 34 59 201 88 | 17 3 1 168 237 30 120 30 175 85 230 0 0 0 0 0 0 34 59 197 89 | 17 3 1 168 237 35 140 50 195 105 15 0 0 0 0 0 0 34 59 200 90 | 17 3 1 168 237 40 160 70 215 125 35 0 0 0 0 0 0 34 59 200 91 | 17 3 1 168 237 45 180 91 34 0 0 0 0 0 0 0 0 34 59 205 92 | 93 | 17 3 1 168 237 0 0 145 55 200 110 0 0 0 0 0 0 34 59 190 94 | 17 3 1 168 237 5 20 165 75 221 130 0 0 0 0 0 0 34 59 206 95 | 17 3 1 168 237 10 40 185 95 5 150 0 0 0 0 0 0 34 59 202 96 | 17 3 1 168 237 15 60 205 115 25 170 0 0 0 0 0 0 34 60 201 97 | 17 3 1 168 237 20 80 225 135 45 190 0 0 0 0 0 0 34 59 201 98 | 17 3 1 168 237 25 100 10 155 65 210 0 0 0 0 0 0 34 59 201 99 | 17 3 1 168 237 30 120 30 175 85 230 0 0 0 0 0 0 34 59 194 100 | 17 3 1 168 237 35 140 50 195 105 15 0 0 0 0 0 0 34 59 201 101 | 17 3 1 168 237 40 160 70 215 125 35 0 0 0 0 0 0 34 59 201 102 | 17 3 1 168 237 45 180 91 34 0 0 0 0 0 0 0 0 34 59 205 103 | 104 | 17 3 1 168 237 0 0 145 55 200 110 0 0 0 0 0 0 34 59 191 105 | 17 3 1 168 237 5 20 165 75 221 130 0 0 0 0 0 0 34 59 201 106 | 17 3 1 168 237 10 40 185 95 5 150 0 0 0 0 0 0 34 59 201 107 | 17 3 1 168 237 15 60 205 115 25 170 0 0 0 0 0 0 34 60 202 108 | 17 3 1 168 237 20 80 225 135 45 190 0 0 0 0 0 0 34 59 201 109 | 17 3 1 168 237 25 100 10 155 65 210 0 0 0 0 0 0 34 59 201 110 | 17 3 1 168 237 30 120 30 175 85 230 0 0 0 0 0 0 34 59 194 111 | 17 3 1 168 237 35 140 50 195 105 15 0 0 0 0 0 0 34 59 199 112 | 17 3 1 168 237 40 160 70 215 125 35 0 0 0 0 0 0 34 59 201 113 | 17 3 1 168 237 45 180 91 34 0 0 0 0 0 0 0 0 34 59 205 -------------------------------------------------------------------------------- /code/startup_stm32f10x.c: -------------------------------------------------------------------------------- 1 | /* Generated by startup_generator */ 2 | 3 | #include 4 | //#include 5 | 6 | extern void _estack(void); // to force type checking 7 | void Reset_Handler(void); 8 | void default_handler (void) 9 | { 10 | while(1); 11 | } 12 | 13 | void __attribute__ ((weak)) __libc_init_array (void){} 14 | 15 | // Linker supplied pointers 16 | 17 | extern unsigned long _sidata; 18 | extern unsigned long _sdata; 19 | extern unsigned long _edata; 20 | extern unsigned long _sbss; 21 | extern unsigned long _ebss; 22 | 23 | extern int main(void); 24 | 25 | void Reset_Handler(void) { 26 | 27 | unsigned long *src, *dst; 28 | 29 | src = &_sidata; 30 | dst = &_sdata; 31 | 32 | // Copy data initializers 33 | 34 | while (dst < &_edata) 35 | *(dst++) = *(src++); 36 | 37 | // Zero bss 38 | 39 | dst = &_sbss; 40 | while (dst < &_ebss) 41 | *(dst++) = 0; 42 | 43 | //SystemInit(); 44 | __libc_init_array(); 45 | main(); 46 | while(1) {} 47 | } 48 | 49 | /* Vector Table */ 50 | 51 | void NMI_Handler (void) __attribute__ ((weak, alias ("default_handler"))); 52 | void HardFault_Handler (void) __attribute__ ((weak, alias ("default_handler"))); 53 | void MemMange_Handler (void) __attribute__ ((weak, alias ("default_handler"))); 54 | void BusFault_Handler (void) __attribute__ ((weak, alias ("default_handler"))); 55 | void UsageFault_Handler (void) __attribute__ ((weak, alias ("default_handler"))); 56 | void SVC_Handler (void) __attribute__ ((weak, alias ("default_handler"))); 57 | void DebugMon_Handler (void) __attribute__ ((weak, alias ("default_handler"))); 58 | void PendSV_Handler (void) __attribute__ ((weak, alias ("default_handler"))); 59 | void SysTick_Handler (void) __attribute__ ((weak, alias ("default_handler"))); 60 | void WWDG_IRQHandler (void) __attribute__ ((weak, alias ("default_handler"))); 61 | void PVD_IRQHandler (void) __attribute__ ((weak, alias ("default_handler"))); 62 | void TAMPER_STAMP_IRQHandler (void) __attribute__ ((weak, alias ("default_handler"))); 63 | void RTC_WKUP_IRQHandler (void) __attribute__ ((weak, alias ("default_handler"))); 64 | void FLASH_IRQHandler (void) __attribute__ ((weak, alias ("default_handler"))); 65 | void RCC_IRQHandler (void) __attribute__ ((weak, alias ("default_handler"))); 66 | void EXTI0_IRQHandler (void) __attribute__ ((weak, alias ("default_handler"))); 67 | void EXTI1_IRQHandler (void) __attribute__ ((weak, alias ("default_handler"))); 68 | void EXTI2_IRQHandler (void) __attribute__ ((weak, alias ("default_handler"))); 69 | void EXTI3_IRQHandler (void) __attribute__ ((weak, alias ("default_handler"))); 70 | void EXTI4_IRQHandler (void) __attribute__ ((weak, alias ("default_handler"))); 71 | void DMA1_Channel1_IRQHandler (void) __attribute__ ((weak, alias ("default_handler"))); 72 | void DMA1_Channel2_IRQHandler (void) __attribute__ ((weak, alias ("default_handler"))); 73 | void DMA1_Channel3_IRQHandler (void) __attribute__ ((weak, alias ("default_handler"))); 74 | void DMA1_Channel4_IRQHandler (void) __attribute__ ((weak, alias ("default_handler"))); 75 | void DMA1_Channel5_IRQHandler (void) __attribute__ ((weak, alias ("default_handler"))); 76 | void DMA1_Channel6_IRQHandler (void) __attribute__ ((weak, alias ("default_handler"))); 77 | void DMA1_Channel7_IRQHandler (void) __attribute__ ((weak, alias ("default_handler"))); 78 | void ADC1_IRQHandler (void) __attribute__ ((weak, alias ("default_handler"))); 79 | void EXTI9_5_IRQHandler (void) __attribute__ ((weak, alias ("default_handler"))); 80 | void TIM1_BRK_TIM15_IRQHandler (void) __attribute__ ((weak, alias ("default_handler"))); 81 | void TIM1_UP_TIM16_IRQHandler (void) __attribute__ ((weak, alias ("default_handler"))); 82 | void TIM1_TRG_COM_TIM17_IRQHandler (void) __attribute__ ((weak, alias ("default_handler"))); 83 | void TIM1_CC_IRQHandler (void) __attribute__ ((weak, alias ("default_handler"))); 84 | void TIM2_IRQHandler (void) __attribute__ ((weak, alias ("default_handler"))); 85 | void TIM3_IRQHandler (void) __attribute__ ((weak, alias ("default_handler"))); 86 | void TIM4_IRQHandler (void) __attribute__ ((weak, alias ("default_handler"))); 87 | void I2C1_EV_IRQHandler (void) __attribute__ ((weak, alias ("default_handler"))); 88 | void I2C1_ER_IRQHandler (void) __attribute__ ((weak, alias ("default_handler"))); 89 | void I2C2_EV_IRQHandler (void) __attribute__ ((weak, alias ("default_handler"))); 90 | void I2C2_ER_IRQHandler (void) __attribute__ ((weak, alias ("default_handler"))); 91 | void SPI1_IRQHandler (void) __attribute__ ((weak, alias ("default_handler"))); 92 | void SPI2_IRQHandler (void) __attribute__ ((weak, alias ("default_handler"))); 93 | void USART1_IRQHandler (void) __attribute__ ((weak, alias ("default_handler"))); 94 | void USART2_IRQHandler (void) __attribute__ ((weak, alias ("default_handler"))); 95 | void USART3_IRQHandler (void) __attribute__ ((weak, alias ("default_handler"))); 96 | void EXTI15_10_IRQHandler (void) __attribute__ ((weak, alias ("default_handler"))); 97 | void RTCAlarm_IRQHandler (void) __attribute__ ((weak, alias ("default_handler"))); 98 | void CEC_IRQHandler (void) __attribute__ ((weak, alias ("default_handler"))); 99 | void TIM12_IRQHandler (void) __attribute__ ((weak, alias ("default_handler"))); 100 | void TIM13_IRQHandler (void) __attribute__ ((weak, alias ("default_handler"))); 101 | void TIM14_IRQHandler (void) __attribute__ ((weak, alias ("default_handler"))); 102 | void ADC3_IRQHandler (void) __attribute__ ((weak, alias ("default_handler"))); 103 | void FSMC_IRQHandler (void) __attribute__ ((weak, alias ("default_handler"))); 104 | void TIM5_IRQHandler (void) __attribute__ ((weak, alias ("default_handler"))); 105 | void SPI3_IRQHandler (void) __attribute__ ((weak, alias ("default_handler"))); 106 | void UART4_IRQHandler (void) __attribute__ ((weak, alias ("default_handler"))); 107 | void UART5_IRQHandler (void) __attribute__ ((weak, alias ("default_handler"))); 108 | void TIM6_DAC_IRQHandler (void) __attribute__ ((weak, alias ("default_handler"))); 109 | void TIM7_IRQHandler (void) __attribute__ ((weak, alias ("default_handler"))); 110 | void DMA2_Channel1_IRQHandler (void) __attribute__ ((weak, alias ("default_handler"))); 111 | void DMA2_Channel2_IRQHandler (void) __attribute__ ((weak, alias ("default_handler"))); 112 | void DMA2_Channel3_IRQHandler (void) __attribute__ ((weak, alias ("default_handler"))); 113 | void DMA2_Channel4_5_IRQHandler (void) __attribute__ ((weak, alias ("default_handler"))); 114 | void DMA2_Channel5_IRQHandler (void) __attribute__ ((weak, alias ("default_handler"))); 115 | 116 | 117 | 118 | __attribute__ ((section(".isr_vector"))) 119 | 120 | void (* const g_pfnVectors[])(void) = { 121 | 122 | _estack, 123 | Reset_Handler, 124 | NMI_Handler, 125 | HardFault_Handler, 126 | MemMange_Handler, 127 | BusFault_Handler, 128 | UsageFault_Handler, 129 | 0, 0, 0, 0, 130 | SVC_Handler, 131 | DebugMon_Handler, 132 | 0, 133 | PendSV_Handler, 134 | SysTick_Handler, 135 | WWDG_IRQHandler, 136 | PVD_IRQHandler, 137 | TAMPER_STAMP_IRQHandler, 138 | RTC_WKUP_IRQHandler, 139 | FLASH_IRQHandler, 140 | RCC_IRQHandler, 141 | EXTI0_IRQHandler, 142 | EXTI1_IRQHandler, 143 | EXTI2_IRQHandler, 144 | EXTI3_IRQHandler, 145 | EXTI4_IRQHandler, 146 | DMA1_Channel1_IRQHandler, 147 | DMA1_Channel2_IRQHandler, 148 | DMA1_Channel3_IRQHandler, 149 | DMA1_Channel4_IRQHandler, 150 | DMA1_Channel5_IRQHandler, 151 | DMA1_Channel6_IRQHandler, 152 | DMA1_Channel7_IRQHandler, 153 | ADC1_IRQHandler, 154 | 0, 0, 0, 0, 155 | EXTI9_5_IRQHandler, 156 | TIM1_BRK_TIM15_IRQHandler, 157 | TIM1_UP_TIM16_IRQHandler, 158 | TIM1_TRG_COM_TIM17_IRQHandler, 159 | TIM1_CC_IRQHandler, 160 | TIM2_IRQHandler, 161 | TIM3_IRQHandler, 162 | TIM4_IRQHandler, 163 | I2C1_EV_IRQHandler, 164 | I2C1_ER_IRQHandler, 165 | I2C2_EV_IRQHandler, 166 | I2C2_ER_IRQHandler, 167 | SPI1_IRQHandler, 168 | SPI2_IRQHandler, 169 | USART1_IRQHandler, 170 | USART2_IRQHandler, 171 | USART3_IRQHandler, 172 | EXTI15_10_IRQHandler, 173 | RTCAlarm_IRQHandler, 174 | CEC_IRQHandler, 175 | TIM12_IRQHandler, 176 | TIM13_IRQHandler, 177 | TIM14_IRQHandler, 178 | 0, 179 | ADC3_IRQHandler, 180 | FSMC_IRQHandler, 181 | 0, 182 | TIM5_IRQHandler, 183 | SPI3_IRQHandler, 184 | UART4_IRQHandler, 185 | UART5_IRQHandler, 186 | TIM6_DAC_IRQHandler, 187 | TIM7_IRQHandler, 188 | DMA2_Channel1_IRQHandler, 189 | DMA2_Channel2_IRQHandler, 190 | DMA2_Channel3_IRQHandler, 191 | DMA2_Channel4_5_IRQHandler, 192 | DMA2_Channel5_IRQHandler, 193 | 0, 0, 0, 0, 0, 0, 0, 0, 194 | 0, 195 | #if defined (STM32F10X_LD_VL) || (defined STM32F10X_MD_VL) 196 | [0x1CC/4] = 0xF108F85F 197 | #elif defined (STM32F10X_HD_VL) 198 | [0x1E0/4] = 0xF108F85F 199 | #endif 200 | 201 | }; 202 | -------------------------------------------------------------------------------- /design/pcb/xlyRX-cache.lib: -------------------------------------------------------------------------------- 1 | EESchema-LIBRARY Version 2.3 2 | #encoding utf-8 3 | # 4 | # +3V3 5 | # 6 | DEF +3V3 #PWR 0 0 Y Y 1 F P 7 | F0 "#PWR" 0 -150 50 H I C CNN 8 | F1 "+3V3" 0 140 50 H V C CNN 9 | F2 "" 0 0 50 H V C CNN 10 | F3 "" 0 0 50 H V C CNN 11 | ALIAS +3.3V 12 | DRAW 13 | P 2 0 1 0 -30 50 0 100 N 14 | P 2 0 1 0 0 0 0 100 N 15 | P 2 0 1 0 0 100 30 50 N 16 | X +3V3 1 0 0 0 U 50 50 1 1 W N 17 | ENDDRAW 18 | ENDDEF 19 | # 20 | # +BATT 21 | # 22 | DEF +BATT #PWR 0 0 Y Y 1 F P 23 | F0 "#PWR" 0 -150 50 H I C CNN 24 | F1 "+BATT" 0 140 50 H V C CNN 25 | F2 "" 0 0 50 H V C CNN 26 | F3 "" 0 0 50 H V C CNN 27 | DRAW 28 | P 2 0 1 0 -30 50 0 100 N 29 | P 2 0 1 0 0 0 0 100 N 30 | P 2 0 1 0 0 100 30 50 N 31 | X +BATT 1 0 0 0 U 50 50 1 1 W N 32 | ENDDRAW 33 | ENDDEF 34 | # 35 | # C 36 | # 37 | DEF C C 0 10 N Y 1 F N 38 | F0 "C" 25 100 50 H V L CNN 39 | F1 "C" 25 -100 50 H V L CNN 40 | F2 "" 38 -150 50 H V C CNN 41 | F3 "" 0 0 50 H V C CNN 42 | $FPLIST 43 | C? 44 | C_????_* 45 | C_???? 46 | SMD*_c 47 | Capacitor* 48 | $ENDFPLIST 49 | DRAW 50 | P 2 0 1 20 -80 -30 80 -30 N 51 | P 2 0 1 20 -80 30 80 30 N 52 | X ~ 1 0 150 110 D 50 50 1 1 P 53 | X ~ 2 0 -150 110 U 50 50 1 1 P 54 | ENDDRAW 55 | ENDDEF 56 | # 57 | # CONN_01X01 58 | # 59 | DEF CONN_01X01 P 0 40 Y N 1 F N 60 | F0 "P" 0 100 50 H V C CNN 61 | F1 "CONN_01X01" 100 0 50 V V C CNN 62 | F2 "" 0 0 50 H V C CNN 63 | F3 "" 0 0 50 H V C CNN 64 | $FPLIST 65 | Pin_Header_Straight_1X01 66 | Pin_Header_Angled_1X01 67 | Socket_Strip_Straight_1X01 68 | Socket_Strip_Angled_1X01 69 | $ENDFPLIST 70 | DRAW 71 | S -50 5 10 -5 0 1 0 N 72 | S -50 50 50 -50 0 1 0 N 73 | X P1 1 -200 0 150 R 50 50 1 1 P 74 | ENDDRAW 75 | ENDDEF 76 | # 77 | # CONN_01X03 78 | # 79 | DEF CONN_01X03 P 0 40 Y N 1 F N 80 | F0 "P" 0 200 50 H V C CNN 81 | F1 "CONN_01X03" 100 0 50 V V C CNN 82 | F2 "" 0 0 50 H V C CNN 83 | F3 "" 0 0 50 H V C CNN 84 | $FPLIST 85 | Pin_Header_Straight_1X03 86 | Pin_Header_Angled_1X03 87 | Socket_Strip_Straight_1X03 88 | Socket_Strip_Angled_1X03 89 | $ENDFPLIST 90 | DRAW 91 | S -50 -95 10 -105 0 1 0 N 92 | S -50 5 10 -5 0 1 0 N 93 | S -50 105 10 95 0 1 0 N 94 | S -50 150 50 -150 0 1 0 N 95 | X P1 1 -200 100 150 R 50 50 1 1 P 96 | X P2 2 -200 0 150 R 50 50 1 1 P 97 | X P3 3 -200 -100 150 R 50 50 1 1 P 98 | ENDDRAW 99 | ENDDEF 100 | # 101 | # CONN_01X04 102 | # 103 | DEF CONN_01X04 P 0 40 Y N 1 F N 104 | F0 "P" 0 250 50 H V C CNN 105 | F1 "CONN_01X04" 100 0 50 V V C CNN 106 | F2 "" 0 0 50 H V C CNN 107 | F3 "" 0 0 50 H V C CNN 108 | $FPLIST 109 | Pin_Header_Straight_1X04 110 | Pin_Header_Angled_1X04 111 | Socket_Strip_Straight_1X04 112 | Socket_Strip_Angled_1X04 113 | $ENDFPLIST 114 | DRAW 115 | S -50 -145 10 -155 0 1 0 N 116 | S -50 -45 10 -55 0 1 0 N 117 | S -50 55 10 45 0 1 0 N 118 | S -50 155 10 145 0 1 0 N 119 | S -50 200 50 -200 0 1 0 N 120 | X P1 1 -200 150 150 R 50 50 1 1 P 121 | X P2 2 -200 50 150 R 50 50 1 1 P 122 | X P3 3 -200 -50 150 R 50 50 1 1 P 123 | X P4 4 -200 -150 150 R 50 50 1 1 P 124 | ENDDRAW 125 | ENDDEF 126 | # 127 | # CONN_01X12 128 | # 129 | DEF CONN_01X12 P 0 40 Y N 1 F N 130 | F0 "P" 0 650 50 H V C CNN 131 | F1 "CONN_01X12" 100 0 50 V V C CNN 132 | F2 "" 0 0 50 H V C CNN 133 | F3 "" 0 0 50 H V C CNN 134 | $FPLIST 135 | Pin_Header_Straight_1X12 136 | Pin_Header_Angled_1X12 137 | Socket_Strip_Straight_1X12 138 | Socket_Strip_Angled_1X12 139 | $ENDFPLIST 140 | DRAW 141 | S -50 -600 50 600 0 1 0 N 142 | S -50 -545 10 -555 0 1 0 N 143 | S -50 -445 10 -455 0 1 0 N 144 | S -50 -345 10 -355 0 1 0 N 145 | S -50 -245 10 -255 0 1 0 N 146 | S -50 -145 10 -155 0 1 0 N 147 | S -50 -45 10 -55 0 1 0 N 148 | S -50 55 10 45 0 1 0 N 149 | S -50 155 10 145 0 1 0 N 150 | S -50 255 10 245 0 1 0 N 151 | S -50 355 10 345 0 1 0 N 152 | S -50 455 10 445 0 1 0 N 153 | S -50 555 10 545 0 1 0 N 154 | X P1 1 -200 550 150 R 50 50 1 1 P 155 | X P2 2 -200 450 150 R 50 50 1 1 P 156 | X P3 3 -200 350 150 R 50 50 1 1 P 157 | X P4 4 -200 250 150 R 50 50 1 1 P 158 | X P5 5 -200 150 150 R 50 50 1 1 P 159 | X P6 6 -200 50 150 R 50 50 1 1 P 160 | X P7 7 -200 -50 150 R 50 50 1 1 P 161 | X P8 8 -200 -150 150 R 50 50 1 1 P 162 | X P9 9 -200 -250 150 R 50 50 1 1 P 163 | X P10 10 -200 -350 150 R 50 50 1 1 P 164 | X P11 11 -200 -450 150 R 50 50 1 1 P 165 | X P12 12 -200 -550 150 R 50 50 1 1 P 166 | ENDDRAW 167 | ENDDEF 168 | # 169 | # CONN_02X01 170 | # 171 | DEF CONN_02X01 P 0 1 Y N 1 F N 172 | F0 "P" 0 100 50 H V C CNN 173 | F1 "CONN_02X01" 0 -100 50 H V C CNN 174 | F2 "" 0 -1200 50 H V C CNN 175 | F3 "" 0 -1200 50 H V C CNN 176 | $FPLIST 177 | Pin_Header_Straight_2X01 178 | Pin_Header_Angled_2X01 179 | Socket_Strip_Straight_2X01 180 | Socket_Strip_Angled_2X01 181 | $ENDFPLIST 182 | DRAW 183 | S -100 5 -50 -5 0 1 0 N 184 | S -100 50 100 -50 0 1 0 N 185 | S 50 5 100 -5 0 1 0 N 186 | X P1 1 -250 0 150 R 50 50 1 1 P 187 | X P2 2 250 0 150 L 50 50 1 1 P 188 | ENDDRAW 189 | ENDDEF 190 | # 191 | # CP 192 | # 193 | DEF CP C 0 10 N Y 1 F N 194 | F0 "C" 25 100 50 H V L CNN 195 | F1 "CP" 25 -100 50 H V L CNN 196 | F2 "" 38 -150 50 H V C CNN 197 | F3 "" 0 0 50 H V C CNN 198 | $FPLIST 199 | CP* 200 | C_Axial* 201 | C_Radial* 202 | TantalC* 203 | C*elec 204 | c_elec* 205 | SMD*_Pol 206 | $ENDFPLIST 207 | DRAW 208 | S -90 20 -90 40 0 1 0 N 209 | S -90 20 90 20 0 1 0 N 210 | S 90 -20 -90 -40 0 1 0 F 211 | S 90 40 -90 40 0 1 0 N 212 | S 90 40 90 20 0 1 0 N 213 | P 2 0 1 0 -70 90 -30 90 N 214 | P 2 0 1 0 -50 110 -50 70 N 215 | X ~ 1 0 150 110 D 50 50 1 1 P 216 | X ~ 2 0 -150 110 U 50 50 1 1 P 217 | ENDDRAW 218 | ENDDEF 219 | # 220 | # Crystal_GND24 221 | # 222 | DEF Crystal_GND24 Y 0 40 Y N 1 F N 223 | F0 "Y" 125 200 50 H V L CNN 224 | F1 "Crystal_GND24" 125 125 50 H V L CNN 225 | F2 "" 0 0 50 H V C CNN 226 | F3 "" 0 0 50 H V C CNN 227 | $FPLIST 228 | Crystal* 229 | $ENDFPLIST 230 | DRAW 231 | S -45 100 45 -100 0 1 12 N 232 | P 2 0 1 0 -100 0 -80 0 N 233 | P 2 0 1 20 -80 -50 -80 50 N 234 | P 2 0 1 0 0 -150 0 -140 N 235 | P 2 0 1 0 0 140 0 150 N 236 | P 2 0 1 20 80 -50 80 50 N 237 | P 2 0 1 0 80 0 100 0 N 238 | P 4 0 1 0 -100 -90 -100 -140 100 -140 100 -90 N 239 | P 4 0 1 0 -100 90 -100 140 100 140 100 90 N 240 | X 1 1 -150 0 50 R 50 50 1 1 P 241 | X 2 2 0 200 50 D 50 50 1 1 P 242 | X 3 3 150 0 50 L 50 50 1 1 P 243 | X 4 4 0 -200 50 U 50 50 1 1 P 244 | ENDDRAW 245 | ENDDEF 246 | # 247 | # GND 248 | # 249 | DEF GND #PWR 0 0 Y Y 1 F P 250 | F0 "#PWR" 0 -250 50 H I C CNN 251 | F1 "GND" 0 -150 50 H V C CNN 252 | F2 "" 0 0 50 H V C CNN 253 | F3 "" 0 0 50 H V C CNN 254 | DRAW 255 | P 6 0 1 0 0 0 0 -50 50 -50 0 -100 -50 -50 0 -50 N 256 | X GND 1 0 0 0 D 50 50 1 1 W N 257 | ENDDRAW 258 | ENDDEF 259 | # 260 | # LED 261 | # 262 | DEF LED D 0 40 Y N 1 F N 263 | F0 "D" 0 100 50 H V C CNN 264 | F1 "LED" 0 -100 50 H V C CNN 265 | F2 "" 0 0 50 H V C CNN 266 | F3 "" 0 0 50 H V C CNN 267 | $FPLIST 268 | LED* 269 | $ENDFPLIST 270 | DRAW 271 | P 2 0 1 8 -50 -50 -50 50 N 272 | P 2 0 1 0 -50 0 50 0 N 273 | P 4 0 1 8 50 -50 50 50 -50 0 50 -50 N 274 | P 5 0 1 0 -120 -30 -180 -90 -150 -90 -180 -90 -180 -60 N 275 | P 5 0 1 0 -70 -30 -130 -90 -100 -90 -130 -90 -130 -60 N 276 | X K 1 -150 0 100 R 50 50 1 1 P 277 | X A 2 150 0 100 L 50 50 1 1 P 278 | ENDDRAW 279 | ENDDEF 280 | # 281 | # NCP1117DTAG 282 | # 283 | DEF NCP1117DTAG U 0 30 Y Y 1 F N 284 | F0 "U" 0 225 50 H V C CNN 285 | F1 "NCP1117DTAG" 0 150 50 H V C CNN 286 | F2 "TO_SOT_Packages_SMD:TO-263-3Lead" 50 -250 50 H I L CNN 287 | F3 "" 0 0 50 H V C CNN 288 | ALIAS NCP1117DT12G NCP1117DT15G NCP1117DT18G NCP1117DT19G NCP1117DT20G NCP1117DT25G NCP1117DT285G NCP1117DT33G NCP1117DT50G 289 | $FPLIST 290 | TO-263-3* 291 | $ENDFPLIST 292 | DRAW 293 | S -200 100 200 -200 0 1 10 f 294 | X GND 1 0 -300 100 U 50 50 1 1 W 295 | X VO 2 300 0 100 L 50 50 1 1 w 296 | X VI 3 -300 0 100 R 50 50 1 1 W 297 | ENDDRAW 298 | ENDDEF 299 | # 300 | # R 301 | # 302 | DEF R R 0 0 N Y 1 F N 303 | F0 "R" 80 0 50 V V C CNN 304 | F1 "R" 0 0 50 V V C CNN 305 | F2 "" -70 0 50 V V C CNN 306 | F3 "" 0 0 50 H V C CNN 307 | $FPLIST 308 | R_* 309 | Resistor_* 310 | $ENDFPLIST 311 | DRAW 312 | S -40 -100 40 100 0 1 10 N 313 | X ~ 1 0 150 50 D 50 50 1 1 P 314 | X ~ 2 0 -150 50 U 50 50 1 1 P 315 | ENDDRAW 316 | ENDDEF 317 | # 318 | # STM32F103C8Tx 319 | # 320 | DEF STM32F103C8Tx U 0 40 Y Y 1 L N 321 | F0 "U" -2800 1725 50 H V L BNN 322 | F1 "STM32F103C8Tx" 2800 1725 50 H V R BNN 323 | F2 "LQFP48" 2800 1675 50 H V R TNN 324 | F3 "" 0 0 50 H V C CNN 325 | ALIAS STM32F103CBTx 326 | DRAW 327 | S -2800 -1700 2800 1700 0 1 10 f 328 | X VBAT 1 -2900 1000 100 R 50 50 1 1 W 329 | X PC13/RTC_OUT/RTC_TAMPER 2 -2900 500 100 R 50 50 1 1 B 330 | X PC14/RCC_OSC32_IN 3 -2900 400 100 R 50 50 1 1 B 331 | X PC15/ADC1_EXTI15/ADC2_EXTI15/RCC_OSC32_OUT 4 -2900 300 100 R 50 50 1 1 B 332 | X PD0/RCC_OSC_IN 5 -2900 800 100 R 50 50 1 1 I 333 | X PD1/RCC_OSC_OUT 6 -2900 700 100 R 50 50 1 1 I 334 | X NRST 7 -2900 1400 100 R 50 50 1 1 I 335 | X VSSA 8 100 -1800 100 U 50 50 1 1 W 336 | X VDDA 9 100 1800 100 D 50 50 1 1 W 337 | X ADC1_IN0/ADC2_IN0/SYS_WKUP/TIM2_CH1/TIM2_ETR/USART2_CTS/PA0 10 2900 100 100 L 50 50 1 1 B 338 | X PB2/BOOT1 20 -2900 -100 100 R 50 50 1 1 B 339 | X TIM1_CH2/USART1_TX/PA9 30 2900 -800 100 L 50 50 1 1 B 340 | X PB4/SPI1_MISO/SYS_NJTRST/TIM3_CH1 40 -2900 -300 100 R 50 50 1 1 B 341 | X ADC1_IN1/ADC2_IN1/TIM2_CH2/USART2_RTS/PA1 11 2900 0 100 L 50 50 1 1 B 342 | X PB10/I2C2_SCL/TIM2_CH3/USART3_TX 21 -2900 -900 100 R 50 50 1 1 B 343 | X TIM1_CH3/USART1_RX/PA10 31 2900 -900 100 L 50 50 1 1 B 344 | X PB5/I2C1_SMBA/SPI1_MOSI/TIM3_CH2 41 -2900 -400 100 R 50 50 1 1 B 345 | X ADC1_IN2/ADC2_IN2/TIM2_CH3/USART2_TX/PA2 12 2900 -100 100 L 50 50 1 1 B 346 | X PB11/ADC1_EXTI11/ADC2_EXTI11/I2C2_SDA/TIM2_CH4/USART3_RX 22 -2900 -1000 100 R 50 50 1 1 B 347 | X ADC1_EXTI11/ADC2_EXTI11/CAN_RX/TIM1_CH4/USART1_CTS/USB_DM/PA11 32 2900 -1000 100 L 50 50 1 1 B 348 | X PB6/I2C1_SCL/TIM4_CH1/USART1_TX 42 -2900 -500 100 R 50 50 1 1 B 349 | X ADC1_IN3/ADC2_IN3/TIM2_CH4/USART2_RX/PA3 13 2900 -200 100 L 50 50 1 1 B 350 | X VSS 23 -200 -1800 100 U 50 50 1 1 W 351 | X CAN_TX/TIM1_ETR/USART1_RTS/USB_DP/PA12 33 2900 -1100 100 L 50 50 1 1 B 352 | X PB7/I2C1_SDA/TIM4_CH2/USART1_RX 43 -2900 -600 100 R 50 50 1 1 B 353 | X ADC1_IN4/ADC2_IN4/SPI1_NSS/USART2_CK/PA4 14 2900 -300 100 L 50 50 1 1 B 354 | X VDD 24 -200 1800 100 D 50 50 1 1 W 355 | X SYS_JTMS-SWDIO/PA13 34 2900 -1200 100 L 50 50 1 1 B 356 | X BOOT0 44 -2900 1200 100 R 50 50 1 1 I 357 | X ADC1_IN5/ADC2_IN5/SPI1_SCK/PA5 15 2900 -400 100 L 50 50 1 1 B 358 | X PB12/I2C2_SMBA/SPI2_NSS/TIM1_BKIN/USART3_CK 25 -2900 -1100 100 R 50 50 1 1 B 359 | X VSS 35 -100 -1800 100 U 50 50 1 1 W 360 | X PB8/CAN_RX/I2C1_SCL/TIM4_CH3 45 -2900 -700 100 R 50 50 1 1 B 361 | X ADC1_IN6/ADC2_IN6/SPI1_MISO/TIM1_BKIN/TIM3_CH1/PA6 16 2900 -500 100 L 50 50 1 1 B 362 | X PB13/SPI2_SCK/TIM1_CH1N/USART3_CTS 26 -2900 -1200 100 R 50 50 1 1 B 363 | X VDD 36 -100 1800 100 D 50 50 1 1 W 364 | X PB9/CAN_TX/I2C1_SDA/TIM4_CH4 46 -2900 -800 100 R 50 50 1 1 B 365 | X ADC1_IN7/ADC2_IN7/SPI1_MOSI/TIM1_CH1N/TIM3_CH2/PA7 17 2900 -600 100 L 50 50 1 1 B 366 | X PB14/SPI2_MISO/TIM1_CH2N/USART3_RTS 27 -2900 -1300 100 R 50 50 1 1 B 367 | X SYS_JTCK-SWCLK/PA14 37 2900 -1300 100 L 50 50 1 1 B 368 | X VSS 47 0 -1800 100 U 50 50 1 1 W 369 | X PB0/ADC1_IN8/ADC2_IN8/TIM1_CH2N/TIM3_CH3 18 -2900 100 100 R 50 50 1 1 B 370 | X PB15/ADC1_EXTI15/ADC2_EXTI15/SPI2_MOSI/TIM1_CH3N 28 -2900 -1400 100 R 50 50 1 1 B 371 | X ADC1_EXTI15/ADC2_EXTI15/SPI1_NSS/SYS_JTDI/TIM2_CH1/TIM2_ETR/PA15 38 2900 -1400 100 L 50 50 1 1 B 372 | X VDD 48 0 1800 100 D 50 50 1 1 W 373 | X PB1/ADC1_IN9/ADC2_IN9/TIM1_CH3N/TIM3_CH4 19 -2900 0 100 R 50 50 1 1 B 374 | X RCC_MCO/TIM1_CH1/USART1_CK/PA8 29 2900 -700 100 L 50 50 1 1 B 375 | X PB3/SPI1_SCK/SYS_JTDO-TRACESWO/TIM2_CH2 39 -2900 -200 100 R 50 50 1 1 B 376 | ENDDRAW 377 | ENDDEF 378 | # 379 | # SW_Push 380 | # 381 | DEF SW_Push SW 0 40 N N 1 F N 382 | F0 "SW" 50 100 50 H V L CNN 383 | F1 "SW_Push" 0 -60 50 H V C CNN 384 | F2 "" 0 200 50 H V C CNN 385 | F3 "" 0 200 50 H V C CNN 386 | DRAW 387 | C -80 0 20 0 1 0 N 388 | C 80 0 20 0 1 0 N 389 | P 2 0 1 0 0 50 0 120 N 390 | P 2 0 1 0 100 50 -100 50 N 391 | X 1 1 -200 0 100 R 50 50 0 1 P 392 | X 2 2 200 0 100 L 50 50 0 1 P 393 | ENDDRAW 394 | ENDDEF 395 | # 396 | #End Library 397 | -------------------------------------------------------------------------------- /code/cc2500.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Patrik Bachan 2 | // 3 | // GNU GENERAL PUBLIC LICENSE 4 | // Version 3, 29 June 2007 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | #ifndef _CC2500_LIB 20 | #define _CC2500_LIB 21 | 22 | #include "config.h" 23 | #include "misc.h" 24 | #include 25 | 26 | enum cc2500_w_registers 27 | { 28 | 29 | CC2500_SRES = 0x30, //Reset chip. 30 | CC2500_SFSTXON = 0x31, //Enable and calibrate frequency synthesizer (if MCSM0.FS_AUTOCAL=1). If in RX (with CCA): Go to a wait state where only the synthesizer is running (for quick RX / TX turnaround). 31 | CC2500_SXOFF = 0x32, //Turn off crystal oscillator. 32 | CC2500_SCAL = 0x33, //Calibrate frequency synthesizer and turn it off. SCAL can be strobed from IDLE mode without setting manual calibration mode (MCSM0.FS_AUTOCAL=0) 33 | CC2500_SRX = 0x34, //Enable RX. Perform calibration first if coming from IDLE and MCSM0.FS_AUTOCAL=1. 34 | CC2500_STX = 0x35, //In IDLE state: Enable TX. Perform calibration first if MCSM0.FS_AUTOCAL=1. If in RX state and CCA is enabled: Only go to TX if channel is clear. 35 | CC2500_SIDLE = 0x36, //Exit RX / TX, turn off frequency synthesizer and exit Wake-On-Radio mode if applicable. 36 | CC2500_SWOR = 0x38, //Start automatic RX polling sequence (Wake-on-Radio) as described in Section 19.5 if WORCTRL.RC_PD=0. 37 | CC2500_SPWD = 0x39, //Enter power down mode when CSn goes high. 38 | CC2500_SFRX = 0x3A, //Flush the RX FIFO buffer. Only issue SFRX in IDLE or RXFIFO_OVERFLOW states. 39 | CC2500_SFTX = 0x3B, //Flush the TX FIFO buffer. Only issue SFTX in IDLE or TXFIFO_UNDERFLOW states. 40 | CC2500_SWORRST = 0x3C, //Reset real time clock to Event1 value. 41 | CC2500_SNOP = 0x3D, //No operation. May be used to get access to the chip status byte. 42 | }; 43 | 44 | enum cc2500_rw_registers 45 | { 46 | CC2500_IOCFG2 = 0x00, //GDO2 output pin configuration 47 | CC2500_IOCFG1 = 0x01, //GDO1 output pin configuration 48 | CC2500_IOCFG0 = 0x02, //GDO0 output pin configuration 49 | CC2500_FIFOTHR = 0x03, //RX FIFO and TX FIFO thresholds 50 | CC2500_SYNC1 = 0x04, //Sync word, high byte 51 | CC2500_SYNC0 = 0x05, //Sync word, low byte 52 | CC2500_PKTLEN = 0x06, //Packet length 53 | CC2500_PKTCTRL1 = 0x07, //Packet automation control 54 | CC2500_PKTCTRL0 = 0x08, //Packet automation control 55 | CC2500_ADDR = 0x09, //Device address 56 | CC2500_CHANNR = 0x0A, //Channel number 57 | CC2500_FSCTRL1 = 0x0B, //Frequency synthesizer control 58 | CC2500_FSCTRL0 = 0x0C, //Frequency synthesizer control 59 | CC2500_FREQ2 = 0x0D, //Frequency control word, high byte 60 | CC2500_FREQ1 = 0x0E, //Frequency control word, middle byte 61 | CC2500_FREQ0 = 0x0F, //Frequency control word, low byte 62 | CC2500_MDMCFG4 = 0x10, //Modem configuration 63 | CC2500_MDMCFG3 = 0x11, //Modem configuration 64 | CC2500_MDMCFG2 = 0x12, //Modem configuration 65 | CC2500_MDMCFG1 = 0x13, //Modem configuration 66 | CC2500_MDMCFG0 = 0x14, //Modem configuration 67 | CC2500_DEVIATN = 0x15, //Modem deviation setting 68 | CC2500_MCSM2 = 0x16, //Main Radio Control State Machine configuration 69 | CC2500_MCSM1 = 0x17, //Main Radio Control State Machine configuration 70 | CC2500_MCSM0 = 0x18, //Main Radio Control State Machine configuration 71 | CC2500_FOCCFG = 0x19, //Frequency Offset Compensation configuration 72 | CC2500_BSCFG = 0x1A, //Bit Synchronization configuration 73 | CC2500_AGCTRL2 = 0x1B, //AGC control 74 | CC2500_AGCTRL1 = 0x1C, //AGC control 75 | CC2500_AGCTRL0 = 0x1D, //AGC control 76 | CC2500_WOREVT1 = 0x1E, //High byte Event 0 timeout 77 | CC2500_WOREVT0 = 0x1F, //Low byte Event 0 timeout 78 | CC2500_WORCTRL = 0x20, //Wake On Radio control 79 | CC2500_FREND1 = 0x21, //Front end RX configuration 80 | CC2500_FREND0 = 0x22, //Front end TX configuration 81 | CC2500_FSCAL3 = 0x23, //Frequency synthesizer calibration 82 | CC2500_FSCAL2 = 0x24, //Frequency synthesizer calibration 83 | CC2500_FSCAL1 = 0x25, //Frequency synthesizer calibration 84 | CC2500_FSCAL0 = 0x26, //Frequency synthesizer calibration 85 | CC2500_RCCTRL1 = 0x27, //RC oscillator configuration 86 | CC2500_RCCTRL0 = 0x28, //RC oscillator configuration 87 | CC2500_FSTEST = 0x29, //Frequency synthesizer calibration control 88 | CC2500_PTEST = 0x2A, //Production test 89 | CC2500_AGCTEST = 0x2B, //AGC test 90 | CC2500_TEST2 = 0x2C, //Various test settings 91 | CC2500_TEST1 = 0x2D, //Various test settings 92 | CC2500_TEST0 = 0x2E, //Various test settings 93 | CC2500_PATABLE = 0x3E, //table of 8 values 94 | CC2500_FIFO = 0x3F, //FIFO access 95 | }; 96 | 97 | enum cc2500_r_registers 98 | { 99 | CC2500_PARTNUM = 0xF0, //CC2500 part number 100 | CC2500_VERSION = 0xF1, //Current version number 101 | CC2500_FREQEST = 0xF2, //Frequency offset estimate 102 | CC2500_LQI = 0xF3, //Demodulator estimate for Link Quality 103 | CC2500_RSSI = 0xF4, //Received signal strength indication 104 | CC2500_MARCSTATE= 0xF5, //Control state machine state 105 | CC2500_WORTIME1 = 0xF6, //High byte of WOR timer 106 | CC2500_WORTIME0 = 0xF7, //Low byte of WOR timer 107 | CC2500_PKTSTATUS = 0xF8, //Current GDOx status and packet status 108 | CC2500_VCO_VC_DAC = 0xF9, //Current setting from PLL calibration module 109 | CC2500_TXBYTES = 0xFA, //Underflow and number of bytes in the TX FIFO 110 | CC2500_RXBYTES = 0xFB, //Overflow and number of bytes in the RX FIFO 111 | CC2500_RCCTRL1_STATUS = 0xFC, //Last RC oscillator calibration result 112 | CC2500_RCCTRL0_STATUS = 0xFD, //Last RC oscillator calibration result 113 | }; 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | #define CC2500_ACCESS_READ 0x80 130 | #define CC2500_ACCESS_WRITE 0x00 131 | #define CC2500_ACCESS_BURST 0x40 132 | 133 | #define FIFOTHR_FIFO_THR_pos 0 134 | #define FIFOTHR_FIFO_THR_msk (0xF<IDR,BIT(8))>>8); 390 | } 391 | 392 | inline uint8_t cc2500_read_GDO2(void) 393 | { 394 | return (bit_get(GPIOB->IDR,BIT(9))>>9); 395 | } 396 | 397 | #endif -------------------------------------------------------------------------------- /code/protocol.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Patrik Bachan 2 | // 3 | // GNU GENERAL PUBLIC LICENSE 4 | // Version 3, 29 June 2007 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | //most protocol knowledge was gathered from https://www.rcgroups.com/forums/showthread.php?1667453-DIY-FrSky-RX 20 | //thank you guys! 21 | 22 | #include "protocol.h" 23 | #include "cc2500.h" 24 | #include "misc.h" 25 | #include "flash.h" 26 | #include "uart.h" 27 | #include "timers.h" 28 | #include "adc.h" 29 | #include "hardware.h" 30 | #include "systick.h" 31 | 32 | uint8_t frsky_channel_data[FRSKY_CHANNEL_COUNT][4];//channel, FSCAL3, FSCAL2, FSCAL1 33 | 34 | union frsky_id 35 | { 36 | uint16_t id; 37 | struct 38 | { 39 | uint8_t low; 40 | uint8_t high; 41 | }nibble; 42 | }; 43 | 44 | union frsky_id frsky_tx_id={.id=0};//set default ID to 0, means not yet set 45 | //in fact, this id is id of link between RX and TX, TX requires same ID in telemetry packets 46 | 47 | //TODO: implement failsafe, output off for now 48 | uint16_t frsky_failsafe[PPM_OUTPUTS]={0}; 49 | 50 | //OFFSET CALIBRATION 51 | 52 | uint8_t *offset_cal_table; 53 | volatile int8_t offset_cal_table_idx; 54 | 55 | volatile enum offset_cal_status 56 | { 57 | FRSKY_OFFSET_CAL_FINISHED, 58 | FRSKY_OFFSET_CAL_WAITING, 59 | FRSKY_OFFSET_CAL_START, 60 | FRSKY_OFFSET_CAL_MEASURING, 61 | } offset_cal_status; 62 | 63 | void protocol_frsky_calibrate_offset_next(void) 64 | { 65 | swdt_stop(); 66 | if(offset_cal_status==FRSKY_OFFSET_CAL_START) 67 | { 68 | //first packet was received 69 | offset_cal_table_idx=INT8_MIN; 70 | offset_cal_status=FRSKY_OFFSET_CAL_MEASURING; 71 | uart_send_string_blocking("TX found, searching frequency offset...\n"); 72 | systick_blink_set(HARDWARE_LED_1, 0, SYSTICK_1s*0.2); 73 | } 74 | else 75 | { 76 | if(offset_cal_table_idxmax) 176 | max=offset_cal_table[(uint8_t)o]; 177 | 178 | uart_send_string_blocking("MAX RSSI: "); 179 | uart_send_string_blocking(itoa(max,3)); 180 | 181 | uart_send_byte_blocking('\n'); 182 | 183 | max=max/2;//set threshold to wind band of acceptable RSSIs 184 | 185 | //locate first RSSI above threshold from bottom 186 | int8_t bottom, top, mid; 187 | for(bottom=INT8_MIN; offset_cal_table[(uint8_t)bottom] 47 unique channels 291 | */ 292 | 293 | #define FRSKY_HOP_TABLE_COMPLETE 0x03FF //bitewise flags of received hop table groups 294 | #define FRSKY_HOP_TABLE_VALID 0xFFFF //signal to finish binding a continue in prg. exec. 295 | 296 | volatile uint16_t frsky_hop_channels=0; 297 | 298 | volatile uint8_t frsky_channel_index=0; 299 | 300 | void protocol_FRSKY_D_BIND_finished(void) 301 | { 302 | cc2500_strobe(CC2500_SIDLE);//stop RX 303 | cc2500_reset_callback(GDO0); 304 | uart_send_string_blocking("HOP sequence:\n"); 305 | for (uint8_t i = 0; i < FRSKY_CHANNEL_COUNT; i++) 306 | { 307 | uart_send_string_blocking(itoa(frsky_channel_data[i][0],4)); 308 | } 309 | frsky_hop_channels=FRSKY_HOP_TABLE_VALID; 310 | } 311 | 312 | void protocol_FRSKY_D_BIND_process_packet(void) 313 | { 314 | uint8_t packet[64]; 315 | cc2500_read_fifo(packet); 316 | uart_send_string_blocking("GRP:"); 317 | uart_send_string_blocking(itoa(packet[FRSKY_D_BIND_INX_HTI],3)); 318 | uart_send_string_blocking("LEN:"); 319 | uart_send_string_blocking(itoa(packet[FRSKY_D_BIND_INX_LENGTH],3)); 320 | uart_send_byte_blocking('\n'); 321 | uart_send_byte_blocking('\n'); 322 | //parse TX ID 323 | union frsky_id IDbuff; 324 | IDbuff.nibble.high=packet[FRSKY_D_BIND_INX_TX_ADDR_H]; 325 | IDbuff.nibble.low=packet[FRSKY_D_BIND_INX_TX_ADDR_L]; 326 | 327 | if(frsky_tx_id.id==0) 328 | { 329 | frsky_tx_id.id=IDbuff.id; 330 | frsky_hop_channels=0; 331 | uart_send_string_blocking("ID LEARNED\n"); 332 | } 333 | systick_blink_set(HARDWARE_LED_1, 1, SYSTICK_1s*0.1); 334 | 335 | if(frsky_tx_id.id==IDbuff.id) 336 | { 337 | if(frsky_hop_channels==FRSKY_HOP_TABLE_COMPLETE) 338 | protocol_FRSKY_D_BIND_finished(); 339 | else 340 | { 341 | //parse 342 | for(uint8_t index=0; index<5; index++) 343 | { 344 | uint8_t hti=packet[FRSKY_D_BIND_INX_HTI]; 345 | if(hti+index < FRSKY_CHANNEL_COUNT) 346 | frsky_channel_data[hti+index][0]=packet[FRSKY_D_BIND_INX_HOP1+index];//save channel number to channel config table 347 | } 348 | frsky_hop_channels|=(1<<(packet[FRSKY_D_BIND_INX_HTI]/5));//mark group as set 349 | } 350 | } 351 | 352 | } 353 | 354 | void protocol_frsky_bind(void) 355 | { 356 | uart_send_string_blocking("BINDING...\n"); 357 | frsky_tx_id.id=0;//protocol_FRSKY_D_BIND_process_packet will parse ID when frsky_tx_id.id==0 or matching non zero value -> clear value to zero 358 | frsky_hop_channels=0; 359 | cc2500_strobe(CC2500_SIDLE); 360 | cc2500_write_reg(CC2500_FIFOTHR, 7);//more bytes than correct packet in RXFIFO to trigger -> triggered only by correct packets received, this way, we have least false positive interrupts from cc2500 361 | cc2500_write_reg(CC2500_IOCFG0, 0x01);//GDO to indicate packet processing end (or RXFIFO threshold crossed) 362 | cc2500_write_reg(CC2500_ADDR, FRSKY_D_BIND_ADDRESS );//address in bind mode 363 | cc2500_set_channel(FRSKY_D_BIND_CHANNEL);//all binding happens on channel 0 :/ 364 | cc2500_strobe(CC2500_SCAL);//calibrate for this frequency (just for sure if no autocal enabled) 365 | delay_ms(1);//I hope it is enough, polling MARCSTATE fro IDLE state is the other way 366 | cc2500_set_callback(GDO0, RISING, protocol_FRSKY_D_BIND_process_packet, NOT_EMPTY);//set callback on GDO0 367 | cc2500_strobe(CC2500_SRX); 368 | 369 | led_on(HARDWARE_LED_2); 370 | systick_blink_stop(HARDWARE_LED_1); 371 | 372 | while(frsky_hop_channels!=FRSKY_HOP_TABLE_VALID) 373 | NOP; 374 | systick_blink_stop(HARDWARE_LED_1); 375 | systick_blink_stop(HARDWARE_LED_2); 376 | uart_send_string_blocking("BINDING finished!\n"); 377 | } 378 | 379 | //to avoid waiting for PLL settlement after every hop, precalibrate all channels, might be necessary to recalibrate during runtime 380 | void protocol_frsky_calibrate_channels(void) 381 | { 382 | 383 | cc2500_strobe(CC2500_SIDLE); 384 | uart_send_string_blocking("calibrating channels...\n"); 385 | 386 | cc2500_write_reg(CC2500_MCSM0, 0x08);//disable autocalibration 387 | for(uint8_t ch_index=0; ch_index=FRSKY_CHANNEL_COUNT) 414 | frsky_channel_index-=FRSKY_CHANNEL_COUNT; 415 | 416 | 417 | cc2500_write_reg(CC2500_CHANNR, frsky_channel_data[frsky_channel_index][0]);//set new channel 418 | //load precalibrated values 419 | cc2500_write_reg(CC2500_FSCAL3, frsky_channel_data[frsky_channel_index][1]);// & ~FSCAL3_CHP_CURR_CAL_EN_msk); //set calibrated value, but disable charge-pump calibration 420 | cc2500_write_reg(CC2500_FSCAL2, frsky_channel_data[frsky_channel_index][2]); 421 | cc2500_write_reg(CC2500_FSCAL1, frsky_channel_data[frsky_channel_index][3]); 422 | 423 | // uart_send_string_blocking("HOP:"); 424 | // uart_send_string_blocking(itoa(frsky_channel_data[frsky_channel_index][0],4)); 425 | // uart_send_byte_blocking('\n'); 426 | } 427 | 428 | //extract ppm data from packets 429 | void protocol_frsky_extract(uint8_t *packet,uint16_t *channel_buffer) 430 | { 431 | channel_buffer[0]=\ 432 | ((uint16_t)FRSKY_EXTRACT_LOWER(packet[FRSKY_D_RX_IDX_CH12_MSB])<<8)|\ 433 | ((uint16_t)packet[FRSKY_D_RX_IDX_CH1_LSB]); 434 | 435 | channel_buffer[1]=\ 436 | ((uint16_t)FRSKY_EXTRACT_HIGHER(packet[FRSKY_D_RX_IDX_CH12_MSB])<<8)|\ 437 | ((uint16_t)packet[FRSKY_D_RX_IDX_CH2_LSB]); 438 | 439 | channel_buffer[2]=\ 440 | ((uint16_t)FRSKY_EXTRACT_LOWER(packet[FRSKY_D_RX_IDX_CH34_MSB])<<8)|\ 441 | ((uint16_t)packet[FRSKY_D_RX_IDX_CH3_LSB]); 442 | 443 | channel_buffer[3]=\ 444 | ((uint16_t)FRSKY_EXTRACT_HIGHER(packet[FRSKY_D_RX_IDX_CH34_MSB])<<8)|\ 445 | ((uint16_t)packet[FRSKY_D_RX_IDX_CH4_LSB]); 446 | 447 | 448 | channel_buffer[4]=\ 449 | ((uint16_t)FRSKY_EXTRACT_LOWER(packet[FRSKY_D_RX_IDX_CH56_MSB])<<8)|\ 450 | ((uint16_t)packet[FRSKY_D_RX_IDX_CH5_LSB]); 451 | 452 | channel_buffer[5]=\ 453 | ((uint16_t)FRSKY_EXTRACT_HIGHER(packet[FRSKY_D_RX_IDX_CH56_MSB])<<8)|\ 454 | ((uint16_t)packet[FRSKY_D_RX_IDX_CH6_LSB]); 455 | 456 | channel_buffer[6]=\ 457 | ((uint16_t)FRSKY_EXTRACT_LOWER(packet[FRSKY_D_RX_IDX_CH78_MSB])<<8)|\ 458 | ((uint16_t)packet[FRSKY_D_RX_IDX_CH7_LSB]); 459 | 460 | channel_buffer[7]=\ 461 | ((uint16_t)FRSKY_EXTRACT_HIGHER(packet[FRSKY_D_RX_IDX_CH78_MSB])<<8)|\ 462 | ((uint16_t)packet[FRSKY_D_RX_IDX_CH8_LSB]); 463 | } 464 | 465 | //describes expected event 466 | volatile enum frsky_state 467 | { 468 | NOSYNC, 469 | RX_PKT1, 470 | RX_PKT2, 471 | RX_PKT3, 472 | TX_PKT, 473 | 474 | }frsky_state; 475 | 476 | volatile uint8_t frsky_last_rssi=0; 477 | 478 | void protocol_frsky_packet_send(void) 479 | { 480 | swdt_restart(FRSKY_D_TX_DELAY);//delay between RXED and TXING 481 | 482 | cc2500_strobe(CC2500_SIDLE); 483 | cc2500_strobe(CC2500_SFTX);//flush TX buffer, should not be necessary 484 | cc2500_strobe(CC2500_SFRX);//flush RX buffer, should not be necessary 485 | uint8_t packet[FRSKY_D_TX_LENGTH+1]={0}; 486 | 487 | packet[FRSKY_D_TX_IDX_LENGTH]=FRSKY_D_TX_LENGTH; 488 | packet[FRSKY_D_TX_IDX_TX_ADDR_H]=frsky_tx_id.nibble.high; 489 | packet[FRSKY_D_TX_IDX_TX_ADDR_L]=frsky_tx_id.nibble.low; 490 | packet[FRSKY_D_TX_IDX_A1]=adc_measure_single_blocking(4)>>4;//12bit ADC, but only 8bit data space :( 491 | packet[FRSKY_D_TX_IDX_A2]=adc_measure_single_blocking(5)>>4; 492 | packet[FRSKY_D_TX_IDX_RX_RSSI]=frsky_last_rssi/2; 493 | cc2500_write_fifo(packet, FRSKY_D_TX_LENGTH+1); 494 | } 495 | 496 | volatile uint8_t packets_lost=0; 497 | volatile uint8_t lna_state=0; 498 | 499 | void protocol_frsky_packet_send_finished(void)//called on TX end to switch back to RX mode 500 | { 501 | // cc2500_reset_callback(GDO2); 502 | protocol_frsky_hop(1);//hop to next channel where next RX packet arrives 503 | cc2500_mode_rx(lna_state);//switch to RX mode 504 | } 505 | 506 | 507 | void protocol_frsky_packet_rxed_callback(void) 508 | { 509 | uint8_t bytes=cc2500_read_reg(CC2500_RXBYTES); 510 | 511 | if(bytes!=FRSKY_D_RX_TOTAL_LENGTH) 512 | { 513 | if(bytes>FRSKY_D_RX_TOTAL_LENGTH) 514 | { 515 | cc2500_strobe(CC2500_SIDLE); 516 | cc2500_strobe(CC2500_SFRX); 517 | cc2500_mode_rx(0); 518 | } 519 | uart_send_string_blocking("LE: ");//packet length error 520 | uart_send_string_blocking(itoa(bytes,2)); 521 | uart_send_byte_blocking('\n'); 522 | return;//won't restart swdt, that will result as TimeOut 523 | } 524 | 525 | 526 | 527 | swdt_restart(FRSKY_PACKET_TIMEOUT); 528 | protocol_frsky_hop(1); 529 | packets_lost=0; 530 | 531 | 532 | uint8_t packet[64]; 533 | bytes = cc2500_read_fifo(packet); 534 | 535 | if( packet[FRSKY_D_RX_IDX_TX_ADDR_H]!=frsky_tx_id.nibble.high ||\ 536 | packet[FRSKY_D_RX_IDX_TX_ADDR_L]!=frsky_tx_id.nibble.low) 537 | { 538 | uart_send_string_blocking("TXID mismatch!\n"); 539 | //kinda WTF, packet passed address: test, CRC check, length check and second byte of address is not matching?! 540 | return;//won't restart swdt, that will result as TimeOut 541 | } 542 | 543 | //YAY! packet was probably valid, continue processing... 544 | led_off(HARDWARE_LED_1); 545 | led_on(HARDWARE_LED_2); 546 | switch (frsky_state) 547 | { 548 | //expected packet and we goot it 549 | case RX_PKT1: 550 | case RX_PKT2: 551 | case RX_PKT3: 552 | frsky_state++; 553 | break; 554 | 555 | case TX_PKT://telemetry packet should have been sent, but we got packet incomming, weird situation 556 | frsky_state=RX_PKT1; 557 | uart_send_string_blocking("RXed while TXing!\n"); 558 | break; 559 | 560 | case NOSYNC: 561 | break; 562 | } 563 | 564 | //sync state machine with packet from packet id 0,1,2,(3),4,5,6,(7),... 565 | uint8_t newstate=packet[FRSKY_D_RX_IDX_PKT_ID]%4 + RX_PKT1 +1; 566 | if(frsky_state != newstate) 567 | { 568 | // uart_send_string_blocking("Qs "); 569 | frsky_state = newstate; 570 | } 571 | 572 | frsky_last_rssi=(int16_t)(int8_t)packet[FRSKY_PKT_INX_RSSI(FRSKY_D_TX_LENGTH)]-INT8_MIN;//save RSSI value, we might need it in telemetry packet 573 | // uart_send_string_blocking("PKT: "); 574 | // uart_send_string_blocking(itoa(frsky_state-RX_PKT1,1)); 575 | // uart_send_byte_blocking(','); 576 | // uart_send_string_blocking(itoa(frsky_last_rssi,1)); 577 | // uart_send_byte_blocking(','); 578 | // uart_send_string_blocking(itoa(frsky_channel_data[frsky_channel_index][0],1)); 579 | // uart_send_byte_blocking('\n'); 580 | 581 | if(frsky_last_rssi > FRSKY_RSSI_MAX && lna_state!=0 )//disable LNA if RSSI gets too high (RX saturation) 582 | { 583 | lna_state=0; 584 | uart_send_string_blocking("LNA OFF\n"); 585 | } 586 | 587 | else if(frsky_last_rssi < FRSKY_RSSI_MIN && lna_state==0 )//enable LNA when RSSI is low enough 588 | { 589 | uart_send_string_blocking("LNA ON\n"); 590 | lna_state=1; 591 | } 592 | 593 | //set received data to ppm outputs 594 | uint16_t channels[8]; 595 | protocol_frsky_extract(packet, channels); 596 | 597 | ppm_set_ticks(FRSKY_1ms, FRSKY_2ms, channels); 598 | 599 | if(frsky_state==TX_PKT)//what we will expect as next event 600 | { 601 | protocol_frsky_packet_send();//sends telemetry packet after 3rx packet was received 602 | } 603 | else 604 | { 605 | cc2500_mode_rx(lna_state);//set correct LNA state and set cc2500 to RX mode 606 | } 607 | led_off(HARDWARE_LED_2); 608 | } 609 | 610 | //when packet does not arrive 611 | void protocol_frsky_packet_timeout_callback(void) 612 | { 613 | if(packets_lost>=FRSKY_PACKETS_LOST_RESYNC_THRESHOLD || frsky_state==NOSYNC) 614 | { 615 | if(frsky_state!=NOSYNC) 616 | { 617 | frsky_state=NOSYNC; 618 | ppm_set_ticks(FRSKY_1ms, FRSKY_2ms, frsky_failsafe); 619 | } 620 | protocol_frsky_hop(1); 621 | cc2500_mode_rx(1);//when we lost signal, turn on LNA 622 | uart_send_string_blocking("NOSYNC CH: "); 623 | uart_send_string_blocking(itoa(frsky_channel_data[frsky_channel_index][0], 3)); 624 | uart_send_byte_blocking('\n'); 625 | swdt_restart(FRSKY_CYCLE_TIMEOUT*3);//n times higher TO than full cycle to not run ahead/after TX and sync soon 626 | } 627 | else 628 | { 629 | switch(frsky_state) 630 | { 631 | //expected packet from TX, but nothing arrived in time 632 | case RX_PKT1: 633 | case RX_PKT2: 634 | case RX_PKT3: 635 | led_on(HARDWARE_LED_1); 636 | swdt_restart(FRSKY_PACKET_TIMEOUT);//schedule tomeout for next packet 637 | protocol_frsky_hop(1);//hop to nect channel to get ready for next packet 638 | cc2500_mode_rx(lna_state);//back to rx 639 | packets_lost++; 640 | uart_send_string_blocking("TO "); 641 | uart_send_string_blocking(itoa(frsky_state,2)); 642 | uart_send_string_blocking(itoa(frsky_channel_data[frsky_channel_index][0],4)); 643 | uart_send_string_blocking("\n"); 644 | break; 645 | 646 | case TX_PKT://time to send telemetry packet 647 | cc2500_mode_tx();//send prepaired packet 648 | swdt_restart(2*FRSKY_PACKET_TIMEOUT-FRSKY_D_TX_DELAY);//schedule next TO for next pkt, subtract time we waited before TXing 649 | cc2500_set_callback(GDO2, RISING, protocol_frsky_packet_send_finished, NONE); 650 | frsky_state=RX_PKT1; 651 | break; 652 | 653 | case NOSYNC: 654 | break; 655 | } 656 | } 657 | } 658 | 659 | void protocol_frsky_start(uint8_t force_bind) 660 | { 661 | systick_blink_stop(HARDWARE_LED_1); 662 | systick_blink_stop(HARDWARE_LED_2); 663 | protocol_frsky_init(); 664 | //read config from flash 665 | if( force_bind || protocol_frsky_read_nvm()<0 )//if no valid data found 666 | { 667 | protocol_frsky_calibrate_offset_start(); 668 | protocol_frsky_bind(); 669 | protocol_frsky_write_nvm(); 670 | systick_blink_set(HARDWARE_LED_1, 1, SYSTICK_1s); 671 | systick_blink_set(HARDWARE_LED_2, 1, SYSTICK_1s); 672 | delay_ms(1000); 673 | } 674 | else 675 | { 676 | uart_send_string_blocking("config LOADED\n"); 677 | } 678 | 679 | frsky_state=NOSYNC; 680 | cc2500_strobe(CC2500_SIDLE); 681 | protocol_frsky_calibrate_channels(); 682 | cc2500_write_reg(CC2500_ADDR, frsky_tx_id.nibble.high);//hw can check only 1 byte of 2 byte ID, second part is checked by SW (just for sure) 683 | cc2500_set_callback(GDO0, RISING, protocol_frsky_packet_rxed_callback, NOT_EMPTY);//set intterupt on falling edge of GDO0 684 | cc2500_write_reg(CC2500_FOCCFG, 0x16);//enable frequecy autotune 685 | cc2500_write_reg(CC2500_IOCFG0, 0x01);//goes high when packet is received (or RX fifo above threshold) 686 | cc2500_write_reg(CC2500_IOCFG2, 0x1B);//Powerdown signal for PA, that means packet was TXED 687 | cc2500_write_reg(CC2500_FIFOTHR, 7);//5 ~ 24+ bytes in RXFIFO to trigger -> troggered on pkt end only 688 | protocol_frsky_hop(0);//load channel config 689 | cc2500_mode_rx(1);//LNA state should not matter, will be tuned dynamically 690 | swdt_set_callback(protocol_frsky_packet_timeout_callback);//callback, when timeout occurs 691 | swdt_restart(FRSKY_CYCLE_TIMEOUT);//run! 692 | } 693 | 694 | 695 | 696 | void protocol_frsky_init(void) 697 | { 698 | cc2500_strobe(CC2500_SRES); 699 | delay_ms(2); 700 | cc2500_strobe(CC2500_SIDLE); 701 | cc2500_write_reg(CC2500_MCSM1, MCSM1_TXOFF_MODE_RX | MCSM1_RXOFF_MODE_RX); 702 | cc2500_write_reg(CC2500_MCSM0, 1< 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {project} Copyright (C) {year} {fullname} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------