Esempio n. 1
0
void Intitialize_Drumset()
{
  P0SEL = 0;

  MCU_IO_OUTPUT(DRUM_PORT, DR0_PIN, 1);
  MCU_IO_OUTPUT(DRUM_PORT, DR1_PIN, 1);
  MCU_IO_OUTPUT(DRUM_PORT, DR2_PIN, 1);
  MCU_IO_OUTPUT(DRUM_PORT, DR3_PIN, 1);
  MCU_IO_OUTPUT(DRUM_PORT, DR4_PIN, 1);
  MCU_IO_OUTPUT(DRUM_PORT, DR5_PIN, 1);

  MCU_IO_INPUT(DRUM_PORT, DR0_PIN, MCU_IO_PULLUP);
  MCU_IO_INPUT(DRUM_PORT, DR1_PIN, MCU_IO_PULLUP);
  MCU_IO_INPUT(DRUM_PORT, DR2_PIN, MCU_IO_PULLUP);
  MCU_IO_INPUT(DRUM_PORT, DR3_PIN, MCU_IO_PULLUP);
  MCU_IO_INPUT(DRUM_PORT, DR4_PIN, MCU_IO_PULLUP);
  MCU_IO_INPUT(DRUM_PORT, DR5_PIN, MCU_IO_PULLUP);

  MCU_IO_INPUT(DRUM_PORT, 6, MCU_IO_PULLDOWN);
  MCU_IO_INPUT(DRUM_PORT, 7, MCU_IO_PULLDOWN);


  PICTL |= 0x01;   //High to Low Edge
  PICTL |= 0x18;    //Enable Interrupts P0ENH, P0ENL
  P0IF = 0;
  P0IFG = 0;
  P0IE = 1;

  halLedSet(1);
  halLedSet(3);

}
Esempio n. 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);
  }
}
Esempio n. 3
0
/***********************************************************************************
* @fn          halMcuInit
*
* @brief       Set Main Clock source to XOSC
*
* @param       none
*
* @return      none
*/
void halMcuInit(void)
{
	// if 32k clock change fails, set system clock to HF RC and try again
	if(clockSelect32k(CLOCK_32K_XTAL) != SUCCESS)
	{
		clockSetMainSrc(CLOCK_SRC_HFRC);
		if(clockSelect32k(CLOCK_32K_XTAL) != SUCCESS)
		{
			halLedSet(1);
			halLedSet(2);
//			HAL_ASSERT(FALSE);
		}
	}
	clockSetMainSrc(CLOCK_SRC_XOSC);
}
Esempio n. 4
0
/***********************************************************************************
* @fn          main
*
* @brief       This is the main entry of the "Light Switch" application.
*              After the application modes are chosen the switch can
*              send toggle commands to a light device.
*
* @param       basicRfConfig - file scope variable. Basic RF configuration
*              data
*              appState - file scope variable. Holds application state
*
* @return      none
*/
void main(void)
{
    uint8 appMode = NONE;

    // Config basicRF
    basicRfConfig.panId = PAN_ID;
    basicRfConfig.channel = RF_CHANNEL;
    basicRfConfig.ackRequest = TRUE;
#ifdef SECURITY_CCM
    basicRfConfig.securityKey = key;
#endif

    // Initalise board peripherals
    halBoardInit();
 //   halJoystickInit();

    // Initalise hal_rf
    if(halRfInit()==FAILED) {
      HAL_ASSERT(FALSE);
    }

    // Indicate that device is powered
    halLedSet(2);//*****************by boo LED2(P1_1=1)
    halLedClear(1);//***************by boo LED1(P1_0=0)
    
    /************Select one and shield to another***********by boo*/
    appSwitch();        //½ÚµãΪ°´¼üS1       P0_4    
    // Role is undefined. This code should not be reached
    HAL_ASSERT(FALSE);
}
Esempio n. 5
0
/***********************************************************************************
* @fn          main
*
* @brief       This is the main entry of the RF Modem application. It sets
*              distinct short addresses for the nodes, initalises and runs
*              receiver and sender tasks sequentially in an endless loop.
*
* @return      none
*/
void main(void)
{

    char *szTitle= "MRFI RF modem";
    appUartRxIdle = FALSE;

    // Initialise board peripherals
    halBoardInit();

    halUartInit(HAL_UART_BAUDRATE_38400, 0);

    // 100 ms RX idle timeout
    appConfigTimer(1000/UART_RX_IDLE_TIME);

    // Indicate that the application has been initialised
    halLcdClear();
    halLcdWriteLine(HAL_LCD_LINE_1, szTitle);
    halLedSet(1);

    // Select application role (Device 1, Device 2 or Loopback)
    appSelectRole();

    if (appRole != DEVICE_LOOPBACK) {
        // Initialize the MRFI RF link layer
        mrfiLinkInit(appLocalAddr,appRemoteAddr,MRFI_CHANNEL);
    }

    // Indicate that the modem is operating
    halLcdWriteLine(HAL_LCD_LINE_1, szTitle);

    // Initialise error counters
    nTxErr= nRxErr= 0;

    // Enable RX idle timeout interrupt
    halTimer32kIntEnable();

    //  Main processing loop
    while(TRUE) {

        // On-board device processing (UART etc.)
        HAL_PROCESS();

        if (appRole == DEVICE_LOOPBACK) {

            // Loopback processing
            appLoopbackTask();

        } else {

            // RF transmitter processing
            appRfSenderTask();

            // RF receiver processing
            appRfReceiverTask();
        }

    }
}
/***********************************************************************************
* @fn          main
*
* @brief       This is the main entry of the RF HID application. It sets
*              distinct short addresses for the nodes, initalises and runs
*              receiver and sender tasks sequentially in an endless loop.
*
* @return      none
*/
void main(void)
{

    // Initialise board peripherals
    halBoardInit();

    // Initialise USB
    usbHidInit();

    // Initialize MRFI
    mrfiLinkInit(DONGLE_ADDRESS,EB_ADDRESS,MRFI_CHANNEL);

    // Indicate that the device is initialised
    halLedSet(1);

    //  Main processing loop
    while (TRUE) {

        // Process USB standard requests
        usbHidProcessEvents();

        // Process incoming radio traffic from HID devices
        if (mrfiLinkDataRdy()) {

            uint8 numBytes;

            // Receive RF packet
            numBytes = mrfiLinkRecv(pRfData);

            // If reception successful, ACK it and send packet to host over USB
            if(numBytes>0) {

                if (pRfData[0]==KEYBOARD_DATA_ID && numBytes==KEYBOARD_DATA_SIZE) {
                    // Process keyboard data
                    usbHidProcessKeyboard(pRfData);
                    halLedToggle(1);
                }

                if (pRfData[0]==MOUSE_DATA_ID && numBytes==MOUSE_DATA_SIZE) {
                    // Process mouse data
                    usbHidProcessMouse(pRfData);
                    halLedToggle(1);
                }

            }

        }

    }

}
Esempio n. 7
0
void led_on(Ledno)
{
    switch (Ledno)
    {
    case "LED_RED":
        halLedSet(1);
    case "LED_YELLOW":
        halLedSet(2);
    case "LED_GREEN":
        halLedSet(3);
    case "LED_ALL": {
        halLedSet(1);
        halLedSet(2);
        halLedSet(3);
    }
    }
}
Esempio n. 8
0
/***********************************************************************************
* @fn          main
*
* @brief
*
* @param
*
*
* @return      none
*/
void main (void)
{
    int8 minRssi, maxRssi, rssiOffset;
    int16 barValue;
    int16 txtValue;
    uint8 barHeight, n;

    appShowText=FALSE;
    barHeight=  3;
    txtChannel= 0;

    // Initalise board peripherals
    halBoardInit();

    // Initalise hal_rf
    if(halRfInit()==FAILED) {
      HAL_ASSERT(FALSE);
    }
    // Indicate that device is powered
    halLedSet(1);

    // Print Logo and splash screen on LCD
    utilPrintLogo("Spectrum Anl");
    halMcuWaitMs(3000);

    // Calculate RSSI offset and range (must be done after setting gain mode)
    halRfSetGain(HAL_RF_GAIN_HIGH);

    rssiOffset= halRfGetRssiOffset();
    minRssi=    MIN_RSSI_DBM + rssiOffset;
    maxRssi=    MAX_RSSI_DBM + rssiOffset;

    // Config IO interrupt
    appConfigIO();

    // Set chip in RX scan mode
    halSetRxScanMode();

    // Load bar graph symbols to LCD
    utilLoadBarGraph();

    while(1) {
    	uint8 sample;
    	
        // For each RSSI sample record
        for (sample = 0; sample < SAMPLE_COUNT; sample++) {
        	uint8 channel;
            // Sample channel 11-26
            for(channel = 0; channel < CHANNELS; channel++ ) {
                ppRssi[channel][sample] = halSampleED(channel+CHANNEL_11, SAMPLE_TIME);
            }

            // Update the display with the latest graph values
            for(channel = 0; channel < CHANNELS; channel++ ) {
			
                barValue = -128;
                for (n = 0; n < SAMPLE_COUNT; n++) {
                    barValue = MAX((int8) barValue, ppRssi[channel][n]);
                }
                barValue -= minRssi;

                // Saturate
                if (barValue < 0)
                    barValue = 0;
                if (barValue > ((int16) maxRssi - (int16) minRssi))
                    barValue = (int16) maxRssi - (int16) minRssi;
                // Scale
                barValue *= (barHeight == 2) ? (8 + 1 + 8) : (8 + 1 + 8 + 1 + 8);
                barValue /= maxRssi - minRssi;

                // Display the bar
                for (n = 0; n < barHeight; n++) {
                    utilDisplayBarGraph(n + 1, channel, (barHeight - 1 - n) * 9, barValue);
                }
            }
        }

        // Show RSSI in text form on display
        if(appShowText) {
            txtValue = -128;
            barHeight=2;
            // find peak value
            for (n = 0; n < SAMPLE_COUNT; n++) {
                txtValue = MAX((int8) txtValue, ppRssi[txtChannel][n]);
            }
            txtValue -= rssiOffset;
            utilLcdDisplayValue(3, (char*)channelText[txtChannel], txtValue, " dBm");
        }
        else
            barHeight=3;
    }
}
Esempio n. 9
0
/***********************************************************************************
* @fn          main
*/
void main(void)
{
  // Initalise board peripherals
  halBoardInit();
  
  basicRfSetUp();
  
  // Initalise hal_rf
  if(halRfInit()==FAILED)
  {
    HAL_ASSERT(FALSE);
  }
  
  // Indicate that device is powered
  halLedSet(1);
  halMcuWaitMs(350);
  
  configureUSART0forUART_ALT1();
  uartStartRxForIsr();
  
  
  while(TRUE)
  {
    //----------------------
    // INITIALIZE
    //----------------------
    if(initFlag)
    {
      while(!start); //waiting for 'a' key from PC 
      //respond to PC -- going to try to start up WRS 
      start=0;
      pTxData[0] = INIT_COMM_CMD;
      basicRfReceiveOff();
      if(basicRfSendPacket(ROBOT_ADDR, pTxData, APP_PAYLOAD_LENGTH)==SUCCESS)
      {
        state=1;
      }
      basicRfReceiveOn();
      //wait for ACK from WRS
      
      pTxData[0] = INIT_COEF_CMD;
      basicRfReceiveOff();
      if(basicRfSendPacket(ROBOT_ADDR, pTxData, APP_PAYLOAD_LENGTH)==SUCCESS)
      {
        basicRfReceiveOn();
        
        //WAIT FOR COEFFICIENTS FROM WRS
        while(!basicRfPacketIsReady());//wait to receive acknowledgement
        
        if(basicRfReceive(pRxData, APP_PAYLOAD_LENGTH, NULL)>0) 
        {
          if(pRxData[0] == 'C') 
          {  
            //Pass to PC
            for (unsigned int uartTxIndex = 0; uartTxIndex<105; uartTxIndex++)
            {
              U0CSR &= ~0x02; //SET U0TX_BYTE to 0
              U0DBUF = pRxData[uartTxIndex];      
              while (!(U0CSR&0x02));
            }
          }    
        }
      }
      
      //finished sending coefficients to PC 
      
      basicRfReceiveOn();
      initFlag=0;
    }
    
    
    
    if(turnOnMotorFlag){
      if(basicRfSendPacket(ROBOT_ADDR, pTxData, APP_PAYLOAD_LENGTH)==SUCCESS)//send command to WRS
      {
        turnOnMotorFlag=0;
      }
    }
    
    if(sendInitFlag){
      if(basicRfSendPacket(ROBOT_ADDR, pTxData, APP_PAYLOAD_LENGTH)==SUCCESS)//send command to WRS
      {
        initFlag=1;
        sendInitFlag=0;
        //Pass to PC
        for (unsigned int uartTxIndex = 0; uartTxIndex<105; uartTxIndex++)
        {
          pRxData[0] == 'R';
          U0CSR &= ~0x02; //SET U0TX_BYTE to 0
          U0DBUF = pRxData[uartTxIndex];      
          while (!(U0CSR&0x02));
        }
      }
    }
    //Receive package from WRS
    if(basicRfPacketIsReady())
    { 
      
      if(basicRfReceive(pRxData, APP_PAYLOAD_LENGTH, myRSSI)>0) {
        getRSSI = basicRfGetRssi();
        pRxData[104]=getRSSI;
        if(pRxData[0] == 'D')//||(pRxData[0] == 'I'))
        {          
          //SEND DATA TO PC 
          for (unsigned int uartTxIndex = 0; uartTxIndex<105; uartTxIndex++)
          {
            U0CSR &= ~0x02; //SET U0TX_BYTE to 0
            U0DBUF = pRxData[uartTxIndex];      
            while (!(U0CSR&0x02));
          }
        }
      }
      
    }    
  }
}
Esempio n. 10
0
/***********************************************************************************
* @fn          main
*/
void main(void)
{
  // Initalise board peripherals
  halBoardInit();
  
  
  basicRfSetUp();
  
  // Initalise hal_rf
  if(halRfInit()==FAILED)
  {
    HAL_ASSERT(FALSE);
  }
  
  // Indicate that device is powered
  halLedSet(1);
  halMcuWaitMs(350);
  
  configureUSART0forUART_ALT1();
  uartStartRxForIsr();
  
  while(!start); //waiting for 'a' key from PC 
  //respond to PC -- going to try to start up WRS 
  
  pTxData[0] = INIT_COMM_CMD;
  basicRfReceiveOff();
  if(basicRfSendPacket(ROBOT_ADDR, pTxData, APP_PAYLOAD_LENGTH)==SUCCESS)
  {
    state=1;
  }
  basicRfReceiveOn();
  //wait for ACK from WRS
  
  pTxData[0] = INIT_COEF_CMD;
  basicRfReceiveOff();
  if(basicRfSendPacket(ROBOT_ADDR, pTxData, APP_PAYLOAD_LENGTH)==SUCCESS)
  {
    basicRfReceiveOn();
    
    state=2;//continuous?
    
    //WAIT FOR COEFFICIENTS FROM WRS
    while(!basicRfPacketIsReady());//wait to receive acknowledgement
    
    if(basicRfReceive(pRxData, APP_PAYLOAD_LENGTH, NULL)>0) 
    {
      if(pRxData[0] == 'C') 
      {  
        //Pass to PC
        for (unsigned int uartTxIndex = 0; uartTxIndex<105; uartTxIndex++)
        {
          U0CSR &= ~0x02; //SET U0TX_BYTE to 0
          U0DBUF = pRxData[uartTxIndex];      
          while (!(U0CSR&0x02));
        }
        // while(!ACK);//waiting for acknowledgement
      }    
    }
  }
  
  //finished sending coefficients to PC 
  
  basicRfReceiveOn();
  
  while(TRUE)
  {
    //Receive package from WRS
    if(basicRfPacketIsReady())
    { 
      
      if(basicRfReceive(pRxData, APP_PAYLOAD_LENGTH, myRSSI)>0) {
        getRSSI = basicRfGetRssi();
        pRxData[104]=getRSSI;
        if((pRxData[0] == 'P')||(pRxData[0] == 'A'))
        {          
          //SEND DATA TO PC 
          for (unsigned int uartTxIndex = 0; uartTxIndex<105; uartTxIndex++)
          {
            U0CSR &= ~0x02; //SET U0TX_BYTE to 0
            U0DBUF = pRxData[uartTxIndex];      
            while (!(U0CSR&0x02));
          }
        }
      }
      
    }
    
    //Receive CMD from PC 
    if(changePWMflag)//have this be set in interrupt 
    {
      //basicRfReceiveOff();
      
      if(basicRfSendPacket(ROBOT_ADDR, pTxData, APP_PAYLOAD_LENGTH)==SUCCESS)//send PWM info to WRS
      {
        
        changePWMflag=0;
      }
      //basicRfReceiveOn();
        
        //        while(changePWMflag)//Keep receiving until PWM acknowledge is sent
        //        {
        //          while(!basicRfPacketIsReady());//waiting for acknowledgement -- important here i think
        //          
        //          if(basicRfReceive(pRxData, APP_PAYLOAD_LENGTH, NULL)>0) 
        //          {
        //            if(pRxData[0] == 'Z')
        //            {
        //              //receive current duty cycle and send back to PC 
        //              for (unsigned int uartTxIndex = 0; uartTxIndex<105; uartTxIndex++)
        //              {
        //                U0CSR &= ~0x02; //SET U0TX_BYTE to 0
        //                U0DBUF = pRxData[uartTxIndex];      
        //                while (!(U0CSR&0x02));
        //              }
        //              changePWMflag = 0;
        //            }
        //            //else send pressure?
        //          }
        //        }
        //      }
      
    }
  }//END OF MAIN WHILE LOOP
}