예제 #1
0
파일: ei_util.c 프로젝트: csurface/gen_q
int ei_x_encode_error_tuple_atom(ei_x_buff *buff, char *atom) {
    EI(ei_x_encode_version(buff));
    EI(ei_x_encode_tuple_header(buff, 2));
    EI(ei_x_encode_atom(buff, "error"));
    EI(ei_x_encode_atom(buff, atom));
    return 0;
}
예제 #2
0
파일: krnl.c 프로젝트: carycode/krnl
int
k_set_prio (char prio)
{
    int i;

    if (!k_running) {
        return (-1);
    }

    DI ();

    if ((prio <= 0) || (DMY_PRIO <= prio)) {
        // not legal value my friend
        EI ();
        return (-2);
    }
    i = pRun->prio;

    pRun->prio = prio;
    prio_enQ (pAQ, deQ (pRun));
    ki_task_shift ();

    EI ();

    return (i);
}
예제 #3
0
파일: imalloc.c 프로젝트: kidasan/tkernel
/*
 * Get memory 
 */
LOCAL void* imalloc( size_t size, IMACB *imacb )
{
	QUEUE	*q;
	VP	mem;
	UW	imask;

	/* If it is smaller than the minimum fragment size,
	   allocate the minimum size to it. */
	if ( size < MIN_FRAGMENT ) {
		size = MIN_FRAGMENT;
	}
	size = ROUND(size);

	DI(imask);  /* Exclusive control by interrupt disable */
	SpinLock(&MemLockObj);

	/* Search FreeQue */
	q = searchFreeArea(size, imacb);
	if ( q != &imacb->freeque ) {
		/* There is free area: Split from FreeQue once */
		removeFreeQue(q);

		q = q - 1;
	} else {
		/* Reserve new pages because there is no free space */
		QUEUE	*e;
		size_t	n;

		/* Reserve pages */
		SpinUnlock(&MemLockObj);
		EI(imask);
		n = PageCount(size + sizeof(QUEUE) * 2);
		q = GetSysMemBlk(n, imacb->mematr);
		if ( q == NULL ) {
			goto err_ret;  /* Insufficient memory */
		}
		DI(imask);
		SpinLock(&MemLockObj);

		/* Register on AreaQue */
		e = (QUEUE*)((VB*)q + n * pagesz) - 1;
		insertAreaQue(&imacb->areaque, e);
		insertAreaQue(&imacb->areaque, q);
		setAreaFlag(q, AREA_TOP);
		setAreaFlag(e, AREA_END);
	}

	/* Allocate memory */
	mem = mem_alloc(q, size, imacb);

	SpinUnlock(&MemLockObj);
	EI(imask);
	return mem;

err_ret:
	BMS_DEBUG_PRINT(("imalloc error\n"));
	return NULL;
}
예제 #4
0
파일: q2e.c 프로젝트: csurface/gen_q
int ei_x_encode_time(ei_x_buff* types, ei_x_buff* values, K r, QOpts* opts) {
    EI(ei_x_encode_atom(types, "time"));
    int v = r->i;
    if(opts->day_seconds_is_q_time) {
        v = msec_to_sec(v);
    }
    EI(ei_x_encode_ki_val(values, v));
    return 0;
}
예제 #5
0
파일: q2e.c 프로젝트: csurface/gen_q
int ei_x_encode_kstring(ei_x_buff* types, ei_x_buff* values, K r, QOpts* opts) {
    EI(ei_x_encode_atom(types, "string"));
    if(r->n == 0) {
        EI(ei_x_encode_empty_list(values));
    } else {
        EI(ei_x_encode_string_len(values, (const char*)kC(r), r->n));
    }
    return 0;
}
예제 #6
0
파일: q2e.c 프로젝트: csurface/gen_q
int ei_x_encode_dict_impl(ei_x_buff* types, ei_x_buff* values, const char* t, K r, QOpts* opts) {
    EI(ei_x_encode_tuple_header(types, r->n+1));
    EI(ei_x_encode_atom(types, t));
    EI(ei_x_encode_tuple_header(values, r->n));
    int i;
    for(i=0; i<r->n; ++i) {
        EI(ei_x_encode_k_tv(types, values, kK(r)[i], opts));
    }
    return 0;
}
예제 #7
0
파일: q2e.c 프로젝트: csurface/gen_q
int ei_x_encode_unknown(ei_x_buff* types, ei_x_buff* values, K r, QOpts* opts) {
    EI(ei_x_encode_tuple_header(types, r->n+1));
    EI(ei_x_encode_long(types, r->t));
    EI(ei_x_encode_tuple_header(values, r->n));
    int i;
    for(i=0; i<r->n; ++i) {
        EI(ei_x_encode_k_tv(types, values, kK(r)[i], opts));
    }
    return 0;
}
예제 #8
0
파일: q2e.c 프로젝트: csurface/gen_q
int ei_x_encode_datetime(ei_x_buff* types, ei_x_buff* values, K r, QOpts* opts) {
    if(opts->unix_timestamp_is_q_datetime) {
        long v = datetime_to_unix_timestamp(r->f);
        EI(ei_x_encode_atom(types, "datetime"));
        EI(ei_x_encode_long(values, v));
    } else {
        EI(ei_x_encode_kf(types, values, "datetime", r, opts));
    }
    return 0;
}
예제 #9
0
파일: q2e.c 프로젝트: csurface/gen_q
int ei_x_encode_same_list_byte(ei_x_buff* types, ei_x_buff* values, const char* t, K r, QOpts* opts) {
    EI(ei_x_encode_tuple_header(types, 2));
    EI(ei_x_encode_atom(types, "list"));
    EI(ei_x_encode_atom(types, t));
    if(r->n == 0) {
        EI(ei_x_encode_empty_list(values));
    } else {
        EI(ei_x_encode_string_len(values, (const char*)kG(r), r->n));
    }
    return 0;
}
예제 #10
0
int _SifCmdIntHandler()
{
	u128 packet[8];
	u128 *pktbuf;
	struct cmd_data *cmd_data = &_sif_cmd_data;
	SifCmdHeader_t *header;
	SifCmdHandlerData_t *cmd_handlers;
	int size, pktquads, id, i = 0;

	EI();

	header = (SifCmdHeader_t *)cmd_data->pktbuf;

	if (!(size = (header->size & 0xff)))
		goto out;

	/* TODO: Don't copy anything extra */
	pktquads = (size + 30) >> 4;
	header->size = 0;
	if (pktquads) {
		pktbuf = (u128 *)cmd_data->pktbuf;
		while (pktquads--) {
			packet[i] = pktbuf[i];
			i++;
		}
	}

	iSifSetDChain();

	header = (SifCmdHeader_t *)packet;
	/* Get the command handler id and determine which handler list to
	   dispatch from.  */
	id = header->cid & ~SYSTEM_CMD;

	if (id < CMD_HANDLER_MAX) {
		if (header->cid & SYSTEM_CMD) {
			cmd_handlers = cmd_data->sys_cmd_handlers;
		}
		else {
			cmd_handlers = cmd_data->usr_cmd_handlers;
		}
	} else {
		goto out;
	}

	if (cmd_handlers[id].handler)
		cmd_handlers[id].handler(packet, cmd_handlers[id].harg);

out:
	EE_SYNC();
	EI();
	return 0;
}
예제 #11
0
파일: q2e.c 프로젝트: csurface/gen_q
int ei_x_encode_kf_val(ei_x_buff* values, double f) {
    EI_X_ENCODE_NULL_OR_INF(f, nf, wf);
    if(f == nf || q2e_isnan(f)) {
        EI(ei_x_encode_atom(values, "null"));
        return 0;
    } else if(f == wf) {
        EI(ei_x_encode_atom(values, "infinity"));
        return 0;
    }
    EI(ei_x_encode_double(values, f));
    return 0;
}
예제 #12
0
파일: q2e.c 프로젝트: csurface/gen_q
int ei_x_encode_k(ei_x_buff* x, K r, QOpts* opts) {
    EI(ei_x_encode_tuple_header(x, 2));
    ei_x_buff* types = x;
    ei_x_buff values;
    EI(ei_x_new(&values));
    EIC(ei_x_encode_k_tv(types, &values, r, opts),
            ei_x_free(&values)); // cleanup expression
    // TODO - JMS - is there a way to do this without deep copying data?
    EIC(ei_x_append(types, &values),
            ei_x_free(&values)); // cleanup expression
    EI(ei_x_free(&values));
    return 0;
}
예제 #13
0
파일: main.c 프로젝트: Muriukidavid/z8_64k
int main(){
	DI();//disable interrupts or hell breaks loose during hardware config
	construct_system();//bind device addresses
	init_system();//init devices
		//clear all interrupts
	clearall_interrupts();
	EI();//enable interrupts: we have UART_recieve
	
	//set the lcd contrast
	//lcd_contrast(0x42);
	lcd_contrast(0x32);
	//clear the lcd
	clearram();
	//show boot up message
	show_bootup();
	//clear boot message
	clearram();
	//screen layout
	screen_layout();
	send(1, 225);
	send(1, 255);
	send(1, 2);
	while(1)
	{
		get_temperature1();
		get_temperature2();
		get_light();
		get_pressure();
		get_humidity();
		get_soilwetness();
		display();
		delay_ms(800);		
	}
	return 0;
}
예제 #14
0
int uart_putchar(unsigned char c)
{
    int buffer_loc;

    if(c == '\n') {
        while(uart_putchar('\r')) {
            ;
        }
    }

    if(trans_buffer_size < BUFFER_SIZE) {
        DI();

        buffer_loc = (trans_buffer_current + trans_buffer_size) % BUFFER_SIZE;
        trans_buffer[buffer_loc] = c;
        trans_buffer_size++;

        //trigger the interrupt if already ready to transmit
        if((U0STAT0 & UART_TRAN_RDY) &&
                ((IRQ0SET & UART_IRQ_TRAN) == 0)) {
            IRQ0SET |= UART_IRQ_TRAN;
        }

        EI();
    }
    else {
        return 1;
    }

    return 0;
}
예제 #15
0
/*
 * Free memory
 *	It may be called during interrupt disable. In this case, need to wait
 *	 until interrupt is enabled and until free.
 */
EXPORT void  knl_Ifree( void *ptr )
{
	QUEUE	*aq;
	UINT	imask;

	DI(imask);  /* Exclusive control by interrupt disable */

	aq = (QUEUE*)ptr - 1;
	clrAreaFlag(aq, AREA_USE);

	if ( !chkAreaFlag(aq->next, AREA_USE) ) {
		/* Merge with free area in after location */
		knl_removeFreeQue(aq->next + 1);
		knl_removeAreaQue(aq->next);
	}

	if ( !chkAreaFlag(aq->prev, AREA_USE) ) {
		/* Merge with free area in front location */
		aq = aq->prev;
		knl_removeFreeQue(aq + 1);
		knl_removeAreaQue(aq->next);
	}

	knl_appendFreeArea(knl_imacb, aq);

	EI(imask);
}
void print_lcd(volatile uint8_t *message) {
    uint8_t len = strlen(message);
    lcd_clear();
    delay(1000);

    volatile uint8_t i = 0;
    //if (len > lcd_message_max) len = lcd_message_max;
    for (i = 0; i < len; i++)
    {
        if (message[i] <= 0x7F) {
            writeByteLcd(1, message[i]);
        }
        else {
            writeByteLcd(1, ' ');
        }
        delay(100);
        if (i == 7) {
//			int k;
//			for (k = 0; k < 32; k++)
//			{
//				writeByteLcd(0U, LCD_CURSOR_RIGHT);
//				delay(100);
//			}
            writeByteLcd(0U, 0xC0);
            delay(100);
        }
    }

    // scroll one right
    //writeByteLcd(0U, 0x1C);
    //	delay(100);
    EI();
}
예제 #17
0
파일: q2e.c 프로젝트: csurface/gen_q
int ei_x_encode_table(ei_x_buff* types, ei_x_buff* values, K r, QOpts* opts) {

    EI(ei_x_encode_tuple_header(types, 2));
    EI(ei_x_encode_atom(types, "table"));

    EI(ei_x_encode_tuple_header(values, 2));

    ei_x_buff column_types;
    ei_x_new_with_version(&column_types);
    EIC(ei_x_encode_k_tv(&column_types, values, kK(r->k)[0], opts),
            ei_x_free(&column_types));
    ei_x_free(&column_types);

    EI(ei_x_encode_k_tv(types, values, kK(r->k)[1], opts));
    return 0;
}
예제 #18
0
파일: led.c 프로젝트: hdweiss/arkanoid-z8
void led_init()
{
	PEADDR = 0x02;		//set alternative function (port E)
	PECTL = 0x00;
	PEADDR = 0x01;		//set datadirection to output (port E)
	PECTL = 0x00;

	PGADDR = 0x02;		//set alternative function (port G)
	PGCTL = 0x00;
	PGADDR = 0x01;		//set datadirection to output (port G)
	PGCTL = 0x00;

	T0CTL = 0x01;		//Disable Timer0 and set it to continous mode
	T0CTL |= 0x38;		//Set the prescale value
	
	T0H = 0x00;		
	T0L = 0x01;			//reset timer

	T0RH = 0x00;
//	T0RH = 0x02;
	T0RL = 0xD0;		//set reload value (0.5 ms)

	IRQ0ENH &= 0xDF;
	IRQ0ENL |= 0x20;	 //enable Timer0 interrupt, and set low priority

	T0CTL |= 0x80;		//enable Timer0
	EI();				//enable interrupts

	SET_VECTOR(TIMER0, drawtimer);		//set timer interrupt function

	led_clear();		//clear the LEDs
	led_onall();	
}
/***********************************************************************************************************************
* Function Name: R_Systeminit
* Description  : This function initializes every macro.
* Arguments    : None
* Return Value : None
***********************************************************************************************************************/
void R_Systeminit(void)
{
    DI();

    /* Enable writing to registers related to operating modes, LPC, CGC and ATCM */
    SYSTEM.PRCR.LONG = 0x0000A50BU;

    /* Enable writing to MPC pin function control registers */
    MPC.PWPR.BIT.B0WI = 0U;
    MPC.PWPR.BIT.PFSWE = 1U;

    r_set_exception_handler();

    /* Set peripheral settings */
    R_CGC_Create();
    R_ICU_Create();
    R_PORT_Create();
    R_TPU_Create();
    R_RSPI1_Create();
    R_MPC_Create();
	R_SCIFA2_Create();

    /* Disable writing to MPC pin function control registers */
    MPC.PWPR.BIT.PFSWE = 0U;
    MPC.PWPR.BIT.B0WI = 1U;

    /* Enable protection */
    SYSTEM.PRCR.LONG = 0x0000A500U;
    EI();
}
예제 #20
0
//内部RTC闹铃,中断等级--------INTER_GRADE_LOWERST (默认:INTRTC_vect)
void CPU_RTC_Interrupt(void)
{
#if ALL_LOSS_TYPE EQ ALL_LOSS_HARD_SINGLE 
  EI();
#endif
  
#if ALL_LOSS_TYPE EQ ALL_LOSS_HARD_MULTI 
  EI();
  Clear_CPU_Dog();
  //醒来了,根据唤醒源马上切换高速晶振-----------PUCK
  Switch_Main_Osc(RUN_MODE);
  Hard_All_Loss_Proc();  
  Switch_Main_Osc(HALT_MODE);
  Clear_CPU_Dog();  
#endif 
}
예제 #21
0
//UP Key,中断等级--------INTER_GRADE_LOWERST
void Inter_Up_Key(void)
{
  EI();
  Resume_Src.Src_Flag|=KEY_RESUME;
  Key_WkUP_Ms_Timr=Ms_Timer_Pub;
  Key_Value_Pub.Key.Bit.UpKey=1;
}
예제 #22
0
/*
	Interrupt for timer events.

	Used for updating the LED, polling the buttons, and responding
	to note change events for the speaker..
 */
void interrupt timer_isr(void)
{
	//enable interrupts for speaker interrupt
	EI();
	
	button_events();
}
예제 #23
0
파일: rpc_client.c 프로젝트: AKuHAK/ps2sdk
static void TxThread(void *arg)
{
	int ThreadToWakeUp;

	while(1)
	{
		SleepThread();

		if(PacketReqs.count > 0)
		{
			while(PacketReqs.count > 0)
			{
				WaitSema(NetManIOSemaID);
				while(SifCallRpc(&NETMAN_rpc_cd, NETMAN_IOP_RPC_FUNC_SEND_PACKETS, 0, &PacketReqs, sizeof(PacketReqs), &ReceiveBuffer, sizeof(ReceiveBuffer.result), &TxEndCallback, NULL) < 0){};
				SignalSema(NetManIOSemaID);
			}
		}
		else
		{
			if(NetmanTxWaitingThread >= 0)
			{
				DI();
				ThreadToWakeUp=NetmanTxWaitingThread;
				NetmanTxWaitingThread=-1;
				EI();
				WakeupThread(ThreadToWakeUp);
			}
		}
	}
}
예제 #24
0
SifRpcServerData_t *
SifRegisterRpc(SifRpcServerData_t *sd, 
		int sid, SifRpcFunc_t func, void *buff, SifRpcFunc_t cfunc,
		void *cbuff, SifRpcDataQueue_t *qd)
{
	SifRpcServerData_t *server;

	DI();

	sd->link  = NULL;
	sd->next  = NULL;
	sd->sid   = sid;
	sd->func  = func;
	sd->buff  = buff;
	sd->cfunc = cfunc;
	sd->cbuff = cbuff;
	sd->base  = qd;

	if (!(server = qd->link)) {
		qd->link = sd;
	} else {
		while ((server = server->next))
			;

		server->next = sd;
	}

	EI();

	return server;
}
예제 #25
0
/***********************************************************************************************************************
* Function Name: R_MAIN_UserInit
* Description  : This function adds user code before implementing main function.
* Arguments    : None
* Return Value : None
***********************************************************************************************************************/
void R_MAIN_UserInit(void)
{
    /* Start user code. Do not edit comment generated here */
    	EI();
	u_timer_Init();
	u_g_param_Init();

	TDR02	= 0x07FF;
	
	TDR00	= 0x03FF;		/* 24MHz / (1023+1)  nearly  24kHz , PWM master */
	TDR01	= 0x0200;		/* PWM slave */


	IICE0	= 0;

	SO0	|= 0x0001;
	SOE0	&= 0xFFF0;

	PM6.0	= 0;
	PM6.1	= 0;
	
	ADIF	= 0;

	set_kind_param(SPEED);

	ADS	= _02_AD_INPUT_CHANNEL_2;
	R_ADC_Set_OperationOn();
    /* End user code. Do not edit comment generated here */
}
예제 #26
0
SifRpcDataQueue_t *
SifSetRpcQueue(SifRpcDataQueue_t *qd, int thread_id)
{
	SifRpcDataQueue_t *queue = NULL;

	DI();

	qd->thread_id = thread_id;
	qd->active = 0;
	qd->link   = NULL;
	qd->start  = NULL;
	qd->end    = NULL;
	qd->next   = NULL;

	if (!_sif_rpc_data.active_queue) {
		_sif_rpc_data.active_queue = qd;
	} else {
		queue = _sif_rpc_data.active_queue;

		while ((queue = queue->next))
			;

		queue->next = qd;
	}

	EI();

	return queue;
}
예제 #27
0
파일: timer.c 프로젝트: hdweiss/arkanoid-z8
void timer1_setup(int difficulty)
{
	T1CTL = 0x01;	//Disable Timer1 and set it to continous mode
	T1CTL |= 0x38;	//Set the prescale value
	
	T1H = 0x00;		//...
	T1L = 0x01;		//reset timer

	

	if(difficulty > 0xFF)	//set timer reload value
	{
	    T1RH = difficulty - 0xFF;
	    T1RL = 0xFF;
	}
	else
	{
	    T1RH = 0x00;
	    T1RL = difficulty;
	} 

	

	IRQ0ENH |= 0x40; 	//enable Timer1 interrupt, and set nominal priority
	IRQ0ENL &= 0xBF;

	SET_VECTOR(TIMER1, timer1int);

	T1CTL |= 0x80;		//enable Timer1
	EI();				//enable interrupts
}
예제 #28
0
/**
 * @param timer The timer to stop
 */
void hal_timer_stop(char timer)
{
	DI();
	switch (timer) {
	case HAL_TIMER_0:
		T0CTL &= ~0x80; //Disable timer
		break;

	case HAL_TIMER_1:	
		T1CTL &= ~0x80;
		break;
	
	case HAL_TIMER_2:
		T2CTL &= ~0x80;
		break;

	case HAL_TIMER_3:
		T3CTL &= ~0x80;
		break;

	default:
		break;
	}
	EI();
}
예제 #29
0
파일: ps2cam_rpc.c 프로젝트: AKuHAK2/ps2sdk
int PS2CamReadPacket(int handle)
{
	int *ret;
	int *iop_addr;

	WaitSema(sem);

	ret = (int *)&data[0];

	ret[0] = handle;

	SifCallRpc(&cdata, PS2CAM_RPC_READPACKET, 0, (void*)(&data[0]),4,(void*)(&data[0]),4*2,0,0);


	if(ret[0] < 0) return ret[0];


	DI();
	ee_kmode_enter();

	iop_addr = (int *)(0xbc000000+ret[1]);

	memcpy(&campacket[0],iop_addr, ret[0]);

	ee_kmode_exit();
	EI();

	//if i add a printf here, the ps2 will exit to sony's explorer
	SignalSema(sem);
	return ret[0];
}
예제 #30
0
void led_display_text(const unsigned char *msg)
{
	char *new_msg;

	msg_size = strlen(msg);
	new_msg = malloc(sizeof(*new_msg) * (msg_size + 2));	//+2 for space pad and null terminator
	if(!new_msg) {
		msg_size = 0;
	}
	else {
		memcpy(new_msg, msg, msg_size);

		//space pads the wrap-around
		if(msg_size > 4) {
			new_msg[msg_size] = ' ';
			++msg_size;
		}
		new_msg[msg_size] = '\0';

		DI();
		
		if(led_msg != NULL) {
			free(led_msg);
		}
		
		led_msg = new_msg;
		msg_pos = 0;
		row_pos = 0;
		led_set_draw_chars();

		EI();
	}
}