In Atmel ASF I found this piece of code
enum status_code eeprom_emulator_init(void)
{
enum status_code error_code = STATUS_OK;
struct nvm_config config;
struct nvm_parameters parameters;
/* Retrieve the NVM controller configuration - enable manual page writing
* mode so that the emulator has exclusive control over page writes to
* allow for caching */
nvm_get_config_defaults(&config);
config.manual_page_write = true;
/* Apply new NVM configuration */
do {
error_code = nvm_set_config(&config);
} while (error_code == STATUS_BUSY);
/* Get the NVM controller configuration parameters */
nvm_get_parameters(¶meters);
/* Ensure the device fuses are configured for at least one master page row,
* one user EEPROM data row and one spare row */
if (parameters.eeprom_number_of_pages < (3 * NVMCTRL_ROW_PAGES)) {
return STATUS_ERR_NO_MEMORY;
}
As far as I know about enums they are used for variables, then how is it also used to contain instructions in above code.?
Best Answer
The
enum
doesn't contain the code. The function is an ordinary function that happens to return a value of typeenum status_code
.You don't normally see this syntax, because most programmers would also create a
typedef
for theenum status_code
and use that to declare the type of the function's return value.For example: