コード例 #1
0
ファイル: kbbasic.c プロジェクト: melvinlim/avr
void main(){
	unsigned long buf,sp;
	unsigned char data,x,y,ch;
#ifdef PARITYCHECK
	unsigned char parity;
	int tmp;
#endif
//	char str[7];
	prescaler_init();
	init_mc();
	spi_init();
	lcd_init();
	ch=x=y=0;
	lcd_goto(0);
	lcd_puts("initializing...");
	init_lut();
	lcd_clrscr();
	lcd_goto(0);
	while(1){
state1:
		if(SPSR&(1<<SPIF)){
			buf=SPDR;
			if(!(buf&1)){
				buf=buf>>1;	//throw out start bit.
				goto state2;
			}
		}
コード例 #2
0
ファイル: blink.c プロジェクト: melvinlim/avr
int main(){
	init_mc();
	SPCR=0;	//disable spi interrupts
	DDRD=(1<<PD5);

  while(1){
		PORTD^=(1<<PD5);
    _delay_ms(1000);
  }

  return(0);
}
コード例 #3
0
/*
 * create two ctx process & 2 resource handler each ctx
 * use diff ctx handler in diff process, get another process
 * ctx handler through PIPE.
 */
int mc_test_inter_prcs_ctx_int(int cmd)
{
    int rc;
    struct ctx myctx;
    struct ctx *p_ctx = &myctx;
    res_hndl_t res_hndl;
    ctx_hndl_t ctx_hndl;
    int pdes[2];
    pid_t cpid;
    pthread_t thread;
    __u64 stride = 0x1000;
    int i;
    //create pipe, child open for write
    // parent open for read

    pipe(pdes);
    cpid = fork();
    if ( 0 == cpid)
    {
        //child one running
        pid = getpid();
        debug("%d: child do init_mc \n", pid);
        rc = init_mc(p_ctx, &res_hndl);
        if (rc)
        {
            fprintf(stderr, "%d: exiting due to init_mc\n:", pid);
            exit(rc);
        }
        //do write into pipe & wait until parent kill me
        close(pdes[0]); //close read des
        write(pdes[1], &p_ctx->ctx_hndl, sizeof(ctx_hndl_t));
        while (1);
    }
    else
    {
        //parent
        close(pdes[1]); //close write des
        //lets child do there work & wait for me
        sleep(1);
        pid = getpid();
        rc = init_mc(p_ctx, &res_hndl);
        if (rc)
        {
            kill(cpid, SIGKILL);
            return rc;
        }
        pthread_create(&thread,NULL,ctx_rrq_rx, p_ctx);
        read(pdes[0], &ctx_hndl, sizeof(ctx_hndl_t));
        fill_send_write(p_ctx, 0, pid, stride);
        //set another process ctx
        debug("%d: use child(%d)process ctx hndl: %d\n", pid, cpid, ctx_hndl);
        for (i = 0; i< NUM_CMDS; i++)
        {
            p_ctx->cmd[i].rcb.ctx_id = ctx_hndl;
        }
        if (2 == cmd)
        {
            //another test is to close one of my ctx res hndl
            //and use child ctx handler here
            //(child has opened 2 res handler)
            p_ctx->res_hndl = res_hndl;
            close_res(p_ctx);
            debug("%d: close res_hndl(%d) but child (%d)has opened\n",
                  pid, res_hndl, cpid);
            for (i = 0; i< NUM_CMDS; i++)
            {
                p_ctx->cmd[i].rcb.res_hndl   = res_hndl;
            }
        }
        send_cmd(p_ctx);
        rc = wait_resp(p_ctx);
        kill(cpid, SIGKILL);
        pthread_cancel(thread);
    }
    return rc;
}