Add can_init_frequency for NXP platforms

pull/4165/head
adustm 2017-04-24 18:22:56 +02:00
parent a912d05f3b
commit 1fe20b281a
5 changed files with 36 additions and 17 deletions

View File

@ -268,7 +268,7 @@ 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;
@ -278,7 +278,7 @@ void can_init(can_t *obj, PinName rd, PinName td) {
LPC_CAN->CNTL |= CANCNTL_INIT;
}
can_frequency(obj, 125000);
can_frequency(obj, hz);
// Resume operation
LPC_CAN->CNTL &= ~CANCNTL_INIT;
@ -288,6 +288,10 @@ void can_init(can_t *obj, PinName rd, PinName td) {
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);

View File

@ -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);

View File

@ -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;

View File

@ -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);
@ -260,11 +260,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;

View File

@ -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;