📄 console_drv.c
字号:
* parity: desired parity to set.
---------------------------------------------------------------*/
UI32_T console_set_parity(UI32_T parity)
{
if (parity==console_parm_data.parity)
return(0);
if ((parity>=CONSOLE_PARITY_NONE) ||
(parity<=CONSOLE_PARITY_SPACE))
{
console_parm_data.parity=parity;
console_set_parm();
return(0);
}
else
return(1);
}
/*--------------------------------------------------------------
* ROUTINE NAME - console_get_stopbits
*---------------------------------------------------------------
* Get the current uart driver stop bits in use.
*
* RETURN:
* Stop bits in use of the uart driver.
---------------------------------------------------------------*/
UI32_T console_get_stopbits()
{
return(console_parm_data.stop_bits);
}
/*--------------------------------------------------------------
* ROUTINE NAME - console_set_stopbits
*---------------------------------------------------------------
* Set the desired stop bits to the uart device.
*
* INPUT:
* stopbits: desired stop bits to set.
---------------------------------------------------------------*/
UI32_T console_set_stopbits(UI32_T stopbits)
{
if (stopbits==console_parm_data.stop_bits)
return(0);
if ((stopbits==CONSOLE_STOP_1) ||
(stopbits==CONSOLE_STOP_2))
{
console_parm_data.stop_bits=stopbits;
console_set_parm();
return(0);
}
else
return(1);
}
/*--------------------------------------------------------------
* ROUTINE NAME - console_get_block_mode
*---------------------------------------------------------------
* Get the current block mode of uart driver stop.
*
* RETURN:
* block mode
---------------------------------------------------------------*/
UI32_T console_get_block_mode()
{
return(console_parm_data.block_mode);
}
/*--------------------------------------------------------------
* ROUTINE NAME - console_set_block_mode
*---------------------------------------------------------------
* Set the desired block mode to the uart device.
*
* INPUT:
* block_mode: desired block mode to set.
---------------------------------------------------------------*/
UI32_T console_set_block_mode(UI32_T block_mode)
{
if (block_mode==console_parm_data.block_mode)
return(0);
if ((block_mode==CONSOLE_BLOCK_MODE) ||
(block_mode==CONSOLE_NONBLOCK_MODE))
{
console_parm_data.block_mode=block_mode;
console_set_parm();
return(0);
}
else
return(1);
}
/*--------------------------------------------------------------
* ROUTINE NAME - console_get_parm
*---------------------------------------------------------------
* Get the current uart driver parameters in used,
* including baudrate, data bits, parity, stop bits.
*
* INPUT:
* *parms_P -- pointer to parmameter
---------------------------------------------------------------*/
UI32_T console_get_parm(CONSOLE_PARM_T *parms_P)
{
cyg_serial_info_t serial_info;
cyg_tty_info_t tty_info;
cyg_uint32 len, blocking;
ULONG rc;
len = sizeof(serial_info);
rc = cyg_io_get_config(console_serial_handle, CYG_IO_GET_CONFIG_SERIAL_INFO, (void *)&serial_info, &len);
if (rc != ENOERR) {
dprintf("Can't get serial config - DEVIO error: %lu\n", rc);
return(1);
}
len = sizeof(tty_info);
rc = cyg_io_get_config(console_tty_handle, CYG_IO_GET_CONFIG_TTY_INFO, &tty_info, &len);
if (rc != ENOERR) {
dprintf("Can't get tty config - DEVIO error: %lu\n", rc);
return(1);
}
len = sizeof(cyg_uint32);
rc = cyg_io_get_config(console_serial_handle, CYG_IO_GET_CONFIG_READ_BLOCKING, (void *)&blocking, &len);
if (rc != ENOERR) {
dprintf("Can't get serial blocking config - DEVIO error: %lu\n", rc);
while (rc);
return(1);
}
parms_P->block_mode = (blocking)? CONSOLE_BLOCK_MODE:CONSOLE_NONBLOCK_MODE;
parms_P->echo_mode = (tty_info.tty_in_flags & CYG_TTY_IN_FLAGS_ECHO) ?
CONSOLE_ECHO_MODE : CONSOLE_NO_ECHO_MODE;
parms_P->bin_mode = (tty_info.tty_in_flags & CYG_TTY_IN_FLAGS_BINARY) ?
CONSOLE_BINARY_MODE : CONSOLE_NON_BINARY_MODE;
parms_P->nl_to_crlf = (tty_info.tty_out_flags & CYG_TTY_OUT_FLAGS_CRLF) ?
CONSOLE_NL2CRLF : CONSOLE_NO_NL2CRLF;
switch (serial_info.baud)
{
case CYGNUM_SERIAL_BAUD_9600:
parms_P->baud_rate = 9600;
break;
case CYGNUM_SERIAL_BAUD_19200:
parms_P->baud_rate = 19200;
break;
case CYGNUM_SERIAL_BAUD_38400:
parms_P->baud_rate = 38400;
break;
case CYGNUM_SERIAL_BAUD_57600:
parms_P->baud_rate = 57600;
break;
default: break;
}
parms_P->parity = serial_info.parity;
parms_P->data_bits = serial_info.word_length;
parms_P->stop_bits = serial_info.stop;
return 0;
}
/*--------------------------------------------------------------
* ROUTINE NAME - console_drv_SetParms
*---------------------------------------------------------------
* FUNCTION:
* This routine set parameters to the uart driver, including
* baudrate, data bits, parity, stop bits. This routine is
* usually used by other driver or BSP modules.
*
* INPUT:
* baudrate_P -- baudrate of the uart
* databits_P -- data bits of the uart
* parity_P -- parity setting of the uart
* stopbits_P -- stop bits of the uart
---------------------------------------------------------------*/
UI32_T console_set_parm()
{
CONSOLE_PARM_T *parms_P= &console_parm_data;
cyg_serial_info_t serial_info;
cyg_tty_info_t tty_info;
cyg_uint32 len, blocking;
ULONG rc;
len = sizeof(serial_info);
rc = cyg_io_get_config(console_serial_handle, CYG_IO_GET_CONFIG_SERIAL_INFO, (void *)&serial_info, &len);
if (rc != ENOERR) {
dprintf("Can't get serial config - DEVIO error: %lu\n", rc);
while (rc);
return(1);
}
len = sizeof(tty_info);
rc = cyg_io_get_config(console_tty_handle, CYG_IO_GET_CONFIG_TTY_INFO, &tty_info, &len);
if (rc != ENOERR) {
dprintf("Can't get tty config - DEVIO error: %lu\n", rc);
while (rc);
return(1);
}
len = sizeof(cyg_uint32);
rc = cyg_io_get_config(console_serial_handle, CYG_IO_GET_CONFIG_READ_BLOCKING, (void *)&blocking, &len);
if (rc != ENOERR) {
dprintf("Can't get serial blocking config - DEVIO error: %lu\n", rc);
while (rc);
return(1);
}
if (parms_P->nl_to_crlf==CONSOLE_NL2CRLF)
{
tty_info.tty_out_flags |= CYG_TTY_OUT_FLAGS_CRLF;
tty_info.tty_in_flags |= CYG_TTY_IN_FLAGS_CRLF;
}
else
{
tty_info.tty_out_flags &= ~CYG_TTY_OUT_FLAGS_CRLF;
tty_info.tty_in_flags &= ~CYG_TTY_IN_FLAGS_CRLF;
}
if (parms_P->echo_mode==CONSOLE_ECHO_MODE)
{
tty_info.tty_in_flags |= CYG_TTY_IN_FLAGS_ECHO;
}
else
{
tty_info.tty_in_flags &= ~CYG_TTY_IN_FLAGS_ECHO;
}
if (parms_P->bin_mode==CONSOLE_BINARY_MODE)
{
tty_info.tty_in_flags |= CYG_TTY_IN_FLAGS_BINARY;
}
else
{
tty_info.tty_in_flags &= ~CYG_TTY_IN_FLAGS_BINARY;
}
blocking=(parms_P->block_mode==CONSOLE_BLOCK_MODE)? 1:0;;
switch (parms_P->baud_rate)
{
case 9600:
serial_info.baud = CYGNUM_SERIAL_BAUD_9600;
break;
case 19200:
serial_info.baud = CYGNUM_SERIAL_BAUD_19200;
break;
case 38400:
serial_info.baud = CYGNUM_SERIAL_BAUD_38400;
break;
case 57600:
serial_info.baud = CYGNUM_SERIAL_BAUD_57600;
break;
}
serial_info.parity=parms_P->parity;
serial_info.word_length = parms_P->data_bits;
serial_info.stop = parms_P->stop_bits;
len = sizeof(serial_info);
rc = cyg_io_set_config(console_serial_handle, CYG_IO_SET_CONFIG_SERIAL_INFO, (void *)&serial_info, &len);
if (rc != ENOERR) {
dprintf("Can't set serial config - DEVIO error: %lu\n", rc);
return (1);
}
len = sizeof(cyg_uint32);
rc = cyg_io_set_config(console_serial_handle, CYG_IO_SET_CONFIG_READ_BLOCKING, (void *)&blocking, &len);
if (rc != ENOERR) {
dprintf("Can't set serial blocking config - DEVIO error: %lu\n", rc);
return (1);
}
len = sizeof(tty_info);
rc = cyg_io_set_config(console_tty_handle, CYG_IO_SET_CONFIG_TTY_INFO, (void *)&tty_info, &len);
if (rc != ENOERR) {
dprintf("Can't set tty config - DEVIO error: %lu\n", rc);
return (1);
}
return 0;
}
char dprintf_buf[256];
void dprintf(char *fmt, ... )
{
va_list argptr;
cyg_scheduler_lock();
va_start(argptr, fmt);
vsnprintf(dprintf_buf, 255, fmt, argptr);
console_putstr(dprintf_buf);
va_end(argptr);
cyg_scheduler_unlock();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -