Skip to content

Commit

Permalink
fixup! feat: convert yield to use the driver library
Browse files Browse the repository at this point in the history
  • Loading branch information
mpolitzer committed Oct 27, 2023
1 parent 5050981 commit 80e4976
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
7 changes: 3 additions & 4 deletions linux/libdriver/base/yield-driver-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* @{ */
#ifndef YIELD_DRIVER_API_H
#define YIELD_DRIVER_API_H
#include<stdint.h>

/** contents of @ref rollup_driver_t are implementation specific.
* Define it in @p <yield.h> */
Expand All @@ -25,9 +26,7 @@ int yield_driver_init(struct yield_driver *me);

/** Report the application progress to the emulator.
*
* @param [in] me A sucessfuly initialized state by @ref yield_driver_init
*
* @note usage of @p me after this call is a BUG and will cause undefined behaviour */
int yield_driver_progress(struct yield_driver *me, float progress);
* @param [in] me A sucessfuly initialized state by @ref yield_driver_init */
int yield_driver_progress(struct yield_driver *me, uint32_t progress);

#endif /* YIELD_DRIVER_API_H */
16 changes: 9 additions & 7 deletions linux/libdriver/examples/yield.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ int main(int argc, char *argv[])
float progress = 0.0;

yield_driver_t Y[1];
if (yield_driver_init(Y))
return EXIT_FAILURE;
if (argc > 1)
progress = strtof(argv[1], NULL);
if (yield_driver_progress(Y, progress))
return EXIT_FAILURE;

if ((argc > 1) && (sscanf(argv[1], "--progress=%f\n", &progress) == 1)) {
if (yield_driver_init(Y))
return EXIT_FAILURE;
if (yield_driver_progress(Y, progress * 10))
return EXIT_FAILURE;
} else {
fprintf(stderr, "usage: %s --progress=<float>\n", argv[0]);
exit(EXIT_FAILURE);
}
return EXIT_SUCCESS;
}
4 changes: 2 additions & 2 deletions linux/libdriver/ioctl/yield.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ int yield_driver_init(struct yield_driver *me)
return 0;
}

int yield_driver_progress(struct yield_driver *me, float progress)
int yield_driver_progress(struct yield_driver *me, uint32_t progress)
{
struct yield_request req = {
.dev = (uint64_t)HTIF_DEVICE_YIELD,
.cmd = (uint64_t)HTIF_YIELD_AUTOMATIC,
.reason = (uint64_t)HTIF_YIELD_REASON_PROGRESS,
.data = progress * 10,
.data = progress,
};
return ioctl(me->fd, IOCTL_YIELD, (unsigned long)&req);
}
4 changes: 2 additions & 2 deletions linux/libdriver/mock/yield.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ int yield_driver_init(struct yield_driver *me)
return 0;
}

int yield_driver_progress(struct yield_driver *me, float progress)
int yield_driver_progress(struct yield_driver *me, uint32_t progress)
{
assert(me);
fprintf(stderr, "Progress: %6.2f\n", progress);
fprintf(stderr, "Progress: %u.%02u\n", progress / 10, progress % 10 * 10);
return 0;
}

0 comments on commit 80e4976

Please sign in to comment.