Changeset - c5bc128e44a6
[Not reviewed]
default
0 3 0
Ethan Zonca - 10 years ago 2016-04-02 20:44:19
ez@ethanzonca.com
WSPR and gps now coexist, don't call jtencode_init because it inits the reed-solomon encoder that wspr doesn't even use
3 files changed with 64 insertions and 36 deletions:
0 comments (0 inline, 0 general)
STM32F031G6_FLASH.ld
Show inline comments
 
/*
 
*****************************************************************************
 
**
 
**  File        : stm32_flash.ld
 
**
 
**  Abstract    : Linker script for STM32F031G6 Device with
 
**                32KByte FLASH, 4KByte RAM
 
**
 
**                Set heap size, stack size and stack location according
 
**                to application requirements.
 
**
 
**                Set memory bank area and size if external memory is used.
 
**
 
**  Target      : STMicroelectronics STM32
 
**
 
**  Environment : Atollic TrueSTUDIO(R)
 
**
 
**  Distribution: The file is distributed “as is,” without any warranty
 
**                of any kind.
 
**
 
**  (c)Copyright Atollic AB.
 
**  You may use this file as-is or modify it according to the needs of your
 
**  project. This file may only be built (assembled or compiled and linked)
 
**  using the Atollic TrueSTUDIO(R) product. The use of this file together
 
**  with other tools than Atollic TrueSTUDIO(R) is not permitted.
 
**
 
*****************************************************************************
 
*/
 

	
 
/* Entry Point */
 
ENTRY(Reset_Handler)
 

	
 
/* Highest address of the user mode stack */
 
_estack = 0x20001000;    /* end of RAM */
 

	
 
/* Generate a link error if heap and stack don't fit into RAM */
 
_Min_Heap_Size = 0;      /* required amount of heap  */
 
_Min_Stack_Size = 0x300; /* required amount of stack */
 
_Min_Stack_Size = 0x200; /* required amount of stack */
 

	
 
/* Specify the memory areas */
 
MEMORY
 
{
 
FLASH (rx)      : ORIGIN = 0x8000000, LENGTH = 32K
 
RAM (xrw)      : ORIGIN = 0x20000000, LENGTH = 4K
 
}
 

	
 
/* Define output sections */
 
SECTIONS
 
{
 
  /* The startup code goes first into FLASH */
 
  .isr_vector :
 
  {
 
    . = ALIGN(4);
 
    KEEP(*(.isr_vector)) /* Startup code */
 
    . = ALIGN(4);
 
  } >FLASH
 

	
 
  /* The program code and other data goes into FLASH */
 
  .text :
 
  {
 
    . = ALIGN(4);
 
    *(.text)           /* .text sections (code) */
 
    *(.text*)          /* .text* sections (code) */
 
    *(.glue_7)         /* glue arm to thumb code */
 
    *(.glue_7t)        /* glue thumb to arm code */
 
    *(.eh_frame)
 

	
 
    KEEP (*(.init))
 
    KEEP (*(.fini))
 

	
 
    . = ALIGN(4);
 
    _etext = .;        /* define a global symbols at end of code */
 
  } >FLASH
 

	
 
  /* Constant data goes into FLASH */
 
  .rodata :
 
  {
 
    . = ALIGN(4);
 
    *(.rodata)         /* .rodata sections (constants, strings, etc.) */
 
    *(.rodata*)        /* .rodata* sections (constants, strings, etc.) */
 
    . = ALIGN(4);
 
  } >FLASH
 

	
 
  .ARM.extab   : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH
 
  .ARM : {
 
    __exidx_start = .;
lib/jtencode/jtencode.c
Show inline comments
 
@@ -12,96 +12,109 @@
 
 * the Free Software Foundation, either version 3 of the License, or
 
 * (at your option) any later version.
 
 *
 
 * This program 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 General Public License for more details.
 
 *
 
 * You should have received a copy of the GNU General Public License
 
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
#include "jtencode.h"
 

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

	
 

	
 
uint8_t jt_code(char);
 
uint8_t wspr_code(char);
 
uint8_t gray_code(uint8_t);
 
void jt_message_prep(char *);
 
void wspr_message_prep(char *, char *, uint8_t);
 
void jt65_bit_packing(char *, uint8_t *);
 
void jt9_bit_packing(char *, uint8_t *);
 
void wspr_bit_packing(uint8_t *);
 
void jt65_interleave(uint8_t *);
 
void jt9_interleave(uint8_t *);
 
void wspr_interleave(uint8_t *);
 
void jt9_packbits(uint8_t *, uint8_t *);
 
void jt_gray_code(uint8_t *, uint8_t);
 
void jt65_merge_sync_vector(uint8_t *, uint8_t *);
 
void jt9_merge_sync_vector(uint8_t *, uint8_t *);
 
void jt4_merge_sync_vector(uint8_t *, uint8_t *);
 
void wspr_merge_sync_vector(uint8_t *, uint8_t *);
 
void convolve(uint8_t *, uint8_t *, uint8_t, uint8_t);
 
void rs_encode(uint8_t *, uint8_t *);
 
void encode_rs_int(void *,data_t *, data_t *);
 
void free_rs_int(void *);
 
void * init_rs_int(int, int, int, int, int, int);
 
void * rs_inst;
 
char callsign[7];
 
char locator[5];
 
uint8_t power;
 

	
 

	
 
static void emz_memcpy( uint8_t *pDest, uint8_t *pSrc, uint32_t len )
 
{
 
    uint32_t i;
 

	
 
    // Manually copy the data
 
    for ( i = 0; i < len; i++ )
 
    {
 
        // Copy data from source to destination
 
        *pDest++ = *pSrc++;
 
    }
 
}
 

	
 

	
 
/* Public Class Members */
 

	
 
void* jtencode_init(void)
 
{
 
  // Initialize the Reed-Solomon encoder
 
  rs_inst = (struct rs *)(intptr_t)init_rs_int(6, 0x43, 3, 1, 51, 0);
 
}
 

	
 
/*
 
 * jt65_encode(char * message, uint8_t * symbols)
 
 *
 
 * Takes an arbitrary message of up to 13 allowable characters and returns
 
 * a channel symbol table.
 
 *
 
 * message - Plaintext Type 6 message.
 
 * symbols - Array of channel symbols to transmit retunred by the method.
 
 *  Ensure that you pass a uint8_t array of size JT65_SYMBOL_COUNT to the method.
 
 *
 
 */
 
void jt65_encode(char * message, uint8_t * symbols)
 
{
 
  // Ensure that the message text conforms to standards
 
  // --------------------------------------------------
 
  jt_message_prep(message);
 

	
 
  // Bit packing
 
  // -----------
 
  uint8_t c[12];
 
  jt65_bit_packing(message, c);
 

	
 
  // Reed-Solomon encoding
 
  // ---------------------
 
  uint8_t s[JT65_ENCODE_COUNT];
 
  rs_encode(c, s);
 

	
 
  // Interleaving
 
  // ------------
 
  jt65_interleave(s);
 

	
 
  // Gray Code
 
  // ---------
 
  jt_gray_code(s, JT65_ENCODE_COUNT);
 

	
 
  // Merge with sync vector
 
  // ----------------------
 
  jt65_merge_sync_vector(s, symbols);
 
}
 

	
 
@@ -118,130 +131,131 @@ void jt65_encode(char * message, uint8_t
 
 */
 
void jt9_encode(char * message, uint8_t * symbols)
 
{
 
  // Ensure that the message text conforms to standards
 
  // --------------------------------------------------
 
  jt_message_prep(message);
 

	
 
  // Bit packing
 
  // -----------
 
  uint8_t c[13];
 
  jt9_bit_packing(message, c);
 

	
 
  // Convolutional Encoding
 
  // ---------------------
 
  uint8_t s[JT9_BIT_COUNT];
 
  convolve(c, s, 13, JT9_BIT_COUNT);
 

	
 
  // Interleaving
 
  // ------------
 
  jt9_interleave(s);
 

	
 
  // Pack into 3-bit symbols
 
  // -----------------------
 
  uint8_t a[JT9_ENCODE_COUNT];
 
  jt9_packbits(s, a);
 

	
 
  // Gray Code
 
  // ---------
 
  jt_gray_code(a, JT9_ENCODE_COUNT);
 

	
 
  // Merge with sync vector
 
  // ----------------------
 
  jt9_merge_sync_vector(a, symbols);
 
}
 

	
 
/*
 
 * jt9_encode(char * message, uint8_t * symbols)
 
 *
 
 * Takes an arbitrary message of up to 13 allowable characters and returns
 
 * a channel symbol table.
 
 *
 
 * message - Plaintext Type 6 message.
 
 * symbols - Array of channel symbols to transmit retunred by the method.
 
 *  Ensure that you pass a uint8_t array of size JT9_SYMBOL_COUNT to the method.
 
 *
 
 */
 
void jt4_encode(char * message, uint8_t * symbols)
 
{
 
    // emz comment memmove
 
  // Ensure that the message text conforms to standards
 
  // --------------------------------------------------
 
  jt_message_prep(message);
 

	
 
  // Bit packing
 
  // -----------
 
  uint8_t c[13];
 
  jt9_bit_packing(message, c);
 

	
 
  // Convolutional Encoding
 
  // ---------------------
 
  uint8_t s[JT4_SYMBOL_COUNT];
 
  convolve(c, s, 13, JT4_BIT_COUNT);
 

	
 
  // Interleaving
 
  // ------------
 
  jt9_interleave(s);
 
  memmove(s + 1, s, JT4_BIT_COUNT);
 
  s[0] = 0; // Append a 0 bit to start of sequence
 

	
 
  // Merge with sync vector
 
  // ----------------------
 
  jt4_merge_sync_vector(s, symbols);
 
//  // --------------------------------------------------
 
//  jt_message_prep(message);
 
//
 
//  // Bit packing
 
//  // -----------
 
//  uint8_t c[13];
 
//  jt9_bit_packing(message, c);
 
//
 
//  // Convolutional Encoding
 
//  // ---------------------
 
//  uint8_t s[JT4_SYMBOL_COUNT];
 
//  convolve(c, s, 13, JT4_BIT_COUNT);
 
//
 
//  // Interleaving
 
//  // ------------
 
//  jt9_interleave(s);
 
//  memmove(s + 1, s, JT4_BIT_COUNT);
 
//  s[0] = 0; // Append a 0 bit to start of sequence
 
//
 
//  // Merge with sync vector
 
//  // ----------------------
 
//  jt4_merge_sync_vector(s, symbols);
 
}
 

	
 
/*
 
 * wspr_encode(char * call, char * loc, uint8_t dbm, uint8_t * symbols)
 
 *
 
 * Takes an arbitrary message of up to 13 allowable characters and returns
 
 *
 
 * call - Callsign (6 characters maximum).
 
 * loc - Maidenhead grid locator (4 charcters maximum).
 
 * loc - Maidenhead grid locator (4 characters maximum).
 
 * dbm - Output power in dBm.
 
 * symbols - Array of channel symbols to transmit retunred by the method.
 
 * symbols - Array of channel symbols to transmit returned by the method.
 
 *  Ensure that you pass a uint8_t array of size WSPR_SYMBOL_COUNT to the method.
 
 *
 
 */
 
void wspr_encode(char * call, char * loc, uint8_t dbm, uint8_t * symbols)
 
{
 
    // Ensure that the message text conforms to standards
 
  // --------------------------------------------------
 
  wspr_message_prep(call, loc, dbm);
 

	
 
  // Bit packing
 
  // -----------
 
  uint8_t c[11];
 
  wspr_bit_packing(c);
 

	
 
  // Convolutional Encoding
 
  // ---------------------
 
  uint8_t s[WSPR_SYMBOL_COUNT];
 
  convolve(c, s, 11, WSPR_BIT_COUNT);
 

	
 
  // Interleaving
 
  // ------------
 
  wspr_interleave(s);
 

	
 
  // Merge with sync vector
 
  // ----------------------
 
  wspr_merge_sync_vector(s, symbols);
 
}
 

	
 
/* Private Class Members */
 

	
 
uint8_t jt_code(char c)
 
{
 
  // Validate the input then return the proper integer code.
 
  // Return 255 as an error code if the char is not allowed.
 

	
 
  if(isdigit(c))
 
  {
 
    return (uint8_t)(c - 48);
 
  }
 
  else if(c >= 'A' && c <= 'Z')
 
  {
 
    return (uint8_t)(c - 55);
 
  }
 
  else if(c == ' ')
 
  {
 
    return 36;
 
  }
 
  else if(c == '+')
 
@@ -287,132 +301,142 @@ uint8_t wspr_code(char c)
 
	{
 
		return (uint8_t)(c - 55);
 
	}
 
	else
 
	{
 
		return 255;
 
	}
 
}
 

	
 
uint8_t gray_code(uint8_t c)
 
{
 
  return (c >> 1) ^ c;
 
}
 

	
 
void jt_message_prep(char * message)
 
{
 
  uint8_t i, j;
 

	
 
  // Convert all chars to uppercase
 
  for(i = 0; i < 13; i++)
 
  {
 
    if(islower(message[i]))
 
    {
 
      message[i] = toupper(message[i]);
 
    }
 
  }
 

	
 
  // Pad the message with trailing spaces
 
  uint8_t len = strlen(message);
 
  if(len < 13)
 
  {
 
    for(i = len; i < 13; i++)
 
    {
 
      message[i] = ' ';
 
    }
 
  }
 
}
 

	
 
void wspr_message_prep(char * call, char * loc, uint8_t dbm)
 
{
 
  // Callsign validation and padding
 
  // -------------------------------
 

	
 
	// If only the 2nd character is a digit, then pad with a space.
 
	// If this happens, then the callsign will be truncated if it is
 
	// longer than 5 characters.
 
	if((call[1] >= '0' && call[1] <= '9') && (call[2] < '0' || call[2] > '9'))
 
	{
 
		memmove(call + 1, call, 5);
 
		//memmove(call + 1, call, 5);
 
		//call[0] = ' ';
 

	
 
	    call[6] = '\0';
 
		call[5] = call[4];
 
		call[4] = call[3];
 
		call[3] = call[2];
 
		call[2] = call[1];
 
		call[1] = call[0];
 
		call[0] = ' ';
 

	
 

	
 
	}
 

	
 
	// Now the 3rd charcter in the callsign must be a digit
 
	if(call[2] < '0' || call[2] > '9')
 
	{
 
    // TODO: need a better way to handle this
 
		call[2] = '0';
 
	}
 

	
 
	// Ensure that the only allowed characters are digits and
 
	// uppercase letters
 
	uint8_t i;
 
	for(i = 0; i < 6; i++)
 
	{
 
		call[i] = toupper(call[i]);
 
		if(!(isdigit(call[i]) || isupper(call[i])))
 
		{
 
			call[i] = ' ';
 
		}
 
	}
 

	
 
  memcpy(callsign, call, 6);
 
	emz_memcpy(callsign, call, 6);
 

	
 
	// Grid locator validation
 
	for(i = 0; i < 4; i++)
 
	{
 
		loc[i] = toupper(loc[i]);
 
		if(!(isdigit(loc[i]) || (loc[i] >= 'A' && loc[i] <= 'R')))
 
		{
 
			loc = "AA00";
 
		}
 
	}
 

	
 
  memcpy(locator, loc, 4);
 
	emz_memcpy(locator, loc, 4);
 

	
 
	// Power level validation
 
	// Only certain increments are allowed
 
	if(dbm > 60)
 
	{
 
		dbm = 60;
 
	}
 
  const uint8_t valid_dbm[19] =
 
    {0, 3, 7, 10, 13, 17, 20, 23, 27, 30, 33, 37, 40,
 
     43, 47, 50, 53, 57, 60};
 
  for(i = 0; i < 19; i++)
 
  {
 
    if(dbm == valid_dbm[i])
 
    {
 
      power = dbm;
 
    }
 
  }
 
  // If we got this far, we have an invalid power level, so we'll round down
 
  for(i = 1; i < 19; i++)
 
  {
 
    if(dbm < valid_dbm[i] && dbm >= valid_dbm[i - 1])
 
    {
 
      power = valid_dbm[i - 1];
 
    }
 
  }
 
}
 

	
 
void jt65_bit_packing(char * message, uint8_t * c)
 
{
 
  uint32_t n1, n2, n3;
 

	
 
  // Find the N values
 
  n1 = jt_code(message[0]);
 
  n1 = n1 * 42 + jt_code(message[1]);
 
  n1 = n1 * 42 + jt_code(message[2]);
 
  n1 = n1 * 42 + jt_code(message[3]);
 
  n1 = n1 * 42 + jt_code(message[4]);
 

	
 
  n2 = jt_code(message[5]);
 
  n2 = n2 * 42 + jt_code(message[6]);
 
  n2 = n2 * 42 + jt_code(message[7]);
 
  n2 = n2 * 42 + jt_code(message[8]);
 
  n2 = n2 * 42 + jt_code(message[9]);
 

	
 
  n3 = jt_code(message[10]);
 
  n3 = n3 * 42 + jt_code(message[11]);
 
  n3 = n3 * 42 + jt_code(message[12]);
 

	
 
@@ -516,180 +540,185 @@ void wspr_bit_packing(uint8_t * c)
 

	
 
	// Callsign is 28 bits, locator/power is 22 bits.
 
	// A little less work to start with the least-significant bits
 
	c[3] = (uint8_t)((n & 0x0f) << 4);
 
	n = n >> 4;
 
	c[2] = (uint8_t)(n & 0xff);
 
	n = n >> 8;
 
	c[1] = (uint8_t)(n & 0xff);
 
	n = n >> 8;
 
	c[0] = (uint8_t)(n & 0xff);
 

	
 
	c[6] = (uint8_t)((m & 0x03) << 6);
 
	m = m >> 2;
 
	c[5] = (uint8_t)(m & 0xff);
 
	m = m >> 8;
 
	c[4] = (uint8_t)(m & 0xff);
 
	m = m >> 8;
 
	c[3] |= (uint8_t)(m & 0x0f);
 
	c[7] = 0;
 
	c[8] = 0;
 
	c[9] = 0;
 
	c[10] = 0;
 
}
 

	
 
void jt65_interleave(uint8_t * s)
 
{
 
  uint8_t i, j;
 
  uint8_t d[JT65_ENCODE_COUNT];
 
  uint8_t d1[7][9];
 

	
 
  // Fill temp d1 array
 
  for(i = 0; i < 9; i++)
 
  {
 
    for(j = 0; j < 7; j++)
 
    {
 
      d1[i][j] = s[(i * 7) + j];
 
    }
 
  }
 

	
 
  // Interleave and translate back to 1D destination array
 
  for(i = 0; i < 7; i++)
 
  {
 
    for(j = 0; j < 9; j++)
 
    {
 
      d[(i * 9) + j] = d1[j][i];
 
    }
 
  }
 

	
 
  memcpy(s, d, JT65_ENCODE_COUNT);
 
  emz_memcpy(s, d, JT65_ENCODE_COUNT);
 
}
 

	
 
void jt9_interleave(uint8_t * s)
 
{
 
  uint8_t i, j, k, n;
 
  uint8_t d[JT9_BIT_COUNT];
 
  uint8_t j0[JT9_BIT_COUNT];
 

	
 
  k = 0;
 

	
 
  // Build the interleave table
 
  for(i = 0; i < 255; i++)
 
  {
 
    n = 0;
 

	
 
    for(j = 0; j < 8; j++)
 
    {
 
      n = (n << 1) + ((i >> j) & 1);
 
    }
 

	
 
    if(n < 206)
 
    {
 
      j0[k] = n;
 
      k++;
 
    }
 

	
 
    if(k >= 206)
 
    {
 
      break;
 
    }
 
  }
 

	
 
  // Now do the interleave
 
  for(i = 0; i < 206; i++)
 
  {
 
    d[j0[i]] = s[i];
 
  }
 

	
 
  memcpy(s, d, JT9_BIT_COUNT);
 
  emz_memcpy(s, d, JT9_BIT_COUNT);
 
}
 

	
 
void wspr_interleave(uint8_t * s)
 
{
 
  uint8_t d[WSPR_BIT_COUNT];
 
	uint8_t rev, index_temp, i, j, k;
 

	
 
	i = 0;
 

	
 
	for(j = 0; j < 255; j++)
 
	{
 
		// Bit reverse the index
 
		index_temp = j;
 
		rev = 0;
 

	
 
		for(k = 0; k < 8; k++)
 
		{
 
			if(index_temp & 0x01)
 
			{
 
				rev = rev | (1 << (7 - k));
 
			}
 
			index_temp = index_temp >> 1;
 
		}
 

	
 
		if(rev < WSPR_BIT_COUNT)
 
		{
 
			d[rev] = s[i];
 
			i++;
 
		}
 

	
 
		if(i >= WSPR_BIT_COUNT)
 
		{
 
			break;
 
		}
 
	}
 

	
 
  memcpy(s, d, WSPR_BIT_COUNT);
 
	emz_memcpy(s, d, WSPR_BIT_COUNT);
 
}
 

	
 
void jt9_packbits(uint8_t * d, uint8_t * a)
 
{
 
  uint8_t i, k;
 
  k = 0;
 
  memset(a, 0, JT9_ENCODE_COUNT);
 

	
 
  //memset(a, 0, JT9_ENCODE_COUNT);
 
  for(uint8_t iter = 0; iter<JT9_ENCODE_COUNT; iter++)
 
  {
 
      a[iter] = 0;
 
  }
 

	
 
  for(i = 0; i < JT9_ENCODE_COUNT; i++)
 
  {
 
    a[i] = (d[k] & 1) << 2;
 
    k++;
 

	
 
    a[i] |= ((d[k] & 1) << 1);
 
    k++;
 

	
 
    a[i] |= (d[k] & 1);
 
    k++;
 
  }
 
}
 

	
 
void jt_gray_code(uint8_t * g, uint8_t symbol_count)
 
{
 
  uint8_t i;
 

	
 
  for(i = 0; i < symbol_count; i++)
 
  {
 
    g[i] = gray_code(g[i]);
 
  }
 
}
 

	
 
void jt65_merge_sync_vector(uint8_t * g, uint8_t * symbols)
 
{
 
  uint8_t i, j = 0;
 
  const uint8_t sync_vector[JT65_SYMBOL_COUNT] =
 
  {1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 0,
 
   0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1,
 
   0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1,
 
   0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1,
 
   1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1,
 
   0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1,
 
   1, 1, 1, 1, 1, 1};
 

	
 
  for(i = 0; i < JT65_SYMBOL_COUNT; i++)
 
  {
 
    if(sync_vector[i])
 
    {
 
      symbols[i] = 0;
 
    }
 
    else
 
    {
 
      symbols[i] = g[j] + 2;
 
      j++;
 
    }
 
  }
src/main.c
Show inline comments
 
@@ -52,143 +52,142 @@ void encode_wspr(void)
 
 
    // 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);
 
}
 
 
 
TIM_HandleTypeDef htim1;
 
 
int main(void)
 
{
 
    HAL_Init();
 
 
    sysclk_init();
 
    gpio_init();
 
    adc_init();
 
    i2c_init();
 
    gps_init();
 
 
 
//    jtencode_init();
 
    //jtencode_init();
 
 
    HAL_Delay(300);
 
 
    // Turn GPS on
 
    HAL_GPIO_WritePin(GPS_NOTEN, 0);
 
 
    // Disable ICs
 
    HAL_GPIO_WritePin(OSC_NOTEN, 1);
 
    HAL_GPIO_WritePin(TCXO_EN, 0);
 
 
    HAL_GPIO_TogglePin(LED_BLUE);
 
 
    // Start timer for WSPR
 
    __TIM1_CLK_ENABLE();
 
    htim1.Instance = TIM1;
 
    htim1.Init.Prescaler = 512; // 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);
 
 
 
    uint32_t led_timer = HAL_GetTick();
 
    uint32_t last_gps  = HAL_GetTick();
 
    uint32_t last_wspr  = 0xfffff; // start immediately.
 
    uint32_t last_wspr  = HAL_GetTick(); //0xfffff; // start immediately.
 
 
    HAL_GPIO_TogglePin(LED_BLUE);
 
    HAL_Delay(100);
 
    HAL_GPIO_TogglePin(LED_BLUE);
 
    HAL_Delay(100);
 
    HAL_GPIO_TogglePin(LED_BLUE);
 
    HAL_Delay(100);
 
    HAL_GPIO_TogglePin(LED_BLUE);
 
    HAL_Delay(100);
 
 
 
    while (1)
 
    {
 
        if(HAL_GetTick() - last_wspr > 120000)
 
        {
 
            //encode_wspr();
 
            encode_wspr();
 
            last_wspr = HAL_GetTick();
 
        }
 
 
        if(HAL_GetTick() - led_timer > 100)
 
        {
 
            HAL_GPIO_TogglePin(LED_BLUE);
 
            led_timer = HAL_GetTick();
 
        }
 
        if(HAL_GetTick() - last_gps > 10)
 
        {
 
            parse_gps_transmission();
 
            last_gps = HAL_GetTick();
 
        }
 
 
        //enter_sleep();
 
    }
 
}
 
 
 
void enter_sleep(void)
 
{
 
    //HAL_SuspendTick();
 
    HAL_TIM_Base_Stop_IT(&htim1);
 
    HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
 
    HAL_TIM_Base_Start_IT(&htim1);
 
    //HAL_ResumeTick();
 
}
 
 
 
void enter_deepsleep(void) 
 
{
 
    // Request to enter STOP mode with regulator in low power mode
 
    HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
 
    // After wake-up from STOP reconfigure the PLL
 
    sysclk_init();
 
}
 
 
 
// Initialize system clocks
 
void sysclk_init(void)
 
{
 
    RCC_OscInitTypeDef RCC_OscInitStruct;
 
    RCC_ClkInitTypeDef RCC_ClkInitStruct;
 
    RCC_PeriphCLKInitTypeDef PeriphClkInit;
 
 
    RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_HSI14;
 
    RCC_OscInitStruct.HSIState = RCC_HSI_ON;
 
    RCC_OscInitStruct.HSI14State = RCC_HSI14_ON;
0 comments (0 inline, 0 general)