⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 temp

📁 tinios的 源码
💻
📖 第 1 页 / 共 2 页
字号:
    }  }    task void SendTask() {    call computeInstruction(&sendContext);    if (sendContext.state == BOMB_STATE_RUN) {      dbg(DBG_USR1, "VM: Posting SendTask in task.\n");      post SendTask();    }  }    task void RecvTask() {    call computeInstruction(&recvContext);    if (recvContext.state == BOMB_STATE_RUN) {      post RecvTask();    }  }  /*  task void OnceTask() {    call computeInstruction(&onceContext);    if (onceContext.state == BOMB_STATE_RUN) {      post OnceTask();    }  }  */  command result_t executeContext(BombillaContext* context) {    dbg(DBG_USR1, "VM: At beginning of execCon.\n");    if (context->state != BOMB_STATE_RUN) {return FAIL;}    switch(context->which) {    case BOMB_CAPSULE_CLOCK:      dbg(DBG_USR1, "VM: Posting ClockTask in execCon.\n");      return post ClockTask();      dbg(DBG_USR1, "VM: Posted ClockTask.\n");      //return SUCCESS;      dbg(DBG_USR1, "VM: after return.\n");      break;      dbg(DBG_USR1, "VM: after break.\n");    case BOMB_CAPSULE_SEND:      dbg(DBG_USR1, "VM: Posting SendTask in execCon.\n");      post SendTask();      return SUCCESS;      break;    case BOMB_CAPSULE_RECV:      post RecvTask();      return SUCCESS;      break;      /*        case BOMB_CAPSULE_ONCE:        return post OnceTask();        case BOMB_CAPSULE_OUTER: */    default:      dbg(DBG_ERROR, "VM: Tried to run context not yet supported: %i\n", context->which);      return FAIL;    }    dbg(DBG_USR1, "VM: At end of execCon.\n");    return FAIL;  }  command result_t alertSendContext(BombillaContext* caller,                                    BombillaStackVariable* arg) {    if (sendContext.state == BOMB_STATE_HALT) {      nmemcpy(&state.sendrBuffer, arg->buffer.var, sizeof(BombillaDataBuffer));      call Synch.initializeContext(&sendContext, &state);      call Stacks.pushBuffer(&sendContext, &state.sendrBuffer);      dbg(DBG_USR1, "VM: Calling resumeCon for sendContext in alertSend. \n");      call Synch.resumeContext(caller, &sendContext, &(state.readyQueue), state.locks);      // This yield/resume allows locks to be yielded to the send context,      // and if none are shared, then it will just continue executing      if (caller->releaseSet) {        call Synch.releaseLocks(caller, caller, state.locks);        call Synch.yieldContext(caller, &(state.readyQueue), state.locks);        //call Synch.resumeContext(caller, caller, &(state.readyQueue), state.locks);      }    }    else {      // Don't send, fail silently -- send context busy    }    return SUCCESS;  }  command result_t alertReceiveContext(TOS_MsgPtr msg) {    if (!msg->crc) {return FAIL;}    if (recvContext.state != BOMB_STATE_HALT) {      dbg(DBG_USR1, "VM: Received packet, receive context busy, drop.\n");    }    else {      int i;      BombillaPacket* packet = (BombillaPacket*)(msg->data);      BombillaDataBuffer* buffer = (BombillaDataBuffer*)&(packet->payload);      dbg(DBG_USR1, "VM: Received packet, enqueuing receive context to run.\n");      dbg(DBG_USR1, "VM: Copying %i bytes of header over:\n  ", sizeof(recvContext.header));      for (i = 0; i < sizeof(recvContext.header); i++) {        dbg_clear(DBG_USR1, "%02hhx", packet->header[i]);      }      dbg_clear(DBG_USR1, "\n->");      nmemcpy(&(recvContext.header), packet->header, sizeof(recvContext.header));      for (i = 0; i < sizeof(recvContext.header); i++) {        dbg_clear(DBG_USR1, "%02hhx", ((uint8_t*)recvContext.header)[i]);      }      dbg_clear(DBG_USR1, "\n");      nmemcpy(&(state.recvBuffer), buffer, sizeof(BombillaDataBuffer));      call Synch.initializeContext(&recvContext, &state);      call Stacks.pushBuffer(&recvContext, &state.recvBuffer);      dbg(DBG_USR1, "VM: Calling resumeCon for recvCon in alertRec.\n");      call Synch.resumeContext(&recvContext, &recvContext, &(state.readyQueue), state.locks);    }    return SUCCESS;  }  command result_t StdControl.start() {    result_t res1, res2;    dbg(DBG_BOOT, "VM: Starting.\n");    res1 = call SubControlTimer.start();    res2 = call SubControlNetwork.start();    res2 = call SubControl.start();    call ClockTimer.start(TIMER_REPEAT, 1024);    return rcombine(res1, res2);  }  command result_t StdControl.stop() {    result_t res1, res2;    dbg(DBG_BOOT, "VM: Stopping.\n");    call ClockTimer.stop();    res1 = call SubControlTimer.stop();    res2 = call SubControlNetwork.stop();    res2 = call SubControl.stop();    return rcombine(res1, res2);  }    command result_t BombillaError.error(BombillaContext* context, uint8_t cause) {    state.inErrorState = TRUE;    dbg(DBG_ERROR|DBG_USR1, "VM: Entering ERROR state. Context: %i, cause %i\n", (int)context->which, (int)cause);    call Leds.redOn();    call Leds.greenOn();    call Leds.yellowOn();    state.errorContext = context;    if (context != NULL) {      state.errorContext = context;      state.errorMsg.context = context->which;      state.errorMsg.reason = cause;      state.errorMsg.capsule = context->capsule->capsule.type;      state.errorMsg.instruction = context->pc - 1;      context->state = BOMB_STATE_HALT;    }    else {      state.errorMsg.context = BOMB_CAPSULE_INVALID;      state.errorMsg.reason = cause;      state.errorMsg.capsule = BOMB_CAPSULE_INVALID;      state.errorMsg.instruction = 255;    }    return SUCCESS;  }  task void ClockErrorTask() {    dbg(DBG_USR1|DBG_ERROR, "VM: ERROR\n");    call Leds.redToggle();    call Leds.greenToggle();    call Leds.yellowToggle();    nmemcpy(state.errorContext->msg.data,	    &state.errorMsg,	    sizeof(BombillaErrorMsg));    if (state.errorFlipFlop) {      call SendError.send(TOS_UART_ADDR,			  sizeof(BombillaErrorMsg),			  (TOS_MsgPtr)&(state.errorContext->msg));    }    else {      call SendError.send(TOS_BCAST_ADDR,			  sizeof(BombillaErrorMsg),			  (TOS_MsgPtr)&(state.errorContext->msg));    }    state.errorFlipFlop = !state.errorFlipFlop;  }      task void ClockEventTask() {    if (clockContext.state == BOMB_STATE_HALT) {      call Synch.initializeContext(&clockContext, &state);      clockContext.state = BOMB_STATE_RUN;      //initializeContext(&clockContext);      dbg(DBG_USR1, "VM: Calling ResumeCon for clockCon in ClockEventTask.\n");      call Synch.resumeContext(&clockContext, &clockContext, &(state.readyQueue), state.locks);      //resumeContext(&clockContext, &clockContext);    }    else {      dbg(DBG_TEMP, "VM: Clock context not halted.\n");      // Can log a clock miss error here, but probably      // not a good idea    }  }  event result_t ClockTimer.fired() {    dbg(DBG_USR1, "VM: clock timer fired, posting ClockEventTask.\n");    if (state.inErrorState) {post ClockErrorTask();}    else {post ClockEventTask();}    return SUCCESS;  }  event result_t SendError.sendDone(TOS_MsgPtr msg, result_t success) {    return SUCCESS;  }    event TOS_MsgPtr ReceivePacket.receive(TOS_MsgPtr msg) {    return msg;  }    command result_t computeInstruction(BombillaContext* context) {    uint8_t instr = context->capsule->capsule.code[(int)context->pc];    //	dbg(DBG_USR1, "VM (%hhi): Issuing instruction 0x%hhx.\n", context->which, instr);    if (context->state != BOMB_STATE_RUN) {      dbg(DBG_ERROR, "VM: (%hhi) Tried to execute instruction in non-run state: %hhi\n", context->which, context->state);      return FAIL;    }    context->pc++;    call Bytecode.execute[instr](instr, context, &state);    return SUCCESS;    }  default command result_t Bytecode.execute[uint8_t opcode](uint8_t instr,							    BombillaContext* context,							    BombillaState* vmState) {    dbg(DBG_ERROR|DBG_USR1, "VM: Executing default instruction: halt!\n");    context->state = BOMB_STATE_HALT;    return FAIL;  }    event result_t Virus.capsuleInstalled(BombillaCapsule* capsule) {    //capsuleAnalysis(capsule->type & BOMB_OPTION_MASK);    return SUCCESS;  }  event result_t Virus.enableExecution() {    return SUCCESS;  }  event result_t Virus.disableExecution() {    return SUCCESS;  }  event result_t Virus.capsuleHeard(uint8_t type) {    return SUCCESS;  }  event void Virus.capsuleForce(uint8_t type) {    return;  }  event result_t Synch.makeRunnable(BombillaContext* context) {    dbg(DBG_USR1, "VM: make runnable event occured for %i.\n", (int)context->which);    context->state = BOMB_STATE_RUN;    dbg(DBG_USR1, "VM: calling execCon.\n");    return call executeContext(context);  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -