mirror of https://github.com/ARMmbed/mbed-os.git
Add can_init_frequency for NXP platforms
parent
a912d05f3b
commit
1fe20b281a
|
@ -268,26 +268,30 @@ int can_config_rxmsgobj(can_t *obj) {
|
|||
}
|
||||
|
||||
|
||||
void can_init(can_t *obj, PinName rd, PinName td) {
|
||||
void can_init_freq(can_t *obj, PinName rd, PinName td, int hz) {
|
||||
// Enable power and clock
|
||||
LPC_SYSCON->PRESETCTRL |= PRESETCTRL_CAN_RST_N;
|
||||
LPC_SYSCON->SYSAHBCLKCTRL |= SYSAHBCLKCTRL_CAN;
|
||||
|
||||
|
||||
// Enable Initialization mode
|
||||
if (!(LPC_CAN->CNTL & CANCNTL_INIT)) {
|
||||
LPC_CAN->CNTL |= CANCNTL_INIT;
|
||||
}
|
||||
|
||||
can_frequency(obj, 125000);
|
||||
|
||||
|
||||
can_frequency(obj, hz);
|
||||
|
||||
// Resume operation
|
||||
LPC_CAN->CNTL &= ~CANCNTL_INIT;
|
||||
while ( LPC_CAN->CNTL & CANCNTL_INIT );
|
||||
|
||||
|
||||
// Initialize RX message object
|
||||
can_config_rxmsgobj(obj);
|
||||
}
|
||||
|
||||
void can_init(can_t *obj, PinName rd, PinName td) {
|
||||
can_init_freq(obj, rd, td, 125000);
|
||||
}
|
||||
|
||||
void can_free(can_t *obj) {
|
||||
LPC_SYSCON->SYSAHBCLKCTRL &= ~(SYSAHBCLKCTRL_CAN);
|
||||
LPC_SYSCON->PRESETCTRL &= ~(PRESETCTRL_CAN_RST_N);
|
||||
|
|
|
@ -415,8 +415,7 @@ int can_config_txmsgobj(can_t *obj) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
|
||||
void can_init(can_t *obj, PinName rd, PinName td) {
|
||||
void can_init_freq(can_t *obj, PinName rd, PinName td, int hz) {
|
||||
// Enable power and clock
|
||||
LPC_SYSCON->SYSAHBCLKCTRL1 |= (1UL << 7);
|
||||
LPC_SYSCON->PRESETCTRL1 |= (1UL << 7);
|
||||
|
@ -430,7 +429,7 @@ void can_init(can_t *obj, PinName rd, PinName td) {
|
|||
LPC_SWM->PINASSIGN[6] &= ~(0x00FFFF00L);
|
||||
LPC_SWM->PINASSIGN[6] |= (rd << 16) | (td << 8);
|
||||
|
||||
can_frequency(obj, 100000);
|
||||
can_frequency(obj, hz);
|
||||
|
||||
// Resume operation
|
||||
LPC_C_CAN0->CANCNTL &= ~(1UL << 0);
|
||||
|
@ -442,6 +441,10 @@ void can_init(can_t *obj, PinName rd, PinName td) {
|
|||
can_config_txmsgobj(obj);
|
||||
}
|
||||
|
||||
void can_init(can_t *obj, PinName rd, PinName td) {
|
||||
can_init_freq(obj, rd, td, 100000);
|
||||
}
|
||||
|
||||
void can_free(can_t *obj) {
|
||||
LPC_SYSCON->SYSAHBCLKCTRL1 &= ~(1UL << 7);
|
||||
LPC_SYSCON->PRESETCTRL1 &= ~(1UL << 7);
|
||||
|
|
|
@ -292,7 +292,7 @@ static unsigned int can_speed(unsigned int sclk, unsigned int pclk, unsigned int
|
|||
|
||||
}
|
||||
|
||||
void can_init(can_t *obj, PinName rd, PinName td) {
|
||||
void can_init_freq(can_t *obj, PinName rd, PinName td, int hz) {
|
||||
CANName can_rd = (CANName)pinmap_peripheral(rd, PinMap_CAN_RD);
|
||||
CANName can_td = (CANName)pinmap_peripheral(td, PinMap_CAN_TD);
|
||||
obj->dev = (LPC_CAN_TypeDef *)pinmap_merge(can_rd, can_td);
|
||||
|
@ -313,11 +313,15 @@ void can_init(can_t *obj, PinName rd, PinName td) {
|
|||
|
||||
can_reset(obj);
|
||||
obj->dev->IER = 0; // Disable Interrupts
|
||||
can_frequency(obj, 100000);
|
||||
can_frequency(obj, hz);
|
||||
|
||||
LPC_CANAF->AFMR = ACCF_BYPASS; // Bypass Filter
|
||||
}
|
||||
|
||||
void can_init(can_t *obj, PinName rd, PinName td) {
|
||||
can_init_freq(obj, rd, td, 100000);
|
||||
}
|
||||
|
||||
void can_free(can_t *obj) {
|
||||
switch ((int)obj->dev) {
|
||||
case CAN_1: LPC_SC->PCONP &= ~(1 << 13); break;
|
||||
|
|
|
@ -239,7 +239,7 @@ static unsigned int can_speed(unsigned int pclk, unsigned int cclk, unsigned cha
|
|||
|
||||
}
|
||||
|
||||
void can_init(can_t *obj, PinName rd, PinName td) {
|
||||
void can_init_freq(can_t *obj, PinName rd, PinName td, int hz) {
|
||||
CANName can_rd = (CANName)pinmap_peripheral(rd, PinMap_CAN_RD);
|
||||
CANName can_td = (CANName)pinmap_peripheral(td, PinMap_CAN_TD);
|
||||
obj->dev = (LPC_CAN_TypeDef *)pinmap_merge(can_rd, can_td);
|
||||
|
@ -252,19 +252,23 @@ void can_init(can_t *obj, PinName rd, PinName td) {
|
|||
|
||||
pinmap_pinout(rd, PinMap_CAN_RD);
|
||||
pinmap_pinout(td, PinMap_CAN_TD);
|
||||
|
||||
|
||||
switch ((int)obj->dev) {
|
||||
case CAN_1: obj->index = 0; break;
|
||||
case CAN_2: obj->index = 1; break;
|
||||
}
|
||||
|
||||
|
||||
can_reset(obj);
|
||||
obj->dev->IER = 0; // Disable Interrupts
|
||||
can_frequency(obj, 100000);
|
||||
can_frequency(obj, hz);
|
||||
|
||||
LPC_CANAF->AFMR = ACCF_BYPASS; // Bypass Filter
|
||||
}
|
||||
|
||||
void can_init(can_t *obj, PinName rd, PinName td) {
|
||||
can_init_freq(obj, rd, td, 100000);
|
||||
}
|
||||
|
||||
void can_free(can_t *obj) {
|
||||
switch ((int)obj->dev) {
|
||||
case CAN_1: LPC_SC->PCONP &= ~(1 << 13); break;
|
||||
|
|
|
@ -236,7 +236,7 @@ static unsigned int can_speed(unsigned int pclk, unsigned int cclk, unsigned cha
|
|||
|
||||
}
|
||||
|
||||
void can_init(can_t *obj, PinName rd, PinName td) {
|
||||
void can_init_freq(can_t *obj, PinName rd, PinName td, int hz) {
|
||||
CANName can_rd = (CANName)pinmap_peripheral(rd, PinMap_CAN_RD);
|
||||
CANName can_td = (CANName)pinmap_peripheral(td, PinMap_CAN_TD);
|
||||
obj->dev = (LPC_CAN_TypeDef *)pinmap_merge(can_rd, can_td);
|
||||
|
@ -257,11 +257,15 @@ void can_init(can_t *obj, PinName rd, PinName td) {
|
|||
|
||||
can_reset(obj);
|
||||
obj->dev->IER = 0; // Disable Interrupts
|
||||
can_frequency(obj, 100000);
|
||||
can_frequency(obj, hz);
|
||||
|
||||
LPC_CANAF->AFMR = ACCF_BYPASS; // Bypass Filter
|
||||
}
|
||||
|
||||
void can_init(can_t *obj, PinName rd, PinName td) {
|
||||
can_init_freq(obj, rd, td, 100000);
|
||||
}
|
||||
|
||||
void can_free(can_t *obj) {
|
||||
switch ((int)obj->dev) {
|
||||
case CAN_1: LPC_SC->PCONP &= ~(1 << 13); break;
|
||||
|
|
Loading…
Reference in New Issue