ecos - Gestores de dispositivos gestores de dispositivos ( device drivers ) interface aplicacional (API) gestor de linha série raw serial driver tty driver ecos - device driver - user API cyg_io_lookup cyg_io_write cyg_io_read cyg_io_get_config cyg_io_set_config - obter identificador a partir de nome - operações de escrita - operações de leitura - obter informação de configuração - especificar configuração 1
Obter identificador ( handle ) a partir de nome Cyg_ErrNo cyg_io_lookup( const char *name, cyg_io_handle_t *handle ) Exemplo de nome: /dev/ser0 Escrever dados no dispositivo Cyg_ErrNo cyg_io_write( cyg_io_handle_t handle, const void *buf, cyg_uint32 *len ) buf len - dados a enviar para o dispositivo - dimensão dos dados a escrever / escritos 2
Ler dados do dispositivo Cyg_ErrNo cyg_io_read( cyg_io_handle_t handle, void *buf, cyg_uint32 *len ) buf len - vector para receber dados do dispositivo - dimensão dos dados a ler / lidos Obter configuração do dispositivo Cyg_ErrNo cyg_io_get_config( cyg_io_handle_t handle, cyg_uint32 key, void *buf, cyg_uint32 *len ) key buf len - tipo de informação a obter - estrutura onde colocar a informação (depende de key) - dimensão da informação a obter / obtida 3
Modificar configuração do dispositivo Cyg_ErrNo cyg_io_set_config( cyg_io_handle_t handle, cyg_uint32 key, const void *buf, cyg_uint32 *len ) key buf len - tipo de parâmetros a modificar - novos valores dos parâmetros (depende de key) - dimensão ocupada pelos novos parâmetros Estruturas de dados associadas ao dispositivo série typedef struct { cyg_serial_baud_rate_t cyg_serial_stop_bits_t cyg_serial_parity_t cyg_serial_word_length_t cyg_uint32 baud; stop; parity; word_length; flags; } cyg_serial_info_t; 4
word_length -- número de bits por caracter CYGNUM_SERIAL_WORD_LENGTH_5 CYGNUM_SERIAL_WORD_LENGTH_6 CYGNUM_SERIAL_WORD_LENGTH_7 CYGNUM_SERIAL_WORD_LENGTH_8 baud -- baud rate CYGNUM_SERIAL_BAUD_50... CYGNUM_SERIAL_BAUD_9600 CYGNUM_SERIAL_BAUD_14400 CYGNUM_SERIAL_BAUD_19200 CYGNUM_SERIAL_BAUD_38400 CYGNUM_SERIAL_BAUD_57600 CYGNUM_SERIAL_BAUD_115200 CYGNUM_SERIAL_BAUD_234000 stop -- número de stop bits CYGNUM_SERIAL_STOP_1 CYGNUM_SERIAL_STOP_1_5 CYGNUM_SERIAL_STOP_2 parity -- paridade CYGNUM_SERIAL_PARITY_NONE CYGNUM_SERIAL_PARITY_EVEN CYGNUM_SERIAL_PARITY_ODD CYGNUM_SERIAL_PARITY_MARK CYGNUM_SERIAL_PARITY_SPACE 5
flags -- máscara de bits que controla o comportamento do gestor de dispositivo série CYG_SERIAL_FLAGS_xxx: #define CYG_SERIAL_FLAGS_RTSCTS 0x0001 Se este bit estiver activo, a porta série é colocada no modo hardware handshake. Neste modo, os pinos CTS e RTS controlam quando é que os dados podem ser enviados / recebidos. Este bit é ignorado caso o hardware não suporte este modo de funcionamento. typedef struct { cyg_int32 cyg_int32 cyg_int32 cyg_int32 rx_bufsize; rx_count; tx_bufsize; tx_count; } cyg_serial_buf_info_t; rx_bufsize rx_count tx_bufsize tx_count -- tamanho do buffer de recepção -- número corrente de bytes no buffer de recepção -- tamanho do buffer de transmissão -- número corrente de bytes no buffer de transmissão Todos estes valores são colocados a zero no caso do dispositivo não suportar armazenamento ( buffering ) (i.e. dispositivo acedido por polling ). 6
Valores de key e tipo de informação CYG_IO_GET_CONFIG_SERIAL_INFO cyg_serial_info_t Função: This function retrieves the current state of the driver and hardware. This information contains fields for hardware baud rate, number of stop bits, and parity mode. It also includes a set of flags that control the port, such as hardware flow control. CYG_IO_GET_CONFIG_SERIAL_BUFFER_INFO cyg_serial_buf_info_t This function retrieves the current state of the software buffers in the serial drivers. For both receive and transmit buffers it returns the total buffer size and the current number of bytes occupied in the buffer. It does not take into account any buffering such as FIFOs or holding registers that the serial device itself may have. 7
CYG_IO_GET_CONFIG_SERIAL_OUTPUT_DRAIN void * This function waits for any buffered output to complete. This function only completes when there is no more data remaining to be sent to the device. CYG_IO_GET_CONFIG_SERIAL_OUTPUT_FLUSH void * This function discards any buffered output for the device. 8
CYG_IO_GET_CONFIG_SERIAL_INPUT_DRAIN void * This function discards any buffered input for the device. CYG_IO_GET_CONFIG_SERIAL_ABORT void* This function will cause any pending read or write calls on this device to return with -EABORT. 9
CYG_IO_GET_CONFIG_SERIAL_READ_BLOCKING cyg_uint32 (values 0 or 1) This function will read back the blocking-mode setting for read calls on this device. This call is only available if the configuration option CYGOPT_IO_SERIAL_SUPPORT_NONBLOCKING is enabled. CYG_IO_GET_CONFIG_SERIAL_WRITE_BLOCKING cyg_uint32 (values 0 or 1) This function will read back the blocking-mode setting for write calls on this device. This call is only available if the configuration option CYGOPT_IO_SERIAL_SUPPORT_NONBLOCKING is enabled. 10
CYG_IO_SET_CONFIG_SERIAL_INFO cyg_serial_info_t This function updates the information for the driver and hardware. The information contains fields for hardware baud rate, number of stop bits, and parity mode. It also includes a set of flags that control the port, such as hardware flow control. CYG_IO_SET_CONFIG_SERIAL_READ_BLOCKING cyg_uint32 (values 0 or 1) This function will set the blocking-mode for read calls on this device. This call is only available if the configuration option CYGOPT_IO_SERIAL_SUPPORT_NONBLOCKING is enabled. 11
CYG_IO_SET_CONFIG_SERIAL_WRITE_BLOCKING cyg_uint32 (values 0 or 1) This function will set the blocking-mode for write calls on this device. This call is only available if the configuration option CYGOPT_IO_SERIAL_SUPPORT_NONBLOCKING is enabled. #include <cyg/kernel/kapi.h> #include <cyg/error/codes.h> #include <cyg/io/io.h> #include <cyg/io/serialio.h> #include <cyg/io/config_keys.h> #include <stdio.h> Exemplo int main(void) { Cyg_ErrNo err; cyg_io_handle_t serh; char c; char bufr[10]; char bufw[10]="123456789"; int n; printf("ola, ecos world!\n"); err = cyg_io_lookup("/dev/ser0", &serh); printf("lookup err=%x\n", err); while(1){ c = getchar(); if (c=='l') { n = 10; err = cyg_io_read(serh, bufr, &n); printf("io_read err=%x, n=%d buf=%s\n", err, n, bufr); } if (c=='w') { n = 10; err = cyg_io_write(serh, bufw, &n); printf("io_write err=%x, n=%d buf=%s\n", err, n, bufw); } } return 0; } 12