1
0
Fork 0
CANopenNode/drivers/CO_storageBlank.c
Pedro Rodríguez Vieites 8751c52836 Added support for CiA 401 / Driver example / Test example.
User must implement the CANInterface for its own hardware
2025-03-07 17:02:55 +01:00

112 lines
3.8 KiB
C

/*
* CANopen Object Dictionary storage object (blank example).
*
* @file CO_storageBlank.c
* @author Janez Paternoster
* @copyright 2021 Janez Paternoster
*
* This file is part of <https://github.com/CANopenNode/CANopenNode>, a CANopen Stack.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and limitations under the License.
*/
#include "CO_storageBlank.h"
#if (CO_CONFIG_STORAGE) & CO_CONFIG_STORAGE_ENABLE
/*
* Function for writing data on "Store parameters" command - OD object 1010
*
* For more information see file CO_storage.h, CO_storage_entry_t.
*/
static ODR_t storeBlank(CO_storage_entry_t* entry, CO_CANmodule_t* CANmodule) {
/* Open a file and write data to it */
/* file = open(entry->pathToFileOrPointerToMemory); */
/* write(entry->addr, entry->len, file); */
return ODR_OK;
}
/*
* Function for restoring data on "Restore default parameters" command - OD 1011
*
* For more information see file CO_storage.h, CO_storage_entry_t.
*/
static ODR_t restoreBlank(CO_storage_entry_t* entry, CO_CANmodule_t* CANmodule) {
/* disable (delete) the file, so default values will stay after startup */
return ODR_OK;
}
CO_ReturnError_t CO_storageBlank_init(CO_storage_t* storage,
CO_CANmodule_t* CANmodule,
OD_entry_t* OD_1010_StoreParameters,
OD_entry_t* OD_1011_RestoreDefaultParam,
CO_storage_entry_t* entries,
uint8_t entriesCount,
uint32_t* storageInitError) {
CO_ReturnError_t ret;
/* verify arguments */
if (storage == NULL || entries == NULL || entriesCount == 0 || storageInitError == NULL) {
return CO_ERROR_ILLEGAL_ARGUMENT;
}
/* initialize storage and OD extensions */
ret = CO_storage_init(storage, CANmodule, OD_1010_StoreParameters, OD_1011_RestoreDefaultParam, storeBlank,
restoreBlank, entries, entriesCount);
if (ret != CO_ERROR_NO) {
return ret;
}
/* initialize entries */
*storageInitError = 0;
for (uint8_t i = 0; i < entriesCount; i++) {
CO_storage_entry_t* entry = &entries[i];
/* verify arguments */
if (entry->addr == NULL || entry->len == 0 || entry->subIndexOD < 2) {
*storageInitError = i;
return CO_ERROR_ILLEGAL_ARGUMENT;
}
/* Open a file and read data from file to entry->addr */
/* file = open(entry->pathToFileOrPointerToMemory); */
/* read(entry->addr, entry->len, file); */
}
return ret;
}
CO_ReturnError_t CO_storageBlank_auto_process(CO_storage_t* storage, bool_t saveAll) {
/* verify arguments */
if (storage == NULL || !storage->enabled) {
return CO_ERROR_ILLEGAL_ARGUMENT;
}
/* loop through entries */
for (uint8_t n = 0; n < storage->entriesCount; n++) {
CO_storage_entry_t* entry = &storage->entries[n];
if ((entry->attr & (uint8_t)CO_storage_auto) == 0) {
continue;
}
if (saveAll) {
/* close the file */
} else {
/* Open a file and write data to it */
}
}
return CO_ERROR_NO;
}
#endif /* (CO_CONFIG_STORAGE) & CO_CONFIG_STORAGE_ENABLE */