Received: from PCH.mit.edu (18.7.21.50) by mail.efplus.com (192.168.0.8) with Microsoft SMTP Server (TLS) id 8.3.485.1; Wed, 17 Feb 2021 13:13:46 -0800 Received: from PCH.MIT.EDU (localhost.localdomain [127.0.0.1]) by PCH.mit.edu (8.14.7/8.12.8) with ESMTP id 11HL3efB025528; Wed, 17 Feb 2021 16:04:20 -0500 Received: from outgoing-exchange-1.mit.edu (OUTGOING-EXCHANGE-1.MIT.EDU [18.9.28.15]) by PCH.mit.edu (8.14.7/8.12.8) with ESMTP id 11HL3chq025521 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Wed, 17 Feb 2021 16:03:39 -0500 Received: from w92exedge4.exchange.mit.edu (W92EXEDGE4.EXCHANGE.MIT.EDU [18.7.73.16]) by outgoing-exchange-1.mit.edu (8.14.7/8.12.4) with ESMTP id 11HL3MHF012672 for ; Wed, 17 Feb 2021 16:03:38 -0500 Received: from w92expo8.exchange.mit.edu (18.7.74.62) by w92exedge4.exchange.mit.edu (18.7.73.16) with Microsoft SMTP Server (TLS) id 15.0.1293.2; Wed, 17 Feb 2021 16:03:10 -0500 Received: from oc11exhyb5.exchange.mit.edu (18.9.1.110) by w92expo8.exchange.mit.edu (18.7.74.62) with Microsoft SMTP Server (TLS) id 15.0.1365.1; Wed, 17 Feb 2021 16:03:24 -0500 Received: from NAM04-BN3-obe.outbound.protection.outlook.com (104.47.46.55) by oc11exhyb5.exchange.mit.edu (18.9.1.110) with Microsoft SMTP Server (TLS) id 15.0.1395.4 via Frontend Transport; Wed, 17 Feb 2021 16:03:24 -0500 Received: from MW4PR03CA0143.namprd03.prod.outlook.com (2603:10b6:303:8c::28) by SN6PR01MB4877.prod.exchangelabs.com (2603:10b6:805:d4::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3846.39; Wed, 17 Feb 2021 21:03:23 +0000 Received: from CO1NAM11FT037.eop-nam11.prod.protection.outlook.com (2603:10b6:303:8c:cafe::c5) by MW4PR03CA0143.outlook.office365.com (2603:10b6:303:8c::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3868.27 via Frontend Transport; Wed, 17 Feb 2021 21:03:21 +0000 Received: from nickel.allotrope.net (82.69.45.61) by CO1NAM11FT037.mail.protection.outlook.com (10.13.174.91) with Microsoft SMTP Server id 15.20.3868.27 via Frontend Transport; Wed, 17 Feb 2021 21:03:19 +0000 Received: by nickel.allotrope.net (Postfix, from userid 1001) id 08B604AB45E; Wed, 17 Feb 2021 20:57:39 +0000 (GMT) Received: from localhost (localhost [127.0.0.1]) by nickel.allotrope.net (Postfix) with ESMTP id 021F04AB439 for ; Wed, 17 Feb 2021 20:57:38 +0000 (GMT) From: sergio To: Microcontroller discussion list - Public. Sender: "piclist-bounces@mit.edu" Date: Wed, 17 Feb 2021 12:57:38 -0800 Subject: Re: [EE]:: Simple Task Scheduler written in C Thread-Topic: [EE]:: Simple Task Scheduler written in C Thread-Index: AdcFccesJ2MGBHWuQfuWd8kCJe9/LA== Message-ID: References: <475a577b94f666c787f1b28acc17d044.squirrel@mai.hallikainen.org> List-Help: List-Subscribe: , List-Unsubscribe: , In-Reply-To: <475a577b94f666c787f1b28acc17d044.squirrel@mai.hallikainen.org> Reply-To: Microcontroller discussion list - Public. Accept-Language: en-US X-MS-Exchange-Organization-AuthAs: Anonymous X-MS-Exchange-Organization-AuthSource: TS500.efplus4.local X-MS-Has-Attach: X-Auto-Response-Suppress: All X-MS-Exchange-Organization-SenderIdResult: Pass X-MS-Exchange-Organization-PRD: mit.edu X-MS-TNEF-Correlator: received-spf: None (protection.outlook.com: allotrope.net does not designate permitted sender hosts) dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mitprod.onmicrosoft.com; s=selector2-mitprod-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=zqo6faEhmuUHJlQL0//Z6GLsjsZ/8lNFZ7owSjNrAts=; b=rM765XZUKmEfB7BHhCXN0hnMQ5geZmkcgeenlO4g3tjlgkrKcXyFNO2VBR0l2pJUx30qusW6yvLNSaOb3+d7c+8NprhK8eMCWRl+Red73jxe/qmvxvPzW4ZqEWuCH/tkPFFQvd5Ko25/8KsiLJNxGWlj+IeZT3PZFEojbBczrkc= authentication-results: spf=none (sender IP is 82.69.45.61) smtp.mailfrom=allotrope.net; mit.edu; dkim=none (message not signed) header.d=none; mit.edu; dmarc=none action=none header.from=allotrope.net; user-agent: Alpine 2.21.9999 (BSF 287 2018-06-16) errors-to: piclist-bounces@mit.edu list-id: "Microcontroller discussion list - Public." list-post: x-beenthere: piclist@mit.edu x-mailman-version: 2.1.6 x-topics: [EE] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 On Tue, 16 Feb 2021, Harold Hallikainen wrote: > Thanks for posting! I've really gotten use to just using state machines > with switch/case statements. Each "task" has an input FIFO that other > tasks can dump complete messages into. When the main loop calls a task, i= t > immediately returns if there is nothing in its input FIFO. If there is > something there, it acts on each message, generally outputting to other > task input FIFOs. Not preemptive, but simple! If needed, priority of a > task can be increased by putting it in the main loop more than once. Hi Harold, I respect your use of state machines (see my own use if you have the=20 slightest doubt :-)), however I think you might be interested in the=20 following. It is a simple implementation of co-routines (cooperative=20 multitasking) for the PIC16. BEWARE you cannot call yield from inside a subroutine that has been called= =20 via the hardware "call" instruction. BUT there is nothing to create your=20 own calling mechanism that circumvents the "call" instruction which is=20 itself similar to the "yield" macro. I do something similar to this within the XCSB compiler. Regards Sergio Masci --=20 http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .