#include "rpp/rpp.h"
#include <math.h>
#include "sys/ti_drv_dmm.h"
+#include "rpp/mutex.h"
+
+RPP_MUTEX_DEFINE(mutex_can);
static const struct rpp_can_config *can_config = NULL;
{
uint16_t i;
+ if (!RPP_MUTEX_INIT(mutex_can))
+ return FAILURE;
+
#ifdef TARGET_TMS570_RPP
dmmInit();
return SUCCESS;
}
-
int8_t rpp_can_write(rpp_can_hw_obj hw_obj, const struct rpp_can_pdu *pdu)
{
uint8_t i;
if (!(controller = map_controller(tx_cfg->controller)))
return -RPP_EINVAL;
+ RPP_MUTEX_LOCK(mutex_can);
+
// Wait until IF1 is ready to use
while (controller->IF1STAT & (1U << 7)) ;
// Copy TX data into message box
controller->IF1NO = tx_cfg->msg_obj;
+ RPP_MUTEX_UNLOCK(mutex_can);
+
return SUCCESS;
}
reg_index = (can_config->rx_config[hw_obj].msg_obj - 1) >> 5;
bit_mask = 1 << ((can_config->rx_config[hw_obj].msg_obj - 1) & 0x1FU);
+ RPP_MUTEX_LOCK(mutex_can);
+
// FIXME: Check whether to abort if there are no new data
- if (!(controller->NWDATx[reg_index] & bit_mask))
+ if (!(controller->NWDATx[reg_index] & bit_mask)) {
+ RPP_MUTEX_UNLOCK(mutex_can);
return -RPP_ENODATA;
+ }
// Wait until IF2 is ready to use
while (controller->IF2STAT & (1U << 7)) ;
#endif
}
+ RPP_MUTEX_UNLOCK(mutex_can);
+
return SUCCESS;
}