B.3 : THE 6 HOUR PROGRAM WITH 1 PPS SIGNAL THE MASTER TO BE CONNECTED TO 11 PIN.

Dependencies:   mbed

Committer:
manujose
Date:
Tue Dec 14 23:26:02 2010 +0000
Revision:
1:9efda6a3f83c
Parent:
0:e6964ff1bbcc
hello

Who changed what in which revision?

UserRevisionLine numberNew contents of line
manujose 0:e6964ff1bbcc 1 /*
manujose 0:e6964ff1bbcc 2 * Copyright (c) 2004-2005, Swedish Institute of Computer Science.
manujose 0:e6964ff1bbcc 3 * All rights reserved.
manujose 0:e6964ff1bbcc 4 *
manujose 0:e6964ff1bbcc 5 * Redistribution and use in source and binary forms, with or without
manujose 0:e6964ff1bbcc 6 * modification, are permitted provided that the following conditions
manujose 0:e6964ff1bbcc 7 * are met:
manujose 0:e6964ff1bbcc 8 * 1. Redistributions of source code must retain the above copyright
manujose 0:e6964ff1bbcc 9 * notice, this list of conditions and the following disclaimer.
manujose 0:e6964ff1bbcc 10 * 2. Redistributions in binary form must reproduce the above copyright
manujose 0:e6964ff1bbcc 11 * notice, this list of conditions and the following disclaimer in the
manujose 0:e6964ff1bbcc 12 * documentation and/or other materials provided with the distribution.
manujose 0:e6964ff1bbcc 13 * 3. Neither the name of the Institute nor the names of its contributors
manujose 0:e6964ff1bbcc 14 * may be used to endorse or promote products derived from this software
manujose 0:e6964ff1bbcc 15 * without specific prior written permission.
manujose 0:e6964ff1bbcc 16 *
manujose 0:e6964ff1bbcc 17 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
manujose 0:e6964ff1bbcc 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
manujose 0:e6964ff1bbcc 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
manujose 0:e6964ff1bbcc 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
manujose 0:e6964ff1bbcc 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
manujose 0:e6964ff1bbcc 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
manujose 0:e6964ff1bbcc 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
manujose 0:e6964ff1bbcc 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
manujose 0:e6964ff1bbcc 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
manujose 0:e6964ff1bbcc 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
manujose 0:e6964ff1bbcc 27 * SUCH DAMAGE.
manujose 0:e6964ff1bbcc 28 *
manujose 0:e6964ff1bbcc 29 * This file is part of the Contiki operating system.
manujose 0:e6964ff1bbcc 30 *
manujose 0:e6964ff1bbcc 31 * Author: Adam Dunkels <adam@sics.se>
manujose 0:e6964ff1bbcc 32 *
manujose 0:e6964ff1bbcc 33 * $Id: pt.h,v 1.7 2006/10/02 07:52:56 adam Exp $
manujose 0:e6964ff1bbcc 34 */
manujose 0:e6964ff1bbcc 35
manujose 0:e6964ff1bbcc 36 /**
manujose 0:e6964ff1bbcc 37 * \addtogroup pt
manujose 0:e6964ff1bbcc 38 * @{
manujose 0:e6964ff1bbcc 39 */
manujose 0:e6964ff1bbcc 40
manujose 0:e6964ff1bbcc 41 /**
manujose 0:e6964ff1bbcc 42 * \file
manujose 0:e6964ff1bbcc 43 * Protothreads implementation.
manujose 0:e6964ff1bbcc 44 * \author
manujose 0:e6964ff1bbcc 45 * Adam Dunkels <adam@sics.se>
manujose 0:e6964ff1bbcc 46 *
manujose 0:e6964ff1bbcc 47 */
manujose 0:e6964ff1bbcc 48
manujose 0:e6964ff1bbcc 49 #ifndef __PT_H__
manujose 0:e6964ff1bbcc 50 #define __PT_H__
manujose 0:e6964ff1bbcc 51
manujose 0:e6964ff1bbcc 52 #include "lc.h"
manujose 0:e6964ff1bbcc 53
manujose 0:e6964ff1bbcc 54 struct pt {
manujose 0:e6964ff1bbcc 55 lc_t lc;
manujose 0:e6964ff1bbcc 56 };
manujose 0:e6964ff1bbcc 57
manujose 0:e6964ff1bbcc 58 #define PT_WAITING 0
manujose 0:e6964ff1bbcc 59 #define PT_YIELDED 1
manujose 0:e6964ff1bbcc 60 #define PT_EXITED 2
manujose 0:e6964ff1bbcc 61 #define PT_ENDED 3
manujose 0:e6964ff1bbcc 62
manujose 0:e6964ff1bbcc 63 /**
manujose 0:e6964ff1bbcc 64 * \name Initialization
manujose 0:e6964ff1bbcc 65 * @{
manujose 0:e6964ff1bbcc 66 */
manujose 0:e6964ff1bbcc 67
manujose 0:e6964ff1bbcc 68 /**
manujose 0:e6964ff1bbcc 69 * Initialize a protothread.
manujose 0:e6964ff1bbcc 70 *
manujose 0:e6964ff1bbcc 71 * Initializes a protothread. Initialization must be done prior to
manujose 0:e6964ff1bbcc 72 * starting to execute the protothread.
manujose 0:e6964ff1bbcc 73 *
manujose 0:e6964ff1bbcc 74 * \param pt A pointer to the protothread control structure.
manujose 0:e6964ff1bbcc 75 *
manujose 0:e6964ff1bbcc 76 * \sa PT_SPAWN()
manujose 0:e6964ff1bbcc 77 *
manujose 0:e6964ff1bbcc 78 * \hideinitializer
manujose 0:e6964ff1bbcc 79 */
manujose 0:e6964ff1bbcc 80 #define PT_INIT(pt) LC_INIT((pt)->lc)
manujose 0:e6964ff1bbcc 81
manujose 0:e6964ff1bbcc 82 /** @} */
manujose 0:e6964ff1bbcc 83
manujose 0:e6964ff1bbcc 84 /**
manujose 0:e6964ff1bbcc 85 * \name Declaration and definition
manujose 0:e6964ff1bbcc 86 * @{
manujose 0:e6964ff1bbcc 87 */
manujose 0:e6964ff1bbcc 88
manujose 0:e6964ff1bbcc 89 /**
manujose 0:e6964ff1bbcc 90 * Declaration of a protothread.
manujose 0:e6964ff1bbcc 91 *
manujose 0:e6964ff1bbcc 92 * This macro is used to declare a protothread. All protothreads must
manujose 0:e6964ff1bbcc 93 * be declared with this macro.
manujose 0:e6964ff1bbcc 94 *
manujose 0:e6964ff1bbcc 95 * \param name_args The name and arguments of the C function
manujose 0:e6964ff1bbcc 96 * implementing the protothread.
manujose 0:e6964ff1bbcc 97 *
manujose 0:e6964ff1bbcc 98 * \hideinitializer
manujose 0:e6964ff1bbcc 99 */
manujose 0:e6964ff1bbcc 100 #define PT_THREAD(name_args) char name_args
manujose 0:e6964ff1bbcc 101
manujose 0:e6964ff1bbcc 102 /**
manujose 0:e6964ff1bbcc 103 * Declare the start of a protothread inside the C function
manujose 0:e6964ff1bbcc 104 * implementing the protothread.
manujose 0:e6964ff1bbcc 105 *
manujose 0:e6964ff1bbcc 106 * This macro is used to declare the starting point of a
manujose 0:e6964ff1bbcc 107 * protothread. It should be placed at the start of the function in
manujose 0:e6964ff1bbcc 108 * which the protothread runs. All C statements above the PT_BEGIN()
manujose 0:e6964ff1bbcc 109 * invokation will be executed each time the protothread is scheduled.
manujose 0:e6964ff1bbcc 110 *
manujose 0:e6964ff1bbcc 111 * \param pt A pointer to the protothread control structure.
manujose 0:e6964ff1bbcc 112 *
manujose 0:e6964ff1bbcc 113 * \hideinitializer
manujose 0:e6964ff1bbcc 114 */
manujose 0:e6964ff1bbcc 115 #define PT_BEGIN(pt) { char PT_YIELD_FLAG = 1; LC_RESUME((pt)->lc)
manujose 0:e6964ff1bbcc 116
manujose 0:e6964ff1bbcc 117 /**
manujose 0:e6964ff1bbcc 118 * Declare the end of a protothread.
manujose 0:e6964ff1bbcc 119 *
manujose 0:e6964ff1bbcc 120 * This macro is used for declaring that a protothread ends. It must
manujose 0:e6964ff1bbcc 121 * always be used together with a matching PT_BEGIN() macro.
manujose 0:e6964ff1bbcc 122 *
manujose 0:e6964ff1bbcc 123 * \param pt A pointer to the protothread control structure.
manujose 0:e6964ff1bbcc 124 *
manujose 0:e6964ff1bbcc 125 * \hideinitializer
manujose 0:e6964ff1bbcc 126 */
manujose 0:e6964ff1bbcc 127 #define PT_END(pt) LC_END((pt)->lc); PT_YIELD_FLAG = 0; \
manujose 0:e6964ff1bbcc 128 PT_INIT(pt); return PT_ENDED; }
manujose 0:e6964ff1bbcc 129
manujose 0:e6964ff1bbcc 130 /** @} */
manujose 0:e6964ff1bbcc 131
manujose 0:e6964ff1bbcc 132 /**
manujose 0:e6964ff1bbcc 133 * \name Blocked wait
manujose 0:e6964ff1bbcc 134 * @{
manujose 0:e6964ff1bbcc 135 */
manujose 0:e6964ff1bbcc 136
manujose 0:e6964ff1bbcc 137 /**
manujose 0:e6964ff1bbcc 138 * Block and wait until condition is true.
manujose 0:e6964ff1bbcc 139 *
manujose 0:e6964ff1bbcc 140 * This macro blocks the protothread until the specified condition is
manujose 0:e6964ff1bbcc 141 * true.
manujose 0:e6964ff1bbcc 142 *
manujose 0:e6964ff1bbcc 143 * \param pt A pointer to the protothread control structure.
manujose 0:e6964ff1bbcc 144 * \param condition The condition.
manujose 0:e6964ff1bbcc 145 *
manujose 0:e6964ff1bbcc 146 * \hideinitializer
manujose 0:e6964ff1bbcc 147 */
manujose 0:e6964ff1bbcc 148 #define PT_WAIT_UNTIL(pt, condition) \
manujose 0:e6964ff1bbcc 149 do { \
manujose 0:e6964ff1bbcc 150 LC_SET((pt)->lc); \
manujose 0:e6964ff1bbcc 151 if(!(condition)) { \
manujose 0:e6964ff1bbcc 152 return PT_WAITING; \
manujose 0:e6964ff1bbcc 153 } \
manujose 0:e6964ff1bbcc 154 } while(0)
manujose 0:e6964ff1bbcc 155
manujose 0:e6964ff1bbcc 156 /**
manujose 0:e6964ff1bbcc 157 * Block and wait while condition is true.
manujose 0:e6964ff1bbcc 158 *
manujose 0:e6964ff1bbcc 159 * This function blocks and waits while condition is true. See
manujose 0:e6964ff1bbcc 160 * PT_WAIT_UNTIL().
manujose 0:e6964ff1bbcc 161 *
manujose 0:e6964ff1bbcc 162 * \param pt A pointer to the protothread control structure.
manujose 0:e6964ff1bbcc 163 * \param cond The condition.
manujose 0:e6964ff1bbcc 164 *
manujose 0:e6964ff1bbcc 165 * \hideinitializer
manujose 0:e6964ff1bbcc 166 */
manujose 0:e6964ff1bbcc 167 #define PT_WAIT_WHILE(pt, cond) PT_WAIT_UNTIL((pt), !(cond))
manujose 0:e6964ff1bbcc 168
manujose 0:e6964ff1bbcc 169 /** @} */
manujose 0:e6964ff1bbcc 170
manujose 0:e6964ff1bbcc 171 /**
manujose 0:e6964ff1bbcc 172 * \name Hierarchical protothreads
manujose 0:e6964ff1bbcc 173 * @{
manujose 0:e6964ff1bbcc 174 */
manujose 0:e6964ff1bbcc 175
manujose 0:e6964ff1bbcc 176 /**
manujose 0:e6964ff1bbcc 177 * Block and wait until a child protothread completes.
manujose 0:e6964ff1bbcc 178 *
manujose 0:e6964ff1bbcc 179 * This macro schedules a child protothread. The current protothread
manujose 0:e6964ff1bbcc 180 * will block until the child protothread completes.
manujose 0:e6964ff1bbcc 181 *
manujose 0:e6964ff1bbcc 182 * \note The child protothread must be manually initialized with the
manujose 0:e6964ff1bbcc 183 * PT_INIT() function before this function is used.
manujose 0:e6964ff1bbcc 184 *
manujose 0:e6964ff1bbcc 185 * \param pt A pointer to the protothread control structure.
manujose 0:e6964ff1bbcc 186 * \param thread The child protothread with arguments
manujose 0:e6964ff1bbcc 187 *
manujose 0:e6964ff1bbcc 188 * \sa PT_SPAWN()
manujose 0:e6964ff1bbcc 189 *
manujose 0:e6964ff1bbcc 190 * \hideinitializer
manujose 0:e6964ff1bbcc 191 */
manujose 0:e6964ff1bbcc 192 #define PT_WAIT_THREAD(pt, thread) PT_WAIT_WHILE((pt), PT_SCHEDULE(thread))
manujose 0:e6964ff1bbcc 193
manujose 0:e6964ff1bbcc 194 /**
manujose 0:e6964ff1bbcc 195 * Spawn a child protothread and wait until it exits.
manujose 0:e6964ff1bbcc 196 *
manujose 0:e6964ff1bbcc 197 * This macro spawns a child protothread and waits until it exits. The
manujose 0:e6964ff1bbcc 198 * macro can only be used within a protothread.
manujose 0:e6964ff1bbcc 199 *
manujose 0:e6964ff1bbcc 200 * \param pt A pointer to the protothread control structure.
manujose 0:e6964ff1bbcc 201 * \param child A pointer to the child protothread's control structure.
manujose 0:e6964ff1bbcc 202 * \param thread The child protothread with arguments
manujose 0:e6964ff1bbcc 203 *
manujose 0:e6964ff1bbcc 204 * \hideinitializer
manujose 0:e6964ff1bbcc 205 */
manujose 0:e6964ff1bbcc 206 #define PT_SPAWN(pt, child, thread) \
manujose 0:e6964ff1bbcc 207 do { \
manujose 0:e6964ff1bbcc 208 PT_INIT((child)); \
manujose 0:e6964ff1bbcc 209 PT_WAIT_THREAD((pt), (thread)); \
manujose 0:e6964ff1bbcc 210 } while(0)
manujose 0:e6964ff1bbcc 211
manujose 0:e6964ff1bbcc 212 /** @} */
manujose 0:e6964ff1bbcc 213
manujose 0:e6964ff1bbcc 214 /**
manujose 0:e6964ff1bbcc 215 * \name Exiting and restarting
manujose 0:e6964ff1bbcc 216 * @{
manujose 0:e6964ff1bbcc 217 */
manujose 0:e6964ff1bbcc 218
manujose 0:e6964ff1bbcc 219 /**
manujose 0:e6964ff1bbcc 220 * Restart the protothread.
manujose 0:e6964ff1bbcc 221 *
manujose 0:e6964ff1bbcc 222 * This macro will block and cause the running protothread to restart
manujose 0:e6964ff1bbcc 223 * its execution at the place of the PT_BEGIN() call.
manujose 0:e6964ff1bbcc 224 *
manujose 0:e6964ff1bbcc 225 * \param pt A pointer to the protothread control structure.
manujose 0:e6964ff1bbcc 226 *
manujose 0:e6964ff1bbcc 227 * \hideinitializer
manujose 0:e6964ff1bbcc 228 */
manujose 0:e6964ff1bbcc 229 #define PT_RESTART(pt) \
manujose 0:e6964ff1bbcc 230 do { \
manujose 0:e6964ff1bbcc 231 PT_INIT(pt); \
manujose 0:e6964ff1bbcc 232 return PT_WAITING; \
manujose 0:e6964ff1bbcc 233 } while(0)
manujose 0:e6964ff1bbcc 234
manujose 0:e6964ff1bbcc 235 /**
manujose 0:e6964ff1bbcc 236 * Exit the protothread.
manujose 0:e6964ff1bbcc 237 *
manujose 0:e6964ff1bbcc 238 * This macro causes the protothread to exit. If the protothread was
manujose 0:e6964ff1bbcc 239 * spawned by another protothread, the parent protothread will become
manujose 0:e6964ff1bbcc 240 * unblocked and can continue to run.
manujose 0:e6964ff1bbcc 241 *
manujose 0:e6964ff1bbcc 242 * \param pt A pointer to the protothread control structure.
manujose 0:e6964ff1bbcc 243 *
manujose 0:e6964ff1bbcc 244 * \hideinitializer
manujose 0:e6964ff1bbcc 245 */
manujose 0:e6964ff1bbcc 246 #define PT_EXIT(pt) \
manujose 0:e6964ff1bbcc 247 do { \
manujose 0:e6964ff1bbcc 248 PT_INIT(pt); \
manujose 0:e6964ff1bbcc 249 return PT_EXITED; \
manujose 0:e6964ff1bbcc 250 } while(0)
manujose 0:e6964ff1bbcc 251
manujose 0:e6964ff1bbcc 252 /** @} */
manujose 0:e6964ff1bbcc 253
manujose 0:e6964ff1bbcc 254 /**
manujose 0:e6964ff1bbcc 255 * \name Calling a protothread
manujose 0:e6964ff1bbcc 256 * @{
manujose 0:e6964ff1bbcc 257 */
manujose 0:e6964ff1bbcc 258
manujose 0:e6964ff1bbcc 259 /**
manujose 0:e6964ff1bbcc 260 * Schedule a protothread.
manujose 0:e6964ff1bbcc 261 *
manujose 0:e6964ff1bbcc 262 * This function shedules a protothread. The return value of the
manujose 0:e6964ff1bbcc 263 * function is non-zero if the protothread is running or zero if the
manujose 0:e6964ff1bbcc 264 * protothread has exited.
manujose 0:e6964ff1bbcc 265 *
manujose 0:e6964ff1bbcc 266 * \param f The call to the C function implementing the protothread to
manujose 0:e6964ff1bbcc 267 * be scheduled
manujose 0:e6964ff1bbcc 268 *
manujose 0:e6964ff1bbcc 269 * \hideinitializer
manujose 0:e6964ff1bbcc 270 */
manujose 0:e6964ff1bbcc 271 #define PT_SCHEDULE(f) ((f) < PT_EXITED)
manujose 0:e6964ff1bbcc 272
manujose 0:e6964ff1bbcc 273 /** @} */
manujose 0:e6964ff1bbcc 274
manujose 0:e6964ff1bbcc 275 /**
manujose 0:e6964ff1bbcc 276 * \name Yielding from a protothread
manujose 0:e6964ff1bbcc 277 * @{
manujose 0:e6964ff1bbcc 278 */
manujose 0:e6964ff1bbcc 279
manujose 0:e6964ff1bbcc 280 /**
manujose 0:e6964ff1bbcc 281 * Yield from the current protothread.
manujose 0:e6964ff1bbcc 282 *
manujose 0:e6964ff1bbcc 283 * This function will yield the protothread, thereby allowing other
manujose 0:e6964ff1bbcc 284 * processing to take place in the system.
manujose 0:e6964ff1bbcc 285 *
manujose 0:e6964ff1bbcc 286 * \param pt A pointer to the protothread control structure.
manujose 0:e6964ff1bbcc 287 *
manujose 0:e6964ff1bbcc 288 * \hideinitializer
manujose 0:e6964ff1bbcc 289 */
manujose 0:e6964ff1bbcc 290 #define PT_YIELD(pt) \
manujose 0:e6964ff1bbcc 291 do { \
manujose 0:e6964ff1bbcc 292 PT_YIELD_FLAG = 0; \
manujose 0:e6964ff1bbcc 293 LC_SET((pt)->lc); \
manujose 0:e6964ff1bbcc 294 if(PT_YIELD_FLAG == 0) { \
manujose 0:e6964ff1bbcc 295 return PT_YIELDED; \
manujose 0:e6964ff1bbcc 296 } \
manujose 0:e6964ff1bbcc 297 } while(0)
manujose 0:e6964ff1bbcc 298
manujose 0:e6964ff1bbcc 299 /**
manujose 0:e6964ff1bbcc 300 * \brief Yield from the protothread until a condition occurs.
manujose 0:e6964ff1bbcc 301 * \param pt A pointer to the protothread control structure.
manujose 0:e6964ff1bbcc 302 * \param cond The condition.
manujose 0:e6964ff1bbcc 303 *
manujose 0:e6964ff1bbcc 304 * This function will yield the protothread, until the
manujose 0:e6964ff1bbcc 305 * specified condition evaluates to true.
manujose 0:e6964ff1bbcc 306 *
manujose 0:e6964ff1bbcc 307 *
manujose 0:e6964ff1bbcc 308 * \hideinitializer
manujose 0:e6964ff1bbcc 309 */
manujose 0:e6964ff1bbcc 310 #define PT_YIELD_UNTIL(pt, cond) \
manujose 0:e6964ff1bbcc 311 do { \
manujose 0:e6964ff1bbcc 312 PT_YIELD_FLAG = 0; \
manujose 0:e6964ff1bbcc 313 LC_SET((pt)->lc); \
manujose 0:e6964ff1bbcc 314 if((PT_YIELD_FLAG == 0) || !(cond)) { \
manujose 0:e6964ff1bbcc 315 return PT_YIELDED; \
manujose 0:e6964ff1bbcc 316 } \
manujose 0:e6964ff1bbcc 317 } while(0)
manujose 0:e6964ff1bbcc 318
manujose 0:e6964ff1bbcc 319 /** @} */
manujose 0:e6964ff1bbcc 320
manujose 0:e6964ff1bbcc 321 #endif /* __PT_H__ */
manujose 0:e6964ff1bbcc 322
manujose 0:e6964ff1bbcc 323 /** @} */