Changeset - 0a0719c60fff
[Not reviewed]
default
0 1 0
Ethan Zonca - 8 years ago 2017-10-10 17:59:26
ez@ethanzonca.com
I'm totally a good C programmer... Add semicolons. Reduce drive strength.
1 file changed with 4 insertions and 3 deletions:
0 comments (0 inline, 0 general)
src/wspr.c
Show inline comments
 
@@ -105,98 +105,98 @@ void wspr_transmit(uint8_t* grid_locator
 

	
 

	
 
        // Static set ID
 
        call[2] = '4'; // balloon ID #4
 

	
 
        // Subtract off previous portion
 
        subalt -= (chunk * 26 * 26 * 26);
 

	
 
        // Mask off following 2 26bit values
 
        chunk = (subalt / 26 / 26);
 

	
 
        call[3] = 'A' + chunk;
 

	
 
        // Subtract off previous portion
 
        subalt -= (chunk * 26 * 26);
 

	
 
        // Mask off following 1 26bit values
 
        chunk = (subalt / 26);
 

	
 
        call[4] = 'A' + chunk;
 

	
 
        // Subtract off previous portion
 
        subalt -= (chunk * 26);
 

	
 
        // Remainder is the last call char
 
        call[5] = 'A' + subalt;
 
 
 

	
 
        ////////////////////////////////////////
 
        // Composite temp/batt/speed/gps 
 
        ////////////////////////////////////////
 

	
 
        // Encode value from -50C to 39C => 0-89. TODO: Bounds!
 
        uint32_t temp_enc = adc_get_dietemp() + 50;
 
        if(temp_enc > 89)
 
            temp_enc = 89;
 

	
 
        // Encode value from 0-39 with some scalar/offset/etc
 
        uint32_t batt_enc = adc_get_vbatt();  // Hopefully in decivolts
 
        if(batt_enc > 39)
 
            batt_enc = 39;
 

	
 
        // Encode speed in knots from 0-82 to 0-41
 
        uint32_t speed_enc = gps_getdata()->speed / 2;
 
        if(speed_enc > 41)
 
            speed_enc = 41;
 

	
 
        // Encode GPS status
 
        uint32_t gps_status = 0b0 // valid fix
 
        uint32_t gps_sats = 0b0   // lats > 8
 
        uint32_t gps_status = 0b0; // valid fix
 
        uint32_t gps_sats = 0b0;  // lats > 8
 

	
 

	
 
        // We always have a fix if we got to this point; and I think we zero out that we had a fix when turning the GPS off before entering this function
 
//        if(gps_getdata()->fixtype == 2 || gps_getdata()->fixtype == 3)
 
            gps_status = 0b1;
 

	
 
        if(gps_getdata()->sats_in_solution > 5)
 
            gps_sats = 0b1;
 

	
 
        uint32_t engdata = gps_sats + 2 * (gps_status + 2 * (speed_enc + 42 * (batt_enc + 40 * temp_enc)));
 

	
 
        ////////////////////////////////////////////
 
        // Encode temp/batt/speed/gps
 
        ////////////////////////////////////////////
 

	
 
        // Mask off fields
 
        chunk = engdata / 18 / 10 / 10 / 19;  
 

	
 
        // Encode to grid locator
 
        loc[0] = 'A' + chunk;
 

	
 
        // Subtract off previous portion 
 
        engdata -= (chunk * 18 * 10 * 10 * 19);  
 

	
 
        // Mask of fields
 
        chunk = engdata / 10 / 10 / 19;  
 

	
 
        // Encode to grid locator
 
        loc[1] = 'A' + chunk;
 

	
 
        // Subtract off previous portion
 
        engdata -= (chunk * 10 * 10 * 19);  
 

	
 
        // Mask off fields
 
        chunk = engdata / 10 / 19;  
 

	
 
        // Encode
 
        loc[2] = '0' + chunk;
 

	
 
        // Subtract
 
        engdata -= (chunk * 10 * 19);  
 

	
 
        // Mask off
 
        chunk = engdata / 19;  
 

	
 
        // Encode
 
        loc[3] = chunk;
 

	
 
@@ -209,97 +209,98 @@ void wspr_transmit(uint8_t* grid_locator
 
        // Encode
 
        uint8_t powers[] = {0, 3, 7, 10, 13, 17, 20, 23, 27, 30, 33, 37, 40, 43, 47, 50, 53, 57, 60};
 
        dbm = powers[chunk];
 

	
 

	
 
    }
 
    else
 
    {
 
        call[0] = call_orig[0];
 
        call[1] = call_orig[1];
 
        call[2] = call_orig[2];
 
        call[3] = call_orig[3];
 
        call[4] = call_orig[4];
 
        call[5] = call_orig[5];
 
        call[6] = call_orig[6];
 

	
 
        dbm = DBM_ORIG; 
 
    }
 

	
 
    // Start timer for WSPR
 
    __TIM1_CLK_ENABLE();
 
    htim1.Instance = TIM1;
 
    htim1.Init.Prescaler = 512 / 4; // FIXED gives 64us ticks from 2mhz clock // gives 64uS ticks from 8MHz ahbclk
 
    htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
 
    htim1.Init.Period = ctc; // Count up to this value (how many 64uS ticks per symbol)
 
    htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
 
    htim1.Init.RepetitionCounter = 0;
 
    HAL_TIM_Base_Init(&htim1);
 
    HAL_TIM_Base_Start_IT(&htim1);
 
    HAL_NVIC_SetPriority(TIM1_BRK_UP_TRG_COM_IRQn, 0, 0);
 
    HAL_NVIC_EnableIRQ(TIM1_BRK_UP_TRG_COM_IRQn);
 

	
 

	
 

	
 
    // TODO: Bring up TCXO sooner! Gotta let it warm up or something
 

	
 
    HAL_GPIO_WritePin(OSC_NOTEN, 0);
 
    HAL_GPIO_WritePin(TCXO_EN, 1);
 
    HAL_Delay(100);
 

	
 
    // Bring up the chip
 
    i2c_init();
 
    si5351_init(i2c_get(), SI5351_CRYSTAL_LOAD_8PF, 0);
 
    si5351_set_correction(0);
 
    //si5351_set_pll(SI5351_PLL_FIXED, SI5351_PLLA);
 
    //si5351_set_ms_source(SI5351_CLK0, SI5351_PLLA);
 
    si5351_set_freq(WSPR_DEFAULT_FREQ * 100, 0, SI5351_CLK0);
 
//    si5351_drive_strength(SI5351_CLK0, SI5351_DRIVE_8MA); // Set for max power if desired (8ma max)
 
    si5351_drive_strength(SI5351_CLK0, SI5351_DRIVE_6MA); // Set for max power if desired (8ma max)
 
//    si5351_drive_strength(SI5351_CLK0, SI5351_DRIVE_6MA); // Set for max power if desired (8ma max)
 
    si5351_drive_strength(SI5351_CLK0, SI5351_DRIVE_2MA); // Set for max power if desired (8ma max)
 
    si5351_output_enable(SI5351_CLK0, 1);
 
    //si5351_pll_reset(SI5351_PLLA);
 

	
 
    // Make sure the other outputs of the SI5351 are disabled
 
    si5351_output_enable(SI5351_CLK1, 0); // Disable the clock initially
 
    si5351_output_enable(SI5351_CLK2, 0); // Disable the clock initially
 

	
 
    // disable clock powers
 
    si5351_set_clock_pwr(SI5351_CLK1, 0);
 
    si5351_set_clock_pwr(SI5351_CLK2, 0);
 

	
 

	
 
    // Encode message to transmit
 
    wspr_encode(call, loc, dbm, tx_buffer);
 

	
 
    // Key transmitter
 
    si5351_output_enable(SI5351_CLK0, 1);
 

	
 
    // Loop through and transmit symbols TODO: Do this from an ISR or ISR-triggered main loop function call (optimal)
 
    uint8_t i;
 
    for(i=0; i<symbol_count; i++)
 
    {
 
        uint32_t freq2 = (freq * 100) + (tx_buffer[i] * tone_spacing);
 
        si5351_set_freq(freq2, 0, SI5351_CLK0);
 
        HAL_GPIO_TogglePin(LED_BLUE);
 

	
 
        proceed = 0;
 
        while(!proceed);
 
    }
 

	
 
    // Disable transmitter
 
    si5351_output_enable(SI5351_CLK0, 0);
 

	
 
    HAL_GPIO_WritePin(OSC_NOTEN, 1);
 
    HAL_GPIO_WritePin(TCXO_EN, 0);
 

	
 
    i2c_deinit();
 

	
 
    // Disable timer
 
    HAL_NVIC_DisableIRQ(TIM1_BRK_UP_TRG_COM_IRQn);
 
    HAL_TIM_Base_Stop_IT(&htim1);
 
    HAL_TIM_Base_DeInit(&htim1);
 

	
 
    __TIM1_CLK_DISABLE();
 

	
 

	
 
}
 

	
0 comments (0 inline, 0 general)