示例#1
0
void type(const char* s) {
  INBUF_IN = INBUF_START;
  for (int i = 0; s[i] != 0; ++i) {
    byte_write(INBUF_IN++, s[i]);
  }
  byte_write(INBUF_IN, 0);
}
示例#2
0
文件: pmove.c 项目: elhobbs/quake2dsi
/*
==============
PM_CheckDuck

Sets mins, maxs, and pm->viewheight
==============
*/
void PM_CheckDuck (void)
{
	trace_t	trace;

	pm->mins[0] = -16;
	pm->mins[1] = -16;

	pm->maxs[0] = 16;
	pm->maxs[1] = 16;

	if (pm->s.pm_type == PM_GIB)
	{
		pm->mins[2] = 0;
		pm->maxs[2] = 16;
		pm->viewheight = 8;
		return;
	}

	pm->mins[2] = -24;

	if (pm->s.pm_type == PM_DEAD)
	{
//		pm->s.pm_flags |= PMF_DUCKED;
		byte_write(&pm->s.pm_flags, pm->s.pm_flags | PMF_DUCKED);
	}
	else if (pm->cmd.upmove < 0 && (pm->s.pm_flags & PMF_ON_GROUND) )
	{	// duck
//		pm->s.pm_flags |= PMF_DUCKED;
		byte_write(&pm->s.pm_flags, pm->s.pm_flags | PMF_DUCKED);
	}
	else
	{	// stand up if possible
		if (pm->s.pm_flags & PMF_DUCKED)
		{
			// try to stand up
			pm->maxs[2] = 32;
			trace = pm->trace (pml.origin, pm->mins, pm->maxs, pml.origin);
			if (!trace.allsolid)
//				pm->s.pm_flags &= ~PMF_DUCKED;
				byte_write(&pm->s.pm_flags, pm->s.pm_flags & ~PMF_DUCKED);
		}
	}

	if (pm->s.pm_flags & PMF_DUCKED)
	{
		pm->maxs[2] = 4;
		pm->viewheight = -2;
	}
	else
	{
		pm->maxs[2] = 32;
		pm->viewheight = 22;
	}
}
示例#3
0
文件: pmove.c 项目: elhobbs/quake2dsi
/*
=============
PM_CheckSpecialMovement
=============
*/
void PM_CheckSpecialMovement (void)
{
	vec3_t	spot;
	int		cont;
	vec3_t	flatforward;
	trace_t	trace;

	if (pm->s.pm_time)
		return;

//	pml.ladder = false;
	byte_write(&pml.ladder, false);

	// check for ladder
	flatforward[0] = pml.forward[0];
	flatforward[1] = pml.forward[1];
	flatforward[2] = 0;
	VectorNormalize (flatforward);

	VectorMA (pml.origin, 1, flatforward, spot);
	trace = pm->trace (pml.origin, pm->mins, pm->maxs, spot);
	if ((trace.fraction < 1) && (trace.contents & CONTENTS_LADDER))
//		pml.ladder = true;
		byte_write(&pml.ladder, true);

	// check for water jump
	if (pm->waterlevel != 2)
		return;

	VectorMA (pml.origin, 30, flatforward, spot);
	spot[2] += 4;
	cont = pm->pointcontents (spot);
	if (!(cont & CONTENTS_SOLID))
		return;

	spot[2] += 16;
	cont = pm->pointcontents (spot);
	if (cont)
		return;
	// jump out of water
	VectorScale (flatforward, 50, pml.velocity);
	pml.velocity[2] = 350;

//	pm->s.pm_flags |= PMF_TIME_WATERJUMP;
//	pm->s.pm_time = 255;
	
	byte_write(&pm->s.pm_flags, pm->s.pm_flags | PMF_TIME_WATERJUMP);
	byte_write(&pm->s.pm_time, 255);
}
示例#4
0
文件: pmove.c 项目: elhobbs/quake2dsi
/*
=============
PM_CheckJump
=============
*/
void PM_CheckJump (void)
{
	if (pm->s.pm_flags & PMF_TIME_LAND)
	{	// hasn't been long enough since landing to jump again
		return;
	}

	if (pm->cmd.upmove < 10)
	{	// not holding jump
//		pm->s.pm_flags &= ~PMF_JUMP_HELD;
		byte_write(&pm->s.pm_flags, pm->s.pm_flags & ~PMF_JUMP_HELD);
		return;
	}

	// must wait for jump to be released
	if (pm->s.pm_flags & PMF_JUMP_HELD)
		return;

	if (pm->s.pm_type == PM_DEAD)
		return;

	if (pm->waterlevel >= 2)
	{	// swimming, not jumping
		pm->groundentity = NULL;

		if (pml.velocity[2] <= -300)
			return;

		if (pm->watertype == CONTENTS_WATER)
			pml.velocity[2] = 100;
		else if (pm->watertype == CONTENTS_SLIME)
			pml.velocity[2] = 80;
		else
			pml.velocity[2] = 50;
		return;
	}

	if (pm->groundentity == NULL)
		return;		// in air, so no effect

//	pm->s.pm_flags |= PMF_JUMP_HELD;
	byte_write(&pm->s.pm_flags, pm->s.pm_flags | PMF_JUMP_HELD);

	pm->groundentity = NULL;
	pml.velocity[2] += 270;
	if (pml.velocity[2] < 270)
		pml.velocity[2] = 270;
}
示例#5
0
文件: timer.c 项目: Aishou/lxdream
/**
 * Initialize the on-chip timer controller. We snag TMU channel 2 in its
 * highest resolution mode, and start it counting down from max_int. 
 */
void timer_init() {
    unsigned int val = byte_read(TSTR);
    byte_write( TSTR, val & (~(1<<TMU_CHANNEL)) ); /* Stop counter */
    long_write( TCOR(TMU_CHANNEL), 0xFFFFFFFF );
    long_write( TCNT(TMU_CHANNEL), 0xFFFFFFFF );
    word_write( TCR(TMU_CHANNEL), 0x00000000 );
}
示例#6
0
文件: bs.c 项目: klammerj/iverilog
int bitSWrite(BitStream *bs,char * file)
{
	FILE * fp;
	int nw,i;
	DListE *e;
	fp=fopen(file,"wt");
	assert(fp);
	
	assert(0==bs->nu);
	byte_write(fp,bs->nu);
	
	assert(bs->pe==0xb7);
	byte_write(fp,bs->pe);
	
	assert(get_cr(28)==0);//reserved==0
	for(i=0;i<4;i++)
	{
		byte_write(fp,bs->cregs[i]);
	}
//	byte_write(fp,bs->idunno);
	
	nw=dlistCount(&bs->windows);
	byte_write(fp,(nw>>8)&0x0ff);
	byte_write(fp,nw&0x0ff);
	e=dlistFirst(&bs->windows);
	while(e)
	{
		BitSWindow * w=(BitSWindow *)e;
		window_write(fp,w);
		e=dlistENext(e);
	}
	
	assert(bs->po==0xe7);
	byte_write(fp,bs->po);
	fclose(fp);
	return 0;
}
示例#7
0
文件: fwh.c 项目: datgao/bbflash
bool fwh_write_address(FWH *fwh, uint32_t addr, uint8_t byte)
{
	fwh_start(fwh, FWH_START_WRITE);
	fwh_nibble_write(fwh, 0);	/* IDSEL hardwired */
	fwh_send_imaddr(fwh, addr);
	fwh_nibble_write(fwh, 0);	/* IMSIZE single byte */
	byte_write(fwh->clock, fwh->nibble, byte);
	nibble_write(fwh->nibble, 0xf);
	nibble_set_dir(fwh->nibble, INPUT);
	clock_cycle(fwh->clock);
	clock_cycle(fwh->clock);
	if (!nibble_ready_sync(fwh->clock, fwh->nibble))
		return false;
	clock_cycle(fwh->clock);
	return true;
}
示例#8
0
文件: bs.c 项目: klammerj/iverilog
static void window_write(FILE *fp,BitSWindow *w)
{
	int nbytes,i;
	byte_write(fp,w->sa[0]);
	byte_write(fp,w->sa[1]);
	byte_write(fp,w->sa[2]);
	byte_write(fp,w->ea[0]);
	byte_write(fp,w->ea[1]);
	byte_write(fp,w->ea[2]);
	nbytes=a2nb(w->sa,w->ea);
	for(i=0;i<nbytes;i++)
	{
		byte_write(fp,w->bytes[i]);
	}
}
示例#9
0
/***********************************************************************
[function]:
                        callback:          burn the FW to ctpm.
[parameters]:
			    pbt_buf[in]:     point to Head+FW ;
			    dw_lenth[in]:   the length of the FW + 6(the Head length);
[return]:
			    ERR_OK:          no error;
			    ERR_MODE:      fail to switch to UPDATE mode;
			    ERR_READID:   read id fail;
			    ERR_ERASE:     erase chip fail;
			    ERR_STATUS:   status error;
			    ERR_ECC:        ecc error.
************************************************************************/
E_UPGRADE_ERR_TYPE  fts_ctpm_fw_upgrade(u8* pbt_buf, int dw_lenth)
{
    u8  cmd,reg_val[2] = {0};
    u8  buffer[2] = {0};
    u8  packet_buf[FTS_PACKET_LENGTH + 6];
    u8  auc_i2c_write_buf[10];
    u8  bt_ecc;

    int  j,temp,lenght,i_ret,packet_number, i = 0;
    int  i_is_new_protocol = 0;


    /******write 0xaa to register 0xfc******/
    cmd=0xaa;
    fts_register_write(0xfc,&cmd);
    mdelay(50);

    /******write 0x55 to register 0xfc******/
    cmd=0x55;
    fts_register_write(0xfc,&cmd);
    printk("[TSP] Step 1: Reset CTPM test\n");

    mdelay(10);


    /*******Step 2:Enter upgrade mode ****/
    printk("\n[TSP] Step 2:enter new update mode\n");
    auc_i2c_write_buf[0] = 0x55;
    auc_i2c_write_buf[1] = 0xaa;
    do
    {
        i ++;
        i_ret = fts_i2c_txdata(auc_i2c_write_buf, 2);
        mdelay(5);
    } while(i_ret <= 0 && i < 10 );

    if (i > 1)
    {
        i_is_new_protocol = 1;
    }

    /********Step 3:check READ-ID********/
    cmd_write(0x90,0x00,0x00,0x00,4);
    byte_read(reg_val,2);
    if (reg_val[0] == 0x79 && reg_val[1] == 0x3)
    {
        printk("[TSP] Step 3: CTPM ID,ID1 = 0x%x,ID2 = 0x%x\n",reg_val[0],reg_val[1]);
    }
    else
    {
        return ERR_READID;
        //i_is_new_protocol = 1;
    }


    /*********Step 4:erase app**********/
    if (i_is_new_protocol)
    {
        cmd_write(0x61,0x00,0x00,0x00,1);
    }
    else
    {
        cmd_write(0x60,0x00,0x00,0x00,1);
    }
    mdelay(1500);
    printk("[TSP] Step 4: erase. \n");



    /*Step 5:write firmware(FW) to ctpm flash*/
    bt_ecc = 0;
    printk("[TSP] Step 5: start upgrade. \n");
    dw_lenth = dw_lenth - 8;
    packet_number = (dw_lenth) / FTS_PACKET_LENGTH;
    packet_buf[0] = 0xbf;
    packet_buf[1] = 0x00;
    for (j=0; j<packet_number; j++)
    {
        temp = j * FTS_PACKET_LENGTH;
        packet_buf[2] = (u8)(temp>>8);
        packet_buf[3] = (u8)temp;
        lenght = FTS_PACKET_LENGTH;
        packet_buf[4] = (u8)(lenght>>8);
        packet_buf[5] = (u8)lenght;

        for (i=0; i<FTS_PACKET_LENGTH; i++)
        {
            packet_buf[6+i] = pbt_buf[j*FTS_PACKET_LENGTH + i];
            bt_ecc ^= packet_buf[6+i];
        }

        byte_write(&packet_buf[0],FTS_PACKET_LENGTH + 6);
        mdelay(FTS_PACKET_LENGTH/6 + 1);
        if ((j * FTS_PACKET_LENGTH % 1024) == 0)
        {
            printk("[TSP] upgrade the 0x%x th byte.\n", ((unsigned int)j) * FTS_PACKET_LENGTH);
        }
    }

    if ((dw_lenth) % FTS_PACKET_LENGTH > 0)
    {
        temp = packet_number * FTS_PACKET_LENGTH;
        packet_buf[2] = (u8)(temp>>8);
        packet_buf[3] = (u8)temp;

        temp = (dw_lenth) % FTS_PACKET_LENGTH;
        packet_buf[4] = (u8)(temp>>8);
        packet_buf[5] = (u8)temp;

        for (i=0; i<temp; i++)
        {
            packet_buf[6+i] = pbt_buf[ packet_number*FTS_PACKET_LENGTH + i];
            bt_ecc ^= packet_buf[6+i];
        }

        byte_write(&packet_buf[0],temp+6);
        mdelay(20);
    }
示例#10
0
E_UPGRADE_ERR_TYPE  fts_ctpm_fw_upgrade(struct i2c_client *client,FTS_BYTE* pbt_buf, FTS_DWRD dw_lenth)
{
//    FTS_BYTE cmd_len     = 0;
    FTS_BYTE reg_val[2] = {0};
    FTS_DWRD i = 0;
//    FTS_BYTE ecc = 0;

    FTS_DWRD  packet_number;
    FTS_DWRD  j;
    FTS_DWRD  temp;
    FTS_DWRD  lenght;
    FTS_BYTE  packet_buf[FTS_PACKET_LENGTH + 6];
    FTS_BYTE  auc_i2c_write_buf[10];
    FTS_BYTE bt_ecc;

    /*********Step 1:Reset  CTPM *****/
    /*write 0xaa to register 0xfc*/
    Fts_i2c_write(client,0xfc,0xaa);
    delay_ms(50);
     /*write 0x55 to register 0xfc*/
    Fts_i2c_write(client,0xfc,0x55);
    pr_info("Step 1: Reset CTPM test\n");

    delay_ms(40);

    /*********Step 2:Enter upgrade mode *****/
     auc_i2c_write_buf[0] = 0x55;
     auc_i2c_write_buf[1] = 0xaa;
     i2c_master_send(client, auc_i2c_write_buf, 2);
     pr_info("Step 2: Enter update mode. \n");

    /*********Step 3:check READ-ID***********************/
    /*send the opration head*/
    do{
        if(i > 3)
        {
            return ERR_READID; 
        }
        /*read out the CTPM ID*/
        
        cmd_write(client,0x90,0x00,0x00,0x00,4);
        byte_read(client,reg_val,2);
        i++;
        pr_info("Step 3: CTPM ID,ID1 = 0x%x,ID2 = 0x%x\n",reg_val[0],reg_val[1]);
    }while(reg_val[0] != 0x79 || reg_val[1] != 0x03);

     /*********Step 4:erase app*******************************/
    cmd_write(client,0x61,0x00,0x00,0x00,1);
    delay_ms(1500);
    pr_info("Step 4: erase. \n");

    /*********Step 5:write firmware(FW) to ctpm flash*********/
    bt_ecc = 0;
    pr_info("Step 5: start upgrade. \n");
    dw_lenth = dw_lenth - 8;
    packet_number = (dw_lenth) / FTS_PACKET_LENGTH;
    packet_buf[0] = 0xbf;
    packet_buf[1] = 0x00;
    for (j=0;j<packet_number;j++)
    {
        temp = j * FTS_PACKET_LENGTH;
        packet_buf[2] = (FTS_BYTE)(temp>>8);
        packet_buf[3] = (FTS_BYTE)temp;
        lenght = FTS_PACKET_LENGTH;
        packet_buf[4] = (FTS_BYTE)(lenght>>8);
        packet_buf[5] = (FTS_BYTE)lenght;

        for (i=0;i<FTS_PACKET_LENGTH;i++)
        {
            packet_buf[6+i] = pbt_buf[j*FTS_PACKET_LENGTH + i]; 
            bt_ecc ^= packet_buf[6+i];
        }
        
        byte_write(client,&packet_buf[0],FTS_PACKET_LENGTH + 6);
        delay_ms(FTS_PACKET_LENGTH/6 + 1);
        if ((j * FTS_PACKET_LENGTH % 1024) == 0)
        {
              pr_info("upgrade the 0x%x th byte.\n", ((unsigned int)j) * FTS_PACKET_LENGTH);
        }
    }

    if ((dw_lenth) % FTS_PACKET_LENGTH > 0)
    {
        temp = packet_number * FTS_PACKET_LENGTH;
        packet_buf[2] = (FTS_BYTE)(temp>>8);
        packet_buf[3] = (FTS_BYTE)temp;

        temp = (dw_lenth) % FTS_PACKET_LENGTH;
        packet_buf[4] = (FTS_BYTE)(temp>>8);
        packet_buf[5] = (FTS_BYTE)temp;

        for (i=0;i<temp;i++)
        {
            packet_buf[6+i] = pbt_buf[ packet_number*FTS_PACKET_LENGTH + i]; 
            bt_ecc ^= packet_buf[6+i];
        }

        byte_write(client,&packet_buf[0],temp+6);    
        delay_ms(20);
    }
示例#11
0
文件: pmove.c 项目: elhobbs/quake2dsi
/*
=============
PM_CatagorizePosition
=============
*/
void PM_CatagorizePosition (void)
{
	vec3_t		point;
	int			cont;
	trace_t		trace;
	int			sample1;
	int			sample2;

// if the player hull point one unit down is solid, the player
// is on ground

// see if standing on something solid	
	point[0] = pml.origin[0];
	point[1] = pml.origin[1];
	point[2] = pml.origin[2] - 0.25;
	if (pml.velocity[2] > 180) //!!ZOID changed from 100 to 180 (ramp accel)
	{
//		pm->s.pm_flags &= ~PMF_ON_GROUND;
		byte_write(&pm->s.pm_flags, pm->s.pm_flags & ~PMF_ON_GROUND);
		pm->groundentity = NULL;
	}
	else
	{
		trace = pm->trace (pml.origin, pm->mins, pm->maxs, point);
		pml.groundplane = trace.plane;
		pml.groundsurface = trace.surface;
		pml.groundcontents = trace.contents;

		if (!trace.ent || (trace.plane.normal[2] < 0.7 && !trace.startsolid) )
		{
			pm->groundentity = NULL;
//			pm->s.pm_flags &= ~PMF_ON_GROUND;
			byte_write(&pm->s.pm_flags, pm->s.pm_flags & ~PMF_ON_GROUND);
		}
		else
		{
			pm->groundentity = trace.ent;

			// hitting solid ground will end a waterjump
			if (pm->s.pm_flags & PMF_TIME_WATERJUMP)
			{
//				pm->s.pm_flags &= ~(PMF_TIME_WATERJUMP | PMF_TIME_LAND | PMF_TIME_TELEPORT);
//				pm->s.pm_time = 0;
				byte_write(&pm->s.pm_flags, pm->s.pm_flags & ~(PMF_TIME_WATERJUMP | PMF_TIME_LAND | PMF_TIME_TELEPORT));
				byte_write(&pm->s.pm_time, 0);
			}

			if (! (pm->s.pm_flags & PMF_ON_GROUND) )
			{	// just hit the ground
//				pm->s.pm_flags |= PMF_ON_GROUND;
				byte_write(&pm->s.pm_flags, pm->s.pm_flags | PMF_ON_GROUND);
				// don't do landing time if we were just going down a slope
				if (pml.velocity[2] < -200)
				{
//					pm->s.pm_flags |= PMF_TIME_LAND;
					byte_write(&pm->s.pm_flags, pm->s.pm_flags | PMF_TIME_LAND);
					// don't allow another jump for a little while
					if (pml.velocity[2] < -400)
//						pm->s.pm_time = 25;
						byte_write(&pm->s.pm_time, 25);
					else
//						pm->s.pm_time = 18;
						byte_write(&pm->s.pm_time, 18);
				}
			}
		}

#if 0
		if (trace.fraction < 1.0 && trace.ent && pml.velocity[2] < 0)
			pml.velocity[2] = 0;
#endif

		if (pm->numtouch < MAXTOUCH && trace.ent)
		{
			pm->touchents[pm->numtouch] = trace.ent;
			pm->numtouch++;
		}
	}

//
// get waterlevel, accounting for ducking
//
	pm->waterlevel = 0;
	pm->watertype = 0;

	sample2 = (int)(pm->viewheight - pm->mins[2]);
	sample1 = sample2 / 2;

	point[2] = pml.origin[2] + pm->mins[2] + 1;	
	cont = pm->pointcontents (point);

	if (cont & MASK_WATER)
	{
		pm->watertype = cont;
		pm->waterlevel = 1;
		point[2] = pml.origin[2] + pm->mins[2] + sample1;
		cont = pm->pointcontents (point);
		if (cont & MASK_WATER)
		{
			pm->waterlevel = 2;
			point[2] = pml.origin[2] + pm->mins[2] + sample2;
			cont = pm->pointcontents (point);
			if (cont & MASK_WATER)
				pm->waterlevel = 3;
		}
	}

}
示例#12
0
文件: pmove.c 项目: elhobbs/quake2dsi
/*
================
Pmove

Can be called by either the server or the client
================
*/
void Pmove (pmove_t *pmove)
{
	pm = pmove;

	// clear results
	pm->numtouch = 0;
	VectorClear (pm->viewangles);
	pm->viewheight = 0;
	pm->groundentity = 0;
	pm->watertype = 0;
	pm->waterlevel = 0;

	// clear all pmove local vars
	memset (&pml, 0, sizeof(pml));

	// convert origin and velocity to float values
	pml.origin[0] = pm->s.origin[0]*0.125;
	pml.origin[1] = pm->s.origin[1]*0.125;
	pml.origin[2] = pm->s.origin[2]*0.125;

	pml.velocity[0] = pm->s.velocity[0]*0.125;
	pml.velocity[1] = pm->s.velocity[1]*0.125;
	pml.velocity[2] = pm->s.velocity[2]*0.125;

	// save old org in case we get stuck
	VectorCopy (pm->s.origin, pml.previous_origin);

	pml.frametime = pm->cmd.msec * 0.001;

	PM_ClampAngles ();

	if (pm->s.pm_type == PM_SPECTATOR)
	{
		PM_FlyMove (false);
		PM_SnapPosition ();
		return;
	}

	if (pm->s.pm_type >= PM_DEAD)
	{
		pm->cmd.forwardmove = 0;
		pm->cmd.sidemove = 0;
		pm->cmd.upmove = 0;
	}

	if (pm->s.pm_type == PM_FREEZE)
		return;		// no movement at all

	// set mins, maxs, and viewheight
	PM_CheckDuck ();

	if (pm->snapinitial)
		PM_InitialSnapPosition ();

	// set groundentity, watertype, and waterlevel
	PM_CatagorizePosition ();

	if (pm->s.pm_type == PM_DEAD)
		PM_DeadMove ();

	PM_CheckSpecialMovement ();

	// drop timing counter
	if (pm->s.pm_time)
	{
		int		msec;

		msec = pm->cmd.msec >> 3;
		if (!msec)
			msec = 1;
		if ( msec >= pm->s.pm_time) 
		{
//			pm->s.pm_flags &= ~(PMF_TIME_WATERJUMP | PMF_TIME_LAND | PMF_TIME_TELEPORT);
//			pm->s.pm_time = 0;
			
			byte_write(&pm->s.pm_time, 0);
			byte_write(&pm->s.pm_flags,
					pm->s.pm_flags & ~(PMF_TIME_WATERJUMP | PMF_TIME_LAND | PMF_TIME_TELEPORT));
		}
		else
			pm->s.pm_time -= msec;
	}
示例#13
0
文件: timer.c 项目: Aishou/lxdream
void timer_run() {
    byte_write( TSTR, byte_read(TSTR) | (1<<TMU_CHANNEL) );
}
示例#14
0
/*
[function]: 
    burn the FW to ctpm.
[parameters]:(ref. SPEC)
    pbt_buf[in]    :point to Head+FW ;
    dw_lenth[in]:the length of the FW + 6(the Head length);    
    bt_ecc[in]    :the ECC of the FW
[return]:
    ERR_OK        :no error;
    ERR_MODE    :fail to switch to UPDATE mode;
    ERR_READID    :read id fail;
    ERR_ERASE    :erase chip fail;
    ERR_STATUS    :status error;
    ERR_ECC        :ecc error.
*/
static E_UPGRADE_ERR_TYPE ft5x0x_fw_upgrade(struct ft5x0x_data *ft5x0x, u8* pbt_buf, int dw_lenth)
{
    int i = 0,j = 0,i_ret;
    int packet_number;
    int temp,lenght;
    u8 packet_buf[FTS_PACKET_LENGTH + 6];
    u8 auc_i2c_write_buf[10];
    u8 reg_val[2] = {0};
    u8 ctpm_id[2] = {0};
    u8 cmd[4];
    u8 bt_ecc;

    /*********Step 1:Reset  CTPM *****/
    /*write 0xaa to register 0xfc*/
    ft5x0x_write_reg(0xfc,0xaa);
    msleep(50);
    /*write 0x55 to register 0xfc*/
    ft5x0x_write_reg(0xfc,0x55);
    printk("[FTS] Step 1: Reset CTPM.\n");
    msleep(30);   

    /*********Step 2:Enter upgrade mode *****/
    auc_i2c_write_buf[0] = 0x55;
    auc_i2c_write_buf[1] = 0xaa;
    do{
        i ++;
        i_ret = byte_write(auc_i2c_write_buf, 2);
        mdelay(5);
    }while(i_ret <= 0 && i < 5 );
    msleep(20);
    
    /*********Step 3:check READ-ID**********/        
    if(ft5x0x->id == FT5606){
        ctpm_id[0] = FT56_CTPM_ID_L;
        ctpm_id[1] = FT56_CTPM_ID_H;
    }else{
        ctpm_id[0] = FT5X_CTPM_ID_L;
        ctpm_id[1] = FT5X_CTPM_ID_H;
    }

    cmd[0] = 0x90;
    cmd[1] = 0x00;
    cmd[2] = 0x00;
    cmd[3] = 0x00;
    cmd_write(cmd,4);
    byte_read(reg_val,2);
    if (reg_val[0] == ctpm_id[0] && reg_val[1] == ctpm_id[1]){
        printk("[FTS] Step 3: CTPM ID,ID1 = 0x%x,ID2 = 0x%x\n",reg_val[0],reg_val[1]);
    }else{
        printk("[FTS] ID_ERROR: CTPM ID,ID1 = 0x%x,ID2 = 0x%x\n",reg_val[0],reg_val[1]);
        return ERR_READID;
    }

    cmd[0] = 0xcd;
    cmd_write(cmd,1);
    byte_read(reg_val,1);
    printk("[FTS] bootloader version = 0x%x\n", reg_val[0]);

    /******Step 4:erase app and panel paramenter area *********/
    cmd[0] = 0x61;
    cmd_write(cmd,1); //erase app area
    msleep(1500); 
    cmd[0] = 0x63;
    cmd_write(cmd,1); //erase panel parameter area
    msleep(100);
    printk("[FTS] Step 4: erase. \n");

    /*********Step 5:write firmware(FW) to ctpm flash*********/
    bt_ecc = 0;
    printk("[FTS] Step 5: start upgrade. \n");
    dw_lenth = dw_lenth - 8;
    packet_number = (dw_lenth) / FTS_PACKET_LENGTH;
    packet_buf[0] = 0xbf;
    packet_buf[1] = 0x00;
    for (j=0;j<packet_number;j++){
        temp = j * FTS_PACKET_LENGTH;
        packet_buf[2] = (u8)(temp>>8);
        packet_buf[3] = (u8)temp;
        lenght = FTS_PACKET_LENGTH;
        packet_buf[4] = (u8)(lenght>>8);
        packet_buf[5] = (u8)lenght;

        for (i=0;i<FTS_PACKET_LENGTH;i++){
            packet_buf[6+i] = pbt_buf[j*FTS_PACKET_LENGTH + i]; 
            bt_ecc ^= packet_buf[6+i];
        }
        
        byte_write(&packet_buf[0],FTS_PACKET_LENGTH + 6);
        mdelay(FTS_PACKET_LENGTH/6 + 1);
        if ((j * FTS_PACKET_LENGTH % 1024) == 0){
              printk("[FTS] upgrade the 0x%x th byte.\n", ((unsigned int)j) * FTS_PACKET_LENGTH);
        }
    }

    if ((dw_lenth) % FTS_PACKET_LENGTH > 0){
        temp = packet_number * FTS_PACKET_LENGTH;
        packet_buf[2] = (u8)(temp>>8);
        packet_buf[3] = (u8)temp;

        temp = (dw_lenth) % FTS_PACKET_LENGTH;
        packet_buf[4] = (u8)(temp>>8);
        packet_buf[5] = (u8)temp;

        for (i=0;i<temp;i++){
            packet_buf[6+i] = pbt_buf[ packet_number*FTS_PACKET_LENGTH + i]; 
            bt_ecc ^= packet_buf[6+i];
        }

        byte_write(&packet_buf[0],temp+6);    
        mdelay(20);
    }
示例#15
0
void main()			   
{													  
	uchar shujv[8];		
	uchar stop=0;
	uchar cejv=1; 
	uchar flag=0;
	uchar helpcejv=0;	 
	init_io();
	led0=1;led1=1;ledk=1; 
	while(NRF_Check())	 
	{
		led0=0;
		delayms(1000);
		led0=1;
		delayms(1000);								  
	}	
	TX_Mode();		   //设置为发送模式
	/*************自己加的***********************/
	while(CNRF_Check())	 //检查nrf是否存在
	{
		led0=0;
		delayms(1000);
		led0=1;
		delayms(1000);								  
	}	
	CTX_Mode();
	/*************自己加的***********************/
	stop=byte_read(0x2000);		//读取上一次保留的值
	while(1)
	{
			wenshi(shujv); //写入前4个数据
		//	yali(shujv);//写入第5个数据
		//	shache(shujv);//写入第六个数据
	Get_weight();
	if (weight_shiwu/1000<=5)
	shujv[4]='0';
	else shujv[4]='1';


	if(stop==0)		 
		shujv[5]='1';
	if(stop==1)		 
		shujv[5]='0';
		if(out==0)	
		shujv[6]='1';
		else	
		shujv[6]='0';

		//////////////////////////////
			if(NRF24L01_TxPacket(shujv)==TX_OK)	
			{
				led1=0;
				delayms(300);
				led1=1;
				delayms(10);
				/////
				flag=1;
			}
			else flag=0;

	   //////////////////////////////
			if(flag==1)
			{
				if(CNRF24L01_TxPacket(shujv)==TX_OK)	
				{
					led3=0;
					delayms(300);
					led3=1;
					delayms(10);
					cejv=0;		
					helpcejv=0;
				}	
				else  
				{
					helpcejv++;
					delayms(100);
					if(helpcejv>2)
					{  			led2=0;
								delayms(300);
								led2=1;
								delayms(10);
						cejv=0;
						helpcejv=0;	
					}		 
				}
			/////////////////////////////////////////////////
							
			if(shache(cejv,stop)==1)	
			{
					led0=0;
					delayms(300);
					led0=1;
					delayms(10);
			stop=1;							  
			SectorErase(0x2000);
			byte_write(0x2000,stop);
			}
			if(checkbutton(cejv,stop)==0)
			{stop=1;
						
			SectorErase(0x2000);
			byte_write(0x2000,stop);
			}
			}			
	}
}