/* Soil Sensor Firmware * Timekeeping * Sensiplicity Systems * * Copyright 2015 * * Department of Botany and Plant Pathology * Center for Genome Research and Biocomputing * Oregon State University * Corvallis, OR 97331 * * This program is not free software; you can not redistribute it and/or * modify it at all. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ #include #include #include "time.h" /* Get the number of seconds since the system was powered on. */ uint32_t get_uptime(void){ return 0; } /* Wait for a condition to become true, timing out after a given * time. The condition is defined by a value, mask, and polarity. * The mask is a bitmask that selects bit(s) in a value. If polarity * is not 0, the condition is true when any of the bits are 1. If * polarity is 0, the condition is true when all are 0. * * The timeout value is in milliseconds. The maximum timeout is 127 milliseconds. * * Returns 0 if the condition became true, -1 if a timeout occurred. */ int8_t wait_condition(volatile uint8_t *value, uint8_t mask, uint8_t polarity, uint8_t timeout_ms){ uint32_t count = 0; uint32_t limit = timeout_ms * 200;/* Assuming 10 clock cycles per loop iteration. */ while(1){ if(polarity){ if(*value & mask){ return 0; } } else { if(!(*value & mask)){ return 0; } } count++; if(count > limit)return -1; } }