SatNOGS-COMMS  4.1.0
A COMMS subsystem for CubeSats
Loading...
Searching...
No Matches
disk_wrapper.cpp
Go to the documentation of this file.
1#include <zephyr/drivers/disk.h>
2#include <zephyr/init.h>
3#include <zephyr/kernel.h>
4#include <zephyr/storage/disk_access.h>
5
6static int
7offset_disk_init(struct disk_info *disk)
8{
9 int rc = disk_access_init(CONFIG_STM32_SDMMC_DEFAULT_DISK_NAME);
10 return rc;
11}
12
13static int
14offset_disk_status(struct disk_info *disk)
15{
16 /* Fix me */
17 return DISK_STATUS_OK;
18}
19
20static int
21offset_disk_read(struct disk_info *disk, uint8_t *buff, uint32_t sector,
22 uint32_t count)
23{
24 return disk_access_read(CONFIG_STM32_SDMMC_DEFAULT_DISK_NAME, buff,
25 sector + CONFIG_DISK_START_SECTOR, count);
26}
27
28static int
29offset_disk_write(struct disk_info *disk, const uint8_t *buff, uint32_t sector,
30 uint32_t count)
31{
32 return disk_access_write(CONFIG_STM32_SDMMC_DEFAULT_DISK_NAME, buff,
33 sector + CONFIG_DISK_START_SECTOR, count);
34}
35
36static int
37offset_disk_ioctl(struct disk_info *disk, uint8_t cmd, void *buff)
38{
39 int ret = disk_access_ioctl(CONFIG_STM32_SDMMC_DEFAULT_DISK_NAME, cmd, buff);
40 if (ret != 0) {
41 return ret;
42 }
43
44 if (cmd == DISK_IOCTL_GET_SECTOR_COUNT) {
45 uint32_t *count = (uint32_t *)buff;
46 *count -= CONFIG_DISK_START_SECTOR;
47 }
48
49 return 0;
50}
51
52static struct disk_operations offset_sd_ops = {
53 .init = offset_disk_init,
54 .status = offset_disk_status,
55 .read = offset_disk_read,
56 .write = offset_disk_write,
57 .ioctl = offset_disk_ioctl,
58};
59
60static struct disk_info offset_disk_info = {
61 .name = CONFIG_DISK_NAME,
62 .ops = &offset_sd_ops,
63};
64
65/* Automatically register at boot */
66static int
67offset_disk_register_init(void)
68{
69 return disk_access_register(&offset_disk_info);
70}
71SYS_INIT(offset_disk_register_init, APPLICATION,
72 CONFIG_APPLICATION_INIT_PRIORITY);
SYS_INIT(offset_disk_register_init, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY)