#include <avr/io.h>
#include "scd_logger.h"
Go to the source code of this file.
Enumerations | |
enum | AT_CMD { AT_NONE, AT_CRST, AT_CTERM, AT_CLET, AT_CGEE, AT_CEEE, AT_CGBM, AT_CCINIT, AT_CCAPDU, AT_CCEND, AT_DUMMY } |
Functions | |
char * | ProcessSerialData (const char *data, log_struct_t *logger) |
Process serial data received from the host. | |
uint8_t | ParseATCommand (const char *data, AT_CMD *command, char **atparams) |
Parse an AT command received from the host. | |
uint8_t | SendEEPROMHexVSerial () |
Send EEPROM content as Intel Hex format to the virtual serial port. | |
void | TerminalVSerial (log_struct_t *logger) |
Virtual Serial Terminal application. | |
uint8_t | hexCharsToByte (char c1, char c2) |
Convert two hex digit characters into a byte. | |
char | nibbleToHexChar (uint8_t b, uint8_t high) |
Convert a nibble into a hex char. | |
Variables | |
uint8_t | lcdAvailable |
uint16_t | revision |
uint8_t | selected |
serial.h header file
This file defines the methods and commands for serial communication between the SCD and a host.
These functions are not microcontroller dependent but they are intended for the AVR 8-bit architecture
Copyright (C) 2012 Omar Choudary (omar.choudary@cl.cam.ac.uk)
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Definition in file serial.h.
enum AT_CMD |
uint8_t hexCharsToByte | ( | char | c1, | |
char | c2 | |||
) |
Convert two hex digit characters into a byte.
Convert 2 hexadecimal characters ('0' to '9', 'A' to 'F') into its binary/hexa representation
c1 | the most significant hexa character | |
c2 | the least significant hexa character |
char nibbleToHexChar | ( | uint8_t | b, | |
uint8_t | high | |||
) |
Convert a nibble into a hex char.
Convert a nibble into a hexadecimal character ('0' to '9', 'A' to 'F')
b | the byte containing the binary representation | |
high | set to 1 if high nibble should be converted, zero if the low nibble is desired. Example: byteToHexChar(0xF3, 1) returns "F". |
uint8_t ParseATCommand | ( | const char * | data, | |
AT_CMD * | atcmd, | |||
char ** | atparams | |||
) |
Parse an AT command received from the host.
This method parses a data stream that should correspond to an AT command and returns the type of command and any parameters.
data | a NUL ('') terminated string representing the data received from the host | |
atcmd | stores the type of command in data if parsing is successful. The caller is responsible for allocating space for this. | |
atparams | points to the place in data where the parameters of the command are located or is NULL if there are no parameters |
char* ProcessSerialData | ( | const char * | data, | |
log_struct_t * | logger | |||
) |
Process serial data received from the host.
This method handles the data received from the serial or virtual serial port.
The SCD should make any necessary processing and then return a response data. However sending a command (e.g. CTERM or CRST) that will reset the SCD will have the obvious consequence that no response will be received. Even more the communication to the host will be interrupted so the host should take care of this.
data | a NUL ('') terminated string representing the data to be processed by the SCD, as sent by the serial host | |
logger | the log structure or NULL if no log is desired |
uint8_t SendEEPROMHexVSerial | ( | ) |
Send EEPROM content as Intel Hex format to the virtual serial port.
This method reads the content of the EEPROM and transmits it in Intel Hex format to the Virtual Serial port. It is the responsibility of the caller to make sure the virtual serial port is availble.
void TerminalVSerial | ( | log_struct_t * | logger | ) |
Virtual Serial Terminal application.
This method implements a virtual serial terminal application.
The SCD receives CAPDUs from the Virtual Serial host and transmits back the RAPDUs received from the card. This method should be called upon reciving the AT+CINIT serial command.
This function never returns, after completion it will restart the SCD.
logger | the log structure or NULL if a log is not desired |
uint8_t lcdAvailable |