Modify system default print uart

- Add uart_debut_init
freertos
zhaozhongxiang 2019-05-15 13:44:54 +08:00
parent 908689942b
commit d1f33dd8be
7 changed files with 52 additions and 98 deletions

View File

@ -73,13 +73,9 @@ void _init_bsp(int core_id, int number_of_cores)
/* Initialize bss data to 0 */ /* Initialize bss data to 0 */
init_bss(); init_bss();
/* Init UART */ /* Init UART */
uart_init(UART_DEVICE_3);
uart_configure(UART_DEVICE_3, 115200, 8, UART_STOP_1, UART_PARITY_NONE);
uart_set_receive_trigger(UART_DEVICE_3, UART_RECEIVE_FIFO_1);
fpioa_set_function(4, FUNC_UART3_RX); fpioa_set_function(4, FUNC_UART3_RX);
fpioa_set_function(5, FUNC_UART3_TX); fpioa_set_function(5, FUNC_UART3_TX);
sys_register_getchar(uart3_getchar); uart_debug_init(UART_DEVICE_3);
sys_register_putchar(uart3_putchar);
/* Init FPIOA */ /* Init FPIOA */
fpioa_init(); fpioa_init();
/* Register finalization function */ /* Register finalization function */

View File

@ -4,4 +4,6 @@
#include "entry.h" #include "entry.h"
#include "sleep.h" #include "sleep.h"
#include "encoding.h" #include "encoding.h"
#include "syscalls.h"
#include "printf.h"
#endif #endif

View File

@ -76,14 +76,11 @@ void sys_stdin_flush(void);
void __attribute__((noreturn)) sys_exit(int code); void __attribute__((noreturn)) sys_exit(int code);
void setStats(int enable); /**
* @brief Get free memory
#undef putchar *
int putchar(int ch); * @return The size of free memory
void printstr(const char *s); */
void printhex(uint64_t x);
size_t get_free_heap_size(void); size_t get_free_heap_size(void);
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -470,64 +470,12 @@ void uart_set_tat(uart_device_number_t uart_channel, uart_tat_mode_t tat_mode, s
void uart_set_det(uart_device_number_t uart_channel, uart_det_mode_t det_mode, size_t time); void uart_set_det(uart_device_number_t uart_channel, uart_det_mode_t det_mode, size_t time);
/** /**
* @brief Put a char to UART1 * @brief Set the default debug serial port
* *
* @param[in] c The char to put * @param[in] uart_channel Uart index
* *
* @return result
* - Byte On success, returns the written character.
* - EOF On failure, returns EOF and sets the error indicator (see ferror()) on stdout.
*/ */
int uart1_putchar(char c); void uart_debug_init(uart_device_number_t uart_channel);
/**
* @brief Get a byte from UART1
*
* @return byte as int type from UART
* - Byte The character read as an unsigned char cast to an int
* - EOF EOF on end of file or error, no enough byte to read
*/
int uart1_getchar(void);
/**
* @brief Put a char to UART2
*
* @param[in] c The char to put
*
* @return result
* - Byte On success, returns the written character.
* - EOF On failure, returns EOF and sets the error indicator (see ferror()) on stdout.
*/
int uart2_putchar(char c);
/**
* @brief Get a byte from UART2
*
* @return byte as int type from UART
* - Byte The character read as an unsigned char cast to an int
* - EOF EOF on end of file or error, no enough byte to read
*/
int uart2_getchar(void);
/**
* @brief Put a char to UART3
*
* @param[in] c The char to put
*
* @return result
* - Byte On success, returns the written character.
* - EOF On failure, returns EOF and sets the error indicator (see ferror()) on stdout.
*/
int uart3_putchar(char c);
/**
* @brief Get a byte from UART3
*
* @return byte as int type from UART
* - Byte The character read as an unsigned char cast to an int
* - EOF EOF on end of file or error, no enough byte to read
*/
int uart3_getchar(void);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -20,6 +20,7 @@
#include "string.h" #include "string.h"
#include "encoding.h" #include "encoding.h"
#include "bsp.h" #include "bsp.h"
#include "uart.h"
#define SYSCTRL_CLOCK_FREQ_IN0 (26000000UL) #define SYSCTRL_CLOCK_FREQ_IN0 (26000000UL)
@ -1790,8 +1791,10 @@ uint32_t sysctl_pll_set_freq(sysctl_pll_t pll, uint32_t pll_freq)
/* 9. Change CPU CLK to PLL */ /* 9. Change CPU CLK to PLL */
if(pll == SYSCTL_PLL0) if(pll == SYSCTL_PLL0)
{
sysctl_clock_set_clock_select(SYSCTL_CLOCK_SELECT_ACLK, SYSCTL_SOURCE_PLL0); sysctl_clock_set_clock_select(SYSCTL_CLOCK_SELECT_ACLK, SYSCTL_SOURCE_PLL0);
uart_debug_init(-1);
}
return result; return result;
} }

View File

@ -19,6 +19,7 @@
#include "uart.h" #include "uart.h"
#include "utils.h" #include "utils.h"
#include "atomic.h" #include "atomic.h"
#include "syscalls.h"
#define __UART_BRATE_CONST 16 #define __UART_BRATE_CONST 16
@ -95,7 +96,9 @@ static int uart_irq_callback(void *param)
return 0; return 0;
} }
int uart_channel_putc(char c, uart_device_number_t channel) static uart_device_number_t s_uart_debug_channel = UART_DEVICE_3;
static int uart_channel_putc(char c, uart_device_number_t channel)
{ {
while (uart[channel]->LSR & (1u << 5)) while (uart[channel]->LSR & (1u << 5))
continue; continue;
@ -103,7 +106,7 @@ int uart_channel_putc(char c, uart_device_number_t channel)
return c & 0xff; return c & 0xff;
} }
int uart_channel_getc(uart_device_number_t channel) static int uart_channel_getc(uart_device_number_t channel)
{ {
/* If received empty */ /* If received empty */
if (!(uart[channel]->LSR & 1)) if (!(uart[channel]->LSR & 1))
@ -112,34 +115,39 @@ int uart_channel_getc(uart_device_number_t channel)
return (char)(uart[channel]->RBR & 0xff); return (char)(uart[channel]->RBR & 0xff);
} }
int uart1_putchar(char c) static int uart_debug_putchar(char c)
{ {
return uart_channel_putc(c, UART_DEVICE_1); return uart_channel_putc(c, s_uart_debug_channel);
} }
int uart1_getchar(void) static int uart_debug_getchar(void)
{ {
return uart_channel_getc(UART_DEVICE_1); return uart_channel_getc(s_uart_debug_channel);
} }
int uart2_putchar(char c) void uart_debug_init(uart_device_number_t uart_channel)
{ {
return uart_channel_putc(c, UART_DEVICE_2); volatile bool v_uart_reset_flag = false;
} if(uart_channel >= UART_DEVICE_1 && uart_channel <= UART_DEVICE_3)
{
int uart2_getchar(void) s_uart_debug_channel = uart_channel;
{ v_uart_reset_flag = true;
return uart_channel_getc(UART_DEVICE_2); }
} uart_init(s_uart_debug_channel);
uart_configure(s_uart_debug_channel, 115200, 8, UART_STOP_1, UART_PARITY_NONE);
int uart3_putchar(char c) uart_set_receive_trigger(s_uart_debug_channel, UART_RECEIVE_FIFO_1);
{ if(v_uart_reset_flag)
return uart_channel_putc(c, UART_DEVICE_3); {
} sys_register_getchar(uart_debug_getchar);
sys_register_putchar(uart_debug_putchar);
int uart3_getchar(void) }
{ else
return uart_channel_getc(UART_DEVICE_3); {
if(sys_getchar == NULL)
sys_register_getchar(uart_debug_getchar);
if(sys_putchar == NULL)
sys_register_putchar(uart_debug_putchar);
}
} }
static int uart_dma_callback(void *ctx) static int uart_dma_callback(void *ctx)

View File

@ -12,9 +12,8 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include <stdio.h> #include <bsp.h>
#include <uart.h> #include <sysctl.h>
#include "bsp.h"
int core1_function(void *ctx) int core1_function(void *ctx)
{ {
@ -23,9 +22,9 @@ int core1_function(void *ctx)
while(1); while(1);
} }
int main(void)
int main()
{ {
sysctl_pll_set_freq(SYSCTL_PLL0, 800000000);
uint64_t core = current_coreid(); uint64_t core = current_coreid();
int data; int data;
printf("Core %ld Hello world\n", core); printf("Core %ld Hello world\n", core);
@ -35,7 +34,8 @@ int main()
sys_stdin_flush(); sys_stdin_flush();
scanf("%d", &data); scanf("%d", &data);
printf("Data is %d\n", data); printf("\nData is %d\n", data);
while(1) while(1)
continue; continue;
return 0;
} }