int spwr_get_linkstatus(int dd,int portnum,unsigned int* status){
	ER er;
	UW data;
	int asize;

	if(portnum<1 || 6<portnum){
		return E_PAR;
	}

	int address;
	switch(portnum){
	case 1: address=DN_SPW1CSR;break;
	case 2: address=DN_SPW2CSR;break;
	case 3: address=DN_SPW3CSR;break;
	case 4: address=DN_SPW4CSR;break;
	case 5: address=DN_SPW5CSR;break;
	case 6: address=DN_SPW6CSR;break;
	default: return E_PAR;break;
	}

	er = tk_srea_dev(dd, address, &data, sizeof(data), &asize);
	if (asize != 4) {
		tk_cls_dev(dd, 0);
		return E_IO;
	}

	*status=data;
	return er;
}
Beispiel #2
0
int spw_close(int dd)
{
	if (dd > 0) {
		return 0;
		tk_cls_dev(dd, 0);
	} else {
		return 1;
	}
}
Beispiel #3
0
/*
        initial setting at driver start up time
*/
LOCAL	ER	kpStartUp(void)
{
	W	w[L_DEVCONF_VAL];
	W	dd, n;
	ER	er;
	RawEvt	evt;
	T_CMBF	cmbf;
	T_CFLG	cflg;
	ID	datatsk;
	void*	name;
	union {
		FlgInStat	stat;
		UW		uw;
	} u;

        /* extract ID of the mailbox for event notification to KB/PD driver */
	dd = er = tk_opn_dev(devkbpd, TD_READ);
	if (er >= E_OK) {
		er = tk_srea_dev(dd, DN_KPINPUT, (VB*)&EvtMbx,
						sizeof(EvtMbx), &n);
		tk_cls_dev(dd, 0);
	}
	if (er < E_OK) goto EEXIT1;

        /* KBID is extracted from DEVCONF parameter */
	KbdId = (GetDevConf("KBTYPE", w) == 1) ? w[0] : KID_IBM_JP;

        /* input message buffer creation */
	SetOBJNAME(cmbf.exinf, "lkbM");
	cmbf.mbfatr = TA_TFIFO;
	cmbf.bufsz  = sizeof(InMsg) * MAX_INMSG;
	cmbf.maxmsz = sizeof(InMsg);
	if ((er = tk_cre_mbf(&cmbf)) < E_OK) goto EEXIT1;
	InpMbf = er;

        /* creating the event flag for command */
	SetOBJNAME(cflg.exinf, "lkbC");
	cflg.flgatr  = TA_WMUL;
	cflg.iflgptn = 0;
	if ((er = tk_cre_flg(&cflg)) < E_OK) goto EEXIT2;
	CmdFlg = (ID)er;

        /* create and start data processing task */
	SetOBJNAME(name, "lkbD");
	er = kpCreTask((W)name, kpDataTask);
	if (er < E_OK) goto EEXIT3;
	datatsk = (ID)er;

        /* create and start command processing task */
	SetOBJNAME(name, "lkbC");
	er = kpCreTask((W)name, kpCmdTask);
	if (er < E_OK) goto EEXIT4;
	CmdTsk = (ID)er;

        /* registering event flag for commands */
	u.uw = 0;
	evt.f.stat = u.stat;
	evt.f.stat.cmd = INP_FLG;
	evt.f.stat.kb = 1;
	evt.f.stat.kbid = KbdId;
	evt.f.stat.reg = 1;
	evt.f.flgid = CmdFlg;
	if ((er = kpSendMsg(&evt)) < E_OK) goto EEXIT5;

        /* device initialization processing */
	er = hwInit(DC_OPEN);
	if (er < E_OK) goto EEXIT5;

	return E_OK;

EEXIT5:
	tk_ter_tsk(CmdTsk);
	tk_del_tsk(CmdTsk);
EEXIT4:
	tk_ter_tsk(datatsk);
	tk_del_tsk(datatsk);
EEXIT3:
	tk_del_flg(CmdFlg);
EEXIT2:
	tk_del_mbf(InpMbf);
EEXIT1:
	DP(("kpStartUp: err=%#x\n", er));
	return er;
}
Beispiel #4
0
/*
	Get from / Set to RTC
*/
LOCAL	void	rtc_get_set(SYSTIM *stm, BOOL set)
{
	ID		dd;
	W		asz;
	ER		er;
	DATE_TIM	dt;
	struct tm	ctm;
	struct tzinfo	tz;

	/* open RTC (CLOCK) driver */
	dd = tk_opn_dev("CLOCK", (set == TRUE) ? TD_WRITE : TD_READ);
	if (dd < E_OK) {
		P("Can't open CLOCK device [%#x]\n", dd);
		goto exit0;
	}

	/* Note: The RTC is set to UTC rather than local time. because UTC
	   is not affected by time zone and daylight saving time. */

	if (set == TRUE) {	/* set date to RTC */

		/* convert system time to UTC date/time */
		dt_gmtime_ms(stm, &ctm);

		/* set local date/time to RTC */
		dt.d_year = ctm.tm_year;
		dt.d_month = ctm.tm_mon + 1;
		dt.d_day = ctm.tm_mday;
		dt.d_hour = ctm.tm_hour;
		dt.d_min = ctm.tm_min;
		dt.d_sec = ctm.tm_sec;
		dt.d_wday = ctm.tm_wday;
		er = tk_swri_dev(dd, DN_CKDATETIME, &dt, sizeof(dt), &asz);
		if (er < E_OK) {
			P("Can't set CLOCK [%#x]\n", er);
			goto exit1;
		}
	} else {		/* get date from RTC */

		/* get timezone of "UTC+0" */
		memset(&tz, 0, sizeof(tz));
		er = dt_tzset(&tz, "UTC+0");
		if (er < E_OK ) {
			P("dt_tzset(UTC+0) ERR [%#x]\n", er);
			goto exit1;
		}

		/* get UTC date/time from RTC */
		er = tk_srea_dev(dd, DN_CKDATETIME, &dt, sizeof(dt), &asz);
		if (er < E_OK) {
			P("Can't get CLOCK [%#x]\n", er);
			goto exit1;
		}

		/* convert to system time */
		ctm.tm_year = dt.d_year;
		ctm.tm_mon = dt.d_month - 1;
		ctm.tm_mday = dt.d_day;
		ctm.tm_hour = dt.d_hour;
		ctm.tm_min = dt.d_min;
		ctm.tm_sec = dt.d_sec;
		ctm.tm_wday = dt.d_wday;
		ctm.tm_usec = 0;
		ctm.tm_wday = -1;
		ctm.tm_isdst = 0;
		ctm.tm_yday = 0;
		dt_mktime_ms(&ctm, &tz, stm);
	}
exit1:
	tk_cls_dev(dd, 0);
exit0:
	return;
}