mirror of https://github.com/ARMmbed/mbed-os.git
fixed misaligned lines in can_api.c of NUC472 & M453
parent
da8fd8b5b7
commit
a044a65996
|
@ -29,7 +29,7 @@
|
||||||
#include "critical.h"
|
#include "critical.h"
|
||||||
|
|
||||||
#define NU_CAN_DEBUG 0
|
#define NU_CAN_DEBUG 0
|
||||||
#define CAN_NUM 1
|
#define CAN_NUM 1
|
||||||
|
|
||||||
static uint32_t can_irq_ids[CAN_NUM] = {0};
|
static uint32_t can_irq_ids[CAN_NUM] = {0};
|
||||||
static can_irq_handler can0_irq_handler;
|
static can_irq_handler can0_irq_handler;
|
||||||
|
@ -44,7 +44,7 @@
|
||||||
|
|
||||||
void can_init(can_t *obj, PinName rd, PinName td)
|
void can_init(can_t *obj, PinName rd, PinName td)
|
||||||
{
|
{
|
||||||
uint32_t can_td = (CANName)pinmap_peripheral(td, PinMap_CAN_TD);
|
uint32_t can_td = (CANName)pinmap_peripheral(td, PinMap_CAN_TD);
|
||||||
uint32_t can_rd = (CANName)pinmap_peripheral(rd, PinMap_CAN_RD);
|
uint32_t can_rd = (CANName)pinmap_peripheral(rd, PinMap_CAN_RD);
|
||||||
obj->can = (CANName)pinmap_merge(can_td, can_rd);
|
obj->can = (CANName)pinmap_merge(can_td, can_rd);
|
||||||
MBED_ASSERT((int)obj->can != NC);
|
MBED_ASSERT((int)obj->can != NC);
|
||||||
|
@ -58,18 +58,18 @@
|
||||||
|
|
||||||
// Enable IP clock
|
// Enable IP clock
|
||||||
CLK_EnableModuleClock(modinit->clkidx);
|
CLK_EnableModuleClock(modinit->clkidx);
|
||||||
|
|
||||||
obj->index = 0;
|
obj->index = 0;
|
||||||
|
|
||||||
pinmap_pinout(td, PinMap_CAN_TD);
|
pinmap_pinout(td, PinMap_CAN_TD);
|
||||||
pinmap_pinout(rd, PinMap_CAN_RD);
|
pinmap_pinout(rd, PinMap_CAN_RD);
|
||||||
|
|
||||||
/* For M453 mbed Board Transmitter Setting (RS Pin) */
|
/* For M453 mbed Board Transmitter Setting (RS Pin) */
|
||||||
GPIO_SetMode(PA, BIT0| BIT1, GPIO_MODE_OUTPUT);
|
GPIO_SetMode(PA, BIT0| BIT1, GPIO_MODE_OUTPUT);
|
||||||
PA0 = 0x00;
|
PA0 = 0x00;
|
||||||
PA1 = 0x00;
|
PA1 = 0x00;
|
||||||
|
|
||||||
CAN_Open((CAN_T *)obj->can, 500000, CAN_NORMAL_MODE);
|
CAN_Open((CAN_T *)obj->can, 500000, CAN_NORMAL_MODE);
|
||||||
|
|
||||||
can_filter(obj, 0, 0, CANStandard, 0);
|
can_filter(obj, 0, 0, CANStandard, 0);
|
||||||
}
|
}
|
||||||
|
@ -78,29 +78,29 @@
|
||||||
void can_free(can_t *obj)
|
void can_free(can_t *obj)
|
||||||
{
|
{
|
||||||
|
|
||||||
const struct nu_modinit_s *modinit = get_modinit(obj->can, can_modinit_tab);
|
const struct nu_modinit_s *modinit = get_modinit(obj->can, can_modinit_tab);
|
||||||
|
|
||||||
MBED_ASSERT(modinit != NULL);
|
MBED_ASSERT(modinit != NULL);
|
||||||
MBED_ASSERT(modinit->modname == obj->can);
|
MBED_ASSERT(modinit->modname == obj->can);
|
||||||
|
|
||||||
// Reset this module
|
// Reset this module
|
||||||
SYS_ResetModule(modinit->rsetidx);
|
SYS_ResetModule(modinit->rsetidx);
|
||||||
|
|
||||||
CLK_DisableModuleClock(modinit->clkidx);
|
CLK_DisableModuleClock(modinit->clkidx);
|
||||||
}
|
}
|
||||||
|
|
||||||
int can_frequency(can_t *obj, int hz)
|
int can_frequency(can_t *obj, int hz)
|
||||||
{
|
{
|
||||||
CAN_SetBaudRate((CAN_T *)obj->can, hz);
|
CAN_SetBaudRate((CAN_T *)obj->can, hz);
|
||||||
|
|
||||||
return CAN_GetCANBitRate((CAN_T *)obj->can);
|
return CAN_GetCANBitRate((CAN_T *)obj->can);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void can_irq(CANName name, int id)
|
static void can_irq(CANName name, int id)
|
||||||
{
|
{
|
||||||
|
|
||||||
CAN_T *can = (CAN_T *)NU_MODBASE(name);
|
CAN_T *can = (CAN_T *)NU_MODBASE(name);
|
||||||
uint32_t u8IIDRstatus;
|
uint32_t u8IIDRstatus;
|
||||||
|
|
||||||
u8IIDRstatus = can->IIDR;
|
u8IIDRstatus = can->IIDR;
|
||||||
|
|
||||||
|
@ -110,12 +110,12 @@ static void can_irq(CANName name, int id)
|
||||||
/**************************/
|
/**************************/
|
||||||
if(can->STATUS & CAN_STATUS_RXOK_Msk) {
|
if(can->STATUS & CAN_STATUS_RXOK_Msk) {
|
||||||
can->STATUS &= ~CAN_STATUS_RXOK_Msk; /* Clear Rx Ok status*/
|
can->STATUS &= ~CAN_STATUS_RXOK_Msk; /* Clear Rx Ok status*/
|
||||||
can0_irq_handler(can_irq_ids[id], IRQ_RX);
|
can0_irq_handler(can_irq_ids[id], IRQ_RX);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(can->STATUS & CAN_STATUS_TXOK_Msk) {
|
if(can->STATUS & CAN_STATUS_TXOK_Msk) {
|
||||||
can->STATUS &= ~CAN_STATUS_TXOK_Msk; /* Clear Tx Ok status*/
|
can->STATUS &= ~CAN_STATUS_TXOK_Msk; /* Clear Tx Ok status*/
|
||||||
can0_irq_handler(can_irq_ids[id], IRQ_TX);
|
can0_irq_handler(can_irq_ids[id], IRQ_TX);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**************************/
|
/**************************/
|
||||||
|
|
|
@ -248,58 +248,58 @@ int can_write(can_t *obj, CAN_Message msg, int cc)
|
||||||
STR_CANMSG_T CMsg;
|
STR_CANMSG_T CMsg;
|
||||||
|
|
||||||
CMsg.IdType = (uint32_t)msg.format;
|
CMsg.IdType = (uint32_t)msg.format;
|
||||||
CMsg.FrameType = (uint32_t)!msg.type;
|
CMsg.FrameType = (uint32_t)!msg.type;
|
||||||
CMsg.Id = msg.id;
|
CMsg.Id = msg.id;
|
||||||
CMsg.DLC = msg.len;
|
CMsg.DLC = msg.len;
|
||||||
memcpy((void *)&CMsg.Data[0],(const void *)&msg.data[0], (unsigned int)8);
|
memcpy((void *)&CMsg.Data[0],(const void *)&msg.data[0], (unsigned int)8);
|
||||||
|
|
||||||
return CAN_Transmit((CAN_T *)(obj->can), cc, &CMsg);
|
return CAN_Transmit((CAN_T *)(obj->can), cc, &CMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
int can_read(can_t *obj, CAN_Message *msg, int handle)
|
int can_read(can_t *obj, CAN_Message *msg, int handle)
|
||||||
{
|
{
|
||||||
STR_CANMSG_T CMsg;
|
STR_CANMSG_T CMsg;
|
||||||
|
|
||||||
if(!CAN_Receive((CAN_T *)(obj->can), handle, &CMsg))
|
if(!CAN_Receive((CAN_T *)(obj->can), handle, &CMsg))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
msg->format = (CANFormat)CMsg.IdType;
|
msg->format = (CANFormat)CMsg.IdType;
|
||||||
msg->type = (CANType)!CMsg.FrameType;
|
msg->type = (CANType)!CMsg.FrameType;
|
||||||
msg->id = CMsg.Id;
|
msg->id = CMsg.Id;
|
||||||
msg->len = CMsg.DLC;
|
msg->len = CMsg.DLC;
|
||||||
memcpy(&msg->data[0], &CMsg.Data[0], 8);
|
memcpy(&msg->data[0], &CMsg.Data[0], 8);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int can_mode(can_t *obj, CanMode mode)
|
int can_mode(can_t *obj, CanMode mode)
|
||||||
{
|
{
|
||||||
int success = 0;
|
int success = 0;
|
||||||
switch (mode)
|
switch (mode)
|
||||||
{
|
{
|
||||||
case MODE_RESET:
|
case MODE_RESET:
|
||||||
CAN_LeaveTestMode((CAN_T*)obj->can);
|
CAN_LeaveTestMode((CAN_T*)obj->can);
|
||||||
success = 1;
|
success = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MODE_NORMAL:
|
case MODE_NORMAL:
|
||||||
CAN_EnterTestMode((CAN_T*)(obj->can), CAN_TEST_BASIC_Msk);
|
CAN_EnterTestMode((CAN_T*)(obj->can), CAN_TEST_BASIC_Msk);
|
||||||
success = 1;
|
success = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MODE_SILENT:
|
case MODE_SILENT:
|
||||||
CAN_EnterTestMode((CAN_T*)(obj->can), CAN_TEST_SILENT_Msk);
|
CAN_EnterTestMode((CAN_T*)(obj->can), CAN_TEST_SILENT_Msk);
|
||||||
success = 1;
|
success = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MODE_TEST_LOCAL:
|
case MODE_TEST_LOCAL:
|
||||||
case MODE_TEST_GLOBAL:
|
case MODE_TEST_GLOBAL:
|
||||||
CAN_EnterTestMode((CAN_T*)(obj->can), CAN_TEST_LBACK_Msk);
|
CAN_EnterTestMode((CAN_T*)(obj->can), CAN_TEST_LBACK_Msk);
|
||||||
success = 1;
|
success = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MODE_TEST_SILENT:
|
case MODE_TEST_SILENT:
|
||||||
CAN_EnterTestMode((CAN_T*)(obj->can), CAN_TEST_SILENT_Msk | CAN_TEST_LBACK_Msk);
|
CAN_EnterTestMode((CAN_T*)(obj->can), CAN_TEST_SILENT_Msk | CAN_TEST_LBACK_Msk);
|
||||||
success = 1;
|
success = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue