-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
libtock: sensors: temp: update to new format
- Loading branch information
Showing
5 changed files
with
71 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include "temperature.h" | ||
#include "tock.h" | ||
|
||
bool temperature_exists(void) { | ||
return driver_exists(DRIVER_NUM_TEMPERATURE); | ||
} | ||
|
||
int temperature_set_upcall(subscribe_upcall callback, void* callback_args) { | ||
subscribe_return_t sval = subscribe(DRIVER_NUM_TEMPERATURE, 0, callback, callback_args); | ||
return tock_subscribe_return_to_returncode(sval); | ||
} | ||
|
||
int temperature_command_read(void) { | ||
syscall_return_t cval = command(DRIVER_NUM_TEMPERATURE, 1, 0, 0); | ||
return tock_command_return_novalue_to_returncode(cval); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#pragma once | ||
|
||
#include "tock.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#define DRIVER_NUM_TEMPERATURE 0x60000 | ||
|
||
// Check if temperature sensor exists. | ||
bool temperature_exists(void); | ||
|
||
// units: temperature in hundredths of degrees centigrade. | ||
|
||
// Set the callback function to be called when the temperature measurement is | ||
// finished. | ||
// | ||
// callback - pointer to function to be called | ||
// callback_args - pointer to data provided to the callback | ||
int temperature_set_upcall(subscribe_upcall callback, void* callback_args); | ||
|
||
// initiate an ambient temperature measurement used both for synchronous and asynchronous readings | ||
int temperature_command_read(void); | ||
|
||
|
||
|
||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,27 @@ | ||
#include "temperature.h" | ||
#include "tock.h" | ||
|
||
struct data { | ||
bool fired; | ||
int temp; | ||
}; | ||
|
||
static struct data result = { .fired = false }; | ||
|
||
// Internal upcall for faking synchronous reads | ||
static void temp_upcall(int temp, | ||
__attribute__ ((unused)) int unused, | ||
__attribute__ ((unused)) int unused1, | ||
void* ud) { | ||
struct data* data = (struct data*) ud; | ||
data->temp = temp; | ||
data->fired = true; | ||
} | ||
#include "temperature.h" | ||
#include "temperature_internal.h" | ||
|
||
bool temperature_exists(void) { | ||
return driver_exists(DRIVER_NUM_TEMPERATURE); | ||
} | ||
|
||
int temperature_set_callback(subscribe_upcall callback, void* callback_args) { | ||
subscribe_return_t sval = subscribe(DRIVER_NUM_TEMPERATURE, 0, callback, callback_args); | ||
return tock_subscribe_return_to_returncode(sval); | ||
} | ||
|
||
int temperature_read(void) { | ||
syscall_return_t cval = command(DRIVER_NUM_TEMPERATURE, 1, 0, 0); | ||
return tock_command_return_novalue_to_returncode(cval); | ||
// Internal upcall for passing to the syscall driver. | ||
static void temperature_temp_upcall(int temp, | ||
__attribute__ ((unused)) int unused, | ||
__attribute__ ((unused)) int unused1, | ||
void* ud) { | ||
temperature_callback cb = (temperature_callback) ud; | ||
cb(RETURNCODE_SUCCESS, temp); | ||
} | ||
|
||
int temperature_read_sync(int* temperature) { | ||
int err; | ||
result.fired = false; | ||
|
||
err = temperature_set_callback(temp_upcall, (void*) &result); | ||
if (err < 0) return err; | ||
|
||
err = temperature_read(); | ||
if (err < 0) return err; | ||
|
||
// Wait for the callback. | ||
yield_for(&result.fired); | ||
int temperature_read(temperature_callback cb) { | ||
int ret; | ||
|
||
*temperature = result.temp; | ||
ret = temperature_set_upcall(temperature_temp_upcall, cb); | ||
if (ret != RETURNCODE_SUCCESS) return ret; | ||
|
||
return RETURNCODE_SUCCESS; | ||
ret = temperature_command_read(); | ||
return ret; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters