Example #1
0
/* save screenshot in bmp format, return true if success, or false */
bool CScreenShot::SaveBmp()
{
	TIMER_START();
	if(!OpenFile())
		return false;

	unsigned char hdr[14 + 40];
	unsigned int i = 0;
#define PUT32(x) hdr[i++] = ((x)&0xFF); hdr[i++] = (((x)>>8)&0xFF); hdr[i++] = (((x)>>16)&0xFF); hdr[i++] = (((x)>>24)&0xFF);
#define PUT16(x) hdr[i++] = ((x)&0xFF); hdr[i++] = (((x)>>8)&0xFF);
#define PUT8(x) hdr[i++] = ((x)&0xFF);
	PUT8('B'); PUT8('M');
	PUT32((((xres * yres) * 3 + 3) &~ 3) + 14 + 40);
	PUT16(0); PUT16(0); PUT32(14 + 40);
	PUT32(40); PUT32(xres); PUT32(yres);
	PUT16(1);
	PUT16(4*8); // bits
	PUT32(0); PUT32(0); PUT32(0); PUT32(0); PUT32(0); PUT32(0);
#undef PUT32
#undef PUT16
#undef PUT8
	fwrite(hdr, 1, i, fd);

	int y;
	for (y=yres-1; y>=0 ; y-=1) {
		fwrite(pixel_data+(y*xres*4),xres*4,1,fd);
	}
	fclose(fd);
	TIMER_STOP(filename.c_str());
	return true;

}
Example #2
0
void FB_draw_pixel (unsigned int x, unsigned int y,
                    unsigned char r, unsigned char g, unsigned char b) {
    volatile unsigned int addr = FB[8] + (x + y*FB[0]) * FB_BPP;
    PUT8(addr+0, r);
    PUT8(addr+1, g);
    PUT8(addr+2, b);
}
Example #3
0
int notmain ( void )
{
    unsigned int ra;

    //PUT8(PADIR_L,GET8(PADIR_L)|0x01);
    PUT8(PASEL0_L,GET8(PASEL0_L)& ~0x01);
    PUT8(PASEL1_L,GET8(PASEL1_L)& ~0x01);

    PUT32(SYST_CSR,4);
    PUT32(SYST_RVR,1200000-1);
    PUT32(SYST_CVR,1200000-1);
    PUT32(SYST_CSR,5);

    ra=GET8(PAOUT_L);
    while(1)
    {
        ra^=1;
        PUT8(PAOUT_L,ra);
        delay();
        ra^=1;
        PUT8(PAOUT_L,ra);
        delay();
    }
    return(0);
}
Example #4
0
void EP0_RX_routine()
{
   if((GET8(USB0_CORE + CSR0)&0b1) == 0)	// if !RxPktRdy,
   {
      return;
   }
   uint32_t size = GET8(USB0_CORE+COUNT0)&0x7F;
   if(size == 0)
   {
      return;
   }
   if((to_receive - ptr_received) > 64)
   {
      USB_ReadFrom(&(EP_get_buffer[0][ptr_received]),size,0);
      PUT8(USB0_CORE+CSR0,(1<<6));
      ptr_received += size;
   }
   else
   {
      USB_ReadFrom(&(EP_get_buffer[0][ptr_received]),size,0);
      PUT8(USB0_CORE+CSR0,(1<<6)|(1<<3));
      ptr_received = 0;
      to_receive = 0;
      USB_state_EP0 = IDLE;
   }
}
Example #5
0
static void lpc2292_serial_putc(const char c)
{
	if (c == '\n')
	{
		while((GET8(U0LSR) & (1<<5)) == 0); /* Wait for empty U0THR */
		PUT8(U0THR, '\r');
	}

	while((GET8(U0LSR) & (1<<5)) == 0); /* Wait for empty U0THR */
	PUT8(U0THR, c);
}
Example #6
0
void systick_handler ( void )
{
    GET32(STCTRL);
    if(twoled&1)
    {
        PUT8(FIO1CLR2,0x20);
    }
    else
    {
        PUT8(FIO1SET2,0x20);
    }
    twoled++;
}
Example #7
0
//------------------------------------------------------------------------
static void uart_init ( void )
{
    PUT8(PASEL1_L,GET8(PASEL1_L)&0xF3);
    PUT8(PASEL0_L,GET8(PASEL0_L)|0x0C);

    PUT16(UCA0CTLW0,0x0081);
    //PUT16(UCA0BRW,104); //12000000/115200 = 104
    PUT16(UCA0BRW,26); //3000000/115200 = 26
    PUT16(UCA0MCTLW,0x0000);
    PUT16(UCA0IE,0);
    PUT16(UCA0CTLW0,0x0081);
    PUT16(UCA0CTLW0,0x0080);
}
Example #8
0
void notmain ( void ) {
    uart_init();
    hexstring(0x12345678);
    hexstring(GETPC());
    timer_init();

    /*
     * 132 byte packet.  All fields are 1 byte except for the 128 byte data
     * payload.
     * 		+-----+------+----------+--....----+-----+
     * 		| SOH | blk# | 255-blk# | ..data.. | cksum |
     * 		+-----+------+----------+--....----+-----+
     * Protocol:
     * 	- first block# = 1.
     *  - CRC is over the whole packet
     *  - after all packets sent, sender transmits a single EOT (must ACK).
     */
    unsigned char block = 1;
    unsigned addr = ARMBASE;
    while (1) {
        unsigned char b;

        // We received an EOT, send an ACK, jump to beginning of code
        if((b = getbyte()) == EOT) {
            uart_send(ACK);
            BRANCHTO(ARMBASE);
            return; // NOTREACHED
        }

        /*
         * if first byte is not SOH, or second byte is not the
         * expected block number or the third byte is not its
         * negation, send a nak for a resend of this block.
         */
        if(b != SOH
                || getbyte() != block
                || getbyte() != (0xFF - block)) {
            uart_send(NAK);
            continue;
        }

        // get the data bytes
        int i;
        unsigned char cksum;
        for(cksum = i = 0; i < PAYLOAD_SIZE; i++) {
            cksum += (b = getbyte());
            PUT8(addr+i, b);
        }

        // Checksum failed: NAK the block
        if(getbyte() != cksum)
            uart_send(NAK);
        // Commit our addr pointer and go to next block.
        else {
            uart_send(ACK);
            addr += PAYLOAD_SIZE;
            block++;
        }
    }
}
Example #9
0
static isc_result_t
table_towire(isccc_sexpr_t *alist, isccc_region_t *target)
{
	isccc_sexpr_t *kv, *elt, *k, *v;
	char *ks;
	isc_result_t result;
	size_t len;

	for (elt = isccc_alist_first(alist);
	     elt != NULL;
	     elt = ISCCC_SEXPR_CDR(elt)) {
		kv = ISCCC_SEXPR_CAR(elt);
		k = ISCCC_SEXPR_CAR(kv);
		ks = isccc_sexpr_tostring(k);
		v = ISCCC_SEXPR_CDR(kv);
		len = strlen(ks);
		INSIST(len <= 255U);
		/*
		 * Emit the key name.
		 */
		if (REGION_SIZE(*target) < 1 + len)
			return (ISC_R_NOSPACE);
		PUT8(len, target->rstart);
		PUT_MEM(ks, len, target->rstart);
		/*
		 * Emit the value.
		 */
		result = value_towire(v, target);
		if (result != ISC_R_SUCCESS)
			return (result);
	}

	return (ISC_R_SUCCESS);
}
Example #10
0
void UART_putC(UART_t uart, char c)
{
   unsigned int uart_base = UART_ARRAY_BASE[uart];
   while((GET8(uart_base+0x14)&0x20)!=0x20);   //wait until txfifo is empty
    
   PUT8(uart_base +0,c);
}
Example #11
0
void EP0_TX_routine()
{
   if((to_send - ptr_send) > 64)
   {
      USB_WriteTo(&(EP_buf[0][ptr_send]),64,0);
      PUT8(USB0_CORE+CSR0,(1<<1)); // set txpckrdy
      ptr_send += 64;
   }
   else
   {
      USB_WriteTo(&(EP_buf[0][ptr_send]),to_send - ptr_send,0);
      PUT8(USB0_CORE+CSR0,(1<<1)|(1<<3)); // set txpckrdy & data end (len <= 64)
      ptr_send = 0;
      to_send = 0;
      ptr_write[0] = 0;
      USB_state_EP0 = IDLE;
   }
}
Example #12
0
int USB_WriteTo(uint8_t *src, uint32_t size, uint8_t endpoint)
{
   USB_DBG("WR 0x%X\n",size);
   for(int i = 0; i < size; i++)
   {
      PUT8(USB0_CORE+FIFOx+(endpoint<<2),src[i]);
   }
   return size;
}
Example #13
0
isc_result_t
isccc_cc_towire(isccc_sexpr_t *alist, isccc_region_t *target,
		isc_uint32_t algorithm, isccc_region_t *secret)
{
	unsigned char *hmac_rstart, *signed_rstart;
	isc_result_t result;

	if (algorithm == ISCCC_ALG_HMACMD5) {
		if (REGION_SIZE(*target) < 4 + sizeof(auth_hmd5))
			return (ISC_R_NOSPACE);
	} else {
		if (REGION_SIZE(*target) < 4 + sizeof(auth_hsha))
			return (ISC_R_NOSPACE);
	}

	/*
	 * Emit protocol version.
	 */
	PUT32(1, target->rstart);
	if (secret != NULL) {
		/*
		 * Emit _auth section with zeroed HMAC signature.
		 * We'll replace the zeros with the real signature once
		 * we know what it is.
		 */
		if (algorithm == ISCCC_ALG_HMACMD5) {
			hmac_rstart = target->rstart + HMD5_OFFSET;
			PUT_MEM(auth_hmd5, sizeof(auth_hmd5), target->rstart);
		} else {
			unsigned char *hmac_alg;

			hmac_rstart = target->rstart + HSHA_OFFSET;
			hmac_alg = hmac_rstart - 1;
			PUT_MEM(auth_hsha, sizeof(auth_hsha), target->rstart);
			PUT8(algorithm, hmac_alg);
		}
	} else
		hmac_rstart = NULL;
	signed_rstart = target->rstart;
	/*
	 * Delete any existing _auth section so that we don't try
	 * to encode it.
	 */
	isccc_alist_delete(alist, "_auth");
	/*
	 * Emit the message.
	 */
	result = table_towire(alist, target);
	if (result != ISC_R_SUCCESS)
		return (result);
	if (secret != NULL)
		return (sign(signed_rstart,
			     (unsigned int)(target->rstart - signed_rstart),
			     hmac_rstart, algorithm, secret));
	return (ISC_R_SUCCESS);
}
Example #14
0
void notmain ( void )
{
    unsigned int ra,rb,rc,rd,re,rf;
    unsigned int lastcount,nowcount;
    unsigned int nticks;
    unsigned int oneled;

    //init GPIO
    ra=GET8(FIO1DIR2);
    ra|=0xB4;
    PUT8(FIO1DIR2,ra);

    ra=FIO1SET2;
    rb=FIO1CLR2;
    rc=0x80;
    rd=0x20;
    re=0x10;
    rf=0x04;

    PUT8(rb,rc);
    PUT8(rb,rd);
    PUT8(rb,re);
    PUT8(rb,rf);

    oneled=0;
    twoled=0;

    //4MHz, 12000000 counts is 3 seconds
    PUT32(STCTRL,0x00000004);
    PUT32(STRELOAD,12000000-1);
    PUT32(STCTRL,0x00000007); //interrupt enabled

    //4Mhz/4 = 1Mhz  500000 is half a second
    nticks=500000;
    PUT32(T0CR,1);  //enable timer
    lastcount=GET32(T0TC);
    while(1)
    {
        nowcount=GET32(T0TC);
        nowcount-=lastcount; //upcounter
        if(nowcount>=nticks)
        {
            if(oneled&1)
            {
                PUT8(ra,rc);
            }
            else
            {
                PUT8(rb,rc);
            }
            oneled++;
            lastcount+=nticks;
        }
    }

    while(1) continue;
}
Example #15
0
inline static void insert_free_block(void* bp) {
#else
static void insert_free_block(void* bp) {
#endif
	/* get specific segregated free list */
	size_t free_list_num = get_list_num(GET_SIZE(HDRP(bp)));

	dbg1("[IN ] : insert_free_block() : insert at tail\n");

	if (GET_FREE_LISTP(free_list_num) != NULL) {
		/* if the list is not empty, insert at tail */
		PUT8(NEXT_FREEP(GET_FREE_LISTP_T(free_list_num)), bp);
		PUT8(PREV_FREEP(bp), GET_FREE_LISTP_T(free_list_num));
	}
	else {
		/* if list is empty, just setup pointers */
		PUT8(FREE_LISTP(free_list_num), bp);
		PUT8(PREV_FREEP(bp), NULL);
	}

	/* update tail pointer */
	PUT8(NEXT_FREEP(bp), NULL);
	PUT8(FREE_LISTP_T(free_list_num), bp);

	dbg1("[OUT] : insert_free_block()\n");

	return;
}
Example #16
0
void notmain ( void )
{
    unsigned int ra,rb,rc,rd,re,rf;

    unsigned int lastcount,nowcount;

    pll_init();


    //init GPIO
    ra=GET8(FIO1DIR2);
    ra|=0xB4;
    PUT8(FIO1DIR2,ra);

    ra=FIO1SET2;
    rb=FIO1CLR2;
    rc=0x80;
    rd=0x20;
    re=0x10;
    rf=0x04;

    PUT8(rb,rc);
    PUT8(rb,rd);
    PUT8(rb,re);
    PUT8(rb,rf);

    PUT32(T0PR,(120-1));
    PUT32(T0CR,1);  //enable timer
    lastcount=GET32(T0TC);
    while(1)
    {
        PUT8(ra,rc);
        while(1)
        {
            nowcount=GET32(T0TC);
            nowcount-=lastcount; //upcounter
            if(nowcount>=25000000) break;
        }
        lastcount+=25000000;
        PUT8(rb,rc);
        while(1)
        {
            nowcount=GET32(T0TC);
            nowcount-=lastcount; //upcounter
            if(nowcount>=25000000) break;
        }
        lastcount+=25000000;
    }
}
Example #17
0
/*
 * audio1575_count()
 *
 * Description:
 *	This is called by the framework to get the engine's frame counter
 *
 * Arguments:
 *	void	*arg		The DMA engine to query
 *
 * Returns:
 *	frame count for current engine
 */
static uint64_t
audio1575_count(void *arg)
{
	audio1575_port_t	*port = arg;
	audio1575_state_t	*statep = port->statep;
	uint64_t		val;
	uint8_t			civ;
	unsigned		n;
	int			civoff;
	int			lvioff;
	int			picoff;

	mutex_enter(&statep->lock);

	if (port->num == M1575_REC) {
		civoff = M1575_PCMICIV_REG;
		lvioff = M1575_PCMILVIV_REG;
		picoff = M1575_PCMIPICB_REG;
	} else {
		civoff = M1575_PCMOCIV_REG;
		lvioff = M1575_PCMOLVIV_REG;
		picoff = M1575_PCMOPICB_REG;
	}

	/*
	 * Read the position counters.  We also take this opportunity
	 * to update the last valid index to the one just previous to
	 * the one we're working on (so we'll fully loop.)
	 */
	n = GET16(picoff);
	civ = GET8(civoff);
	PUT8(lvioff, (civ - 1) % M1575_BD_NUMS);

	n = port->samp_size - (n * sizeof (int16_t));
	if (n < port->offset) {
		val = (port->samp_size - port->offset) + n;
	} else {
		val = n - port->offset;
	}
	port->offset = n;
	port->count += (val / (port->nchan * sizeof (int16_t)));
	val = port->count;
	mutex_exit(&statep->lock);

	return (val);
}
Example #18
0
void*
memset(void *dst, int c, uint n)
{
  // while there's still stuff to move
  while(n > 0) {
    // if our start is 32b aligned, AND what's left is 4 or more bytes long
    if ((int)dst%4 == 0 && (n >= 4)){
      c &= 0xFF;				// mask the lower 8 bits
      PUT32((uint)dst, (c<<24)|(c<<16)|(c<<8)|c);	// put 4 bytes of those @ pointer
      n-=4;					// tick off 4 done
      dst+=4;					// move the pointer by four
    } else					// otherwise
      PUT8((uint)dst, c);			// only put down 1 byte worth
      n-=1;					// mark it done
      dst+=1;					// move the pointer
  }
  return dst;					// return the pointer, pointing just beyond the end
}
Example #19
0
inline static void remove_free_block(void* bp) {
#else
static void remove_free_block(void* bp) {
#endif
	/* get specific segregated free list */
	size_t free_list_num = get_list_num(GET_SIZE(HDRP(bp)));

	dbg1("[IN ] : remove_free_block()\n");

	/* remove block */
	if ((void*)NEXT_FREE_BLKP(bp) == NULL) {
		/* if next pointer is null */
		if ((void*)PREV_FREE_BLKP(bp) == NULL) {

			/* if prev pointer is null, make list empty */
			PUT8(FREE_LISTP(free_list_num), NULL);
			PUT8(FREE_LISTP_T(free_list_num), NULL);

			dbg1("[OUT] : remove_free_block() : list is empty\n");
			return;
		}
		/* remove from tail */
		PUT8(NEXT_FREEP(PREV_FREE_BLKP(bp)), NULL);
		PUT8(FREE_LISTP_T(free_list_num), PREV_FREE_BLKP(bp));
	}
	else if ((void*)PREV_FREE_BLKP(bp) == NULL) {
		/* if prev pointer is null, remove from head */
		PUT8(FREE_LISTP(free_list_num), NEXT_FREE_BLKP(bp));
		PUT8(PREV_FREEP(GET_FREE_LISTP(free_list_num)), NULL);
	}
	else {
		/* just remove from middle of list */
		PUT8(PREV_FREEP(NEXT_FREE_BLKP(bp)), PREV_FREE_BLKP(bp));
		PUT8(NEXT_FREEP(PREV_FREE_BLKP(bp)), NEXT_FREE_BLKP(bp));
	}
	dbg1("[OUT] : remove_free_block()\n");
}
Example #20
0
static void lpc2292_serial_setbrg(void)
{
	unsigned short divisor = 0;

	switch (gd->baudrate) {
	case   1200:	divisor = 3072;	break;
	case   9600:	divisor =  384;	break;
	case  19200:	divisor =  192;	break;
	case  38400:	divisor =   96;	break;
	case  57600:	divisor =   64;	break;
	case 115200:	divisor =   32;	break;
	default:	hang ();	break;
	}

	/* init serial UART0 */
	PUT8(U0LCR, 0);
	PUT8(U0IER, 0);
	PUT8(U0LCR, 0x80);	/* DLAB=1 */
	PUT8(U0DLL, (unsigned char)(divisor & 0x00FF));
	PUT8(U0DLM, (unsigned char)(divisor >> 8));
	PUT8(U0LCR, 0x03);	/* 8N1, DLAB=0  */
	PUT8(U0FCR, 1);		/* Enable RX and TX FIFOs */
}
Example #21
0
static isc_result_t
value_towire(isccc_sexpr_t *elt, isccc_region_t *target)
{
	size_t len;
	unsigned char *lenp;
	isccc_region_t *vr;
	isc_result_t result;

	if (isccc_sexpr_binaryp(elt)) {
		vr = isccc_sexpr_tobinary(elt);
		len = REGION_SIZE(*vr);
		if (REGION_SIZE(*target) < 1 + 4 + len)
			return (ISC_R_NOSPACE);
		PUT8(ISCCC_CCMSGTYPE_BINARYDATA, target->rstart);
		PUT32(len, target->rstart);
		if (REGION_SIZE(*target) < len)
			return (ISC_R_NOSPACE);
		PUT_MEM(vr->rstart, len, target->rstart);
	} else if (isccc_alist_alistp(elt)) {
		if (REGION_SIZE(*target) < 1 + 4)
			return (ISC_R_NOSPACE);
		PUT8(ISCCC_CCMSGTYPE_TABLE, target->rstart);
		/*
		 * Emit a placeholder length.
		 */
		lenp = target->rstart;
		PUT32(0, target->rstart);
		/*
		 * Emit the table.
		 */
		result = table_towire(elt, target);
		if (result != ISC_R_SUCCESS)
			return (result);
		len = (size_t)(target->rstart - lenp);
		/*
		 * 'len' is 4 bytes too big, since it counts
		 * the placeholder length too.  Adjust and
		 * emit.
		 */
		INSIST(len >= 4U);
		len -= 4;
		PUT32(len, lenp);
	} else if (isccc_sexpr_listp(elt)) {
		if (REGION_SIZE(*target) < 1 + 4)
			return (ISC_R_NOSPACE);
		PUT8(ISCCC_CCMSGTYPE_LIST, target->rstart);
		/*
		 * Emit a placeholder length and count.
		 */
		lenp = target->rstart;
		PUT32(0, target->rstart);
		/*
		 * Emit the list.
		 */
		result = list_towire(elt, target);
		if (result != ISC_R_SUCCESS)
			return (result);
		len = (size_t)(target->rstart - lenp);
		/*
		 * 'len' is 4 bytes too big, since it counts
		 * the placeholder length.  Adjust and emit.
		 */
		INSIST(len >= 4U);
		len -= 4;
		PUT32(len, lenp);
	}

	return (ISC_R_SUCCESS);
}
Example #22
0
int notmain ( void )
{
    static volatile unsigned int FB[] __attribute__((aligned (16))) = {
        640, 480,
        640, 480,
        0,
        24,
        0, 0,
        0, 0
    };
    MailboxWrite(((unsigned int)FB)+0x40000000, 1);

    assert(MailboxRead(1) == 0); // TODO: check?

    {
        unsigned int ptr = FB[8];
        int i;
        for(i=0;i<640*480;i++) {
            PUT8(ptr++,0x00);
            PUT8(ptr++,0xFF);
            PUT8(ptr++,0x00);
        }
    }

/*
    {
        unsigned int ptr = FB[8];
        ptr += 640*10*3 + 50;
        int idx = 0;
        int i, j;
        for(i=0;i<10;i++) {
            for(j=0;j<10;j++) {
                PUT8(ptr++,image_smile[idx++]);
                PUT8(ptr++,image_smile[idx++]);
                PUT8(ptr++,image_smile[idx++]);
            }
            for(;j<640;j++) {
                PUT8(ptr++, 0x00);
                PUT8(ptr++, 0x00);
                PUT8(ptr++, 0x00);
            }
        }
    }

    {
        unsigned int ptr = FB[8];
        ptr += 640*30*3 + 50;
        int idx = 0;
        int i, j;
        for(i=0;i<105;i++) {
            for(j=0;j<288;j++) {
                PUT8(ptr++,image_ceu[idx+0]);
                PUT8(ptr++,image_ceu[idx+2]);   // TODO: why?
                PUT8(ptr++,image_ceu[idx+1]);   // TODO: why?
                idx += 3;
            }
            for(;j<640;j++) {
                PUT8(ptr++, 0x00);
                PUT8(ptr++, 0x00);
                PUT8(ptr++, 0x00);
            }
        }
    }
*/

    return(0);
}
Example #23
0
/* 
 * mm_init - initialize the malloc package.
 */
int mm_init(void)
{
	int i;
	
	dbg1("[IN ] : mm_init()\n");

	/* create the initial empty heap */
//	if ((heap_listp = mem_sbrk(18*DSIZE + 4 * WSIZE)) == NULL)
	if ((heap_listp = mem_sbrk((MAXCLASS+1)*2*DSIZE + 4 * WSIZE)) == NULL)
		return -1;

	
	/* free_list_ptrs points to starting point of free list pointers */
	free_list_ptrs = heap_listp;
	
	for (i=0; i<= MAXCLASS; i++) {
		PUT8(heap_listp+DSIZE*(i*2), NULL);
		PUT8(heap_listp+DSIZE*(i*2+1), NULL);
	}
	
	/* heap starting point is set right after the free list pointers */
	heap_listp = heap_listp+DSIZE*2*(MAXCLASS+1);
	
#if 0
	/* set up segregated free list pointers */
	PUT8(heap_listp, NULL);           /* free list 0 head */
	PUT8(heap_listp+DSIZE, NULL);     /* free list 0 tail */
	PUT8(heap_listp+DSIZE*2, NULL);   /* free list 1 head */
	PUT8(heap_listp+DSIZE*3, NULL);   /* free list 1 tail */
	PUT8(heap_listp+DSIZE*4, NULL);   /* free list 2 head */
	PUT8(heap_listp+DSIZE*5, NULL);   /* free list 2 tail */
	PUT8(heap_listp+DSIZE*6, NULL);   /* free list 3 head */
	PUT8(heap_listp+DSIZE*7, NULL);   /* free list 3 tail */
	PUT8(heap_listp+DSIZE*8, NULL);   /* free list 4 head */
	PUT8(heap_listp+DSIZE*9, NULL);   /* free list 4 tail */
	PUT8(heap_listp+DSIZE*10, NULL);  /* free list 5 head */
	PUT8(heap_listp+DSIZE*11, NULL);  /* free list 5 tail */
	PUT8(heap_listp+DSIZE*12, NULL);  /* free list 6 head */
	PUT8(heap_listp+DSIZE*13, NULL);  /* free list 6 tail */
	PUT8(heap_listp+DSIZE*14, NULL);  /* free list 7 head */
	PUT8(heap_listp+DSIZE*15, NULL);  /* free list 7 tail */
	PUT8(heap_listp+DSIZE*16, NULL);  /* free list 8 head */
	PUT8(heap_listp+DSIZE*17, NULL);  /* free list 8 tail */
	
	/* free_list_ptrs points to starting point of free list pointers */
	free_list_ptrs = heap_listp;

	/* heap starting point is set right after the free list pointers */
	heap_listp = heap_listp+DSIZE*18;
#endif
	
	PUT(heap_listp, 0);															/* alignment padding */
	PUT(heap_listp+WSIZE, PACK(OVERHEAD, 3));				/* prologue header */
	PUT(heap_listp+2*WSIZE, PACK(OVERHEAD, 3));			/* prologue footer */
	PUT(heap_listp+3*WSIZE, PACK(0, 3));						/* epilogue header */

	epilogue = (unsigned *)(heap_listp+3*WSIZE);		/* update epilogue pointer */

	heap_listp += 2*WSIZE;

	/* extends heap only on demand */

	mm_initialized = 1;
	
	dbg1("[OUT] : mm_init()\n");

	return 0;
}
Example #24
0
/*
 * audio1575_dma_stop()
 *
 * Description:
 *	This routine is used to put each DMA engine into the quiet state.
 *
 * Arguments:
 *	audio1575_state_t *statep	The device's state structure
 */
static void
audio1575_dma_stop(audio1575_state_t *statep, boolean_t quiesce)
{
	uint32_t	intrsr;
	int		i;

	if (statep->regsh == NULL) {
		return;
	}

	/* pause bus master (needed for the following reset register) */
	for (i = 0; i < M1575_LOOP_CTR; i++) {

		SET32(M1575_DMACR_REG, M1575_DMACR_PAUSE_ALL);
		if (GET32(M1575_DMACR_REG) & M1575_DMACR_PAUSE_ALL) {
			break;
		}
		drv_usecwait(10);
	}

	if (i >= M1575_LOOP_CTR) {
		if (!quiesce)
			audio_dev_warn(statep->adev, "failed to stop DMA");
		return;
	}

	/* Pause bus master (needed for the following reset register) */
	PUT8(M1575_PCMICR_REG, 0);
	PUT8(M1575_PCMOCR_REG, 0);
	PUT8(M1575_MICICR_REG, 0);
	PUT8(M1575_CSPOCR_REG, 0);
	PUT8(M1575_PCMI2CR_RR, 0);
	PUT8(M1575_MICI2CR_RR, 0);

	/* Reset the bus master registers for all DMA engines */
	PUT8(M1575_PCMICR_REG, M1575_PCMICR_RR);
	PUT8(M1575_PCMOCR_REG, M1575_PCMOCR_RR);
	PUT8(M1575_MICICR_REG, M1575_MICICR_RR);
	PUT8(M1575_CSPOCR_REG, M1575_CSPOCR_RR);
	PUT8(M1575_PCMI2CR_REG, M1575_PCMI2CR_RR);
	PUT8(M1575_MICI2CR_REG, M1575_MICI2CR_RR);

	/* Reset FIFOS */
	PUT32(M1575_FIFOCR1_REG, 0x81818181);
	PUT32(M1575_FIFOCR2_REG, 0x81818181);
	PUT32(M1575_FIFOCR3_REG, 0x81818181);

	/* Clear Interrupts */
	SET16(M1575_PCMISR_REG, M1575_SR_CLR);
	SET16(M1575_PCMOSR_REG, M1575_SR_CLR);
	SET16(M1575_MICISR_REG, M1575_SR_CLR);
	SET16(M1575_CSPOSR_REG, M1575_SR_CLR);
	SET16(M1575_PCMI2SR_REG, M1575_SR_CLR);
	SET16(M1575_MICI2SR_REG, M1575_SR_CLR);

	/*
	 * clear the interrupt control and status register
	 * READ/WRITE/READ workaround required to flush PCI caches
	 */

	PUT32(M1575_INTRCR_REG, 0);
	(void) GET32(M1575_INTRCR_REG);

	intrsr = GET32(M1575_INTRSR_REG);
	PUT32(M1575_INTRSR_REG, (intrsr & M1575_INTR_MASK));
	(void) GET32(M1575_INTRSR_REG);
}
Example #25
0
int notmain ( void )
{
	unsigned int ra;
	unsigned int rx;
	unsigned int block;
	unsigned int state;
	unsigned int addr;
	unsigned int crc;
	int i = 0;

	// Initialize mini UART
	uart_init();
	timer_init();

	display_msg();

	//SOH 0x01
	//ACK 0x06
	//NAK 0x15
	//EOT 0x04

	//block numbers start with 1

	//132 byte packet
	//starts with SOH
	//block number byte
	//255-block number
	//128 bytes of data
	//checksum byte (whole packet)
	//a single EOT instead of SOH when done, send an ACK on it too

	block = 1;
	state = 0;
	addr = ARMBASE;
	crc = 0;
	rx = timer_tick();

	while(1)
	{
		ra = timer_tick();

		if((ra -rx) >= 4000000) {
			uart_putc(0x15);
			rx += 4000000;
		}

		if (uart_get_flags() & (1 << 4))
			continue;

		xstring[state] = uart_getc();
		
		rx = timer_tick();

		if(state == 0) {
			if(xstring[state] == 0x04) {
				uart_putc(0x06);
				BRANCHTO(ARMBASE);
				break;
			}
		}

		switch(state) {
			case 0: {
					if(xstring[state] == 0x01) {
						crc = xstring[state];
						state++;
					} else {
						uart_putc(0x15);
					}
					break;
				}

			case 1: {
					if(xstring[state] == block) {
						crc += xstring[state];
						state++;
					} else {
						state = 0;
						uart_putc(0x15);
					}
					break;
				}

			case 2: {
					if(xstring[state] == (0xFF - xstring[state-1]))	{
						crc += xstring[state];
						state++;
					} else {
						uart_putc(0x15);
						state = 0;
					}
					break;
				}

			case 131: {
					  crc &= 0xFF;
					  if(xstring[state] == crc) {
						  for(ra = 0 ; ra < 128 ; ra++) {
							  PUT8(addr++, xstring[ra+3]);
						  }
						  uart_putc(0x06);
						  block = (block + 1) & 0xFF;
					  } else {
						  uart_putc(0x15);
					  }
					  state = 0;
					  break;
				  }

			default: {
					 crc += xstring[state];
					 state++;
					 break;
				 }
		}
	}
	return(0);
}
Example #26
0
/*
 * audio1575_start()
 *
 * Description:
 *	This is called by the framework to start a port transferring data.
 *
 * Arguments:
 *	void	*arg		The DMA engine to start
 *
 * Returns:
 *	0 	on success (never fails, errno if it did)
 */
static int
audio1575_start(void *arg)
{
	audio1575_port_t	*port = arg;
	audio1575_state_t	*statep = port->statep;

	mutex_enter(&statep->lock);

	port->offset = 0;

	if (port->num == M1575_REC) {
		/* Uli FIFO madness ... */
		SET32(M1575_FIFOCR1_REG, M1575_FIFOCR1_PCMIRST);
		SET32(M1575_DMACR_REG, M1575_DMACR_PCMIPAUSE);

		PUT8(M1575_PCMICR_REG, 0);
		PUT8(M1575_PCMICR_REG, M1575_CR_RR);

		PUT32(M1575_PCMIBDBAR_REG, port->bdl_paddr);
		PUT8(M1575_PCMILVIV_REG, M1575_BD_NUMS - 1);

		CLR32(M1575_DMACR_REG, M1575_DMACR_PCMIPAUSE);

		/* ULi says do fifo resets here */
		SET32(M1575_FIFOCR1_REG, M1575_FIFOCR1_PCMIRST);
		CLR32(M1575_DMACR_REG, M1575_DMACR_PCMIPAUSE);
		PUT8(M1575_PCMICR_REG, 0);
		SET32(M1575_DMACR_REG, M1575_DMACR_PCMISTART);

	} else {

		uint32_t	scr;

		/* Uli FIFO madness ... */
		SET32(M1575_FIFOCR1_REG, M1575_FIFOCR1_PCMORST);
		SET32(M1575_DMACR_REG, M1575_DMACR_PCMOPAUSE);

		/* configure the number of channels properly */
		scr = GET32(M1575_SCR_REG);
		scr &= ~(M1575_SCR_6CHL_MASK | M1575_SCR_CHAMOD_MASK);
		scr |= M1575_SCR_6CHL_2;	/* select our proper ordering */
		switch (port->nchan) {
		case 2:
			scr |= M1575_SCR_CHAMOD_2;
			break;
		case 4:
			scr |= M1575_SCR_CHAMOD_4;
			break;
		case 6:
			scr |= M1575_SCR_CHAMOD_6;
			break;
		}
		PUT32(M1575_SCR_REG, scr);

		PUT8(M1575_PCMOCR_REG, 0);
		PUT8(M1575_PCMOCR_REG, M1575_CR_RR);

		PUT32(M1575_PCMOBDBAR_REG, port->bdl_paddr);
		PUT8(M1575_PCMOLVIV_REG, M1575_BD_NUMS - 1);

		CLR32(M1575_DMACR_REG, M1575_DMACR_PCMOPAUSE);
		PUT8(M1575_PCMOCR_REG, 0);
		SET32(M1575_DMACR_REG, M1575_DMACR_PCMOSTART);
	}

	mutex_exit(&statep->lock);
	return (0);
}
Example #27
0
//------------------------------------------------------------------------
int notmain ( void )
{
    unsigned int ra;
    //unsigned int rb;
    unsigned int rx;
    unsigned int addr;
    unsigned int block;

    unsigned int crc;

    PUT32(AUX_ENABLES,1);
    PUT32(AUX_MU_IER_REG,0);
    PUT32(AUX_MU_CNTL_REG,0);
    PUT32(AUX_MU_LCR_REG,3);
    PUT32(AUX_MU_MCR_REG,0);
    PUT32(AUX_MU_IER_REG,0);
    PUT32(AUX_MU_IIR_REG,0xC6);
    PUT32(AUX_MU_BAUD_REG,270);
    ra=GET32(GPFSEL1);
    ra&=~(7<<12); //gpio14
    ra|=2<<12;    //alt5
    ra&=~(7<<15); //gpio15
    ra|=2<<15;    //alt5
    PUT32(GPFSEL1,ra);
    PUT32(GPPUD,0);
    for(ra=0;ra<150;ra++) dummy(ra);
    PUT32(GPPUDCLK0,(1<<14)|(1<<15));
    for(ra=0;ra<150;ra++) dummy(ra);
    PUT32(GPPUDCLK0,0);
    PUT32(AUX_MU_CNTL_REG,3);

    PUT32(ARM_TIMER_CTL,0x00F90000);
    PUT32(ARM_TIMER_CTL,0x00F90200);

    hexstring(0x12345678);

//SOH 0x01
//ACK 0x06
//NAK 0x15
//EOT 0x04

//block numbers start with 1

//132 byte packet
//starts with SOH
//block number byte
//255-block number
//128 bytes of data
//checksum byte (whole packet)
//a single EOT instead of SOH when done, send an ACK on it too


//this is a very crude solution, worked for a small test program though
//if it slips one byte it is all over.  Need to make a more robust
//solution.

    rx=GET32(ARM_TIMER_CNT);
    while(1)
    {
        ra=GET32(ARM_TIMER_CNT);
        if((ra-rx)>=4000000)
        {
            uart_send(0x15);
            rx+=4000000;
        }
        if(GET32(AUX_MU_LSR_REG)&0x01) break;
    }
    block=1;
    addr=ARMBASE;
    while(1)
    {
        xstring[0]=uart_recv();
        if(xstring[0]==0x04)
        {
            uart_send(0x06);
            break;
        }
        if(xstring[0]!=0x01) break;
        crc=0x01;
        for(ra=1;ra<132;ra++)
        {
            xstring[ra]=uart_recv();
            crc+=xstring[ra];
        }
        if(xstring[2]!=(255-xstring[1])) break;
        crc-=xstring[131];
        crc&=0xFF;
        if(xstring[131]!=crc)
        {
            uart_send(0x15);
        }
        for(ra=0;ra<128;ra++)
        {
            PUT8(addr++,xstring[ra+3]);
        }
        if(addr>0x200000)
        {
            uart_send(0x15);
            break;
        }
        uart_send(0x06);
        block=(block+1)&0xFF;
    }
    if(xstring[0]==0x04)
    {
        BRANCHTO(ARMBASE);
    }
    return(0);
}
Example #28
0
void UART_initUART(UART_t uart, unsigned int baudrate, STOP_BIT_t stopBit, PARITY_BIT_t parity, FLOW_t flowControl)
{
   if(UART_checkValidUart(uart))
   {
      unsigned int uart_base = UART_ARRAY_BASE[uart];
      switch(uart)
      {
         case UART0: // tx=1.11  rx=1.10  cts=1.8  rts=1.9
            
            GPIO_initPort(GPIO1);
            CM_setCtrlModule(CM_conf_uart0_txd,0); // do nothing on UART0_tx
            CM_setCtrlModule(CM_conf_uart0_rxd,(1<<4)|(1<<5)); // set pullup/pulldown & receiver enabled on UART0_rx
            PAD_setMode(CM_conf_uart0_txd,MODE_0); // set p1.11 as UART0_tx
            PAD_setMode(CM_conf_uart0_rxd,MODE_0); // set p1.10 as UART0_rx
            
            unsigned int temp = CKM_getCLKModuleRegister(CKM_WKUP,CKM_WKUP_CLKSTCTRL);
            temp &= ~(0b11);
            temp |= 0b10;      // software-forced wake-up transition on the "always on clock domain", TRM Table 8-92
            CKM_setCLKModuleRegister(CKM_WKUP,CKM_WKUP_CLKSTCTRL,temp);
            
            temp = CKM_getCLKModuleRegister(CKM_PER,CKM_PER_L4HS_CLKSTCTRL);
            temp &= ~(0b11);
            temp |= 0b10;      // software-forced wake up transition on the L4 high speed domain
                   CKM_setCLKModuleRegister(CKM_PER,CKM_PER_L4HS_CLKSTCTRL,temp);

            temp = CKM_getCLKModuleRegister(CKM_WKUP,CKM_WKUP_UART0_CLKCTRL);
            temp &= ~(0b11);
            temp |= 0b10;      // Module is explicitly enabled,    TRM Table 8-137
                   CKM_setCLKModuleRegister(CKM_WKUP,CKM_WKUP_UART0_CLKCTRL,temp);
            while((CKM_getCLKModuleRegister(CKM_WKUP, CKM_WKUP_UART0_CLKCTRL) & (0b11<<16)) != 0); // wait until clock transition is complete
            
            // TODO: verifiy it next block is needed for uart0
            // warning, why would the UART1 registers need modification when configuring UART0?
            temp = CKM_getCLKModuleRegister(CKM_PER,CKM_PER_UART1_CLKCTRL);
            temp &= ~(0b11);
            temp |= 0b10;      // Module is explicitly enabled,    TRM Table 8-137
                   CKM_setCLKModuleRegister(CKM_PER,CKM_PER_UART1_CLKCTRL,temp);
            
            temp = GET32(uart_base+0x54);    // SYSC
            temp |= 0x2;      // uart module reset
            PUT32(uart_base+0x54,temp);
            
            while((GET32(uart_base+0x58)&1)==0);   // wait for reset to be complete
            
            temp = GET8(uart_base+0x54);
            temp |= (0x1<<3); // no idle
            PUT8(uart_base+0x54,temp);
            
            while(((GET32(uart_base+0x14)&0x40)!=0x40));    // wait for txfifo to be empty
            
            
            float div = 48000000.0/(16.0*(float)baudrate);
            unsigned int intdiv = (unsigned int) div;
            PUT8(uart_base+0x04,0);
            PUT8(uart_base+0x20,0x7);        // Disable modeselect (default) TRM table 19-50
            PUT8(uart_base+0x0C,~(0x7C));    // divisor latch enable, access DLL DHL, set uart as 8bit
            PUT8(uart_base+0x00,0);          // DLL = 0
            PUT8(uart_base+0x04,0);          // DHL = 0
            PUT8(uart_base+0x0C,0x3);        // set uart as 8bit
            PUT8(uart_base+0x10,0x3);        // force /rts & /drt to active (low) (?!)
            PUT8(uart_base+0x08,0x7);        // clear rx&tx FIFOs, and enables them (each 64 bytes deep)
            PUT8(uart_base+0x0C,~(0x7C));    // divisor latch enable, access DLL DHL, set uart as 8bit
            PUT8(uart_base+0x00,intdiv&0xFF);          // DLL = 0
            PUT8(uart_base+0x04,(intdiv>>8)&0x3F);          // DHL = 0

//            PUT8(uart_base+0x00,26);         // DLL/DHL value for 115200
            PUT8(uart_base+0x0C,0x3);        // set uart as 8 bit
            PUT8(uart_base+0x20,0);          // uart 16x oversampling
            
            break;
         // TODO: implement UART1-5
         case UART1:
            break;
         case UART2:
            break;
         case UART3:
            break;
         case UART4:
            break;
         case UART5:
            break;
      }
   }
}
Example #29
0
int
main(int argc, char **argv)
{
  int i, nw, status, trig, layer, strip;
  int l, tag, num, nchan[22], *nchanptr, nn, mm, npulses;
  int pulse_integral, pulse_time, pulse_min, pulse_max;
  int ind, fragtag, fragnum, nbytes, ind_data, timestamp_flag, type, *nhits;
  int slot, slot_old, event, chan, tdc;
  int banktag = 0xe102, banknum = 0, banktyp = 0xf;
  char *fmt = "c,i,l,N(c,N(s,i,s,s))";
  unsigned int ret, word;
  unsigned long long timestamp, timestamp_old;
  unsigned char *end, *start;
  FILE *fd;
  GET_PUT_INIT;

  if(argc!=3) printf("Usage: evioUtilTest <input evio file> <output evio file>\n");
  input_filename = strdup(argv[1]);
  output_filename = strdup(argv[2]);
  printf("Use >%s< as input file\n",input_filename);
  printf("Use >%s< as output file\n",output_filename);
  if(!strcmp(input_filename,output_filename))
  {
    printf("input and output files must be different - exit\n");
    exit(0);
  }

  fd = fopen(output_filename,"r");
  if(fd>0)
  {
    printf("Output file %s exist - exit\n",output_filename);
    fclose(fd);
    exit(0);
  }

  /* open evio input file */
  if((status = evOpen(input_filename,"r",&input_handle))!=0)
  {
    printf("\n ?Unable to open input file %s, status=%d\n\n",input_filename,status);
    exit(1);
  }

  /* open evio output file */
  if((status = evOpen(output_filename,"w",&output_handle))!=0)
  {
    printf("\n ?Unable to open output file %s, status=%d\n\n",output_filename,status);
    exit(1);
  }


  nevent=0;
  nwrite=0;
  trig = 0;
  pulse_min = 0;
  pulse_max = 0;
  npulses = 1;
  timestamp = 0x0102030405LL;
  while( (status=evRead(input_handle,buf,MAXEVIOBUF))==0 && nevent < max_event)
  {
    nevent++;
    if(!(nevent%10000)) printf("processed %d events\n",nevent);
    if(skip_event>=nevent) continue;
    /*if(user_event_select(buf)==0) continue;*/









    /**********************/
	/* evioBankUtil stuff */


#if 0

    /********/
    /* ECAL */
    /********/

	fragtag = 1602;
    fragnum = 0;
    tag = 1602;

    printf("\n");
    for(num=1; num<=6; num++) /* 1-sector, 2-io, 3-view, 4-strip, 5-adc, 6-tdc */
	{
      ind = evLinkBank(buf, fragtag, fragnum, tag, num, &nbytes, &ind_data);
      if(ind > 0)
	  {
		/*
		PRINT_BUFFER(&buf[ind_data], &buf[ind_data]+(nbytes/4));
		*/

        if(num==1)      printf("SECTOR: ");
        else if(num==2) printf("    IO: ");
        else if(num==3) printf("  VIEW: ");
        else if(num==4) printf(" STRIP: ");
        else if(num==5) printf("   ADC: ");
        else if(num==6) printf("   TDC: ");

        for(i=0; i<nbytes/4; i++)
		{
          inBuf[num][i] = buf[ind_data+i];
          printf("%6d",inBuf[num][i]);
		}
        printf("\n");
	  }
	}
    printf("\n");



    /* clean up */
    nw = 0;
	printf("Process %d hit candidates\n",nbytes/4);
    for(i=0; i<nbytes/4; i++)
	{
      if(inBuf[1][i] != 5) continue; /* skip wrong sectors */
      if(inBuf[5][i] <= 0) continue; /* skip zero energy */

      aBuf[nw].sector = inBuf[1][i];
      aBuf[nw].io     = inBuf[2][i];
      aBuf[nw].view   = inBuf[3][i];
      aBuf[nw].strip  = inBuf[4][i];
      aBuf[nw].adc    = inBuf[5][i];
      aBuf[nw].tdc    = inBuf[6][i];
	  nw++;
	}

	printf("Found %d good hits\n",nw);
    for(num=1; num<=6; num++)
	{
      if(num==1)      printf("SECTOR: ");
      else if(num==2) printf("    IO: ");
      else if(num==3) printf("  VIEW: ");
      else if(num==4) printf(" STRIP: ");
      else if(num==5) printf("   ADC: ");
      else if(num==6) printf("   TDC: ");
      for(i=0; i<nw; i++)
	  {
        if(num==1)      printf("%6d",aBuf[i].sector);
        else if(num==2) printf("%6d",aBuf[i].io);
        else if(num==3) printf("%6d",aBuf[i].view);
        else if(num==4) printf("%6d",aBuf[i].strip);
        else if(num==5) printf("%6d",aBuf[i].adc);
        else if(num==6) printf("%6d",aBuf[i].tdc);
	  }
	  printf("\n");
	}
	printf("\n");

    /* sort */
    qsort((void *)aBuf, nw, sizeof(ECData), (int (*) (const void *, const void *))ecdata_compare);

	printf("Sorted %d hits\n",nw);
    for(num=1; num<=6; num++)
	{
      if(num==1)      printf("SECTOR: ");
      else if(num==2) printf("    IO: ");
      else if(num==3) printf("  VIEW: ");
      else if(num==4) printf(" STRIP: ");
      else if(num==5) printf("   ADC: ");
      else if(num==6) printf("   TDC: ");
      for(i=0; i<nw; i++)
	  {
        if(num==1)      printf("%6d",aBuf[i].sector);
        else if(num==2) printf("%6d",aBuf[i].io);
        else if(num==3) printf("%6d",aBuf[i].view);
        else if(num==4) printf("%6d",aBuf[i].strip);
        else if(num==5) printf("%6d",aBuf[i].adc);
        else if(num==6) printf("%6d",aBuf[i].tdc);
	  }
	  printf("\n");
	}

    if(ind > 0)
	{
      trig ++;
      slot_old = 0;
	  
      i = evOpenFrag(buf, 7, 1);
      printf("evOpenFrag returned %d\n",i);
	  
      ret = evOpenBank(buf, 7/*fragtag*/, 1/*fragnum*/, banktag, banknum, banktyp, fmt, &ind_data);
      printf("evOpenBank returns = %d\n",ret);

      b08out = (unsigned char *)&buf[ind_data];
      printf("first b08out = 0x%08x\n",b08out);

	  for(i=0; i<22; i++) nchan[i] = 0;

      for(i=0; i<nw; i++)
      {
        printf("begin while: b08=0x%08x\n",b08);

		layer = (aBuf[i].io-1)*3+aBuf[i].view-1;
		printf("+++++++++++++ %d %d -> %d\n",aBuf[i].io,aBuf[i].view,layer);
        strip = aBuf[i].strip-1;
        slot = adcslotecal [layer] [strip];
		chan = adcchanecal [layer] [strip];
        printf("### layer=%d strip=%d -> slot=%d chan=%d (nchan(so far)=%d)\n",layer,strip,slot,chan,nchan[slot]);

        if(slot != slot_old)
		{
          slot_old = slot;

          PUT8(slot);
          PUT32(trig);
          PUT64(timestamp);

          nchan[slot]=0;
          nchanptr = (unsigned int *)b08out;
          PUT32(nchan[slot]); /* reserve space for channel counter */

          printf("slot=%d, trig=%d, timestamp=%lld nchan[%d]=%d\n",slot,trig,timestamp,slot,nchan[slot]);
		}

        /*for(nn=0; nn<nchan[slot]; nn++)*/
	    {
	      nchan[slot] ++;
          *nchanptr = nchan[slot];

          PUT8(chan);
          PUT32(npulses);
          printf("  chan=%d, npulses=%d\n",chan,npulses);

          for(mm=0; mm<npulses; mm++)
	      {
            pulse_integral = aBuf[i].adc;
            pulse_time = aBuf[i].tdc-25000; /* sergey: arbitrary !!! */
            PUT16(pulse_time);
            PUT32(pulse_integral);
            PUT16(pulse_min);
            PUT16(pulse_max);
            printf("  pulse_time=%d pulse_integral=%d\n",pulse_time,pulse_integral);
        /*printf(">>> layer %d, strip %d -> adc %d\n",adclayerecal[slot][chan],adcstripecal[slot][chan],pulse_integral);*/
	      }

          printf("last b08out=0x%08x\n",b08out);
        }
      }
	  /*printf("last b08out = 0x%08x\n",b08out);*/
      evCloseBank(buf, 7/*fragtag*/, 1/*fragnum*/, banktag, banknum, b08out);
	}

#endif




#if 1

    /********/
    /* PCAL */
    /********/

	fragtag = 1502;
    fragnum = 0;
    tag = 1502;

    printf("\n");
    for(num=1; num<=6; num++) /* 1-sector, 2-io, 3-view, 4-strip, 5-adc, 6-tdc */
	{
      ind = evLinkBank(buf, fragtag, fragnum, tag, num, &nbytes, &ind_data);
      if(ind > 0)
	  {
		/*
		PRINT_BUFFER(&buf[ind_data], &buf[ind_data]+(nbytes/4));
		*/

        if(num==1)      printf("SECTOR: ");
        else if(num==2) printf("    IO: ");
        else if(num==3) printf("  VIEW: ");
        else if(num==4) printf(" STRIP: ");
        else if(num==5) printf("   ADC: ");
        else if(num==6) printf("   TDC: ");

        for(i=0; i<nbytes/4; i++)
		{
          inBuf[num][i] = buf[ind_data+i];
          printf("%6d",inBuf[num][i]);
		}
        printf("\n");
	  }
	}
    printf("\n");



    /* clean up */
    nw = 0;
	printf("Process %d hit candidates\n",nbytes/4);
    for(i=0; i<nbytes/4; i++)
	{
      if(inBuf[1][i] != 5) continue; /* skip wrong sectors */
      if(inBuf[5][i] <= 0) continue; /* skip zero energy */

      aBuf[nw].sector = inBuf[1][i];
      aBuf[nw].io     = inBuf[2][i];
      aBuf[nw].view   = inBuf[3][i];
      aBuf[nw].strip  = inBuf[4][i];
      aBuf[nw].adc    = inBuf[5][i];
      aBuf[nw].tdc    = inBuf[6][i];
	  nw++;
	}

	printf("Found %d good hits\n",nw);
    for(num=1; num<=6; num++)
	{
      if(num==1)      printf("SECTOR: ");
      else if(num==2) printf("    IO: ");
      else if(num==3) printf("  VIEW: ");
      else if(num==4) printf(" STRIP: ");
      else if(num==5) printf("   ADC: ");
      else if(num==6) printf("   TDC: ");
      for(i=0; i<nw; i++)
	  {
        if(num==1)      printf("%6d",aBuf[i].sector);
        else if(num==2) printf("%6d",aBuf[i].io);
        else if(num==3) printf("%6d",aBuf[i].view);
        else if(num==4) printf("%6d",aBuf[i].strip);
        else if(num==5) printf("%6d",aBuf[i].adc);
        else if(num==6) printf("%6d",aBuf[i].tdc);
	  }
	  printf("\n");
	}
	printf("\n");

    /* sort */
    qsort((void *)aBuf, nw, sizeof(ECData), (int (*) (const void *, const void *))ecdata_compare);

	printf("Sorted %d hits\n",nw);
    for(num=1; num<=6; num++)
	{
      if(num==1)      printf("SECTOR: ");
      else if(num==2) printf("    IO: ");
      else if(num==3) printf("  VIEW: ");
      else if(num==4) printf(" STRIP: ");
      else if(num==5) printf("   ADC: ");
      else if(num==6) printf("   TDC: ");
      for(i=0; i<nw; i++)
	  {
        if(num==1)      printf("%6d",aBuf[i].sector);
        else if(num==2) printf("%6d",aBuf[i].io);
        else if(num==3) printf("%6d",aBuf[i].view);
        else if(num==4) printf("%6d",aBuf[i].strip);
        else if(num==5) printf("%6d",aBuf[i].adc);
        else if(num==6) printf("%6d",aBuf[i].tdc);
	  }
	  printf("\n");
	}

    if(ind > 0)
	{
      trig ++;
      slot_old = 0;
	  
      i = evOpenFrag(buf, 8, 1);
      printf("evOpenFrag returned %d\n",i);
	  
      ret = evOpenBank(buf, 8/*fragtag*/, 1/*fragnum*/, banktag, banknum, banktyp, fmt, &ind_data);
      printf("evOpenBank returns = %d\n",ret);

      b08out = (unsigned char *)&buf[ind_data];
      printf("first b08out = 0x%08x\n",b08out);

	  for(i=0; i<22; i++) nchan[i] = 0;

      for(i=0; i<nw; i++)
      {
        printf("begin while: b08=0x%08x\n",b08);

		layer = (aBuf[i].io-1)*3+aBuf[i].view-1;
		printf("+++++++++++++ %d %d -> %d\n",aBuf[i].io,aBuf[i].view,layer);
        strip = aBuf[i].strip-1;
        slot = adcslotpcal [layer] [strip];
		chan = adcchanpcal [layer] [strip];
        printf("### layer=%d strip=%d -> slot=%d chan=%d (nchan(so far)=%d)\n",layer,strip,slot,chan,nchan[slot]);

        if(slot != slot_old)
		{
          slot_old = slot;

          PUT8(slot);
          PUT32(trig);
          PUT64(timestamp);

          nchan[slot]=0;
          nchanptr = (unsigned int *)b08out;
          PUT32(nchan[slot]); /* reserve space for channel counter */

          printf("slot=%d, trig=%d, timestamp=%lld nchan[%d]=%d\n",slot,trig,timestamp,slot,nchan[slot]);
		}

        /*for(nn=0; nn<nchan[slot]; nn++)*/
	    {
	      nchan[slot] ++;
          *nchanptr = nchan[slot];

          PUT8(chan);
          PUT32(npulses);
          printf("  chan=%d, npulses=%d\n",chan,npulses);

          for(mm=0; mm<npulses; mm++)
	      {
            pulse_integral = aBuf[i].adc;
            pulse_time = aBuf[i].tdc-25000; /* sergey: arbitrary !!! */
            PUT16(pulse_time);
            PUT32(pulse_integral);
            PUT16(pulse_min);
            PUT16(pulse_max);
            printf("  pulse_time=%d pulse_integral=%d\n",pulse_time,pulse_integral);
        /*printf(">>> layer %d, strip %d -> adc %d\n",adclayerecal[slot][chan],adcstripecal[slot][chan],pulse_integral);*/
	      }

          printf("last b08out=0x%08x\n",b08out);
        }
      }
	  /*printf("last b08out = 0x%08x\n",b08out);*/
      evCloseBank(buf, 8/*fragtag*/, 1/*fragnum*/, banktag, banknum, b08out);
	}
#endif



	/* evioBankUtil stuff */
    /**********************/





    nwrite++;
	printf("nwrite=%d\n",nwrite);
    status = evWrite(output_handle,buf);
    if(status!=0)
    {
      printf("\n ?evWrite error output file %s, status=%d (0x%08x)\n\n",output_filename,status,status);
      exit(1);
    }

    if( (max_event>0) && (nevent>=max_event+skip_event) ) break;

  }


  /* done */
  printf("\n  Read %d events, copied %d events\n\n",nevent,nwrite);
  evClose(output_handle);
  evClose(input_handle);

  exit(0);
}
Example #30
0
int lpc2292_write_buff (flash_info_t * info, uchar * src, ulong addr,
			ulong cnt)
{
	int first_copy_size;
	int last_copy_size;
	int first_block;
	int last_block;
	int nbr_mid_blocks;
	uchar memmap_value;
	ulong i;
	uchar* src_org;
	uchar* dst_org;
	int ret = ERR_OK;

	src_org = src;
	dst_org = (uchar*)addr;

	first_block = addr / 512;
	last_block = (addr + cnt) / 512;
	nbr_mid_blocks = last_block - first_block - 1;

	first_copy_size = 512 - (addr % 512);
	last_copy_size = (addr + cnt) % 512;

	debug("\ncopy first block: (1) %lX -> %lX 0x200 bytes, "
		"(2) %lX -> %lX 0x%X bytes, (3) %lX -> %lX 0x200 bytes\n",
	(ulong)(first_block * 512),
	(ulong)COPY_BUFFER_LOCATION,
	(ulong)src,
	(ulong)(COPY_BUFFER_LOCATION + 512 - first_copy_size),
	first_copy_size,
	(ulong)COPY_BUFFER_LOCATION,
	(ulong)(first_block * 512));

	/* copy first block */
	memcpy((void*)COPY_BUFFER_LOCATION,
		(void*)(first_block * 512), 512);
	memcpy((void*)(COPY_BUFFER_LOCATION + 512 - first_copy_size),
		src, first_copy_size);
	lpc2292_copy_buffer_to_flash(info, first_block * 512);
	src += first_copy_size;
	addr += first_copy_size;

	/* copy middle blocks */
	for (i = 0; i < nbr_mid_blocks; i++) {
		debug("copy middle block: %lX -> %lX 512 bytes, "
		"%lX -> %lX 512 bytes\n",
		(ulong)src,
		(ulong)COPY_BUFFER_LOCATION,
		(ulong)COPY_BUFFER_LOCATION,
		(ulong)addr);

		memcpy((void*)COPY_BUFFER_LOCATION, src, 512);
		lpc2292_copy_buffer_to_flash(info, addr);
		src += 512;
		addr += 512;
	}


	if (last_copy_size > 0) {
		debug("copy last block: (1) %lX -> %lX 0x200 bytes, "
		"(2) %lX -> %lX 0x%X bytes, (3) %lX -> %lX x200 bytes\n",
		(ulong)(last_block * 512),
		(ulong)COPY_BUFFER_LOCATION,
		(ulong)src,
		(ulong)(COPY_BUFFER_LOCATION),
		last_copy_size,
		(ulong)COPY_BUFFER_LOCATION,
		(ulong)addr);

		/* copy last block */
		memcpy((void*)COPY_BUFFER_LOCATION,
			(void*)(last_block * 512), 512);
		memcpy((void*)COPY_BUFFER_LOCATION,
			src, last_copy_size);
		lpc2292_copy_buffer_to_flash(info, addr);
	}

	/* verify write */
	memmap_value = GET8(MEMMAP);

	disable_interrupts();

	PUT8(MEMMAP, 01);		/* we must make sure that initial 64
							   bytes are taken from flash when we
							   do the compare */

	for (i = 0; i < cnt; i++) {
		if (*dst_org != *src_org){
			printf("Write failed. Byte %lX differs\n", i);
			ret = ERR_PROG_ERROR;
			break;
		}
		dst_org++;
		src_org++;
	}

	PUT8(MEMMAP, memmap_value);
	enable_interrupts();

	return ret;
}