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:14:43 -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 11HL6DYe025989; Wed, 17 Feb 2021 16:06:42 -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 11HL6Bfc025983 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Wed, 17 Feb 2021 16:06:11 -0500 Received: from oc11exedge1.exchange.mit.edu (OC11EXEDGE1.EXCHANGE.MIT.EDU [18.9.3.17]) by outgoing-exchange-1.mit.edu (8.14.7/8.12.4) with ESMTP id 11HL64Jo012850 for ; Wed, 17 Feb 2021 16:06:11 -0500 Received: from w92expo16.exchange.mit.edu (18.7.74.70) by oc11exedge1.exchange.mit.edu (18.9.3.17) with Microsoft SMTP Server (TLS) id 15.0.1293.2; Wed, 17 Feb 2021 16:05:48 -0500 Received: from oc11exhyb8.exchange.mit.edu (18.9.1.113) by w92expo16.exchange.mit.edu (18.7.74.70) with Microsoft SMTP Server (TLS) id 15.0.1365.1; Wed, 17 Feb 2021 16:06:00 -0500 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (104.47.55.170) by oc11exhyb8.exchange.mit.edu (18.9.1.113) with Microsoft SMTP Server (TLS) id 15.0.1395.4 via Frontend Transport; Wed, 17 Feb 2021 16:06:00 -0500 Received: from BN6PR13CA0041.namprd13.prod.outlook.com (2603:10b6:404:13e::27) by CO2PR01MB2023.prod.exchangelabs.com (2603:10b6:102:6::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3846.42; Wed, 17 Feb 2021 21:05:59 +0000 Received: from BN8NAM11FT050.eop-nam11.prod.protection.outlook.com (2603:10b6:404:13e:cafe::5) by BN6PR13CA0041.outlook.office365.com (2603:10b6:404:13e::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3868.11 via Frontend Transport; Wed, 17 Feb 2021 21:05:59 +0000 Received: from nickel.allotrope.net (82.69.45.61) by BN8NAM11FT050.mail.protection.outlook.com (10.13.177.5) with Microsoft SMTP Server id 15.20.3868.27 via Frontend Transport; Wed, 17 Feb 2021 21:05:58 +0000 Received: by nickel.allotrope.net (Postfix, from userid 1001) id 789904AB45E; Wed, 17 Feb 2021 21:00:18 +0000 (GMT) Received: from localhost (localhost [127.0.0.1]) by nickel.allotrope.net (Postfix) with ESMTP id 7221D4AB439 for ; Wed, 17 Feb 2021 21:00:18 +0000 (GMT) From: sergio To: Microcontroller discussion list - Public. Sender: "piclist-bounces@mit.edu" Date: Wed, 17 Feb 2021 13:00:18 -0800 Subject: Re: [EE]:: Simple Task Scheduler written in C Thread-Topic: [EE]:: Simple Task Scheduler written in C Thread-Index: AdcFcemhmJqultlpTRKwtVXk7nqQSA== 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=HYi8k60lo4D9HWoM1DLYYX+sh+0zgzpEcH3WGM8y4oA=; b=UyGiwUB8j+HnWpa2qKz1kle7t1MtJHnFGePuNuxX33DcviUUjsSVsQaHNriID1t/doSJUw4TU650If6AcWmxX3iAck/Tx2EZ/BzvwOYpqwvAWHksmbhtkR3d9dNSu1+LzUzcIViO9AWRqVOMOS/rGqk/oJCMBcVhNXhTrzMhtHI= 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 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 --=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 .