int main(int argc, char *argv[]) { if(argc>1){ initUart(argv[1]); }else{ initUart(UART); } char buf[BUFLEN]; if ((s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP))==-1) { diep("socket"); } memset((char *) &si_me, 0, sizeof(si_me)); si_me.sin_family = AF_INET; si_me.sin_port = htons(PORT); si_me.sin_addr.s_addr = htonl(INADDR_ANY); if (bind(s, &si_me, sizeof(si_me))==-1) { diep("bind"); } multiWiiInit(multiwiiBuf,sendDataBack); //Start thread for UART pthread_t receive_thread; if(pthread_create(&receive_thread, NULL, receive, NULL)) { diep("Error creating thread"); } int len=0; while (1) { if ((len = recvfrom(s, buf, BUFLEN, 0, &si_other, &slen)) == -1) { diep("recvfrom()"); } // printf("data received\n"); multiWiiStartTransmission(buf,len); //inet_ntoa(si_other.sin_addr), ntohs(si_other.sin_port), buf); } close(s); return 0; }
void main(void) { /* stop the watchdog timer */ WDTCTL = WDTPW + WDTHOLD; /* For debouncing: set the auxilliary clock to use very low-power * oscillator. Later, we'll have the Watchdog timer use the * auxilliary clock for debouncing the button. */ BCSCTL3 |= LFXT1S_2; /* LEDs off, but later we'll blink them as we send bits */ P1DIR |= RED_LED+GRN_LED; P1OUT &= ~ (RED_LED + GRN_LED ); initUart(); /* We'll use the button to let the chip know we're ready to communicate. * Direction is receive, clear interrupt flag, and * interrupts are enabled. */ P1DIR &= ~BUTTON; P1IFG &= ~BUTTON; P1IE |= BUTTON; for( ; ; ) { /* go to sleep until button press */ __bis_SR_register( LPM3_bits + GIE ); sendString( "Hello, world!\r\n" ); } }
void SpiUartDevice::begin(unsigned long baudrate /* default value */) { /* */ SpiDevice::begin(); initUart(baudrate); }
void SpiUartDevice::begin() { /* */ SpiDevice::begin(); initUart(); }
void main (void) { DDRB = 0xff; PORTB = 0; initUart(9600, 0); #ifdef DEBUG printHelp(NULL); #endif // initialize the 16-bit timer TCCR1A = _BV(COM1A1); TCCR1B |= TIMER1_CLOCKSOURCE; TIMSK = _BV (TOIE1); memset(info, 0, sizeof(struct LED_INFO) * 8); process = force = 0; sei (); while(1) { if(UCSRA & (1 << RXC)) processCommand(); } }
int main(void){ #if PROTOCOL==PROTO_JUMPER uint8_t autoproto; #endif MCUSR = 0; wdt_disable(); CLKPR = 0x80; CLKPR = 0x00; initUart(); spiInitMaster(SPI_CLOCKRATE); #if PROTOCOL==PROTO_SEDU_BUGGY buggySeduLoop(); #elif PROTOCOL==PROTO_SEDU seduLoop(); #elif PROTOCOL==PROTO_TPM2 tpm2Loop(); #elif PROTOCOL==PROTO_JUMPER autoproto = getProtoJumper(); if( autoproto == PROTO_SEDU_BUGGY ) buggySeduLoop(); else if( autoproto == PROTO_SEDU ) seduLoop(); else if( autoproto == PROTO_TPM2 ) tpm2Loop(); #endif return 0; }
/****************************************************************************** * @fn zb_HandleOsalEvent * * @brief The zb_HandleOsalEvent function is called by the operating * system when a task event is set * * @param event - Bitmask containing the events that have been set * * @return none */ void zb_HandleOsalEvent( uint16 event ) { uint8 logicalType; if(event & SYS_EVENT_MSG) { } if( event & ZB_ENTRY_EVENT ) { // Initialise UART initUart(uartRxCB); // blind LED 1 to indicate starting/joining a network #ifndef SYS_DEBUG_SH HalLedBlink ( HAL_LED_1, 0, 50, 500 ); #endif HalLedSet( HAL_LED_2, HAL_LED_MODE_OFF ); // Read logical device type from NV zb_ReadConfiguration(ZCD_NV_LOGICAL_TYPE, sizeof(uint8), &logicalType); // Start the device zb_StartRequest(); #ifdef SYS_DEBUG_SH // Turn ON Allow Bind mode infinitly zb_AllowBind( 0xFF ); HalLedSet( HAL_LED_2, HAL_LED_MODE_ON ); #endif } if ( event & MY_START_EVT ) { zb_StartRequest(); } if ( event & MY_REPORT_EVT ) { if (isGateWay) { osal_start_timerEx( sapi_TaskID, MY_REPORT_EVT, myReportPeriod ); } else if (appState == APP_BINDED) { sendDummyReport(); osal_start_timerEx( sapi_TaskID, MY_REPORT_EVT, myReportPeriod ); } } if ( event & MY_FIND_COLLECTOR_EVT ) { // Find and bind to a gateway device (if this node is not gateway) if (!isGateWay) { zb_BindDevice( TRUE, DUMMY_REPORT_CMD_ID, (uint8 *)NULL ); } } }
extern "C" void SystemInit(void) { System_InitializeClock(); //! \todo FPU settings should go into the peripheral description file. // Enable the FPU coprocessor. *((volatile unsigned long*)0xE000ED88) = 0xF << 20; initUart(); }
void initialization() { sei(); setupMillisTimers(); initFirmata(); systemReset(); initUart(1,BAUD_115200); #ifdef PLUS_BOARD initUart(0,getSavedBaudRateFromEeprom()); #endif #ifdef CLASSIC_BOARD initUart(0,BAUD_115200); #endif setUnusedPinsAsOutput(); setupUartLeds(); requestBluetoothReset(); sendIsAlive(); }
void SpiUartDevice::begin(unsigned long baudrate) { /* * Initialize SPI and UART communications * * Uses BAUD_RATE_DEFAULT as baudrate if none is given */ SPI.begin(); initUart(baudrate); }
/** * @brief Esta función es llamada por el SO cuando se debe atender un * evento de la tarea. * @param event Mascara de bits conteniendo los eventos a atender */ void zb_HandleOsalEvent(uint16 event) { uint8 logicalType; if (event & SYS_EVENT_MSG) { } if (event & ZB_ENTRY_EVENT) { // inicializa UART initUart(uartRxCB); // blick LED 1 para indicar que se está uniendo a la red HalLedBlink(HAL_LED_1, 0, 50, 500 ); HalLedSet(HAL_LED_2, HAL_LED_MODE_OFF); // lee tipo de logical device desde la memoria NV zb_ReadConfiguration(ZCD_NV_LOGICAL_TYPE, sizeof(uint8), &logicalType); // inicia la red zb_StartRequest(); } if (event & MY_START_EVT) { // inicia la red zb_StartRequest(); } if (event & SEND_UART_MSG) { // envia mensaje por UART a la PC //HalLcdWriteString("UART_EVT", HAL_LCD_LINE_1); sendUartMessage(&msgReport, &alarmFlags); } if (event & MY_TEST_EVT) { // crea mensaje de prueba msgReport.msgType = MSG_TYPE_REPORT; msgReport.sequence++; msgReport.lenData = MSG_LEN_DATA_REPORT; for (uint8 i = 0; i < 8; i++) msgReport.mac[i] = i; // datos de prueba static double d[10] = {220.5, 0.354, 85.12, 88.33, 85.06, 0.98, 1.23, 3.25, 0.97, 4.55}; for (int i = 0; i < 10; i++) memcpy(&(msgReport.data[i*4]), &(d[i]), sizeof(double)); // flags de prueba uint16 flags = 0; // imprime info en LCD HalLcdWriteString("TEST_EVT", HAL_LCD_LINE_1); HalLcdWriteStringValue("#", msgReport.sequence, 10, HAL_LCD_LINE_2); // envia mensaje por UART sendUartMessage(&msgReport, &flags); // crea evento nuevamente osal_start_timerEx(sapi_TaskID, MY_TEST_EVT, 5000); } }
int main( void ) { initUart(); //wait to receive data c = 0; ES = 1; EA = 1; while( 1 ); return 0; }
extern "C" void SystemInit(void) { System_InitializeClock(); //! \todo FPU settings should go into the peripheral description file. // Enable the FPU coprocessor. //SCB->CPACR = uint32_t(0xF) << 20; *((volatile uint32_t*)0xE000ED88) = uint32_t(0xF) << 20; // Trap on unaligned memory accesses. //SCB->CCR |= uint32_t(8); *((volatile uint32_t*)0xE000ED14) = uint32_t(8); initUart(); }
int main() { trace_puts(">>> VfdClock main() init"); initGpio(); initRtc(); initTimer(); initUart(); SysTick_Config(72000); // 1kHz trace_puts("<<< VfdClock main() init"); GPIO_WriteBit(LED_PORT, LED_PIN, RESET); // Disable buzzer. GPIO_WriteBit(BUZ_PORT, BUZ_PIN, RESET); TIM_Cmd(TIM3, DISABLE); backupLoad(); uint8_t digits[6] = { DIGIT_BLANK, DIGIT_DASH, DIGIT_DASH, DIGIT_DASH, DIGIT_DASH, DIGIT_BLANK}; setDisplay(digits); gSeconds = RTC_GetCounter(); time_t localtime; struct tm *t = gmtime(&gSeconds); // Logic loop. while (1) { // Read GPS data, if it exists. if (strlen(gGpsLine) > 0) { handleGpsLine(); } else if (gGpsNextPoll < gSeconds) { gpsSetPushFreq("ZDA", 2); } handleDigits(digits, t); handleButtonPress(); if (gSecondFlag) { gSecondFlag = 0; localtime = gSeconds + gUtcOffset; t = gmtime(&localtime); handleDigits(digits, t); setDisplay(digits); // Blink decimal point. GPIO_WriteBit(DP_PORT, DP_PIN, SET); gDpTick = 500; } } }
int main( void ) { unsigned long c; unsigned char recByte; initUart(); //wait to receive data c = 0; RI = 0; while( 1 ) { recByte = receiveByte(); xArrayAt4000[c++] = recByte; } return 0; }
int main( void ) { char *hello = "Greeting From IMS@SCUT. rem"; unsigned char cnt; //1200baud use timer1 initUart( ); cnt = 0x4F - 0x30 + 1; location = 0; ES = 1; //enable uart interrupt EA = 1; //enable golbal inteerupt whoAmI = (unsigned char )type; if( TRANS == whoAmI ) //I am the transifer I will transfer 30H~4FH idata { //let the receiver get a little ready delay_uc( 50 ); //first initial the 30H~4FH idata to the data I want p = 0x30; memcpy( p , hello , strlen(hello) ); memset( p+strlen(hello) , 'L' , cnt - strlen(hello )); SBUF = p[location++]; //use interrupt to transfer; } else //I am the receiver I will receive an put at 50H~6FH { p = 0x50; memset( p , 'R' , cnt ); } while( 1 ); return 0; }
void init(void) { // LEDs DDRC |= (1 << PC0); DDRD |= (1 << PD0); // Switch PORTD |= (1 << PD2); #ifdef DEBUG initUart(); #endif initCan(); // POC - led dimming POCR_RB = 4000; PCNF = (1 << POPA) | (1 << POPB); PMIC0 = (1 << POVEN0); PMIC1 = (1 << POVEN1); POCR0SA = 0; POCR0RA = 0; POCR1SA = 0; POCR1RA = 0; PCTL = (1 << PRUN); POC = (1 << POEN1A) | (1 << POEN0A); // Timer 0 - Mainloop TCCR0A = (1 << WGM01); // CTC mode, TCCR0B = (1 << CS01); OCR0A = 200 - 1; // Prescalar 8, TOP 200 -> 10000 Hz TIMSK0 = (1 << OCIE0A); // Output compare interrupt enable // Timer 1 - WSS Emulation TCCR1A = (1 << COM1B1) | (1 << COM1B0) | (1 << WGM10); TCCR1B = (1 << WGM13) | (1 << CS11); DDRC |= (1 << PC1); freq = 100; // Enable Interrupts sei(); }
void init() { printf("start init \n"); initArrays(); if(initDatabaseConnection() == 1) { printf("error setting up database connection\n"); } if(initUart() == 1) { printf("error connecting to serial device\n"); } if(initServerConnection() == 1) { printf("error setting up database connection\n"); } getDeviceID(); sendDeviceIP(); printf("init done\n"); }
int main (void) { DDRB = 0xff; PORTB = 0x00; initUart(9600, 0); printf("Synchronous serial test:\n"); printf("Type something and I'll cough it back...\n"); uint16_t count = 0; char buffer[128]; while(1) { char c = getchar(); PORTB |= _BV(0); sprintf(buffer, "%d: got %c (0x%x)\n", count++, c, c); printf(buffer); PORTB &= ~_BV(0); } }
int main(void) { /* stop the watchdog timer */ WDTCTL = WDTPW + WDTHOLD; /* set up the clocks for 1 mhz */ BCSCTL1 = CALBC1_1MHZ; // Set range DCOCTL = CALDCO_1MHZ; BCSCTL2 &= ~(DIVS_3); // SMCLK = DCO / 8 = 1Mhz /* LEDs off, but we can use them for debugging if we want */ P1DIR |= RED_LED+GRN_LED; P1OUT &= ~ (RED_LED + GRN_LED ); initUart(); /* Start listening for data */ UART_Start(); /* enable interrupts */ __bis_SR_register( GIE ); uartPrint("\n\rCli Started.\n\r"); cliHelp(); uartPrint(PROMPT); char in_char; while(1) { while(rx_size() > 0) { in_char = uartGetChar(); uartPutChar(in_char); cli_input(in_char); } /* go to sleep and wait for data */ __bis_SR_register( LPM0_bits ); } }
/** ****************************************************************************** ** \简 述 初始化MCU系统,包括看门狗、系统时钟、GPIO和各种需要的外设 ** ** \参 数 none ** \返回值 none ******************************************************************************/ void initMCU(void) { initGpio(); LED1 = LED_ON; LED2 = LED_ON; LED3 = LED_ON; LEDRED = LED_ON; LEDGRN = LED_ON; delay100ms(2); LED1 = LED_OFF; LED2 = LED_OFF; LED3 = LED_OFF; LEDRED = LED_OFF; LEDGRN = LED_OFF; initUart(); initSPI(); initButton(); UsbConfig_UsbInit(); UsbDeviceCdcCom_SetSeparator('\r'); // there is the possibility to set end of buffer by a seperator UsbDeviceCdcCom_SetEchomode(TRUE); // all input shall be echoed UsbConfig_SwitchMode(); __enable_interrupt(); }
int main( void) { int tmp; int ip_fd; int fd; int ran_num; int m_ip, t_ip, b_ip, l_ip, r_ip; char buf[3]= {0,}; char send_data[17]= {0,}; char ip_temp[15]= {0,}; char ipBuf[15]= {0,}; char ip; int cnt; int i; ip_fd=open("./config_MyIp",O_RDONLY); // sleep(1); tmp = read(ip_fd,(char*)buf,sizeof(buf)+1); // printf("%d\n",tmp); if (tmp <0) { perror ("read\n"); exit(1); } m_ip=atoi(buf); fd=initUart(); srand((unsigned)time(NULL)); while(1) { // printf("%d\n",ip); strncpy(ip_temp+12,buf,3); cnt=get_IpInfo(3,ipBuf); if(cnt==1) { ipBuf[0]='0'; ipBuf[1]='0'; ipBuf[2]='0'; } strncpy(ip_temp,ipBuf,3); cnt=get_IpInfo(1,ipBuf); if(cnt==1) { ipBuf[0]='0'; ipBuf[1]='0'; ipBuf[2]='0'; } strncpy(ip_temp+3,ipBuf,3); cnt=get_IpInfo(2,ipBuf); if(cnt==1) { ipBuf[0]='0'; ipBuf[1]='0'; ipBuf[2]='0'; } strncpy(ip_temp+6,ipBuf,3); cnt=get_IpInfo(0,ipBuf); if(cnt==1) { ipBuf[0]='0'; ipBuf[1]='0'; ipBuf[2]='0'; } strncpy(ip_temp+9,ipBuf,3); send_data[0]='f'; strncpy(send_data+1,ip_temp,15); send_data[16]='e'; ran_num=((rand()%50000))+50000; for(i=0; i<17; i++) // printf("%c",send_data[i]); // printf("\n"); write(fd,send_data,sizeof(send_data)); usleep(ran_num); } close(ip_fd); close( fd); return 0; }
//***************************************************************************** // //! \brief Initializes the UART Terminal interface //! //! \param none //! //! \return none // //***************************************************************************** void initTerminal() { initUart(); }
void init() { initUart(); }
//***************************************************************************** // // This example demonstrates how to send a string of data to the UART. // //***************************************************************************** int main(void) { int32_t i32CommandStatus; int i; initUart(); UARTprintf("Welcome to the Tiva C Series TM4C123G LaunchPad!\n"); UARTprintf("Type 'help' for a list of commands to control Moto\n"); UARTprintf("> "); InitDelay(); cSPIN_Peripherals_Init(); cSPIN_Reset_And_Standby(); /* Structure initialization by default values, in order to avoid blank records */ cSPIN_Regs_Struct_Reset(&cSPIN_RegsStruct); //cSPIN_PWM_Enable(2000); //cSPIN_Delay(0x00FFFFFF); //cSPIN_PWM_DISABLE(); #if 0 /* Acceleration rate settings to cSPIN_CONF_PARAM_ACC in steps/s2, range 14.55 to 59590 steps/s2 */ cSPIN_RegsStruct.ACC = AccDec_Steps_to_Par(cSPIN_CONF_PARAM_ACC); /* Deceleration rate settings to cSPIN_CONF_PARAM_DEC in steps/s2, range 14.55 to 59590 steps/s2 */ cSPIN_RegsStruct.DEC = AccDec_Steps_to_Par(cSPIN_CONF_PARAM_DEC); /* Maximum speed settings to cSPIN_CONF_PARAM_MAX_SPEED in steps/s, range 15.25 to 15610 steps/s */ cSPIN_RegsStruct.MAX_SPEED = MaxSpd_Steps_to_Par(cSPIN_CONF_PARAM_MAX_SPEED); /* Full step speed settings cSPIN_CONF_PARAM_FS_SPD in steps/s, range 7.63 to 15625 steps/s */ cSPIN_RegsStruct.FS_SPD = FSSpd_Steps_to_Par(cSPIN_CONF_PARAM_FS_SPD); /* Minimum speed settings to cSPIN_CONF_PARAM_MIN_SPEED in steps/s, range 0 to 976.3 steps/s */ cSPIN_RegsStruct.MIN_SPEED = cSPIN_CONF_PARAM_LSPD_BIT|MinSpd_Steps_to_Par(cSPIN_CONF_PARAM_MIN_SPEED); /* Acceleration duty cycle (torque) settings to cSPIN_CONF_PARAM_KVAL_ACC in %, range 0 to 99.6% */ cSPIN_RegsStruct.KVAL_ACC = Kval_Perc_to_Par(cSPIN_CONF_PARAM_KVAL_ACC); /* Deceleration duty cycle (torque) settings to cSPIN_CONF_PARAM_KVAL_DEC in %, range 0 to 99.6% */ cSPIN_RegsStruct.KVAL_DEC = Kval_Perc_to_Par(cSPIN_CONF_PARAM_KVAL_DEC); /* Run duty cycle (torque) settings to cSPIN_CONF_PARAM_KVAL_RUN in %, range 0 to 99.6% */ cSPIN_RegsStruct.KVAL_RUN = Kval_Perc_to_Par(cSPIN_CONF_PARAM_KVAL_RUN); /* Hold duty cycle (torque) settings to cSPIN_CONF_PARAM_KVAL_HOLD in %, range 0 to 99.6% */ cSPIN_RegsStruct.KVAL_HOLD = Kval_Perc_to_Par(cSPIN_CONF_PARAM_KVAL_HOLD); /* Thermal compensation param settings to cSPIN_CONF_PARAM_K_THERM, range 1 to 1.46875 */ cSPIN_RegsStruct.K_THERM = KTherm_to_Par(cSPIN_CONF_PARAM_K_THERM); /* Intersect speed settings for BEMF compensation to cSPIN_CONF_PARAM_INT_SPD in steps/s, range 0 to 3906 steps/s */ cSPIN_RegsStruct.INT_SPD = IntSpd_Steps_to_Par(cSPIN_CONF_PARAM_INT_SPD); /* BEMF start slope settings for BEMF compensation to cSPIN_CONF_PARAM_ST_SLP in % step/s, range 0 to 0.4% s/step */ cSPIN_RegsStruct.ST_SLP = BEMF_Slope_Perc_to_Par(cSPIN_CONF_PARAM_ST_SLP); /* BEMF final acc slope settings for BEMF compensation to cSPIN_CONF_PARAM_FN_SLP_ACC in% step/s, range 0 to 0.4% s/step */ cSPIN_RegsStruct.FN_SLP_ACC = BEMF_Slope_Perc_to_Par(cSPIN_CONF_PARAM_FN_SLP_ACC); /* BEMF final dec slope settings for BEMF compensation to cSPIN_CONF_PARAM_FN_SLP_DEC in% step/s, range 0 to 0.4% s/step */ cSPIN_RegsStruct.FN_SLP_DEC = BEMF_Slope_Perc_to_Par(cSPIN_CONF_PARAM_FN_SLP_DEC); /* Stall threshold settings to cSPIN_CONF_PARAM_STALL_TH in mV, range 31.25 to 1000mV */ cSPIN_RegsStruct.STALL_TH = StallTh_to_Par(cSPIN_CONF_PARAM_STALL_TH); /* Set Config register according to config parameters */ /* clock setting, switch hard stop interrupt mode, */ /* supply voltage compensation, overcurrent shutdown */ /* UVLO threshold, VCC reg output voltage , PWM frequency */ cSPIN_RegsStruct.CONFIG = (uint16_t)cSPIN_CONF_PARAM_CLOCK_SETTING | \ (uint16_t)cSPIN_CONF_PARAM_SW_MODE | \ (uint16_t)cSPIN_CONF_PARAM_VS_COMP | \ (uint16_t)cSPIN_CONF_PARAM_OC_SD | \ (uint16_t)cSPIN_CONF_PARAM_UVLOVAL | \ (uint16_t)cSPIN_CONF_PARAM_VCCVAL | \ (uint16_t)cSPIN_CONF_PARAM_PWM_DIV | \ (uint16_t)cSPIN_CONF_PARAM_PWM_MUL; /* Overcurrent threshold settings to cSPIN_CONF_PARAM_OCD_TH, range 31.25 to 1000mV */ cSPIN_RegsStruct.OCD_TH = cSPIN_CONF_PARAM_OCD_TH; /* Alarm settings to cSPIN_CONF_PARAM_ALARM_EN */ cSPIN_RegsStruct.ALARM_EN = cSPIN_CONF_PARAM_ALARM_EN; /* Step mode and sycn mode settings via cSPIN_CONF_PARAM_SYNC_MODE and cSPIN_CONF_PARAM_STEP_MODE */ cSPIN_RegsStruct.STEP_MODE = (uint8_t)cSPIN_CONF_PARAM_SYNC_MODE | \ (uint8_t)cSPIN_CONF_PARAM_STEP_MODE; /* Sink/source current, duration of constant current phases, duration of overboost phase settings */ cSPIN_RegsStruct.GATECFG1 = (uint16_t)cSPIN_CONF_PARAM_IGATE | \ (uint16_t)cSPIN_CONF_PARAM_TCC | \ (uint16_t)cSPIN_CONF_PARAM_TBOOST; /* Blank time, Dead time stiings */ cSPIN_RegsStruct.GATECFG2 = (uint16_t)cSPIN_CONF_PARAM_TBLANK | \ (uint16_t)cSPIN_CONF_PARAM_TDT; /* Program all cSPIN registers */ cSPIN_Registers_Set(&cSPIN_RegsStruct); #if defined(DEBUG) /* check the values of all cSPIN registers */ cSPIN_rx_data = cSPIN_Registers_Check(&cSPIN_RegsStruct); /* get the values of all cSPIN registers and print them to the terminal I/O */ cSPIN_Registers_Get(&cSPIN_RegsStruct); #endif /* defined(DEBUG) */ #else /**********************************************************************/ /* Start example of DAISY CHAINING */ /**********************************************************************/ /* Structure initialization by default values, in order to avoid blank records */ for (i=0;i<number_of_slaves;i++) { cSPIN_Regs_Struct_Reset(&cSPIN_RegsStructArray[i]); } /* Setting of parameters for ALL DEVICES */ for (i=0;i<number_of_slaves;i++) { cSPIN_RegsStructArray[i].ACC = AccDec_Steps_to_Par(ACC[i]); cSPIN_RegsStructArray[i].DEC = AccDec_Steps_to_Par(DEC[i]); cSPIN_RegsStructArray[i].MAX_SPEED = MaxSpd_Steps_to_Par(MAX_SPEED[i]); cSPIN_RegsStructArray[i].FS_SPD = FSSpd_Steps_to_Par(FS_SPD[i]); cSPIN_RegsStructArray[i].MIN_SPEED = LSPD_BIT[i]|MinSpd_Steps_to_Par(MIN_SPEED[i]); cSPIN_RegsStructArray[i].KVAL_ACC = Kval_Perc_to_Par(KVAL_ACC[i]); cSPIN_RegsStructArray[i].KVAL_DEC = Kval_Perc_to_Par(KVAL_DEC[i]); cSPIN_RegsStructArray[i].KVAL_RUN = Kval_Perc_to_Par(KVAL_RUN[i]); cSPIN_RegsStructArray[i].KVAL_HOLD = Kval_Perc_to_Par(KVAL_HOLD[i]); cSPIN_RegsStructArray[i].K_THERM = KTherm_to_Par(K_THERM[i]); cSPIN_RegsStructArray[i].INT_SPD = IntSpd_Steps_to_Par(INT_SPD[i]); cSPIN_RegsStructArray[i].ST_SLP = BEMF_Slope_Perc_to_Par(ST_SLP[i]); cSPIN_RegsStructArray[i].FN_SLP_ACC = BEMF_Slope_Perc_to_Par(FN_SLP_ACC[i]); cSPIN_RegsStructArray[i].FN_SLP_DEC = BEMF_Slope_Perc_to_Par(FN_SLP_DEC[i]); cSPIN_RegsStructArray[i].STALL_TH = StallTh_to_Par(STALL_TH[i]); cSPIN_RegsStructArray[i].CONFIG = (uint16_t)CONFIG_CLOCK_SETTING[i] | (uint16_t)CONFIG_SW_MODE[i] | \ (uint16_t)CONFIG_VS_COMP[i] | \ (uint16_t)CONFIG_OC_SD[i] | \ (uint16_t)CONFIG_UVLOVAL[i] | \ (uint16_t)CONFIG_VCCVAL[i] | \ (uint16_t)CONFIG_PWM_DIV[i] | \ (uint16_t)CONFIG_PWM_MUL[i]; cSPIN_RegsStructArray[i].OCD_TH = OCD_TH[i]; cSPIN_RegsStructArray[i].ALARM_EN = ALARM_EN[i]; cSPIN_RegsStructArray[i].STEP_MODE = (uint8_t)SYNC_MODE[i] | (uint8_t)STEP_MODE[i]; cSPIN_RegsStructArray[i].GATECFG1 = (uint16_t)GATECFG1_WD_EN[i] | \ (uint16_t)GATECFG1_TBOOST[i] | \ (uint16_t)GATECFG1_IGATE[i] | \ (uint16_t)GATECFG1_TCC[i]; cSPIN_RegsStructArray[i].GATECFG2 = (uint16_t)GATECFG2_TBLANK[i] | \ (uint16_t)GATECFG2_TDT[i]; } /* Program all cSPIN registers of All Devices */ cSPIN_All_Slaves_Registers_Set(number_of_slaves, &cSPIN_RegsStructArray[0]); /* Get status of all devices, clear FLAG pin */ cSPIN_All_Slaves_Get_Status(number_of_slaves, responseArray); #endif // // Loop forever echoing data through the UART. // while(1) { UARTprintf("\n>"); // // Peek to see if a full command is ready for processing // while(UARTPeek('\r') == -1) { // // millisecond delay. A SysCtlSleep() here would also be OK. // SysCtlDelay(SysCtlClockGet() / (1000 / 3)); // // Check for change of mode and enter hibernate if requested. // all other mode changes handled in interrupt context. // //if(g_sAppState.ui32Mode == APP_MODE_HIB) //{ // AppHibernateEnter(); //} } // // a '\r' was detected get the line of text from the user. // UARTgets(g_cInput,sizeof(g_cInput)); // // Pass the line from the user to the command processor. // It will be parsed and valid commands executed. // i32CommandStatus = CmdLineProcess(g_cInput); // // Handle the case of bad command. // if(i32CommandStatus == CMDLINE_BAD_CMD) { UARTprintf("Bad command!\n"); } // // Handle the case of too many arguments. // else if(i32CommandStatus == CMDLINE_TOO_MANY_ARGS) { UARTprintf("Too many arguments for command processor!\n"); } } }
void SpiUartDevice::begin(unsigned long baudrate) { SpiDevice::begin(); initUart(baudrate); }
void main(void) { // Stop watchdog timer WDTCTL = WDTPW + WDTHOLD; // set clocks BCSCTL1 = CALBC1_1MHZ; DCOCTL = CALDCO_1MHZ; BCSCTL2 &= ~(DIVS_3); // port 1 init P1DIR |= LED1 + LED2; P1OUT = 0x00; P2DIR |= RFM70_CSN + RFM70_CE; P2OUT = 0x00; P2OUT |= RFM70_CSN; //init button P1DIR &= ~BUTTON; P1OUT |= BUTTON; P1REN |= BUTTON; working_mode = MODE_PC_CONN_WAIT; // init ADC configureAdcTempSensor(); // init SPI initSpi(); // wait to init SPI slave device __delay_cycles(200); // init UART initUart(); // delay __delay_cycles(200); // wait for correct data by reading status register while (rx != 0x0E) { rx = rfm70Nop(); // turn on red led while not initialized P1OUT |= LED1; P1OUT |= LED2; __delay_cycles(200); } // got slave response, turn red led off P1OUT &= ~LED1; P1OUT &= ~LED2; __bis_SR_register(LPM0_bits + GIE); // working ... rfm70Init(); rfm70SetRxMode(); while (1) { // detect carrier rfm70ReadRegister(rfm70_buffer, RFM70_CD, 1); if (rfm70_buffer[0] == 0x01) { P1OUT |= LED1; } else { P1OUT &= ~LED1; } // receive data rfm70ReadRegister(rfm70_buffer, RFM70_R_RX_PL_WID, 1); rx = rfm70Nop(); if (rx & (1 << 6)) { rfm70ReadRxPayload(rfm70_buffer, 1); //sendUart(rfm70_buffer[0]); //sendUart('T'); if (rfm70_buffer[0] == 0xFF) { P1OUT |= LED1; } else { P1OUT &= ~LED1; } // clear interrupt status rfm70_buffer[0] = 0x00; rfm70WriteRegister(rfm70_buffer, RFM70_STATUS, 1); } } //__bis_SR_register(LPM0_bits + GIE); }
//***************************************************************************** // //! main //! //! \param None //! //! \return none //! //! \brief The main loop is executed here // //***************************************************************************** void main(void) { unsigned char loopCount = 0; int loop_time = 2000; ulCC3000Connected = 0; SendmDNSAdvertisment = 0; // Initialize hardware and interfaces board_init(); initUart(); sendString("System init : \r\n"); // Must initialize one time for MAC address prepare.. if (!Exosite_Init("exosite", "cc3000wifismartconfig", IF_WIFI, 0)) { show_status(); while(1); } // Main Loop while (1) { // Perform Smart Config if button pressed in current run or if flag set in FRAM // from previous MSP430 Run. if(runSmartConfig == 1 || *ptrFtcAtStartup == SMART_CONFIG_SET) { // Clear flag ClearFTCflag(); unsetCC3000MachineState(CC3000_ASSOC); // Start the Smart Config Process StartSmartConfig(); runSmartConfig = 0; } WDTCTL = WDTPW + WDTHOLD; // If connectivity is good, run the primary functionality if(checkWiFiConnected()) { char * pbuf = exo_buffer; //unsolicicted_events_timer_disable(); if (0 == cloud_status) { //check to see if we have a valid connection loop_time = 2000; loopCount = 1; while (loopCount++ <= (WRITE_INTERVAL+1)) { // WDTCTL = WDT_ARST_1000; if (Exosite_Read("led7_ctrl", pbuf, EXO_BUFFER_SIZE)) { // Read success turnLedOn(CC3000_CLIENT_CONNECTED_IND); if (!strncmp(pbuf, "0", 1)) turnLedOff(LED7); else if (!strncmp(pbuf, "1", 1)) turnLedOn(LED7); } else { if (EXO_STATUS_NOAUTH == Exosite_StatusCode()) { turnLedOff(CC3000_CLIENT_CONNECTED_IND); // Activate device again cloud_status = Exosite_Activate(); } } hci_unsolicited_event_handler(); unsolicicted_events_timer_init(); //sendString("== Exosite Read==\r\n"); WDTCTL = WDTPW + WDTHOLD; busyWait(loop_time); //delay before looping again } unsolicicted_events_timer_init(); if (EXO_STATUS_NOAUTH != Exosite_StatusCode()) { unsigned char sensorCount = 0; int value; char strRead[6]; //largest value of an int in ascii is 5 + null terminate WDTCTL = WDT_ARST_1000; for (sensorCount = 0; sensorCount < SENSOR_END; sensorCount++) { value = getSensorResult(sensorCount); //get the sensor reading itoa(value, strRead, 10); //convert to a string unsolicicted_events_timer_init(); //for each reading / data source (alias), we need to build the string "alias=value" (must be URL encoded) //this is all just an iteration of, for example, Exosite_Write("mydata=hello_world",18); memcpy(pbuf,&sensorNames[sensorCount][0],strlen(&sensorNames[sensorCount][0])); //copy alias name into buffer pbuf += strlen(&sensorNames[sensorCount][0]); *pbuf++ = 0x3d; //put an '=' into buffer memcpy(pbuf,strRead, strlen(strRead)); //copy value into buffer pbuf += strlen(strRead); *pbuf++ = 0x26; //put an '&' into buffer, the '&' ties successive alias=val pairs together } pbuf--; //back out the last '&' WDTCTL = WDT_ARST_1000; Exosite_Write(exo_buffer,(pbuf - exo_buffer - 1)); //write all sensor values to the cloud if (EXO_STATUS_OK == Exosite_StatusCode()) { // Write success turnLedOn(CC3000_CLIENT_CONNECTED_IND); } } } else { //we don't have a good connection yet - we keep retrying to authenticate WDTCTL = WDTPW + WDTHOLD; //sendString("== Exosite Activate==\r\n"); cloud_status = Exosite_Activate(); if (0 != cloud_status) loop_time = 30000; //delay 30 seconds before retrying... } unsolicicted_events_timer_init(); } WDTCTL = WDTPW + WDTHOLD; // TODO - make this a sleep instead of busy wait busyWait(loop_time); //delay before looping again } }
void gpioButton0(void){ initUart(); }