static void prvSetupHardware( void ) { /* Convert a Hz value to a KHz value, as required by the Init_FLL_Settle() function. */ unsigned long ulCPU_Clock_KHz = ( configCPU_CLOCK_HZ / 1000UL ); halBoardInit(); LFXT_Start( XT1DRIVE_0 ); Init_FLL_Settle( ( unsigned short ) ulCPU_Clock_KHz, 488 ); halButtonsInit( BUTTON_ALL ); halButtonsInterruptEnable( BUTTON_SELECT ); /* Initialise the LCD, but note that the backlight is not used as the library function uses timer A0 to modulate the backlight, and this file defines vApplicationSetupTimerInterrupt() to also use timer A0 to generate the tick interrupt. If the backlight is required, then change either the halLCD library or vApplicationSetupTimerInterrupt() to use a different timer. Timer A1 is used for the run time stats time base6. */ halLcdInit(); halLcdSetContrast( 100 ); halLcdClearScreen(); halLcdPrintLine( " www.FreeRTOS.org", 0, OVERWRITE_TEXT ); }
/*********************************************************************************** * @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); }
static void prvSetupHardware( void ) { taskDISABLE_INTERRUPTS(); /* Disable the watchdog. */ WDTCTL = WDTPW + WDTHOLD; halBoardInit(); LFXT_Start( XT1DRIVE_0 ); hal430SetSystemClock( configCPU_CLOCK_HZ, configLFXT_CLOCK_HZ ); hal430SetSubSystemMasterClock( ); halButtonsInit( BUTTON_ALL ); halButtonsInterruptEnable( BUTTON_SELECT ); /* Initialise the LCD, but note that the backlight is not used as the library function uses timer A0 to modulate the backlight, and this file defines vApplicationSetupTimerInterrupt() to also use timer A0 to generate the tick interrupt. If the backlight is required, then change either the halLCD library or vApplicationSetupTimerInterrupt() to use a different timer. Timer A1 is used for the run time stats time base6. */ halLcdInit(); halLcdSetContrast( 100 ); halLcdClearScreen(); halLcdPrintLine( " www.FreeRTOS.org", 0, OVERWRITE_TEXT ); }
/************************************************************************************************** * @fn main * * @brief This is the C-code entry function after powerup and compiler generated inits. * * input parameters * * None. * * output parameters * * None. * * @return None. ************************************************************************************************** */ void main(void) { halBoardInit(); // Initialize the Z-Accel and the Host/RPC executive functionality. zaccelInit(); #ifdef HOST_MT mtInit(); #endif appInit(); for (;;) { /* Prioritize HAL events to maintain quasi-realtime performance on H/W related events. * After all HAL events are processed, service the ZACC events. */ if (!appExecHal()) { // If all HAL and Host events have been processed, it is ok to go to low power // for RFD/End devices. if (!appExecHost() && (appFlags & appLowPwrF)) { HAL_LOW_POWER_MODE(); } } } }
/*********************************************************************************** * @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); } } } } }
int main(void){ // stop watchdog timer WDTCTL = WDTPW + WDTHOLD; //Initialize clock and peripherals halBoardInit(); halBoardStartXT1(); halBoardSetSystemClock(SYSCLK_16MHZ); // Debug UART halUsbInit(); // show off doLCD(); // init LEDs LED_PORT_OUT |= LED_1 | LED_2; LED_PORT_DIR |= LED_1 | LED_2; /// GET STARTED /// btstack_memory_init(); run_loop_init(RUN_LOOP_EMBEDDED); // init HCI hci_transport_t * transport = hci_transport_h4_dma_instance(); bt_control_t * control = bt_control_cc256x_instance(); hci_uart_config_t * config = hci_uart_config_cc256x_instance(); remote_device_db_t * remote_db = (remote_device_db_t *) &remote_device_db_memory; hci_init(transport, config, control, remote_db); // use eHCILL bt_control_cc256x_enable_ehcill(1); // init L2CAP l2cap_init(); l2cap_register_packet_handler(packet_handler); // ready - enable irq used in h4 task __enable_interrupt(); // turn on! hci_power_control(HCI_POWER_ON); // go! run_loop_execute(); return 0; }
static void prvSetupHardware(void) { /* Convert a Hz value to a KHz value, as required by the Init_FLL_Settle() function. */ unsigned long ulCPU_Clock_KHz = (25000000UL / 1000UL ); /* Disable the watchdog. */ WDTCTL = WDTPW + 0x36; SFRIE1 |= WDTIE; /* select port pin functions */ halBoardInit(); LFXT_Start(XT1DRIVE_0); /* enable oszillator */ Init_FLL_Settle((unsigned short) ulCPU_Clock_KHz, 488); /* clock divisor */ }
static void hw_setup(){ // stop watchdog timer WDTCTL = WDTPW + WDTHOLD; //Initialize clock and peripherals halBoardInit(); halBoardStartXT1(); halBoardSetSystemClock(SYSCLK_16MHZ); // init debug UART halUsbInit(); // init LEDs LED_PORT_OUT |= LED_1 | LED_2; LED_PORT_DIR |= LED_1 | LED_2; // ready - enable irq used in h4 task __enable_interrupt(); }
/*********************************************************************************** * @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; } }
// main int main(void) { // stop watchdog timer WDTCTL = WDTPW + WDTHOLD; //Initialize clock and peripherals halBoardInit(); halBoardStartXT1(); halBoardSetSystemClock(SYSCLK_16MHZ); // init debug UART halUsbInit(); // init LEDs LED_PORT_OUT |= LED_1 | LED_2; LED_PORT_DIR |= LED_1 | LED_2; /// GET STARTED with BTstack /// btstack_memory_init(); run_loop_init(RUN_LOOP_EMBEDDED); // init HCI hci_transport_t * transport = hci_transport_h4_dma_instance(); bt_control_t * control = bt_control_cc256x_instance(); hci_uart_config_t * config = hci_uart_config_cc256x_instance(); remote_device_db_t * remote_db = (remote_device_db_t *) &remote_device_db_memory; hci_init(transport, config, control, remote_db); // use eHCILL bt_control_cc256x_enable_ehcill(1); // init L2CAP l2cap_init(); l2cap_register_packet_handler(packet_handler); // init RFCOMM rfcomm_init(); rfcomm_register_packet_handler(packet_handler); rfcomm_register_service_with_initial_credits_internal(NULL, rfcomm_channel_nr, 100, 1); // reserved channel, mtu=100, 1 credit // init SDP, create record for SPP and register with SDP sdp_init(); memset(spp_service_buffer, 0, sizeof(spp_service_buffer)); service_record_item_t * service_record_item = (service_record_item_t *) spp_service_buffer; sdp_create_spp_service( (uint8_t*) &service_record_item->service_record, 1, "SPP Counter"); printf("SDP service buffer size: %u\n\r", (uint16_t) (sizeof(service_record_item_t) + de_get_len((uint8_t*) &service_record_item->service_record))); sdp_register_service_internal(NULL, service_record_item); // set one-shot timer timer_source_t heartbeat; heartbeat.process = &heartbeat_handler; run_loop_set_timer(&heartbeat, HEARTBEAT_PERIOD_MS); run_loop_add_timer(&heartbeat); puts("SPP FlowControl Demo: simulates processing on received data...\n\r"); // ready - enable irq used in h4 task __enable_interrupt(); // turn on! hci_power_control(HCI_POWER_ON); // go! run_loop_execute(); // happy compiler! return 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)); } } } } } }
int main(void) { uint8_t currState; uint8_t targetState; uint16_t readbcLength; uint32_t nwkId; uint8_t errorCheckInterval = 100; // Stop watchdog timer to prevent time out reset WDTCTL = WDTPW + WDTHOLD; // Initialize the MCU and board peripherals halBoardInit(); halBoardStartXT1(); halBoardSetSystemClock(SYSCLK_16MHZ); halButtonsInit(BUTTON_ALL); halLcdInit(); halLcdBackLightInit(); halLcdSetContrast(90); halLcdSetBackLight(10); halLcdClearScreen(); halLcdPrintLine(" CC85XX SLAVE ", 0, OVERWRITE_TEXT ); halLcdPrintLine(" ", 1, OVERWRITE_TEXT ); halLcdPrintLine("S1: Power toggle ", 2, OVERWRITE_TEXT ); halLcdPrintLine("S2: Pairing start", 3, OVERWRITE_TEXT ); uifLcdPrintJoystickInfo(); // Wipe remote control information memset(&ehifRcSetDataParam, 0x00, sizeof(ehifRcSetDataParam)); // Initialize EHIF IO ehifIoInit(); // Reset into the application ehifSysResetPin(true); currState = CC85XX_STATE_ALONE; targetState = CC85XX_STATE_ACTIVE; // Get the last used network ID from CC85XX non-volatile storage initParam(); ehifCmdParam.nvsGetData.index = 0; ehifCmdExecWithRead(EHIF_EXEC_ALL, EHIF_CMD_NVS_GET_DATA, sizeof(EHIF_CMD_NVS_GET_DATA_PARAM_T), &ehifCmdParam, sizeof(EHIF_CMD_NVS_GET_DATA_DATA_T), &ehifCmdData); nwkId = ehifCmdData.nvsGetData.data; // Handle illegal default network IDs that may occur first time after programming if ((nwkId == 0x00000000) || (nwkId == 0xFFFFFFFF)) { nwkId = 0xFFFFFFFE; } // Main loop while (1) { // Wait 10 ms EHIF_DELAY_MS(10); // Perform action according to edge-triggered button events (debouncing with 100 ms delay) switch (pollButtons()) { // POWER TOGGLE case BUTTON_S1: if (currState == CC85XX_STATE_OFF) { targetState = CC85XX_STATE_ACTIVE; } else { targetState = CC85XX_STATE_OFF; } break; // PAIRING TRIGGER case BUTTON_S2: if (currState != CC85XX_STATE_OFF) { targetState = CC85XX_STATE_PAIRING; } break; } // Run the state machine if (currState != targetState) { if (currState == CC85XX_STATE_OFF) { // HANDLE POWER ON // Ensure known state (power state 5) ehifSysResetPin(true); currState = CC85XX_STATE_ALONE; } else if (targetState == CC85XX_STATE_OFF) { // HANDLE POWER OFF // Ensure known state (power state 5) ehifSysResetPin(true); currState = CC85XX_STATE_ALONE; // Set power state 0 ehifCmdParam.pmSetState.state = 0; ehifCmdExec(EHIF_CMD_PM_SET_STATE, sizeof(EHIF_CMD_PM_SET_STATE_PARAM_T), &ehifCmdParam); currState = CC85XX_STATE_OFF; } else if (targetState == CC85XX_STATE_PAIRING) { // HANDLE PAIRING // Let the last executed EHIF command complete, with 5 second timeout ehifWaitReadyMs(5000); // Disconnect if currently connected if (ehifGetStatus() & BV_EHIF_STAT_CONNECTED) { initParam(); // All parameters should be zero ehifCmdExec(EHIF_CMD_NWM_DO_JOIN, sizeof(EHIF_CMD_NWM_DO_JOIN_PARAM_T), &ehifCmdParam); } // Search for one protocol master with pairing signal enabled for 10 seconds initParam(); ehifCmdParam.nwmDoScan.scanTo = 1000; ehifCmdParam.nwmDoScan.scanMax = 1; ehifCmdParam.nwmDoScan.reqPairingSignal = 1; ehifCmdParam.nwmDoScan.reqRssi = -128; ehifCmdExecWithReadbc(EHIF_EXEC_CMD, EHIF_CMD_NWM_DO_SCAN, sizeof(EHIF_CMD_NWM_DO_SCAN_PARAM_T), &ehifCmdParam, NULL, NULL); // Fetch network information once ready ehifWaitReadyMs(12000); readbcLength = sizeof(ehifNwmDoScanData); ehifCmdExecWithReadbc(EHIF_EXEC_DATA, EHIF_CMD_NWM_DO_SCAN, 0, NULL, &readbcLength, &ehifNwmDoScanData); // If found ... if (readbcLength == sizeof(EHIF_CMD_NWM_DO_SCAN_DATA_T)) { // Update the network ID to be used next nwkId = ehifNwmDoScanData.deviceId; // Place the new network ID in CC85XX non-volatile storage initParam(); ehifCmdParam.nvsSetData.index = 0; ehifCmdParam.nvsSetData.data = ehifNwmDoScanData.deviceId; ehifCmdExec(EHIF_CMD_NVS_SET_DATA, sizeof(EHIF_CMD_NVS_SET_DATA_PARAM_T), &ehifCmdParam); } // Done currState = CC85XX_STATE_ALONE; targetState = CC85XX_STATE_ACTIVE; } else if (targetState == CC85XX_STATE_ACTIVE) { // We're disconnected. Proceed only if EHIF is ready, so that power toggle and pairing // buttons can still be operated uint16_t status = ehifGetStatus(); if (status & BV_EHIF_STAT_CMD_REQ_RDY) { // Perform join operation first and then activate audio channels. We're using remote // volume control if (!(status & BV_EHIF_STAT_CONNECTED)) { // Enable disconnection notification to avoid unnecessary EHIF activity while active initParam(); ehifCmdParam.ehcEvtClr.clearedEvents = BV_EHIF_EVT_NWK_CHG; ehifCmdExec(EHIF_CMD_EHC_EVT_CLR, sizeof(EHIF_CMD_EHC_EVT_CLR_PARAM_T), &ehifCmdParam); initParam(); ehifCmdParam.ehcEvtMask.irqGioLevel = 0; ehifCmdParam.ehcEvtMask.eventFilter = BV_EHIF_EVT_NWK_CHG; ehifCmdExec(EHIF_CMD_EHC_EVT_MASK, sizeof(EHIF_CMD_EHC_EVT_MASK_PARAM_T), &ehifCmdParam); // Not connected: Start JOIN operation initParam(); ehifCmdParam.nwmDoJoin.joinTo = 100; ehifCmdParam.nwmDoJoin.deviceId = nwkId; ehifCmdExec(EHIF_CMD_NWM_DO_JOIN, sizeof(EHIF_CMD_NWM_DO_JOIN_PARAM_T), &ehifCmdParam); } else { // Connected: Subscribe to audio channels (0xFF = unused) memset(&ehifCmdParam, 0xFF, sizeof(EHIF_CMD_NWM_ACH_SET_USAGE_PARAM_T)); ehifCmdParam.nwmAchSetUsage.pAchUsage[0] = 0; // Front left -> I2S LEFT ehifCmdParam.nwmAchSetUsage.pAchUsage[1] = 1; // Front right -> I2S RIGHT ehifCmdExec(EHIF_CMD_NWM_ACH_SET_USAGE, sizeof(EHIF_CMD_NWM_ACH_SET_USAGE_PARAM_T), &ehifCmdParam); currState = CC85XX_STATE_ACTIVE; } } } } else { // Only OFF and ACTIVE are permanent target states. SCAN is only a temporary target state. // In the OFF state we do nothing, so only need to handle the ACTIVE state. if (currState == CC85XX_STATE_ACTIVE) { // Detect network disconnection without generating noise on the SPI interface if (EHIF_INTERRUPT_IS_ACTIVE()) { currState = CC85XX_STATE_ALONE; } // Perform error checking at 10 ms * 100 = 1 second intervals: // - No timeouts or SPI errors shall have occurred // - We should be connected unless disconnection has been signalized if (--errorCheckInterval == 0) { errorCheckInterval = 100; uint16_t status = ehifGetStatus(); if (ehifGetWaitReadyError() || (status & BV_EHIF_EVT_SPI_ERROR) || (!(status & BV_EHIF_STAT_CONNECTED) && !(status & BV_EHIF_EVT_NWK_CHG))) { // The device is in an unknown state -> restart everything ehifSysResetPin(true); currState = CC85XX_STATE_ALONE; } } // If the network connection is up and running... if (currState == CC85XX_STATE_ACTIVE) { // Send remote control commands (mouse or play control, depending on which uif file // is included in the build) if (uifPollFunc(&ehifRcSetDataParam)) { ehifCmdExec(EHIF_CMD_RC_SET_DATA, sizeof(EHIF_CMD_RC_SET_DATA_PARAM_T), &ehifRcSetDataParam); } } } } } } // main
void main( void ) { unsigned int ucState=0xffff; unsigned char test[10]; memset(test,'\0',10); int i=0; halBoardInit(); hal430SetSystemClock(); halButtonsInit(); Init_Uart(115200); Init_Lcd(); Msp430_ADC12_Init(); Write_NByte((unsigned char *)eeprom,10,0); Read_NByte_Randomaddress(test,10,0); printf("main %s\r\n",test); while(1) { if(flag==1) { //WDTCTL = WDTPW + WDTNMI + WDTTMSEL + WDTSSEL + WDTCNTCL; // Start watchdog timer //IE1 |= WDTIE; // Enable WDT interrupt printf("we are in active state\r\n"); //这里写自己的程序,把程序做在一个有限的循环里,这样做完之后就可以自动结束并关机。 for(i=0;i<1000;i++){ ucState = halButtonsPressed(); if(ucState!=0xffff) { i=0; send_wave(); hal_buzzer(2); Get_Power(); //printf("%x is pressed\r\n",ucState); switch(ucState) { case BUTTON_MATL: printf("matl is pressed\r\n"); break; case BUTTON_HARD: printf("hard is pressed\r\n"); break; case BUTTON_DIREC: printf("direc is pressed\r\n"); break; case BUTTON_TIMES: printf("times is pressed\r\n"); break; case BUTTON_SAVE: printf("save is pressed\r\n"); break; case BUTTON_UP: printf("up is pressed\r\n"); break; case BUTTON_DEL: printf("del is pressed\r\n"); break; case BUTTON_AVE: printf("ave is pressed\r\n"); break; case BUTTON_LEFT: printf("left is pressed\r\n"); break; case BUTTON_MENU: printf("menu is pressed\r\n"); break; case BUTTON_RIGHT: printf("right is pressed\r\n"); break; case BUTTON_BACKLIGHT: printf("backlight is pressed\r\n"); break; case BUTTON_ESC: printf("esc is pressed\r\n"); break; case BUTTON_DOWN: printf("down is pressed\r\n"); break; case BUTTON_ENTER: printf("enter is pressed\r\n"); break; default: break; } } //LPM3; Delay(100); } //如需定时,上边这个LPM3要被包括在那个有循环的循环体中,这样才能实现类似便携式仪表5分钟自动关机的效果。如果不使用定时也可以不要LPM3这句话。 //WDTCTL = WDTPW + WDTHOLD + WDTNMI; // Stop watchdog timer flag=0; } else { //如果周边设备在关机时有需要复位的或是关闭的在这里处理 printf("we are in power off state\r\n"); } hal_buzzer(0); printf("we going to LPM4\r\n"); LPM4; } }
/*********************************************************************************** * @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 }
// main int main(void) { // stop watchdog timer WDTCTL = WDTPW + WDTHOLD; //Initialize clock and peripherals halBoardInit(); halBoardStartXT1(); halBoardSetSystemClock(SYSCLK_16MHZ); // init debug UART halUsbInit(); // init LEDs P1OUT |= LED_1 | LED_2; P1DIR |= LED_1 | LED_2; /*//init linkLED P1OUT &= ~BIT0; P1DIR |= BIT0;*/ //Setup Input Port 2 initSwitch(2, BIT0); initSwitch(2, BIT1); initSwitch(2, BIT2); initSwitch(2, BIT3); //tie port3 and unused pins of port 2 /*P3OUT = 0; P3DIR = 0xFF; P3SEL = 0; P2OUT &= 0x0F; P2DIR |= 0xF0; P2SEL &= 0x0F;*/ /// GET STARTED with BTstack /// btstack_memory_init(); run_loop_init(RUN_LOOP_EMBEDDED); // add gpio port 2 to run loop // default values port2_status = P2IN & 0x0F; data_source_t data_src_port2; data_src_port2.process = port2_poll; data_src_port2.fd = 0; run_loop_add_data_source(&data_src_port2); // init HCI hci_transport_t * transport = hci_transport_h4_dma_instance(); bt_control_t * control = bt_control_cc256x_instance(); hci_uart_config_t * config = hci_uart_config_cc256x_instance(); remote_device_db_t * remote_db = (remote_device_db_t *) &remote_device_db_memory; hci_init(transport, config, control, remote_db); // use eHCILL bt_control_cc256x_enable_ehcill(1); // init L2CAP l2cap_init(); l2cap_register_packet_handler(bt_packet_handler); l2cap_register_service_internal(NULL, l2cap_packet_handler, 0x1001, L2CAP_MINIMAL_MTU); // ready - enable irq used in h4 task __enable_interrupt(); // turn on! if(hci_power_control(HCI_POWER_ON)) printf("power on failed"); //init i2c initi2c(); // go! run_loop_execute(); // happy compiler! return 0; }