/*******************************************************************************
*   @fn         initMCU
*
*   @brief      Initialize MCU and board peripherals
*
*   @param      none
*
*   @return     none
*/
static void initMCU(void) {

    // Init clocks and I/O
    bspInit(BSP_SYS_CLK_8MHZ);

    // Init LEDs
    bspLedInit();

    // Init buttons
    bspKeyInit(BSP_KEY_MODE_POLL);

    // Initialize SPI interface to LCD (shared with SPI flash)
    bspIoSpiInit(BSP_FLASH_LCD_SPI, BSP_FLASH_LCD_SPI_SPD);

    // Init LCD
    lcdInit();

    // Instantiate transceiver RF SPI interface to SCLK ~ 4 MHz
    // Input parameter is clockDivider
    // SCLK frequency = SMCLK/clockDivider
    trxRfSpiInterfaceInit(2);

    // Enable global interrupt
    _BIS_SR(GIE);
}
Beispiel #2
0
/******************************************************************************
 * @fn          main
 *
 * @brief       Main handles all applications attached to the menu system
 *
 * input parameters
 *
 * output parameters
 *
 *@return
 */
void main( void )
{
  /* Stop watchdog timer to prevent time out reset */
  WDTCTL = WDTPW + WDTHOLD;

  /* Settingcapacitor values for XT1, 32768 Hz */
  halMcuStartXT1();

  /* Clocks:
   * mclk  = mclkFrequency
   * smclk = mclkFrequency
   * aclk  = 32768 Hz
   */
  mclkFrequency = HAL_MCU_SYSCLK_16MHZ;
  halMcuSetSystemClock(mclkFrequency);

  /* Care must be taken when handling power modes
   * - Peripheral units can request clocks and have them granted even if
   *   the system is in a power mode. Peripheral clock request is enabled
   *   as default.
   * - Per test only needs ACLK to be enabled to timers
   *   during power mode operation
   */
  halMcuDisablePeripheralClockRequest((MCLKREQEN+SMCLKREQEN));


  /* SPI flash uses same SPI interface as LCD -- we'll disable the SPI flash */
 P8SEL &= BIT6; /*ioflash_csn = gp.      */
 P8DIR |= BIT6; /*tpflash_csn = ouut.    */
 P8OUT |= BIT6; /*flash_csn = 1.         */

  /* Init leds and turn them on */
  halLedInit();

  /* Init Buttons */
  halButtonsInit();
  halButtonsInterruptEnable();

  /* Instantiate tranceiver RF spi interface to SCLK = 1 MHz */
  trxRfSpiInterfaceInit(0x10);

  halLedSet(LED_1);

  initSimpleLink();

  halLedSet(LED_2);

  simpleLinkMaster();

  while(1)
  {
	  halLedSet(LED_3);
	  halTimer32kMcuSleepTicks(3276);
	  halLedClear(LED_3);
	  halTimer32kMcuSleepTicks(3276);
  }
}
void cc112x_init(void)
{
    #ifdef CC112x_DEBUG
	    printf("[CC112X] cc112x_init...\r\n");   
	#endif
#if 1
	// Disable interrupts 
	disableInterrupts();
	
	trxRfSpiInterfaceInit();
	
	GPIO_Init(GPIO_PORT_CC112X_TE, GPIO_PIN_CC112X_TE, GPIO_Mode_Out_PP_Low_Fast);
	GPIO_Init(GPIO_PORT_CC112X_RE, GPIO_PIN_CC112X_RE, GPIO_Mode_Out_PP_Low_Fast);
	GPIO_Init(GPIO_PORT_CC112X_RESET, GPIO_PIN_CC112X_RESET, GPIO_Mode_Out_PP_Low_Fast);
	GPIO_Init(GPIO_PORT_CC112X_GPIO2, GPIO_PIN_CC112X_GPIO2, GPIO_Mode_Out_PP_Low_Fast);
	GPIO_Init(GPIO_PORT_CC112X_GPIO3, GPIO_PIN_CC112X_GPIO3, GPIO_Mode_Out_PP_Low_Fast);

	GPIO_Init(GPIO_PORT_CC112X_GPIO0, GPIO_PIN_CC112X_GPIO0, GPIO_Mode_In_FL_IT);
    EXTI_SetPinSensitivity(EXTI_PIN_CC112X_GPIO0, EXTI_Trigger_CC112X_GPIO0);

	//GPIO_Init(GPIO_PORT_CC112X_GPIO2, GPIO_PIN_CC112X_GPIO2, GPIO_Mode_In_FL_IT);
    //EXTI_SetPinSensitivity(EXTI_PIN_CC112X_GPIO2, EXTI_Trigger_CC112X_GPIO2);
	
	// Enable interrupts 
	enableInterrupts();
	EXTI_ClearITPendingBit(EXTI_IT_PIN_CC112X_GPIO0);
	//EXTI_ClearITPendingBit(EXTI_IT_PIN_CC112X_GPIO2);
#else	

	GPIO_Init(GPIO_PORT_CC112X_TE, GPIO_PIN_CC112X_TE, GPIO_Mode_Out_PP_Low_Fast);
	GPIO_Init(GPIO_PORT_CC112X_RE, GPIO_PIN_CC112X_RE, GPIO_Mode_Out_PP_Low_Fast);
	GPIO_Init(GPIO_PORT_CC112X_RESET, GPIO_PIN_CC112X_RESET, GPIO_Mode_Out_PP_Low_Fast);
	GPIO_Init(GPIO_PORT_CC112X_GPIO2, GPIO_PIN_CC112X_GPIO2, GPIO_Mode_Out_PP_Low_Fast);
	GPIO_Init(GPIO_PORT_CC112X_GPIO3, GPIO_PIN_CC112X_GPIO3, GPIO_Mode_Out_PP_Low_Fast);
	GPIO_Init(GPIO_PORT_CC112X_GPIO0, GPIO_PIN_CC112X_GPIO0, GPIO_Mode_Out_PP_Low_Fast);

	GPIO_Init(GPIO_PORT_CC112X_SPI_NSS, GPIO_PIN_CC112X_SPI_NSS, GPIO_Mode_Out_PP_Low_Fast);
	GPIO_Init(GPIO_PORT_CC112X_SPI_SCK, GPIO_PIN_CC112X_SPI_SCK, GPIO_Mode_Out_PP_Low_Fast);
	GPIO_Init(GPIO_PORT_CC112X_SPI_MOSI, GPIO_PIN_CC112X_SPI_MOSI, GPIO_Mode_Out_PP_Low_Fast);
	GPIO_Init(GPIO_PORT_CC112X_SPI_MISO, GPIO_PIN_CC112X_SPI_MISO, GPIO_Mode_Out_PP_Low_Fast);
#endif
	
}
Beispiel #4
0
/******************************************************************************
 * @fn          main
 *
 * @brief       Main handles all applications attached to the menu system
 *
 * input parameters
 *
 * output parameters
 *
 *@return
 */
void main( void )
{
   
  // Init clocks and I/O 
  bspInit(BSP_SYS_CLK_16MHZ);
  
  // Init leds 
  bspLedInit(); 

  // Init Buttons
  bspKeyInit(BSP_KEY_MODE_POLL);
  
  // Initialize SPI interface to LCD (shared with SPI flash)
  bspIoSpiInit(BSP_FLASH_LCD_SPI, BSP_FLASH_LCD_SPI_SPD);  

  /* Init Buttons */
  bspKeyInit(BSP_KEY_MODE_ISR);
  bspKeyIntEnable(BSP_KEY_ALL);
  /* Init LCD and issue a welcome */
  lcdInit();
  lcdClear();
  // Instantiate tranceiver RF spi interface to SCLK ~ 4 MHz */
  //input clockDivider - SMCLK/clockDivider gives SCLK frequency
  trxRfSpiInterfaceInit(0x10);
  
  /* Welcome Screen Part */
  lcdSendBuffer(trxebWelcomeScreen);
  lcdBufferPrintString(lcdDefaultBuffer,"TEXAS",60,eLcdPage6);
  lcdBufferPrintString(lcdDefaultBuffer,"INSTRUMENTS",60,eLcdPage7);
  lcdSendBufferPart(lcdDefaultBuffer, 60,127,eLcdPage6, eLcdPage7);
  /* MCU will stay in sleep until button is pressed */
  __low_power_mode_3();
  bspKeyPushed(BSP_KEY_ALL);
  //Clear screen
  lcdBufferClear(0);

  /* Menu Driver */
  menu_t *pCurrentMenu = &mainMenu;
  uint8 menuButtonsPressed;
  menuDisplay(pCurrentMenu);
  __low_power_mode_3();
  while(1)
  {
    menuButtonsPressed = bspKeyPushed(BSP_KEY_ALL);
    switch(menuButtonsPressed)
    {
      case BSP_KEY_LEFT:
        pCurrentMenu = menuBack(pCurrentMenu);
        break;
      case BSP_KEY_RIGHT:
        pCurrentMenu = menuEnter(pCurrentMenu);
        break;
      case BSP_KEY_DOWN:
        menuDown(pCurrentMenu);
        break;
      case BSP_KEY_UP:
        menuUp(pCurrentMenu);
        break;
      default:
        break;
    }
    menuDisplay(pCurrentMenu);
    /* Enter low power mode while menu driver waits on user input */
    __low_power_mode_3();
  }
}
/***********************************************************************
  * @brief  Deal with the event handler for cc112x.
  * @param  p_event_data
  * @param  event_size
  * @retval None
************************************************************************/
void cc112x_event_handler(void * p_event_data, uint16_t event_size)
{
    cc112x_event_t * p_cc112x_event_temp = p_event_data;
	uint8_t part_num = 0;
	uint8_t i,readByte;
    
    switch(p_cc112x_event_temp->eCC112x_event)
    {
        case CC112X_INIT_EVENT:
			#ifdef CC112x_DEBUG
			    printf("[CC112X] CC112X_INIT_EVENT...\r\n");   
			#endif

			cc112x_init();
			GPIO_ResetBits(GPIO_PORT_CC112X_RESET, GPIO_PIN_CC112X_RESET);
			delay1ms(1);
			GPIO_SetBits(GPIO_PORT_CC112X_RESET, GPIO_PIN_CC112X_RESET);

			// Power Up Reset 
			rf_PowerUpReset();
			registerConfig();
			
			#ifdef CC112x_DEBUG
			    printf("[CC112X] registerConfiging OK...\r\n"); 
				cc112xSpiReadReg(CC112X_PARTNUMBER, &part_num, 1);
				printf("[CC112X] cc112xSpiReadReg,part_num = 0x%02x\r\n",part_num);   
			#endif
			
			SPI_DeInit(APP_CC112X_SPI);
			GPIO_DeInit(GPIO_PORT_CC112X_SPI_NSS);
            break;
            
        case CC112X_TRANSMIT_EVENT:
			#ifdef CC112x_DEBUG
			    printf("[CC112X] CC112X_TRANSMIT_EVENT...\r\n");   
			#endif

			trxRfSpiInterfaceInit();

			#ifdef CC112x_DEBUG	
				printf("[CC112X] cc112xSpiReadReg,part_num = 0x%02x\r\n",part_num);	 
				for(i = 0;i < (sizeof(preferredSettings)/sizeof(registerSetting_t)); i++) 
				{
					cc112xSpiReadReg(preferredSettings[i].addr, &readByte, 1);
					printf("[CC112X] i = %d : 0x%02x \r\n",i,readByte); 
				}
			#endif
			
			SPI_DeInit(APP_CC112X_SPI);
			GPIO_DeInit(GPIO_PORT_CC112X_SPI_NSS);
            break;
            
        case CC112X_RECEIVE_EVENT:
			trxRfSpiInterfaceInit();

			#ifdef CC112x_DEBUG	
				cc112xSpiReadReg(CC112X_PARTNUMBER, &part_num, 1);
				printf("[CC112X] cc112xSpiReadReg,part_num = 0x%02x\r\n",part_num);	 
				for(i = 0;i < (sizeof(preferredSettings)/sizeof(registerSetting_t)); i++) 
				{
					cc112xSpiReadReg(preferredSettings[i].addr, &readByte, 1);
					printf("[CC112X] i = %d : 0x%02x \r\n",i,readByte); 
				}
			#endif
			
			SPI_DeInit(APP_CC112X_SPI);
			GPIO_DeInit(GPIO_PORT_CC112X_SPI_NSS);
            break;
            
        default:
            break;
    }
}
/***************************************************************************//**
 *   @brief      Initialize MCU and BOARD Peripherals
 *
 *	 @note 		This function initializes the following
 *	 @note 		\li \b MCU \b Clock
 *	 @note 		\li \b BSP \b keys
 *	 @note 		\li \b BSP \b LEDs
 *	 @note 		\li \b LCD display (only for TRXEB)
 *	 @note 		\li \b RF_SPI Interface
 *	 @note 		\li \b UART interface
 *	 @note 		\li \b PA_LNA controls
 *	 @note 		\li \b TIMER Bit Rate for the symbols
 *	 @note 		\li \b INTERRUPT enable service
 *******************************************************************************/
static void
initMCU(void)
{
	// Initialize clocks and I/O
	//bspInit(BSP_SYS_CLK_20MHZ);
	bspInit(BSP_SYS_CLK_24MHZ);

	// Initialize buttons
	bspKeyInit(BSP_KEY_MODE_POLL);

	// Initialize leds
	bspLedInit();

#ifdef __MSP430F5438A__
	// Initialize SPI interface to LCD (shared with SPI flash)
	bspIoSpiInit(BSP_FLASH_LCD_SPI, BSP_FLASH_LCD_SPI_SPD);

	// Initialize LCD
	lcdInit();
#endif
	// Instantiate transceiver RF SPI interface to SCLK ~ 8 MHz */
	/* Input parameter is clockDivider
	 * SCLK frequency = SMCLK/clockDivider
	 */
	//trxRfSpiInterfaceInit(2);
	trxRfSpiInterfaceInit(3);

#ifdef AT_CMD
	// Initialize the UART interface
	halUartInit();

	// Toggle UART Echo. Disabled by default. Might cause unwanted behaviour if enabled.
	// Note: Try enabling local echo on the host console instead!
	//uartDrvToggleEcho();
#endif

#ifdef __MSP430F5529__
	// remove the reset from the rf device
	RF_RESET_N_PORT_SEL &= ~RF_RESET_N_PIN;
	RF_RESET_N_PORT_DIR |= RF_RESET_N_PIN;
	RF_RESET_N_PORT_OUT |= RF_RESET_N_PIN;
#endif
#ifdef CC1190_PA_LNA
	// initialize the IO
	RF_PA_EN_PxDIR |= RF_PA_EN_PIN;
	RF_LNA_EN_PxDIR |= RF_LNA_EN_PIN;

	// configure idle
	RF_PA_EN_PxOUT &= ~RF_PA_EN_PIN;
	RF_LNA_EN_PxOUT &= ~RF_LNA_EN_PIN;
#endif

	// Init Bitrate Timer
	/* - FCC bit rate  = 1.66ms ( 600bps )
	 * - ETSI bit rate = 10 ms  ( 100bps )
	 */
	TIMER_bitrate_init();

	// Enable global interrupt
	_BIS_SR(GIE);
}