Пример #1
0
void EraseFlashPage(u16 a) { // a = byte address of first word of page
  Assert((a & (PageSize()-1)) == 0);
  DwSetRegs(29, Bytes(PGERS, lo(a), hi(a))); // r29 := op (erase page), Z = first byte address of page
  DwSetPC(BootSect());                       // Set PC that allows access to all of flash
  DwSend(Bytes(0x64));                       // Set up for single step mode
  DwOut(SPMCSR(), 29);                       // out SPMCSR,r29 (select page erase)
  DwSend(Bytes(0xD2, 0x95, 0xE8, 0x33));     // spm (do page erase)
  DwSync();
}
Пример #2
0
static void
faultamd64(Ureg* ureg, void* v)
{
    Proc *up = externup();
    uint64_t addr;
    int ftype, user, insyscall;
    char buf[ERRMAX];

    addr = machp()->MMU.cr2;
    user = userureg(ureg);
    if(!user && mmukmapsync(addr))
        return;

    /*
     * There must be a user context.
     * If not, the usual problem is causing a fault during
     * initialisation before the system is fully up.
     */
    if(up == nil) {
        panic("fault with up == nil; pc %#llx addr %#llx\n",
              ureg->ip, addr);
    }

    ftype = (ureg->error&2) ? FT_WRITE : (ureg->error&16) ? FT_EXEC : FT_READ;
    /*
    if (read) hi("read fault\n"); else hi("write fault\n");
    hi("addr "); put64(addr); hi("\n");
     */

    insyscall = up->insyscall;
    up->insyscall = 1;
    if (0)hi("call fault\n");

    if(fault(addr, ureg->ip, ftype) < 0) {
        iprint("could not %s fault %p\n", faulttypes[ftype], addr);
        /*
         * It is possible to get here with !user if, for example,
         * a process was in a system call accessing a shared
         * segment but was preempted by another process which shrunk
         * or deallocated the shared segment; when the original
         * process resumes it may fault while in kernel mode.
         * No need to panic this case, post a note to the process
         * and unwind the error stack. There must be an error stack
         * (up->nerrlab != 0) if this is a system call, if not then
         * the game's a bogey.
         */
        if(!user && (!insyscall || up->nerrlab == 0))
            panic("fault: %#llx\n", addr);
        sprint(buf, "sys: trap: fault %s addr=%#llx",
               faulttypes[ftype], addr);
        postnote(up, 1, buf, NDebug);
        if(insyscall)
            error(buf);
    }
    up->insyscall = insyscall;
}
Пример #3
0
void split_window (zword height)
{
    zword stat_height = 0;

    flush_buffer ();

    /* Calculate height of status line and upper window */

    if (h_version != V6)
        height *= hi (wp[1].font_size);

    if (h_version <= V3)
        stat_height = hi (wp[7].font_size);

    /* Cursor of upper window mustn't be swallowed by the lower window */

    wp[1].y_cursor += wp[1].y_pos - 1 - stat_height;

    wp[1].y_pos = 1 + stat_height;
    wp[1].y_size = height;

    if ((short) wp[1].y_cursor > (short) wp[1].y_size)
        reset_cursor (1);

    /* Cursor of lower window mustn't be swallowed by the upper window */

    wp[0].y_cursor += wp[0].y_pos - 1 - stat_height - height;

    wp[0].y_pos = 1 + stat_height + height;
    wp[0].y_size = h_screen_height - stat_height - height;

    if ((short) wp[0].y_cursor < 1)
        reset_cursor (0);

    /* Erase the upper window in V3 only */

    if (h_version == V3 && height != 0)
        erase_window (1);

    os_window_height (0, wp[0].y_size);
    os_window_height (1, wp[1].y_size);

}/* split_window */
Пример #4
0
///////////////////////////////////////////////////////////////////
//   CAN MESSAGING FUNCTIONS:
///////////////////////////////////////////////////////////////////
void Motor::pack_move_to_angle( float mAngleDeg, word mSpeedHundredthPercent )
{
	MMsg.id = create_CAN_eid( ID_MOVE_TO_ANGLE, Instance );
	MMsg.header.DLC = 6;
	MMsg.header.rtr = 0;

	// PREPARE ANGLE:
	long int AngleHundredths = mAngleDeg * 100;
	word hi_Angle = hi_word(AngleHundredths);
	word lo_Angle = lo_word(AngleHundredths);
	MMsg.data[0] = hi(hi_Angle);
	MMsg.data[1] = lo(hi_Angle);
	MMsg.data[2] = hi(lo_Angle);
	MMsg.data[3] = lo(lo_Angle);

	// PREPARE SPEED:
	MMsg.data[4] = hi(mSpeedHundredthPercent);		// or tenth percent?
	MMsg.data[5] = lo(mSpeedHundredthPercent);
}
Пример #5
0
void GMD1602::data(uint8_t data) {
	lo(RW);
	hi(RS);

	write4(data);
	delayTimer.uDelay(50);
	write4(data << 4);

	delayTimer.uDelay(50);
}
Пример #6
0
void write_ext_eeprom(long int address, byte data) {

   i2c_start();
   i2c_write(0xa0);
   i2c_write(hi(address));
   i2c_write(address);
   i2c_write(data);
   i2c_stop();
   delay_ms(11);
}
Пример #7
0
std::string hexUUID (std::string in) {
    std::ostringstream out;
    for (unsigned n = 0; n < 4; ++n)
      out << hi(in[n]) << lo(in[n]);
    out << '-';
    for (unsigned n = 4; n < 6; ++n)
      out << hi(in[n]) << lo(in[n]);
    out << '-';
    for (unsigned n = 6; n < 8; ++n)
      out << hi(in[n]) << lo(in[n]);
    out << '-';
    for (unsigned n = 8; n < 10; ++n)
      out << hi(in[n]) << lo(in[n]);
    out << '-';
    for (unsigned n = 10; n < 16; ++n)
      out << hi(in[n]) << lo(in[n]);
    std::string op=out.str();
    return op;
}
Пример #8
0
void TTStringTestStream(int& errorCount, int&testAssertionCount)
{
	TTTestLog("\n");
	TTTestLog("Testing string stream");
	TTTestLog("(there will be no assertions, look for stdout output)");
	
	TTString hi("Hello World!");
	
	std::cout << "	Passing TTString to stdout: " << hi << " (hooray)" << std::endl;
}
Пример #9
0
void die(char *s)
{
	wave('d');
	wave('i');
	wave('e');
	wave(':');
	hi(s);
	while(staydead);
	staydead = 1;
}
Пример #10
0
static inline AbstractQoreNode* crlr_hash_copy(const QoreHashNode* n, ExceptionSink* xsink) {
   ReferenceHolder<QoreHashNode> h(new QoreHashNode(true), xsink);
   ConstHashIterator hi(n);
   while (hi.next()) {
      h->setKeyValue(hi.getKey(), copy_and_resolve_lvar_refs(hi.getValue(), xsink), xsink);
      if (*xsink)
	 return 0;
   }
   return h.release();
}
Пример #11
0
void can_prep_motor_angle( sCAN* mMsg )
{
	byte size = 4;
    mMsg->id = create_CAN_eid( ID_MOTOR_ANGLE, MyInstance );
	// GET CURRENT ANGLE :
	float_array Angle; 
	Angle.value = get_motor_angle();

	for (int i=0; i<size; i++)
	    mMsg->data[i] = Angle.array[i];

	// MOTOR CURRENT (Larger of left/right) (in Amps*10):
	mMsg->data[size+0] = hi(LeftCurrentSample[1]*10 );
	mMsg->data[size+1] = lo(LeftCurrentSample[1]*10 );
	mMsg->data[size+2] = hi(RightCurrentSample[1]*10);
	mMsg->data[size+3] = lo(RightCurrentSample[1]*10);
    mMsg->header.DLC = size+4;
    mMsg->header.rtr = 0;
}
Пример #12
0
rt_rrect::rt_rrect(const rt_point& p)
    : rt_rect(p.dim(),
	new double[rt_rrect::dim2size(p.dim())/sizeof(double)]),
      rank(p.dim(), coord + (rt_rect::dim2size(p.dim())/sizeof(double)))
{
    dealloc = true;
    for (int i = 0; i < dimension; i++) {
        hi(i) = lo(i) = p.co(i);
    }
    rank.nrec() = 1;
}
Пример #13
0
void can_prep_board_revision_msg( ssCAN* mMsg )
{
	mMsg->id  = create_CAN_eid( ID_BOARD_REVISION, MyInstance );
    mMsg->data[0] = HARDWARE_REVISION;
    mMsg->data[1] = SOFTWARE_MAJOR;
    mMsg->data[2] = SOFTWARE_MINOR;
    mMsg->data[3] = lo(MANUFACTURER);
    mMsg->data[4] = hi(MANUFACTURER);
    mMsg->header.DLC 	= 5;
    mMsg->header.rtr    = 0;
}
Пример #14
0
void LoadPageBuffer(u16 a, const u8 *buf) {
  DwSetRegs(29, Bytes(SPMEN, lo(a), hi(a))); // r29 := op (write next page buffer word), Z = first byte address of page
  DwSend(Bytes(0x64));                       // Set up for single step mode
  const u8 *limit = buf + PageSize();
  while (buf < limit) {
    DwSetRegs(0, buf, 2); buf += 2;  // r0 := low byte, r1 := high byte
    DwSetPC(BootSect());             // Set PC that allows access to all of flash
    DwOut(SPMCSR(), 29);             // out SPMCSR,r29 (write next page buffer word)
    DwInst(0x95E8);                  // spm
    DwInst(0x9632);                  // adiw Z,2
  }
}
Пример #15
0
rt_rrect::rt_rrect(const rt_rrect& r)
    : rt_rect(r.dim(),
	new double[rt_rrect::dim2size(r.dim())/sizeof(double)]),
      rank(r.dim(), coord + (rt_rect::dim2size(r.dim())/sizeof(double)))
{
    dealloc = true;
    for (int i = 0; i < dimension; i++) {
        lo(i) = r.lo(i);
        hi(i) = r.hi(i);
    }
    rank.nrec() = r.rank.nrec();
}
Пример #16
0
void erase_window (zword win)
{
    zword y = wp[win].y_pos;
    zword x = wp[win].x_pos;

    if (h_version == V6 && win != cwin && h_interpreter_number != INTERP_AMIGA)
        os_set_colour (lo (wp[win].colour), hi (wp[win].colour));

    os_erase_area (y,
                   x,
                   y + wp[win].y_size - 1,
                   x + wp[win].x_size - 1);

    if (h_version == V6 && win != cwin && h_interpreter_number != INTERP_AMIGA)
        os_set_colour (lo (cwp->colour), hi (cwp->colour));

    reset_cursor (win);

    wp[win].line_count = 0;

}/* erase_window */
Пример #17
0
    bool AddFeatureDifferenceDataTest(bool create, int width, int height, const Func & f)
    {
        bool result = true;

        Data data(f.description);

        TEST_LOG_SS(Info, (create ? "Create" : "Verify") << " test " << f.description << " [" << width << ", " << height << "].");

        View value(width, height, View::Gray8, NULL, TEST_ALIGN(width));
        View lo(width, height, View::Gray8, NULL, TEST_ALIGN(width));
        View hi(width, height, View::Gray8, NULL, TEST_ALIGN(width));
        View differenceSrc(width, height, View::Gray8, NULL, TEST_ALIGN(width));

        View differenceDst1(width, height, View::Gray8, NULL, TEST_ALIGN(width));
        View differenceDst2(width, height, View::Gray8, NULL, TEST_ALIGN(width));

        const uint16_t weight = 256*7;

        if(create)
        {
            FillRandom(value);
            FillRandom(lo);
            FillRandom(hi);
            FillRandom(differenceSrc);

            TEST_SAVE(value);
            TEST_SAVE(lo);
            TEST_SAVE(hi);
            TEST_SAVE(differenceSrc);

            f.Call(value, lo, hi, weight, differenceSrc, differenceDst1);

            TEST_SAVE(differenceDst1);
        }
        else
        {
            TEST_LOAD(value);
            TEST_LOAD(lo);
            TEST_LOAD(hi);

            TEST_LOAD(differenceSrc);
            TEST_LOAD(differenceDst1);

            f.Call(value, lo, hi, weight, differenceSrc, differenceDst2);

            TEST_SAVE(differenceDst2);

            result = result && Compare(differenceDst1, differenceDst2, 0, true, 32, 0);
        }

        return result;
    }
Пример #18
0
void Motor::pack_move_speed( float mSpeedPercent )
{
	MMsg.id = create_CAN_eid( ID_MOVE_SPEED, Instance );
	MMsg.header.DLC = 2;
	MMsg.header.rtr = 0;

	// User enters a number [-100.0 , 100.0]
	// BigMotorEn board looks for Percent*100 however 
	//(for additional resolution)
	short Speed  = round(mSpeedPercent * 100.0);	// *100 = 10,000
	MMsg.data[0] = hi(Speed);		// 65 535
	MMsg.data[1] = lo(Speed);		// 10 000
}
Пример #19
0
void can_prep_motor_speed( sCAN* mMsg, float_array mSpeed )
{
    mMsg->id 	  = create_CAN_eid( 0x00, ID_MOTOR_SPEED, MyInstance );
	if (config_byte_1 & MODE_USE_ENCODER)  {
		mMsg->data[0] = hi(EncoderSpeed);
		mMsg->data[1] = lo(EncoderSpeed);
	} else {
		for (int i=0; i<size; i++)
		    mMsg->data[i] = mSpeed.array[i];
	}
    mMsg->header.DLC = size;
    mMsg->header.rtr = 0;
}
Пример #20
0
void cpu_save_PC(void) {
	
	cpu.stack[cpu.sp] = lo(cpu.pc);
	
	cpu.sp --;
	
	cpu.stack[cpu.sp] = hi(cpu.pc);
	
	/* WTF? */
	
	cpu.sp --;
	
}
Пример #21
0
void PanoramaPhotoModeManager::StartHugin()
{
   HuginInterface hi(m_host.GetAppSettings().m_cszHuginPath);
   if (!hi.IsInstalled())
   {
      m_host.SetStatusText(_T("Finished taking panorama images"));
      return;
   }

   m_host.SetStatusText(_T("Starting Hugin..."));

   hi.RunUI(m_vecPanoramaFilenameList);
}
Пример #22
0
byte read_ext_eeprom(long int address) {
   byte data;

   i2c_start();
   i2c_write(0xa0);
   i2c_write(hi(address));
   i2c_write(address);
   i2c_start();
   i2c_write(0xa1);
   data=i2c_read(0);
   i2c_stop();
   return(data);
}
Пример #23
0
void ProgramPage(u16 a) {
  DwSend(Bytes(0x66));
  DwSetRegs(29, Bytes(PGWRT, lo(a), hi(a))); // r29 = op (page write), Z = first byte address of page
  DwSetPC(BootSect());                       // Set PC that allows access to all of flash
  DwSend(Bytes(0x64));                       // Set up for single step mode
  DwOut(SPMCSR(), 29);                       // out SPMCSR,r29 (PGWRT)
  if (BootSect()) {
    DwInst(0x95E8);                          // spm
    while ((ReadSPMCSR() & 0x1F) != 0) {Wc('.'); Wflush();} // Wait while programming busy
  } else {
    DwSend(Bytes(0xD2, 0x95, 0xE8, 0x33));   // spm and break
    DwSync();
  }
}
Пример #24
0
void can_prep_motor_values_raw( sCAN* mMsg )
{
    mMsg->id 	  = create_CAN_eid( 0x00, ID_MOTOR_VALUE, MyInstance );
	if (isConfigured(MODE_USE_ENCODER))  {
		mMsg->data[0] = hi(EncoderCount);
		mMsg->data[1] = lo(EncoderCount);	
	} else {
		mMsg->data[0] = hi(PotSample[1]);
		mMsg->data[1] = lo(PotSample[1]);
	}
	
	// Also send Currents Raw:
	mMsg->data[2] = hi(LeftCurrentSample[1] );
	mMsg->data[3] = lo(LeftCurrentSample[1] );
	mMsg->data[4] = hi(RightCurrentSample[1]);
	mMsg->data[5] = lo(RightCurrentSample[1]);

	word Duty = MotorDutyRequest * 100;
	mMsg->data[6] = hi(Duty);
	mMsg->data[7] = lo(Duty);	
    mMsg->header.DLC = 8;
    mMsg->header.rtr = 0;
}
Пример #25
0
void resize_screen (void)
{

    if (h_version != V6) {

        int h = wp[0].y_pos + wp[0].y_size;

        wp[0].x_size = h_screen_width;
        wp[1].x_size = h_screen_width;
        wp[7].x_size = h_screen_width;

        wp[0].y_size = h_screen_height - wp[1].y_size;
        if (h_version <= V3)
            wp[0].y_size -= hi (wp[7].font_size);

        if (os_font_data (TEXT_FONT, &font_height, &font_width)) {

            int i;
            for (i = 0; i < 8; i++)
                wp[i].font_size = (font_height << 8) | font_width;
        }

        if (cwin == 0) {

            int lines = wp[0].y_cursor + font_height - wp[0].y_size - 1;

            if (lines > 0) {

                if (lines % font_height != 0)
                    lines += font_height;
                lines /= font_height;

                if (wp[0].y_cursor > (font_height * lines)) {

                    os_scroll_area (wp[0].y_pos,
                                    wp[0].x_pos,
                                    h - 1,
                                    wp[0].x_pos + wp[0].x_size - 1,
                                    font_height * lines);
                    wp[0].y_cursor -= (font_height * lines);
                    update_cursor ();
                }
            }
        }

        os_window_height (0, wp[0].y_size);

    }

}/* resize_screen */
Пример #26
0
int encode_const(char *data, int *bytes_left, argument *arg) {
	int bytes_written = 0;

	switch (Encoding) {
		case short_encoding:
			put_nybbles(0x0, Value);
			break;
		case medium_encoding:
			put_nybbles(0x1, hi(Value));
			put_byte(lo(Value));
			break;
		case byte_encoding:
			put_nybbles(0x2, 0x0);
			put_byte(Value);
			break;
		case long_encoding:
			put_nybbles(0x2, 0x1);
			put_byte(hi(Value));
			put_byte(lo(Value));
			break;
	}

	return bytes_written;
}
Пример #27
0
void
ApplyLedgerChainWork::openCurrentInputFiles()
{
    mHdrIn.close();
    mTxIn.close();
    FileTransferInfo hi(mDownloadDir, HISTORY_FILE_TYPE_LEDGER, mCurrSeq);
    FileTransferInfo ti(mDownloadDir, HISTORY_FILE_TYPE_TRANSACTIONS, mCurrSeq);
    CLOG(DEBUG, "History") << "Replaying ledger headers from "
                           << hi.localPath_nogz();
    CLOG(DEBUG, "History") << "Replaying transactions from "
                           << ti.localPath_nogz();
    mHdrIn.open(hi.localPath_nogz());
    mTxIn.open(ti.localPath_nogz());
    mTxHistoryEntry = TransactionHistoryEntry();
}
Пример #28
0
inline void
test_prox_topk_cone_biased_check_feasible(const ptrdiff_t k, const Type rho,
        const Type eps, std::vector<Type>& v) {
    sdca::prox_topk_cone_biased(v.begin(), v.end(), k, rho);

    Type sum = std::accumulate(v.begin(), v.end(), static_cast<Type>(0));

    Type lo(0), hi(sum / static_cast<Type>(k));
    std::for_each(v.begin(), v.end(), [=](const Type x) {
        ASSERT_GE(x, lo);
    });
    std::for_each(v.begin(), v.end(), [=](const Type x) {
        ASSERT_LE(x, hi + eps);
    });
}
Пример #29
0
TEST(SimpleString, split)
{
	SimpleString hi("hello\nworld\nhow\ndo\nyou\ndo\n\n");

	SimpleStringCollection collection;
	hi.split("\n", collection);

	LONGS_EQUAL(7, collection.size());
	STRCMP_EQUAL("hello\n", collection[0].asCharString());
	STRCMP_EQUAL("world\n", collection[1].asCharString());
	STRCMP_EQUAL("how\n", collection[2].asCharString());
	STRCMP_EQUAL("do\n", collection[3].asCharString());
	STRCMP_EQUAL("you\n", collection[4].asCharString());
	STRCMP_EQUAL("do\n", collection[5].asCharString());
	STRCMP_EQUAL("\n", collection[6].asCharString());
}
Пример #30
0
/*
 * colour_in_use
 *
 * Check if a colour is set in any window.
 *
 */
int colour_in_use (zword colour)
{
    int max = (h_version == V6) ? 8 : 2;
    int i;

    for (i = 0; i < max; i++) {
        zword bg = hi (wp[i].colour);
        zword fg = lo (wp[i].colour);

        if (colour == fg || colour == bg)
            return 1;
    }

    return 0;

}/* colour_in_use */