// *************************************************************************** // * FILE : iso7816.c // * PURPOSE : ISO/IEC 7816-3 implementations with TDA8029 // * DATE : JAN-08 // * VERSION : 1.0 // * AUTHOR : Rushikesh // * DESCRIPTION : ?? // * : ?? // * REV. HISTORY : VERSION DATE CHANGES // * : ?? // *************************************************************************** //****************** // I N C L U D E S //****************** // eCos includes #include #ifdef CYGPKG_KERNEL # include #endif #ifdef CYGPKG_LIBC # include #endif #ifdef CYGPKG_IO_SERIAL # include #endif #ifndef CYGFUN_KERNEL_API_C # error Kernel API must be enabled to build this example #endif #ifndef CYGPKG_LIBC_STDIO # error C library standard I/O must be enabled to build this example #endif #ifndef CYGPKG_IO_SERIAL_HALDIAG # error I/O HALDIAG pseudo-device driver must be enabled to build this example #endif /* INCLUDES */ #include /* printf */ #include /* strlen */ #include /* All the kernel specific stuff */ #include /* I/O functions */ #include /* CYGNUM_HAL_STACK_SIZE_TYPICAL */ // eCos includes #include #include #include #include #include #include #include #include //****************** // D E F I N E S //****************** #define NTHREADS 4 #define STACKSIZE (CYGNUM_HAL_STACK_SIZE_TYPICAL) // if we will be using a receive then enable following macro #define RECEIVE_THREAD_USED 1 // Priority levels for threads #define INIT_PRIORITY 4 // Stack size of thread #define STACK_SIZE 1024 // thread names #define INIT_THREAD 0 // thread names #define RECEIVE_THREAD 1 static cyg_handle_t thread[NTHREADS]; static cyg_thread thread_obj[NTHREADS]; static char stack[NTHREADS][STACKSIZE]; static cyg_io_handle_t _HandleScrUart; //********************************* // E X T E R N P R O T O T Y P E S //********************************* extern void _Filemain (CYG_ADDRESS data); // ####################################################################### // F O P S // ####################################################################### /******************************************************************************* * FUNCTION : void _ThreadScrInit(cyg_addrword_t data) * DESCRIPTION : Thread to initailize the card. * RETURNS : None * INPUT : cyg_addrword_t data : NULL * OUTPUT : None * INPUT/OUTPUT : None *******************************************************************************/ static void _ThreadScrInit(CYG_ADDRESS data) { cyg_serial_info_t ScrUartCfg; cyg_uint32 Length; unsigned int dwAddr; unsigned int dwRegValue; unsigned char bRxBuffer[30]; unsigned int dwRxLength; printf("\n-----------------------------"); printf("\nSCR Application Build: 107"); printf("\n-----------------------------\n\n"); printf("\nInitThread..."); if(cyg_io_lookup("/dev/ser1", &_HandleScrUart) == ENOERR) { printf("\nSerialPort found!"); ScrUartCfg.baud = CYGNUM_SERIAL_BAUD_38400; ScrUartCfg.word_length = CYGNUM_SERIAL_WORD_LENGTH_8; ScrUartCfg.stop = CYGNUM_SERIAL_STOP_1; ScrUartCfg.parity = CYGNUM_SERIAL_PARITY_NONE; ScrUartCfg.flags = 0x01; Length = sizeof(ScrUartCfg ); if(cyg_io_set_config(_HandleScrUart, CYG_IO_SET_CONFIG_SERIAL_INFO, &ScrUartCfg, &Length) == ENOERR) { // No error in configuration. printf("\nUART configured successfully"); printf("\nChecking modem signals"); dwAddr = CYGARC_HAL_LPC24XX_REG_U1MCR; HAL_READ_UINT8(dwAddr, dwRegValue); printf("\n Reading U1MCR = 0x%x",dwRegValue); dwRegValue &= ~(CYGARC_HAL_LPC24XX_REG_U1MCR_DTR | CYGARC_HAL_LPC24XX_REG_U1MCR_RTS | CYGARC_HAL_LPC24XX_REG_U1MCR_LOOPBACK); HAL_WRITE_UINT8(dwAddr, dwRegValue); printf("\n Written U1MCR = 0x%x",dwRegValue); // Write a dummy byte to start communication. } } else { printf("\nSerialPort NOT found!"); } cyg_thread_exit(); } /******************************************************************************* * FUNCTION : void _ThreadScrReceive(cyg_addrword_t data) * DESCRIPTION : Thread to receive data over uart. * RETURNS : None * INPUT : cyg_addrword_t data : NULL * OUTPUT : None * INPUT/OUTPUT : None *******************************************************************************/ static void _ThreadScrReceive(CYG_ADDRESS data) { // The 10 count is temporary, ideally we should receive // single byte at a time. unsigned char bStorage[10]; unsigned int dwLen = 1; unsigned int dwOffset = 0; printf("\nReceiveThread..."); while(1) { // Read data from uart. // This should be a blocking call. dwLen = 1; cyg_io_read(_HandleScrUart, bStorage, &dwLen); printf("\nRxLen = %d",dwLen); } } void cyg_user_start(void) //void scr_start(void) { // Initialize a init thread. #if 1 cyg_thread_create(4, _ThreadScrInit, (cyg_addrword_t) 0, "scr_init", (void *)stack[0], STACKSIZE, &thread[0], &thread_obj[0]); cyg_thread_resume(thread[0]); cyg_thread_create(4, _ThreadScrReceive, (cyg_addrword_t) 0, "scr_rcv", (void *)stack[1], STACKSIZE, &thread[1], &thread_obj[1]); cyg_thread_resume(thread[1]); /*cyg_thread_create(4, _ThreadScrTest, (cyg_addrword_t) 0, "scr_test", (void *)stack[2], STACKSIZE, &thread[2], &thread_obj[2]); cyg_thread_resume(thread[2]);*/ cyg_thread_create(6, _Filemain, (cyg_addrword_t) 0, "FileOp_APP", (void *)stack[3], STACKSIZE, &thread[3], &thread_obj[3]); cyg_thread_resume(thread[3]); #endif } // ####################################################################### // M O D U L E D E C L A R A T I O N S // #######################################################################