Presentation is loading. Please wait.

Presentation is loading. Please wait.

Z8 IrDA Flash Loader Dustin Graves March 28, 2006.

Similar presentations


Presentation on theme: "Z8 IrDA Flash Loader Dustin Graves March 28, 2006."— Presentation transcript:

1 Z8 IrDA Flash Loader Dustin Graves March 28, 2006

2 Goal Z8 IrDA Flash Loader: Modify a flash loader to use IrDA and write a communication program (in Java) that sends Z8 programs to the Z8. You will need a computer with a working IrDA port (or purchase a IrDA dongle). Dongle must include a driver that enables access as a COM port so you can use the Java COMM API as I don't think the Java USB API is complete yet or use Linux (maybe this will work under cygwin) and the HP Labs Java IrDA API or the JIR API might work. This will be mostly Java programming. references: –HP Labs Java IrDA API –JIR API –Z8 IrDA appnote AN0184 –Z8 flash loader appnote AN0118, appnote AN0164

3 Overview IR Communication –IrDA Background –Z8 Support for IrDA –Windows Support for IrDA –Linux Support for IrDA –IR Communication Options Flash Loader –Z8 Flash Loader Characteristics –Z8 Program Relocation Implementation –Pico-IrDA, Z8 Server, WIN32 Client

4 IrDA Background Infrared Data Association –An organization that creates, promotes, and standardizes IrDA technology. A protocol suite designed to provide wireless, line of sight connectivity between devices –Secure, reliable, and low cost point-to-point communication among devices such as PDAs, digital cameras, pagers, set-top boxes, machinery, and computer peripherals –Faulty cables and incompatible connectors/wiring are not an issue. –Devices negotiate connection speed and properties, no user configuration required –High speed IrDA devices are compatible with low speed IrDA devices (All connections start at 9600 bps) Consists of two main subsets –IrDA Data – Data Exchange –IrDA Control (IrDA-C) – HCI (Keyboard, Mouse, etc)

5 IrDA Data Properties Three main transfer rates –Serial Infrared (SIR) – Asynchronous, 9600 – bps Resembles standard UART with one start bit, 8 data bits, and one stop bit –Fast Infrared (FIR) – Synchronous, up to 4 Mb/s –Very Fast Infrared (VFIR) – Synchronous, up to 16 Mb/s Two way communication –Half-duplex –Automatic device discovery –Error correction –Primary and secondary modes of operation Primary device is similar to a network client – establishes connections with other devices with which to transmit data and commands Secondary device is similar to a network server – waits for connections from other devices from which to accept data and commands Multi-layer protocol stack –Support for multiple modes of communication with various devices.

6 IrDA Protocol Stack Required Layers –IrPHY – The physical layer –IrLAP – Link Access Protocol –IrLMP – Link Management Protocol –IAS – Information Access Service Optional Layers –TinyTP – Tiny Transport Protocol –IrOBEX – Object Exchange –IrCOMM – Serial and Parallel Port Emulation –IrLAN – Local Area Network Access –IrTran-P – Transfer Picture Protocol –IrMC – Infrared Mobile Communications New Additions –IrFM – Financial Management Transactions –IrWW – Wrist Watch Communication

7 IrDA Protocols of Interest IrOBEX – Transmitting small programs –One-way communication (no feedback from Z8) –Protocol handles flow control and error checking IrCOMM – Managed transmission of programs –Two-way communication –Z8 client responds to each data block received with a send next block notification or transfer complete notification Physical Layer IrLAP IrLMP TinyTP IAS IrCOMMIrOBEX

8 Z8 Support for IrDA Z8F6403 support for the IrDA Protocol includes: –The Physical Layer (SIR – 9600 baud to kbaud) –An IrLAP Framer (IrDA Lite) AN0152 – IrDA Framer Implementation –Creates data frames for IrLAP –Performs data checksum AN0184 – Using the IrDA Port –Provides a cleaner, simpler, and more efficient IrLAP framer BOFIrLAP PayloadFCSEOF Address (A)Control (C)Information (I)

9 IrDA Discovery Frame Windows XP IrDA Frame captured with IrDA Framer What does it mean? FF Address Field – IRLAP_ADDR_BROADCAST | IRLAP_ADDR_C_TEST 3F Control Field – IRLAP_CTRL_U_XID_CMD | IRLAP_CTRL_P_F_MASK 01 Information Field - IRLAP_XID_FMT_DISCOVERY AB Source address FF FF FF FF Destination address 01 Flags - IRLAP_XID_FLAGS_SLOTS_6 00 Slot 00 IRLAP version 23 9DChecksum FF3F01AB080000FFFFFFFF D

10 Pico-IrDA Minimalist IrDA stack for microcontrollers –http://blaulogic.com/pico_irda.shtml Implements IrLAP, IrLMP, IAS, and TinyTP as lower level transport layers Implements IrOBEX for primary and secondary devices –Send and receive files Implements IrCOMM for secondary devices –Receive data and optionally respond with data Requires implementation of IrPHY Source code available from project website is not ANSI C compliant –Uses zero length arrays such as ‘char info[0]’ –ANSI C compliant version is available from the download section of the Pico-IrDA Yahoo! Group

11 Windows Support for IrDA Windows support for IrDA varies by version –Windows 2000/XP/Server 2003 TinyTP based TCP like support for non-serialized data transmission at VFIR rates through Windows Sockets API IrOBEX functionality available at OS level, not exposed through Winsock API Limited IrCOMM support (9-wire cooked) exposed through Winsock API Communication with non-Windows devices that implement the core IrDA protocol is possible –Suggested that devices implement Winsock like client/server functionality –Windows 95/98/ME Support for serial communication with the IrCOMM programming model –Windows CE Support for Serial Communication IrOBEX functionality is exposed through Winsock API Supplemental information for Winsock IrDA programming –MSDN documentation is limited, possibly inaccurate

12 Communication with a Non-Windows Device

13 IrCOMM2K Serial Port Emulator Driver for Windows 2000/XP that provides a virtual IR COM port Also provides irda2kdump IrDA traffic monitor –Similar to a utility provided with Linux –Available from

14 Linux Support for IrDA Low level and high level access to IR device –Support for SIR and FIR devices –Access directly as serial port –Access through IrDA module with socket API TCP like connection oriented communication UDP like connectionless communication – Ultra Protocol for IrWW –Multiple utilities and libraries for IrDA interaction irdadump – IrDA traffic monitor OpenOBEX – Open source IrOBEX implementation (may work with Windows) Java Infrared Sockets API –More information from Linux IR HOWTO

15 Linux IrDA Setup Install/compile irda-utils and irda kernel modules Determine the name of the infrared device –Use ‘dmesg | grep ttyS’ to list available serial devices: ttyS0 at I/O 0x3f8 (irq = 4) 16550A  Probably COM port ttyS1 at I/O 0x2f8 (irq = 3) 16550A  Probably IrDA device ttyS2 at I/O 0x3f8 (irq = 4) 16550A  Probably Modem Load the appropriate kernel modules –‘modprobe irda’ –‘modprobe irtty-sir’ –‘modprobe ircomm-tty’ Attach the infrared device with the IrDA module and initiate device discovery –‘irattach /dev/ttyS1 –s’ IrDA can be started as a service with Fedora –Edit ‘/etc/modprobe.conf’ –Edit ‘/etc/sysconfig/irda’ –Enable service with ‘chkconfig irda on’

16 Linux irdadump Utility Useful for debugging –Decodes and displays contents of IrDA Frames

17 IR Communication Options Z8 communication with Windows XP –IrOBEX from Windows XP to Z8 Pico IrDA implementation –IrCOMM from Winsock API to Z8 Pico IrDA implementation –Possibly use IrCOMM2K for basic serial communication with Z8? –Possibly use IrCOMM2K and a Windows XP Pico IrDA implementation to communicate with Z8 Pico IrDA implementation? Z8 communication with Windows XP –Basic serial communication with Linux and Z8 –IrOBEX from Linux implementation of OpenOBEX to Z8 Pico IrDA implementation –IrCOMM from Linux to Z8 Pico IrDA implementation –Linux Pico IrDA implementation to Z8 Pico IrDA implementation

18 One more option… Hardware solution - Microchip MCP2140 –IrDA standard protocol stack controller with fixed 9600 baud communication rate –Implements IrLAP, IrLMP, IAS, TinyTP, and IrCOMM (9-wire cooked) Similar to functionality provided by Winsock API More information at –http://ww1.microchip.com/downloads/en/devicedoc/21790a.pdfhttp://ww1.microchip.com/downloads/en/devicedoc/21790a.pdf

19 Z8 Flash Loader A program that permanently resides in Flash memory to load a users application to Flash memory when signaled at program start or to execute the user application residing in Flash memory when not signaled at program start –Startup code – Execute flash loader or resident user application –Communication initialization – Initialize communication device –Flash I/O utilities – Basic Flash and RAM read/write utilities –Data processor / Flash loader – Receive, process, and load data frames for user program –Communication interface – Interaction with Flash Loader AN0164 – Boot Loader for Z8 Encore –Assembly implementation of a boot loader –Requires 1000 bytes of flash memory AN0118 – Flash Loader Utility for the Z8 Encore –C implementation of a flash loader –Requires 16 kilobytes of flash memory

20 Z8 Flash Loader Characteristics Wait to receive signal to enter Flash Loader Mode –Monitor GPIO pin, button, UART, etc Load User Program to Flash –Support for communication with UART –Support for Flash I/O operations –Support for Intel Hex16 format Define start of user program –Application program start address must relocate to address required by Flash loader Prevent user program from overwriting Flash writer –Carefully check the address for each record loaded from Intel Hex16 file Execute user program –Jump to start of user code

21 Z8 Flash Loader Relocation Z8 Flash loader must be moved to a safe Flash memory location –Loading a user program requires addresses 0x00-0x37 (Flash Option Bits, Reset Vector, Interrupt Vectors) to be erased for programming –Flash memory is erased by 512 byte pages –Flash loader must start at address 0x200 to avoid being damaged by erase of first page –Relocation performed through ZDS II Project Settings dialog

22 Z8 Flash Loader Target Settings Target settings for Flash Loader –Target Settings specified through Address Space category of Linker tab with ZDS II 4.9.6

23 Z8 Flash Loader Linker Directives Special input directive settings to place vector code before startup code –ORDER __VECTORS,STARTUP

24 User Program Relocation Target settings for User Program –AN0118 specified 0x4000 as start address –The IrDA Flash loader specifies 0x5000 as start address

25 User Program Linker Directives

26 User Program Relocation with Assembly include "ez8.inc" SEGMENT code VECTOR RESET = main; add the entry point to the reset vector ORG %5000; start AFTER the interrupt vector main: CLRR0 LDX4064,#1; PEDD = 0x00; LDX4065,R0...

27 Z8 Flash Loader Implementation Implement IrPHY layer for Pico-IrDA –Accept programs with IrOBEX No feedback is transmitted to sender –Accept programs with IrCOMM Feedback is transmitted to sender indicating success/failure Create Flash loader based on program defined by AN0118 –Similar program location strategy –Only useable component is the module for processing Intel Hex16 data and loading Intel Hex16 data to flash Create a Windows XP program for transmitting IrCOMM data through Winsock API –Send Intel Hex16 file one line (record) at a time as 32 byte increments –Provide progress indicator –Provide final summary

28 Pico-IrDA IrPHY Implementation Implement four functions to initialize IrDA device, transmit data, receive data, and wait for data –void irphy_reset(void) – Initialize UART0 and enable IrDA –void irphy_send(uint8_t) – Transmit a byte –uint8_t irphy_wait(int16_t timeout) – Wait specified number of seconds for data to arrive; infinite wait for -1 –uint8_t itphy_receive(void) – Receive a byte Requires definition of types that are typically found in inttypes.h on UNIX systems –typedef unsigned char uint8_t –…

29 Reset, Receive, and Transmit #define BAUDRATE ( UL / (9600UL * 16UL)) void irphy_reset(void) { U0BRH = (unsigned char)((0xFF00&BAUDRATE)>>0x08); U0BRL = (unsigned char) (0x00FF&BAUDRATE); PAAF |= 0x30;/* Enable UART0 alternate function */ U0CTL0 = 0x40;/* Enable UART0 receive */ U0CTL1 = 0x01;/* Enable UART IR */ } uint8_t irphy_receive(void) { return U0RXD;/* Receive byte */ } void irphy_send(uint8_t v) { U0CTL0 = 0x80;/* Set UART0 to transmit */ while((U0STAT0 & 0x04) == 0);/* Wait for tx buffer to be available */ U0TXD = v;/* Transmit byte */ while((U0STAT0 & 0x02) == 0);/* Wait for tx complete */ U0CTL0 = 0x40; /* Set UART0 to receive */ }

30 Waiting uint8_t irphy_wait(int16_t timeout) { unsigned char done = 0; if(timeout != -1) {/* Timed wait */ enable_timer3();/* Initialize timer */ while(!(U0STAT0 & 0x80) && !done) {/* Until read ready or timeout */ if(T3H > 0x48) {/* Count for 1 millisecond */ if(--timeout == 0)/* Done waiting */ done = 1; else {/* Reset timer */ T3H = 0x00; T3L = 0x01; } disable_timer3();/* Disable timer */ } else { while(!(U0STAT0 & 0x80)); }/* Infinite wait */ return (U0STAT0 & 0x80) ? 1 : 0; }

31 Debugging Pico-IrDA for the Z8 Time critical transactions and constant state changes make Pico- IrDA difficult to debug Pico-IrDA comes with a Linux based IrPHY Implementation –Intended for Actisys IR220L serial IrDA dongle –Will work with any serial based IrDA device –Compare Linux implementation with Z8 implementation Differences most likely due to problems with the compiler Problems with the Z8 compiler –The following expression is always true: #define IRLMP_DLSAP_C_MASK 0x80 if(req_p->head.dlsap_sel & ~IRLMP_DLSAP_C_MASK) –This prevents the Z8 from connecting to other devices –Replace all references to ~IRLMP_DLSAP_C_MASK with uint8_t inv = ~IRLMP_DLSAP_C_MASK if(req_p->head.dlsap_sel & inv)

32 Windows XP Program Loader Open Intel Hex16 file and Initialize Winsock “Enumerate” available IrDA devices –Returns address of devices within range Set 9-Wire mode for IrCOMM –Could be unnecessary Select Z8 from list of devices and establish connection Read one line from file Transmit 32 bytes of data to Z8 and wait for response –FLASH_RESULT_DONE – Transmission is complete; print summary to console and exit –FLASH_RESULT_RESEND – Checksum error for line; print an ‘x’ to console and resend line –FLASH_RESULT_NEXT_LINE – Line has been loaded; print a ‘.’ to the console and read next line from file –FLASH_RESULT_NEXT_PART – Send next 32 byte block from current line

33 Demonstration IrOBEX and IrCOMM program transmission

34 References us/irda/irda/irda_start_page.asphttp://msdn.microsoft.com/library/default.asp?url=/library/en- us/irda/irda/irda_start_page.asp %20programming.htmlhttp://www.alanjmcf.me.uk/comms/infrared/Microsoft%20Windows%20IrDA %20programming.html us/irda/irda/ircomm_client_sample_code.asphttp://windowssdk.msdn.microsoft.com/library/default.asp?url=/library/en- us/irda/irda/ircomm_client_sample_code.asp


Download ppt "Z8 IrDA Flash Loader Dustin Graves March 28, 2006."

Similar presentations


Ads by Google