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 19:14:51 -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 11I34NcI028476; Wed, 17 Feb 2021 22:05:10 -0500 Received: from outgoing-exchange-7.mit.edu (OUTGOING-EXCHANGE-7.MIT.EDU [18.9.28.58]) by PCH.mit.edu (8.14.7/8.12.8) with ESMTP id 11I34LO6028473 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Wed, 17 Feb 2021 22:04:22 -0500 Received: from oc11exedge2.exchange.mit.edu (OC11EXEDGE2.EXCHANGE.MIT.EDU [18.9.3.18]) by outgoing-exchange-7.mit.edu (8.14.7/8.12.4) with ESMTP id 11I34EiJ029292 for ; Wed, 17 Feb 2021 22:04:21 -0500 Received: from w92exhyb8.exchange.mit.edu (18.7.71.113) by oc11exedge2.exchange.mit.edu (18.9.3.18) with Microsoft SMTP Server (TLS) id 15.0.1293.2; Wed, 17 Feb 2021 22:04:04 -0500 Received: from oc11exhyb7.exchange.mit.edu (18.9.1.112) by w92exhyb8.exchange.mit.edu (18.7.71.113) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Wed, 17 Feb 2021 22:04:10 -0500 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (104.47.55.108) by oc11exhyb7.exchange.mit.edu (18.9.1.112) with Microsoft SMTP Server (TLS) id 15.0.1395.4 via Frontend Transport; Wed, 17 Feb 2021 22:04:10 -0500 Received: from BN6PR22CA0070.namprd22.prod.outlook.com (2603:10b6:404:ca::32) by BY5PR01MB5634.prod.exchangelabs.com (2603:10b6:a03:1ae::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3846.25; Thu, 18 Feb 2021 03:04:08 +0000 Received: from BN8NAM11FT054.eop-nam11.prod.protection.outlook.com (2603:10b6:404:ca:cafe::fb) by BN6PR22CA0070.outlook.office365.com (2603:10b6:404:ca::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3868.27 via Frontend Transport; Thu, 18 Feb 2021 03:04:07 +0000 Received: from mailscanner.virtbiz.com (208.80.15.114) by BN8NAM11FT054.mail.protection.outlook.com (10.13.177.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3868.27 via Frontend Transport; Thu, 18 Feb 2021 03:04:07 +0000 Received: from s18855546.onlinehome-server.com (s18855546.onlinehome-server.com [74.208.193.200]) by mailscanner.virtbiz.com (8.14.7/8.14.7) with ESMTP id 11I33wFv018917 for ; Wed, 17 Feb 2021 21:04:05 -0600 Received: from mai.hallikainen.org (localhost [127.0.0.1]) by s18855546.onlinehome-server.com (8.14.4/8.14.4) with ESMTP id 11I33rab000534 for ; Wed, 17 Feb 2021 19:03:53 -0800 Received: (from apache@localhost) by mai.hallikainen.org (8.14.4/8.14.4/Submit) id 11I33rAv000531; Wed, 17 Feb 2021 19:03:53 -0800 Received: from 174.16.109.119 (SquirrelMail authenticated user harold) by mai.hallikainen.org with HTTP; Wed, 17 Feb 2021 19:03:53 -0800 From: Harold Hallikainen To: Microcontroller discussion list - Public. Sender: "piclist-bounces@mit.edu" Date: Wed, 17 Feb 2021 19:03:53 -0800 Subject: Re: [EE]:: Simple Task Scheduler written in C Thread-Topic: [EE]:: Simple Task Scheduler written in C Thread-Index: AdcFpDjNzqPIc2W7S5KNUXaqfJ6xSw== Message-ID: References: <475a577b94f666c787f1b28acc17d044.squirrel@mai.hallikainen.org> List-Help: List-Subscribe: , List-Unsubscribe: , In-Reply-To: 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: Pass (protection.outlook.com: domain of mai.hallikainen.org designates 208.80.15.114 as permitted sender) receiver=protection.outlook.com; client-ip=208.80.15.114; helo=mailscanner.virtbiz.com; 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=O8Gs8Ae7ApV2RsbcZQPniQtLbZjIp7oapAUmN2vdSpo=; b=ZBhqstp6yeuycAYBZHBylJqfuc2JhqpLgGb4W7/t04TePHfO+sa+d3jhF+zohXX9tVTu0ACcfbfFLVPbneY/tzPe5ksj/w9w0UVNzY60E0Hgg39wrVpFyvKhjn1MeqtcpwS3U10W7eUMiz+/7SESfjbpAprJb1G2sCEmldt0DQs= authentication-results: spf=pass (sender IP is 208.80.15.114) smtp.mailfrom=mai.hallikainen.org; mit.edu; dkim=none (message not signed) header.d=none;mit.edu; dmarc=permerror action=none header.from=mai.hallikainen.org; user-agent: SquirrelMail/1.4.22-5.el6 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-authentication-warning: mai.hallikainen.org: apache set sender to harold@mai.hallikainen.org using -f x-spam-status: No x-greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mailscanner.virtbiz.com [208.77.216.252]); Wed, 17 Feb 2021 21:04:05 -0600 (CST) x-topics: [EE] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Reminds me of something I wrote a LONG time ago! http://www.piclist.com/techref/microchip/language/c/MultiTask.c.htm Harold > > oops! hit the wrong key :-) > > here's the code: > > .data > > alt_task_pc: .dsw 1 > tmp_bl: .dsw 1 > > yield .macro arg > > movf arg+0,w > movwf tmp_bl+0 > movf arg+1,w > movwf tmp_bl+1 > > ; <<<< this is the really really important trick!!! > ; use the assembler to generate the return address > ; not an instruction such as "call" > > movlw ($+8) & 0xff ; low (addr of "lab9") > movwf arg+0 > movlw (($+8) >> 8) & 0xff ; high (addr of "lab9") > movwf arg+1 > > movf tmp_bl+1,w > movwf PCLATH > movf tmp_bl+0,w > movwf PCL > > ; lab9 > > .endm > > > new_task .macro arg1, arg2 > > movlw (arg2) & 0xff ; low (addr of "task") > movwf arg1+0 > movlw ((arg2) >> 8) & 0xff ; high (addr of "task") > movwf arg1+1 > > .endm > > ;=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > > ; example of use > > .code > > main: > new_task alt_task_pc, task2 > > lab1_1: > > ; do task1 stuff > > yield alt_task_pc > > ; do more task2 stuff > > yield alt_task_pc > > goto lab1 > > ;=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > > task2: > > lab2_1 > ; do task2 stuff > > yield alt_task_pc > > ; do more task2 stuff > > yield alt_task_pc > > goto lab2_1 > > > -- > http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist > --=20 FCC Rules Updated Daily at http://www.hallikainen.com Not sent from an iPhone. --=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 .