GPS Device
Loading...
Searching...
No Matches
SD Command Handlers

Functions

static ERR_te sd_cmd_list_handler (uint32_t argc, char **argv)
 CLI handler for the "list" command. Logs the names of all active SD card handles.
static ERR_te sd_cmd_info_handler (uint32_t argc, char **argv)
 CLI handler for the "info" command. Logs detailed information about a named SD card handle.

Detailed Description

Function Documentation

◆ sd_cmd_list_handler()

ERR_te sd_cmd_list_handler ( uint32_t argc,
char ** argv )
static

CLI handler for the "list" command. Logs the names of all active SD card handles.

Expected invocation: sd list

Parameters
[in]argcArgument count. Must be exactly 2.
[in]argvArgument list: argv[0] = "sd", argv[1] = "list".
Returns
  • ERR_OK on success
  • ERR_INVALID_ARGUMENT if argc != 2

Definition at line 1761 of file sd.c.

1761 {
1762 if(argc != 2) {
1763 LOG_ERROR(
1764 internal_state.subsys,
1765 internal_state.log_level,
1766 "sd_cmd_list_handler: invalid arguments"
1767 );
1768 return ERR_INVALID_ARGUMENT;
1769 }
1770
1771 for(uint32_t i = 0; i < CONFIG_SD_MAX_OBJECTS; i++) {
1772 if(internal_state.sds[i].in_use == true) {
1773 LOG_INFO(
1774 internal_state.subsys,
1775 internal_state.log_level,
1776 "%s",
1777 internal_state.sds[i].name
1778 );
1779 }
1780 }
1781
1782 return ERR_OK;
1783}
static struct internal_state_s internal_state
Singleton instance of the SysTick driver internal state.
@ ERR_OK
Definition err.h:36
@ ERR_INVALID_ARGUMENT
Definition err.h:38
#define LOG_ERROR(subsys, lvl, fmt,...)
Definition log.h:258
#define LOG_INFO(subsys, lvl, fmt,...)
Definition log.h:255

◆ sd_cmd_info_handler()

ERR_te sd_cmd_info_handler ( uint32_t argc,
char ** argv )
static

CLI handler for the "info" command. Logs detailed information about a named SD card handle.

Expected invocation: sd info <n>

Searches the pool for a handle whose name matches argv[2] and logs its type (SDSC/SDHC), addressing mode (byte/block), capacity in MB, block size in bytes, and block count.

Parameters
[in]argcArgument count. Must be exactly 3.
[in]argvArgument list: argv[0] = "sd", argv[1] = "info", argv[2] = SD card handle name.
Returns
  • ERR_OK on success
  • ERR_INVALID_ARGUMENT if argc != 3 or no handle with the given name exists

Definition at line 1803 of file sd.c.

1803 {
1804 if(argc != 3) {
1805 LOG_ERROR(
1806 internal_state.subsys,
1807 internal_state.log_level,
1808 "sd_cmd_info_handler: invalid arguments"
1809 );
1810 return ERR_INVALID_ARGUMENT;
1811 }
1812
1813 for(uint32_t i = 0; i < CONFIG_SD_MAX_OBJECTS; i++) {
1814 if(str_cmp(internal_state.sds[i].name, argv[2]) == true) {
1815 char type_str[10];
1816 char addr_mode[10];
1817
1818 switch(internal_state.sds[i].type) {
1819 case SDSC: str_cpy(type_str, "SDSC", get_str_len("SDSC") + 1); break;
1820 case SDHC: str_cpy(type_str, "SDHC", get_str_len("SDHC") + 1); break;
1821 }
1822
1823 switch(internal_state.sds[i].addr_mode) {
1824 case SD_ADDR_MODE_BLOCK: str_cpy(addr_mode, "block", get_str_len("block") + 1); break;
1825 case SD_ADDR_MODE_BYTE: str_cpy(addr_mode, "byte", get_str_len("byte") + 1); break;
1826 }
1827
1828 LOG_INFO(
1829 internal_state.subsys,
1830 internal_state.log_level,
1831 "type: %s, addr mode: %s, capacity: %d mb, block size: %d byte, block count: %d",
1832 type_str,
1833 addr_mode,
1834 internal_state.sds[i].capacity_mb,
1835 internal_state.sds[i].block_len,
1836 internal_state.sds[i].block_count
1837 );
1838
1839 break;
1840 }
1841
1842 if(i == CONFIG_SD_MAX_OBJECTS - 1) {
1843 LOG_ERROR(
1844 internal_state.subsys,
1845 internal_state.log_level,
1846 "sd_cmd_info_handler: no such handle"
1847 );
1848
1849 return ERR_INVALID_ARGUMENT;
1850 }
1851 }
1852
1853 return ERR_OK;
1854}
bool str_cmp(const char *str1, const char *str2)
Compares two null-terminated strings for equality.
Definition common.c:248
int str_cpy(char *str_to, const char *str_from, uint32_t len)
Copies a null-terminated string into a destination buffer.
Definition common.c:333
uint32_t get_str_len(char const *str)
Returns the length of a string, excluding the null terminator.
Definition common.c:22
@ SDSC
Definition sd.c:151
@ SDHC
Definition sd.c:152
@ SD_ADDR_MODE_BYTE
Definition sd.c:135
@ SD_ADDR_MODE_BLOCK
Definition sd.c:136
Here is the call graph for this function: