static void DoLoad(System *sys) { VMFILE *fp; /* check for a program name on the command line */ if (!SetProgramName(sys)) { VM_printf("expecting a file name\n"); return; } /* load the program */ if (!(fp = VM_fopen(programName, "r"))) VM_printf("error loading '%s'\n", programName); else { VM_printf("Loading '%s'\n", programName); BufInit(); while (VM_fgets(sys->lineBuf, sizeof(sys->lineBuf), fp) != NULL) { int len = strlen(sys->lineBuf); VMVALUE lineNumber; char *token; sys->linePtr = sys->lineBuf; if ((token = NextToken(sys)) != NULL) { if (ParseNumber(token, &lineNumber)) BufAddLineN(lineNumber, sys->linePtr); else VM_printf("expecting a line number: %s\n", token); } } VM_fclose(fp); } }
/* *@描述:初始化串口 *@参数:void *@返回:无 */ void InitUart(void) { // UART Configuration structure variable UART_CFG_Type UARTConfigStruct; // UART FIFO configuration Struct variable UART_FIFO_CFG_Type UARTFIFOConfigStruct; // Pin configuration for UART0 PINSEL_CFG_Type PinCfg; /* * Initialize UART pin connect */ PinCfg.OpenDrain = UARTOpendrain; PinCfg.Pinmode = UARTPinMode; PinCfg.Portnum = UARTPortTX; PinCfg.Pinnum = UARTPinTX; PinCfg.Funcnum = UARTFuncTX; PINSEL_ConfigPin(&PinCfg); PinCfg.Portnum = UARTPortRX; PinCfg.Pinnum = UARTPinRX; PinCfg.Funcnum = UARTFuncRX; PINSEL_ConfigPin(&PinCfg); /* Initialize UART Configuration parameter structure to default state: * Baudrate = 9600bps * 8 data bit * 1 Stop bit * None parity */ UART_ConfigStructInit(&UARTConfigStruct); // Re-configure baudrate to 57600bps UARTConfigStruct.Baud_rate = 57600; // Initialize UART peripheral with given to corresponding parameter UART_Init((LPC_UART_TypeDef *)_LPC_UART, &UARTConfigStruct); /* Initialize FIFOConfigStruct to default state: * - FIFO_DMAMode = DISABLE * - FIFO_Level = UART_FIFO_TRGLEV0 * - FIFO_ResetRxBuf = ENABLE * - FIFO_ResetTxBuf = ENABLE * - FIFO_State = ENABLE */ UART_FIFOConfigStructInit(&UARTFIFOConfigStruct); UARTFIFOConfigStruct.FIFO_Level = UART_FIFO_TRGLEV3;//8 character // Initialize FIFO for UART0 peripheral UART_FIFOConfig((LPC_UART_TypeDef *)_LPC_UART, &UARTFIFOConfigStruct); // Enable UART Transmit UART_TxCmd((LPC_UART_TypeDef *)_LPC_UART, ENABLE); /* Enable UART Rx interrupt */ UART_IntConfig((LPC_UART_TypeDef *)_LPC_UART, UART_INTCFG_RBR, ENABLE); /* Enable UART line status interrupt */ UART_IntConfig((LPC_UART_TypeDef *)_LPC_UART, UART_INTCFG_RLS, DISABLE); /* preemption = 1, sub-priority = 1 */ NVIC_SetPriority(_UART_IRQ, ((0x01<<3)|0x01)); /* Enable Interrupt for UART channel */ NVIC_EnableIRQ(_UART_IRQ); BufInit(&bufSerialRec); }
static void DoNew(System *sys) { /* check for a program name on the command line */ #ifdef LOAD_SAVE SetProgramName(sys); #endif BufInit(); }
/** * [BufInitAll :Init whole buffer queue] */ void BufInitAll() { struct buffer *bufPtr,*bufNew; int i; BufInit(freebuf); bufNew = freebuf; bufPtr = freebuf; for(i = 1; i < MAX_BUF_NUM; i++) { BufInit(bufNew); bufPtr->next = bufNew; bufPtr = bufNew; } bufPtr->next = NULL; }
int ActingAsServer(int argc, char* argv[], bool dbg) { SerialCom comm; PipeShell shell; int nPort = 1; int nBaud = 9600; int nBits = 8; int nStop = 1; char cParity = 'N'; char sIfName[32]; char sLcdDev[32]; int distance = 26000; int neg_mode = 0; bool trace_gws = dbg; bool trace_lcd = false; bool trace_neg = false; memset(sIfName, 0x00, 32); memset(sLcdDev, 0x00, 32); strcpy(sIfName, "wlan0"); strcpy(sLcdDev, "/dev/ttyS0"); if (svrInitInstance()) { InitParameters(true); BufInit(&local_gws_buff); ScInit(&comm, 0); //nonblock mode ReadFileConf(&comm, &nPort, &nBaud, &nBits, &nStop, &cParity, sIfName,sLcdDev,&distance,&neg_mode, &trace_gws,&trace_lcd,&trace_neg); ReadCmdLine(argc, argv, &nPort, &nBaud, &nBits, &nStop, &cParity, &trace_lcd,&trace_neg); if (false == ScOpen(&comm, nPort, nBaud, nBits, nStop, cParity)) { ShowStatusBar("%s", "Can not open GWS radio port.\n"); } else { ShowStatusBar("%s", "GWS port OK.\n"); } PipeShellInit(&shell); svrInitCommandHandler(&comm,&shell,sIfName,trace_gws); ShowStatusBar("%s" VT100_RESET "\n", "gwsman server ready.\n"); if (lcd_main(sLcdDev,distance,neg_mode,trace_lcd,trace_neg) < 0) { printf("\n\n"); fflush(stdout); while (svrTestInstance(static_chp.m_semInstance)) usleep(100000); } else fflush(stdout); ScExit(&comm); BufExit(&local_gws_buff); svrExitCommandHandler(); } svrExitInstance(); return 1; }
/** * [ReceivePrim : Receive Primitive] * @param sender [sender name] * @param msgGet [string pointer to store the message get from buffer] */ int ReceivePrim(char *sender,char *msgGet) { struct buffer *buff; int tcbId; int size; /* Close Interrupt */ disable(); /* Get Sender id*/ tcbId = FindTcbByName(sender); if(tcbId == TCB_NOT_FOUND) { enable(); return 0; } /* Read info from message queue to buff*/ P(&(tcbs[current].sm)); P(&(tcbs[current].mutex)); buff = BufRemov(&(tcbs[current].mq),tcbId); V(&(tcbs[current].mutex)); /* If Buffer is Null */ if(buff == NULL) { /*No message sent by sender*/ V(&tcbs[current].sm); enable(); return 0; } /* Read the message from buffer */ size = buff->size; strncpy(msgGet,buff->text,strlen(buff->text)); /* Recycle: Insert Message Into Free Buffer*/ BufInit(buff); P(&mutexFB); BufPut(buff); V(&mutexFB); V(&semFB); /* Open Interrupt */ enable(); return size; }
int main() { int i; /* Initialization Part */ DosInit(); TcbInitAll(); BufInit(freebuf); /* Get access to the entry address of clock intrrupt */ old_int8 = getvect(8); clrscr(); tcbs[0].state = RUNNING; current = 0; /* current thread */ /* Init NumBuf*/ for(i = 0; i < NUM_BUF_LEN; i++) { numBuf[i] = 0; } pIn = pOut = 0; /* out/in Index for numBuf */ ThreadCreate("T1",(codeptr)T1Producer,STACK_SIZE); ThreadCreate("T2",(codeptr)T2Custemer,STACK_SIZE); setvect(8, new_int8); my_swtch(); TcbState(); while(!ThreadFinished()); TcbState(); setvect(8, old_int8); /* Recover old clock interrupt */ ThreadDestory(0); return 0; }
int main() { /* Initialization Part */ DosInit(); TcbInitAll(); BufInit(freebuf); /* Get access to the entry address of clock intrrupt */ old_int8 = getvect(8); /* printf("Please Input the Time Slice \n"); scanf("%d",&timeSlice); printf("Press Any Key To Continue ......\n"); getch(); */ clrscr(); tcbs[0].state = RUNNING; current = 0; /* current thread */ sum = 0; ThreadCreate("T1",(codeptr)T1AddOne,STACK_SIZE); ThreadCreate("T2",(codeptr)T2AddTwo,STACK_SIZE); setvect(8, new_int8); my_swtch(); TcbState(); while(!ThreadFinished()); TcbState(); setvect(8, old_int8); /* Recover old clock interrupt */ printf("End : Sum is %d \n",sum); ThreadDestory(0); return 0; }
void EditWorkspace(System *sys) { VMVALUE lineNumber; char *token; BufInit(); VM_printf("ebasic 0.001\n"); for (;; ) { VM_getline(sys->lineBuf, sizeof(sys->lineBuf)); sys->linePtr = sys->lineBuf; if ((token = NextToken(sys)) != NULL) { if (ParseNumber(token, &lineNumber)) { if (IsBlank(sys->linePtr)) { if (!BufDeleteLineN(lineNumber)) VM_printf("no line %d\n", lineNumber); } else if (!BufAddLineN(lineNumber, sys->linePtr)) VM_printf("out of edit buffer space\n"); } else { int i; for (i = 0; cmds[i].name != NULL; ++i) if (strcasecmp(token, cmds[i].name) == 0) break; if (cmds[i].handler) { (*cmds[i].handler)(sys); VM_printf("OK\n"); } else VM_printf("unknown command: %s\n", token); } } } }