Ejemplo n.º 1
0
static bool fifoInternalSend(u32 firstword, int extrawordcount, u32 * wordlist) {
	if(extrawordcount>0 && !wordlist) return false;
	if(fifo_freewords<extrawordcount+1) return false;
	if(extrawordcount<0 || extrawordcount>(FIFO_MAX_DATA_BYTES/4)) return false;

	int count = 0;
	int oldIME = enterCriticalSection();

	u32 head = fifo_waitBlock();
	if(fifo_send_queue.head == FIFO_BUFFER_TERMINATE) {
		fifo_send_queue.head = head;
	} else {
		FIFO_BUFFER_SETNEXT(fifo_send_queue.tail,head);		
	}
	FIFO_BUFFER_DATA(head)=firstword;
	fifo_send_queue.tail = head;

	while (count<extrawordcount) {
		u32 next = fifo_waitBlock();
		if(fifo_send_queue.head == FIFO_BUFFER_TERMINATE) {
			fifo_send_queue.head = next;
		} else {
			FIFO_BUFFER_SETNEXT(fifo_send_queue.tail,next);		
		}
		FIFO_BUFFER_DATA(next)=wordlist[count];
		count++;
		fifo_send_queue.tail = next;
	}

	REG_IPC_FIFO_CR |= IPC_FIFO_SEND_IRQ;

	leaveCriticalSection(oldIME);
	
	return true;
}
Ejemplo n.º 2
0
//---------------------------------------------------------------------------------
void irqClearAUX(u32 mask) {
//---------------------------------------------------------------------------------
    int oldIME = enterCriticalSection();
    __irqClear(mask,irqTableAUX);
    irqDisable( mask);
    leaveCriticalSection(oldIME);
}
Ejemplo n.º 3
0
Archivo: sdmmc.c Proyecto: bowies/Team3
//---------------------------------------------------------------------------------
void sdmmc_controller_init() {
//---------------------------------------------------------------------------------
	int oldIME = enterCriticalSection();
	// Reset
	sdmmc_write16(0x100, 0x0402);
	sdmmc_write16(0x100, 0x0000);
	sdmmc_write16(0x104, 0x0000);
	sdmmc_write16(0x108, 0x0001);

	// InitIP
	sdmmc_mask16(REG_SDRESET, 0x0001, 0x0000);
	sdmmc_mask16(REG_SDRESET, 0x0000, 0x0001);
	sdmmc_mask16(REG_SDSTOP, 0x0001, 0x0000);

	// Reset
	sdmmc_mask16(REG_SDOPT, 0x0005, 0x0000);

	// EnableInfo
	sdmmc_mask16(REG_SDSTATUS0, 0x0018, 0x0000);
	sdmmc_mask16(0x20, 0x0018, 0x0000); // ??
	sdmmc_mask16(0x20, 0x0000, 0x0018);

	sdmmc_init_irq();
	leaveCriticalSection(oldIME);
}
Ejemplo n.º 4
0
int fifoGetDatamsg(int channel, int buffersize, u8 * destbuffer) {
	if(channel<0 || channel>=FIFO_NUM_CHANNELS) return -1;
	int block = fifo_data_queue[channel].head;
	if (block == FIFO_BUFFER_TERMINATE) return -1;
	int oldIME = enterCriticalSection();

	int num_bytes = FIFO_BUFFER_GETEXTRA(block);
	int	num_words = (num_bytes+3)>>2;
	u32 buffer_array[num_words];

	int i,next;
	for(i=0; i<num_words;i++) {
		buffer_array[i] = FIFO_BUFFER_DATA(block);
		next=FIFO_BUFFER_GETNEXT(block);
		fifo_freeBlock(block);
		block=next;
		if(block==FIFO_BUFFER_TERMINATE) break;
	}
	fifo_data_queue[channel].head = block;

	if(buffersize<num_bytes) num_bytes=buffersize;
	memcpy(destbuffer,buffer_array,num_bytes);

	leaveCriticalSection(oldIME);
	return num_bytes;
	
}
//------------------------------------------------------------------------------
tOplkError timeru_deleteTimer(tTimerHdl* pTimerHdl_p)
{
    tTimerEntry*    pTimerEntry;
    tTimerEntry**   ppEntry;

    // check pointer to handle
    if (pTimerHdl_p == NULL)
        return kErrorTimerInvalidHandle;

    // check handle itself, i.e. was the handle initialized before
    if (*pTimerHdl_p == 0)
        return kErrorOk;

    pTimerEntry = (tTimerEntry*)*pTimerHdl_p;

    // remove timer entry from timer list
    enterCriticalSection(TIMERU_TIMER_LIST);
    ppEntry = &timeruInstance_l.pTimerListFirst;
    while (*ppEntry != NULL)
    {
        if (*ppEntry == pTimerEntry)
        {
            *ppEntry = pTimerEntry->pNext;
            if (*ppEntry != NULL)
            {
                (*ppEntry)->timeoutInMs += pTimerEntry->timeoutInMs;
            }
            break;
        }

        ppEntry = &(*ppEntry)->pNext;
    }
    leaveCriticalSection(TIMERU_TIMER_LIST);

    // insert in free list
    enterCriticalSection(TIMERU_FREE_LIST);
    pTimerEntry->pNext = timeruInstance_l.pFreeListFirst;
    timeruInstance_l.pFreeListFirst = pTimerEntry;
    timeruInstance_l.freeEntries++;
    leaveCriticalSection(TIMERU_FREE_LIST);

    // set handle invalid
    *pTimerHdl_p = 0;
    return kErrorOk;

}
//------------------------------------------------------------------------------
static DWORD WINAPI processThread(LPVOID parameter_p)
{
    tTimerEntry*    pTimerEntry;
    UINT32          timeoutInMs;
    UINT32          waitResult;
    tOplkError      ret;

    UNUSED_PARAMETER(parameter_p);

    for (;;)
    {
        ret = timeru_process();
        if (ret != kErrorOk)
        {
            // Error
        }

        // calculate time until the next timer event
        enterCriticalSection(TIMERU_TIMER_LIST);
        pTimerEntry = timeruInstance_l.pTimerListFirst;
        if (pTimerEntry == NULL)
        {   // timer list is empty
            timeoutInMs = INFINITE;
        }
        else
        {
            timeoutInMs = getTickCount() - timeruInstance_l.startTimeInMs;
            if (timeoutInMs > pTimerEntry->timeoutInMs)
            {   // timeout elapsed
                timeoutInMs = 0;
            }
            else
            {   // adjust timeout with elapsed time since start time
                timeoutInMs = pTimerEntry->timeoutInMs - timeoutInMs;
            }
        }
        leaveCriticalSection(TIMERU_TIMER_LIST);

        waitResult = WaitForMultipleObjects(2, timeruInstance_l.ahEvents, FALSE, timeoutInMs);
        switch (waitResult)
        {
            case (WAIT_OBJECT_0 + TIMERU_EVENT_SHUTDOWN):
                goto Exit;
                break;

            case (WAIT_OBJECT_0 + TIMERU_EVENT_WAKEUP):
            case WAIT_TIMEOUT:
                break;

            default:
                // Error
                break;
        }
    }

Exit:
    return 0;
}
Ejemplo n.º 7
0
void * fifoGetAddress(int channel) {
	if(channel<0 || channel>=FIFO_NUM_CHANNELS) return NULL;
	int block = fifo_address_queue[channel].head;
	if (block == FIFO_BUFFER_TERMINATE) return NULL;
	int oldIME = enterCriticalSection();
	void *address = (void*)FIFO_BUFFER_DATA(block);
	fifo_address_queue[channel].head = FIFO_BUFFER_GETNEXT(block);
	fifo_freeBlock(block);
	leaveCriticalSection(oldIME);
	return address;
}
Ejemplo n.º 8
0
//---------------------------------------------------------------------------------
void irqSet(u32 mask, IntFn handler) {
//---------------------------------------------------------------------------------
    int oldIME = enterCriticalSection();
    __irqSet(mask,handler,irqTable);
    if(mask & IRQ_VBLANK)
        REG_DISPSTAT |= DISP_VBLANK_IRQ ;
    if(mask & IRQ_HBLANK)
        REG_DISPSTAT |= DISP_HBLANK_IRQ ;
    if(mask & IRQ_IPC_SYNC)
        REG_IPC_SYNC |= IPC_SYNC_IRQ_ENABLE;
    leaveCriticalSection(oldIME);
}
Ejemplo n.º 9
0
u32 fifoGetValue32(int channel) {
	if(channel<0 || channel>=FIFO_NUM_CHANNELS) return 0;
	int block = fifo_value32_queue[channel].head;
	if ( block == FIFO_BUFFER_TERMINATE) return 0;

	int oldIME = enterCriticalSection();
	u32 value32 = FIFO_BUFFER_DATA(block);
	fifo_value32_queue[channel].head = FIFO_BUFFER_GETNEXT(block);
	fifo_freeBlock(block);
	leaveCriticalSection(oldIME);
	return value32;
}
Ejemplo n.º 10
0
void CPythonEngine::threadGILAcquire(int ms)
{
    init();
    enterCriticalSection();

    PyGILState_STATE gstate;
    gstate = PyGILState_Ensure();
    char buf[128];
    sprintf(buf, "time.sleep(%d.%03d)", ms / 1000, ms % 1000);
    PyRun_SimpleString(buf);

    PyGILState_Release(gstate);
    leaveCriticalSection();
}
Ejemplo n.º 11
0
//---------------------------------------------------------------------------------
void irqDisable(uint32 irq) {
//---------------------------------------------------------------------------------
    int oldIME = enterCriticalSection();
    if (irq & IRQ_VBLANK)
        REG_DISPSTAT &= ~DISP_VBLANK_IRQ ;
    if (irq & IRQ_HBLANK)
        REG_DISPSTAT &= ~DISP_HBLANK_IRQ ;
    if (irq & IRQ_VCOUNT)
        REG_DISPSTAT &= ~DISP_YTRIGGER_IRQ;
    if(irq & IRQ_IPC_SYNC)
        REG_IPC_SYNC &= ~IPC_SYNC_IRQ_ENABLE;

    REG_IE &= ~irq;
    leaveCriticalSection(oldIME);
}
Ejemplo n.º 12
0
void CPythonEngine::backpipeTamsgTick()
{
    init();
    enterCriticalSection();
    long int tm = GetTickCount();
    CMemReader& reader = CMemReader::getMemReader();
    CIpcMessage mess;

    if (CIPCBackPipe::readFromPipe(&mess, 1007))
    {
        int msgLen;
        char msgBuf[16384];

        memset(msgBuf, 0, 16384);
        memcpy(&msgLen, mess.payload, sizeof(int));
        memcpy(msgBuf, mess.payload + 4, msgLen);

        int scriptNr;
        for (scriptNr = 0;; scriptNr++)
        {
            CPythonScript *pythonScript = CPythonScript::getScriptByNr(scriptNr);
            if (!pythonScript)
                break;
            if (!pythonScript->isEnabled())
                continue;
            int funNr;
            for (funNr = 0;; funNr++)
            {
                struct funType *fun = pythonScript->getFunDef(funNr);
                if (!fun)
                    break;

                if (fun->type == FUNTYPE_TAMSG)
                {
                    PyGILState_STATE gstate;
                    gstate = PyGILState_Ensure();
                    PyObject *params = pythonScript->getParamsDic();
                    PyObject *result = PyObject_CallMethod(pythonScript->getPluginObject(), fun->name, "(Os)", params, msgBuf);
                    Py_XDECREF(params);
                    Py_XDECREF(result);
                    fun->call();
                    PyGILState_Release(gstate);
                }
            }
        }
    }
    leaveCriticalSection();
}
Ejemplo n.º 13
0
int writeFirmwarePage(u32 address,u8 *buffer) {
	int i;
	u8 pagebuffer[256];
	readFirmware(address, pagebuffer, 256);
	
	if(memcmp(pagebuffer, buffer, 256) == 0) return 0;
	
	int oldIME = enterCriticalSection();
	
	//write enable
	REG_SPICNT = SPI_ENABLE | SPI_CONTINUOUS | SPI_DEVICE_NVRAM;
	readwriteSPI(FIRMWARE_WREN);
	REG_SPICNT = 0;
	
	//Wait for Write Enable Latch to be set
	REG_SPICNT = SPI_ENABLE | SPI_CONTINUOUS | SPI_DEVICE_NVRAM;
	readwriteSPI(FIRMWARE_RDSR);
	while((readwriteSPI(0) & 0x02) == 0); //Write Enable Latch
	REG_SPICNT = 0;
	
	//page write
	REG_SPICNT = SPI_ENABLE | SPI_CONTINUOUS | SPI_DEVICE_NVRAM;
	readwriteSPI(FIRMWARE_PW);
	// Set the address
	readwriteSPI((address>>16) & 0xff);
	readwriteSPI((address>> 8) & 0xff);
	readwriteSPI((address) & 0xff);
	
	for(i = 0; i < 256; i++) {
		readwriteSPI(buffer[i]);
	}
	
	REG_SPICNT = 0;
	
	// wait for programming to finish
	REG_SPICNT = SPI_ENABLE|SPI_CONTINUOUS|SPI_DEVICE_NVRAM;
	readwriteSPI(FIRMWARE_RDSR);
	while(readwriteSPI(0) & 0x01); //Write In Progress
	REG_SPICNT = 0;
	
	leaveCriticalSection(oldIME);
	
	// read it back & verify
	readFirmware(address, pagebuffer, 256);
	if(memcmp(pagebuffer, buffer, 256) == 0) return 0;
	return -1;
}
//------------------------------------------------------------------------------
tOplkError timeru_process(void)
{
    tTimerEntry*        pTimerEntry;
    UINT32              timeoutInMs;
    tEvent              event;
    tTimerEventArg      timerEventArg;
    tOplkError          ret = kErrorOk;

    enterCriticalSection(TIMERU_TIMER_LIST);
    // calculate elapsed time since start time
    timeoutInMs = getTickCount() - timeruInstance_l.startTimeInMs;

    // observe first timer entry in timer list
    pTimerEntry = timeruInstance_l.pTimerListFirst;
    if (pTimerEntry != NULL)
    {
        if (timeoutInMs >= pTimerEntry->timeoutInMs)
        {   // timeout elapsed - remove entry from timer list
            timeruInstance_l.pTimerListFirst = pTimerEntry->pNext;
            // adjust start time
            timeruInstance_l.startTimeInMs += pTimerEntry->timeoutInMs;
        }
        else
        {
            pTimerEntry = NULL;
        }
    }
    leaveCriticalSection(TIMERU_TIMER_LIST);

    if (pTimerEntry != NULL)
    {
        // call event function
        timerEventArg.timerHdl = (tTimerHdl)pTimerEntry;
        OPLK_MEMCPY(&timerEventArg.argument, &pTimerEntry->timerArg.argument, sizeof(timerEventArg.argument));

        event.eventSink = pTimerEntry->timerArg.eventSink;
        event.eventType = kEventTypeTimer;
        OPLK_MEMSET(&event.netTime, 0x00, sizeof(tNetTime));
        event.pEventArg = &timerEventArg;
        event.eventArgSize = sizeof(timerEventArg);

        ret = eventu_postEvent(&event);
    }

    return ret;
}
Ejemplo n.º 15
0
void CVmc::setMotorRPM(int motor, int rpm)
{
	if((rpm < -1*_maxRpm) || (rpm > _maxRpm)) return;
	if((motor < 1) || (motor > 3)) return;

	enterCriticalSection();

	switch(motor)
	{
		case 1: _pwmOut1= rpm; break;
		case 2: _pwmOut2= rpm; break;
		case 3: _pwmOut3= rpm; break;
		default: break;
	}

	leaveCriticalSection();
}
Ejemplo n.º 16
0
// fifoSetAddressHandler - Set a callback to receive incoming address messages on a specific channel.
bool fifoSetAddressHandler(int channel, FifoAddressHandlerFunc newhandler, void * userdata) {
	if(channel<0 || channel>=FIFO_NUM_CHANNELS) return false;

	int oldIME = enterCriticalSection();

	fifo_address_func[channel] = newhandler;
	fifo_address_data[channel] = userdata;
	
	if(newhandler) {
		while(fifoCheckAddress(channel)) {
			newhandler( fifoGetAddress(channel), userdata );
		}
	}

	leaveCriticalSection(oldIME);

	return true;
}
Ejemplo n.º 17
0
void CPythonEngine::periodicalTick()
{
    init();
    enterCriticalSection();
    long int tm = GetTickCount();
    int scriptNr;
    for (scriptNr = 0;; scriptNr++)
    {
        CPythonScript *pythonScript = CPythonScript::getScriptByNr(scriptNr);
        if (!pythonScript)
            break;
        if (!pythonScript->isEnabled())
            continue;
        int funNr;
        for (funNr = 0;; funNr++)
        {
            struct funType *fun = pythonScript->getFunDef(funNr);
            if (!fun)
                break;

            if (fun->type == FUNTYPE_PERIODICAL && tm >= fun->tmNextExec)
            {
                CPythonScript *pythonScript = CPythonScript::getScriptByNr(scriptNr);

                PyGILState_STATE gstate;
                gstate = PyGILState_Ensure();
                PyObject *params = pythonScript->getParamsDic();
                PyObject *result = PyObject_CallMethod(pythonScript->getPluginObject(), fun->name, "(O)", params);
                Py_XDECREF(params);
                Py_XDECREF(result);

                fun->call();

                PyGILState_Release(gstate);
            }
        }
    }
    leaveCriticalSection();
}
Ejemplo n.º 18
0
// fifoSetDatamsgHandler - Set a callback to receive incoming data sequences on a specific channel.
bool fifoSetDatamsgHandler(int channel, FifoDatamsgHandlerFunc newhandler, void * userdata) {
	if(channel<0 || channel>=FIFO_NUM_CHANNELS) return false;

	int oldIME = enterCriticalSection();

	fifo_datamsg_func[channel] = newhandler;
	fifo_datamsg_data[channel] = userdata;


	if(newhandler) {
		while(fifoCheckDatamsg(channel)) {
			int block = fifo_data_queue[channel].head;
			int n_bytes = FIFO_UNPACK_DATALENGTH(FIFO_BUFFER_DATA(block));
			newhandler(n_bytes, userdata);
			if (block == fifo_data_queue[channel].head) fifoGetDatamsg(channel,0,0);
		}
	}

	leaveCriticalSection(oldIME);

	return true;
}
Ejemplo n.º 19
0
void CPythonEngine::unloadScript(int scriptNr)
{


    init();
    enterCriticalSection();
    CPythonScript *pythonScript = CPythonScript::getScriptByNr(scriptNr);
    pythonScript->setEnabled(false);
    struct funType *fun = NULL;
    for (int funNr = 0; (fun = pythonScript->getFunDef(funNr)); funNr++)
    {
        if (fun->type == FUNTYPE_INPACKET)
            CPackSender::unregisterInpacketRegex(fun->matchExprHandle);
    }

    CPythonScript::pythonScriptTab[scriptNr] = CPythonScript::pythonScriptTab[CPythonScript::pythonScriptCount - 1];
    CPythonScript::pythonScriptCount--;
    registerPluginCount--;
    // this is commented out by purpose - there would be too much threads
    // playing to cleanup this memory here
    //delete pythonScript;//crashes TA on reloading script possibly fix later!
    leaveCriticalSection();
}
Ejemplo n.º 20
0
// Calls python functions of type 3 when we receive notice of an incoming packet
void CPythonEngine::backpipeInpacketTick()
{
    init();
    enterCriticalSection();
    CMemReader& reader = CMemReader::getMemReader();
    CIpcMessage mess;
    struct parcelRecvActionData* pd;

    //runs at most 'maxtimes' python functions each tick
    for (int maxtimes = 5; CIPCBackPipe::readFromPipe(&mess, 1010) && maxtimes > 0; maxtimes--)
    {
        char buf[1024];

        long int tm = GetTickCount();
        pd = (parcelRecvActionData*)&(mess.payload);

        int discardIncompletePacket = pd->countLeft + 1 != pd->totalCount; //the initial packets were too old and were discarded

        int countLeft = pd->countLeft;
        int msgLen    = pd->len;
        int handle    = pd->handle;
        char* msgBuf  = (char*)malloc(sizeof(pd->actionData) * (countLeft + 1));
        memcpy(msgBuf, pd->actionData, pd->len);
        while (countLeft && GetTickCount() - tm < 200)  // wait for remaining sections to come in for up to 200ms(they should always be on their way)
        {
            if (CIPCBackPipe::readFromPipe(&mess, 1010))
            {
                if (pd->handle != handle || pd->countLeft != countLeft - 1)
                    sprintf(buf, "ERROR in backpipeInpacketTick: handle %d should be %d and count %d should be %d", pd->handle, handle, pd->countLeft, countLeft - 1);
                //AfxMessageBox(buf);
                memcpy(msgBuf + msgLen, pd->actionData, pd->len);
                msgLen   += pd->len;
                countLeft = pd->countLeft;
            }
        }
        if (countLeft)
        {
            sprintf(buf, "ERROR in backpipeInpacketTick: did not finish reading data");
            //AfxMessageBox(buf);
        }
        else if (discardIncompletePacket)
        {
            int a = 0;// discard data and continue
        }
        else     //everything is OK
        {
            sprintf(buf, "One packet took %dms", GetTickCount() - tm);
            //if (GetTickCount() - tm>20) MessageBox(NULL, buf,"huaeotnre",0);
            CPythonScript *pythonScript = NULL;
            for (int scriptNr = 0; (pythonScript = CPythonScript::getScriptByNr(scriptNr)); scriptNr++)
            {
                if (!pythonScript->isEnabled())
                    continue;
                struct funType *fun = NULL;
                for (int funNr = 0; (fun = pythonScript->getFunDef(funNr)); funNr++)
                {
                    if (fun->type == FUNTYPE_INPACKET && fun->matchExprHandle == pd->handle)
                    {
                        PyGILState_STATE gstate;
                        gstate = PyGILState_Ensure();
                        PyObject *result = PyObject_CallMethod(pythonScript->getPluginObject(), fun->name, "(s#)", msgBuf, msgLen);
                        Py_XDECREF(result);
                        fun->call();
                        PyGILState_Release(gstate);
                        goto inpacketTickCleanup;
                    }
                }
            }
        }
inpacketTickCleanup:
        msgBuf[0] = 0;
        free(msgBuf);
    }
    leaveCriticalSection();
}
Ejemplo n.º 21
0
Archivo: sdmmc.c Proyecto: bowies/Team3
//---------------------------------------------------------------------------------
int sdmmc_sdcard_init() {
//---------------------------------------------------------------------------------
	u16 sdaddr;
	u32 resp0;
	u32 resp1;
	u32 resp2;
	u32 resp3;
	u32 resp4;
	u32 resp5;
	u32 resp6;
	u32 resp7;

	u32 ocr, ccs, hcs, response;

	sdmmc_cardready = 0;

	int oldIME = enterCriticalSection();

	sdmmc_write16(REG_SDCLKCTL, 0x20);
	sdmmc_write16(REG_SDOPT, 0x40EA); // XXX: document me!
	sdmmc_write16(0x02, 0x400);

	sdmmc_mask16(REG_SDCLKCTL, 0, 0x100);
	sdmmc_write16(REG_SDCLKCTL, sdmmc_read16(REG_SDCLKCTL));
	sdmmc_mask16(REG_SDCLKCTL, 0x100, 0);
	sdmmc_mask16(REG_SDCLKCTL, 0, 0x200);
	sdmmc_mask16(REG_SDCLKCTL, 0, 0x100);

	// CMD0
	sdmmc_send_command(0x0000, 0x0000, 0x0000);
	sdmmc_send_command(0x0408, 0x01aa, 0x0000);
	sdmmc_gotcmd8reply = 1;

	if(sdmmc_timeout)
		sdmmc_gotcmd8reply = 0;

	if(sdmmc_gotcmd8reply)
		hcs = (1<<30);
	else
		hcs = 0;

	ocr = 0x00ff8000;

	while (1) {
		sdmmc_send_acmd41(ocr | hcs, &response);

		if (response & 0x80000000)
			break;
	}

	ccs = response & (1<<30);

	if(ccs && hcs) 
		sdmmc_sdhc = 1;
	else
		sdmmc_sdhc = 0;

	// CMD2 - get CID
	sdmmc_send_command(2, 0, 0);
	
	resp0 = sdmmc_read16(REG_SDRESP0);
	resp1 = sdmmc_read16(REG_SDRESP1);
	resp2 = sdmmc_read16(REG_SDRESP2);
	resp3 = sdmmc_read16(REG_SDRESP3);
	resp4 = sdmmc_read16(REG_SDRESP4);
	resp5 = sdmmc_read16(REG_SDRESP5);
	resp6 = sdmmc_read16(REG_SDRESP6);
	resp7 = sdmmc_read16(REG_SDRESP7);

	sdmmc_cid[0] = resp0 | (u32)(resp1<<16);
	sdmmc_cid[1] = resp2 | (u32)(resp3<<16);
	sdmmc_cid[2] = resp4 | (u32)(resp5<<16);
	sdmmc_cid[3] = resp6 | (u32)(resp7<<16);

	// CMD3
	sdmmc_send_command(3, 0, 0);
	
	resp0 = sdmmc_read16(REG_SDRESP0);
	resp1 = sdmmc_read16(REG_SDRESP1);
	
	sdaddr = resp1;
	
	// CMD9 - get CSD
	sdmmc_send_command(9, 0, sdaddr);
	
	resp0 = sdmmc_read16(REG_SDRESP0);
	resp1 = sdmmc_read16(REG_SDRESP1);
	resp2 = sdmmc_read16(REG_SDRESP2);
	resp3 = sdmmc_read16(REG_SDRESP3);
	resp4 = sdmmc_read16(REG_SDRESP4);
	resp5 = sdmmc_read16(REG_SDRESP5);
	resp6 = sdmmc_read16(REG_SDRESP6);
	resp7 = sdmmc_read16(REG_SDRESP7);
	
	sdmmc_write16(REG_SDCLKCTL, 0x100);	
	
	// CMD7
	sdmmc_send_command(7, 0, sdaddr);
	
	resp0 = sdmmc_read16(REG_SDRESP0);
	resp1 = sdmmc_read16(REG_SDRESP1);
	
	// CMD55
	sdmmc_send_command(55, 0, sdaddr);
	
	// ACMD6
	sdmmc_send_command(6, 2, 0);
	
	resp0 = sdmmc_read16(REG_SDRESP0);
	resp1 = sdmmc_read16(REG_SDRESP1);

	sdmmc_send_command(13, 0, sdaddr);
	
	resp0 = sdmmc_read16(REG_SDRESP0);
	resp1 = sdmmc_read16(REG_SDRESP1);

	sdmmc_send_command(16, 0x200, 0x0);
	
	resp0 = sdmmc_read16(REG_SDRESP0);
	resp1 = sdmmc_read16(REG_SDRESP1);	
	
	sdmmc_write16(REG_SDCLKCTL, sdmmc_read16(REG_SDCLKCTL));
	sdmmc_write16(REG_SDBLKLEN, 0x200);

	sdmmc_mask16(REG_SDCLKCTL, 0x100, 0);

	sdmmc_cardready = 1;
	leaveCriticalSection(oldIME);

	return 0;
}
//------------------------------------------------------------------------------
tOplkError timeru_setTimer(tTimerHdl* pTimerHdl_p, ULONG timeInMs_p, tTimerArg argument_p)
{
    tTimerEntry*    pNewEntry;
    tTimerEntry**   ppEntry;

    // check pointer to handle
    if (pTimerHdl_p == NULL)
        return kErrorTimerInvalidHandle;

    // fetch entry from free timer list
    enterCriticalSection(TIMERU_FREE_LIST);
    pNewEntry = timeruInstance_l.pFreeListFirst;
    if (pNewEntry != NULL)
    {
        timeruInstance_l.pFreeListFirst = pNewEntry->pNext;
        timeruInstance_l.freeEntries--;
        if (timeruInstance_l.minFreeEntries > timeruInstance_l.freeEntries)
        {
            timeruInstance_l.minFreeEntries = timeruInstance_l.freeEntries;
        }
    }
    leaveCriticalSection(TIMERU_FREE_LIST);

    if (pNewEntry == NULL)
    {   // sorry, no free entry
        return kErrorTimerNoTimerCreated;
    }

    *pTimerHdl_p = (tTimerHdl)pNewEntry;
    OPLK_MEMCPY(&pNewEntry->timerArg, &argument_p, sizeof(tTimerArg));

    // insert timer entry in timer list
    enterCriticalSection(TIMERU_TIMER_LIST);
    // calculate timeout based on start time
    pNewEntry->timeoutInMs = (getTickCount() - timeruInstance_l.startTimeInMs) + timeInMs_p;

    ppEntry = &timeruInstance_l.pTimerListFirst;
    while (*ppEntry != NULL)
    {
        if ((*ppEntry)->timeoutInMs > pNewEntry->timeoutInMs)
        {
            (*ppEntry)->timeoutInMs -= pNewEntry->timeoutInMs;
            break;
        }
        pNewEntry->timeoutInMs -= (*ppEntry)->timeoutInMs;
        ppEntry = &(*ppEntry)->pNext;
    }
    // insert before **ppEntry
    pNewEntry->pNext = *ppEntry;
    *ppEntry = pNewEntry;
    leaveCriticalSection(TIMERU_TIMER_LIST);

#if (TARGET_SYSTEM == _WIN32_ || TARGET_SYSTEM == _WINCE_ )
    if (ppEntry == &timeruInstance_l.pTimerListFirst)
    {
        SetEvent(timeruInstance_l.ahEvents[TIMERU_EVENT_WAKEUP]);
    }
#endif

    return kErrorOk;
}
Ejemplo n.º 23
0
//---------------------------------------------------------------------------------
void irqEnableAUX(uint32 irq) {
//---------------------------------------------------------------------------------
    int oldIME = enterCriticalSection();
    REG_AUXIE |= irq;
    leaveCriticalSection(oldIME);
}
Ejemplo n.º 24
0
void CPythonEngine::backpipeMsgTick()
{
    init();
    enterCriticalSection();
    long int tm = GetTickCount();
    CMemReader& reader = CMemReader::getMemReader();
    CIpcMessage mess;

    if (CIPCBackPipe::readFromPipe(&mess, 1006))
    {
        int infoType;
        int chanType;
        int nickLen;
        int msgLen;
        char nickBuf[16384];
        char msgBuf[16384];
        char chanBuf[16384];

        memset(nickBuf, 0, 16384);
        memset(msgBuf, 0, 16384);
        memcpy(&infoType, mess.payload, sizeof(int));
        memcpy(&chanType, mess.payload + 4, sizeof(int));
        memcpy(&nickLen, mess.payload + 8, sizeof(int));
        memcpy(&msgLen, mess.payload + 12, sizeof(int));
        memcpy(nickBuf, mess.payload + 16, nickLen);
        memcpy(msgBuf, mess.payload + 16 + nickLen, msgLen);
        switch (infoType)
        {
        case 1:
            sprintf(chanBuf, "say");
            break;
        case 2:
            sprintf(chanBuf, "whisper");
            break;
        case 3:
            sprintf(chanBuf, "yell");
            break;
        case 11:
            sprintf(chanBuf, "NPC");
            break;
        case 6:
            sprintf(chanBuf, "private");
            break;
        case 7:
            sprintf(chanBuf, "channel");
            break;
        default:
            sprintf(chanBuf, "other[%d]", infoType);
            break;
        }
        //Channel IDs
        //1-Party
        //2-Own Chat Channel(premium)
        //3-Game Chat
        //4-English Channel
        //5-Trade
        //6-Rook Trade
        //7-Help

        int scriptNr;
        for (scriptNr = 0;; scriptNr++)
        {
            CPythonScript *pythonScript = CPythonScript::getScriptByNr(scriptNr);
            if (!pythonScript)
                break;
            if (!pythonScript->isEnabled())
                continue;
            int funNr;
            for (funNr = 0;; funNr++)
            {
                struct funType *fun = pythonScript->getFunDef(funNr);
                if (!fun)
                    break;

                if (fun->type == FUNTYPE_MSG)
                {
                    PyGILState_STATE gstate;
                    gstate = PyGILState_Ensure();
                    PyObject *params = pythonScript->getParamsDic();
                    PyObject *result = PyObject_CallMethod(pythonScript->getPluginObject(), fun->name, "(O(isss))", params, infoType, chanBuf, nickBuf, msgBuf);
                    Py_XDECREF(params);
                    Py_XDECREF(result);
                    fun->call();
                    PyGILState_Release(gstate);
                }
            }
        }
    }
    leaveCriticalSection();
}
Ejemplo n.º 25
0
//---------------------------------------------------------------------------------
void irqSetAUX(u32 mask, IntFn handler) {
//---------------------------------------------------------------------------------
    int oldIME = enterCriticalSection();
    __irqSet(mask,handler,irqTableAUX);
    leaveCriticalSection(oldIME);
}