Example #1
0
//native print(..) function
void nativePrint(vm* vm, u08 a, u16 b, u16 c)
{

	//print all variables
	for(u08 i=0; i<b-1; i++)
	{
		vmregister reg = vm->state[vm->statept].reg[a+1+i];
		printRegister(reg);
	}

	if(b==0)
		printRegister(vm->state[vm->statept].reg[a+1]);

	platformPrintf("\n");
}
Example #2
0
//native print(..) function
void nativePrint(vm* vm, readBytes read, lu08 a, lu16 b, lu16 c)
{
	lu08 i=0;
	//print all variables
	for(i=0; i<b-1; i++)
	{
		vmregister reg = vm->state[vm->statept].reg[a+1+i];
		printRegister(read, reg);
	}

	if(b==0)
		printRegister(read, vm->state[vm->statept].reg[a+1]);

	printf("\n");
}
void Setup() {
    node.begin(9600); // set transmission rate - other parameters are set inside the object and can't be changed here

    printRegister(node, 3); // for debugging

    node.writeSingleRegister(0, 0x0406); // prepare for starting

    printRegister(node, 3); // for debugging

    Sleep(1000); // give converter some time to set up
    // note: we should have a startup state machine that check converter status and acts per current status
    //       but we take the easy way out and just wait a while and hope that everything goes well

    printRegister(node, 3); // for debugging

    node.writeSingleRegister(0, 0x047F); // set drive to start mode

    printRegister(node, 3); // for debugging

    Sleep(1000); // give converter some time to set up
    // note: we should have a startup state machine that check converter status and acts per current status
    //       but we take the easy way out and just wait a while and hope that everything goes well

    printRegister(node, 3); // for debugging

    int j = 0;


    uint8_t result;

    // slave: read (2) 16-bit registers starting at register 102 to RX buffer
    j = 0;
    do {
        result = node.readHoldingRegisters(102, 2);
        j++;
    } while(j < 3 && result != node.ku8MBSuccess);
    // note: sometimes we don't succeed on first read so we try up to threee times
    // if read is successful print frequency and current (scaled values)
    if (result == node.ku8MBSuccess) {
        printf("F=%4d, I=%4d  (ctr=%d)\n", node.getResponseBuffer(0), node.getResponseBuffer(1),j);
    }
    else {
        printf("ctr=%d\n",j);
    }
}
Example #4
0
int main(void)
{
#if defined (__USE_LPCOPEN)
    // Read clock settings and update SystemCoreClock variable
    SystemCoreClockUpdate();
#if !defined(NO_BOARD_LIB)
    // Set up and initialize all required blocks and
    // functions related to the board hardware
    Board_Init();
    // Set the LED to the state of "On"
    Board_LED_Set(0, true);
#endif
#endif
	ModbusMaster node(2); // Create modbus object that connects to slave id 2

		node.begin(9600); // set transmission rate - other parameters are set inside the object and can't be changed here

		printRegister(node, 3); // for debugging

		node.writeSingleRegister(0, 0x0406); // prepare for starting

		printRegister(node, 3); // for debugging

		Sleep(1000); // give converter some time to set up
		// note: we should have a startup state machine that check converter status and acts per current status
		//       but we take the easy way out and just wait a while and hope that everything goes well

		printRegister(node, 3); // for debugging

		node.writeSingleRegister(0, 0x047F); // set drive to start mode

		printRegister(node, 3); // for debugging

		Sleep(1000); // give converter some time to set up
		// note: we should have a startup state machine that check converter status and acts per current status
		//       but we take the easy way out and just wait a while and hope that everything goes well

		printRegister(node, 3); // for debugging

		int i = 0;
		int j = 0;
		const uint16_t fa[20] = { 1000, 2000, 3000, 3500, 4000, 5000, 7000, 8000, 8300, 10000, 10000, 9000, 8000, 7000, 6000, 5000, 4000, 3000, 2000, 1000 };

		while (1) {
			uint8_t result;

			// slave: read (2) 16-bit registers starting at register 102 to RX buffer
			j = 0;
			do {
				result = node.readHoldingRegisters(102, 2);
				j++;
			} while(j < 3 && result != node.ku8MBSuccess);
			// note: sometimes we don't succeed on first read so we try up to threee times
			// if read is successful print frequency and current (scaled values)
			if (result == node.ku8MBSuccess) {
				printf("F=%4d, I=%4d  (ctr=%d)\n", node.getResponseBuffer(0), node.getResponseBuffer(1),j);
			}
			else {
				printf("ctr=%d\n",j);
			}

			Sleep(3000);
			i++;
			if(i >= 20) {
				i=0;
			}
			// frequency is scaled:
			// 20000 = 50 Hz, 0 = 0 Hz, linear scale 400 units/Hz
			setFrequency(node, fa[i]);
		}

		return 0;

}
static std::string formatRegister(LIBMAUS2_SIMD_WORD_TYPE const reg)
{
	std::ostringstream ostr;
	printRegister(ostr,reg);
	return ostr.str();
}
Example #6
0
/* translate each instruction in his assembler symbolic representation */
void translateCodeSegment(t_program_infos *program, FILE *fp)
{
   t_list *current_element;
   t_axe_instruction *current_instruction;
   int _error;
   
   /* preconditions */
   if (fp == NULL)
      notifyError(AXE_INVALID_INPUT_FILE);

   if (program == NULL)
   {
      _error = fclose(fp);
      if (_error == EOF)
         notifyError(AXE_FCLOSE_ERROR);
      notifyError(AXE_PROGRAM_NOT_INITIALIZED);
   }

   /* initialize the current_element */
   current_element = program->instructions;

   /* write the .text directive */
   if (current_element != NULL)
   {
      if (fprintf(fp, "\t.text\n") < 0)
      {
         _error = fclose(fp);
         if (_error == EOF)
            notifyError(AXE_FCLOSE_ERROR);
         notifyError(AXE_FWRITE_ERROR);
      }
   }

   while (current_element != NULL)
   {
      /* retrieve the current instruction */
      current_instruction = (t_axe_instruction *) LDATA(current_element);
      assert(current_instruction != NULL);
      assert(current_instruction->opcode != INVALID_OPCODE);

      if (current_instruction->labelID != NULL)
      {
            /* create a string identifier for the label */
            if (  fprintf(fp, "L%d : \t"
                     , (current_instruction->labelID)->labelID ) < 0)
            {
              _error = fclose(fp);
               if (_error == EOF)
                  notifyError(AXE_FCLOSE_ERROR);
               notifyError(AXE_FWRITE_ERROR);
            }
      }
      else
      {
            /* create a string identifier for the label */
            if (fprintf(fp, "\t") < 0)
            {
              _error = fclose(fp);
               if (_error == EOF)
                  notifyError(AXE_FCLOSE_ERROR);
               notifyError(AXE_FWRITE_ERROR);
            }
      }

      /* print the opcode */
      printOpcode(current_instruction->opcode, fp);

      if (  (current_instruction->opcode == HALT)
            || (current_instruction->opcode == NOP) )
      {
         if (fprintf(fp, "\n") < 0)
         {
              _error = fclose(fp);
               if (_error == EOF)
                  notifyError(AXE_FCLOSE_ERROR);
               notifyError(AXE_FWRITE_ERROR);
         }

         /* update the current_element */
         current_element = LNEXT(current_element);
         continue;
      }
      
      if (fputc(' ', fp) == EOF)
      {
         _error = fclose(fp);
         if (_error == EOF)
            notifyError(AXE_FCLOSE_ERROR);
         notifyError(AXE_FWRITE_ERROR);
      }

      if (current_instruction->reg_1 != NULL)
      {
         printRegister(current_instruction->reg_1, fp);
         
         if (fputc(' ', fp) == EOF)
         {
            _error = fclose(fp);
            if (_error == EOF)
               notifyError(AXE_FCLOSE_ERROR);
            notifyError(AXE_FWRITE_ERROR);
         }
      }
      if (current_instruction->reg_2 != NULL)
      {
         printRegister(current_instruction->reg_2, fp);
         if (errorcode != AXE_OK)
            return;

         if (fputc(' ', fp) == EOF)
         {
            _error = fclose(fp);
            if (_error == EOF)
               notifyError(AXE_FCLOSE_ERROR);
            notifyError(AXE_FWRITE_ERROR);
         }
      }
      if (current_instruction->reg_3 != NULL)
      {
         printRegister(current_instruction->reg_3, fp);

         if (fprintf(fp, "\n") < 0) {
            _error = fclose(fp);
            if (_error == EOF)
               notifyError(AXE_FCLOSE_ERROR);
            notifyError(AXE_FWRITE_ERROR);
         }

         /* update the current_element */
         current_element = LNEXT(current_element);
         continue;
      }

      if (current_instruction->address != NULL)
      {
         if ((current_instruction->address)->type == ADDRESS_TYPE)
         {
            if (fprintf(fp, "%d", (current_instruction->address)->addr) < 0)
            {
               _error = fclose(fp);
               if (_error == EOF)
                  notifyError(AXE_FCLOSE_ERROR);
               notifyError(AXE_FWRITE_ERROR);
            }
         }
         else
         {
            assert((current_instruction->address)->type == LABEL_TYPE);
            if (  fprintf(fp, "L%d"
                     , ((current_instruction->address)->labelID)
                              ->labelID) < 0)
            {
               _error = fclose(fp);
               if (_error == EOF)
                  notifyError(AXE_FCLOSE_ERROR);
               notifyError(AXE_FWRITE_ERROR);
            }
         }
         
         if (fprintf(fp, "\n") < 0) {
            _error = fclose(fp);
            if (_error == EOF)
               notifyError(AXE_FCLOSE_ERROR);
            notifyError(AXE_FWRITE_ERROR);
         }

         /* update the current_element */
         current_element = LNEXT(current_element);
         continue;
      }

      if (fprintf(fp, "#%d", current_instruction->immediate) < 0)
      {
         _error = fclose(fp);
         if (_error == EOF)
            notifyError(AXE_FCLOSE_ERROR);
         notifyError(AXE_FWRITE_ERROR);
      }

      if (fprintf(fp, "\n") < 0) {
         _error = fclose(fp);
         if (_error == EOF)
            notifyError(AXE_FCLOSE_ERROR);
         notifyError(AXE_FWRITE_ERROR);
      }

      /* loop termination condition */
      current_element = LNEXT(current_element);
   }
}