diff options
Diffstat (limited to 'src/fsm')
-rw-r--r-- | src/fsm/fsm.c | 411 | ||||
-rw-r--r-- | src/fsm/fsm.h | 103 | ||||
-rw-r--r-- | src/fsm/pio.c | 147 | ||||
-rw-r--r-- | src/fsm/pio.h | 80 |
4 files changed, 0 insertions, 741 deletions
diff --git a/src/fsm/fsm.c b/src/fsm/fsm.c deleted file mode 100644 index 0c8cbed..0000000 --- a/src/fsm/fsm.c +++ /dev/null @@ -1,411 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2016 Matthias P. Braendli - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. -*/ - -#include <string.h> -#include "common.h" -#include "fsm.h" -#include "usart.h" - -static struct fsm_input_signals_t fsm_in; -static struct fsm_output_signals_t fsm_out; - -static fsm_state_t current_state; - -// Keep track of when we last entered a given state, measured -// in ms using the timestamp_now() function -static uint64_t timestamp_state[_NUM_FSM_STATES]; - -void fsm_init() { - memset(&fsm_in, 0, sizeof(fsm_in)); - memset(&fsm_out, 0, sizeof(fsm_out)); - - memset(timestamp_state, 0, _NUM_FSM_STATES * sizeof(*timestamp_state)); - timestamp_state[FSM_OISIF] = timestamp_now(); - - current_state = FSM_OISIF; -} - -// Calculate the time spent in the current state -uint64_t fsm_current_state_time_ms(void) { - return timestamp_now() - timestamp_state[current_state]; -} - -uint64_t fsm_current_state_time_s(void) { - return fsm_current_state_time_ms() / 1000; -} - -// Between turns in a QSO, the repeater sends a letter in CW, -// different messages are possible. They are sorted here from -// low to high priority. -const char* letter_all_ok = "K"; -const char* letter_sstv = "S"; -const char* letter_qrp = "G"; -const char* letter_freq_high = "U"; -const char* letter_freq_low = "D"; -const char* letter_swr_high = "R"; - -const char* fsm_select_letter(void) { - if (fsm_in.swr_high) { - return letter_swr_high; - } - else if (fsm_in.discrim_d) { - return letter_freq_low; - } - else if (fsm_in.discrim_u) { - return letter_freq_high; - } - else if (fsm_in.qrp) { - return letter_qrp; - } - else if (fsm_in.sstv_mode) { - return letter_sstv; - } - - return letter_all_ok; -} - -void fsm_update() { - - fsm_state_t next_state = current_state; - - // Some defaults for the outgoing signals - fsm_out.tx_on = 0; - fsm_out.modulation = 0; - fsm_out.cw_psk31_trigger = 0; - fsm_out.cw_dit_duration = 50; - fsm_out.msg_frequency = 960; - // other output signals keep their value - - switch (current_state) { - case FSM_OISIF: - if (fsm_in.tone_1750 && fsm_in.sq) { - next_state = FSM_OPEN1; - } - else if (fsm_in.start_tm) { - if (fsm_in.qrp || fsm_in.swr_high) { - next_state = FSM_BALISE_SPECIALE; - } - else { - next_state = FSM_BALISE_LONGUE; - } - } - else if (!fsm_in.qrp && fsm_current_state_time_s() > 20 * 60) { - next_state = FSM_BALISE_COURTE; - } - break; - - case FSM_OPEN1: - fsm_out.tx_on = 1; - - if (!fsm_in.sq) { - next_state = FSM_OPEN2; - } - break; - - case FSM_OPEN2: - fsm_out.tx_on = 1; - fsm_out.modulation = 1; - - if (fsm_current_state_time_ms() > 200) { - next_state = FSM_LETTRE; - } - break; - - case FSM_LETTRE: - fsm_out.tx_on = 1; - fsm_out.modulation = 1; - fsm_out.msg = fsm_select_letter(); - if (fsm_out.msg[0] == 'G') { - // The letter 'G' is a bit different - fsm_out.msg_frequency = 696; - fsm_out.cw_dit_duration = 70; - } - fsm_out.cw_psk31_trigger = 1; - - if (fsm_in.cw_psk31_done) { - next_state = FSM_ECOUTE; - } - break; - - case FSM_ECOUTE: - fsm_out.tx_on = 1; - fsm_out.modulation = 1; - - if (fsm_in.sq) { - next_state = FSM_QSO; - } - else if (fsm_current_state_time_s() > 6 && - timestamp_state[FSM_ECOUTE] - timestamp_state[FSM_OPEN2] < - 1000ul * 5) { - next_state = FSM_ATTENTE; - } - else if (fsm_current_state_time_s() > 5 && - timestamp_state[FSM_ECOUTE] - timestamp_state[FSM_OPEN2] < - 1000ul * 5 * 60) { - next_state = FSM_OISIF; - } - else if (fsm_current_state_time_s() > 5 && - timestamp_state[FSM_ECOUTE] - timestamp_state[FSM_OPEN2] < - 1000ul * 10 * 60) { - next_state = FSM_TEXTE_73; - } - else if (fsm_current_state_time_s() > 5 && - timestamp_state[FSM_ECOUTE] - timestamp_state[FSM_OPEN2] < - 1000ul * 15 * 60) { - next_state = FSM_TEXTE_HB9G; - } - else if (fsm_current_state_time_s() > 5 && - timestamp_state[FSM_ECOUTE] - timestamp_state[FSM_OPEN2] >= - 1000ul * 15 * 60) { - next_state = FSM_TEXTE_LONG; - } - break; - - case FSM_ATTENTE: - if (fsm_in.sq) { - next_state = FSM_ECOUTE; - } - else if (fsm_current_state_time_s() > 15) { - next_state = FSM_OISIF; - } - break; - - case FSM_QSO: - fsm_out.tx_on = 1; - fsm_out.modulation = 1; - - if (!fsm_in.sq) { - next_state = FSM_LETTRE; - } - else if (fsm_current_state_time_s() > 5 * 60) { - next_state = FSM_ANTI_BAVARD; - } - break; - - case FSM_ANTI_BAVARD: - fsm_out.tx_on = 1; - // No modulation! - fsm_out.msg = "HI HI"; - fsm_out.cw_psk31_trigger = 1; - - if (fsm_in.cw_psk31_done) { - next_state = FSM_BLOQUE; - } - break; - - case FSM_BLOQUE: - if (fsm_current_state_time_s() > 10) { - next_state = FSM_OISIF; - } - break; - - case FSM_TEXTE_73: - fsm_out.tx_on = 1; - fsm_out.modulation = 1; - fsm_out.msg_frequency = 696; - fsm_out.cw_dit_duration = 70; - fsm_out.msg = "73"; - fsm_out.cw_psk31_trigger = 1; - - if (fsm_in.sq) { - next_state = FSM_QSO; - } - else if (fsm_in.cw_psk31_done) { - next_state = FSM_OISIF; - } - break; - - case FSM_TEXTE_HB9G: - fsm_out.tx_on = 1; - fsm_out.modulation = 1; - fsm_out.msg_frequency = 696; - fsm_out.cw_dit_duration = 70; - fsm_out.msg = "HB9G"; - fsm_out.cw_psk31_trigger = 1; - - if (fsm_in.sq) { - next_state = FSM_QSO; - } - else if (fsm_in.cw_psk31_done) { - next_state = FSM_OISIF; - } - break; - - case FSM_TEXTE_LONG: - fsm_out.tx_on = 1; - fsm_out.modulation = 1; - - fsm_out.msg_frequency = 696; - fsm_out.cw_dit_duration = 70; - - if (random_bool()) { - fsm_out.msg = "HB9G 1628M"; - } - else { - fsm_out.msg = "HB9G JN36BK"; - } - fsm_out.cw_psk31_trigger = 1; - - if (fsm_in.sq) { - next_state = FSM_QSO; - } - else if (fsm_in.cw_psk31_done) { - next_state = FSM_OISIF; - } - break; - - case FSM_BALISE_LONGUE: - fsm_out.tx_on = 1; - fsm_out.msg_frequency = 588; - fsm_out.cw_dit_duration = 110; - fsm_out.ack_start_tm = 1; - - // TODO transmit humidity - // TODO read voltage - if (fsm_in.wind_generator_ok) { - fsm_out.msg = "HB9G JN36BK 1628M U 10V5 = T 11 73"; - // = means same voltage as previous - // + means higher - // - means lower - } - else { - fsm_out.msg = "HB9G JN36BK 1628M U 10V5 = T 11 #"; - // The # is the SK digraph - } - fsm_out.cw_psk31_trigger = 1; - - if (fsm_in.cw_psk31_done) { - next_state = FSM_OISIF; - } - break; - - case FSM_BALISE_SPECIALE: - fsm_out.tx_on = 1; - fsm_out.msg_frequency = 696; - fsm_out.cw_dit_duration = 70; - fsm_out.ack_start_tm = 1; - - // TODO read voltage - if (fsm_in.wind_generator_ok) { - fsm_out.msg = "HB9G U 10V5 73"; - } - else { - fsm_out.msg = "HB9G U 10V5 #"; // The # is the SK digraph - } - fsm_out.cw_psk31_trigger = 1; - - if (fsm_in.cw_psk31_done) { - next_state = FSM_OISIF; - } - break; - - case FSM_BALISE_COURTE: - fsm_out.tx_on = 1; - - fsm_out.msg_frequency = 696; - fsm_out.cw_dit_duration = 70; - - { - int rand = random_bool() * 2 + random_bool(); - - if (rand == 0) { - fsm_out.msg = "HB9G"; - } - else if (rand == 1) { - fsm_out.msg = "HB9G JN36BK"; - } - else if (rand == 2) { - fsm_out.msg = "HB9G 1628M"; - } - else { - fsm_out.msg = "HB9G JN36BK 1628M"; - } - } - fsm_out.cw_psk31_trigger = 1; - - if (fsm_in.sq) { - next_state = FSM_OPEN2; - } - else if (fsm_in.cw_psk31_done) { - next_state = FSM_OISIF; - } - break; - default: - // Should never happen - next_state = FSM_OISIF; - break; - } - - - if (next_state != current_state) { - timestamp_state[next_state] = timestamp_now(); - switch (next_state) { - case FSM_OISIF: - usart_debug_puts("FSM: FSM_OISIF\r\n"); break; - case FSM_OPEN1: - usart_debug_puts("FSM: FSM_OPEN1\r\n"); break; - case FSM_OPEN2: - usart_debug_puts("FSM: FSM_OPEN2\r\n"); break; - case FSM_LETTRE: - usart_debug_puts("FSM: FSM_LETTRE\r\n"); break; - case FSM_ECOUTE: - usart_debug_puts("FSM: FSM_ECOUTE\r\n"); break; - case FSM_ATTENTE: - usart_debug_puts("FSM: FSM_ATTENTE\r\n"); break; - case FSM_QSO: - usart_debug_puts("FSM: FSM_QSO\r\n"); break; - case FSM_ANTI_BAVARD: - usart_debug_puts("FSM: FSM_ANTI_BAVARD\r\n"); break; - case FSM_BLOQUE: - usart_debug_puts("FSM: FSM_BLOQUE\r\n"); break; - case FSM_TEXTE_73: - usart_debug_puts("FSM: FSM_TEXTE_73\r\n"); break; - case FSM_TEXTE_HB9G: - usart_debug_puts("FSM: FSM_TEXTE_HB9G\r\n"); break; - case FSM_TEXTE_LONG: - usart_debug_puts("FSM: FSM_TEXTE_LONG\r\n"); break; - case FSM_BALISE_LONGUE: - usart_debug_puts("FSM: FSM_BALISE_LONGUE\r\n"); break; - case FSM_BALISE_SPECIALE: - usart_debug_puts("FSM: FSM_BALISE_SPECIALE\r\n"); break; - case FSM_BALISE_COURTE: - usart_debug_puts("FSM: FSM_BALISE_COURTE\r\n"); break; - default: - usart_debug_puts("FSM: ERROR!\r\n"); break; - } - } - current_state = next_state; -} - -void fsm_update_inputs(struct fsm_input_signals_t* inputs) -{ - fsm_in = *inputs; -} - -void fsm_get_outputs(struct fsm_output_signals_t* out) -{ - *out = fsm_out; -} - - diff --git a/src/fsm/fsm.h b/src/fsm/fsm.h deleted file mode 100644 index 41f0503..0000000 --- a/src/fsm/fsm.h +++ /dev/null @@ -1,103 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2016 Matthias P. Braendli - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. -*/ - -#ifndef _FSM_H_ -#define _FSM_H_ - -// List of all states the FSM of the relay can be in -enum fsm_state_e { - FSM_OISIF = 0, // Idle - FSM_OPEN1, // 1750 Hz received and squelch open - FSM_OPEN2, // Squelch closed - FSM_LETTRE, // Transmit single status letter - FSM_ECOUTE, // Repeater open, waiting for QSO - FSM_ATTENTE, // No QSO after a short while - FSM_QSO, // QSO ongoing - FSM_ANTI_BAVARD, // QSO too long, cut transmission - FSM_BLOQUE, // Backoff after ANTI_BAVARD - FSM_TEXTE_73, // Transmit 73 after QSO - FSM_TEXTE_HB9G, // Transmit HB9G after QSO - FSM_TEXTE_LONG, // Transmit either HB9G JN36BK or HB9G 1628M after QSO - FSM_BALISE_LONGUE, // Full-length 2-hour beacon - FSM_BALISE_SPECIALE, // 2-hour beacon when in QRP or with high power return mode - FSM_BALISE_COURTE, // Short intermittent beacon - _NUM_FSM_STATES // Dummy state to count the number of states -}; - -typedef enum fsm_state_e fsm_state_t; - -// All signals that the FSM can read, most of them are actually booleans -struct fsm_input_signals_t { - /* Signals coming from repeater electronics */ - int sq; // Squelch detection - int discrim_u; // FM discriminator says RX is too high in frequency - int qrp; // The relay is currently running with low power - int start_tm; // 2-hour pulse - float temp; // temperature in degrees C - float humidity; // relative humidity, range [0-100] % - int wind_generator_ok; // false if the generator is folded out of the wind - int discrim_d; // FM discriminator says RX is too low in frequency - int tone_1750; // Detect 1750Hz tone - int sstv_mode; // The 1750Hz filter is disabled, permitting SSTV usage - - /* Signals coming from CW and PSK generator */ - int cw_psk31_done; // The CW and PSK generator has finished transmitting the message - - /* Signal coming from the standing wave ratio meter */ - int swr_high; // We see a lot of return power - -}; - -// All signals the FSM has to control -struct fsm_output_signals_t { - /* Signals to the repeater electronics */ - int qrp; // Place the repeater in QRP mode // TODO move out of FSM - int tx_on; // Enable TX circuitry - int modulation; // Enable repeater RX to TX modulation - - /* Signals to the CW and PSK generator */ - const char* msg; // The message to transmit - int msg_frequency; // What audio frequency for the CW or PSK message - int cw_dit_duration; // CW speed, dit duration in ms - int cw_psk31_trigger; // Set to true to trigger a CW or PSK31 transmission. - // PSK31 is sent if cw_dit_duration is 0 - - /* Acknowledgements for input signals */ - int ack_start_tm; // Set to 1 to clear start_tm -}; - -// Initialise local structures -void fsm_init(); - -// Call the FSM once and update the internal state -void fsm_update(); - -// Setter for inputs -void fsm_update_inputs(struct fsm_input_signals_t* inputs); - -// Getter for outputs -void fsm_get_outputs(struct fsm_output_signals_t* out); - -#endif // _FSM_H_ - diff --git a/src/fsm/pio.c b/src/fsm/pio.c deleted file mode 100644 index 2ff5447..0000000 --- a/src/fsm/pio.c +++ /dev/null @@ -1,147 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2015 Matthias P. Braendli - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. -*/ - -#include "pio.h" -#include "common.h" -#include "FreeRTOS.h" -#include "task.h" -#include "queue.h" -#include "semphr.h" - -void read_fsm_input_task(void *pvParameters); - -struct fsm_input_signals_t pio_signals; - -void pio_init() -{ - GPIO_InitTypeDef GPIO_InitStructure; - - // Init pio - RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE); - - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; - GPIO_InitStructure.GPIO_Pin = GPIOC_OUTPUT_PINS; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; - GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; - GPIO_Init(GPIOC, &GPIO_InitStructure); - -#if defined(GPIOC_OPENDRAIN_PINS) - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; - GPIO_InitStructure.GPIO_Pin = GPIOC_OPENDRAIN_PINS; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; - GPIO_InitStructure.GPIO_OType = GPIO_OType_OD; - GPIO_Init(GPIOC, &GPIO_InitStructure); -#endif - -#if defined(GPIOC_INPUT_PU_PINS) - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; - GPIO_InitStructure.GPIO_Pin = GPIOC_INPUT_PU_PINS; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; - GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; - GPIO_Init(GPIOC, &GPIO_InitStructure); -#endif - -#if defined(GPIOC_INPUT_PINS) - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; - GPIO_InitStructure.GPIO_Pin = GPIOC_INPUT_PINS; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; - GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; - GPIO_Init(GPIOC, &GPIO_InitStructure); -#endif - - xTaskCreate( - read_fsm_input_task, - "TaskPIO", - configMINIMAL_STACK_SIZE, - (void*) NULL, - tskIDLE_PRIORITY + 2UL, - NULL); -} - -void pio_set_fsm_signals(struct fsm_input_signals_t* sig) -{ - *sig = pio_signals; -} - -void read_fsm_input_task(void *pvParameters) -{ - while (1) { - pio_signals.qrp = - GPIO_ReadInputDataBit(GPIOC, GPIO_PIN_QRP_n) ? 0 : 1; - - pio_signals.tone_1750 = - GPIO_ReadInputDataBit(GPIOC, GPIO_PIN_1750_n) ? 0 : 1; - - pio_signals.sq = - GPIO_ReadInputDataBit(GPIOC, GPIO_PIN_SQ_n) ? 0 : 1; - - pio_signals.discrim_u = - GPIO_ReadInputDataBit(GPIOC, GPIO_PIN_U) ? 1 : 0; - - pio_signals.discrim_d = - GPIO_ReadInputDataBit(GPIOC, GPIO_PIN_D) ? 1 : 0; - - pio_signals.wind_generator_ok = - GPIO_ReadInputDataBit(GPIOC, GPIO_PIN_REPLIE_n) ? 1 : 0; - - pio_signals.sstv_mode = - GPIO_ReadInputDataBit(GPIOC, GPIO_PIN_FAX_n) ? 0 : 1; - - vTaskDelay(100 / portTICK_RATE_MS); - } -} - -void pio_set_tx(int on) -{ - if (on) { - GPIO_SetBits(GPIOC, GPIO_PIN_TX); - } - else { - GPIO_ResetBits(GPIOC, GPIO_PIN_TX); - } -} - -void pio_set_qrp(int on) -{ - if (on) { - GPIO_SetBits(GPIOC, GPIO_PIN_QRP_out); - } - else { - GPIO_ResetBits(GPIOC, GPIO_PIN_QRP_out); - } -} - -void pio_set_mod_off(int mod_off) -{ - if (mod_off) { - GPIO_SetBits(GPIOC, GPIO_PIN_MOD_OFF); - } - else { - GPIO_ResetBits(GPIOC, GPIO_PIN_MOD_OFF); - } -} diff --git a/src/fsm/pio.h b/src/fsm/pio.h deleted file mode 100644 index 9e7d4fb..0000000 --- a/src/fsm/pio.h +++ /dev/null @@ -1,80 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2015 Matthias P. Braendli - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. -*/ - -#ifndef _PIO_H_ -#define _PIO_H_ - -#include <stddef.h> -#include <stdint.h> -#include "fsm.h" -#include "stm32f4xx_rcc.h" -#include "stm32f4xx_gpio.h" - -/* See pio.txt for PIO allocation details */ - -/* On GPIO C */ -#define GPIO_PIN_QRP_n GPIO_Pin_1 -#define GPIO_PIN_TX GPIO_Pin_2 -#define GPIO_PIN_1750_n GPIO_Pin_4 -#define GPIO_PIN_MOD_OFF GPIO_Pin_5 -#define GPIO_PIN_SQ_n GPIO_Pin_6 -#define GPIO_PIN_U GPIO_Pin_8 -#define GPIO_PIN_QRP_out GPIO_Pin_9 -#define GPIO_PIN_D GPIO_Pin_11 -#define GPIO_PIN_REPLIE_n GPIO_Pin_13 -#define GPIO_PIN_FAX_n GPIO_Pin_14 - - -#define GPIOC_OUTPUT_PINS ( \ - GPIO_PIN_TX | \ - GPIO_PIN_MOD_OFF | \ - GPIO_PIN_QRP_out | \ - 0) - -#undef GPIOC_OPENDRAIN_PINS -#undef GPIOC_INPUT_PU_PINS - -#define GPIOC_INPUT_PINS ( \ - GPIO_PIN_QRP_n | \ - GPIO_PIN_1750_n | \ - GPIO_PIN_SQ_n | \ - GPIO_PIN_U | \ - GPIO_PIN_D | \ - GPIO_PIN_REPLIE_n | \ - 0 ) - -/* Analog inputs */ -// TODO: SWR forward power -// TODO: SWR reflected power - -void pio_init(void); - -void pio_set_tx(int on); -void pio_set_mod_off(int mod_off); -void pio_set_qrp(int on); - -void pio_set_fsm_signals(struct fsm_input_signals_t* sig); - -#endif // _PIO_H_ - |