MCPcopy Create free account
hub / github.com/CANopenNode/CANopenNode / main

Function main

example/main_blank.c:45–211  ·  view source on GitHub ↗

main ***********************************************************************/

Source from the content-addressed store, hash-verified

43
44/* main ***********************************************************************/
45int
46main(void) {
47 CO_ReturnError_t err;
48 CO_NMT_reset_cmd_t reset = CO_RESET_NOT;
49 uint32_t heapMemoryUsed;
50 void* CANptr = NULL; /* CAN module address */
51 uint8_t pendingNodeId = 10; /* read from dip switches or nonvolatile memory, configurable by LSS slave */
52 uint8_t activeNodeId = 10; /* Copied from CO_pendingNodeId in the communication reset section */
53 uint16_t pendingBitRate = 125; /* read from dip switches or nonvolatile memory, configurable by LSS slave */
54
55#if (CO_CONFIG_STORAGE) & CO_CONFIG_STORAGE_ENABLE
56 CO_storage_t storage;
57 CO_storage_entry_t storageEntries[] = {{.addr = &OD_PERSIST_COMM,
58 .len = sizeof(OD_PERSIST_COMM),
59 .subIndexOD = 2,
60 .attr = CO_storage_cmd | CO_storage_restore,
61 .addrNV = NULL}};
62 uint8_t storageEntriesCount = sizeof(storageEntries) / sizeof(storageEntries[0]);
63 uint32_t storageInitError = 0;
64#endif
65
66 /* Configure microcontroller. */
67
68 /* Allocate memory */
69 CO_config_t* config_ptr = NULL;
70#ifdef CO_MULTIPLE_OD
71 /* example usage of CO_MULTIPLE_OD (but still single OD here) */
72 CO_config_t co_config = {0};
73 OD_INIT_CONFIG(co_config); /* helper macro from OD.h */
74 co_config.CNT_LEDS = 1;
75 co_config.CNT_LSS_SLV = 1;
76 config_ptr = &co_config;
77#endif /* CO_MULTIPLE_OD */
78 CO = CO_new(config_ptr, &heapMemoryUsed);
79 if (CO == NULL) {
80 log_printf("Error: Can't allocate memory\n");
81 return 0;
82 } else {
83 log_printf("Allocated %u bytes for CANopen objects\n", heapMemoryUsed);
84 }
85
86#if (CO_CONFIG_STORAGE) & CO_CONFIG_STORAGE_ENABLE
87 err = CO_storageBlank_init(&storage, CO->CANmodule, OD_ENTRY_H1010_storeParameters,
88 OD_ENTRY_H1011_restoreDefaultParameters, storageEntries, storageEntriesCount,
89 &storageInitError);
90
91 if (err != CO_ERROR_NO && err != CO_ERROR_DATA_CORRUPT) {
92 log_printf("Error: Storage %d\n", storageInitError);
93 return 0;
94 }
95#endif
96
97 while (reset != CO_RESET_APP) {
98 /* CANopen communication reset - initialize CANopen objects *******************/
99 log_printf("CANopenNode - Reset communication...\n");
100
101 /* Wait rt_thread. */
102 CO->CANmodule->CANnormal = false;

Callers

nothing calls this directly

Calls 11

CO_newFunction · 0.85
CO_storageBlank_initFunction · 0.85
CO_CANmodule_disableFunction · 0.85
CO_CANinitFunction · 0.85
CO_LSSinitFunction · 0.85
CO_CANopenInitFunction · 0.85
CO_CANopenInitPDOFunction · 0.85
CO_CANsetNormalModeFunction · 0.85
CO_processFunction · 0.85
CO_deleteFunction · 0.85

Tested by

no test coverage detected