From a927b480494b6c9110539aabaf9df5b41cba1e8e Mon Sep 17 00:00:00 2001 From: reynoldxu Date: Wed, 24 Jul 2013 18:31:26 +0800 Subject: [PATCH 1/5] modify codes for fractional divider --- bsp/K60Fxxxx/drivers/drv_uart.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/bsp/K60Fxxxx/drivers/drv_uart.c b/bsp/K60Fxxxx/drivers/drv_uart.c index d0ccb043e5..b4bb07d638 100644 --- a/bsp/K60Fxxxx/drivers/drv_uart.c +++ b/bsp/K60Fxxxx/drivers/drv_uart.c @@ -39,19 +39,25 @@ static struct k60_serial_device _k60_node = static rt_err_t _configure(struct rt_serial_device *serial, struct serial_configure *cfg) { - unsigned int reg_C1 = 0,reg_BDH = 0,reg_BDL = 0,reg_S2; + unsigned int reg_C1 = 0,reg_C4 = 0,reg_BDH = 0,reg_BDL = 0,reg_S2,reg_BRFA=0; unsigned int cal_SBR = 0; UART_Type *uart_reg; + /* ref : drivers\system_MK60F12.c Line 64 ,BusClock = 60MHz */ uart_reg = ((struct k60_serial_device *)serial->parent.user_data)->baseAddress; + + //calc SBR cal_SBR = 60000000 / (16 * cfg->baud_rate); - reg_BDH = (cal_SBR & 0x1FFF) >> 8 & 0x00FF; - reg_BDL = cal_SBR & 0x00FF; //calc baud_rate reg_BDH = (cal_SBR & 0x1FFF) >> 8 & 0x00FF; reg_BDL = cal_SBR & 0x00FF; + //fractional divider + reg_BRFA = ((60000*32000)/(cfg->baud_rate * 16)) - (cal_SBR * 32); + + reg_C4 = (unsigned char)(reg_BRFA & 0x001F); + //calc bit_order if (cfg->bit_order == BIT_ORDER_LSB) reg_S2 &= ~(UART_S2_MSBF_MASK<BDH = reg_BDH; uart_reg->BDL = reg_BDL; uart_reg->C1 = reg_C1; + uart_reg->C4 = reg_C4; uart_reg->S2 = reg_S2; uart_reg->S2 = 0; From 421d980b07e3d04716d19a762ce31e0eef2c140b Mon Sep 17 00:00:00 2001 From: reynoldxu Date: Wed, 24 Jul 2013 12:07:09 +0800 Subject: [PATCH 2/5] add NRZ feature on K60 --- bsp/K60Fxxxx/K60/K60.pro | 43 ++++++++++++++++++++++++++ bsp/K60Fxxxx/drivers/drv_uart.c | 55 ++++++++++++++++++++++++++------- 2 files changed, 86 insertions(+), 12 deletions(-) create mode 100644 bsp/K60Fxxxx/K60/K60.pro diff --git a/bsp/K60Fxxxx/K60/K60.pro b/bsp/K60Fxxxx/K60/K60.pro new file mode 100644 index 0000000000..7611330024 --- /dev/null +++ b/bsp/K60Fxxxx/K60/K60.pro @@ -0,0 +1,43 @@ +HEADERS += \ + ../rtconfig.h \ + ../drivers/led.h \ + ../drivers/drv_uart.h \ + ../drivers/board.h \ + ../../../components/drivers/include/rtdevice.h \ + ../../../components/drivers/include/drivers/serial.h \ + ../../../include/rtthread.h \ + ../../../include/rtservice.h \ + ../../../include/rtm.h \ + ../../../include/rthw.h \ + ../../../include/rtdef.h \ + ../../../include/rtdebug.h \ + ../../../src/module.h \ + ../../../../../../../../Keil/ARM/INC/Freescale/Kinetis/MK60F12.H + +SOURCES += \ + ../applications/startup.c \ + ../applications/application.c \ + ../drivers/system_MK60F12.c \ + ../drivers/led.c \ + ../drivers/drv_uart.c \ + ../drivers/board.c \ + ../../../components/drivers/serial/serial.c \ + ../../../src/timer.c \ + ../../../src/thread.c \ + ../../../src/slab.c \ + ../../../src/scheduler.c \ + ../../../src/object.c \ + ../../../src/module.c \ + ../../../src/mempool.c \ + ../../../src/memheap.c \ + ../../../src/mem.c \ + ../../../src/kservice.c \ + ../../../src/irq.c \ + ../../../src/ipc.c \ + ../../../src/idle.c \ + ../../../src/device.c \ + ../../../src/clock.c + +OTHER_FILES += \ + ../drivers/startup_MK60F12.s \ + ../../../src/SConscript diff --git a/bsp/K60Fxxxx/drivers/drv_uart.c b/bsp/K60Fxxxx/drivers/drv_uart.c index b4bb07d638..c621713c37 100644 --- a/bsp/K60Fxxxx/drivers/drv_uart.c +++ b/bsp/K60Fxxxx/drivers/drv_uart.c @@ -39,52 +39,83 @@ static struct k60_serial_device _k60_node = static rt_err_t _configure(struct rt_serial_device *serial, struct serial_configure *cfg) { - unsigned int reg_C1 = 0,reg_C4 = 0,reg_BDH = 0,reg_BDL = 0,reg_S2,reg_BRFA=0; + unsigned int reg_C1 = 0,reg_C3 = 0,reg_C4 = 0,reg_BDH = 0,reg_BDL = 0,reg_S2,reg_BRFA=0; unsigned int cal_SBR = 0; UART_Type *uart_reg; - /* ref : drivers\system_MK60F12.c Line 64 ,BusClock = 60MHz */ + /* ref : drivers\system_MK60F12.c Line 64 ,BusClock = 60MHz + * calculate baud_rate + */ uart_reg = ((struct k60_serial_device *)serial->parent.user_data)->baseAddress; - //calc SBR + /* calc SBR */ cal_SBR = 60000000 / (16 * cfg->baud_rate); - //calc baud_rate + /* calc baud_rate */ reg_BDH = (cal_SBR & 0x1FFF) >> 8 & 0x00FF; reg_BDL = cal_SBR & 0x00FF; - //fractional divider + /* fractional divider */ reg_BRFA = ((60000*32000)/(cfg->baud_rate * 16)) - (cal_SBR * 32); reg_C4 = (unsigned char)(reg_BRFA & 0x001F); - //calc bit_order + /* + * set bit order + */ if (cfg->bit_order == BIT_ORDER_LSB) reg_S2 &= ~(UART_S2_MSBF_MASK<bit_order == BIT_ORDER_MSB) reg_S2 |= UART_S2_MSBF_MASK<data_bits == DATA_BITS_8) reg_C1 &= ~(UART_C1_M_MASK<data_bits == DATA_BITS_9) reg_C1 |= UART_C1_M_MASK<parity == PARITY_NONE) - reg_C1 &= ~(UART_C1_PE_MASK<parity == PARITY_ODD) - reg_C1 |= UART_C1_PT_MASK<parity == PARITY_EVEN) - reg_C1 &= ~(UART_C1_PT_MASK<invert != NRZ_NORMAL) + { + /* not in normal mode ,set inverted polarity */ + reg_C3 |= UART_C3_TXINV_MASK; } switch( (int)uart_reg) { + /* Tower board use UART5 for communication + * if you're using other board + * set clock and pin map for UARTx + */ case UART5_BASE: //set UART5 clock From 8f0fffc1323ff393bf8365aaa09e15e4ae7fa4bf Mon Sep 17 00:00:00 2001 From: reynoldxu Date: Wed, 24 Jul 2013 17:14:54 +0800 Subject: [PATCH 3/5] fix a bug in rt_hw_uart_init() where u CAN NOT init some feature. --- bsp/K60Fxxxx/drivers/drv_uart.c | 2 -- components/drivers/serial/serial.c | 4 ++++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/bsp/K60Fxxxx/drivers/drv_uart.c b/bsp/K60Fxxxx/drivers/drv_uart.c index c621713c37..4264af4d4c 100644 --- a/bsp/K60Fxxxx/drivers/drv_uart.c +++ b/bsp/K60Fxxxx/drivers/drv_uart.c @@ -241,8 +241,6 @@ void rt_hw_uart_init(void) rt_hw_serial_register(&_k60_serial, "uart5", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_STREAM, (void*)&_k60_node); - - rt_device_control(&_k60_serial.parent, RT_DEVICE_CTRL_SET_INT, 0); } void rt_hw_console_output(const char *str) diff --git a/components/drivers/serial/serial.c b/components/drivers/serial/serial.c index 1f6b29e261..bcc9f431d9 100644 --- a/components/drivers/serial/serial.c +++ b/components/drivers/serial/serial.c @@ -145,7 +145,11 @@ static rt_err_t rt_serial_init(struct rt_device *dev) serial_ringbuffer_init(serial->int_rx); if (dev->flag & RT_DEVICE_FLAG_INT_TX) + { + serial->ops->control(serial, RT_DEVICE_CTRL_SET_INT, (void *)RT_NULL); serial_ringbuffer_init(serial->int_tx); + serial->int_sending_flag = RT_FALSE; + } if (dev->flag & RT_DEVICE_FLAG_DMA_TX) { From 151ce31be8c6d8c1e90b0b332c07beb232f32d45 Mon Sep 17 00:00:00 2001 From: reynoldxu Date: Wed, 24 Jul 2013 18:38:16 +0800 Subject: [PATCH 4/5] delete K60.pro --- bsp/K60Fxxxx/K60/K60.pro | 43 ---------------------------------------- 1 file changed, 43 deletions(-) delete mode 100644 bsp/K60Fxxxx/K60/K60.pro diff --git a/bsp/K60Fxxxx/K60/K60.pro b/bsp/K60Fxxxx/K60/K60.pro deleted file mode 100644 index 7611330024..0000000000 --- a/bsp/K60Fxxxx/K60/K60.pro +++ /dev/null @@ -1,43 +0,0 @@ -HEADERS += \ - ../rtconfig.h \ - ../drivers/led.h \ - ../drivers/drv_uart.h \ - ../drivers/board.h \ - ../../../components/drivers/include/rtdevice.h \ - ../../../components/drivers/include/drivers/serial.h \ - ../../../include/rtthread.h \ - ../../../include/rtservice.h \ - ../../../include/rtm.h \ - ../../../include/rthw.h \ - ../../../include/rtdef.h \ - ../../../include/rtdebug.h \ - ../../../src/module.h \ - ../../../../../../../../Keil/ARM/INC/Freescale/Kinetis/MK60F12.H - -SOURCES += \ - ../applications/startup.c \ - ../applications/application.c \ - ../drivers/system_MK60F12.c \ - ../drivers/led.c \ - ../drivers/drv_uart.c \ - ../drivers/board.c \ - ../../../components/drivers/serial/serial.c \ - ../../../src/timer.c \ - ../../../src/thread.c \ - ../../../src/slab.c \ - ../../../src/scheduler.c \ - ../../../src/object.c \ - ../../../src/module.c \ - ../../../src/mempool.c \ - ../../../src/memheap.c \ - ../../../src/mem.c \ - ../../../src/kservice.c \ - ../../../src/irq.c \ - ../../../src/ipc.c \ - ../../../src/idle.c \ - ../../../src/device.c \ - ../../../src/clock.c - -OTHER_FILES += \ - ../drivers/startup_MK60F12.s \ - ../../../src/SConscript From 10c75c3dc6d5d0e1653384a9cf94f74fe1549900 Mon Sep 17 00:00:00 2001 From: reynoldxu Date: Thu, 25 Jul 2013 10:18:33 +0800 Subject: [PATCH 5/5] remove a var for INT_TX. --- components/drivers/serial/serial.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/components/drivers/serial/serial.c b/components/drivers/serial/serial.c index bcc9f431d9..c7b8e79b2b 100644 --- a/components/drivers/serial/serial.c +++ b/components/drivers/serial/serial.c @@ -146,9 +146,12 @@ static rt_err_t rt_serial_init(struct rt_device *dev) if (dev->flag & RT_DEVICE_FLAG_INT_TX) { + /* not supported yet */ + /* serial->ops->control(serial, RT_DEVICE_CTRL_SET_INT, (void *)RT_NULL); serial_ringbuffer_init(serial->int_tx); serial->int_sending_flag = RT_FALSE; + */ } if (dev->flag & RT_DEVICE_FLAG_DMA_TX)