| 
									
										
										
										
											2018-06-18 22:47:50 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |     Aerospace Decoder - Copyright (C) 2018 Bob Anderson (VK2GJ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Unless required by applicable law or agreed to in writing, software | 
					
						
							|  |  |  |     distributed under the License is distributed on an "AS IS" BASIS, | 
					
						
							|  |  |  |     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * @file    portab.c | 
					
						
							|  |  |  |  * @brief   Application portability module code. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @addtogroup application_portability | 
					
						
							|  |  |  |  * @{ | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "hal.h"
 | 
					
						
							|  |  |  | #include "chprintf.h"
 | 
					
						
							|  |  |  | #include "pkttypes.h"
 | 
					
						
							|  |  |  | #include "portab.h"
 | 
					
						
							|  |  |  | #include "usb.h"
 | 
					
						
							|  |  |  | #include "types.h"
 | 
					
						
							|  |  |  | #include <stdarg.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*===========================================================================*/ | 
					
						
							|  |  |  | /* Module local definitions.                                                 */ | 
					
						
							|  |  |  | /*===========================================================================*/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const radio_band_t band_2m = { | 
					
						
							|  |  |  |   .start    = BAND_MIN_2M_FREQ, | 
					
						
							|  |  |  |   .end      = BAND_MAX_2M_FREQ, | 
					
						
							|  |  |  |   .step     = BAND_STEP_2M_HZ, | 
					
						
							|  |  |  |   .def_aprs = BAND_DEF_2M_APRS | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const radio_band_t band_70cm = { | 
					
						
							|  |  |  |   .start    = BAND_MIN_70CM_FREQ, | 
					
						
							|  |  |  |   .end      = BAND_MAX_70CM_FREQ, | 
					
						
							|  |  |  |   .step     = BAND_STEP_70CM_HZ, | 
					
						
							|  |  |  |   .def_aprs = BAND_DEF_70CM_APRS | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*===========================================================================*/ | 
					
						
							|  |  |  | /* Module exported variables.                                                */ | 
					
						
							|  |  |  | /*===========================================================================*/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | typedef struct SysProviders { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } providers_t; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-25 14:00:15 +00:00
										 |  |  | const radio_config_t radio_list[] = { | 
					
						
							| 
									
										
										
										
											2018-06-18 22:47:50 +00:00
										 |  |  |   { /* Radio #1 */ | 
					
						
							|  |  |  |     .unit = PKT_RADIO_1, | 
					
						
							|  |  |  |     .type = SI4464, | 
					
						
							|  |  |  |     .band = { | 
					
						
							|  |  |  |              (radio_band_t * const)&band_2m, | 
					
						
							|  |  |  |               NULL | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2018-06-25 14:00:15 +00:00
										 |  |  |   }, /* End radio1 */ | 
					
						
							| 
									
										
										
										
											2018-06-26 23:32:39 +00:00
										 |  |  |   { | 
					
						
							|  |  |  |      .unit = PKT_RADIO_NONE | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-06-18 22:47:50 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const SerialConfig debug_config = { | 
					
						
							|  |  |  |   115200, | 
					
						
							|  |  |  |   0, | 
					
						
							|  |  |  |   0, | 
					
						
							|  |  |  |   0 | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*===========================================================================*/ | 
					
						
							|  |  |  | /* Module local types.                                                       */ | 
					
						
							|  |  |  | /*===========================================================================*/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*===========================================================================*/ | 
					
						
							|  |  |  | /* Module local variables.                                                   */ | 
					
						
							|  |  |  | /*===========================================================================*/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*===========================================================================*/ | 
					
						
							|  |  |  | /* Module local functions.                                                   */ | 
					
						
							|  |  |  | /*===========================================================================*/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*===========================================================================*/ | 
					
						
							|  |  |  | /* Module exported functions.                                                */ | 
					
						
							|  |  |  | /*===========================================================================*/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void pktConfigSerialDiag(void) { | 
					
						
							| 
									
										
										
										
											2018-06-21 14:57:31 +00:00
										 |  |  | #if ENABLE_EXTERNAL_I2C == FALSE
 | 
					
						
							| 
									
										
										
										
											2018-06-18 22:47:50 +00:00
										 |  |  |   /* USART3 TX.       */ | 
					
						
							|  |  |  |   palSetLineMode(LINE_USART3_TX, PAL_MODE_ALTERNATE(7)); | 
					
						
							|  |  |  |   /* USART3 RX.       */ | 
					
						
							|  |  |  |   palSetLineMode(LINE_USART3_RX, PAL_MODE_ALTERNATE(7)); | 
					
						
							| 
									
										
										
										
											2018-06-21 14:57:31 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2018-06-18 22:47:50 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void pktConfigSerialPkt(void) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-25 14:00:15 +00:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Get number of radios for this board type. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | uint8_t pktGetNumRadios(void) { | 
					
						
							|  |  |  |   uint8_t i = 0; | 
					
						
							|  |  |  |   while(radio_list[i++].unit != PKT_RADIO_NONE); | 
					
						
							|  |  |  |   return --i; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * Return pointer to radio object array. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | const radio_config_t *pktGetRadioList(void) { | 
					
						
							|  |  |  |   return radio_list; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-18 22:47:50 +00:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * TODO: Move this into pktconf.h and use general GPIO to setup. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | void pktSetLineModeICU(void) { | 
					
						
							|  |  |  |   palSetLineMode(LINE_ICU, PAL_MODE_INPUT | PAL_MODE_ALTERNATE(2)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * Read GPIO that are used for: | 
					
						
							|  |  |  |  * a) general use or | 
					
						
							|  |  |  |  * b) UART and s/w I2C external. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @return State of lines regardless of general or specific use. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | uint8_t pktReadIOlines() { | 
					
						
							|  |  |  |   return palReadLine(LINE_GPIO_PIN) | 
					
						
							|  |  |  |       | palReadLine(LINE_IO_TXD) << 1 | 
					
						
							|  |  |  |       | palReadLine(LINE_IO_RXD) << 2; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void pktSerialStart(void) { | 
					
						
							|  |  |  | #if ENABLE_EXTERNAL_I2C == FALSE
 | 
					
						
							|  |  |  |   pktConfigSerialDiag(); | 
					
						
							|  |  |  |   pktConfigSerialPkt(); | 
					
						
							|  |  |  |   sdStart(SERIAL_CFG_DEBUG_DRIVER, &debug_config); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  |   /* Setup diagnostic resource access semaphore. */ | 
					
						
							|  |  |  |   extern binary_semaphore_t diag_out_sem; | 
					
						
							|  |  |  |   chBSemObjectInit(&diag_out_sem, false); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void dbgWrite(uint8_t level, uint8_t *buf, uint32_t len) { | 
					
						
							|  |  |  |   (void)level; | 
					
						
							|  |  |  | #if ENABLE_EXTERNAL_I2C == FALSE
 | 
					
						
							|  |  |  |   chnWrite((BaseSequentialStream*)SERIAL_CFG_DEBUG_DRIVER, buf, len); | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  |   (void)buf; | 
					
						
							|  |  |  |   (void)len; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int dbgPrintf(uint8_t level, const char *format, ...) { | 
					
						
							|  |  |  |   (void)level; | 
					
						
							|  |  |  | #if ENABLE_EXTERNAL_I2C == FALSE
 | 
					
						
							|  |  |  |   va_list arg; | 
					
						
							|  |  |  |   int done; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   va_start(arg, format); | 
					
						
							|  |  |  |   done = chprintf((BaseSequentialStream*)SERIAL_CFG_DEBUG_DRIVER, format, arg); | 
					
						
							|  |  |  |   va_end(arg); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return done; | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  |   (void)format; | 
					
						
							|  |  |  |   return 0; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void pktWrite(uint8_t *buf, uint32_t len) { | 
					
						
							|  |  |  |   chnWrite((BaseSequentialStream*)SERIAL_CFG_DEBUG_DRIVER, buf, len); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-04 14:15:00 +00:00
										 |  |  | void pktConfigureCoreIO(void) { | 
					
						
							| 
									
										
										
										
											2018-06-18 22:47:50 +00:00
										 |  |  |   /* Setup SPI3. */ | 
					
						
							|  |  |  |   palSetLineMode(LINE_SPI_SCK, PAL_MODE_ALTERNATE(6) | 
					
						
							|  |  |  |                  | PAL_STM32_OSPEED_HIGHEST);     // SCK
 | 
					
						
							|  |  |  |   palSetLineMode(LINE_SPI_MISO, PAL_MODE_ALTERNATE(6) | 
					
						
							|  |  |  |                  | PAL_STM32_OSPEED_HIGHEST);    // MISO
 | 
					
						
							|  |  |  |   palSetLineMode(LINE_SPI_MOSI, PAL_MODE_ALTERNATE(6) | 
					
						
							|  |  |  |                  | PAL_STM32_OSPEED_HIGHEST);    // MOSI
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* Setup I2C1. */ | 
					
						
							|  |  |  |   palSetLineMode(LINE_I2C_SDA, PAL_MODE_ALTERNATE(4) | 
					
						
							|  |  |  |                  | PAL_STM32_OSPEED_HIGHEST | 
					
						
							|  |  |  |                  | PAL_STM32_OTYPE_OPENDRAIN); // SDA
 | 
					
						
							|  |  |  |   palSetLineMode(LINE_I2C_SCL, PAL_MODE_ALTERNATE(4) | 
					
						
							|  |  |  |                  | PAL_STM32_OSPEED_HIGHEST | 
					
						
							|  |  |  |                  | PAL_STM32_OTYPE_OPENDRAIN); // SCL
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   #if ACTIVATE_USB
 | 
					
						
							|  |  |  |   startUSB(); | 
					
						
							|  |  |  |   #endif
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * Return a single radio parameter record pointer | 
					
						
							|  |  |  |  * The radio parameter picks a single records. | 
					
						
							|  |  |  |  * The current system does not work if the same radio is listed multiple times. | 
					
						
							|  |  |  |  * TODO: Have an enumeration and check radio array on startup. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | radio_config_t *pktGetRadioParameters(radio_unit_t radio) { | 
					
						
							|  |  |  |   (void)radio; | 
					
						
							|  |  |  |   return NULL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** @} */ | 
					
						
							|  |  |  | 
 |