int main (void) { USB_Init(); ProtocolInit(); // Connect in[0] = XLINK_MODE_SWD; XLINK_Connect(in, out); // Out sequence in[0] = sizeof(jtag2swd) * 8; memcpy(in + 1, jtag2swd, sizeof(jtag2swd)); XLINK_SWJ_Sequence(in, out); // Read ID do { id = 0; in[0] = 0; in[1] = 1; in[2] = 0; in[3] = 1 << 1; XLINK_SWDTransferBlock(in, out); id = *(unsigned long *)&out[3]; }while ((id & 0xFFF) == 0x477); LED_CONNECTED_OUT(0); LED_RUNNING_OUT(0); USB_Connect(__FALSE); USB_Connect(__TRUE); while (!USB_configured()) { LED_CONNECTED_OUT(0); LED_RUNNING_OUT(0); Delayms(50); LED_CONNECTED_OUT(1); LED_RUNNING_OUT(1); Delayms(50); } LED_CONNECTED_OUT(1); LED_RUNNING_OUT(1); while (1) { USB_ProcessCommand(); } }
/** * PlatformInit - sets up platform and protocol hardware. Also configures the * protocol using the setup structure data. * * @return Success of the operation. If true, the protocol has been setup * successfully. If false, an error has occurred during protocol * setup. */ bool PlatformInit(void) { // Disable global interrupts during hardware initialization to prevent any // unwanted interrupts from occurring. MCU_DISABLE_INTERRUPT(); // Setup basic platform hardware (e.g. watchdog, clocks). HardwareInit(); // Attempt to initialize protocol hardware and information using the provided // setup structure data. if (!ProtocolInit(&gProtocolSetupInfo)) { return false; } // Re-enable global interrupts for normal operation. MCU_ENABLE_INTERRUPT(); return true; }
int main(void) { unsigned char panId[2][PROTOCOL_PHYADDRESS_PANID_SIZE] = { { 0x12, 0x34 }, { 0x00, 0x00 } }; unsigned char remote[2][PROTOCOL_PHYADDRESS_ADDRESS_SIZE] = { { 0xBB, 0xBB }, { 0x00, 0x01 } }; WDTCTL = WDTPW | WDTHOLD; ProtocolInit(&gProtocolSetupInfo); PhyAddressLinkEstablish(panId[0], remote[0]); #if defined( PROTOCOL_GATEWAY ) PhyAddressSetFilter(remote[1]); #endif PhyAddressLinkDestroy(); return 0; }
ThreadProc::ThreadProc(TParaSettings *p,int index,QFile &Upfile,WORD filecrc,QObject *parent) : QThread(parent) { TerComParaInit(p); StatusMachineInit(); UIDisplayInit(); SendRecvBufferInit(); ComMethodInit(); MiscParaInit(index); LogFileAddrAssignInit(); ProtocolInit(Upfile, filecrc); connect (this,SIGNAL(Need2Back()),this,SLOT(Back2TheLast())); connect (this,SIGNAL(UIInfoSend(TUpgradeUIStruct)), this->parent ()->parent (), SLOT(UiFresh (TUpgradeUIStruct))); }
/** * main - main application loop. Sets up platform and then performs simple * transfers (simplex) while incrementing the sequence number for the lifetime * of execution. * * @return Exit code of the main application, however, this application * should never exit. */ int main(void) { RCC_ClocksTypeDef RCC_ClockFreq; RCC_GetClocksFreq(&RCC_ClockFreq); if (SysTick_Config(RCC_ClockFreq.HCLK_Frequency/1000)) { /* Capture error */ while (1); } Il_Hw_Init(); Init_SI4463_Pin(); vRadio_Init(); ClkSwitch2HseSystemInit(); RCC_GetClocksFreq(&RCC_ClockFreq); if (SysTick_Config(RCC_ClockFreq.HCLK_Frequency/1000)) { /* Capture error */ while (1); } Il_Hw_Init(); Uart_Init(); Init_SI4463_Pin(); //TimingBaseInit(50000); // while(1) // { //// //LedD4StaInvert(); //// GPIOB->BSRR = 0x00000040; //// GPIOB->BRR = 0x00000040; // } //EXTILine_TimingSync_Config(); //si446x_get_int_status(0u, 0u, 0u); uint8_t testBuff[6]={0x05,0xD0,0x01,0x02,0x03,0xD6}; //UartSendByte(testBuff, 6); vRadio_StartRX(pRadioConfiguration->Radio_ChannelNumber); RadioGotoRxSta(); SI4463_Enable_NIRQ_Int(); if (!ProtocolInit(&gProtocolSetupInfo)) { return false; } while(true) { if(GetPubRxBufCount()>0x00) { //UartSendByte(timMark, 1); //UartSendByte(uartRxDataBuff, uartRxCount); //uartDataProcess(); PubRxDataProcess(); } if(GetPubTxBufCount()>0x00) { PubTxDataProcess(); } if (!ProtocolBusy()) { // Increment the sequence number for the next transmission. gPacket.seqNum++; } } // while (true) // { // // Perform a simple transfer of the packet. // if (!ProtocolSimpleTransfer((unsigned char*)&gPacket, sizeof(struct sPacket))) // { // // Put the microcontroller into a low power state (sleep). Remain here // // until the ISR wakes up the processor. // //McuSleep(); // } // // /** // * Check if the protocol is busy. If it is, a new transfer cannot occur // * until it becomes ready for the next instruction. Do not increment the // * sequence number until the protocol is ready. This prevents incrementing // * the sequence number more than once between transmissions. // */ // if (!ProtocolBusy()) // { // // Increment the sequence number for the next transmission. // gPacket.seqNum++; // } // } }
/** * main - main application loop. Sets up platform and then goes to sleep for * the lifetime of execution. * * @return Exit code of the main application, however, this application * should never exit. */ int main(void) { RCC_ClocksTypeDef RCC_ClockFreq; RCC_GetClocksFreq(&RCC_ClockFreq); if (SysTick_Config(RCC_ClockFreq.HCLK_Frequency/1000)) { /* Capture error */ while (1); } Il_Hw_Init(); Init_SI4463_Pin(); vRadio_Init(); ClkSwitch2HseSystemInit(); RCC_GetClocksFreq(&RCC_ClockFreq); if (SysTick_Config(RCC_ClockFreq.HCLK_Frequency/1000)) { /* Capture error */ while (1); } Il_Hw_Init(); Uart_Init(); Init_SI4463_Pin(); //TimingBaseInit(50000); // while(1) // { //// //LedD4StaInvert(); //// GPIOB->BSRR = 0x00000040; //// GPIOB->BRR = 0x00000040; // } //EXTILine_TimingSync_Config(); //si446x_get_int_status(0u, 0u, 0u); uint8_t testBuff[6]={0x05,0xD0,0x01,0x02,0x03,0xD6}; //UartSendByte(testBuff, 6); vRadio_StartRX(pRadioConfiguration->Radio_ChannelNumber); RadioGotoRxSta(); SI4463_Enable_NIRQ_Int(); if (!ProtocolInit(&gProtocolSetupInfo)) { return false; } while(1) { if(GetPubTxBufCount()>0x00) { PubTxDataProcess(); } } }
/********************************************************************* * Function: void BerkeleyTCPServerDemo(void) * * PreCondition: Stack is initialized * * Input: None * * Output: None * * Side Effects: None * * Overview: None * * Note: None ********************************************************************/ void BerkeleyTCPServerDemo(void) { static SOCKET bsdServerSocket; static SOCKET ClientSock[MAX_CLIENT]; struct sockaddr_in addr; struct sockaddr_in addRemote; int addrlen = sizeof(struct sockaddr_in); char bfr[64]; int length; int i; int ClientsCnt = 0; BYTE res = STR_OK; static enum { BSD_INIT = 0, BSD_CREATE_SOCKET, BSD_BIND, BSD_LISTEN, BSD_OPERATION } BSDServerState = BSD_INIT; switch(BSDServerState) { case BSD_INIT: // Initialize all client socket handles so that we don't process // them in the BSD_OPERATION state for(i = 0; i < MAX_CLIENT; i++) { ClientSock[i] = INVALID_SOCKET; } BSDServerState = BSD_CREATE_SOCKET; ProtocolInit(); // No break needed case BSD_CREATE_SOCKET: // Create a socket for this server to listen and accept connections on bsdServerSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if(bsdServerSocket == INVALID_SOCKET) return; BSDServerState = BSD_BIND; // No break needed case BSD_BIND: // Bind socket to a local port addr.sin_port = PORTNUM; addr.sin_addr.S_un.S_addr = IP_ADDR_ANY; if( bind( bsdServerSocket, (struct sockaddr*)&addr, addrlen ) == SOCKET_ERROR ) return; BSDServerState = BSD_LISTEN; // No break needed case BSD_LISTEN: if(listen(bsdServerSocket, MAX_CLIENT) == 0) BSDServerState = BSD_OPERATION; // No break. If listen() returns SOCKET_ERROR it could be because // MAX_CLIENT is set to too large of a backlog than can be handled // by the underlying TCP socket count (TCP_PURPOSE_BERKELEY_SERVER // type sockets in TCPIPConfig.h). However, in this case, it is // possible that some of the backlog is still handleable, in which // case we should try to accept() connections anyway and proceed // with normal operation. case BSD_OPERATION: for(i=0; i<MAX_CLIENT; i++) { // Accept any pending connection requests, assuming we have a place to store the socket descriptor if(ClientSock[i] == INVALID_SOCKET) ClientSock[i] = accept(bsdServerSocket, (struct sockaddr*)&addRemote, &addrlen); // If this socket is not connected then no need to process anything if(ClientSock[i] == INVALID_SOCKET) { continue; } // For all connected sockets, receive and send back the data length = recv( ClientSock[i], bfr, sizeof(bfr), 0); res = STR_OK; res = RunServer(i, (BYTE*)bfr, sizeof(bfr), &length); if(res==STR_NEED_ANSWER) { send(ClientSock[i], bfr, length, 0); res = STR_OK; } if(( length < 0 )||(res != STR_OK)) { closesocket( ClientSock[i] ); ClientSock[i] = INVALID_SOCKET; } ClientsCnt++; } //if(ClientsCnt == 0) LED1_IO = 0; break; default: return; } return; }
void DefaultExtraIcons_Load() { DBExtraIconsInit(); ProtocolInit(); }
int main(int argc, char *argv[]) { //根据参数,创建守护进程 int nDaemon = 0; int opt; while((opt=getopt(argc,argv, "dnsv:i:")) != -1) { switch(opt) { case 'd': { nDaemon = 1; break; } case 'v': { printf_Enable = *optarg - '0'; break; } case 's': { SetSerialPrint(); break; } case 'n': { SetNetPrint(); break; } case 'i': { memcpy(g_dev_name, optarg, strlen(optarg)); } default: { break; } } } if (nDaemon) { //daemon(0, 0); init_daemon(); } //serial相关初始化 //设备尚未连接的时候打不开,需要实时检测设备是否连接. /* if(0 >= SerialOpen()) { TRACEERR("serial dev open fail\n"); exit(ReturnError); } */ SerialInit(); SetCallbackRecvSerialFun(CallBackRecvSerialFun); SetCallbackRecvSerialBuff(g_szRecvSerialBuff); SetCallbackRecvSerialBuffSize(&g_nRecvSerialBuffSize); if (ReturnError == SerialStartListen()) { TRACEERR("serial start listen fail\n"); exit(ReturnError); } //网络相关初始化 SetCallBackRecvNet(CallBackRecvNetFun); SetCallBackRecvNetBuff(g_szRecvNetBuff); SetCallBackRecvNetBuffSize(&g_nRecvNetBuffSize); SetCallBackRecvNetAddr(&g_oRecvNetBuffFrom); if (ReturnError == StartNetService()) { TRACEERR("start net service fail\n"); exit(ReturnError); } //协议相关初始化 if (ReturnError == ProtocolInit()) { TRACEERR("Protocol init fail\n"); exit(ReturnError); } while(1) { sleep(3); } return ReturnSuccess; }