void *QueueCreate(int v_size) { QUEUE_S *pQ = NULL; pQ = (QUEUE_S *)malloc(sizeof(QUEUE_S)); if (NULL == pQ) { return NULL; } pQ->pMemb = (void **)malloc(sizeof(void*) * v_size); if (NULL == pQ->pMemb) { free(pQ); return NULL; } pQ->head = 0; pQ->tail = 0; pQ->num = 0; pQ->max = v_size; CSInit(&pQ->cs); return pQ; }
TLog::TLog(const char *module,const char *version,int bakmode, int multiuser) { m_nMultiUser = multiuser; m_iTraceLevelThreshold = 0; m_iBakMode = bakmode; m_iIdx = 0; CSInit(&m_Lock); LOCK(); m_nTotalCount = 0; m_nMaxLines = MAX_FILE_LINES; m_nTraceMode = LOG_TO_NULL; m_nFlushFlag = 1; m_FP = NULL; assert(module); assert(version); strcpy(m_acModuleName,module); strcpy(m_acVersion,version); #ifdef WIN32 mkdir("./log"); #else mkdir("./log", 0777); #endif sprintf(m_acFileName, "./log/%s.log", m_acModuleName); sprintf(m_acErrorFileName, "./log/%s.err", m_acModuleName); UNLOCK(); }
void user_init(void) { uart_init(BIT_RATE_115200, BIT_RATE_115200); uart0_sendStr("\r\nesp8266 ws2812 driver\r\n"); // int opm = wifi_get_opmode(); // if( opm == 1 ) need_to_switch_opmode = 120; // wifi_set_opmode_current(2); //Uncomment this to force a system restore. // system_restore(); CSSettingsLoad( 0 ); CSPreInit(); pUdpServer = (struct espconn *)os_zalloc(sizeof(struct espconn)); ets_memset( pUdpServer, 0, sizeof( struct espconn ) ); espconn_create( pUdpServer ); pUdpServer->type = ESPCONN_UDP; pUdpServer->proto.udp = (esp_udp *)os_zalloc(sizeof(esp_udp)); pUdpServer->proto.udp->local_port = 7777; espconn_regist_recvcb(pUdpServer, udpserver_recv); if( espconn_create( pUdpServer ) ) { while(1) { uart0_sendStr( "\r\nFAULT\r\n" ); } } CSInit(); SetServiceName( "ws2812" ); AddMDNSName( "cn8266" ); AddMDNSName( "ws2812" ); AddMDNSService( "_http._tcp", "An ESP8266 Webserver", 80 ); AddMDNSService( "_ws2812._udp", "WS2812 Driver", 7777 ); AddMDNSService( "_cn8266._udp", "ESP8266 Backend", 7878 ); //Add a process system_os_task(procTask, procTaskPrio, procTaskQueue, procTaskQueueLen); //Timer example os_timer_disarm(&some_timer); os_timer_setfn(&some_timer, (os_timer_func_t *)myTimer, NULL); os_timer_arm(&some_timer, 100, 1); ws2812_init(); uint8_t ledout[] = { 0x00, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00 }; ws2812_push( ledout, sizeof( ledout ) ); system_os_post(procTaskPrio, 0, 0 ); }
/* * PreProcess - pre-process source file */ vi_rc PreProcess( const char *fn, sfile **sf, labels *lab ) { GENERIC_FILE gf; int i, token, k, len; sfile *tsf; char tmp[MAX_SRC_LINE], tmp2[MAX_SRC_LINE]; char tmp3[MAX_SRC_LINE]; bool ret; #ifdef VICOMP bool AppendingFlag = FALSE; #else #define AppendingFlag EditFlags.Appending #endif /* * get source file */ #ifdef VICOMP ret = SpecialOpen( fn, &gf ); #else if( EditFlags.CompileScript ) { EditFlags.OpeningFileToCompile = TRUE; ret = SpecialOpen( fn, &gf, FALSE ); EditFlags.OpeningFileToCompile = FALSE; } else { ret = SpecialOpen( fn, &gf, EditFlags.BoundData ); } #endif if( !ret ) { return( ERR_FILE_NOT_FOUND ); } /* * init control */ CSInit(); CurrentSrcLine = 0L; tsf = MemAlloc( sizeof( sfile ) ); tsf->next = NULL; tsf->prev = NULL; tsf->arg1 = NULL; tsf->arg2 = NULL; tsf->data = NULL; tsf->token = SRC_T_NULL; *sf = tmpTail = tsf; cLab = lab; /* * set up error handler */ i = setjmp( genExit ); if( i != 0 ) { SpecialFclose( &gf ); return( (vi_rc)i ); } /* * process each line */ while( SpecialFgets( tmp, MAX_SRC_LINE - 1, &gf ) >= 0 ) { /* * prepare this line */ CurrentSrcLine++; #ifndef VICOMP if( !EditFlags.ScriptIsCompiled ) { #endif RemoveLeadingSpaces( tmp ); k = strlen( tmp ); memcpy( tmp3, tmp, k + 1 ); if( (len = NextWord1( tmp, tmp2 )) <= 0 ) { continue; } if( tmp2[0] == '#' ) { continue; } hasVar = FALSE; for( i = 0; i < k; i++ ){ if( tmp3[i] == '%' ) { hasVar = TRUE; break; } } /* * if we are appending (ie, an append token was encounterd * before, stop tokenizing */ if( !AppendingFlag ) { token = Tokenize( SourceTokens, tmp2, TRUE ); #ifndef VICOMP if( token == SRC_T_VBJ__ ) { EditFlags.ScriptIsCompiled = TRUE; continue; } #endif } else { token = TOK_INVALID; } #ifndef VICOMP } else { len = NextWord1( tmp, tmp2 ); hasVar = (bool) tmp2[0] - '0'; token = atoi( &tmp2[1] ); } #endif /* * process recognized tokens */ if( token != TOK_INVALID ) { RemoveLeadingSpaces( tmp ); if( token > SRC_T_NULL ) { genItem( token, tmp ); continue; } /* * get parm */ AddString( &CurrentSrcData, tmp ); freeSrcData = TRUE; /* * process token */ switch( token ) { case SRC_T_EXPR: genExpr(); break; case SRC_T_LABEL: GenLabel( tmp ); break; case SRC_T_IF: CSIf(); break; case SRC_T_QUIF: CSQuif(); break; case SRC_T_ELSEIF: CSElseIf(); break; case SRC_T_ELSE: CSElse(); break; case SRC_T_ENDIF: CSEndif(); break; case SRC_T_LOOP: CSLoop(); break; case SRC_T_ENDLOOP: case SRC_T_ENDWHILE: CSEndLoop(); break; case SRC_T_WHILE: CSWhile(); break; case SRC_T_UNTIL: CSUntil(); break; case SRC_T_BREAK: CSBreak(); break; case SRC_T_CONTINUE: CSContinue(); break; default: genItem( token, NULL ); if( token == SRC_T_GOTO ) { #ifndef VICOMP if( EditFlags.ScriptIsCompiled ) { NextWord1( CurrentSrcData, tmp ); tmpTail->branchcond = atoi( CurrentSrcData ); strcpy( CurrentSrcData, tmp ); } else { #endif tmpTail->branchcond = COND_JMP; #ifndef VICOMP } #endif } tmpTail->data = CurrentSrcData; freeSrcData = FALSE; break; } if( freeSrcData ) { MemFree( CurrentSrcData ); } /* * set all other tokens to be processed at run time */ } else { #ifndef VICOMP if( EditFlags.ScriptIsCompiled ) { RemoveLeadingSpaces( tmp ); genItem( token, tmp ); continue; } #endif if( !AppendingFlag ) { token = Tokenize( TokensCmdLine, tmp2, TRUE ); } else { token = TOK_INVALID; } switch( token ) { case PCL_T_COMMANDWINDOW: case PCL_T_STATUSWINDOW: case PCL_T_COUNTWINDOW: case PCL_T_EDITWINDOW: case PCL_T_EXTRAINFOWINDOW: case PCL_T_FILECWINDOW: case PCL_T_LINENUMBERWINDOW: case PCL_T_DIRWINDOW: case PCL_T_FILEWINDOW: case PCL_T_SETWINDOW: case PCL_T_SETVALWINDOW: case PCL_T_MESSAGEWINDOW: case PCL_T_MENUWINDOW: case PCL_T_MENUBARWINDOW: case PCL_T_ENDWINDOW: case PCL_T_SETCOLOR: case PCL_T_MATCH: case PCL_T_DIMENSION: case PCL_T_BORDER: case PCL_T_HILIGHT: case PCL_T_TEXT: case PCL_T_ALIAS: case PCL_T_ABBREV: case PCL_T_MENU: case PCL_T_MENUITEM: case PCL_T_ENDMENU: case PCL_T_WHITESPACE: case PCL_T_SELECTION: case PCL_T_EOFTEXT: case PCL_T_KEYWORD: case PCL_T_OCTAL: case PCL_T_HEX: case PCL_T_INTEGER: case PCL_T_CHAR: case PCL_T_PREPROCESSOR: case PCL_T_SYMBOL: case PCL_T_INVALIDTEXT: case PCL_T_IDENTIFIER: case PCL_T_JUMPLABEL: case PCL_T_COMMENT: case PCL_T_FLOAT: case PCL_T_STRING: case PCL_T_VARIABLE: case PCL_T_FILETYPESOURCE: case PCL_T_ENDFILETYPESOURCE: case PCL_T_LOCATE: case PCL_T_MAP: case PCL_T_MAP_DMT: case PCL_T_MENUFILELIST: case PCL_T_MENULASTFILES: case PCL_T_DEFAULTWINDOW: case PCL_T_ACTIVEMENUWINDOW: case PCL_T_GREYEDMENUWINDOW: case PCL_T_ACTIVEGREYEDMENUWINDOW: RemoveLeadingSpaces( tmp ); token += SRC_T_NULL + 1; genItem( token, tmp ); break; case PCL_T_SET: token += SRC_T_NULL + 1; #ifdef VICOMP WorkLine->data[0] = 0; Set( tmp ); genItem( token, WorkLine->data ); #else if( EditFlags.CompileScript ) { vi_rc rc; WorkLine->data[0] = 0; rc = Set( tmp ); if( rc != ERR_NO_ERR ) { Error( GetErrorMsg( rc ) ); } genItem( token, WorkLine->data ); } else { genItem( token, tmp ); } #endif break; default: if( AppendingFlag ) { if( tmp3[0] == '.' && tmp3[1] == 0 ) { AppendingFlag = FALSE; } } else if( token == TOK_INVALID ) { /* * see if the current token is a Ex token. If * it isn't, then see if the next one is * (i.e., look for <n> append) */ token = Tokenize( TokensEx, tmp2, FALSE ); if( token == TOK_INVALID ) { if( NextWord1( tmp, tmp2 ) >= 0 ) { token = Tokenize( TokensEx, tmp2, FALSE ); if( token == EX_T_APPEND ) { AppendingFlag = TRUE; } } } } if( tmp3[0] == '>' ) { tmp3[0] = ' '; } genItem( TOK_INVALID, tmp3 ); break; } } } SpecialFclose( &gf ); AppendingFlag = FALSE; return( CSFini() ); } /* PreProcess */