Exemple #1
0
        public Nucleus(IKernel kernel, int sysTmrIntNo, TMO sysTmrIntv)
        {
            m_Kernel = kernel;
            m_SysTmrIntNo = sysTmrIntNo;
            m_SysTmrIntv = sysTmrIntv;

            m_rsys.sysstat = SYSSTAT.TTS_INDP;

            for (int i = 0; i < m_ReadyQueue.Length; i++)
                m_ReadyQueue[i] = new LinkedList<Task>();

            m_SysTime.Value = 0;
            m_CurrentTask = null;
            m_lwIP = new lwip(ip_output);
            #if LWIP_STATS
            stats.stats_init();
            #endif
            sys.sys_init(m_lwIP, this);

            m_lwIP.mem_init();
            lwip.memp_init();
            pbuf.pbuf_init(m_lwIP);

            udp.udp_init(m_lwIP);
            tcp.tcp_init(m_lwIP);
        }
        public ER GetMemoryBlock(out pointer p_blk, int blksz, TMO tmout)
        {
            ER ret;

            p_blk = null;

            //if (p_blk == null)
            //	return ER.E_PAR;

            for (; ; ) {
                LinkedListNode<pointer> Node = m_MpfQueue.First;

                if (Node != null) {
                    p_blk = Node.Value;
                    m_MpfQueue.RemoveFirst();
                    break;
                }

                if (tmout == 0)
                    return ER.E_TMOUT;

                Task task = m_Nucleus.GetTask(ID.TSK_SELF);

                if (task == null)
                    return ER.E_CTX;

                ret = task.Wait(m_TskQueue, TSKWAIT.TTW_MPF, m_MpfID, tmout);

                switch (ret) {
                case ER.E_OK:
                    continue;
                case ER.E_TMOUT:
                    return ER.E_TMOUT;
                default:
                    return ER.E_RLWAI;
                }
            }

            return ER.E_OK;
        }
Exemple #3
0
        public Kernel(long frequency, int sysTmrIntNo, TMO sysTmrIntv)
        {
            m_Nucleus = new Nucleus(this, sysTmrIntNo, sysTmrIntv);

            m_Frequency = frequency;
            m_OnSetEvent = null;
            m_OnStart = null;
            m_OnTerminate = null;
            m_OnIdle = null;
            m_OnOutput = null;
            m_OnGetSystemTimeEvent = null;

            m_Thread = null;
            m_Terminate = false;
            m_IntEvent = null;
            m_Locked = 0;
            m_TaskMode = false;
            m_TlsIndex = new ThreadLocal<int>();
            m_SysSem = new System.Threading.Semaphore(1, 1);
            m_CallbackSem = new System.Threading.Semaphore(1, 1);
            m_Lock = 0;
        }
Exemple #4
0
        public ER tget_blf(out pointer p_blf, ID mpfid, int blfsz, TMO tmout)
        {
            ER Result = ER.E_NOEXS;
            MemoryPoolFixedsize MemoryPoolFixedsize;

            p_blf = null;

            if (g_Kernel == null)
                return ER.E_DLT;

            g_Kernel.LockCPU();
            try {
                MemoryPoolFixedsize = g_Kernel.Nucleus.GetMemoryPoolFixedsize(mpfid);
                if (MemoryPoolFixedsize == null)
                    Result = ER.E_NOEXS;
                else
                    Result = MemoryPoolFixedsize.GetMemoryBlock(out p_blf, blfsz, tmout);
            }
            finally {
                g_Kernel.UnlockCPU();
            }

            return Result;
        }
Exemple #5
0
        public ER udp_snd_dat(ID cepid, T_IPV4EP p_dstaddr, pointer data, int len, TMO tmout)
        {
            ER Result = ER.E_NOEXS;
            UdpCep UdpCep;

            if ((data == null) || (len <= 0))
                return ER.E_PAR;

            if (g_Kernel == null)
                return ER.E_DLT;

            g_Kernel.LockCPU();
            try {
                UdpCep = g_Kernel.Nucleus.GetUdpCep(cepid);
                if (UdpCep == null)
                    Result = ER.E_NOEXS;
                else
                    Result = UdpCep.SendData(p_dstaddr, data, len, tmout);
            }
            finally {
                g_Kernel.UnlockCPU();
            }

            return Result;
        }
Exemple #6
0
 public abstract void Progress(TMO interval);
Exemple #7
0
        public ER twai_sem(ID semid, TMO tmout)
        {
            ER Result = ER.E_NOEXS;
            Semaphore Semaphore;

            if (g_Kernel == null)
                return ER.E_DLT;

            g_Kernel.LockCPU();
            try {
                Semaphore = g_Kernel.Nucleus.GetSemaphore(semid);
                if (Semaphore == null)
                    Result = ER.E_NOEXS;
                else
                    Result = Semaphore.Wait(tmout);
            }
            finally {
                g_Kernel.UnlockCPU();
            }

            return Result;
        }
Exemple #8
0
        public ER udp6_rcv_dat(ID cepid, T_IPV6EP p_dstaddr, pointer data, int len, TMO tmout)
        {
            ER Result = ER.E_NOEXS;
            Udp6Cep UdpCep;

            if (g_Kernel == null)
                return ER.E_DLT;

            g_Kernel.LockCPU();
            try {
                UdpCep = g_Kernel.Nucleus.GetUdp6Cep(cepid);
                if (UdpCep == null)
                    Result = ER.E_NOEXS;
                else
                    Result = UdpCep.ReceiveData(p_dstaddr, data, len, tmout);
            }
            finally {
                g_Kernel.UnlockCPU();
            }

            return Result;
        }
Exemple #9
0
        public ER tslp_tsk(TMO tmout)
        {
            ER result = ER.E_NOEXS;
            Task task;

            if (g_Kernel == null)
                return ER.E_DLT;

            g_Kernel.LockCPU();
            try {
                task = g_Kernel.Nucleus.GetTask(ID.TSK_SELF);

                if (task == null)
                    result = ER.E_CTX;
                else
                    result = task.Sleep(tmout);
            }
            finally {
                g_Kernel.UnlockCPU();
            }

            return result;
        }
Exemple #10
0
        public ER twai_flg(ref FLGPTN p_flgptn, ID flgid, TMO tmout, FLGPTN waiptn, MODE wfmode)
        {
            ER Result = ER.E_NOEXS;
            EventFlag EventFlag;

            if (g_Kernel == null)
                return ER.E_DLT;

            g_Kernel.LockCPU();
            try {
                EventFlag = g_Kernel.Nucleus.GetEventFlag(flgid);
                if (EventFlag == null)
                    Result = ER.E_NOEXS;
                else
                    Result = EventFlag.WaitEventFlag(ref p_flgptn, tmout, waiptn, wfmode);
            }
            finally {
                g_Kernel.UnlockCPU();
            }

            return Result;
        }
Exemple #11
0
        public ER GetMemoryBlock(out pointer p_blk, int blksz, TMO tmout)
        {
            ER ret;

            p_blk = null;

            //if (p_blk == null)
            //	return ER.E_PAR;

            for (; ; ) {
                TMemNode Node = Allocate(blksz);

                if (Node != null) {
                    p_blk = Node.GetData();
                    break;
                }

                if (tmout == 0)
                    return ER.E_TMOUT;

                Task task = m_Nucleus.GetTask(ID.TSK_SELF);

                if (task == null)
                    return ER.E_CTX;

                task.MemoryBlockSize = blksz;
                ret = task.Wait(m_TskQueue, TSKWAIT.TTW_MPL, m_MplID, tmout);

                switch (ret) {
                case ER.E_OK:
                    continue;
                case ER.E_TMOUT:
                    return ER.E_TMOUT;
                default:
                    return ER.E_RLWAI;
                }
            }
            #if DEBUG
            string lpszFileName = "";
            int nLine = 0;
            _CrtMemBlockHeader.AddBlock(m_pFirstBlock, m_pLastBlock, p_blk, blksz, lpszFileName, nLine);
            m_nBlockCount++;
            #endif
            return ER.E_OK;
        }
Exemple #12
0
        public ER trcv_msg(out T_MSG ppk_msg, ID mbxid, TMO tmout)
        {
            ER Result = ER.E_NOEXS;
            Mailbox Mailbox;

            ppk_msg = null;

            if (g_Kernel == null)
                return ER.E_DLT;

            g_Kernel.LockCPU();
            try {
                Mailbox = g_Kernel.Nucleus.GetMailbox(mbxid);
                if (Mailbox == null)
                    Result = ER.E_NOEXS;
                else
                    Result = Mailbox.ReceiveMessage(out ppk_msg, tmout);
            }
            finally {
                g_Kernel.UnlockCPU();
            }

            return Result;
        }
Exemple #13
0
        public ER tcp_snd_oob(ID cepid, pointer data, int len, TMO tmout)
        {
            ER Result = ER.E_NOEXS;
            TcpCep TcpCep;

            if (g_Kernel == null)
                return ER.E_DLT;

            g_Kernel.LockCPU();
            try {
                TcpCep = g_Kernel.Nucleus.GetTcpCep(cepid);
                if (TcpCep == null)
                    Result = ER.E_NOEXS;
                else
                    Result = TcpCep.SendUrgentData(data, len, tmout);
            }
            finally {
                g_Kernel.UnlockCPU();
            }

            return Result;
        }
Exemple #14
0
        public ER ReceiveMessage(out T_MSG ppk_msg, TMO tmout)
        {
            ER ret;

            ppk_msg = null;

            Task task = m_Nucleus.GetTask(ID.TSK_SELF);

            if ((tmout != 0) && (task == null))
                return ER.E_CTX;

            //if (ppk_msg == null)
            //	return ER.E_PAR;

            if ((m_TskQueue.First == null) && (m_MsgQueue.First != null)) {
                ppk_msg = m_MsgQueue.First.Value;
                m_MsgQueue.RemoveFirst();
            }
            else {
                if (task == null)
                    return ER.E_TMOUT;

                if (tmout == 0)
                    return ER.E_TMOUT;

                ret = task.Wait(m_TskQueue, TSKWAIT.TTW_MBX, m_MbxID, tmout);

                switch (ret) {
                case ER.E_OK:
                    if (m_MsgQueue.First == null)
                        return ER.E_RLWAI;
                    ppk_msg = m_MsgQueue.First.Value;
                    m_MsgQueue.RemoveFirst();
                    break;
                case ER.E_TMOUT:
                    return ER.E_TMOUT;
                default:
                    return ER.E_RLWAI;
                }
            }

            //SetDebugInfo(ppk_msg, lpszFileName, nLine);

            return ER.E_OK;
        }
Exemple #15
0
        public ER tcp_rcv_dat(ID cepid, pointer data, int len, TMO tmout)
        {
            ER Result = ER.E_NOEXS;
            TcpCep TcpCep;

            if (g_Kernel == null)
                return ER.E_DLT;

            g_Kernel.LockCPU();
            try {
                TcpCep = g_Kernel.Nucleus.GetTcpCep(cepid);
                if (TcpCep == null)
                    Result = ER.E_NOEXS;
                else if (tmout == TMO.TMO_NBLK)
                    Result = TcpCep.ReceiveDataNblk(data, len);
                else
                    Result = TcpCep.ReceiveData(data, len, tmout);
            }
            finally {
                g_Kernel.UnlockCPU();
            }

            return Result;
        }
Exemple #16
0
        public ER tcp_rcv_buf(ID cepid, ref pointer p_buf, TMO tmout)
        {
            ER Result = ER.E_NOEXS;
            TcpCep TcpCep;

            if (g_Kernel == null)
                return ER.E_DLT;

            g_Kernel.LockCPU();
            try {
                TcpCep = g_Kernel.Nucleus.GetTcpCep(cepid);
                if (TcpCep == null)
                    Result = ER.E_NOEXS;
                else
                    Result = TcpCep.ReceiveBuffer(ref p_buf, tmout);
            }
            finally {
                g_Kernel.UnlockCPU();
            }

            return Result;
        }
Exemple #17
0
        public ER tcp_con_cep(ID cepid, T_IPV4EP p_myaddr, T_IPV4EP p_dstaddr, TMO tmout)
        {
            ER Result = ER.E_NOEXS;
            TcpCep TcpCep;

            if (p_dstaddr == null)
                return ER.E_PAR;

            if (g_Kernel == null)
                return ER.E_DLT;

            g_Kernel.LockCPU();
            try {
                TcpCep = g_Kernel.Nucleus.GetTcpCep(cepid);
                if (TcpCep == null)
                    Result = ER.E_NOEXS;
                else
                    Result = TcpCep.Connect(p_myaddr, p_dstaddr, tmout);
            }
            finally {
                g_Kernel.UnlockCPU();
            }

            return Result;
        }
Exemple #18
0
        public ER tcp_cls_cep(ID cepid, TMO tmout)
        {
            ER Result = ER.E_NOEXS;
            TcpCep TcpCep;

            if (g_Kernel == null)
                return ER.E_DLT;

            g_Kernel.LockCPU();
            try {
                TcpCep = g_Kernel.Nucleus.GetTcpCep(cepid);
                if (TcpCep == null)
                    Result = ER.E_NOEXS;
                else
                    Result = TcpCep.Close(tmout);
            }
            finally {
                g_Kernel.UnlockCPU();
            }

            return Result;
        }
Exemple #19
0
        public ER WaitEventFlag(ref FLGPTN p_flgptn, TMO tmout, FLGPTN waiptn, MODE wfmode)
        {
            ER ret;

            Task task = m_Nucleus.GetTask(ID.TSK_SELF);

            if ((tmout != 0) && (task == null))
                return ER.E_CTX;

            //if (p_flgptn == null)
            //	return ER.E_PAR;

            if ((wfmode & ~(MODE.TWF_ANDW | MODE.TWF_ORW | MODE.TWF_CLR)) != 0)
                return ER.E_PAR;

            if ((m_TskQueue.First == null) && CheckPattern(waiptn, wfmode)) {
                p_flgptn = m_FlagPattern;
                if ((wfmode & MODE.TWF_CLR) != 0)
                    m_FlagPattern = 0;
            }
            else {
                if (task == null)
                    return ER.E_TMOUT;

                if (tmout == 0)
                    return ER.E_TMOUT;

                task.WaitPattern = waiptn;
                task.WaitMode = wfmode;
                ret = task.Wait(m_TskQueue, TSKWAIT.TTW_FLG, m_FlgID, tmout);

                switch (ret) {
                case ER.E_OK:
                    p_flgptn = m_FlagPattern;
                    if (!CheckPattern(waiptn, wfmode))
                        return ER.E_RLWAI;
                    if ((wfmode & MODE.TWF_CLR) != 0)
                        m_FlagPattern = 0;
                    break;
                case ER.E_TMOUT:
                    return ER.E_TMOUT;
                default:
                    return ER.E_RLWAI;
                }
            }

            return ER.E_OK;
        }
Exemple #20
0
        public ER Wait(TMO tmout)
        {
            ER ret;

            Task task = m_Nucleus.GetTask(ID.TSK_SELF);

            if ((tmout != 0) && (task == null))
                return ER.E_CTX;

            m_Count--;

            if (m_Count < 0) {
                if (tmout == 0) {
                    m_Count++;
                    return ER.E_TMOUT;
                }

                ret = task.Wait(m_TskQueue, TSKWAIT.TTW_SEM, m_SemID, tmout);

                switch (ret) {
                case ER.E_OK:
                    return ER.E_OK;
                case ER.E_TMOUT:
                    m_Count++;
                    return ER.E_TMOUT;
                default:
                    return ER.E_RLWAI;
                }
            }

            return ER.E_OK;
        }
Exemple #21
0
        public ER tget_blk(out pointer p_blk, ID mplid, int blksz, TMO tmout)
        {
            ER Result = ER.E_NOEXS;
            MemoryPool MemoryPool;

            p_blk = null;

            if (g_Kernel == null)
                return ER.E_DLT;

            g_Kernel.LockCPU();
            try {
                MemoryPool = g_Kernel.Nucleus.GetMemoryPool(mplid);
                if (MemoryPool == null)
                    Result = ER.E_NOEXS;
                else
                    Result = MemoryPool.GetMemoryBlock(out p_blk, blksz, tmout);
            }
            finally {
                g_Kernel.UnlockCPU();
            }

            return Result;
        }