Home

Application Note CMX-Micronet for 78K0 Family Application

image

Contents

1. User Interface Web page development User Program User Defined Application Device file Header Custom Application dfxxxx h A html2c exe Initialisation of Ports amp SFR s init c Y y y NEC_hw c NEC_hw h gt l Example c lt gt Timer Setup Callback c Timer Interrupt Physical Layer Setup User_config h Micronet h Micronet Stack Y Micronet r26 CMX Stack Link Layer IN mn port c UART ye The CMX Micronet stack is supplied in object code format with a time limitation of approximately 30min While the layer above API layer is supplied as source code for user interaction Examples of user program interaction with the API layer are contained in Chapter 7 While in Chapter 6 enters into how to use the API Headers User config h contains compiler tests to check if config h has been set up correctly Micronet h Links all header information Must be added to all user application code NEC_hw h Contains definitions used for peripheral setup DF0066 h Device file header for uPD78FOO66 Source Code Example c Contains initialisation and startup routines for CMX Micronet Callback c IP address and additional function calls for CMX Micronet NEC_hw c All CMX Micronet peripheral requirements Init c Initialisation of hardware and software for user application 16 Application Note CMX Micronet for 78K0 Family Chapter3 System Configuration 3 1 Memory Ma
2. data_ptr socket_ptr gt recv_ptr Application Note CMX Micronet for 78K0 Family 65 Chapter7 Example Code data_len socket_ptr gt recv_len if PPP if Ppp status up break endif PPP mn_abort socket_no endif EXAMPLE TYPE TCP EXAMPLE if EXAMPLE TYPE SMTP EXAMPLE replace the email addresses below byte from frodo cmx com byte to bilbo cmx com byte subject SMTP test byte message This is the message body Mn byte attach This is the attachment r n byte fname micronet txt void doSMTP void cmx_reentrant CHAR socket_no CHAR retval SMTP_INFO_T mail_info socket_no mn_smtp_start_session DEFAULT_PORT if socket_no gt 0 send a message with an attachment mail_info from from mail_info to to mail_info subject subject mail_info message message mail_info attachment attach mail_info filename fname retval mn_smtp_send_mail socket_no amp mail_info if retval lt 0 there was an error sending the message send a message without an attachment mail_info from from mail_info to to mail_info subject subject mail_info message message mail_info attachment PTR_NULL mail_info filename PTR_NULL retval mn_smtp_send_mail socket_no amp mail_info if retval lt 0 there was an error sending the message 66 Application Note CMX Mi
3. Je Po e dd Module name vADCComplete Description cl This module is the Interrupt service routine for the de A D converter Operation uh interrupt INTADO_vect void vADCComplete void bADCFlag TRUE Set flag endif PROJECT 78K0 Demonstration Board MODULE dice c SHORT DESC DEVICE uPD78F0066 VERSION 1 0 DATE 02 01 2000 LAST CHANGE VM EE a SEE EE ed ESE EIE Description Electronic Dice D After initialization all LEDs flash twice Application Note CMX Micronet for 78K0 Family Chapter7 Example Code eg After pressing Key1 one to six LEDs get switched on ep Then the program waits for the next start Environment Device uPD78F0066 Assembler A78000 Version 3 30A de C Compiler 1CC78000 Version 3 304 Linker XLINK Version 4 510 Simulator SM78KO Version 2 10 By NEC Electronics Europe GmbH Oberrather Strasse 4 27 D 40472 Duesseldorf include lt in78000 h gt include DFOO66 h include micronet h HE Function prototyps HE void vFlashLED unsigned char Flash all LEDs n times void vWait5 unsigned char n 5ms delay void dice void unsigned char ucRandom void A Generation of random number Ml rana Global variables Ml rain bit bTimer50Flag Status Flag Timer50 bit bTimer51 Flag Status Flag Timer51 bit bKey1Flag Status Flag Key1 saddr unsigned char ucThrow dice value saddr unsigned cha
4. Set timer clock x 248 4 194304 MHz gt 16384 Hz Timer50 compare value gt 10 01ms intervall output no cascade mode if defined D78F0034 Il defined D78F0078 PM72 0 TMIF50 FALSE TMMK50 FALSE TMC50 7 1 endif if defined D78F0066 PM22 0 TMIF50 FALSE TMMK50 FALSE TMC50 7 1 endif if defined D78F0828 PM34 0 TMIF50 FALSE TMMK50 FALSE Set to output Mode Clear interrupt request Bit Timer50 Enable Timer50 Interrupt Set to output Mode Clear interrupt request Bit Timer50 Enable Timer50 Interrupt Set to output Mode Clear interrupt request Bit Timer50 Enable Timer50 Interrupt TMC50 7 1 endif timer_tick 0 ENABLE_INTERRUPTS 7 2 1 4 Init c ff o oo ooooooooo o o o o o PROJECT 78K0 Demonstration Board MODULE init c SHORT DESC DEVICE uPD78F0066 VERSION 1 0 DATE 27 11 2001 LAST CHANGE AA A ASA ee EN TT REA SORA rk A DU TARA EIN OO O NAAA a EES geg o A AAA SECAS IP EA AAA IA ad A A Environment Device uPD78F0066 27 Assembler A78000 Version V3 33A eg C Compiler I1CC78000 Version V3 33A kk Linker XLINK Version V4 52J By NEC Electronics UK Ltd Ke Cygnus House Sunrise Parkway kk Es Linford Wood n Milton Keynes UK MK14 6NP Changes 76 Application Note CMX Micronet for 78K0 Family Chapter7 Exa
5. 3 2 4 User Program available RAM In addition to the protocol stack RAM requirements the user program will require RAM and so it is important to understand how much RAM will be available for this task For the evaluation system the following paramaters have been fixed to allow a certain amount of user program RAM Use this example as guide to implement your own application Fixed Values for the Object Code Time limited version Sockets Server Side Includes POST Functions Virtual File Pages HTTP_BUFFER_LEN 1536 N 09 O RECV_BUFF_SIZE 256 XMIT_BUFF_SIZE 256 URI_BUFFER_LEN 64 BODY_BUFFER_LEN 64 TCP_WINDOW 128 Check the following Link Layer RECV BUFF SIZE XMIT BUFF SIZE 1804 x 512 x 332 OK CMX Micronet Stack RECH BUFF SIZE 512 wholenumber TCP WINDOW 128 RECV _ BUFF SIZE _ OK TCP WINDOW HTTPTotal 64 64 1536 HTTPTotal 1664 OK ArrayTotal Socket RAM PAP _ RAM FTP _ RAM FILE RAM POST RAM SSI RAM 6x52 2 0 0 7x 6 20 8x 2 20 8x 2 20 848 CMX _ Micronet _ Stack TCP WINDOW HTTPTotal ArrayTotal Temp _ Variables CMX _ Micronet _ Stack 128 1664 848 82 CMX _ Micronet Stack 2722 Note Temp variables are included from 2 example arrays still contained within Example c Application Note CMX Micronet for 78K0 Family 21 Chapter3 System Configuration 22 Therefore RAM available for user program is TotalRAM User _Program CMX _ Micron
6. EWS78K TESTIT lt font gt lt i gt lt b gt lt font gt lt p gt lt p gt lt b gt lt i gt lt font face Georgia Times New Roman Times serif size 6 color BLUE gt This page is coming from 78K Hopper lt font gt lt i gt lt b gt lt p gt Application Note CMX Micronet for 78K0 Family 37 Chapter6 Application Programmers Interface API lt p gt lt HR gt lt center gt lt p gt lt font size 4 color BLUE gt 78K Hopper is running CMX Micronet from CMX systems It can display more than just HTML pages Forms can be added to send data can be acted apon by user defined functions lt font gt lt p gt lt center gt lt font color 0000FF gt Here is a simple demonstration for an Electronic Dice lt font gt lt FORM NAME LCD_TEXT ACTION Icd_msg METHOD POST gt lt p gt lt font size 7 gt lt exec cgi dice gt lt font gt lt p gt lt INPUT TYPE Submit VALUE Roll Dice name display gt lt FORM gt lt FORM NAME LCD_TEXT ACTION Icd_stop METHOD POST gt lt input type Submit value Reset name Stop gt lt FORM gt lt HR gt lt center gt lt div align center gt lt p gt amp nbsp lt p gt lt p gt lt img src table gif width 788 height 66 gt lt p gt lt div gt lt p gt lt img src necem gif width 400 height 60 gt lt p gt lt p align right gt lt FONT SIZE 4 gt lt a href page2 htm gt Go to Page 2 lt a gt lt font gt lt br gt lt p gt
7. TMC50 7 1 endif if defined D78F0828 PM34 0 TMIF50 FALSE TMMK50 FALSE TMC50 7 1 endif Set to output Mode Clear interrupt request Bit Timer50 Enable Timer50 Interrupt timer_tick 0 ENABLE_INTERRUPTS 7 1 4 init c ff o oo ooooooooo o o o o PROJECT 78K0 Demonstration Board MODULE init c SHORT DESC DEVICE uPD78F0066 VERSION 1 0 DATE 27 11 2001 LAST CHANGE EA ae n oa mo AS IAEA EE AAN EA EEE AAA ESB ICAA AENA A IAN Environment Device uPD78F0066 dd Assembler A78000 Version V3 33A Ke C Compiler I1CC78000 Version V3 33A Linker XLINK Version V4 52J By NEC Electronics UK Ltd Cygnus House Sunrise Parkway K Linford Wood at Milton Keynes UK MK14 6NP Changes 56 Application Note CMX Micronet for 78KO Family Chapter7 Example Code include lt in78000 h gt if defined D78F0034 include lt df0034 h gt change to appropriate file endif if defined D78F0066 include lt df0066 h gt change to appropriate file endif if defined D78F0078 include lt df0078 h gt change to appropriate file endif if defined D78F0828 include lt df0828 h gt change to appropriate file endif if defined D78076 include lt d076 h gt change to appropriate file endif include micronet h kk Module name vHardwarelnit De
8. gt send_len gt 0 socket_ptr gt send_ ptr data len else socket_ptr gt send_ ptr PTR_NULL endif Zar TCP called from mn_recv CHAR mn_app_recv_idle void cmx_reentrant put your code here return NEED_TO_EXIT if mn_recv must be exited immediately return 0 if HTTP CHAR mn_app_http_server_idle void Application Note CMX Micronet for 78K0 Family 71 Chapter7 Example Code cmx_reentrant put your code here return NEED_TO_SEND if data must be sent immediately return 0 endif HTTP if FTP 88 FTP_SERVER CHAR mn app ftp server idle void cmx_reentrant put your code here return NEED_TO_SEND if data must be sent immediately return 0 endif if FTP amp amp FTP_SERVER PROJECT API for CMX Implementation MODULE NEC_hw c SHORT DESC Hardware setup for CMX stack DEVICE uPD78F0066 specify change in project options to choose different processor VERSION 1 1 DATE 04 01 2002 LAST CHANGE WE EES Em RD RE BRA ea Se MR ES RAD EERS ig A DEE ELE Description API Implementation el The 78K Test It demo board implements CMX Internet connectivity stack 8 bit timer required stack tick UART required for connection This file can be modified to change hardware requirements for Ce CMX stack kk kk kk ER A a ne Environment Device uPD78F0066 g Assembler A78000 Versio
9. lt CENTER gt lt CENTER gt lt BODY gt lt HTML gt To get HTML generated files into a format required for integration ALL files must pass through the html2C exe application contained in the util directory ALL files must be placed into a flattened directory structure before integration into the user application Below shows how to integrate developed Web pages into your embedded application using the mn_vf_set_entry function to create the virtual file structure Sample HTML code integration from Example c add Web pages to virtual file system The main page MUST be first mn_vf_set_entry byte index htm INDEX_SIZE void index_htm VF_PTYPE_STATIC mn_vf_set_entry byte page2 htm PAGE2_ SIZE void page2_htm VF_PTYPE_STATIC mn_vf_set_entry byte necem gif NECEM_SIZE void necem_gif VF_PTYPE_STATIC mn_vf_set_entry byte table gif TABLE SIZE void table_gif VF_PTYPE_STATIC ALL the files above require NO interaction from the browser to the embedded application The embedded application knows the location of the main page and sends this to the browser ALL following pages are called by main page to be transferred to the browser 6 8 1 1 Server Side Includes SSI mn_gf_get_entry name_ptr Where name_ ptr has the name of the function to look uf Returned Status A function pointer corresponding to the passed name This function returns a function pointer corresponding to the passed
10. 9 15 Null MODEME es dt 31 NULL MODEM sisi 31 NUM GET FUNGCS ee ee ee ee ee 20 NUM POST EUNGCS se ee 20 NUM SOCKETS ee ee ee 20 NUM VE PAGES ee ee ee ee ee ee ee ee 20 PAP Ee sank Se ee ee ee 9 11 12 20 45 65 PAP NUM USERS iee esse sees ee esse ee ee ee ee ee ee ee ee ee ee 20 PASSIVE OPEN 30 34 36 44 46 48 64 66 67 PASSIVE OPEN A 44 64 Physical Layer 12 18 PING ak ER RE cna 9 11 15 36 POST6 9 13 15 19 20 21 30 31 33 40 41 50 69 70 PPP9 12 15 18 20 30 31 33 34 36 44 45 46 47 48 49 55 56 57 63 64 65 66 67 68 75 76 77 78 RAR Putas tallados 12 13 RECV_BUFF_SIZE 0 19 21 56 76 77 ele E EE 56 76 77 FECV IR CET 56 76 send out Dir 57 77 78 send out Dir 57 77 78 89 Index Server 9 12 13 14 15 19 20 21 26 27 31 40 9 12 18 36 55 56 57 75 76 77 78 SMTP9 11 12 14 27 42 43 46 49 50 51 52 61 62 63 66 68 69 72 TCP6 9 10 11 13 15 19 20 21 27 33 34 36 38 42 43 46 47 48 49 52 53 54 61 62 63 65 67 68 72 74 TCP IP Protocol Stack 9 TCP WINDOW ee e ese e eee 19 21 52 72 TATP caia gen 9 11 12 44 45 46 63 65 90 UART 8 9 15 18 23 44 54 55 56 64 75 76 UDP9 10 11 27 38 42 43 46 61 62 63 65 66 UR BUFEFER EN 19 21 Virtual Files iese ee ee ee ee ee EE ee 18 21 XMT BUFF SIZE eise ee ee ees ee ee ee ee ee ese ee ee e
11. Application Note CMX Micronet for 78KO Family Chapter5 Description of Software 5 5 1 6 Server Side Include Setup SSI setup is required when a user program requires interaction with the HTML pages This allows a direct substitution of text within a HTML Web page The function call for this is mn_gf_set_entry Only 8 SSI functions are available for the evaluation version Note Like the POST function the SSI function initialisation also requires a corresponding function to be developed In both cases each of these functions are specific to the user application requirements or action needed for the task required 5 5 2 PC Connection Started In this evaluation version the MODEM function has been set for a direct connection to a PC This means that mn modem connect type has been set to DIRECT CONNECT and the NULL_MODEM option is set to one This allows connection to a PC through a null MODEM cable and a null MODEM driver must be used within the PC This option is supported on Windows NT or Windows 2000 ME XP See Getting Started User Manual for instructions on the connection to a PC Based on the initial settings for the MODEM connect type this is the entry point to the round robin loop shown in Figure 5 3 A test is carried out within the mn modem connect function if a MODEM connection is successful entry is allowed into the round robin If the test is not successful the round robin is not entered and within example c a loop is
12. Chapter7 Example Code data len 0 else client mode socket no mn_open ip_dest_addr DEFAULT_PORT ECHO_PORT ACTIVE_OPEN PROTO_UDPA STD TYPE data but DATA BUFF LEN data ptr TESTSTRING data len strlen char TESTSTRING endif if socket no lt 0 did we open socket successfully EXIT 1 socket_ptr MK_SOCKET_PTR socket_no get pointer to the socket while 1 if defined BORLANDC II defined _MSC_VER if bios keybrd KEYBRD READY check if ctrl c pressed if _bios_keybrd _KEYBRD_READ A Oxff 3 mn_close socket_no break endif fr if defined BORLANDC II defined _MSC_VER status 0 if data_ptr PTR_NULL status mn_send socket_no data_ptr data_len if status lt 0 data_len 0 break status mn_recv socket_no data_buff DATA_BUFF_LEN if status lt 0 amp amp status SOCKET_TIMED_OUT data_len 0 break if we got something send back what we got if status gt 0 data_ptr socket_ptr gt recv_ptr data_len socket_ptr gt recv_len if PPP if ppp_status up break endif PPP mn_abort socket_no endif if EXAMPLE_TYPE TCP_EXAMPLE void doTCP void cmx_reentrant CHAR socket_no 64 Application Note CMX Micronet for 78KO Family Chapter7 Example Code PSOCKET INFO socket ptr byte data_ptr word16 data_len int status if SERVER MODE sock
13. Location of CMX source code for API build Example c Callback c Location of c files for user application including nec_hw c Location of memory map requirements for build Location of NEC h files used for application example Application Note CMX Micronet for 78KO Family Chapter5 Description of Software 5 2 Context Diagram The relationship between the software and hardware peripherals are shown in the context diagram Figure 5 2 Figure 5 2 Context Diagram User Application User Data timer_tick TM50 CMX Micronet Protocol Stack INTSRO INTSTO Web Bowser Data HTML PPP 5 3 Interaction with CMX Micronet There is no set location for a user application to interact with CMX Micronet There can only be pointers to use the protocol stack These pointers are contained in Example c and Callback c However there can be guides to where to put a user application depending on the type of interraction required For example a user application is required to do something and return a value depending on a submit button contained within a HTML page This type of interaction is contained in the example of Electronic Dice shown in 7 2 1 The original example has come from the original 78K Test It program examples where the example required an input via a key press to display a random value between 1 and 6 on the LED s provided To allow user interraction to occur using a Web
14. OxFF Disable all interrupts MKOH OxFF MK1iL OxFF PROL OxFF Set all interrupts to low priority PROH OxFF PRiL OxFF A Compiler Version Number setting Il Compiler Version Number _ VER Must be left in code so Micronet will work with current compiler version endif if defined D78076 clock generator setting VEE PCC 0x00 Use high speed mode OSTS 0x02 2415 fx ms wait after STOP release by interrupt OSMS 0x01 Scalar not used IMS 0xCC A Select 1024 Byte RAM and 48k Byte ROM IXS OXOA Select 1024 Byte RAM endif ee Module name vSoftwarelnit ak kk Description This module is to initialize the bit variables ak kk Operation kk EE A EO ODE IE A A EE E EENEG void vSoftwarelnit void 7 2 Examples 7 2 1 Electronic Dice and A D Input The example below is based on the original 78K Test It Electronic Dice Program The main changes to the electronic dice example allows the user to use a Web browser to to initiate and display the result of the electronic dice In addition to this a second Web page and application was added to show how to add more than one application to CMX Micronet 58 Application Note CMX Micronet for 78K0 Family Chapter7 Example Code Therefore it is possible to use the 78K Test It User Manual for the flow and resources used for this example Additions to this example include a conversi
15. browser the key press on the 78K Test It is substituted with a Web browser submit button press So before a user application can interract with CMX Micronet it is important to detirmine the type of interraction required This task can be broken down into 3 different types of interaction Application Note CMX Micronet for 78K0 Family 25 Chapter5 Description of Software Figure 5 3 User Application Active Only When Needed Only Active When HTML HTML Web Page User Application Return Result Submit POST Figure 5 3 shows the type of connection required for the electronic dice example The figure shows that the user application does not need to be active all the time but only needs to be active when an action occurs from the HTML Web page In this case the interraction takes the form of a submit button within the HTML page The PC client requests an update of the HTML page from the server using a submit button The HTTP server then acknowledges the update and included within the HTML Web page are Server Side Include functions exec cgi The HTTP server acts on these SSI functons The user application is called from the SSI function to get the next dice value returned result The returned result is formated within the SSI function call and a text substitution occurs within the HTML page The SSI functions used for this type of interraction are contained within Example c Figure 5 4 User Application Active All The Ti
16. byte i word16 temp word16 y P8 0 TRUE Switch on potentiomer supply P7 4 TRUE Switch on potential divider supply P7 5 TRUE Switch on reference diode supply for i 0 i lt ucAChannel i AtoD_buff i ucGetAD i Store result of each analog port P8 0 FALSE Switch off potentiomer supply P7 4 FALSE H Switch off potential divider supply P7 5 FALSE Switch off reference diode supply y ADCscalar AtoD_buff 0 10 Work out y scalar based on ADC Channel 0 voltage reference 1 25V for i 0 i lt ucAChannel i Calculate all ADC values against Scalar if i 3 temp AtoD_buff i y temp 127 AtoD_buff i temp else 82 Application Note CMX Micronet for 78KO Family Chapter7 Example Code temp AtoD_buff i y temp 255 AtoD_buff i temp fe ed NS ORE a A NC Oe A SI N N PS O GU ee ed ge ae A E q il er O E PU ed ve Ee A AEN ES ls ie e ri JS DO E OS ee OE ER ee al ee N EN a AT SS Module name ucGetAD Description id This module returns the AD result of the selected channel GE channel range 0 7 Operation unsigned char ucGetAD unsigned char ucChannel ADMO 7 TRUE Start AD Conversion ADSO ucChannel Channel selection while bADCFlag FALSE bADCFlag FALSE Reset status flag ADC while bADCFlag FALSE bADCFlag FALSE Reset status flag ADC ADMO 7 FALSE Stop AD Conversion return ADCRO
17. each of the configuration options for CMX Micronet pre set within config h The header config h contains all configurable options for setting the protocols used number of sockets sizes of buffers etc These configuration options can be changed within the full source code version For the evaluation version these values have been fixed See 3 2 4 for the fixed values 5 5 1 1 Switch Settings Additional configuration options have been included within example c Where Application type EXAMPLE TYPE is set to use HTTP MODEM connect type MODEM MODE is set to be Answer Mode Where in Answer Mode the device running CMX Micronet is waiting for a call from a MODEM It is possible within the full source code version to dial out MODEM_MODE would be set to Dial_Mode for this option PPP Type open mode is set to PASSIVE_OPEN for server mode This means that the client must first initiate the connection to the CMX Micronet device To initiate a connection from the CMX Micronet device this option can be set to ACTIVE OPEN and the CMX Micronet device becomes a client 5 5 1 2 User Application Initialisation Initialisation of Hardware and Software is contained in the functions vHardwarelnit and vSoftwarelnit respectively Both of these functions are to initially set up the device peripherals and clocking for user application only Both functions are located in init c 5 5 1 3 CMX Micronet Initialisation Before any API functio
18. function name mn of set entry new name new_func 38 Application Note CMX Micronet for 78K0 Family Chapter6 Application Programmers Interface API Where new name is the name of the function to be inserted into the table new_func is the function to be added to the table Returned Result A pointer to the SSI GET function table entry corresponding to the name passed This function places the passed name and function pointer into the first empty get function entry mn_gf_del_entry func_name Where func_name has the name of the function to delete from the table Returned Status 1 GET function entry successful 0 GET function entry not found This function deletes the GET function entry corresponding to the passed function name 6 8 1 2 POST Functions mn_pf_get_entry URIptr Where URIptr has the name of the function to look up Returned Status A function pointer corresponding to the passed name mn DI set entry new name new_func Where new name is the name of the function to insert into the table New_func is the function to be added to the table Returned Status A pointer to the POST function table entry corresponding to the passed name This function places the passed name and function pointer into the first POST function entry point mn_pf_del_entry func_name Where func_name is the name of the function to be deleted from the table This function deletes the POST function entry Application No
19. if HTTP Il FTP II SMTP if socket_ptr gt socket_type amp HTTP TYPEISMTP TYPE II socket_ptr gt src_port FTP DATA PORT bytes_to_send bytes_to_send gt TCP_WINDOW TCP WINDOW bytes_to_send endif return bytes_to_send initialization before receiving a packet Called from mn_tcp_recv and mn_udp_recv num number of bytes to be received void mn_app_init_recv word16 num PSOCKET_INFO socket_ptr cmx_reentrant Hif FTP amp amp FTP_SERVER num num endif I FTP 88 FTP_SERVER socket_ptr gt recv_len 0 if HTTP if socket_ptr gt socket_type amp HTTP_TYPE mn_http_init_recv else endif if FTP amp amp FTP_SERVER if socket_ptr gt socket_type amp FTP_TYPE mn_ftp_server_init_recv num socket_ptr else endif put your code here process received byte Called from mn_tcp_recv and mn_udp_recv void mn_app_recv_byte byte c PSOCKET_INFO socket_ptr cmx_reentrant if HTTP if socket_ptr gt socket_type amp HTTP_TYPE mn_http_recv_byte c else endif if FTP amp amp FTP_SERVER if socket_ptr gt src_port FTP CONTROL PORT mn ftp server recv byte c else endif if socket_ptr gt recv_ptr PTR_NULL copy the data into a buffer where we will deal with it later if socket_ptr gt recv_ptr socket_ptr gt recv_len lt socket_ptr gt recv_end socket_ptr gt recv_ptr socket_ptr
20. mail_info from from mail_info to to mail_info subject subject mail_info message message mail_info attachment attach mail_info filename fname retval mn_smtp_send_mail socket_no amp mail_info if retval lt 0 there was an error sending the message send a message without an attachment mail_info from from mail_info to to mail_info subject subject mail_info message message mail_info attachment PTR_NULL mail_info filename PTR_NULL retval mn_smtp_send_mail socket_no amp mail_info if retval lt 0 there was an error sending the message mn_smtp_end_session socket_no endif EXAMPLE_TYPE SMTP_EXAMPLE if EXAMPLE_TYPE HTTP_EXAMPLE this function is called from a Web page by an HTTP POST request void Icd_msg_func PSOCKET_INFO socket_ptr cmx_reentrant we are expecting a variable called display with escaped string e g display hello 2C world 21 where equals and XX is a hexadecimal representation of a char msg_buff will have decoded value if available Application Note CMX Micronet for 78K0 Family 47 Chapter7 Example Code if mn http find value BODYptr byte display msg_buff if ISERVER SIDE INCLUDES Just return good status socket_ptr gt send_ptr byte HTTPStatus204 socket_ptr gt send_len STATUS_204_LEN else inthis example we are always returni
21. orientated protocol i e every packet must be acknowledged TCP is also a full duplex protocol and data in both directions must be opened and closed independantly TCP resides above the IP protocol and provides the interface to the various application ports data is passed to and from the IP stack via the application ports Delivery integrity is maintained via the use of sequence and acknowledge numbers TCP is used to support the following application level protocols PAP FTP SMTP HTTP 2 2 Application Layer 22 1 DNS Domain Name System is a simple map between host names and IP addresses It is also used to provide mail routing information The DNS provides the protocol that allows clients and servers to communicate with each other 2 2 2 TFTP Trivial File Transfer Protocol is designed to be used when initialising hardware from a diskless system This is intended transfer small files using UDP and therefore fit into the internal ROM of the embedded device This application is typically used in conjunction with BOOTP 2 2 3 PING The ping application program is designed to test whether another host connected to the system is reachable This program sends an ICMP echo request message to host expecting an ICMP echo reply to be returned Application Note CMX Micronet for 78K0 Family 11 Chapter 2 TCP IP stack theory including application layers 22 4 Application Ports The main area s of concern during the development of an embed
22. the destination is known replace ip dest addr with that address If you are dialing into an ISP the source and destination addresses initially specified do not matter as they will be negotiated Al Hif ETHERNET if HTTP II FTP Il SMTP byte ip_dest_addr IP_ADDR_LEN 216 233 5 32 byte ip_src_addr IP_ADDR_LEN 216 233 5 26 else byte ip_dest_addr IP_ADDR_LEN 209 67 233 68 byte ip_src_addr IP_ADDR_LEN 209 67 233 67 endif F HTTP II FTP else byte ip_dest_addr IP_ADDR_LEN 192 6 94 5 byte ip_src_addr IP_ADDR_LEN 192 6 94 2 endif ZG Ethernet if ETHERNET A SEALERS Ee if using a chip with EEPROM you may need to write a routine to take the value of the hw_addr in EEPROM and put it into the array below on startup otherwise replace eth_src_hw_addr below with the proper Ethernet hardware address REAP ESE AE AEE TELA ne OPA ORES SE eee dee byte eth_src_hw_addr ETH_ADDR_LEN 0x00 0x00 0x00 0x12 0x34 0x56 EE ES EARS EE EEREN ERA L SEER AE IE EA If ARP is used the array below is used as a temporary holder for the destination hardware address It does not have to be changed If ARP is not being used replace the hardware address below with the hardware address of the destination The hardware address used MUST be the correct one REG O EE byte eth_dest_hw_addr ETH_ADDR_LEN 0x00 0xE0 0x98 0x03 0xE5 0xFA endif ETHERN
23. wait for a request from the client The server responds to the task give by the client Therefore HTTP Server means that this application must wait for a resonse from the client which is external to the device running CMX Micronet 14 Application Note CMX Micronet for 78K0 Family Chapter3 System Configuration 3 System Configuration The following was developed on the 78K Test It evaluation board However this document is designed to be used irrespective of the 78KO device used For evaluation purposes the following options have been enabled within the object code time limited version to simplify the approval process for the CMX Micronet protocol stack All other options listed at the front of this document have been tested and will be available once evaluation has been completed and C source code provided User Application Application Layer Transport Layer Network Layer Link Layer HTML Web pages Server Side Includes SSI POST functions Virtual file System HTTP server PING TCP 6 sockets IP ICMP PPP UART driver Direct Cable connection via RS232 Figure 3 1 shows a block diagram of the software functional blocks within the evaluation system Application Note CMX Micronet for 78K0 Family 15 Chapter3 System Configuration Figure 3 1 Functional Blocks within CMX Micronet
24. 1 0 strcpy char jett char AtoD return word16 strlen char AtoD word16 getAtoD_funcO byte et cmx_reentrant AtoD_Values DEC_ASCII AtoD_buff 0 3 1 strcpy char str char AtoD return word16 strlen char AtoD word16 getAtoD_func2 byte str cmx_reentrant DEC_ASCII AtoD_buff 2 3 1 strcpy char jett char AtoD return word16 strlen char AtoD word16 getAtoD_func3 byte str cmx_reentrant DEC_ASCII AtoD_buff 3 3 1 strcpy char jett char AtoD return word16 strlen char AtoD word16 Version_func byte str cmx_reentrant DEC_ASCII Version 4 1 strcpy char str char AtoD return word16 strlen char AtoD word16 Code_func byte str cmx_reentrant 68 Application Note CMX Micronet for 78KO Family Chapter7 Example Code DEC_ASCIl Code 3 1 strcpy char str char AtoD return word16 strlen char AtoD endif if SERVER SIDE INCLUDES endif EXAMPLE TYPE HTTP EXAMPLE 7 2 1 2 Callback c ed EE EE Copyright c CMX Systems Inc 2001 All rights reserved EE BE AE SE AA ES ERARIO ee EE AA CMX recommends making a copy of this file before changing any of the routines below S KERE KREET EER KEER KOR ek RA dek ek de de EE KEER ER ER PEE include micronet h EE ME EE EG EE EE de Change the ip_src_addr below to relect the IP address of your target If the IP address of
25. 44 45 61 63 64 88 Memory Map 17 Mn app http server de 36 54 74 Mn app init FeCV sesse ees ee ee 33 37 52 73 Mn_app_process_packet 33 38 53 73 Mn app recv bie sees esse ee 33 38 52 73 Mn app recv idle n 38 54 74 Application Note CMX Micronet for 78K0 Family Index Mn of del entY ee ee Re Re ee ee 41 Mn of get ent 34 40 Mn of set entnm eee 31 41 45 64 Mn http find value sesse esse ee ee 33 50 69 70 Mn http mn FECV ees ee ee ee 33 52 73 Mn http process packet sesse 33 53 73 Mn http recv byte A 33 53 73 Mn http server 33 46 66 MOI EER N EE EE 30 33 44 64 A EE EE OE 36 Mn modem connect sesse 31 38 45 65 Mn modem disconnect 32 38 45 46 65 66 Mn modem send striNg seeen 38 Mn modem wait reply esse ee ee 38 Mn pf del entY ees ee Re Re ee ee 41 Mn pf get eN ese ee ee ee 33 41 Mn pf set eNtY ecen 30 41 45 64 Mn opp close 31 36 46 66 Mm opp open 36 45 65 OR ee ER OE EE EE EE OE a 36 Mn tep aborts EO EE OE a 34 35 Moes EL OE 34 Mn cp re see ee ee ee 34 52 53 73 74 Mn tcp send sees ee 34 52 72 Mn tcp sbutdown sees ee ee Re ee 34 Mn vf del entY 0 0 ee ee Re eke 39 Mn vi get entY ees ees ske ee Re ee ee 33 39 Mn vi set ent ees ees ese ee ee 30 39 40 64 MODEMS 27 30 31 32 34 36 38 42 44 45 46 61 63 64 65 66 MODEM MODE ee 30 42 44 61 63 Network Layer
26. E AAA EA EE define EXAMPLE TYPE HTTP EXAMPLE if IUDP AS EXAMPLE TYPE UDP EXAMPLE error UDP example selected without UDP endif if TCP 88 EXAMPLE TYPE TCP_EXAMPLE error TCP example selected without TCP endif if HTTP ASA EXAMPLE TYPE HTTP EXAMPLE error HTTP example selected without HTTP endif if FTP amp amp EXAMPLE TYPE FTP_EXAMPLE error FTP example selected without FTP endif Application Note CMX Micronet for 78K0 Family 59 Chapter7 Example Code HIFISMTP amp amp EXAMPLE TYPE SMTP_EXAMPLE error SMTP example selected without SMTP endif if EXAMPLE TYPE HTTP EXAMPLE EXAMPLE TYPE FTP EXAMPLE put includes for Web pages here include index h include page2 h include necem h include table h endif EXAMPLE TYPE HTTP EXAMPLE EXAMPLE TYPE FTP_EXAMPLE if EXAMPLE TYPE HTTP EXAMPLE undef SERVER MODE define SERVER MODE 1 void ed msg func PSOCKET INFO cmx_reentrant void ed stop func PSOCKET INFO cmx reentrant if SERVER SIDE INCLUDES word16 getMsg func byte cmx_reentrant word16 dice_func byte cmx_reentrant word16 getAtoD_funcO byte cmx_reentrant word16 getAtoD func2 byte cmx_reentrant word16 getAtoD_func3 byte cmx_reentrant word16 Version_func byte cmx_reentrant word16 Code func byte cmx_reentrant endif elif EXAMPLE TYPE FTP EXAMPLE for now ftp is only serv
27. E ANSWER_MODE connect_mode ANSWER_MODE else connect_mode DIAL_MODE endif endif MODEM if PPP if SERVER_MODE open_mode PASSIVE_OPEN else open_mode ACTIVE_OPEN endif endif if PPP if defined POL78KO0 II defined CMX78K0 DEC ASCII conversion put your hardware initialisation routines here for all peripherals and sfr s Except Timer and UART used by stack vHardwarelnit vSoftwarelnit Variable Initialization endif call mn_init before using any other MicroNet API functions mn_init if defined BORLANDC II defined _MSC_VER old1b getvector 0x1b setvector 0x1b onbreak stop ctrl break setvector 0x23 onbreak atexit cmx_restore Application Note CMX Micronet for 78K0 Family 61 Chapter7 Example Code endif if defined __BORLANDC__ Il defined _MSC_VER if EXAMPLE TYPE HTTP EXAMPLE EXAMPLE TYPE FTP EXAMPLE add Web pages to virtual file system The main page MUST be first mn_vf_set_entry byte index htm INDEX SIZE void index_htm VF_PTYPE_STATIC mn_vf_set_entry byte page2 htm PAGE2_SIZE void page2_htm VF_PTYPE_STATIC mn_vf_set_entry byte necem gif NECEM_SIZE void necem_gif VF_PTYPE_STATIC mn_vf_set_entry byte table gif TABLE SIZE void table_gif VF_PTYPE_STATIC if EXAMPLE_TYPE HTTP_EXAMPLE add post functions to be used with fo
28. ET Application Note CMX Micronet for 78K0 Family 69 Chapter7 Example Code JE e return number of bytes to send Called from mn_tcp_send and mn_udp_send word16 mn_app_get_send_size PSOCKET_INFO socket_ptr cmx_reentrant word16 bytes_to_send bytes_to_send socket_ptr gt send_ptr PTR_NULL 0 socket_ptr gt send_len if HTTP Il FTP II SMTP if socket_ptr gt socket_type amp HTTP_TYPEISMTP_TYPE II socket_ptr gt src_port FTP_DATA_PORT bytes_to_send bytes_to_send gt TCP_WINDOW TCP WINDOW bytes_to_send endif return bytes_to_send initialization before receiving a packet Called from mn_tcp_recv and mn_udp_recv num number of bytes to be received void mn_app_init_recv word16 num PSOCKET_INFO socket_ptr cmx_reentrant if FTP amp amp FTP_SERVER num num endif I FTP 88 FTP_SERVER socket_ptr gt recv_len 0 if HTTP if socket_ptr gt socket_type amp HTTP_TYPE mn_http_init_recv else endif if FTP amp amp FTP_SERVER if socket_ptr gt socket_type amp FTP_TYPE mn_ftp_server_init_recv num socket_ptr else endif put your code here process received byte Called from mn_tcp_recv and mn_udp_recv void mn_app_recv_byte byte c PSOCKET_INFO socket_ptr cmx_reentrant if HTTP if socket_ptr gt socket_type amp HTTP_TYPE mn_http_recv_byte c else endif if FTP amp amp FTP_SE
29. ET function are a feature of the HTML language It allows the Web server to skim the contents of the HTML file looking for server based commands When it finds one it performs the requested action and places the results of the action in the place of the SSI statement This is ideal for an embedded application because it allows the results of some action to be viewed within a Web browser Such applications allow the user implement such things as remote diagnostics etc 2 4 1 2 POST Functions A POST function is another HTML feature lt is used when form data is sent from the Web browser to the embedded Web server The function allows the transfer of of data back to the embedded Web server which the embedded Web server can at apon An application of this type would use a POST function to change variables within the Web server which can be acted apon by a user application 2 4 2 XML Extensible Markup Language can be used in conjunction with HTML to allow the creation and management of data which can be kept on the embedded Webserver XML enables data processing that HTML is unable to do Typical examples of the use of XML include the efficient use of database management and so on an embedded Webserver a very simple database can be implemented such as a datalogger when the data needs to be addressed in a simple way using a Web browser 2 4 3 JAVA JAVA applets allow JAVA enabled Web browsers to compile from within a HTML document JAVA code to r
30. E_TYPE FTP_EXAMPLE mn_ftp_server see ftpservr c elif EXAMPLE_TYPE SMTP_EXAMPLE doSMTP endif EXAMPLE TYPE UDP EXAMPLE if DHCP mn_dhcp_release elif PPP mn_ppp_close endif if PPP if MODEM mn_modem_disconnect endif MODEM EXIT O if EXAMPLE_TYPE UDP_EXAMPLE void doUDP void cmx_reentrant CHAR socket_no PSOCKET_INFO socket_ptr byte data_ptr word16 data_len int status if SERVER_MODE socket_no mn_open ip_dest_addr ECHO_PORT 0 PASSIVE_OPEN PROTO_UDP STD_TYPE data_buff DATA_BUFF_LEN data_ptr PTR_NULL data_len 0 else client mode socket_no mn_open ip_dest_addr DEFAULT_PORT ECHO_PORT ACTIVE_OPEN PROTO_UDP STD_TYPE data_buff DATA_BUFF_LEN data_ptr TESTSTRING data_len strlen char TESTSTRING endif if socket no lt 0 did we open socket successfully EXIT 1 socket_ptr MK_SOCKET_PTR socket_no get pointer to the socket while 1 if defined BORLANDC II defined _MSC_VER if bios keybrd KEYBRD READY check if ctrl c pressed if _bios_keybrd _KEYBRD_READ amp Oxff 3 44 Application Note CMX Micronet for 78K0 Family Chapter7 Example Code mn_close socket_no break endif if defined BORLANDC II defined _MSC_VER status 0 if data_ptr PTR_NULL status mn_send socket_no data_ptr data_len if status lt 0 data_
31. Function call was successful negative number Could not establish a connection This function connection the CMX Micronet device to another MODEM mn modem disconnect This function puts the MODEM into command mode and hangs up the MODEM mn modem send string const byte word16 Where const byte Is the pointer to the MODEM string word116 Length of the reply This function sends a string of a passed length to the MODEM mn_modem_wait_reply const byte word16 word16 Where const byte Is the string to get from the MODEM word16 Is the length of the string to get word16 is the number of system ticks to wait for string Returned Status 1 function call was successful 1 could not establish a connection 36 Application Note CMX Micronet for 78KO Family Chapter6 Application Programmers Interface API 6 8 Virtual File System mn_vf_get_entry byte Where byte is the name of the Web page to look up Returned Status A pointer to the directory table entry corresponding to the passed name This function returns a pointer to the directory entry crresponding to the passed file name mn_vf_set_entry mypage htm page size page_ptr page type Where mypage htm is the name of the page to insert into the virtual file table Page size is the number of bytes in the page pointed to by page ptr page_ptr is the address of the Web page to be added to the table page type is either VF_PTYPE_DYNAMIC for the file to be
32. KO Family Index ACTIVE_OPEN 30 34 36 44 46 48 64 66 67 ACTIVE OPEN 44 64 ANSWER_MODE ossee 38 42 44 61 63 ANSWER MODE A 44 63 Application Layer 9 11 15 Application Porte 12 ARP re ESE aguas 9 12 13 B2 57 72 78 Array Total EE 19 BODY BUFEER te Eed EE als 19 21 BOOTP tend ed isi 9 11 12 44 45 46 63 65 Callback 16 24 25 27 33 36 42 51 71 oa RE dE 14 DHC Pirireis 9 12 45 46 57 65 66 78 DIAL MODE sesse esse seke 38 42 44 61 64 DIAL MODE i e sesse ese ee ke ge iaeiei 44 64 DIRECT CONNECT esse ees eek ee eke ee 31 BERE EE ER OE 11 EXAMPLE TYPES30 42 43 45 46 47 49 50 51 61 62 63 64 65 66 67 68 69 70 71 EXGC OOl RA EE eps 26 34 40 FTP9 11 12 20 27 30 42 43 45 46 51 52 53 54 61 62 64 65 66 72 73 74 Pil SE 12 27 FIP NUM USERS ese ees ee ee ee ee ee 20 GE Tu Ee De ee rah Dt bond 20 33 41 HTMLY 12 13 15 21 25 26 27 30 31 33 39 40 61 83 elle ica tl 30 HTTPg9 11 12 13 14 15 19 21 26 27 30 31 33 42 43 45 46 50 51 52 53 54 61 62 63 64 65 66 69 70 71 72 73 74 HTTP Semer eege eeue Gee ee vee cd iaa 12 14 31 HTTP BUFFER LENA 21 HTTP Tal SR Ee Ee Ee ee Gee ese Ge Ge ede 19 COMP tata is 9 10 11 15 36 INTSERO ui 23 56 77 INTSRO EE 23 56 76 INS TO siria cad 23 57 77 JAVA aii dia 13 Link Layer 9 15 18 21 Maing8 10 11 12 28 30 40
33. MODEMs still use this protocol and so it is still provided 12 Application Note CMX Micronet for 78K0 Family Chapter 2 TCP IP stack theory including application layers 2 3 2 Ethernet 2 3 2 1 ARP Address Resolution Protocol provides a mapping between two different forms of addresses The 32 bit IP address to the 48 bit Ethernet Address MAC address This mapping is held in the form of a table of the locally connected devices on the network 2 3 2 2 RARP Reverse Address Resolution Protocol works in the reverse direction to ARP in that it contains a mapping of the 48 bit Ethernet Address to the 32 bit IP address 2 4 User Application The User Applications contain customer specific applications These specific applications interact through the various application ports and application programs within the TCP IP protocol stack The file System contains a list of the files available to the user both in ROM and RAM 2 4 1 HTML HyperText Markup Language is a markup language which is a text only language lt is not a high level language such as C but instead of being compiled and executed it is read or interpreted by what is termed a user agent The user agent is commonly known as a Web browser HTML uses HTTP to transfer information independent of the type of computer or language and allows the of exchange of information across different networks 2 4 1 1 Server Side Includes SSI Server Side Includes sometimes known as a G
34. NEC Application Note CMX Micronet For 78K0 Family Application Programmers Interface Document No U16225EE1VOANOO Date published April 2002 O NEC Corporation 2002 Printed in Germany Table of Contents 2 Application Note CMX Micronet for 78K0 Family 6 Server Side Include Setup PC Connection Started Application Note CMX Micronet for 78K0 Family 3 List of Figures 4 Application Note CMX Micronet for 78K0 Family List of Tables able 3 1 Array RAM usage able 4 1 VO Assignment Application Note CMX Micronet for 78K0 Family 5 Introduction Target Readers Purpose Organization How to use this Manual Conventions Note Caution Remark Numeric notation Introduction This application note is intended for users who understand the functions of the 78KO family and who design application systems using these microcontrollers The software was developed on the 78K Test It kit but can be provided in source code format to be used on any 78KO microcontroller The purpose of this application note is to help users understand the use and composition of CMX Micronet functions and to understand how users can interact with a protocol stack and various application layers associated with connectivity The system example uses the 78K Test lt application programs to demonstrate the use of CMX Micronet Application features include Web page development interaction POST SSI and the use of
35. OUNT volatile word16 uart_errors endif extern void vTimer1 void if PPP II SLIP 52 Application Note CMX Micronet for 78KO Family Chapter7 Example Code void mn uart init void cmx_reentrant DISABLE_INTERRUPTS init_io_buffs do not remove this function call put uart init code here if defined D78076 PM70 1 Set RXD to input mode PM71 0 Set TXD to output mode P7 1 1 endif if defined D78F0034 II defined D78F0078 PM23 1 Set RXD to input mode PM24 0 Set TXD to output mode endif if defined D78F0066 PM73 1 Set RXD to input mode PM72 0 Set TXD to output mode endif if defined D78F0828 PM62 1 Set RXD to input mode PM63 0 Set TXD to output mode endif if defined D78F0034 II defined D78F0066 II defined D78F0078 defined D78F0828 ASIMO 0x08 disable uart No Parity 8bit 1stop BRGCO Baud 38400 4 194304MHz SRIFO FALSE Clear Interrupt request reception complete STIFO FALSE Clear Interrupt request transmision complete SRMKO FALSE Enable Interrupt reception complete STMKO FALSE Enable Interrupt transmision complete ASIMO 0xC8 Enable UART receive and transmit endif if defined D78076 ASIM 0x09 disable uart No Parity 8bit 1stop BRGC Baud_38400_5MHz 38400 O 5Mhz SRIF FALSE Clear Interrupt request reception complete STIF FALSE Clear Interrupt request trans
36. P Application ArrayTotal Compiled arrays in different layers The following equation shows the relationship between the link layer receive and transmit buffers and the size of the network layer TCP buffers Remark TCP WINDOW lt RECV_ BUFF SIZE bytes RECV _ BUFF _ SIZE TCP WINDOW ie 2 3 wholenumbe r The equation shows that the TCP buffer must be smaller than the receive and transmit buffers to ensure that a complete TCP packet can be encapsulated within the link layer buffers For successful operation the relationship between the TCP buffer and the link layer buffers must be a multiple ie if RECV_BUFF_SIZE is 512 bytes then TCP_WINDOW can be 64 128 or 256 bytes HTTP Application requires 3 different buffers depending on the type of implementation required The following equation shows how to calculate the total RAM requirement for this application where Remark HTTPTotal URI_ BUFFER _ LEN BODY BUFFER _ LEN HTTP BUFFER _ LEN URI_BUFFER_LEN is used to store URI data from Server Side Include requests Default 64 bytes BODY_BUFFER_LEN is used to store body data from POST requests Default 64 bytes HTTP_BUFFER_LEN size is set from the Virtual Files Section 3 2 3 Both of these buffers will need to be increased if more than 64 bytes are required for either type of function Application Note CMX Micronet for 78K0 Family 19 Chapter3 System Configuration To help understand the RAM requirements for th
37. PP XP PP Sm ae Ere ad PP a e ad ae I Cong ie Der gee ee ee PP eed ed are ees Semen ebe Ir a rr e ebessen dice main function K void dice void unsigned char i vFlashLED 2 Signal end of initialization if bKey1Flag 1 bKey1Flag 0 Reset status bit key1 ucThrow ucRandom Get random number ucLEDs 0xFE for i 1 i lt ucThrow i ucLEDs ucLEDs lt lt 1 Output of new value Application Note CMX Micronet for 78K0 Family Chapter7 Example Code 7 2 1 8 Interrupt c PROJECT 78K0 Demonstration Board Electronic Dice MODULE interrupt c SHORT DESC DEVICE uPD78F0066 VERSION 1 1 DATE 05 02 2002 LAST CHANGE TA SEER EE ED ASBES EE EE EIE SESSE SERIES SEE SS EE ES SEE kk Environment Device uPD78F0066 Assembler A78000 Version V3 33A Ke C Compiler I1CC78000 Version V3 33A CS Linker XLINK Version V4 52J By NEC Electronics UK Ltd is Cygnus House E Sunrise Parkway Wa Linford Wood aa Milton Keynes UK MK14 6NP include lt in78000 h gt ttinclude df0066 h include micronet h Ml rana Global variables HE extern bit bTimer50Flag Status Flag Timer50 extern bit bTimer51Flag Status Flag Timer51 extern bit bKey1Flag Status Flag Key1 extern bit bKey2Flag Status Flag Key2 extern saddr unsigned char ucLEDs static saddr unsigned char ucOldLEDs void vTimer1 void ZS o ad Module name vTimerO Descrip
38. RVER if socket_ptr gt src_port FTP CONTROL PORT mn ftp server recv byte c else endif if socket_ptr gt recv_ptr PTR_NULL copy the data into a buffer where we will deal with it later if socket_ptr gt recv_ptr socket_ptr gt recv_len lt socket_ptr gt recv_end 70 Application Note CMX Micronet for 78K0 Family Chapter7 Example Code socket_ptr gt recv_ptr socket_ptr gt recv_len c socket_ptr gt recv_len Process received packet Called from mn_tcp_recv and mn_udp_recv void mn_app_process_packet PSOCKET_INFO socket_ptr cmx_reentrant if HTTP if socket_ptr gt socket_type amp HTTP_TYPE mn_http_process_packet socket_ptr else endif if FTP amp amp FTP_SERVER if socket_ptr gt src_port FTP_CONTROL_PORT mn_ftp_server_process_packet socket_ptr else if socket_ptr gt src_port FTP_DATA_PORT mn_ftp_server_process_data socket_ptr else endif remove the next line and put your code here socket_ptr socket_ptr if TCP ia Do what needs to be done after successfully sending a packet Called from mn_tcp_recv void mn_app_send_complete word16 data_len PSOCKET_INFO socket_ptr cmx_reentrant if socket_ptr gt send_len gt 0 socket_ptr gt send_len data len subtract bytes already sent move pointer to next spot to start sending if anything left to send or set itto PTR_NULL otherwise if socket_ptr
39. SISO amp 0x01 d overrun error H temp RXBO if errors must read RXB to clear rubbish data else if ASISO amp 0x04 parity error else if ASISO amp 0x02 framing error P5 0 Visual Test for errors endif place service routine for transmit buffer here if defined D78F0034 II defined D78F0066 defined D78F0078 I defined D78F0828 interrupt INTSTO_vect using 2 void VUARTTransmit void A P5 7 0 if send_out_ptr send_in_ptr TXSO send_out_ptr send_out_ptr else 54 Application Note CMX Micronet for 78K0 Family Chapter7 Example Code xmit_busy 0 STMKO 1 Wi P5 7 1 Wi P5 7 1 PPP II SLIP endif if defined D78076 interrupt INTST_vect using 2 void vUARTTransmit void if send_out_ptr send_in_ptr TXS send_out_ptr send_out_ptr else xmit_busy 0 PPP II SLIP endif put timer isr here if defined D78F0034 II defined D78F0066 defined D78F0078 II defined D78F0828 interrupt INTTM50_vect using 1 void vTimer void endif if defined D78076 interrupt INTTM1_vect using 1 void vTimer void endif timer_tick if DHCP mn_dhcp_update_timer endif DHCP if ARP amp amp ARP_TIMEOUT mn_arp_update_timer endif ARP amp amp ARP_TIMEOUT void mn_timer_init void cmx_reentrant DISABLE INTERRUP
40. T 1 elif BOOTP if mn_bootp PTR_NULL amp bp gt 0 if the define BOOTP_REQUEST_IP was set to 0 should check here if bp yiaddr is different than ip_src_addr if TFTP length mn_tftp_get_file bp siaddr bp file testBuffer TESTLEN if length lt 0 TFTP error EXIT 1 endif TFTP else BOOTP error EXIT 1 elif TFTP tftp without bootp or dhcp replace boot mn with the file you wish to retrieve length mn_tftp_get_file ip_dest_addr byte boot mn testBuffer TESTLEN if length lt 0 TFTP error EXIT 1 endif BOOTP if EXAMPLE TYPE UDP EXAMPLE doUDP elif EXAMPLE TYPE TCP EXAMPLE doTCP elif EXAMPLE TYPE HTTP EXAMPLE mn http server see http c elif EXAMPLE_TYPE FTP_EXAMPLE mn_ftp_server see ftpservr c elif EXAMPLE_TYPE SMTP_EXAMPLE doSMTP endif EXAMPLE TYPE UDP EXAMPLE if DHCP mn dhcp release elif PPP mn ppp close endif if PPP if MODEM mn_modem_disconnect endif MODEM EXIT O if EXAMPLE_TYPE UDP_EXAMPLE void doUDP void cmx_reentrant CHAR socket_no PSOCKET_INFO socket_ptr byte data_ptr word16 data_len int status if SERVER_MODE socket_no mn_open ip_dest_addr ECHO_PORT 0 PASSIVE_OPEN PROTO_UDP STD_TYPE data_buff DATA_BUFF_LEN data_ptr PTR_NULL Application Note CMX Micronet for 78K0 Family 63
41. TS put timer init code here Must achieve 10ms count for operation if defined D78076 TMC1 0x00 Stop timer operation TCL1 OXFD Set timer clock fx 249 5MHz gt 9800 Hz CR10 0x31 Timer1 compare value gt 10 00ms intervall TOC1 0x03 Set to output mode PM31 0 Set to output Mode TMIF1 FALSE Clear interrupt request Bit Timer1 TMMK1 FALSE Enable Timer1 Interrupt TMC1 0x01 output no cascade mode endif if defined D78F0828 TMC50 0x00 Stop timer operation TCL50 0x05 Set timer clock fx 248 4 194304 MHz gt 16384 Hz CR50 0x52 Timer50 compare value gt 10 01ms intervall TMC50 0x03 output no cascade mode Application Note CMX Micronet for 78K0 Family 55 Chapter7 Example Code if defined D78F0034 Il defined D78F0066 Il defined D78F0078 endif TMC50 0x00 TCL50 0x06 CR50 0x52 TMC50 0x03 endif Stop timer operation Set timer clock x 248 4 194304 MHz gt 16384 Hz Timer50 compare value gt 10 01ms intervall output no cascade mode if defined D78F0034 Il defined D78F0078 PM72 0 TMIF50 FALSE TMMK50 FALSE TMC50 7 1 endif if defined D78F0066 PM22 0 TMIF50 FALSE TMMK50 FALSE Set to output Mode Clear interrupt request Bit Timer50 Enable Timer50 Interrupt Set to output Mode Clear interrupt request Bit Timer50 Enable Timer50 Interrupt
42. V_BUFF_SIZE if recv_count lt RECV_BUFF_SIZE 1 Fix for buffer management problems RTS 0 recv_in_ptr RXB recv_count if recv_in_ptr gt amp recv_buff RECV_BUFF_SIZE 1 recv_in_ptr amp recv_buff 0 else RTS 1 endif if defined D78F0034 defined D78F0066 defined D78F0078 defined D78F0828 interrupt INTSERO_vect using 3 void eri0 void byte temp if KEEP_ERROR_COUNT uart_errors endif if ASISO amp 0x01 d overrun error Wi temp RXBO if errors must read RXB to clear rubbish data else if ASISO amp 0x04 parity error else if ASISO A 0x02 framing error P5 0 Visual Test for errors endif place service routine for transmit buffer here if defined D78F0034 II defined D78F0066 defined D78F0078 II defined D78F0828 interrupt INTSTO_vect using 2 void VUARTTransmit void A P5 7 0 if send_out_ptr send_in_ptr TXSO send_out_ptr send_out_ptr 74 Application Note CMX Micronet for 78K0 Family Chapter7 Example Code else xmit busy 0 STMKO 1 Wi P5 7 1 1 P5 7 1 PPP II SLIP endif if defined D78076 interrupt INTST_vect using 2 void vUARTTransmit void if send out ptr send in Dir TXS send_out_ptr send_out_ptr else xmit_busy 0 PPP II SLIP endif put timer isr here if de
43. a connection SOCKET NOT FOUND Invalid socket pointer passed to function This function is used to establish a TCP connection All initialisation must be done and MODEM and PPP connection must be established before calling this function mn tcp send PSOCKET INFO Where PSOCKET INFO is the socket pointer Returned Status Number of bytes sent Function call was successful O No data to send TCP_ERROR Unable to send packet TCP_TOO_LONG Packet is too long tp send in one piece This function sends a packet using data pointed to by the send_ptr mn_tcp_recv PSOCKET_INFO Where PSOCKET_INFO is a pointer to the socket pointer Returned Status Number of bytes received Function call was successful NEED_TO_LISTEN A reply to the received packet was atomatically sent and should wait for an answer TCP_BAD_HEADER The received packet had a bad header TCP_BAD_CSUM The TCP checksum failed TCP_BAD_FCS The PPP frame check sequence failed This function receives a TCP packet from a remote TCP The received packet will be assigned to the correct socket a new socket is opened if necessary mn_tcp_shutdown PSOCKET_INFO Where PSOCKET_INFO is the socket pointer This function closes the current TCP connection for the passed socket This function should be used when the connection with the remote is working correctly If the other side is not responding the function mn_tcp_abort should be used instead mn_tcp_abort PSOCKET_INFO 34 Appli
44. able Port PO 2 interrupt Mask Flag Register 8 Bit Timer setting Timer 50 setup in NEC_HW_v2_15f for Micronet Stack implementation ext Interrupt setting If EGP 0x0C EGN 0x00 PMK3 FALSE PMK2 TRUE If TMC51 0x00 TCL51 0x07 CR51 0x66 Y 1 TMIF51 FALSE TMMK51 FALSE TMC51 0x00 16 Bit Timer setting TMCO 0x00 CRCO 0x00 CROO 0x028f TOCO 0x00 PRMO 0x02 TMIFOO FALSE TMMKOO FALSE 78 Stop timer operation Set timer clock x 2411 4 914304MHz gt 2048 Hz Timer51 compare value gt 50ms intervall Clear interrupt request Bit Timer51 Enable Timer51 Interrupt Timer 51 setting no output single mode clear and start by matching TM51 and CR51 Stop and Clear Timer 0 Register CROO CRO1 operate as compare register Compare values for 10ms Intervall Disable Timer output Clock selection fx 246 4 914304MHz gt 65537 Hz Clear interrupt request Bit TimerO Enable Timer0 Interrupt Application Note CMX Micronet for 78K0 Family Chapter7 Example Code TMCO 0x02 Clear and start on match between TMO and CROO TMCO Ox0C Start Timer O Compiler Version Number setting VEE Compiler Version Number _ VER Must be left in code so Micronet will work with current compiler version endif if defined D78076 clock generator setting VEE PCC 0x00 Use high spe
45. and waits for an ACK Some echo servers will return the ACK and the data in the same packet so we need to handle that case if data_ptr PTR_NULL status mn_send socket_no data_ptr data_len if status gt 0 amp amp socket_ptr gt recv_len gt 0 data_ptr socket_ptr gt recv_ptr data_len socket_ptr gt recv_len continue if status lt O ll socket_ptr gt tcp_state TCP_CLOSED break do status mn recv socket no data bunt DATA BUFF LEN while status NEED TO LISTEN if status lt 0 amp amp status SOCKET TIMED OUT break if we got something send back what we got if status gt 0 data Dir socket ptr recv Dir data len socket ptr recv len if PPP if ppp_status up break endif PPP mn_abort socket_no endif EXAMPLE_TYPE TCP_EXAMPLE if EXAMPLE_TYPE SMTP_EXAMPLE replace the email addresses below byte from frodo cmx com byte to bilbo cmx com byte subject SMTP test 46 Application Note CMX Micronet for 78K0 Family Chapter7 Example Code byte message This is the message body Mn byte attach This is the attachment Ann byte fname micronet txt void doSMTP void cmx_reentrant CHAR socket_no CHAR retval SMTP_INFO_T mail_info socket_no mn_smtp_start_session DEFAULT_PORT if socket_no gt 0 send a message with an attachment
46. ation If more detailed information is required to customise how the CMX Micronet stack is used then the full CMX Micronet User Manual would be provided with the source code version 6 1 initialisation mn_init This function initialises CMX Micronet This function must be called before any CMX Micronet function 6 2 HTTP mn_http_server This function opens a TCP socket and waits for a HTTP request from the client Additional sockets are opened and closed as and when required to service client requests This function does not close down unless there is an error in opening a socket or PPP connection is shut down by the client as shown in Figure 5 5 The callback function mn_app_server_idle when no packets are being processed mn_http_init_recv This function performs initialisation if HTTP variables when receiving data starts It is also called from the Callback function mn_app_init_recv mn_http_recv_byte c Where c is the latest byte retreived from the HTTP packet This function processes a received byte It is called from the Callback function mn_app_recv_byte The type of HTTP request is detirmined There are three types of acceptable requests SSI GET HEAD and POST mn_http_process_packet PSOCKET_INFO Where PSOCKET_INFO is the socket pointer This function processes a received packet It is called from the Callback function mn_app_process_packet If the HTTP is SSI GET or HEAD the function will use the mn_vf_get_entr
47. bject only time limited version is supplied with this system An outline of the features enabled in this version are described in Chapter 3 Features of CMX Micronet TCP IP Stack User Application HTML Web pages Server Side Includes SSI POST functions Virtual file System Application Layer SMTP client HTTP server FTP server TFTP BOOTP DHCP PING Transport Layer TCP UDP Network Layer IP ICMP Link Layer ARP PPP PAP SLIP Ethernet Driver UART driver MODEM or direct Cable connection via RS232 Support for 16 sockets using UDP or TCP All 16 sockets can be either Ethernet PPP or SLIP but not mixed Due to the low ROM and RAM footprint to Micronet there are certain departures made from the RFC standards to implement this Restrictions PPP can negotiate IP addresses but all other options are ignored TCP ignores all options Micronet does not handle fragmented packets For evaluation purposes the CMX Micronet stack is time limited However these restrictions do not affect the development of an application requiring Internet protocol based connectivity Application Note CMX Micronet for 78K0 Family 9 Chapter 2 TCP IP stack theory including application layers 2 TCP IP stack theory including application layers This chapter is designed to highlight the basic protocols available within the CMX Micronet TCP IP stack and to give a brief overview of each It is assumed that the theory behind how the TCP IP stack operates and
48. cation Note CMX Micronet for 78K0 Family Chapter6 Application Programmers Interface API Where PSOCKET INFO is the socket pointer This function reset the TCP statemachine for the current passed socket This function should not be used if the remote is working correctly 6 4 IP mn ip recv Returned Status O No packet received or the packet received had an IP address that was not one of ours Greater than zero one of the packet types defined in ip h was found This function receives either an Ethernet PPP or SLIP header and the IP header IF an ICMP request is received it will send an ICMP reply if a PING request is sent 6 5 PPP mn_ppp_close This function closes a PPP connection without waiting for a response and resets the PPP state machine mn_ppp_open type Where Type is either ACTIVE_OPEN or PASSIVE_OPEN depending on client or server mode Returned Status 1 Function call wa successful O Could not establish a connection This function is used ot establish a PPP connectionwith a remote PPP Before this can take place all initialisation must be done including the MODEM connection mn_ppp_reset This function resets the PPP statemachine This function should only be called if an error condition exists 6 6 Callback mn_app_get_send_size PSOCKET_INFO Where PSOCKET_INFO is the socket pointer Returned Status Number of bytes to send in current packet This function is called from various other functio
49. cronet for 78K0 Family Chapter7 Example Code mn smtp end session socket no endif EXAMPLE_TYPE SMTP_EXAMPLE if EXAMPLE_TYPE HTTP_EXAMPLE this function is called from a Web page by an HTTP POST request void od msg func PSOCKET INFO socket_ptr cmx_reentrant we are expecting a variable called display with escaped string e g display hello 2C world 21 where equals and XX is a hexadecimal representation of a char msg_buff will have decoded value if available if mn_http_find_value BODYptr byte display msg_buff if ISERVER SIDE INCLUDES Just return good status socket_ptr gt send_ptr byte HTTPStatus204 socket_ptr gt send_len STATUS 204 LEN else inthis example we are always returning index htm we will cheat here and assume index htm is the first entry in the virtual file directory P5 ASCII_DEC msg_buff bKey1Flag 1 Allow Web page to update dice throw socket_ptr gt send_len vf_dir 0 page_ size socket_ptr gt send_ptr vf_dir 0 page_ptr mn_http_process_includes socket_ptr endif if ISERVER SIDE INCLUDES else variable not found issue a bad request error message socket_ptr gt send_ptr byte HTTPStatus400 socket_ptr gt send_len STATUS_400_LEN if EXAMPLE_TYPE HTTP_EXAMPLE this function is called from a Web page by an HTTP POST request void Icd_stop_func PSOCKET_INFO s
50. ddr IP_ADDR_LEN 209 67 233 67 endif HITP II FTP else byte ip_dest_addr IP_ADDR_LEN 192 6 94 5 byte ip_src_addr IP_ADDR_LEN 192 6 94 2 endif Ethernet if ETHERNET ER ERERASERER EARS EEEEE EER SPREE ES REREL SEERA EELS ER EERE ESE REE EY if using a chip with EEPROM you may need to write a routine to take the value of the hw_addr in EEPROM and put it into the array below on startup otherwise replace eth_src_hw_addr below with the proper Ethernet hardware address EE EE Ad ESE RAER ERE AA byte eth_src_hw_addr ETH_ADDR_LEN 0x00 0x00 0x00 0x12 0x34 0x56 ES ERERESSAERELS ERR ELEN EE AR SELLA SERRA EERE SED RES If ARP is used the array below is used as a temporary holder for the destination hardware address It does not have to be changed If ARP is not being used replace the hardware address below with the hardware address of the destination The hardware address used MUST be the correct one EES ERA REEL LEER ER ERE NEE EE EERE byte eth_dest_hw_addr ETH_ADDR_LEN 0x00 0xE0 0x98 0x03 0xE5 0xFA endif ETHERNET Application Note CMX Micronet for 78K0 Family 49 Chapter7 Example Code return number of bytes to send Called from mn tcp send and mn_udp_send word16 mn app get send size PSOCKET INFO socket ptr cmx_reentrant word16 bytes to send bytes to send socket_ptr gt send_ptr PTR_NULL 0 socket ptr send len
51. ded Internet application are the interfaces to the application ports and this will be the major focus of the API the following is a brief explanation of the application ports used 2 2 4 1 HTTP Server The HTTP Web server is the application port for embedded Web applications The port number for HTTP is always port 80 The Webserver will provide the embedded HTML pages to the browser upon request from the browser Acquired data from the user application temperature measurement etc can be dynamically inserted in to the Web page for remote monitoring The Webserver can also call up user defined functions as long as they are included in a special format within the embedded HTML page 2 2 4 2 FTP Server The FTP File Transfer Protocol server allows for the transfer of files to and from an embedded application The application port used is always port 21 This maybe used to transfer files that are stored on the application i e log files etc 2 2 4 3 SMTP client SMTP Simple Mail Transport Protocol allows for the email notification of events to occur SMTP always uses application port 25 Email notification is ideal for alarm events etc SMTP is the standard Internet mail protocol and allows for example a notification to be sent to an operator when an event occurs that requires user intervention 2 2 4 4 BOOTP Bootstrap Protocol is used when the embedded system has initialised with no knowledge of its IP address when using Etherne
52. e arrays TABLE 3 1 shows the values of RAM required for each of the elements that make up the protocol stack Table 3 1 Array RAM usage EC ET eme Byles par number NUM_VF_PAGES 6 Name Length NUM_POST_FUNCS 2 Function Length where Name default 10 Password default 10 FtpName default 10 FtpPassword Default 10 Name Length default 20 Function Length default 20 Note These figures denote the number of characters in a string To determine the total RAM usage for the arrays use the following equation using the table above ArrayTotal Socket RAM PAP RAM FTP RAM FILE RAM POST RAM SSI RAM where Socket RAM NUM _ SOCKETS x Number PAP RAM PAP NUM _ USERS x Number FTP RAM FTP NUM _ USERS x Number FILE RAM NUM _VF _ PAGES x Number POST RAM NUM POST _ FUNCS x Number SSI_ RAM NUM GET _ FUNCS x Number 20 Application Note CMX Micronet for 78KO Family Chapter3 System Configuration 3 2 3 Virtual Files HTTP_BUFFER_LEN is one of the largest buffers required within CMX Micronet When Server Side Includes are enabled this buffer MUST be the same size as the largest HTML virtual file page If SSI is not enabled this buffer is optional to allow a header to be added to a HTML page The default value would then be 64 bytes For the evaluation version SSI s have been enabled Note The size of the buffers is dependant on the HTML page text size not the array size after conversion using html2c exe
53. e ee ee ee ee 21 dIE AE taa de 13 Application Note CMX Micronet for 78K0 Family
54. eable from high speed 0 24 us 8 38 MHz operation with main system clock to ultra low speed 122 us 32 768 KHz operation with subsystem clock Instruction set suited to system control Bit manipulation possible in all address spaces Multiply and divide instructions Sixty VO ports 8 bit resolution A D converter 8 channels Serial interface 4 channels 3 wire serial VO mode provided with automatic transmission reception function 1 channel 3 wire serial VO mode 1 channel 2 wire serial VO mode 1 channel UART mode 1 channel Timer Five channels 16 bit timer event counter 1 channel 8 bit timer event counter 2 channels Watch timer 1 channel Watchdog timer 1 channel Vectored interrupts 20 Two types of on chip clock oscillators main system clock and subsystem clock Power supply voltage VDD 2 7 to 5 5 V Note 1 The capacity of internal flash memory can be changed by means of the memory size switching register IMS 8 Application Note CMX Micronet for 78K0 Family Chapter 1 Overview 1 2 CMX Micronet The CMX Micronet TCP IP Protocol Stack has been designed to work on processors with small amounts of ROM and RAM This low ROM and RAM usage make it an ideal TCP IP stack to implement on an 8 bit processor such as the 78KO family and also on the low end 32 bit RISC V850 family in single chip mode with no external memory The CMX Micronet Stack is supplied as C source code But for evaluation purposes an o
55. ed mode OSTS 0x02 11 2415 fx ms wait after STOP release by interrupt OSMS 0x01 Scalar not used IMS 0xCC Select 1024 Byte RAM and 48k Byte ROM IXS OXOA Select 1024 Byte RAM endif i baten Haar es coms la ar ur ea ent es fees dio ee cet aN Ca ea Ge or ae la beater lee ad van ae cl ee iy las o fs hee ios um ae Gee er Los hans ans ins e Jl cates Gam Petrel eben cee ad ale a Cae de dae joes Youle ni ae ee Module name vSoftwarelnit Description Se This module is to initialize the bit variables Operation Kl void vSoftwarelnit void bTimer50Flag FALSE Reset status flag Timer50 bTimer51Flag FALSE Reset status flag Timer51 bKey1Flag FALSE Reset status flag Key1 7 2 1 5 Conversion c PROJECT 78KO Demonstration Board MODULE conversion c SHORT DESC DEVICE UPD78F0066 VERSION 1 1 DATE 05 02 2002 LAST CHANGE MA oe ea oe ie ER ee a E ee eg ee ed SRY E ASA REN NE E n PEL ACRE IA ed AI OP Oe Environment Device uPD78F0066 Ke Assembler A78000 Version V3 33A ER C Compiler I1CC78000 Version V3 33A e Linker XLINK Version V4 52J By NEC Electronics UK Ltd Cygnus House Es Sunrise Parkway id Linford Wood Application Note CMX Micronet for 78K0 Family 79 Chapter7 Example Code ii Milton Keynes UK MK14 6NP include lt in78000 h gt include lt string h gt if defined D78F0066 ttinclude df0066 h endif ttinclude m
56. eption complete STIFO FALSE Clear Interrupt request transmision complete SRMKO FALSE Enable Interrupt reception complete STMKO FALSE Enable Interrupt transmision complete ASIMO 0xC8 Enable UART receive and transmit endif if defined D78076 ASIM 0x09 disable uart No Parity 8bit 1stop BRGC Baud_38400_5MHz 38400 O 5Mhz SRIF FALSE Clear Interrupt request reception complete STIF FALSE Clear Interrupt request transmision complete SRMK FALSE Enable Interrupt reception complete STMK FALSE Enable Interrupt transmision complete ASIM 0xC9 Enable UART receive and transmit endif ENABLE_INTERRUPTS endif PPP II SLIP put uart isr s here place service routine for receive buffer here if defined D78F0034 defined D78F0066 defined D78F0078 I defined D78F0828 interrupt INTSRO_vect using 3 void vUARTReceive void 1 P5 3 0 1 if recv count lt RECV BUFF SIZE if recv count lt RECV BUFF SIZE 1 Fix for buffer management problems Application Note CMX Micronet for 78K0 Family 73 Chapter7 Example Code RTS 0 recv_in_ptr RXBO recv_count recv_in_ptr if recv_in_ptr gt amp recv_buff RECV_BUFF_SIZE 1 recv_in_ptr amp recv_buff 0 else RTS 1 Ht P5 3 1 Sg if defined D78076 interrupt INTSR_vect using 3 void vUARTReceive void D if recv_count lt REC
57. er this will change later undef SERVER MODE define SERVER MODE 1 elif EXAMPLE TYPE SMTP EXAMPLE smtp is only client undef SERVER MODE define SERVER MODE 0 else static byte TESTSTRING THIS IS A TEST STRING TO ECHO define DATA_BUFF_LEN 40 byte data_buff DATA_BUFF_LEN endif EXAMPLE TYPE HTTP EXAMPLE if defined __BORLANDC __ Il defined MSC VER extern void __interrupt __ far old1b to hold old int 0x1b handler endif if EXAMPLE_TYPE UDP_EXAMPLE void doUDP void cmx_reentrant elif EXAMPLE_TYPE TCP_EXAMPLE void doTCP void cmx_reentrant elif EXAMPLE TYPE SMTP_EXAMPLE void doSMTP void cmx_reentrant endif EXAMPLE TYPE UDP EXAMPLE if BOOTP BOOTP_INFO_T bp endif BOOTP if TFTP 60 Application Note CMX Micronet for 78KO Family Chapter 7 Example Code define TESTLEN 64 byte testBuffer TESTLEN long length endif BOOTP extern byte AtoD 4 extern byte AtoD_buff 8 static byte msg_buff 17 extern bit bKey1Flag extern saddr unsigned char ucThrow const unsigned char Welcomel Welcome to NEC r n extern byte ASCII_DEC byte a extern void DEC ASCll byte a byte b byte c extern void dice void if defined D78F0066 extern void AtoD_Values void endif void main void if MODEM byte connect_mode endif if PPP byte open_mode endif if MODEM if MODEM_MOD
58. et _ Stack Link _ Layer 5Kbytes User _ Pr ogram 2722 256 256 User _ Pr ogram 5152 2722 56 256 User _ Program 1918 There is 1918 bytes available for User Program This value includes stack requirements which has a default value of 848 bytes The stack value has been set to 848 bytes to accommodate CMX Micronet on the 78K Test It Board A high baud rate has been set and a low main clock frequency of 4 194304MHz is used The stack value is modified at link time within the xcl file Application Note CMX Micronet for 78KO Family Chapter4 Hardware and Peripherals 4 Hardware and Peripherals This section describes the hardware requirements for the evaluation of CMX Micronet The chosen I O timers and interrupts are common to most 78KO devices Making the CMX Micronet very portable across the 78KO family However the I O utilises some of the hardware on the 78K Test It evaluation board 4 1 uPD78F0066 Peripheral and I O Assignments Table 4 1 VO Assignment 7 2 3 4 5 Ground 6 7 8 9 Note P70 output signal may be used to shut down the MAX3222 serial line driver It is recommended to shut down the MAX3222 driver if the serial interface is not used This will extend the battery lifetime A low signal output at P70 will shut down the MAX3222 A high signal will wake up MAX3222 P71 output signal must be set to low signal to enable MAX3222 4 2 Timer Functions Timer 5 TM50 10ms Interval Timer f
59. et no mn openi ip dest adr ECHO PORT O PASSIVE OPEN PROTO TCP STD TYPE data buff DATA BUFF LEN data ptr PTR NULL data len 0 else socket no mn open ip dest addr DEFAULT PORT ECHO PORT ACTIVE OPEN PROTO TCP STD TYPE data buff DATA BUFF LEN data ptr TESTSTRING data len strlen char TESTSTRING endif if socket no lt 0 did we open socket successfully EXIT 1 socket_ptr MK_SOCKET_PTR socket_no get pointer to the socket while 1 if defined __BORLANDC_ Il defined _MSC_VER if _bios_keybrd KEYBRD READY check if ctrl c pressed if _bios_keybrd _KEYBRD_READ amp Oxff 3 mn_close socket_no break endif if defined __BORLANDC_ II defined _MSC_VER status 0 mn_send sends the data and waits for an ACK Some echo servers will return the ACK and the data in the same packet so we need to handle that case if data_ptr PTR_NULL status mn_send socket_no data_ptr data_len if status gt 0 amp amp socket_ptr gt recv_len gt 0 data_ptr socket_ptr gt recv_ptr data_len socket_ptr gt recv_len continue if status lt O I socket_ptr gt tcp_state TCP_CLOSED break do status mn_recv socket_no data_buff DATA_BUFF_LEN while status NEED_TO_LISTEN if status lt 0 amp amp status SOCKET_TIMED_OUT break if we got something send back what we got if status gt 0
60. fined D78F0034 II defined D78F0066 I defined D78F0078 defined D78F0828 interrupt INTTM50_vect using 1 void vTimer void endif if defined D78076 interrupt INTTM1_vect using 1 void vTimer void endif vTimer1 Added for Dice implementation timer_tick if DHCP mn_dhcp_update_timer endif DHCP if ARP amp amp ARP_TIMEOUT mn_arp_update_timer endif ARP amp amp ARP_TIMEOUT void mn_timer_init void cmx_reentrant DISABLE_INTERRUPTS put timer init code here Must achieve 10ms count for operation if defined D78076 TMC1 0x00 Stop timer operation TCL1 OxFD Set timer clock fx 249 5MHZ gt 9800 Hz CR10 0x31 Timer1 compare value gt 10 00ms intervall TOC1 0x03 Set to output mode PM31 0 Set to output Mode TMIF1 FALSE Clear interrupt request Bit Timer1 TMMK1 FALSE Enable Timer1 Interrupt TMC1 0x01 output no cascade mode endif if defined D78F0828 TMC50 0x00 Stop timer operation Application Note CMX Micronet for 78K0 Family 75 Chapter7 Example Code Set timer clock fx 248 4 194304 MHz gt 16384 Hz H Timer50 compare value gt 10 01ms intervall output no cascade mode if defined D78F0034 Il defined D78F0066 Il defined D78F0078 TCL50 0x05 CR50 0x52 TMC50 0x03 endif TMC50 0x00 TCL50 0x06 CR50 0x52 TMC50 0x03 endif Stop timer operation
61. generated to keep testing for a MODEM connection using the mn_modem_connect function 5 5 3 HTTP Server Figure 5 8 decomposes the HTTP Server process to highlight that once a successul PPP negociation has taken place CMX Micronet will continually loop within this application layer Once the client requests a PPP close the HTTP Server will exit and wait for the client to re establish a PC connection as shown in Figure 5 6 Figure 5 8 Simplified State Diagram for HTTP Server PPP Close PPP Close PPP Open PPP Close mn tcp send Recieve IP Header Send Data TCP Packet Not TCP Packet mn_tcp_recv 5 5 4 PPP Close After HTTP Server has shut down due to the client requesting a disconnect the link layer must be shut down from the server side using the function call mn_ppp_close Application Note CMX Micronet for 78K0 Family 31 Chapter5 Description of Software 5 5 5 MODEM Close The MODEM must also be shut down from the server side using the function call mn modem disconnect Once the MODEM has been shut down this completes the round robin loop 32 Application Note CMX Micronet for 78K0 Family Chapter6 Application Programmers Interface API 6 Application Programmers Interface API This chapter is not a definitive list of all function calls and procedures available within CMX Micronet It is only intended to expand on the procedures and function calls used in the previous chapters for evalu
62. gram for the HTTP server example make sure TCP and HTTP are selected in config h then change the line of code below to define EXAMPLE TYPE HTTP EXAMPLE To setup the example program for the FTP server example make sure TCP and FTP are selected in config h then change the line of code below to define EXAMPLE TYPE FITP EXAMPLE To setup the example program for the SMTP server example make sure TCP and SMTP are selected in config h then change the line of code below to define EXAMPLE TYPE SMTP_EXAMPLE AA EE AE AE EE ES define EXAMPLE TYPE HTTP EXAMPLE HIFIUDP SS EXAMPLE TYPE UDP EXAMPLE error UDP example selected without UDP 40 Application Note CMX Micronet for 78K0 Family Chapter7 Example Code endif HifITCP amp amp EXAMPLE TYPE TCP EXAMPLE error TCP example selected without TCP endif if HTTP 88 EXAMPLE TYPE HTTP EXAMPLE error HTTP example selected without HTTP endif if IFTP amp amp EXAMPLE TYPE FTP EXAMPLE error FTP example selected without FTP endif if ISMTP amp amp EXAMPLE TYPE SMTP EXAMPLE error SMTP example selected without SMTP endif if EXAMPLE TYPE HTTP EXAMPLE EXAMPLE TYPE FTP_EXAMPLE put includes for Web pages here endif EXAMPLE TYPE HTTP EXAMPLE Il EXAMPLE TYPE FTP EXAMPLE if EXAMPLE TYPE HTTP EXAMPLE undef SERVER MODE define SERVER MODE 1 void od msg func PSOCKET INFO cmx_reentrant
63. gt recv_len c 50 Application Note CMX Micronet for 78K0 Family Chapter7 Example Code socket_ptr gt recv_len Process received packet Called from mn_tcp_recv and mn_udp_recv void mn_app_process_packet PSOCKET_INFO socket_ptr cmx_reentrant if HTTP if socket_ptr gt socket_type amp HTTP_TYPE mn_http_process_packet socket_ptr else endif if FTP amp amp FTP_SERVER if socket_ptr gt src_port FTP_CONTROL_PORT mn_ftp_server_process_packet socket_ptr else if socket_ptr gt src_port FTP_DATA_PORT mn_ftp_server_process_data socket_ptr else endif remove the next line and put your code here socket_ptr socket_ptr if TCP y Do what needs to be done after successfully sending a packet Called from mn_tcp_recv El void mn_app_send_complete word16 data_len PSOCKET_INFO socket_ptr cmx_reentrant if socket_ptr gt send_len gt 0 socket_ptr gt send_len data len subtract bytes already sent move pointer to next spot to start sending if anything left to send or set itto PTR_NULL otherwise if socket_ptr gt send_len gt 0 socket_ptr gt send_ ptr data len else socket_ptr gt send_ ptr PTR_NULL endif Zar TCP called from mn_recv CHAR mn_app_recv_idle void cmx_reentrant put your code here return NEED_TO_EXIT if mn_recv must be exited immediately return 0 if HTTP CHAR mn_app_http_serve
64. icronet h bit bTransmit bit bADCFlag byte AtoD 4 byte AtoD_buff 8 EE GE AE EA e Conversion from ASCII to DEC EE EE EA EE pS ES byte ASCII DEC byte a byte DEC if a lt amp amp a gt DEC a 01 else DEC OXAA return DEC EE IRAE AESS EE RERES RARE ERR EEE he Conversion from DEC to ASCII byte only Example ASCII 12 output to HTML page 1 2 a 12 b 3 c 1 AtoD 0 1 2 3 DEC 1 2 ASCII 49 46 50 13 Example ASCII 215 output to HTML page 2 15 a 215 b 4 c 1 AtoD 0 1 2 3 4 DEC 2 1 5 ASCII 50 46 49 53 13 EE EERE REL SRE REES A AE PA id void DEC_ASCIl byte a byte b byte c unsigned char ASCII unsigned char temp 80 Application Note CMX Micronet for 78KO Family Chapter7 Example Code ASCII a AtoD b Mi Set End of AtoD buffer to Carriage return for strcopy command AtoD 3 13 if c gt 1 AtoD c Insert decimal point AtoD 1 if ASCII gt 100 temp ASCII 100 ASCII 100 if c gt 1 AtoD 4 b 0 ASCII ASCIl 2 AtoD O 2 ASCII temp if ASCII gt 10 AtoD b 1 0 ASCII 10 HASCIl 15 AtoD 2 ASCII MOD 10 5 ASCII 10 if c gt 1 amp amp b 3 AtoD b 3 0 ASCII ASCIl 1 AtoD O if c gt 1 amp amp b A AtoD b 2 0 ASCII ASCIl 1 AtoD 0 else AtoD 1 b 0 ASCII A ASCII 9 AtoD 2 9 if c gt 1 AtoD c 1 0 A
65. ile 1 if MODEM if mn_modem_connect connect_mode lt 0 EXIT 1 endif MODEM if PPP if USE_PAP mn_ppp_add_pap_user cmx password endif USE_PAP if Imn_ppp_open open_mode if MODEM mn_modem_disconnect endif MODEM EXIT 1 endif if PPP if DHCP define LEASE_TIME 1000 if mn_dhcp_start PTR_NULL LEASE_TIME 1 if TFTP length mn_tftp_get_file dhcp_lease server_id dhcp_info file testBuffer TESTLEN if length lt 0 TFTP error EXIT 1 endif TFTP else dhcp error EXIT 1 elif BOOTP if mn bootp PTR NULL amp bp gt 0 if the define BOOTP_REQUEST_IP was set to 0 should check here if bp yiaddr is different than ip_src_addr if TFTP length mn_tftp_get_file bp siaddr bp file testBuffer TESTLEN if length lt 0 TFTP error EXIT 1 endif TFTP else BOOTP error EXIT 1 elif TFTP tftp without bootp or dhcp replace boot mn with the file you wish to retrieve length mn_tftp_get_file ip_dest_addr byte boot mn testBuffer TESTLEN if length lt 0 TFTP error Application Note CMX Micronet for 78K0 Family 43 Chapter7 Example Code EXIT 1 endif BOOTP if EXAMPLE TYPE UDP EXAMPLE doUDP elif EXAMPLE TYPE TCP_EXAMPLE doTCP elif EXAMPLE TYPE HTTP EXAMPLE mn http server see http c elif EXAMPL
66. len 0 break status mn_recv socket_no data_buff DATA_BUFF_LEN if status lt 0 amp amp status SOCKET_TIMED_OUT data_len 0 break if we got something send back what we got if status gt 0 data_ptr socket_ptr gt recv_ptr data_len socket_ptr gt recv_len if PPP if ppp_status up break endif PPP mn_abort socket_no endif if EXAMPLE_TYPE TCP_EXAMPLE void doTCP void cmx_reentrant CHAR socket_no PSOCKET_INFO socket_ptr byte data_ptr word16 data_len int status if SERVER_MODE socket_no mn_open ip_dest_addr ECHO_PORT 0 PASSIVE_OPEN PROTO_TCP STD_TYPE data_buff DATA_BUFF_LEN data_ptr PTR_NULL data_len 0 else socket_no mn_open ip_dest_addr DEFAULT_PORT ECHO_PORT ACTIVE_OPEN PROTO_TCP STD TYPE data buff DATA BUFF LEN data ptr TESTSTRING data len strlen char TESTSTRING endif if socket no lt 0 did we open socket successfully EXIT 1 Application Note CMX Micronet for 78K0 Family 45 Chapter7 Example Code socket_ptr MK SOCKET PTR socket no get pointer to the socket while 1 if defined __BORLANDC__ II defined _MSC_VER if _bios_keybrd KEYBRD_READY check if ctrl c pressed if _bios_keybrd _KEYBRD_READ A Oxff 3 mn_close socket_no break endif Ir if defined BORLANDC II defined _MSC_VER status 0 mn_send sends the data
67. me Dynamic FTP HTTP Generation HTML Web Page Update Data Submit POST User Application Active All The Time Figure 5 4 shows the user application to be running continuously For this type of user application it is nessesary to use different options to run the user application in parallel to CMX Micronet depending on the type of application These are 1 An additional timer to operate the user application in parallel to the CMX Micronet 2 The user application call can be contained within the round robin used for checking for a PC connection not started shown in 5 4 2 or within the callback routines discussed in a later chapter 26 Application Note CMX Micronet for 78K0 Family Chapter5 Description of Software The first option allows the user application to run in parallel to CMX Micronet even after a connection is established with a client The second option only allows the user application to operate when the client has not established a connection The interraction to CMX Micronet through the Callback c and Example c routines has its advantages for applications such as remote diagnostics where the application program must run all the time and only data for status logged information and control are needed lt can also be used to dynamically develop HTML pages or files for FTP download that can be stored in RAM A future example will be developed using CMX Micronet to output data to a Web br
68. mision complete SRMK FALSE Enable Interrupt reception complete STMK FALSE Enable Interrupt transmision complete ASIM 0xC9 Enable UART receive and transmit endif ENABLE_INTERRUPTS endif PPP II SLIP put uart isr s here place service routine for receive buffer here if defined D78F0034 defined D78F0066 defined D78F0078 II defined D78F0828 interrupt INTSRO_vect using 3 void vUARTReceive void 1 P5 3 0 ie if recv_count lt RECV_BUFF_SIZE if recv_count lt RECV_BUFF_SIZE 1 Fix for buffer management problems RTS 0 recv_in_ptr RXBO Application Note CMX Micronet for 78K0 Family 53 Chapter7 Example Code recv_count recv_in_ptr if recv_in_ptr gt amp recv_buff RECV_BUFF_SIZE 1 recv_in_ptr amp recv_buff 0 else RTS 1 1 P5 3 1 Sg if defined D78076 interrupt INTSR_vect using 3 void VUARTReceive void D if recv_count lt RECV_BUFF_SIZE if recv_count lt RECV_BUFF_SIZE 1 Fix for buffer management problems RTS 0 recv_in_ptr RXB recv_count if recv_in_ptr gt amp recv_buff RECV_BUFF_SIZE 1 recv_in_ptr amp recv_buff 0 else RTS 1 endif if defined D78F0034 defined D78F0066 defined D78F0078 I defined D78F0828 interrupt INTSERO_vect using 3 void eri0 void byte temp if KEEP_ERROR_COUNT uart_errors endif if A
69. mple Code include lt in78000 h gt if defined D78F0034 include lt df0034 h gt change to appropriate file endif if defined D78F0066 include lt df0066 h gt change to appropriate file endif if defined D78F0078 include lt df0078 h gt change to appropriate file endif if defined D78F0828 include lt df0828 h gt change to appropriate file endif if defined D78076 include lt d076 h gt change to appropriate file endif include micronet h HE Global variables HE extern bit bTimer50Flag Status Flag Timer50 extern bit bTimer51Flag Status Flag Timer51 extern bit bKey1Flag Status Flag Key1 extern bit bKey2Flag Status Flag Key2 extern unsigned int Compiler_Version_Number en me meee eer ep en ee Spe ee A e eene ene m ee PP PP o pa A a eebe seet Sp pn Sy ce cl pee a Module name vHardwarelnit Description ia This module is to initialize some peripheral hardware Operation Sets the clock generator the port modes and output latches ES and initializes the interrupts void vHardwarelnit void Hardware inizialization if defined D78F0066 clock generator setting VEE PCC 0x00 Use high speed mode OSTS 0x02 2415 fx ms wait after STOP release by interrupt IMS 0xCC Select 1024 Byte RAM and 48k Byte ROM IXS 0x04 A Select 4096 Byte RAM port setting PO 0x00 Set output latch
70. n V3 33A j C Compiler 1CC78000 Version V3 33A bj Linker XLINK Version V4 52J By NEC Electronics UK Ltd Cygnus House Sunrise Parkway de Linford Wood We Milton Keynes UK MK14 6NP A AEREO AA EA RA EE E AE IE A EE Pe DOG EE VERE GE aal Pa oo DIN ADA E CT EN ICA di include micronet h volatile word16 timer tick Restart timer define KEEP ERROR COUNT 0 set to 1 to count errors if KEEP_ERROR_COUNT volatile word16 uart_errors endif extern void vTimer1 void 72 Application Note CMX Micronet for 78K0 Family Chapter7 Example Code VES EE AE N EE EE NE SM CANA ASA GAIL if PPP II SLIP void mn_uart_init void cmx_reentrant DISABLE_INTERRUPTS init_io_buffs do not remove this function call put uart init code here if defined D78076 PM70 1 Set RXD to input mode PM71 0 Set TXD to output mode P7 1 1 endif if defined D78F0034 I defined D78F0078 PM23 1 Set RXD to input mode PM24 0 Set TXD to output mode endif if defined D78F0066 PM73 1 Set RXD to input mode PM72 0 Set TXD to output mode endif if defined D78F0828 PM62 1 Set RXD to input mode PM63 0 Set TXD to output mode endif if defined D78F0034 II defined D78F0066 II defined D78F0078 defined D78F0828 ASIMO 0x08 disable uart No Parity 8bit 1stop BRGCO Baud 38400 4 194304MHz SRIFO FALSE Clear Interrupt request rec
71. n calls are made to CMX Micxronet the protocol stack must be initialised by calling mn_init 5 5 1 4 Virtual File Setup After initialisation of CMX Micronet hardware and software for the user application it is nessesary to initialise any Virtual File pages required for either FTP or HTTP use This is done with the function call mn_vf_set_entry where each file or page required for entry must use a separate function call For the evaluation version only 7 files are allowed The format for the Virtual File Pages is outlined in 6 8 Note For every Virtual File page whether it is a graphic or HTML page will need to be pass through the conversion program html2c exe This formats the data into an array with an attached header that can be compiled into the device containing CMX Micronet at compile time The headers have to be included at the top of example c 5 5 1 5 POST Function Setup Post Function Setup is required for those Web pages developed with POST functions enabled These function calls allow user interaction between the HTML Web pages and the user application The function call for POST function is mn_pf_set_entry A separate function call is required for each POST function used within the HTML Web pages For the evaluation version only 8 POST functions are available Note Once a POST function has been initialised there must be a corresponding function developed For the examples provided this is also contained in Example c 30
72. ng index htm we will cheat here and assume index htm is the first entry in the virtual file directory socket_ptr gt send_len vf_dir 0 page_size socket_ptr gt send_ptr vf_dir 0 page_ptr mn_http_process_includes socket_ptr endif if ISERVER SIDE INCLUDES else variable not found issue a bad request error message socket_ptr gt send_ptr byte HTTPStatus400 socket_ptr gt send_len STATUS_400_LEN if EXAMPLE_TYPE HTTP_EXAMPLE this function is called from a Web page by an HTTP POST request void Icd_stop_func PSOCKET_INFO socket_ptr cmx_reentrant we are expecting a variable called display with escaped string e g display hello 2C world 21 where equals and XX is a hexadecimal representation of a char af msg_buff will have decoded value if available if mn_http_find_value BODY ptr byte Stop msg_buff if ISERVER SIDE INCLUDES Just return good status socket_ptr gt send_ptr byte HTTPStatus204 socket_ptr gt send_len STATUS_204_LEN else inthis example we are always returning index htm we will cheat here and assume index htm is the first entry in the virtual file directory socket_ptr gt send_len vf_dir 0 page_size socket_ptr gt send_ptr vf_dir 0 page_ptr mn_http_process_includes socket_ptr endif if ISERVER SIDE INCLUDES else variable not found issue a bad request error message socket_p
73. ns to get the number of bytes of data to be sent mn_app_http_server_idle Returned Status NEED_TO_SEND If data must be sent immediately by the server This function is used for application speific program when the Web server is not processing any packets mn_app_init_recv ip_recv_len PSOCKET_INFO Application Note CMX Micronet for 78K0 Family 35 Chapter6 Application Programmers Interface API Where ip recv len is the length of the incomming packet not including headers PSOCKET INFO is the current socket pointer This function is used to allow any specific initialisation to occur before receiving data from a packet mn_app_process_packet PSOCKET_INFO Where PSOCKET_INFO is the current socket pointer This function ia used to allow processing of a packet after it is done being received mn_app_recv_byte c PSOCKET_INFO Where c is the character just received from the incoming TCP or UDP packet PSOCKET_INFO is the current socket pointer This function is called to allow processing of each single byte of data as it is received mn_app_recv_idle Returned Status NEED_TO_EXIT If mn_recv must exit now This functionis called when mn_recv is not processing any packets Any user application code can be placed within this function when mn_recv is idle 6 7 MODEM mn_modem_connect byte Where byte Is either ANSWER_MODE if MODEM is waiting for a call or DIAL MODE the MODEM is dialing out Returned Status 1
74. ocket_ptr cmx_reentrant we are expecting a variable called display with escaped string e g display hello 2C world 21 where equals and XX is a hexadecimal representation of a char el msg_ buff will have decoded value if available if mn_http_find_value BODY ptr byte Stop msg_buff if ISERVER SIDE INCLUDES Just return good status socket_ptr gt send_ptr byte HTTPStatus204 socket_ptr gt send_len STATUS 204 LEN else inthis example we are always returning index htm Application Note CMX Micronet for 78K0 Family 67 Chapter7 Example Code we will cheat here and assume index htm is the first entry in the virtual file directory ucThrow 0 added to reset dice application socket_ptr gt send_len vf_dir 0 page_ size socket_ptr gt send_ptr vf_dir 0 page_ptr mn_http_process_includes socket_ptr endif if ISERVER_SIDE_INCLUDES else variable not found issue a bad request error message socket_ptr gt send_ptr byte HTTPStatus400 socket_ptr gt send_len STATUS_400_LEN if SERVER_SIDE_INCLUDES this function is called from a Web page by a Server Side Include put current msg_buff in str and return number of bytes added to str word16 getMsg_func byte str cmx_reentrant strcpy char str char msg_buff return word16 strlen char msg_buff word16 dice_func byte str cmx_reentrant dice DEC ASCII ucThrow
75. on c to convert the A D value and dice result to ASCII to allow insertion via SSI to the HTML page 7 2 1 1 Example c EE PAIS RIIIE ICON REAR ER ICA ek Copyright c CMX Systems Inc 2001 All rights reserved ii EE AE GE ES ttinclude micronet h include User_config h define SERVER MODE 1 setto 1 if a server or O if a client define MODEM MODE ANSWER MODE set to DIAL_MODE or ANSWER_MODE define UDP_EXAMPLE 0 define TCP_EXAMPLE 1 define HTTP EXAMPLE 2 define FTP EXAMPLE 3 define SMTP EXAMPLE 4 ii ed RR SEER ERE DERE dek RE ER ER ee Re Re ee To setup the example program for the UDP echo example make sure UDP is selected in config h then change the line of code below to define EXAMPLE TYPE UDP EXAMPLE To setup the example program for the TCP echo example make sure TCP is selected in config h then change the line of code below to define EXAMPLE TYPE TCP EXAMPLE To setup the example program for the HTTP server example make sure TCP and HTTP are selected in config h then change the line of code below to define EXAMPLE TYPE HTYTP EXAMPLE To setup the example program for the FTP server example make sure TCP and FTP are selected in config h then change the line of code below to define EXAMPLE TYPE FIP EXAMPLE To setup the example program for the SMTP server example make sure TCP and SMTP are selected in config h then change the line of code below to define EXAMPLE TYPE SMTP_EXAMPL
76. or CMX Micronet Stack operation This is fixed for the evaluation version but can be changed within the source code version Note This timer can be changed to suite other 78KO devices It can also be used for user application if a 10ms Interval timer is required The location of this timer setup is contained in nec_hw c 4 3 Interrupts UART Recieve INTSRO Set for 38400 Baud 8 bit 1 stop no parity 4 194304MHz UART Transmit INTSTO Set for 38400 Baud 8 bit 1 stop no parity 4 194304MHz UART Error INTSERO Enabled to check for framing and parity error Note These values can be changed within the nec_hw c Application Note CMX Micronet for 78K0 Family 23 Chapter5 Description of Software 5 Description of Software 5 1 Software Location Setup Micronet Inc Micronet Lib Micronet netlib Micronet Manual Micronet Util Micronet Webpage Micronet source source xcl finc 24 Figure 5 1 Directory Structure Root Directory Structure Micronet inc Lib source Manual netlib util webpage xcl source inc Location of all h files Location of object files from Micronet after library build Micronet r26 Location of all c files supplied by CMX if source build supplied Location of user manual from CMX supplied with source build Location of Micronet utilities Location of Webpage development
77. owser based on the 78K Test It datalogger example Figure 5 5 User Application Using Both Types Of Interaction Only Active When HTML Dynamic EE Wep P aga ACINO MT tel FTP HTTP Generation HTML Web Page User Application 2 Start Applic tion Submit POST Update Data User Application 1 Active All The Time Figure 5 5 shows that both types of user application are possible within the one system The type of user application required for interraction to CMX Mironet is important and should be the initial point of discussion before integration occurs and the RAM requirements have been assigned 5 4 State Diagram for Example c Figure 5 6 removes the peripherals from CMX Micronet and shows the different processes involved in running an application layer such as HTTP server in what is simply termed a round robin approach for connection disconnection to an external MODEM To simplify the design the HTTP server can be replaced in Figure 5 6 with one of the following TCP UDP FTP Server or SMTP For evaluation this has been limited to HTTP or TOP if required Application Note CMX Micronet for 78K0 Family 27 Chapter5 Description of Software Figure 5 6 State Diagram for Example c CMX Micronet Setup PC Connection Started MODEM Close PPP Close Round Robin Loop 5 5 Software Discriptions This sub section describes the various processes in the
78. p The 78K Test It CMX Evaluation version memory layout is shown in the figure below Figure 3 2 Memory Map SFR Area OxFFFF OxFFFF SFR Area OXFFOO OXFFOO OXFEFF OXFEFF Internal Highspeed RAM Free for user application 1008 Bytes OXFBOO OXFBOF OXFAFF Heap Reserved e OXFBOO OXFAFF OxFAEO Reserved OxFADF OxFAEO Internal Buffer RAM OxFADF Free for user application 32 Bytes OxFABF Reserved OxF800 OxF7FF OxF7FF Internal Expansion RAM 960 Bytes OxF400 0xE800 OxF43F OxE7FF RAM required for CMX stack External Memory acre 0xE800 0xC000 OxBFFF OxBFFF Flash Memory Free for user Application 24720 Bytes 0x5F70 0x0000 Ox5F6F CMX Micronet Stack uPD78F0066 0x1000 OXOFFF Free for user Application 2979 Bytes 0x045D 0x045C Initialisation of code 0x0080 0x007F CALLT Table Area 0x0040 0x003F Interrupt Vector 0x0000 CMX Micronet Memory Map ER ROM RAM Application Note CMX Micronet for 78K0 Family 17 Chapter3 System Configuration 3 2 RAM While the CMX Micronet protocol stack has been designed for small RAM and ROM footprints this does not mean that the requirement for RAM in a protocol stack goes away The basis behind the Internet protocol stack has still come from the PC world where developers of software had plenty of RAM to use Therefore Figure 3 3 shows that the total RAM requirement for the system is made up of 4 parts Figure 3 3 RAM Usage User Application Virtual File
79. publication may include preliminary versions However preliminary versions are not marked as such Documents related to nPD78F0066 Document Name Document No uPD78F0066 User s Manual U13420EJ2VOUMOO uPD78F0066 Data Sheet U13419EJ1VOPMOO Documents related to development tools User s Manuals Document Name Document No 78K Test It Starter Kit 78K TESTITO90V10 Documents related to CMX Systems Document Name Document No CMX Micronet mn213man Not provided in evaluation version Application Note CMX Micronet for 78K0 Family Chapter 1 Overview 1 Overview This document outlines specifics related to the device uPD78FOO66 and its use with the Internet protocol stack called CMX Micronet from CMX Systems It is the intention however to use the same basic architecture of this device and relate this to any 78K0 microcontroller available Therefore the hardware required to implement CMX Micronet is common to all 78KO devices The only exception to this is the amount of RAM available on other 78K0 devices The uPD78F0066 has the largest amount of RAM available in the 78KO family 1 1 The 78K0 device PD78F0066 Features Internal Memory Type Program Memory Data Memory Part Number Mask ROM Flash memory High Speed RAM Expansion RAM Buffer RAM UPD780065 40 Kbytes 1024 bytes 4096 bytes 32 bytes uPD78F0066 48 Kbytes e External Memory Expansion Space 64 Kbytes Minimum instruction execution time chang
80. r ucLEDs Oxff output value LEDs JE n Sete se ad Sere GC Gala O e e ta te rd pu Ca quo che tr a ate ees Tr A tl Se Ca rd am een DOS ta ti Se a aC Ga ae See e o ebe ts aes e Pulp os la al et eo cer Ca ld aed Module name ucRandom Description T This module generates a pseudo random number Operation Y unsigned char ucRandom void return TM50 6 1 pseudo random number between 1 6 84 Application Note CMX Micronet for 78KO Family Chapter7 Example Code VES A ew fe a Fa ee ve al benennen deet eebe enden SI A A arbeiten A SF a YE A NN ms de oh ur Module name vFlashLED kk Description This module flashes all LEDs n times kk kk kk Operation kk void vFlashLED unsigned char Number while Number gt 0 ucLEDs 0x00 vWait5 10 Delay of 500 ms ucLEDs Oxff vWait5 10 Delay of 500 ms Number return fE kan aard ram amejaa apra PPP PP raa XX PP a PA O A aard ar va vae eend aas AX aa bed oar SE vae ee en oe ee el eie ee geesde A wel Eege ee e mm Lm Module name vWait5 kk Description This module delays the program for n 5 ms kk kk kk Operation kk gi void vWait5 unsigned char Number bTimer51Flag 0 Reset Timer51 Flag TMC51 7 1 Start Timer51 while Number gt 0 while bTimer51 Flag 0 bTimer51Flag 0 Reset status flag Timer51 Number TMC51 7 0 A Stop Timer51 return Je PP PP PX PP penny Re Gon
81. r_idle void cmx_reentrant put your code here Application Note CMX Micronet for 78K0 Family 51 Chapter7 Example Code return NEED TO SEND if data must be sent immediately return 0 endif HTTP if FTP 88 FTP_SERVER CHAR mn app ftp server idle void cmx_reentrant put your code here return NEED_TO_SEND if data must be sent immediately return 0 endif if FTP amp amp FTP_SERVER 7 1 3 nec_hw c PROJECT API for CMX Implementation MODULE NEC_hw c SHORT DESC Hardware setup for CMX stack DEVICE UPD78F0066 specify change in project options to choose different processor VERSION 1 1 DATE 04 01 2002 LAST CHANGE AAA A E a eet Ed EI OE O DIN VA AN Description API Implementation The 78K Test It demo board implements CMX Internet connectivity stack 8 bit timer required stack tick UART required for connection This file can be modified to change hardware requirements for di CMX stack Environment Device uPD78F0066 Assembler A78000 Version V3 33A C Compiler I1CC78000 Version V3 33A sde Linker XLINK Version V4 52J By NEC Electronics UK Ltd Cygnus House Sunrise Parkway de Linford Wood Kg Milton Keynes UK MK14 6NP e ARE AAA AAA IEA EE IS AA include micronet h volatile word16 timer_tick Restart timer define KEEP ERROR COUNT 0 set to 1 to count errors Hif KEEP_ERROR_C
82. rms strcpy char msg_buff char Welcome mn_pf_set_entry byte Icd_msg d msg func mn DI set entry byte Icd_stop lcd stop func if SERVER SIDE INCLUDES add any get functions server side includes here AtoD_Values mn gf set entry mn gf set entry mn gf set entry byte getMsg getMsg_func byte dice dice func byte getAtoDO getAtoD func0 mn gf set entry byte getAtoD2 getAtoD_func2 mn gf set entry byte getAtoD3 getAtoD_func3 mn gf set entry byte Version Version func mn gf set entry byte Code Code func endif SERVER SIDE INCLUDES endif EXAMPLE TYPE HTTP EXAMPLE endif EXAMPLE TYPE HTTP EXAMPLE Il EXAMPLE TYPE FTP_EXAMPLE ann RE ER while 1 if MODEM if mn modem connect connect mode lt 0 EXIT 1 endif MODEM Hif PPP if USE PAP mn ppp add pap user cmx password endif USE PAP if mn ppp open open model if MODEM mn modem disconnect endif MODEM EXIT 1 endif if PPP if DHCP define LEASE TIME 1000 if mn dhcp start PTR NULL LEASE TIME 1 if TFTP length mn_tftp_get_file dhcp_lease server_id dhcp_info file testBuffer TESTLEN if length lt 0 TFTP error EXIT 1 endif TFTP else dhcp error 62 Application Note CMX Micronet for 78KO Family Chapter7 Example Code EXI
83. s Total RAM CMX Micronet Stack Link Layer 3 2 1 Link Layer The Physical Layer for PPP requires full duplex operation over a UART The buffer size for both receive and transmit have a direct relationship to the size of a PPP packet and therefore the size of these buffers must be chosen to reflect this The overall size of these buffers are dependant on the performance required for the user program and a compromise on the RAM available To calculate a RAM value for the receive and transmit buffers use the following RECV_BUFF_SIZE XMIT_BUFF_SIZE 180 x bytes where 0 lt x gt MAX MAX is determined by user program RAM requirements and performance required Remark If smaller buffers are required it is possible to implement SLIP instead of PPP but for evaluation purposes this has been disabled 3 2 2 CMX Micronet Stack The CMX Micronet Stack requires RAM for buffers within the network layer It also requires RAM for Sockets and Virtual Files which are stored as arrays at compile time Therefore the actual value of RAM required for the protocol stack can vary greatly and a cautious designer will need to take this into account when implementing the end system Therefore to understand this use the following 18 Application Note CMX Micronet for 78K0 Family Chapter3 System Configuration where CMX _ Micronet _ Stack TCP WINDOW HTTPTotal ArrayTotal TCP_WINDOW Buffers in TCP Layer HTTPTotal Buffers in HTT
84. scription This module is to initialize some peripheral hardware Operation Sets the clock generator the port modes and output latches and initializes the interrupts void vHardwarelnit void Hardware inizialization if defined D78F0066 clock generator setting VEE PCC 0x00 Use high speed mode OSTS 0x02 11 2415 fx ms wait after STOP release by interrupt IMS 0xCC Select 1024 Byte RAM and 48k Byte ROM IXS 0x04 Select 4096 Byte RAM port setting PO 0x00 Set output latch to O P2 0x00 Set output latch to O P3 0x00 Set output latch to O P4 0x00 Set output latch to O P5 0xff Set output latch to Oxff P6 0x00 Set output latch to O P7 0x01 Set output latch to 0x01 enable RS232 driver P8 0x00 Set output latch to O P8 0x00 Set output latch to O PU7 0x08 Enable internal pull up resistor P7 3 PMO OxFF Port O input 8 bits PM2 OxFF Port 2 input 8 bits PM3 OxFF Port 3 input 8 bits Application Note CMX Micronet for 78K0 Family 57 Chapter7 Example Code PM4 0x00 Port 4 input 8 bits PM5 0x00 Port 5 output 8 bits PM6 OxFF Port 6 input 4 bits PM7 0x88 Port 7 7 7 3 input other output PM8 OXEO Port 8 output 5 bits PM9 OxFF Port 9 input 3 bits interrupt setting VEE IFOL 0x00 Reset all interrupt request bits IFOH 0x00 IFiL 0x00 MKOL
85. se connect_mode DIAL_MODE endif endif MODEM if PPP if SERVER_MODE open_mode PASSIVE_OPEN else open_mode ACTIVE_OPEN endif endif if PPP if defined POLZ8KO defined CMX78KO put your hardware initialisation routines here for all peripherals and sfrs Except Timer and UART used by stack vHardwarelnit vSoftwarelnit Variable Initialization endif call mn_init before using any other MicroNet API functions mn_init if defined __BORLANDC__ II defined _MSC_VER old1b getvector 0x1b setvector 0x1b onbreak stop ctrl break setvector 0x23 onbreak atexit cmx_restore endif Hit defined __BORLANDC__ Il defined _MSC_VER if EXAMPLE TYPE HTTP EXAMPLE EXAMPLE TYPE FTP_EXAMPLE add Web pages to virtual file system The main page MUST be first Hif EXAMPLE_TYPE HTTP_EXAMPLE add post functions to be used with forms strcpy char msg_buff char Welcome 42 Application Note CMX Micronet for 78K0 Family Chapter7 Example Code mn pf set entry byte lcd msg lcd_msg_func mn pf set entry byte lcd stop cd stop func if SERVER SIDE INCLUDES add any get functions server side includes here mn gf set entry byte getMsg getMsg_func endif SERVER SIDE INCLUDES endif EXAMPLE TYPE HTTP EXAMPLE endif EXAMPLE TYPE HTTP EXAMPLE Il EXAMPLE TYPE FTP_EXAMPLE wh
86. st of the optimisations undertaken are to reduce memory usage The TCP IP stack consists of the following protocols TCP Transport Control Protocol UDP User Datagram Protocol IP Internet Protocol ICMP Internet Control Message Protocol The above provide the main core of the TCP IP protocol the following will provide an overview of each of the elements 10 Application Note CMX Micronet for 78K0 Family Chapter 2 TCP IP stack theory including application layers 2 1 1 Internet Protocol IP Internet Protocol is designed to interconnect packet switch communication networks to form an Internet through which to pass data The IP protocol provides four main functions Basic unit for transfer Protocol Addressing Routing of Datagrams or Packets Fragmentation of datagrams As can be seen the IP is responsible for the addressing each device on an Internet or Intranet must have a unique IP address on the current version of CMX Micronet Ipv4 addressing is supported 2 1 2 ICMP Internet Control Message Protocol is a companion protocol to the IP and must be present The purpose of ICMP is to provide feedback about problems in the communications system 2 1 3 UDP User Datagram Protocol is a simple connectionless protocol i e there is no guarantee of delivery The major uses for this protocol are to support the following application level protocols DNS TFTP BOOTP 2 1 4 TCP TCP is the transport layer protocol a connection
87. state machine shown in Figure 5 6 5 5 1 CMX Micronet Setup This process is responsible for initialising the uPD78F0066 after system reset and is the main entry point into CMX Micronet and user application It configures the type of connection that the CMX Micronet will use and initialises the hardware and software for the task Figure 5 7 shows the flow through initialisation and the options in bold highlight the compile options used for the evaluation version of CMX Micronet 28 Application Note CMX Micronet for 78K0 Family Chapter5 Description of Software Figure 5 7 CMX Micronet Setup Flow Diagram Example c main Y Setup application type HTTP UDP FTP TCP SMTP Use Modem Dial Out ACTIVE_OPEN PASSIVE_OPEN Server Mode Client Mode Initialisation of HW and SW vHardwarelnit vHardwarelnit y CMX Micronet Initialisation mn_init conneciton HTTP or FTP Virtual File mn_vf_set_entry Yes POST function mn_pf_set_entry Server Side Includes Server Side Includes mn_gf_set_entry No Round Robin Loop Application Note CMX Micronet for 78K0 Family 29 Chapter5 Description of Software The entry point main after reset for the evaluation software is contained in example c with
88. stored in RAM VF_PTYPE_STATIC for the file to be stored in ROM and VF_PTYPE_FLASH for the file to be stored in programable flash Returned Status A pointer to the directory table entry corresponding to the passed name This function places the passed file name size location and page type into the first empty directory if one is available mn_vf_del_entry name Where name is the page to delete Returned Status 1 page deleted successfully O page not found This function is used to delete or remove a directory entry 6 8 1 HTML lt must be possible to add Web pages to your embedded application To do this you first must develop the Web pages using a HTML editor The HTML pages must be tested on a browser such as Explorer or Netscape before integration into the embedded application To view the pages developed within the example activate the following hyperlink MICRONET V2 15fWebpagelindex htm ALL files generated by the HTML editor must be included within the embedded application Here is a copy of the source code generated by the developed HTML Web page example used for the electronic dice HTML Source generated by Explorer lt HTML gt lt HEAD gt lt TITLE gt CMX MicroNet Demo lt TITLE gt lt HEAD gt lt BODY bgcolor FFFFFF onLoad window status 78K Hopper Demo gt lt CENTER gt lt p gt lt font face Georgia Times New Roman Times serif gt lt b gt lt i gt lt font size 7 color RED gt 78K Hopper
89. t The IP address is detirmined by using RARP when bootstrap is enabled It usually is used in conjunction with TFTP BOOTP usually uses port 67 for server and 68 for client 2 2 4 5 DHCP Dynamic Host Configuration Protocol is an alternative to BOOTP and also its replacement BOOTP has limited flexibility and therefore DHCP improves on this 2 3 Physical Layer Protocols There are several physical layer options available but initially we will focus on the serial interface for 78KO and later the Ethernet interface for V850 providing the physical layer connection To use the serial interface we must use an appropriate physical layer protocol in this case the protocol can be PPP Point to Point Protocol or SLIP Serial Line Internet Protocol For Ethernet ARP Address Resolution Protocol and its counterpart RARP Reverse Address Resolution Protocol are required to implement the physical layer 2 3 1 Serial 2 3 1 1 PPP Point To Point Protocol establishes the connection and negotiates the applicable network protocol IP in the embedded Internet case During the PPP negotiation phase the IP addressing is determined 2 3 1 1 1 PAP Password Authentication Protocol is a simple protocol for requesting a username and password to connect to the host This user name and password is compared to those stored on the host and if a match then the user has access 2 3 1 2 SLIP Serial Line Internet Protocol is an alternative to PPP Many PC s and
90. te CMX Micronet for 78K0 Family 39 Chapter7 Example Code 7 Example Code This section contains the souce code to interact with the API and source code for the application examples provided The code is contained in various files based on the directory structure outlined in 5 1 7 1 API Build The API build for CMX Micronet is contained below Example c is used for the initialisation of CMX Micronet Callback c is used for the setup of IP addresses and for the additional routines Init c initialises the hardare and software required for the 78KO device NEC_hw c contains the peripheral setup required for CMX Micronet successful operation 7 1 1 Example c AE EE EA EE EE Copyright c CMX Systems Inc 2001 All rights reserved ii dt ttinclude micronet h include User_config h define SERVER MODE 1 setto 1 if a server or O if a client define MODEM MODE ANSWER MODE set to DIAL_MODE or ANSWER_MODE define UDP_EXAMPLE 0 define TCP_EXAMPLE 1 define HTTP EXAMPLE 2 define FTP EXAMPLE 3 define SMTP EXAMPLE 4 EER ERRRRE RE SAREE RR dd SEAL EEN To setup the example program for the UDP echo example make sure UDP is selected in config h then change the line of code below to define EXAMPLE TYPE UDP EXAMPLE To setup the example program for the TCP echo example make sure TCP is selected in config h then change the line of code below to define EXAMPLE TYPE TCP EXAMPLE To setup the example pro
91. the application layer options included within the CMX Micronet structure This application note is divided into the following sections Overview of uPD78F0066 and CMX Micronet TCP IP stack theory including application layers System Configuration used for this application note Hardware and peripherals used for this application Description of software Application Programmers Interface API Example Code It is assumed that the reader of this application note has general knowledge in the fields of electronic engineering logic circuits and microcomputers For details of hardware and instruction functions especially register functions setting methods etc see the uPD76F0066 Hardware User s Manual Data significance Higher digits on the left and lower digits on the right Active low representation xxx overscore over pin or signal name Memory map address Higher address on the top and lower address on the bottom Explanation of Note in the text Information requiring particular attention Supplementary explanation to the text Binary XXXX or XXXB Decimal XXXX Hexadecimal XXXXH or Ox XXXX Application Note CMX Micronet for 78K0 Family Introduction Prefixes representing powers of 2 K kilo 210 1024 address space memory capacity M mega 220 10242 1 048 576 G giga 230 10243 1 073 741 824 Data Type Word 32 bits Halfword 16 bits Byte 8 bits Related Documents The related documents indicated in this
92. the associated application layer protocols are not required within this document There are many respectable books available on the subject of TCP IP and so a detailed description is not needed Figure 2 1 TCP IP Protocol Stack Layers Application Layer Ping ETE SMTP HTTP DNS TFTP BOOTP DHCP TCP UDP KEN En Network Layer ICMP IP Ps pad CH e SH Bai Ske Link Lay _ Link Layer y we CH ARP Data Link RARP SLIP Data Link RE Ethernet Serial Figure 2 1 shows the different protocol names and layers within a TCP IP stack There are additional applications layers available however for reference the protocols mentioned in figure 2 1 are touched upon within this chapter 2 1 The TCP IP Stack The TCP IP stack is a family of protocols specifically designed to aid in the movement of information between diverse systems The stack is also designed to be independent of the media over which the information is to be transferred Because of the widespread adoption of the protocol stack and the uptake of the Internet this is an ideal protocol family to use The negative side of using the TCP IP stack is that the stack was designed for desktop systems where memory usage is not a critical element in an embedded system we have to be very careful with memory usage and mo
93. tion Ce This module is the Interrupt service routine for TimerO Operation 86 Application Note CMX Micronet for 78KO Family Chapter7 Example Code RE interrupt INTTMOO_vect void vTimer0 void static saddr unsigned char ucFlag static saddr unsigned char ucOldLEDs if ucOldLEDs ucLEDs if ucFlag 0x01 ucFlag 0x00 LED Oxff all LEDs off else ucFlag 0x01 LED ucLEDs Output LED value else ucOldLEDs ucLEDs save current LED value LED ucLEDs Output LED value ucFlag 0x01 E ed Module name vTimer1 Description Ss This module is the Interrupt service routine for Timer50 added procedure to NEC_HW_v2_15f Operation void vTimer1 void bTimer50Flag 1 Set status flag Timer50 JE III AAA SS SS SS SS SS SS SS SS SS SS SS SS SS SS SS SS SS SSS Module name vTimer51 Description E This module is the Interrupt service routine for Timer51 Operation af interrupt INTTM51_vect void vTimer2 void bTimer51Flag 1 Set status flag Timer51 Je Ps dd Module name vKey1 Description Ke This module is the Interrupt service routine for Ke the external interrupt P3 gt Key1 Application Note CMX Micronet for 78K0 Family 87 Chapter7 Example Code Operation kk AAA II AI AE EE AE TIA PIT AAA A II AI IIA AER K interrupt INTP3_vect void vKey1 void bKey1Flag 1 Set status flag Key1 88 Application Note CMX Micronet for 78
94. to O P2 0x00 Set output latch to O P3 0x00 Set output latch to O P4 0x00 Set output latch to O P5 0xff Set output latch to Oxff P6 0x00 Set output latch to O Application Note CMX Micronet for 78K0 Family 77 Chapter7 Example Code Set output latch to 0x01 enable RS232 driver Set output latch to O Set output latch to O Enable internal pull up resistor P7 3 Port O input 8 bits Port 2 input 8 bits Port 3 input 8 bits Port 4 input 8 bits Port 5 output 8 bits Port 6 input 4 bits Port 7 7 7 3 input other output Port 8 output 5 bits Port 9 input 3 bits Reset all interrupt request bits Disable all interrupts Set all interrupts to low priority Stop AD Converter start conversion by SW conversion time 144 fx gt 17 1us Default selection channel 0 P7 0Ox01 P8 0x00 P8 0x00 PU7 0x08 PMO OxFF PM2 OxFF PM3 OxFF PM4 0x00 PM5 0x00 PM6 OxFF PM7 0x88 PM8 OXEO PM9 OxFF interrupt setting VEE IFOL 0x00 IFOH 0x00 IF1L 0x00 MKOL OxFF MKOH OxFF MK1iL OxFF PROL OxFF PROH OxFF PRiL OxFF Analog Converter setting VR ADMO 0x00 ADSO 0x00 ADIFO FALSE ADMKO FALSE Clear Interrupt request bit ADC Enable ADC Interrupt Enable ext interrupt rising edge P2 P3 Enable Port PO 3 interrupt Mask Flag Register Dis
95. toD 0 0 7 2 1 6 AtoD c PROJECT 78K0 Demonstration Board MODULE AtoD c SHORT DESC DEVICE uPD78F0066 VERSION 1 0 DATE 04 02 2002 LAST CHANGE Description A to D demonstration of Test It board using CMX Micronet ies The demo boards logs the analog ports in defined time Kn time intervals kk Environment Device uPD78F0066 We Assembler A78000 Version V3 33A e C Compiler 1CC78000 Version V3 33A Ke Linker XLINK Version V4 52J By NEC Electronics UK Ltd GE Cygnus House me Sunrise Parkway We Linford Wood be Milton Keynes UK MK14 6NP Changes Application Note CMX Micronet for 78K0 Family 81 Chapter7 Example Code include lt in78000 h gt if defined D78F0066 include df0066 h endif ttinclude micronet h if defined D78F0034 II defined D78F0066 II defined D78F0078 II defined D78F0828 unsigned char ucGetAD unsigned char Read ADC result of one channel extern bit bADCFlag Status flag ADC extern byte AtoD_buff 8 extern bit bTransmit Status flag Transmit complete aes TT SN Re OE EL TF ee Ke A hE TR SE I Aj ea aard ede ra he e aoe ne Module name AtoD_ Values kk kk Description This module gets the A to D values and stores them back in AtoD_ buff kk ak Operation kk MNS an EIA AR AAA IAS EN ETE S E PAC SPRINT PURO IAE DAS BR A EES GE EE IMA void AtoD_Values void
96. tr gt send_ptr byte HTTPStatus400 socket_ptr gt send_len STATUS_400_LEN if SERVER_SIDE_INCLUDES this function is called from a Web page by a Server Side Include put current msg_buff in str and return number of bytes added to str word16 getMsg func byte str cmx_reentrant 48 Application Note CMX Micronet for 78K0 Family Chapter7 Example Code strcpy char str char msg_ buff return word16 strlen char msg_buff endif if SERVER_SIDE_INCLUDES endif EXAMPLE TYPE HTTP EXAMPLE 7 1 2 Callback c ii AG EE E AE ERE RES EEE LEER EE Copyright c CMX Systems Inc 2001 All rights reserved ERASE NEARER ER AA AE ee REEL ARERR EE ii deg CMX recommends making a copy of this file before changing any of the routines below A EES AE EE OE EA ES Ree ee ee na include micronet h EER E EE EE EE REK ER REK EE dek ee EERE Change the ip_src_addr below to relect the IP address of your target If the IP address of the destination is known replace ip_dest_addr with that address If you are dialing into an ISP the source and destination addresses initially specified do not matter as they will be negotiated AE EE EE REEL AA if ETHERNET if HTTP II FTP Il SMTP byte ip_dest_addr IP_ADDR_LEN 216 233 5 32 byte ip_src_addr IP_ADDR_LEN 216 233 5 26 else byte ip_dest_addr IP_ADDR_LEN 209 67 233 68 byte ip_src_a
97. un on a JAVA Runtime Engine JRE The clear advantage of JAVA over HTML then becomes clear when the Web browser running a JAVA applet can come to an end result after running such an applet without sending any information or request any additional information from the embedded Web server An example of this is a JAVA applet to plot x and y co ordinates for a temperature sensor over time The JAVA applet is loaded initially from the embedded Web server The Web browser runs the applet and only requests from the Web browser a new data sample for the temperature sensor without the need to request the time The HTML document does not need to be re loaded to plot temperature over time and display the new information Application Note CMX Micronet for 78K0 Family 13 Chapter 2 TCP IP stack theory including application layers 2 5 Peer Type The term client and server are used throughout the protocol world and are therefore used throughout this document It is important to understand why they are used so we have outlined these terms The CMX Mictonet protocol stack makes reference to these within the application layer 2 5 1 Client Client simply means the requester of a service ie this means that the client must initiate some task to get a response SMTP client application initiate the sending of an email to another location external to the device running CMX Micronet 2 5 2 Server Server is the opposite to client in that a server must
98. void od stop func PSOCKET INFO cmx_reentrant if SERVER SIDE INCLUDES put includes for SSI s here word16 getMsg func byte cmx_reentrant endif elif EXAMPLE TYPE FTP EXAMPLE for now ftp is only server this will change later ttundef SERVER_MODE define SERVER MODE 1 elif EXAMPLE TYPE SMTP EXAMPLE smtp is only client undef SERVER MODE define SERVER MODE 0 else static byte TESTSTRING THIS IS A TEST STRING TO ECHO define DATA_BUFF_LEN 40 byte data buff DATA BUFF LENS endif EXAMPLE TYPE HTTP EXAMPLE if defined __BORLANDC __ II defined MSC VER extern void interrupt far old1b to hold old int Ox1b handler endif if EXAMPLE_TYPE UDP_EXAMPLE void doUDP void cmx_reentrant elif EXAMPLE_TYPE TCP_EXAMPLE void doTCP void cmx_reentrant elif EXAMPLE_TYPE SMTP_EXAMPLE void doSMTP void cmx_reentrant endif EXAMPLE TYPE UDP EXAMPLE if BOOTP BOOTP INFO T bp endif BOOTP Application Note CMX Micronet for 78K0 Family 41 Chapter7 Example Code if TFTP define TESTLEN 64 byte testBuffer TESTLEN long length endif BOOTP static byte msg_buff 17 const unsigned char Welcomel Welcome to NEC r n void main void if MODEM byte connect_mode endif if PPP byte open_mode endif if MODEM if MODEM_MODE ANSWER_MODE connect_mode ANSWER_MODE el
99. y function to obtain a HTML Web page located in the URIbuffer If the request is a POST function the mn_pf_get_entry is used to lookup and run the function from the URIbuffer mn_http_find_value BODYptr name buff Where BODYptr points to the POST body whwere we are looking for a match Name is the field we are looking for Buff is the buffer where the found value is being stored Returned Status 1 The function call was successful 0 Field name not found This function searched the field name field value pairs for the passed field name and copies the decoded field value into the passed buffer POST functions would use this function to detirmine the value of variables sent from the Web page mn_http_process_includes PSOCKET_INFO Application Note CMX Micronet for 78K0 Family 33 Chapter6 Application Programmers Interface API Where PSOCKET INFO is the socket pointer If SSI s are enabed this function is used to inser values directly into a Web page The page is searched for strings in the form lt exec cgi userfunc gt The name inside the quotation marks is looked for in the get function table mn gf get entry function and the associated function is run 6 3 TCP mn_tcp_open type PSOCKET_INFO Where type is either ACTIVE_OPEN for client mode or PASSIVE_OPEN for server mode PSOCKET INFO is the socket pointer Returned Status TCP ESTABLISHED The function call was successful TCP CLOSED Unable to establish

Download Pdf Manuals

image

Related Search

Related Contents

Microlife BP A2 Basic  TB35C1/TB35C2 取扱説明書  USER`S MANUAL  PSR シリーズ - 竹中電子工業株式会社  MÉDICAMENTS ntvcrsrrs. tentent des maladies de peau  BIEN UTILISER LES SITES DE DEALS  SC250 SMOKECLOAK MANUAL  Installation Guide / Installationsanleitung / Instrucciones de  RC-202ION_manuale  User`s manual rev. 8.4 March 2004 software rel. 41  

Copyright © All rights reserved.
Failed to retrieve file