Changeset - 041562172b4a
[Not reviewed]
default
0 4 0
Ethan Zonca (ethanzonca) - 9 years ago 2017-01-12 09:16:48
e@ethanzonca.com
Doubleinit radio for guaranteed init; GPS fixes
4 files changed with 23 insertions and 49 deletions:
0 comments (0 inline, 0 general)
Libraries/Si446x/si446x.c
Show inline comments
 
//
 
// Si446x: Initializes and configures a Si446x transceiver over SPI
 
//
 
 
#include "stm32f0xx_hal.h"
 
 
#include "si446x.h"
 
#include "config.h"
 
#include "error.h"
 
#include "system/gpio.h"
 
#include "system/sysclk.h"
 
 
 
// Private variables
 
static SPI_HandleTypeDef hspi1;
 
static uint8_t si446x_cw_status = 0;
 
 
 
// Private function prototypes
 
static void __init_spi1(void);
 
 
 
// Initialize Si446x in 2FSK transmit mode
 
void si446x_init(void)
 
{
 
	// init spi port
 
	__init_spi1();
 
 
	GPIO_InitTypeDef GPIO_InitStruct;
 
 
	// GPIO: TCXO control
 
	GPIO_InitStruct.Pin = SI446x_TCXO_EN_PIN;
 
	GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
 
	GPIO_InitStruct.Pull = GPIO_NOPULL;
 
	HAL_GPIO_Init(SI446x_TCXO_EN_PORT, &GPIO_InitStruct);
 
	HAL_GPIO_WritePin(SI446x_TCXO_EN_PORT, SI446x_TCXO_EN_PIN, 1);
 
 
	// GPIO: VHF radio shutdown control
 
	GPIO_InitStruct.Pin = SI446x_SHUTDOWN_PIN;
 
	GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
 
	GPIO_InitStruct.Pull = GPIO_NOPULL;
 
	HAL_GPIO_Init(SI446x_SHUTDOWN_PORT, &GPIO_InitStruct);
 
 
	// Perform PoR (takes 20ms) and turn device on
 
	si446x_reset();
 
	si446x_reset();
 
 
    // Divide SI446x_VCXO_FREQ into its bytes; MSB first
 
    uint16_t x3 = SI446x_VCXO_FREQ / 0x1000000;
 
    uint16_t x2 = (SI446x_VCXO_FREQ - x3 * 0x1000000) / 0x10000;
 
    uint16_t x1 = (SI446x_VCXO_FREQ - x3 * 0x1000000 - x2 * 0x10000) / 0x100;
 
    uint16_t x0 = (SI446x_VCXO_FREQ - x3 * 0x1000000 - x2 * 0x10000 - x1 * 0x100);
 
 
    // Power up radio module                          boot  xtal  _XO_frequency_
 
 
    //TCXO
 
    const char init_command[] = {SI446x_CMD_POWER_UP, 0x01, 0x01, x3, x2, x1, x0};
 
    si446x_sendcmd(7, init_command, SI446x_CHECK_ACK);
 
 
    HAL_Delay(10);
 
 
	// Change to SPI Ready state EMZ added for re-init, might help on startup
 
	uint8_t change_state_commanda[] = {SI446x_CMD_CHANGE_STATE, 0x02}; //  Change to spi ready
 
    si446x_sendcmd(2, change_state_commanda, SI446x_CHECK_ACK);
 
    HAL_Delay(10);
 
 
    // Radio ready: clear all pending interrupts and get the interrupt status back
 
	uint8_t get_int_status_command[] = {SI446x_CMD_GET_INT_STATUS, 0x00, 0x00, 0x00};
 
    si446x_sendcmd(4, get_int_status_command, SI446x_CHECK_ACK);
 
 
    HAL_Delay(10);
 
 
    // GPIO config: Set all GPIOs LOW; Link NIRQ to CTS; Link SDO to MISO; Max drive strength
 
	uint8_t gpio_pin_cfg_command[] = {
 
    		SI446x_CMD_GPIO_PIN_CFG, // Command
 
			SI446x_GPIO_LOW,      // GPIO0 - Power amp control DAC AD5611 Sync Pin
 
			SI446x_GPIO_INPUT,    // GPIO1 - Input for modulation
 
			SI446x_GPIO_LOW,      // GPIO2 - Blue LED
 
			SI446x_GPIO_NOCHANGE, // GPIO3 - Unused
 
			SI446x_GPIO_NOCHANGE, // NIRQ
 
			SI446x_GPIO_NOCHANGE, // 0x11, // SDO
 
			SI446x_GPIO_NOCHANGE, // Gencfg
 
	};
 
    si446x_sendcmd(8, gpio_pin_cfg_command, SI446x_CHECK_ACK);
 
 
    HAL_Delay(10);
 
 
//	uint8_t tune_xo_cmd[] = {
 
//    		SI446x_CMD_SET_PROPERTY,
 
//			SI446x_XO_TUNE_REGISTER_GROUP,
 
//			0x1, // num data
 
//			SI446x_XO_TUNE_REGISTER_PROP,
 
//			SI446x_CRYSTAL_LOAD_TUNING,
 
//    };
 
//    si446x_sendcmd(5, tune_xo_cmd, SI446x_CHECK_ACK);
 
 
    HAL_Delay(10);
 
 
    // Tune to frequency specified
 
	si446x_setchannel(TUNE_FREQUENCY);
 
 
	HAL_Delay(10);
 
 
    // Set to 2FSK mode
 
    uint8_t modemconfig = SI446x_MOD_TYPE_2FSK | SI446x_MOD_TYPE_SOURCE_DIRECTMODE | SI446x_MOD_TYPE_DIRECT_ASYNCH | SI446x_MOD_TYPE_DIRECT_SOURCE_GPIO1; //SI446x_MOD_TYPE_SOURCE_PACKETHANDLER
 
    uint8_t set_modem_mod_type_command[] = {
 
    		SI446x_CMD_SET_PROPERTY,
 
    		SI446x_MOD_TYPE_REGISTER_GROUP,
 
			0x01, // num data
 
			SI446x_MOD_TYPE_REGISTER_PROP,
 
			modemconfig
 
    };
 
    si446x_sendcmd(5, set_modem_mod_type_command, SI446x_CHECK_ACK);
 
 
    HAL_Delay(10);
 
 
	// Set Si446x initial output power, input to power amp (0-0x7F, 0mW - 40mw?)
 
	uint8_t basepower = 0x02;
 
	// FIXME: basepower should be 0x10 for underperforming units and 0x04 for normal units
 
    uint8_t set_power_level_command[] = {SI446x_CMD_SET_PROPERTY, 0x22, 0x01, 0x01, basepower};
 
	si446x_sendcmd(5, set_power_level_command, SI446x_CHECK_ACK);
 
 
 
	HAL_Delay(10);
 
 
    // Set air data rate
 
    si446x_setdatarate();
 
    HAL_Delay(10);
 
 
	// Tune TX
 
	uint8_t change_state_command[] = {SI446x_CMD_CHANGE_STATE, 0x05}; //  Change to TX tune state
 
    si446x_sendcmd(2, change_state_command, SI446x_CHECK_ACK);
 
    HAL_Delay(10);
 
 
	si446x_cw_status = 0;
 
}
 
 
 
// Perform power-on-reset of Si446x. Takes 20ms.
 
void si446x_reset(void)
 
{
 
	si446x_shutdown();
Libraries/aprs/aprs.c
Show inline comments
 
/*
 
 * FeatherHAB 
 
 *
 
 * This file is part of FeatherHAB.
 
 *
 
 * FeatherHab is free software: you can redistribute it and/or modify
 
 * it under the terms of the GNU Affero General Public License as published by
 
 * the Free Software Foundation, either version 3 of the License, or
 
 * (at your option) any later version.
 
 *
 
 * FeatherHab is distributed in the hope that it will be useful,
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
 * GNU Affero General Public License for more details.
 
 *
 
 * You should have received a copy of the GNU Affero General Public License
 
 * along with FeatherHAB. If not, see <http://www.gnu.org/licenses/>.
 
 * 
 
 * Ethan Zonca
 
 *
 
 */
 

	
 
#include <string.h>
 
#include <stdlib.h>
 

	
 
#include "config.h"
 
#include "pressure.h"
 
#include "aprs.h"
 
#include "gps.h"
 
//#include "gps.h"
 
//#include "adc.h"
 
#include "ax25.h"
 
#include "system/adc.h"
 

	
 

	
 
int32_t meters_to_feet(int32_t m)
 
{
 
  // 10000 ft = 3048 m
 
  return (float)m / 0.3048;
 
}
 

	
 
void aprs_send(void)
 
{
 
  struct s_address addresses[] = { 
 
    {D_CALLSIGN, D_CALLSIGN_ID},  // Destination callsign
 
    {"", S_CALLSIGN_ID},  // Source callsign (-11 = balloon, -9 = car)
 
		//{S_CALLSIGN, S_CALLSIGN_ID},
 
#ifdef DIGI_PATH1
 
    {DIGI_PATH1, DIGI_PATH1_TTL}, // Digi1 (first digi in the chain)
 
#endif
 
#ifdef DIGI_PATH2
 
    {DIGI_PATH2, DIGI_PATH2_TTL}, // Digi2 (second digi in the chain)
 
#endif
 
  };
 

	
 
  strncpy(addresses[1].callsign, S_CALLSIGN, 7);
 
  
 
  // emz: modified this to get the size of the first address rather than the size of the struct itself, which fails
 
  ax25_send_header(addresses, sizeof(addresses)/sizeof(addresses[0]));
 
  ax25_send_byte(',');
 

	
 
  char tmpBuffer[128];
 
  tmpBuffer[0] = ',';
 
  tmpBuffer[1] = '\0';
 

	
 
  // Latitude
 
  snprintf(tmpBuffer, 128, "%ld,", gps_getdata()->latitude);
 
  ax25_send_string(tmpBuffer);
 
  
 
  // Longitude
 
  snprintf(tmpBuffer, 128, "%ld,", gps_getdata()->longitude);
 
  ax25_send_string(tmpBuffer);
 

	
 
  // Speed
 
  snprintf(tmpBuffer, 128, "%d,", gps_getdata()->speed);
 
  ax25_send_string(tmpBuffer);
 

	
 
  // Altitude
 
  snprintf(tmpBuffer, 128, "%d,", gps_getdata()->altitude);
 
  ax25_send_string(tmpBuffer);
 

	
 
  // Pressure
 
  snprintf(tmpBuffer, 128, "%d,", pressure_getpressure());
 
  ax25_send_string(tmpBuffer);
 
  
 
  // Temperature
 
  snprintf(tmpBuffer, 128, "%d,", pressure_gettemp());
 
  ax25_send_string(tmpBuffer);
 

	
 
  // HDOP
 
  snprintf(tmpBuffer, 128, "%u,", gps_getdata()->pdop);
 
  ax25_send_string(tmpBuffer);
 

	
 
  // Heading
 
  snprintf(tmpBuffer, 128, "%u,", gps_getdata()->heading);
 
  ax25_send_string(tmpBuffer);
 

	
 
  // Vbatt
 
  snprintf(tmpBuffer, 128, "%u,", adc_get_vbatt());
 
  ax25_send_string(tmpBuffer);
 

	
 
  ax25_send_footer();
 
  ax25_flush_frame();
 
}
 

	
 
// vim:softtabstop=4 shiftwidth=4 expandtab 
Source/gps.c
Show inline comments
 
//
 
// GPS: communicate with ublox GPS module via ubx protocol
 
//
 

	
 
#include "stm32f0xx_hal.h"
 

	
 
#include "config.h"
 
#include "system/gpio.h"
 
#include "system/uart.h"
 
#include "gps.h"
 

	
 

	
 
volatile gps_data_t position;
 
uint8_t gpson = 0;
 

	
 
// Private methods
 
static void gps_ubx_checksum(uint8_t* data, uint8_t len, uint8_t* cka, uint8_t* ckb);
 
static uint8_t _gps_verify_checksum(uint8_t* data, uint8_t len);
 

	
 

	
 
// Poll for fix data from the GPS and update the internal structure
 
void gps_update_data(void)
 
{
 
	// Error!
 
	if(!gpson)
 
	{
 
//		led_blink(5);
 
		return;
 
	}
 

	
 
    // Construct the request to the GPS
 
    uint8_t request[8] = {0xB5, 0x62, 0x01, 0x07, 0x00, 0x00, 0xFF, 0xFF};
 

	
 

	
 
    volatile uint8_t check_a = 0;
 
    volatile uint8_t check_b = 0;
 
    for(uint8_t i = 2; i<6; i++)
 
    {
 
    	check_a += request[i];
 
    	check_b += check_a;
 
    }
 
    request[6] = check_a;
 
    request[7] = check_b;
 

	
 
    volatile uint8_t flushed = uart_gethandle()->Instance->RDR;
 
    HAL_UART_Transmit(uart_gethandle(), request, 8, 100);
 

	
 

	
 

	
 
    // Get the message back from the GPS
 
    uint8_t buf[100];
 
    for(uint8_t i=0; i<100; i++)
 
    	buf[i] = 0xaa;
 
    volatile HAL_StatusTypeDef res = HAL_UART_Receive(uart_gethandle(), buf, 100, 3000);
 

	
 
    // Check 60 bytes minus SYNC and CHECKSUM (4 bytes)
 
//    if( !_gps_verify_checksum(&buf[2], 96) )
 
//        led_blink(2);
 

	
 

	
 
    //volatile uint32_t gpstime_ms = (buf[6+0] << 24) | (buf[6+1] << 16) | buf[6+2] << 8) | (buf[6+3]);
 

	
 
    position.month = buf[6+6];
 
    position.day = buf[6+7];
 
    position.hour = buf[6+8];
 
    position.minute = buf[6+9];
 
    position.second = buf[6+10];
 
    position.valid = buf[6+11] & 0b1111;
 
    position.fixtype = buf[6+20];
 

	
 
    position.sats_in_solution = buf[6+23];
 

	
 
    position.longitude = (buf[6+24] << 0) | (buf[6+25] << 8) | (buf[6+26] << 16) | (buf[6+27] << 24); // degrees
 
    position.latitude =  (buf[6+28] << 0) | (buf[6+29] << 8) | (buf[6+30] << 16) | (buf[6+31] << 24); // degrees
 

	
 
    position.altitude = (buf[6+36] << 0) | (buf[6+37] << 8) | (buf[6+38] << 16) | (buf[6+39] << 24); // mm above sealevel
 
    position.altitude /= 1000; // mm => m
 

	
 
    position.speed = (buf[6+60] << 0) | (buf[6+61] << 8) | (buf[6+62] << 16) | (buf[6+63] << 24); // mm/second
 
    position.speed /= 1000; // mm/s -> m/s
 
    position.speed /= 10; // mm/s -> cm/s
 
    
 
    position.pdop = (buf[6+76] << 0) | (buf[6+77] << 8);
 
    position.pdop /= 100; // scale to dop units
 

	
 
    position.heading = (buf[6+84] << 0) | (buf[6+85] << 8) | (buf[6+86] << 16) | (buf[6+87] << 24); // mm above sealevel
 
    position.heading = (buf[6+64] << 0) | (buf[6+65] << 8) | (buf[6+66] << 16) | (buf[6+67] << 24);
 
    position.heading /= 100000; // 1e-5
 

	
 
//    // Return the value if GPSfixOK is set in 'flags'
 
//    if( buf[17] & 0x01 )
 
//        *lock = buf[16];
 
//    else
 
//        *lock = 0;
 

	
 
}
 

	
 
// TODO: Add data valid flag: invalidate data when GPS powered off
 

	
 

	
 
// Verify that the uBlox 6 GPS receiver is set to the <1g airborne navigaion mode.
 
uint8_t gps_check_nav(void)
 
{
 
    uint8_t request[8] = {0xB5, 0x62, 0x06, 0x24, 0x00, 0x00,
 
        0x2A, 0x84};
 
    uint8_t flushed = uart_gethandle()->Instance->RDR;
 
    HAL_UART_Transmit(uart_gethandle(), request, 8, 100);
 

	
 
    // Get the message back from the GPS
 
    uint8_t buf[44];
 
    HAL_UART_Receive(uart_gethandle(), buf, 44, 100);
 

	
 
//    // Verify sync and header bytes
 
//    if( buf[0] != 0xB5 || buf[1] != 0x62 )
 
//        led_set(LED_RED, 1);
 
//    if( buf[2] != 0x06 || buf[3] != 0x24 )
 
//        led_set(LED_RED, 1);
 

	
 
    // Check 40 bytes of message checksum
 
//    if( !_gps_verify_checksum(&buf[2], 40) ) led_set(LED_RED, 1);
 

	
 
    // Clock in and verify the ACK/NACK
 
    uint8_t ack[10];
 
//    for(uint8_t i = 0; i < 10; i++)
 
//        ack[i] = _gps_get_byte();
 

	
 
    HAL_UART_Receive(uart_gethandle(), ack, 10, 100);
 

	
 
    // If we got a NACK, then return 0xFF
 
    if( ack[3] == 0x00 ) return 0xFF;
 

	
 
    // Return the navigation mode and let the caller analyse it
 
    return buf[8];
 
}
 

	
 

	
 
// Verify the checksum for the given data and length.
 
static uint8_t _gps_verify_checksum(uint8_t* data, uint8_t len)
 
{
 
    uint8_t a, b;
 
    gps_ubx_checksum(data, len, &a, &b);
 
    if( a != *(data + len) || b != *(data + len + 1))
 
        return 0;
 
    else
 
        return 1;
 
}
 

	
 

	
 
// Calculate a UBX checksum using 8-bit Fletcher (RFC1145)
 
static void gps_ubx_checksum(uint8_t* data, uint8_t len, uint8_t* cka, uint8_t* ckb)
 
{
 
    *cka = 0;
 
    *ckb = 0;
 
    for( uint8_t i = 0; i < len; i++ )
 
    {
 
        *cka += *data;
 
        *ckb += *cka;
 
        data++;
 
    }
 
}
 

	
 

	
 
// Power on GPS module and initialize UART
 
void gps_poweron(void)
 
{
 
    // NOTE: pchannel
 
    HAL_GPIO_WritePin(GPS_NOTEN, 0);
 
    uart_init();
 

	
 
	// Disable messages
 
	uint8_t setGGA[] = {0XB5, 0X62, 0X06, 0X01, 0X08, 0X00, 0XF0, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0XFF, 0X23};
 
	HAL_UART_Transmit(uart_gethandle(), setGGA, sizeof(setGGA)/sizeof(uint8_t), 100);
 
	HAL_Delay(100);
 

	
 
	uint8_t ackbuffer[10];
 
	for(uint8_t i=0; i<10; i++)
 
		ackbuffer[i] = 0xaa;
 
	HAL_UART_Receive(uart_gethandle(), ackbuffer, 10, 100);
 

	
 
	uint8_t setZDA[] = {0XB5, 0X62, 0X06, 0X01, 0X08, 0X00, 0XF0, 0X08, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X07, 0X5B};
 
	HAL_UART_Transmit(uart_gethandle(), setZDA, sizeof(setZDA)/sizeof(uint8_t), 100);
 
	HAL_Delay(100);
 

	
 
	uint8_t setGLL[] = {0XB5, 0X62, 0X06, 0X01, 0X08, 0X00, 0XF0, 0X01, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X2A};
 
	HAL_UART_Transmit(uart_gethandle(), setGLL, sizeof(setGLL)/sizeof(uint8_t), 100);
 
	HAL_Delay(100);
 

	
 
	uint8_t setGSA[] = {0XB5, 0X62, 0X06, 0X01, 0X08, 0X00, 0XF0, 0X02, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X01, 0X31};
 
	HAL_UART_Transmit(uart_gethandle(), setGSA, sizeof(setGSA)/sizeof(uint8_t), 100);
 
	HAL_Delay(100);
 

	
 
	uint8_t setGSV[] = {0XB5, 0X62, 0X06, 0X01, 0X08, 0X00, 0XF0, 0X03, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X02, 0X38};
 
	HAL_UART_Transmit(uart_gethandle(), setGSV, sizeof(setGSV)/sizeof(uint8_t), 100);
 
	HAL_Delay(100);
 

	
 
	uint8_t setRMC[] = {0XB5, 0X62, 0X06, 0X01, 0X08, 0X00, 0XF0, 0X04, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X03, 0X3F};
 
	HAL_UART_Transmit(uart_gethandle(), setRMC, sizeof(setRMC)/sizeof(uint8_t), 100);
 
	HAL_Delay(100);
 

	
 
	uint8_t setVTG[] = {0XB5, 0X62, 0X06, 0X01, 0X08, 0X00, 0XF0, 0X05, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X04, 0X46};
 
	HAL_UART_Transmit(uart_gethandle(), setVTG, sizeof(setRMC)/sizeof(uint8_t), 100);
 
	HAL_Delay(100);
 

	
 

	
 
//    // Disable GLONASS mode
 
//    uint8_t disable_glonass[20] = {0xB5, 0x62, 0x06, 0x3E, 0x0C, 0x00, 0x00, 0x00, 0x20, 0x01, 0x06, 0x08, 0x0E, 0x00, 0x00, 0x00, 0x01, 0x01, 0x8F, 0xB2};
 
//
 
//    //gps_sendubx(disable_glonass, 20);
 
//    volatile HAL_StatusTypeDef res = HAL_UART_Transmit(uart_gethandle(), disable_glonass, 20, 100);
 
//    HAL_UART_Transmit(uart_gethandle(), disable_glonass, sizeof(disable_glonass)/sizeof(uint8_t), 100);
 
//	HAL_Delay(100);
 
//
 
//    // Enable power saving
 
//    uint8_t enable_powersave[10] = {0xB5, 0x62, 0x06, 0x11, 0x02, 0x00, 0x08, 0x01, 0x22, 0x92};
 
//    //gps_sendubx(enable_powersave, 10);
 
//    res = HAL_UART_Transmit(uart_gethandle(), enable_powersave, 10, 100);
 
//    HAL_UART_Transmit(uart_gethandle(), enable_powersave, sizeof(enable_powersave)/sizeof(uint8_t), 100);
 
//	HAL_Delay(100);
 
//
 
//
 
//    // Set dynamic model 6 (<1g airborne platform)
 
//    uint8_t airborne_model[] = { 0xB5, 0x62, 0x06, 0x24, 0x24, 0x00, 0xFF, 0xFF, 0x06, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10, 0x27, 0x00, 0x00, 0x05, 0x00, 0xFA, 0x00, 0xFA, 0x00, 0x64, 0x00, 0x2C, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0xDC };
 
//    //gps_sendubx(airborne_model, sizeof(airborne_model)/sizeof(uint8_t));
 
//    res = HAL_UART_Transmit(uart_gethandle(), airborne_model, sizeof(airborne_model)/sizeof(uint8_t), 100);
 

	
 

	
 
//    HAL_UART_Transmit(uart_gethandle(), airborne_model, sizeof(airborne_model)/sizeof(uint8_t), 100);
 
//	HAL_Delay(100);
 
//
 
//
 

	
 

	
 

	
 
    // Begin DMA reception
 
    //HAL_UART_Receive_DMA(uart_gethandle(), nmeaBuffer, NMEABUFFER_SIZE);
 

	
 
    gpson = 1;
 
}
 

	
 

	
 
// Power off GPS module
 
void gps_poweroff(void)
 
{
 
    // NOTE: pchannel
 
//	position.hour = 0;
 
//	position.minute = 0;
 
//	position.second = 0;
 
//	position.altitude = 0;
 
//	position.latitude = 0;
 
//	position.longitude = 0;
 
//	position.day = 0;
 
//	position.month = 0;
 
//	position.fixtype = 0;
 
//	position.valid = 0;
 
	position.pdop = 0;
 
	position.sats_in_solution = 0;
 
//	position.speed = 0;
 

	
 
    uart_deinit();
 
    HAL_GPIO_WritePin(GPS_NOTEN, 1);
 
    gpson = 0;
 
}
 

	
 
gps_data_t* gps_getdata(void)
 
{
 
    return &position;
 
}
 

	
 
uint8_t gps_ison(void)
 
{
 
    return gpson;
 
}
 

	
 
// vim:softtabstop=4 shiftwidth=4 expandtab 
Source/main.c
Show inline comments
 
//
 
// mBuoy Depth Select Firmware
 
// Copyright 2015 SeaLandAire Technologies
 
//
 
 
#include "config.h"
 
#include "error.h"
 
#include "system/gpio.h"
 
#include "system/sysclk.h"
 
#include "system/watchdog.h"
 
#include "system/uart.h"
 
#include "system/adc.h"
 
#include "stm32f0xx_hal.h"
 
#include "si446x/si446x.h"
 
#include "aprs/aprs.h"
 
#include "aprs/afsk.h"
 
#include "pressure.h"
 
#include "gps.h"
 
 
 
int main(void)
 
{
 
  hal_init();
 
  sysclock_init();
 
  gpio_init();
 
 
  HAL_Delay(100);
 
 
  adc_init();
 
 
  afsk_init();
 
  si446x_init();
 
  si446x_init();
 
 
  HAL_Delay(100);
 
 
  gps_poweron();
 
  HAL_Delay(100);
 
 
  pressure_init();
 
 
  // Software timers
 
  uint32_t last_transmission = HAL_GetTick();
 
  uint32_t last_led = HAL_GetTick();
 
 
  while (1)
 
  {
 
	  // Blink LEDs
 
	  if(HAL_GetTick() - last_transmission > 700)
 
	  {
 
		  gps_update_data(); // Will always return at 1hz rate (default measurement rate)
 
		  pressure_read();
 
		  aprs_send();
 
		  //while(afsk_busy());
 
 
		  last_transmission = HAL_GetTick();
 
	  }
 
 
	  if(HAL_GetTick() - last_led > 100)
 
	  {
 
		  HAL_GPIO_TogglePin(LED_POWER);
 
		  last_led = HAL_GetTick();
 
	  }
 
 
	  if(afsk_request_cwoff())
 
		  si446x_cw_off();
 
 
	  // High-frequency function calls
 
//	  watchdog_feed();
 
  }
 
}
 
0 comments (0 inline, 0 general)