Ejemplo n.º 1
0
/**************************************************************************************************
* @fn      hal_key_int_keys()
*
* @brief   Determine if key was and which key was pressed during interrupt
*
* @param   none
*
* @return  None
**************************************************************************************************/
uint8 hal_key_int_keys(void)                                      
{ 
  uint8 x = 0;
  /* Get bitmask of buttons pushed (clear directional keys' bitmask) */
  uint8 ucKeysPressed;
  
  ucKeysPressed = bspKeyPushed(BSP_KEY_DIR_ALL);
  if(ucKeysPressed & BSP_KEY_LEFT) {
    x |= HAL_KEY_SW_4;
  }
  if(ucKeysPressed & BSP_KEY_RIGHT) {
    x |= HAL_KEY_SW_2;
  }
  if(ucKeysPressed & BSP_KEY_UP) {
    x |= HAL_KEY_SW_1;
  }
  if(ucKeysPressed & BSP_KEY_DOWN) {
    x |= HAL_KEY_SW_3;
  }
  
  ucKeysPressed = bspKeyPushed(BSP_KEY_SELECT);
  if(ucKeysPressed & BSP_KEY_SELECT) {
    x |= HAL_KEY_SW_5;
  }
  return x;
}
Ejemplo n.º 2
0
/**************************************************************************************************
* @fn      hal_key_keys()
*
* @brief   Determine if key was pressed and which key was pressed
*
* @param   none
*
* @return  0 if no key pressed, HAL_KEY_SW bit(s) if pressed
**************************************************************************************************/
uint8 hal_key_keys(void)                                           
{                                                                 
  uint8 x = 0;
  uint8 ucKeysPressed = bspKeyPushed(BSP_KEY_ALL);
  
  if(ucKeysPressed & BSP_KEY_LEFT)
  {
    x |= HAL_KEY_SW_4;
  }
  if(ucKeysPressed & BSP_KEY_RIGHT)
  {
    x |= HAL_KEY_SW_2;
  }
  if(ucKeysPressed & BSP_KEY_UP)
  {
    x |= HAL_KEY_SW_1;
  }
  if(ucKeysPressed & BSP_KEY_DOWN)
  {
    x |= HAL_KEY_SW_3;
  }
  if(ucKeysPressed & BSP_KEY_SELECT)
  {
    x |= HAL_KEY_SW_5;
  }
  return x; 
}
Ejemplo n.º 3
0
/**************************************************************************//**
* @brief    Main function of example.
******************************************************************************/
void main(void)
{
    uint8_t ui8KeyBm = 0;
    uint_fast16_t ui16Cnt = 0;
    uint8_t ui8Byte = APP_TX_BYTE;

    //
    // Initialize clocks and board I/O
    //
    bspInit(BSP_SYS_CLK_SPD);

    //
    // Set LED1 to indicate life
    //
    bspLedSet(BSP_LED_1);

    //
    // Initialize key driver
    //
    bspKeyInit(BSP_KEY_MODE_ISR);
    bspKeyIntEnable(BSP_KEY_SELECT|BSP_KEY_UP);

    //
    // Initialize UART to USB MCU
    //
    bspUartBufInit(pui8TxBuf, sizeof(pui8TxBuf), pui8RxBuf, sizeof(pui8RxBuf));

    //
    // Application must register the UART interrupt handler
    //
    UARTIntRegister(BSP_UART_BASE, &appUartIsr);

    //
    // Open UART connection
    //
    if(bspUartOpen(eBaudRate115200) != BSP_UART_SUCCESS)
    {
        //
        // Failed to initialize UART handler
        //
        bspAssert();
    }

    //
    // Initialize SPI interface to LCD, configure LCD, and display information.
    //
    bspSpiInit(BSP_SPI_CLK_SPD);
    lcdInit();
    lcdBufferPrintStringAligned(0, "UART example", eLcdAlignCenter, eLcdPage0);
    lcdBufferInvertPage(0, 0,127, eLcdPage0);
    lcdBufferPrintString(0, "Baud rate   :", 6, eLcdPage2);
    lcdBufferPrintIntAligned(0, bspUartBaudRateGet(), eLcdAlignRight, eLcdPage2);
    lcdBufferPrintString(0, "Format      :", 6, eLcdPage3);
    lcdBufferPrintStringAligned(0, "8-N-1", eLcdAlignRight, eLcdPage3);
    lcdBufferPrintString(0, "Flow control:", 6, eLcdPage4);
    lcdBufferPrintStringAligned(0, "No", eLcdAlignRight, eLcdPage4);
    lcdBufferPrintStringAligned(0, "Transmit: UP key", eLcdAlignRight, eLcdPage6);
    lcdBufferPrintStringAligned(0, "SELECT to toggle mode", eLcdAlignCenter, eLcdPage7);
    lcdBufferInvertPage(0, 0,127, eLcdPage7);
    lcdSendBuffer(0);

    //
    // Enable global interrupts
    //
    IntMasterEnable();

    while(1)
    {
        ui8KeyBm = bspKeyPushed(BSP_KEY_ALL);

        if(BSP_KEY_SELECT & ui8KeyBm)
        {
            //
            // Change mode
            //
            bRepeaterMode ^= 1;
            bspLedToggle(BSP_LED_3);

            //
            // Update LCD for the new mode
            //
            lcdBufferClearPart(0, 0,127, eLcdPage6, eLcdPage6);
            if(bRepeaterMode)
            {
                lcdBufferPrintStringAligned(0, "Repeater mode",
                                            eLcdAlignCenter, eLcdPage6);
            }
            else
            {
                lcdBufferPrintStringAligned(0, "Transmit: UP key",
                                            eLcdAlignCenter, eLcdPage6);
            }
            lcdSendBufferPart(0, 0,127, eLcdPage6, eLcdPage6);
        }

        //
        // Read data from UART RX buffer to application buffer
        //
        ui16Cnt = bspUartDataGet(pui8AppBuf, bspUartRxCharsAvail());

        if(bRepeaterMode)
        {
            //
            // Repeater mode
            //

            if(ui16Cnt)
            {
                //
                // Send data from application buffer to UART TX buffer
                //
                bspUartDataPut(pui8AppBuf, ui16Cnt);
            }
        }
        else
        {
            //
            // Transmit mode
            //

            if(BSP_KEY_UP & ui8KeyBm)
            {
                //
                // Transmit a single character
                //
                bspUartDataPut(&ui8Byte, 1);
            }
        }
    }
}
/******************************************************************************
 * @fn          runRX
 *
 * @brief       puts radio in RX and waits for packets. Function assumes
 *              that status bytes are appended in the RX_FIFO
 *              Update packet counter and display for each packet received.
 *                
 * @param       none
 *
 * @return      none
 */
void cc120xRunRX(void){
  
  uint8 rxBuffer[128] = {0};
  uint8 rxBytes;
  uint8 marcStatus;
  
    // Write radio registers
  registerConfig();
  
  // Connect ISR function to GPIO0, interrupt on falling edge
  trxIsrConnect(&radioRxTxISR);
  
  // Enable interrupt from GPIO_0
  trxEnableInt();
   
  // Update LCD
  updateLcd();

  // Set radio in RX
  trxSpiCmdStrobe(CC120X_SRX);

  // Loop until left button is pushed (exits application)
  while(BSP_KEY_LEFT != bspKeyPushed(BSP_KEY_ALL)){
    
    // Wait for packet received interrupt 
    if(packetSemaphore == ISR_ACTION_REQUIRED){
      
      // Read number of bytes in rx fifo
      cc120xSpiReadReg(CC120X_NUM_RXBYTES, &rxBytes, 1);
      
      // Check that we have bytes in fifo
      if(rxBytes != 0){
        
        // Read marcstate to check for RX FIFO error
        cc120xSpiReadReg(CC120X_MARCSTATE, &marcStatus, 1);
        
        // Mask out marcstate bits and check if we have a RX FIFO error
        if((marcStatus & 0x1F) == RX_FIFO_ERROR){
          
          // Flush RX Fifo
          trxSpiCmdStrobe(CC120X_SFRX);
        }
        else{
        
          // Read n bytes from rx fifo
          cc120xSpiReadRxFifo(rxBuffer, rxBytes);  
          
          // Check CRC ok (CRC_OK: bit7 in second status byte)
          // This assumes status bytes are appended in RX_FIFO
          // (PKT_CFG1.APPEND_STATUS = 1.)
          // If CRC is disabled the CRC_OK field will read 1
          if(rxBuffer[rxBytes-1] & 0x80){
            
            // Update packet counter
            packetCounter++;
          }
        }
      }
      
      // Update LCD
      updateLcd();
      
      // Reset packet semaphore
      packetSemaphore = ISR_IDLE;
      
      // Set radio back in RX
      trxSpiCmdStrobe(CC120X_SRX);
      
    }
  }
  // Reset packet counter
  packetCounter = 0;
  // Put radio to sleep and exit application
  trxSpiCmdStrobe(CC120X_SPWD);
}
Ejemplo n.º 5
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();
  }
}
Ejemplo n.º 6
0
//
// Application entry point
//
int main(void)
{
    KEYBOARD_IN_REPORT keybReport;
    uint8_t keybReportSendReq = false;
    uint8_t currKey = 0x00;

    //
    // Initialize board and system clock
    //
    bspInit(SYS_CTRL_32MHZ);

    //
    // Enable the USB interface
    //
    usbHidInit();

    //
    // Initialize GPIO pins for keyboard LEDs (LED 1 on PC0 is used by USB to
    // control D+ pull-up)
    //
    GPIOPinTypeGPIOOutput(BSP_LED_BASE, BSP_LED_2 | BSP_LED_3 | BSP_LED_4);

    //
    // Configure interrupt with wakeup for all buttons
    //
    IntRegister(INT_GPIOA, selKeyRemoteWakeupIsr);
    GPIOPowIntTypeSet(BSP_KEY_SEL_BASE, BSP_KEY_SELECT, GPIO_POW_RISING_EDGE);
    IntRegister(INT_GPIOC, dirKeyRemoteWakeupIsr);
    GPIOPowIntTypeSet(BSP_KEY_DIR_BASE, BSP_KEY_DIR_ALL, GPIO_POW_RISING_EDGE);

    //
    // Initialize button polling for keyboard HID reports
    //
    memset(&keybReport, 0x00, sizeof(KEYBOARD_IN_REPORT));

    //
    // Main loop
    //
    while (1)
    {

        //
        // Process USB events
        //
        usbHidProcessEvents();

        //
        // Generate keyboard input
        //
        if (!keybReportSendReq)
        {
            switch (bspKeyPushed(BSP_KEY_ALL))
            {
            case BSP_KEY_LEFT:
                currKey = 0x50;
                break;
            case BSP_KEY_RIGHT:
                currKey = 0x4F;
                break;
            case BSP_KEY_UP:
                currKey = 0x52;
                break;
            case BSP_KEY_DOWN:
                currKey = 0x51;
                break;
            case BSP_KEY_SELECT:
                currKey = 0x28;
                break;
            default:
                currKey = 0x00;
                break;
            }
            if (currKey != keybReport.pKeyCodes[0])
            {
                keybReport.pKeyCodes[0] = currKey;
                hidUpdateKeyboardInReport(&keybReport);
                keybReportSendReq = true;
            }
        }
        if (keybReportSendReq)
        {
            if (hidSendKeyboardInReport())
            {
                keybReportSendReq = false;
            }
        }
    }

}
Ejemplo n.º 7
0
/***************************************************************************//**
 *   @brief      Runs the main routine
 *
 *               This function covers the main application code.
 *
 *   @note 		 Depending on the application, you can use either one or several
 *   			 calls from the following functions from the SIGFOX Library:
 *
 *	 @note 		\li SfxSendFrame(message, length, NULL, NULL) : Send an Uplink frame
 *   @note 		\li SfxSendFrame(message, length, ReceivedPayload, TRUE) : Downlink with ack
 *   @note 		\li SfxSendBit( 0, NULL, NULL) : Send a bit
 *   @note 		\li SfxSendOutOfBand() : Send OOB frame
 *   @note 		\li SfxTxTestMode(nb_frames, channel_number) : Tx TestModeFrame activation
 ******************************************************************************/
void
main(void)
{
	SFX_error_t volatile err;		// error returned from sigfox api functions. (For debug purpose)
#if defined(AT_CMD)
	host_cmd_status_t hostCmdStatus;
	char cmd[40];
	unsigned char length;
#endif
#if defined(PB_KEY)
	unsigned char buttonPressed;
#endif

	//Initialize the memory
	dynamic_memory_init();

	// Initialize MCU and Peripherals
	initMCU();

#ifdef __MSP430F5438A__

	// Display welcome screen on LCD
	welcomeLCD();
#endif

	// Write the uplink and downlink frequencies if device is programmed for first time
	resetCF();

	// SIGFOX library init
	err = SfxInit();
	assert(SFX_ERR_NONE == err);

	// Infinite loop
	for(;;)
	{

	GPIO_setAsOutputPin(GPIO_PORT_P4, GPIO_PIN7);
//	GPIO_setOutputLowOnPin(GPIO_PORT_P4, GPIO_PIN7);

//	P4OUT |= 0x00;
	P4OUT &= ~BIT7;
#if defined(AT_CMD)
		// Detect Carriage Return in the string
		if(uartGetRxEndOfStr() == END_OF_LINE_DETECTED)
		{
			// Reset end of string detection
			uartResetRxEndOfStr();

			// Get the input string and its length
			length = uartGetRxStrLength();
			uartGetStr(cmd, length);

			// Parse the string to find AT commands
			hostCmdStatus = parseHostCmd((unsigned char *)cmd, length);
			assert(HOST_CMD_NOT_FOUND != hostCmdStatus);
		}
#endif
#if defined(PB_KEY)
		buttonPressed = bspKeyPushed(BSP_KEY_ALL);

		// Detect button push to send the message
		if((buttonPressed == BSP_KEY_SELECT) || (buttonPressed == BSP_KEY_UP))
		{
#if defined(__MSP430F5438A__)

			// Update LCD
			updateLCD();

			// Toggle LED indicators
			bspLedClear(BSP_LED_3);
			bspLedClear(BSP_LED_4);
#endif
			bspLedClear(BSP_LED_2);
			bspLedSet(BSP_LED_1);


			if(buttonPressed == BSP_KEY_UP)
			{
				// Send uplink only frame
				err = SfxSendFrame(message, sizeof(message), NULL, NULL);
			}
			else if(buttonPressed == BSP_KEY_SELECT)
			{
				// Send a bi-directional frame
				err = SfxSendFrame(message, sizeof(message), ReceivedPayload, TRUE);
			}

			// Reset button status
			buttonPressed = 0;

#if defined (__MSP430F5438A__)

			// Clear LED1
			bspLedClear(BSP_LED_1);

			// LED indicator for sigfox API error status
			if (err == SFX_ERR_NONE) {
				bspLedSet(BSP_LED_3);
			}
			else {
				bspLedSet(BSP_LED_4);
			}

			// Update LCD
			updateLCD();

#elif defined (__MSP430F5529__)

			if (err == SFX_ERR_NONE) {
				bspLedSet(BSP_LED_2);
			}
			else {
				bspLedClear(BSP_LED_2);
			}
#endif

			// Increment in message
			message[11]++;
		}
		else
		{
#if defined (__MSP430F5438A__)

			// Set LED2
			bspLedSet(BSP_LED_2);
#elif defined (__MSP430F5529__)

			// Clear LED1
			bspLedClear(BSP_LED_1);
#endif	//MSP
		}
#endif //INTERFACE
	}
}
/******************************************************************************
* @fn          cc120x_masterStartApp
*
* @brief       
*
* input parameters
*
* @param       pDummy  - pointer to pointer to void. Not used
*
* output parameters
*
* @return      SNIFF_RETURN_SUCCESS
*/
uint8 cc120x_masterStartApp(void)
{ 
  static uint8 marcState;
  // Set first packet number
  pkt = 1;
  
  // Set up GPIO pins. For debug
  cc112xSpiWriteReg(CC120X_IOCFG3,&cc120x_gpioConfigMaster[0],4);
  
  //Display while configuring radios*
  lcdBufferClear(0);
  lcdBufferPrintString(0,"    RX Sniff Test    ",0,eLcdPage0);
  lcdBufferSetHLine(0,0,LCD_COLS-1,eLcdPage7);
  lcdBufferPrintString(0,"     Radio in TX     ",0,eLcdPage2);
  lcdBufferPrintString(0,"                 ",0,eLcdPage3);
  lcdBufferPrintString(0,"  Press right button  ",0,eLcdPage4);
  lcdBufferPrintString(0,"    to send packet  ",0,eLcdPage5);
  lcdBufferPrintString(0," 1 Abort Master Mode ",0,eLcdPage7);
  lcdBufferSetHLine(0,0,LCD_COLS-1,55);
  lcdBufferInvertPage(0,0,LCD_COLS,eLcdPage7);
  lcdSendBuffer(0);
  
  // Calibrate radio
  trxSpiCmdStrobe(CC120X_SCAL);
  
  // Wait for calibration to be done (radio back in IDLE state)
  do {
    cc120xSpiReadReg(CC120X_MARCSTATE, &marcState, 1);
  } while (marcState != 0x41);
  // Put MCU to sleep
  __low_power_mode_3();
  while(1)
  {
    if(buttonPressed = bspKeyPushed(BSP_KEY_ALL))
    {
      if(buttonPressed == BSP_KEY_LEFT)
      {
        // Left button pressed. Abort function
        // Put radio in powerdown to save power
        trxSpiCmdStrobe(CC120X_SPWD);
        //Insert Carrier Sense threshold warning in Sniff Test Menu
        drawInfo();
        
        return SNIFF_RETURN_FAILURE;
      }
      else if (buttonPressed == BSP_KEY_RIGHT)
      {        
        //Right button pressed, send packet
        lcdBufferClear(0);
        // build packet
        comArray[0] = PKTLEN;   // length field
        comArray[1] = 0x00;     // address field
        comArray[2] = pkt>>24;  // payload
        comArray[3] = pkt>>16;
        comArray[4] = pkt>>8;
        comArray[5] = pkt;
        // Update LCD
        lcdBufferPrintString(0,"    RX Sniff Test    ",0,eLcdPage0);
        lcdBufferSetHLine(0,0,LCD_COLS-1,eLcdPage7);
        lcdBufferPrintString(0,"Sent Pkt number:",0,eLcdPage3);
        lcdBufferPrintInt(0,pkt,70,eLcdPage4);
        lcdBufferPrintString(0," 1 Abort Master Mode ",0,eLcdPage7);
        lcdBufferSetHLine(0,0,LCD_COLS-1,55);
        lcdBufferInvertPage(0,0,LCD_COLS,eLcdPage7);
        lcdSendBuffer(0);
        // Update packet counter
        pkt++;
        // Strobe IDLE and fill TX FIFO
        trxSpiCmdStrobe(CC120X_SIDLE);
        // wait for radio to enter IDLE state
        while((trxSpiCmdStrobe(CC112X_SNOP)& 0xF0) != 0x00);
        cc112xSpiWriteTxFifo(comArray,PKTLEN+1);
        // Send packet
        trxSpiCmdStrobe(CC120X_STX);
        // Wait for radio to finish sending packet
        while((trxSpiCmdStrobe(CC120X_SNOP)& 0xF0) != 0x00);
        // Put radio in powerdown to save power
        trxSpiCmdStrobe(CC120X_SPWD);
        //Put MCU to sleep
        __low_power_mode_3(); 
      }
    }
  }