From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24570 invoked by alias); 18 Jun 2012 14:34:59 -0000 Received: (qmail 24395 invoked by uid 22791); 18 Jun 2012 14:34:57 -0000 X-SWARE-Spam-Status: No, hits=-0.9 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,KHOP_THREADED,RCVD_IN_DNSWL_NONE,RCVD_IN_HOSTKARMA_YE,TW_EV X-Spam-Check-By: sourceware.org Received: from elasmtp-masked.atl.sa.earthlink.net (HELO elasmtp-masked.atl.sa.earthlink.net) (209.86.89.68) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 18 Jun 2012 14:34:44 +0000 Received: from [70.16.212.165] (helo=[192.168.0.5]) by elasmtp-masked.atl.sa.earthlink.net with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.67) (envelope-from ) id 1Sgd2R-0005BW-LI for ecos-devel@ecos.sourceware.org; Mon, 18 Jun 2012 10:34:43 -0400 Message-ID: <4FDF3C83.6050102@mindspring.com> Date: Mon, 18 Jun 2012 14:34:00 -0000 From: Frank Pagliughi User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.24) Gecko/20111108 Fedora/3.1.16-1.fc14 Lightning/1.0b2 Thunderbird/3.1.16 MIME-Version: 1.0 To: eCos Subject: Re: Closing devices References: <4FD7374A.1090602@kuantic.com> <4FDF355B.2010209@mindspring.com> In-Reply-To: <4FDF355B.2010209@mindspring.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-ELNK-Trace: 4d82f965df0f6dd9e3f977c6d1ea408f0a9da525759e2654dc27e47cf2545483a3ed48b3a72f7acbc6b317bf5bc479bb350badd9bab72f9c350badd9bab72f9c X-IsSubscribed: yes Mailing-List: contact ecos-devel-help@ecos.sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: ecos-devel-owner@ecos.sourceware.org X-SW-Source: 2012-06/txt/msg00008.txt.bz2 Hello All, I'm looking for ideas on how to close and re-open devices on eCos. The needs for this are (1) to support swappable/removable devices, (2) to have a consistent way to put devices into a low-power state when they are not being used, and (3) to prevent devices from using the CPU when they are not needed. On a current project for a battery-powered device, I have a need for all of this: a CompactFlash that can be removed; a GPS that sends data constantly, but only needs to be read once every few hours; and many of the peripherals need to be put in a consistent state prior to going into a low power mode. I've been able to accomplish all of this with ugly application-level code, but thought that a much better solution would be to propagate the close() call of a devfs device down to the driver, so you could do this: while (true) { int fd = open("/dev/ser0", O_RDONLY); read(fd, buf, BUF_LEN); // power down the port close(fd); sleep(60); } I think this can be done pretty easily by adding a "shutdown" function to the devtab entries: typedef struct cyg_devtab_entry { // ... Cyg_ErrNo (*lookup)(struct cyg_devtab_entry **tab, struct cyg_devtab_entry *sub_tab, const char *name); Cyg_ErrNo (*shutdown)(struct cyg_devtab_entry *tab); // ... } CYG_HAL_TABLE_TYPE cyg_devtab_entry_t; The existing macros CHAR_DEVTAB_ENTRY, BLOCK_DEVTAB_ENTRY, etc, can just insert an empty function into the shutdown slot, whereas a new set of macros can accept the shutdown pointer: #define CHAR_CLOSABLE_DEVTAB_ENTRY(_l,_name,_dep_name,_handlers,_init,_lookup,_shutdown,_priv) ... #define BLOCK_CLOSABLE_DEVTAB_ENTRY(_l,_name,_dep_name,_handlers,_init,_lookup,_shutdown,_priv) ... The assumption is that anything done in the shutdown would be undone in a subsequent lookup so that the devices could bre closed then re-opened, and that the shutdown would mark the entry as "unavailable": tab->status &= ~CYG_DEVTAB_STATUS_AVAIL; Assuming that this is a good way to handle this I would need to know how to hook this into the upper-level device and file operations. What would be needed? Thanks, Frank