Lines Matching refs:CANmodule

42 static CO_ReturnError_t setFilters(CO_CANmodule_t *CANmodule){  in setFilters()  argument
45 if(CANmodule->useCANrxFilters){ in setFilters()
49 nFiltersIn = CANmodule->rxSize; in setFilters()
64 fin = &CANmodule->filter[i]; in setFilters()
77 if(setsockopt(CANmodule->fd, SOL_CAN_RAW, CAN_RAW_FILTER, in setFilters()
87 CANmodule->filter[0].can_id = 0; in setFilters()
88 CANmodule->filter[0].can_mask = 0; in setFilters()
89 if(setsockopt(CANmodule->fd, SOL_CAN_RAW, CAN_RAW_FILTER, in setFilters()
90 &CANmodule->filter[0], sizeof(struct can_filter)) != 0) in setFilters()
106 void CO_CANsetNormalMode(CO_CANmodule_t *CANmodule){ in CO_CANsetNormalMode() argument
108 if(CANmodule == NULL || setFilters(CANmodule) != CO_ERROR_NO){ in CO_CANsetNormalMode()
111 CANmodule->CANnormal = true; in CO_CANsetNormalMode()
117 CO_CANmodule_t *CANmodule, in CO_CANmodule_init() argument
129 if(CANmodule==NULL || CANdriverState==NULL || rxArray==NULL || txArray==NULL){ in CO_CANmodule_init()
135 CANmodule->CANdriverState = CANdriverState; in CO_CANmodule_init()
136 CANmodule->rxArray = rxArray; in CO_CANmodule_init()
137 CANmodule->rxSize = rxSize; in CO_CANmodule_init()
138 CANmodule->txArray = txArray; in CO_CANmodule_init()
139 CANmodule->txSize = txSize; in CO_CANmodule_init()
140 CANmodule->CANnormal = false; in CO_CANmodule_init()
141 CANmodule->useCANrxFilters = true; in CO_CANmodule_init()
142 CANmodule->bufferInhibitFlag = false; in CO_CANmodule_init()
143 CANmodule->firstCANtxMessage = true; in CO_CANmodule_init()
144 CANmodule->error = 0; in CO_CANmodule_init()
145 CANmodule->CANtxCount = 0U; in CO_CANmodule_init()
146 CANmodule->errOld = 0U; in CO_CANmodule_init()
147 CANmodule->em = NULL; in CO_CANmodule_init()
150 CANmodule->useCANrxFilters = false; in CO_CANmodule_init()
165 if(ret == CO_ERROR_NO && CANmodule->wasConfigured == 0){ in CO_CANmodule_init()
168 CANmodule->wasConfigured = 1; in CO_CANmodule_init()
171 CANmodule->fd = socket(AF_CAN, SOCK_RAW, CAN_RAW); in CO_CANmodule_init()
172 if(CANmodule->fd < 0){ in CO_CANmodule_init()
178 if(bind(CANmodule->fd, (struct sockaddr*)&sockAddr, sizeof(sockAddr)) != 0){ in CO_CANmodule_init()
185 CANmodule->filter = (struct can_filter *) calloc(rxSize, sizeof(struct can_filter)); in CO_CANmodule_init()
186 if(CANmodule->filter == NULL){ in CO_CANmodule_init()
193 if(ret == CO_ERROR_NO && CANmodule->filter == NULL){ in CO_CANmodule_init()
198 if(ret == CO_ERROR_NO && CANmodule->useCANrxFilters){ in CO_CANmodule_init()
201 CANmodule->filter[i].can_id = 0; in CO_CANmodule_init()
202 CANmodule->filter[i].can_mask = CAN_SFF_MASK | CAN_EFF_FLAG | CAN_RTR_FLAG; in CO_CANmodule_init()
208 setsockopt(CANmodule->fd, SOL_CAN_RAW, CAN_RAW_FILTER, NULL, 0); in CO_CANmodule_init()
216 void CO_CANmodule_disable(CO_CANmodule_t *CANmodule){ in CO_CANmodule_disable() argument
217 close(CANmodule->fd); in CO_CANmodule_disable()
218 free(CANmodule->filter); in CO_CANmodule_disable()
219 CANmodule->filter = NULL; in CO_CANmodule_disable()
231 CO_CANmodule_t *CANmodule, in CO_CANrxBufferInit() argument
241 if((CANmodule!=NULL) && (object!=NULL) && (pFunct!=NULL) && in CO_CANrxBufferInit()
242 (CANmodule->filter!=NULL) && (index < CANmodule->rxSize)){ in CO_CANrxBufferInit()
244 CO_CANrx_t *buffer = &CANmodule->rxArray[index]; in CO_CANrxBufferInit()
258 if(CANmodule->useCANrxFilters){ in CO_CANrxBufferInit()
259 CANmodule->filter[index].can_id = buffer->ident; in CO_CANrxBufferInit()
260 CANmodule->filter[index].can_mask = buffer->mask; in CO_CANrxBufferInit()
261 if(CANmodule->CANnormal){ in CO_CANrxBufferInit()
262 ret = setFilters(CANmodule); in CO_CANrxBufferInit()
276 CO_CANmodule_t *CANmodule, in CO_CANtxBufferInit() argument
285 if((CANmodule != NULL) && (index < CANmodule->txSize)){ in CO_CANtxBufferInit()
287 buffer = &CANmodule->txArray[index]; in CO_CANtxBufferInit()
305 CO_ReturnError_t CO_CANsend(CO_CANmodule_t *CANmodule, CO_CANtx_t *buffer){ in CO_CANsend() argument
310 n = write(CANmodule->fd, buffer, count); in CO_CANsend()
317 CO_errorReport((CO_EM_t*)CANmodule->em, CO_EM_CAN_TX_OVERFLOW, CO_EMC_CAN_OVERRUN, n); in CO_CANsend()
326 void CO_CANclearPendingSyncPDOs(CO_CANmodule_t *CANmodule){ in CO_CANclearPendingSyncPDOs() argument
332 void CO_CANverifyErrors(CO_CANmodule_t *CANmodule){ in CO_CANverifyErrors() argument
335 CO_EM_t* em = (CO_EM_t*)CANmodule->em; in CO_CANverifyErrors()
338 canGetErrorCounters(CANmodule->CANdriverState, &rxErrors, &txErrors); in CO_CANverifyErrors()
342 err = ((uint32_t)txErrors << 16) | ((uint32_t)rxErrors << 8) | CANmodule->error; in CO_CANverifyErrors()
344 if(CANmodule->errOld != err){ in CO_CANverifyErrors()
345 CANmodule->errOld = err; in CO_CANverifyErrors()
365 if(!CANmodule->firstCANtxMessage){ in CO_CANverifyErrors()
386 if(CANmodule->error & 0x02){ /* CAN RX bus overflow */ in CO_CANverifyErrors()
395 void CO_CANrxWait(CO_CANmodule_t *CANmodule){ in CO_CANrxWait() argument
399 if(CANmodule == NULL){ in CO_CANrxWait()
406 n = read(CANmodule->fd, &msg, size); in CO_CANrxWait()
408 if(CANmodule->CANnormal){ in CO_CANrxWait()
411 … CO_errorReport((CO_EM_t*)CANmodule->em, CO_EM_CAN_RXB_OVERFLOW, CO_EMC_COMMUNICATION, n); in CO_CANrxWait()
424 buffer = &CANmodule->rxArray[0]; in CO_CANrxWait()
425 for(i = CANmodule->rxSize; i > 0U; i--){ in CO_CANrxWait()