From b470b87e694865bd8f209b78edc48c4ec15cac51 Mon Sep 17 00:00:00 2001 From: idgay Date: Thu, 8 Feb 2007 17:49:05 +0000 Subject: [PATCH] arbitrate a parameterised Read interface and forward requests to a single Read interface (contrast with ArbitratedReadC) --- tos/system/MultiplexedReadC.nc | 46 ++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 tos/system/MultiplexedReadC.nc diff --git a/tos/system/MultiplexedReadC.nc b/tos/system/MultiplexedReadC.nc new file mode 100644 index 00000000..97a6c8f0 --- /dev/null +++ b/tos/system/MultiplexedReadC.nc @@ -0,0 +1,46 @@ +/* $Id$ + * Copyright (c) 2005 Intel Corporation + * All rights reserved. + * + * This file is distributed under the terms in the attached INTEL-LICENSE + * file. If you do not find these files, copies can be found by writing to + * Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA, + * 94704. Attention: Intel License Inquiry. + */ +/** + * Multiplex access to a single Read interface for a parameterised + * Read interface whose access is controlled by an arbiter. + * + * @param width_t Width of the underlying Read interface. + * + * @author David Gay + */ +generic module MultiplexedReadC(typedef width_t) { + provides interface Read[uint8_t client]; + uses { + interface Read as Service; + interface Resource[uint8_t client]; + } +} +implementation { + command error_t Read.read[uint8_t client]() { + return call Resource.request[client](); + } + + event void Resource.granted[uint8_t client]() { + call Service.read(); + } + + event void Service.readDone(error_t result, width_t data) { + uint8_t client = call ArbiterInfo.userId(); + + call Resource.release[client](); + signal Read.readDone[client](result, data); + } + + default async command error_t Resource.request[uint8_t client]() { + return FAIL; + } + default async command error_t Resource.release[uint8_t client]() { return FAIL; } + default event void Read.readDone[uint8_t client](error_t result, width_t data) { } +} -- 2.39.2