![]() |
|
If you can't view the Datasheet, Please click here to try to view without PDF Reader . |
|
Datasheet File OCR Text: |
? freescale semiconductor, inc., 2004. all rights reserved. freescale semiconductor application note AN2821 rev. 1, 08/2004 this document contains information on a new pr oduct. specifications and information herein are subject to change without notice. table of contents this application note shows how to build the host interface to access etpu functions. the etpu pwm driver is used as an example to illustrate what the host needs to do to configure etpu module, channel and initialize pwm function. th e application note also describes the details of how to export etpu software information to the host compiler. the working code example is presented in the appendix. the user can compile both host and etpu code, then download to actual hardware for testing. 1 introduction the etpu is the new generati on of time processing unit (tpu) by freescale. besides th e hardware enhancement, significant improvements have been made to the accompanying software devel opment tools; these tools make the enhanced time pro cessing unit (etpu) easy to use. a high level language (c) compiler has been developed to allow the user to program the etpu by using c language instead of microcode. to program the etpu effectiv ely, the programmer still needs to have a clear understanding of how the etpu 1 introduction..........................................................1 2 overview .............................................................2 3 etpu and host interface hardware ..... ........ .......3 4 host interface software ......................................4 4.1 initialization overview ........................................4 4.2 etpu module initialization.................................5 4.3 etpu channel initializati on ...............................6 4.4 etpu function initialization...............................6 4.5 etpu and host interactiv e control ..... ........ .......7 5 software integration ............................................8 6 conclusion...........................................................8 appendix 1 ..........................................................9 etpu host interface by: ming li detroit virtual garage
etpu host interface, rev. .1 overview freescale semiconductor 2 hardware works. coding in c, the programmer can focus more on the application logic and leave the mechanics of the etpu pr ogramming to the compiler (i.e., register usage and tracking, parameter packing, micro-instruction packing, etc.). wi th the help of the etpu simulato r and debugger, etpu software can be developed much like the softwa re for the host cpu. productivity of software development can be significantly improved. the introduction of the etpu c comp iler also changes the way the host interfaces to the etpu functions. with the help of the compiler, the same symbol can be referenced by the both etpu and host software. the host software can interface with etpu functions via api functions, instead of accessing physical memory locations and registers. for each etpu function, a host interface api function can now be developed as a part of th e etpu c program. the host a pplication can call these ap i functions to interface with the etpu. the references to th ese api functions and sy mbols for parameters are resolved at compile time. the implementation details of the etpu functions are hidden from the host application. this design improves the flexibility of the etpu functions? implementati on and the portability of the host application code. this application note di scusses how to build the host interface for etpu functions. 2 overview host interface software adds another layer of ab straction between the host cpu and etpu. the host interface api functions hide the complexity of the interaction between the hos t cpu and etpu, providing a simple interface for host applicati ons. ideally, every etpu function shall have one or more host interface api functions. the interface software between host and etpu facilitates three major tasks: 1. etpu hardware initialization ? configure etpu peripheral hardware 2. etpu function initialization ? pass initial parameters a nd initiate function execution 3. etpu function run time interactive control ? update function parameters and handle handshaking once the etpu peripheral and etpu f unctions are initialized, each etpu f unction can start to execute with initial function parameters. the host interface api functions need to be provided for interactive control (i.e., parameters updating and contro l mode changing, etc.). to update the parameter or change control mode, the host is responsible for passing updated para meters to the etpu functions, and then informing the etpu that the function parameters have changed. if a coherent change of function parameters is required, the logic has to be built in the etpu functions to ensure the coherency. for some etpu functions, the interaction between host and etpu is an esse ntial part of the operation. in both host and etpu software, the logic is n eeded to handle the handsh aking between host and etpu . the interaction between the etpu and host can be encapsulated in the host interface api functions. the host code and etpu code are co mpiled by different compil ers. the host compiler is normally used to build a single code image fo r both host and etpu. in order to build etpu code and host code together, the etpu software building information (i.e. etpu code image) has to be exported to the host compiler. the symbol information has to be exporte d from the etpu compiler to the hos t compiler as we ll. for the byte craft etpu compiler, the mechanism is implemented as a set of host interface macros. in the etpu code, these macros are inserted to generate proper execut able and symbol information for the host compiler. the host interface design process will be illustrated in the etpu pwm driver example in the appendices. etpu and host interface hardware etpu host interface, rev. .1 freescale semiconductor 3 3 etpu and host interface hardware the host interface hardware for the etpu is shown in etpu host interface hardware . the host and etpu can communicate to each ot her via event or by data. the host has access to all etpu host interface registers. when the host wants the etpu?s services, it can issue the host service request (hsr) by writing the etpu channel contro l registers. once the host service request is acknowledged, a thread of etpu code associated with this hsr is activated for execution. the etpu code in the thread implements the functions requested by the host. when etpu needs the host service, it can issue the in terrupt request or dma data transfer request, or gene rate a global exception. the events handling logic is needed in the host software to provide services to the etpu corresponding to these requests. the etpu code memory (ram) and data memory (ram) are accessible by both host and etpu. etpu code memory stores the etpu executable binary im age. at the power up initialization, following the defined sequences, the host transfers th e etpu code stored in the flash memory to the etpu code memory. during the execution, the etpu micro- engine fetches the micro-instructions from the code memory. figure 1. etpu host interface hardware the etpu data memory is implemented by using tri-por t ram. it provides for data sharing between the host and etpu engines. both host and etpu can read and write the etpu data memory in any data size (8, 16, 24, and 32 bit). since the etpu da ta bus is 24 bits wide, it is best to pack together a data word with an 8 bit value and a 24 bit value in order to reduce data memory utilization. to reduce the overhead of packing and unpacking the data, a virt ual mirror memory space of the normal etpu data memory has been created. the virtual memory space is called parameter sign extension (pse) memory space. when the host reads the 32-bit data from the pse memory space, it will return the sign extended 24-bit data. the conversion is needed if the 24-bit data is unsigned. s imilarly, when the host writ es the 32-bit data to the etpu pse memory, only the three least significant bytes will be written to the etpu data memory. the most significant byte is untouched. etpu host interface, rev. .1 host interface software freescale semiconductor 4 4 host interface software the function partition between the appl ication software and low-level driver is defined duri ng the software architecture design. to make the so ftware portable, the a pplication software is normally designed to interface with the low-level driver via abstracted interface apis. the hos t interface of the etpu functions should be designed such that the im plementation of the low-level driver is hidden from the application software. once the application software interface to the low-level driver is defined, the func tionality of the low-level driver can be partitioned between host cpu and etpu. the etpu inte rface software running on the host cpu is an integral part of the low-level driver. it handles the details of the interaction between host and etpu. the etpu code and host interface code are compiled by two different compilers. in order to resolve the etpu code symbol reference in the host code, it is necessary to expor t the symbolic information from the etpu compiler to the host compiler. si milarly, to build a single executable image, it is necessary to export etpu code image to the host compiler. several type s of information are expor ted from etpu_c through host interface files, generated from #pragma write statements during compilation. for detailed information on #pragma write , see the etpu_c documentation. an example of application software and low-level driver part ition is shown in code example 1 . 4.1 initialization overview the etpu initialization is an important part of th e host interface. at the power up, the host has to configure the etpu peripheral properly before the etpu function can be execute d. the etpu initialization process is accomplished by both host cpu a nd etpu. during the initialization, the functional partition between host cpu and etpu is as follows: host responsibility: ? etpu module initialization ? etpu channel configuration ? providing initial et pu function parameters ? initiating the etpu function execution etpu responsibility: ? responding to the hsr ? transitioning into th e initialization state the etpu initialization can be br oken down into three steps: etpu module initialization, etpu channel initialization and etpu function initialization. the foll owing sections discuss th e interface design and the data exchange between hos t cpu and etpu for each step of initialization. host interface software etpu host interface, rev. .1 freescale semiconductor 5 4.2 etpu module initialization at the power up initialization, the et pu peripheral hardware is confi gured by the host. the etpu module initialization includes the following steps: 1. initialize etpu global registers ? etpu misc compare register (etpu_misccmpr) ? etpu module configurati on register (etpu_mcr) ? etpu time base configurat ion register (etpu_tbcr) ? etpu stac bus configurat ion register (etpu_stacr) ? etpu engine configurati on register (etpu_ecr) 2. load etpu code from flash memory to etpu code ram 3. copy initial values of etpu code global variables to etpu data memory most of the information required to configure the etpu global re gisters are not depe ndent on the etpu software implementation (i.e., time base, clock frequency, entry table address, et c.). the configuration information is determined during th e host peripheral configur ation and resource allo cation. only the misc value depends on the actual etpu software implementati on; it has to be exported to the host program after the etpu code is compiled. the etpu_c compiler provides a macro ( ::etpumisc ) to calculate the misc value of the etpu code image (see code example 3 ). the etpu code image is generated when the etpu c program is compiled. to use this code in the host program, the etpu code image can be exported as an array of consta nt values. the etpu_c compiler provides a macro ( ::etpucode ) to generate and export the etpu code image (see code example 3 ). the etpu code image constant array is suitable to be included in the host source code. the host compiler locates the etpu code image array in the flash memory at host source code compil e time. since the etpu micro-engine can only fetch micro- instructions out of etpu code memory (ram), at the power up initialization, the etpu code image has to be loaded to etpu code memory. as it is in the standard c syntax, when the etpu code is compiled, the global vari ables are allocated to the etpu data memory and the initial values are assigned to the correspondi ng memory locations. the standard c syntax requires that al l global variables are declared outsi de of any function. for etpu, this means that all global va riables have to be declared outside of a ny execution thread. si nce only the code in a thread can be executed on etpu, the global vari able initial value assignment statements will not be executed. the global variables cannot be initialized in the etpu code; they must be initialized by the host. the software statements have to be added to the hos t code to initialize the etpu global variables. the initialization values have to be exported from the etpu compiler to host compiler. the etpu_c compiler provides a macro ( ::etpuglobalimage ) to capture initial values for all global variables and exports them as a constant array ( code example 4 ). at power up initialization, the global variable initial values are loaded to the etpu data memory for global variables. the host interface macros have to be added to the etpu code in #pragma write statements to export the etpu software information to the host compiler ( code example 3 ). these statements will generate header files that contain the mi sc value, etpu code image and global variable memory image ( code example 4 ). etpu host interface, rev. .1 host interface software freescale semiconductor 6 the software for the etpu module initialization can be encapsulated in an api function. an example of the etpu module initiali zation function implementa tion is provided in code example 6 ( mc_etpu_init() ). 4.3 etpu channel initialization after the etpu module is configur ed, each channel on the etpu module can be configured. etpu channel initialization includes the following tasks: 1. etpu channel configuration registers initialization ? assign etpu function to a channel ? setup channel priority ? configure interrupt/dma/output enable ? select etpu function entry table encoding ? assign the function frame to a channel 2. etpu channel status cont rol register initialization ? set up etpu function mode the etpu channel assignment and the channel priority determination are a part of the host software architecture design. they are indepe ndent of the etpu func tions implementation. the information for the configuration is provided by the host software design. during the channel initialization, a section of etpu data memory is assigned to each channel. this memory section is called the ?function frame?. the function frame contains al l the function parameters and static local vari ables used by the etpu functi on. the starting address of th e function frame is assigned to the channel at initialization. the function frame assignment can be static or dynamic. dynamic allocation assigns the function frame to the channe l based on the next availa ble memory space. the availability of the etpu data memory depends on the number of functions that ha ve been assigned and the number of parameters the function is using. dyna mic allocation can reduce the etpu data memory consumption by minimizing unus ed memory ?holes?. to allocate th e function frame dynamically, the host must know the function frame c onsumption by a particular etpu function. the etpu_c compiler provides a macro ( ::etpuram ) to report the number of parameters and static local variables used by a function at compile time ( code example 3 ). the etpu function table entry encodi ng, interrupt enable, dma enable, out put enable, output polarity, and function mode are constant s specific to the etpu function softwa re implementation. it is a good practice to define them only once in the etpu code and e xport the configuration info rmation at compile time. once the host interface macros ar e added to the etpu code ( code example 3 ), the #pragma write statements will generate a header file that contains all the etpu function configuration and software symbol information at compile time ( code example 5 ). the header file can be included in the host interface code to resolve symbol references. 4.4 etpu function initialization the etpu function initialization is the last step of the etpu initialization process. during the etpu function initialization, the host is responsible for pa ssing the parameters to the etpu functions and host interface software etpu host interface, rev. .1 freescale semiconductor 7 initiating the etpu function execution by issuing a hos t service request. once the host service request for initialization is recognized, the etpu will transition to the initialization state. unlike in the host cpu, the etpu function parameters passed from host are not placed on the stack. instead, memory in the function frame is allocated to accommodate every function parameter. the host passes the etpu function parameters by writing directly to the etpu function frame. the host needs to know the function frame for each channel, as well as the data type and address offset for every parameter. the function frame can be obtained by reading the etpu channel base address register. the etpu_c compiler provides the host interface m acros to export the offset of each function parameter; use them in #pragma write directives to export this information. the function parameters can be 8-bit, 16-bit, or 32-bit. the etpu compiler can allocate function parameters at 8-, 16-, 24-, or 32-bi t boundaries. to pass 8-bit or 16-bit parameters, the host can directly write to etpu data memory. most etpu data regi sters and timers are 24-bit. to pass 24-bit etpu function parameters, the host needs to pass a 32-bit parameter to the etpu. since the host cannot access et pu data memory on the 24-bit boundary, the host code needs to reali gn the parameter to the 32-bit addr ess boundary before writing it to the function frame. it is the respons ibility of the host to ensure the f unction parameters are within proper range. it is also the responsibility of the host when writing the 24-bit parameter to ensure that the upper byte on the function frame is not corrupted. similarly, when reading a 24 bit return value from the function frame, the host code must mask the upper byte before re turning the correct 24 bit value. to simplify the interface code, it is recommended to access the 24-bit function paramete r by using pse memory space. an example of the etpu function initialization is listed in code example 7 ( etpu_pwm_init() ). 4.5 etpu and host interactive control once the etpu function is initiali zed, it will start execution base d on the initial parameters and input/output conditions. the etpu function can provid e the api for the host appl ication code to update the function parameter or change th e control mode. similarly , the host software has to provide proper logic to handle the etpu interrupt or dma requests. the software to handle the host and etpu interaction has to cross betw een two different compilers. when the host initiates the etpu function, the data flows fro m the host to etpu. this behavior is the same as the ?call by value? protocol in the standard c synt ax. sometimes ?call by reference? is desired to access etpu function internal variables. si nce the data flow for ?call by reference? has to cross both compilers, it is not directly supported by the compilers. howeve r, the behavior of the ?call by reference? can be implemented in the host interface software. the host in terface software can pass a reference to the api function to access the etpu function internal va riables. an example of the ?call by reference? implementation is shown in both code example 1 and code example 7 ( etpu_pwm_getstarttime() ) some etpu functions require host or dma service. the etpu software can write the circ bits in the channel interrupt and data transfer request register to send the request to the host or dma. the interrupt service routine must be a dded and the dma channel must be configured in the hos t code to respond to the etpu request. the host interface software has to provide functions to update etpu function parameters or change the control mode during the normal operation. similar to the function initialization api, the interface api etpu host interface, rev. .1 software integration freescale semiconductor 8 function needs to check the validity of the parameters, write them to th e etpu data memory, and then issue the host service request to inform etpu that the pa rameters are newly updated. an example of the update pwm function parameter is shown in code example 7 ( etpu_pwm_update ( ) ) . 5 software integration the etpu code and host cpu code are compiled and li nked separately. the etpu code needs to be built first to generate and export the etpu code imag e and parameter symbol information, as shown in code example 4 and code example 5 . the host code needs to include thes e files properly to resolve all the symbol reference betw een etpu and host code. this software build dependency can be added easily to the makefile to ensure the proper sequence. 6conclusion the benefit of the host interface design is to isol ate any hardware depende ncy from the application software by means of the host in terface api functions. in the etpu host interface design, all the interactions between host and etpu are encapsulated in the interface api functions. with this interface design, the implementation of the low-level driver can be hidden from the host application. in the pwm example, the application software in terfaces to a generic pwm driver with two control parameters: period and duty cycle. when the etpu implementation of the pwm is changed, the host application software does not need to change. for the host application software, it does not make any difference if the low-level pwm driver is implemented by using a general purpos e discrete output, emios timer channel, or etpu channel. conclusion etpu host interface, rev. .1 freescale semiconductor 9 appendix 1 code example 1.main.c #include "etpu_image.h" #include "etpu_pwmcontrol.h" /********************************************************************************* * function: main * * purpose: this function is the entry point of the host pwm application. the * * main function initializes the etpu to execute pwm function. once the * * etpu pwm function is initialized, the main function calls the api * * function periodically to update the pwm function parameters. * *********************************************************************************/ void main(void) { unsigned long dutycycle_host = 0x200000; uint16_t delay_counter; uint32_t pulsestarttime; /* init device */ init_error = etpu_init(); /* main user code goes here */ while(1) { for (delay_counter=0; delay_counter <= 0x0fee; delay_counter++) {} if (dutycycle_host == 0x800000) dutycycle_host = 0x400000; else dutycycle_host = 0x800000; etpu_pwm_update(pwm0, 4000, dutycycle_host); etpu_pwm_getpulsetime(pwm0, &pulsestarttime); } } /******************************************************************************** * function: etpu_init * * purpose: this host function initializes etpu module and configures each etpu * * channel. the etpu pwm functions initialization apis are called to * * initiate etpu function execution. * ********************************************************************************/ int16_t etpu_init () { int16_t error_code; uint32_t chanconfigparam = 0; /* initialize etpu hardware */ mc_etpu_init(etpu_config_a, (uint32_t *)etpu_code,(uint8_t)etpu_code_ram_size, (uint32_t *)etpu_globals); /* initialize etpu channels */ chanconfigparam = (etpu_pwm_int_req | etpu_pwm_dma_req | etpu_pwm_out_disable | \ (etpu_pwm_table_select << 24) | (pwm0_chan_priority << 28)); mc_etpu_chan_init(pwm0, etpu_pwm_function_number, etpu_pwm_func_mode, \ etpu host interface, rev. .1 conclusion freescale semiconductor 10 etpu_pwm_num_parms, chanconfigparam, auto_func_frame); /* initialize etpu functions */ etpu_pwm_init(pwm0, 4000, dutycycle_host); /* enable all timebases */ mc_mpc5500_timer_start(); return (0); } conclusion etpu host interface, rev. .1 freescale semiconductor 11 appendix 2 code example 2.etpu_pwmcontrol.h /*--------------------------------------------------------------------+ | include header files | +--------------------------------------------------------------------*/ #include "mpc5554.h" //mpc5554 register definitions. #include "mpc5500_util.h" //useful utility routines. #include "etpu_image.h" /*--------------------------------------------------------------------+ | constants definition | +--------------------------------------------------------------------*/ /* define functions to channels */ #define pwm0 0 #define pwm0_chan_priority3 #define etpu_entry_table 0x0 // etpu entry table address struct etpu_config_t etpu_config_a = { etpu_misc_enable, //mcr register etpu_misc_val,//misc value from etpu compiler link file //configure etpu engine a etpu_filter_clock_div8 + etpu_chan_filter_3sample + etpu_entry_table, //configure etpu engine a timebases etpu_tcr2ctl_div8 + ( 7 << 16) + //tcr2 prescaler of 8 (7+1) etpu_tcr1ctl_div2 + 3, //tcr1 prescaler of 4 (3+1) 0, //configure etpu engine b etpu_filter_clock_div4 + etpu_chan_filter_3sample + etpu_entry_table, //configure etpu engine b timebases etpu_tcr2ctl_div8 + ( 7 << 16) + //tcr2 prescaler of 8 (7+1) etpu_tcr1ctl_div2 + 3, 0 }; etpu host interface, rev. .1 conclusion freescale semiconductor 12 appendix 3 code example 3.etpuc_pwm.c #include conclusion etpu host interface, rev. .1 freescale semiconductor 13 } else { //this else statement is used to catch all unspecified entery table conditions } } #pragma endlibrary; /* information exported to host cpu program */ #pragma write h, (::etpufilename (etpu_pwm_auto.h)); #pragma write h, (/* warning this file is automatically generated do not edit it! */); #pragma write h, ( ); #pragma write h, (::etpuliteral(#ifndef __etpu_pwm_auto_h)); #pragma write h, (::etpuliteral(#define __etpu_pwm_auto_h)); #pragma write h, ( ); #pragma write h, (/* function configuration information */); #pragma write h, (::etpuliteral(#define etpu_pwm_function_number) pwm_function_number ); #pragma write h, (::etpuliteral(#define etpu_pwm_table_select) ::etpuentrytype(pwm) ); #pragma write h, (::etpuliteral(#define etpu_pwm_num_parms) ::etpuram(pwm) ); #pragma write h, ( ); #pragma write h, (::etpuliteral(#define etpu_pwm_int_enable) pwm_int_enable ); #pragma write h, (::etpuliteral(#define etpu_pwm_dma_enable) pwm_dma_enable ); #pragma write h, ( ); #pragma write h, (::etpuliteral(#define etpu_pwm_out_dis) pwm_out_disable ); #pragma write h, (::etpuliteral(#define etpu_pwm_func_mode) pwm_function_mode ); #pragma write h, ( ); #pragma write h, (/* host service request definitions */); #pragma write h, (::etpuliteral(#define etpu_pwm_init) hsrinitpwm ); #pragma write h, (::etpuliteral(#define etpu_pwm_update) hsrupdtpwm ); #pragma write h, ( ); #pragma write h, (/* parameter definitions */); #pragma write h, (::etpuliteral(#define etpu_pwm_period_offset) ((::etpulocation(pwm,period)?1)/4)); #pragma write h, (::etpuliteral(#define etpu_pwm_duty_offset) (::etpulocation(pwm, duty)-1)/4 ); #pragma write h, ( ); #pragma write h, (::etpuliteral(#endif /*__etpu_pwm_auto_h */ )); /* information exported to host cpu program */ #pragma write m, (::etpufilename (etpu_image.h)); #pragma write m, (/* warning this file is automatically generated do not edit it! */); #pragma write m, ( ); #pragma write m, (::etpuliteral(#ifndef __etpu_image_h)); #pragma write m, (::etpuliteral(#define __etpu_image_h)); #pragma write m, ( ); #pragma write m, (/* etpu code ram constants definitions */); #pragma write m, (::etpuliteral(#define etpu_code_ram_size) etpu_code_image_size); #pragma write m, (::etpuliteral(#define etpu_misc_val) ::etpumisc); #pragma write m, ( ); /* global const initialization array */ #pragma write m,( const uint32_t etpu_globals[]= { ::etpuglobalimage32 };); #pragma write m, ( ); etpu host interface, rev. .1 conclusion freescale semiconductor 14 /* this is an example of a code as a constant array */ #pragma write m,( const uint32_t etpu_code[]= { ::etpucode32 };); #pragma write m, ( ); #pragma write m, (/* end of etpu code image */); #pragma write m, (::etpuliteral(#endif /*__etpu_image_h */ )); conclusion etpu host interface, rev. .1 freescale semiconductor 15 appendix 4 code example 4.etpuc_image.h /* warning this file is automatically generated do not edit it! */ #ifndef __etpu_image_h #define __etpu_image_h /* etpu code ram constants definitions */ #define etpu_code_ram_size 2 #define etpu_misc 0x0ef38a79 const uint32_t etpu_globals[]= { 0x000001f4,0x00000000 }; const uint32_t etpu_code[]= { 0x4fffffe7,0x3bfc3ff4,0x4f3f0f9f,0xf73ffcfb, 0xdfef7a80,0xbfe80a82,0x3b193ff4,0x4f3f0f9f, 0xf73ffcfb,0x7ff37fbb,0xbffffb82,0xbfeffb81, 0x1fffffec,0x3838fff4,0xf0c0029f,0x1c8f5f96, 0x3bf42ff4,0x48f0fe7f,0xff3ffcfb,0xf7c003df, 0xbfeffb80,0xbfe80a81,0x3b190fe9,0xf34802ff, 0x3bf70fb4,0xbfeffb82,0x3b195fd4,0x3bf42ff4, 0x4af0fe7f,0xff3ffcfb,0x6fffffff,0x6fffffff, 0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x00000000,0x00000000,0x00000000, 0x40004000,0x40004000,0xc01fc01f,0xc01fc01f, 0xc01fc01f,0x40044004,0x40094009,0x40094009, 0x40044004,0x40044004,0x40044004,0x40044004, 0xc01fc01f,0xc01fc01f,0x40094009,0x40044004, 0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x00000000,0x00000000,0x00000000, .... 0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000 }; #endif /*__etpu_image_h */ etpu host interface, rev. .1 conclusion freescale semiconductor 16 appendix 5 code example 5.etpu_pwm_auto.h /* warning this file is automatically generated do not edit it! */ #ifndef __etpu_pwm_auto_h #define __etpu_pwm_auto_h /* function configuration information */ #define etpu_pwm_function_number 5 #define etpu_pwm_table_select 0 #define etpu_pwm_num_parms 0x0010 #define etpu_pwm_int_enable 0 #define etpu_pwm_dma_enable 0 #define etpu_pwm_out_dis 0 #define etpu_pwm_func_mode 0 /* host service request definitions */ #define etpu_pwm_init 1 #define etpu_pwm_update 3 /* parameter definitions */ #define etpu_pwm_period_offset (( 0x0001 - 1)/4) #define etpu_pwm_duty_offset ( 0x0005 - 1)/4 /* global variables image for etpuc_pwm.c*/ #endif /*__etpu_pwm_auto_h */ conclusion etpu host interface, rev. .1 freescale semiconductor 17 appendix 6 code example 6.utility.c /******************************************************************************** * function: mc_etpu_init * * purpose: this function initialize the etpu module including * * 1. initialize global registers * * 2. load etpu code into memory * * 3. copy initial values of global variables to data ram * ********************************************************************************/ uint32_t mc_etpu_init( struct etpu_config_t p_etpu_config, uint32_t *code, uint8_t codesize, uint32_t *globals) { uint32_t *code_end; uint32_t unused_code_ram; unused_code_ram = (((etpu.mcr.b.scmsize - 1 ) * 1024) - (uint32_t)codesize*1024); if ( unused_code_ram < 0 ) return((uint32_t)etpu_error_codesize); /* 1. initialize global registers */ etpu.misccmpr.r = p_etpu_config.misc; //write misc value before it is enable in mcr etpu.mcr.r = p_etpu_config.mcr; /* configure engine 1 */ etpu.tbcr_1.r = p_etpu_config.tbcr_1; etpu.stacr_1.r = p_etpu_config.stacr_1; etpu.ecr_1.r = p_etpu_config.ecr_1; /* configure engine 2 */ etpu.tbcr_2.r = p_etpu_config.tbcr_2; etpu.stacr_2.r = p_etpu_config.stacr_2; etpu.ecr_2.r = p_etpu_config.ecr_2; /* load microcode */ /* in order to write the etpu code ram, both etpu engine has to be stopped. */ /* stopping etpu engine can be achieved by set low power stop bit. */ etpu.ecr_1.b.mdis = 1; etpu.ecr_2.b.mdis = 1; /* enable writing to scm */ etpu.mcr.b.vis = 1; /* 2. copy microcode */ mc_memcpy32( &code_ram, code, (uint32_t)codesize*1024); /* disable writing to scm */ etpu.mcr.b.vis = 0; /* 3. copy initial global values to parameter ram. */ mc_memcpy32 ( &data_ram, globals, etpu_global_mem_size); /* after writing the etpu code ram, both etpu engine has to be re-started. */ /* restart etpu engine can be achieved by clear low power stop bit. */ etpu.ecr_1.b.mdis = 0; etpu.ecr_2.b.mdis = 0; etpu host interface, rev. .1 conclusion freescale semiconductor 18 return((uint32_t) 0); } /******************************************************************************** * function: mc_etpu_chan_init * * purpose: this function initialize the etpu channel including * * 1. assign the etpu function to channel * * 2. configure the channel * * 3. calculate and auto assign function frame * ********************************************************************************/ uint16_t mc_etpu_chan_init( uint8_t channel, uint8_t function, uint8_t mode, \ uint8_t num_param, uint32_t config, uint16_t func_frame) { if (func_frame == 0) { func_frame = mc_etpu_malloc(num_param); if (func_frame == 0) return((uint16_t)etpu_error_malloc); } etpu.chan[channel].cr.r = config + (function<<16) + (func_frame>>3); etpu.chan[channel].scr.r = mode; return(func_frame); } /******************************************************************************** * function: mc_etpu_malloc * * purpose: this function calculates the memory space for a etpu function based * * the number and size of the parameter as well as the static local * * variable for a etpu function. the function returns the address at * * which the next function frame can be assigned. * ********************************************************************************/ uint16_t mc_etpu_malloc( uint16_t num_params) { static uint16_t etpu_pram_used = etpu_pram_start_addr; uint16_t next_function_frame = etpu_pram_used; //each parameter takes 4 bytes, check if there is enough space available if ((etpu_pram_used + num_params<<2) > etpu_pram_size) return(0); else etpu_pram_used += (num_params<<2); //scale the pointer for the function frame return (next_function_frame); } conclusion etpu host interface, rev. .1 freescale semiconductor 19 appendix 7 code example 7.etpu_pwm.c #include "etpu_constants.h" #include "etpu_pwm_auto.h" #define etpu_pse_ram_offset 0x1000 /******************************************************************************** * function: etpu_pwm_init * * purpose: this function executes on the host cpu. * * the function checks validity for parameters then pass them to * * the etpu functions. the function issue the host service request to * * etpu pwm function to initiate the execution. * ********************************************************************************/ int etpu_pwm_init(unsigned char channel, unsigned long period, unsigned long duty) { int errorcode = 0; unsigned long functframe = etpu.chan[channel].cr.b.cpba; unsigned long *pba_32 = &data_ram + (functframe << 1) + etpu_pse_ram_offset; // function parameter validity check if (period > 0xffffff) { errorcode = param_out_range; period = 0xffffff; } if (duty > 0xffffff) { errorcode = param_out_range; duty = 0xffffff; } // passing function parameter to etpu function frame *(pba_32 + etpu_pwm_period_offset) = period; *(pba_32 + etpu_pwm_duty_offset) = duty; //write hsr etpu.chan[channel].hsrr.r = etpu_pwm_init; return (errorcode); } /******************************************************************************** * function: etpu_pwm_update * * purpose: this function executes on the host cpu. * * this function checks validity for parameters then pass them to * * the etpu functions. the function issue the host service request to * * etpu pwm function to update the function parameters. * ********************************************************************************/ int etpu_pwm_update(unsigned char channel, unsigned long period, unsigned long duty) { int errorcode = 0; unsigned long functframe = etpu.chan[channel].cr.b.cpba; unsigned long *pba_32 = &data_ram + (functframe << 1) + etpu_pse_ram_offset; // function parameter validity check etpu host interface, rev. .1 conclusion freescale semiconductor 20 if (period > 0xffffff) { errorcode = param_out_range; period = 0xffffff; } if (duty > 0xffffff) { errorcode = param_out_range; duty = 0xffffff; } // passing function parameter to etpu function frame *(pba_32 + etpu_pwm_period_offset) = period; *(pba_32 + etpu_pwm_duty_offset) = duty; //write hsr etpu.chan[channel].hsrr.r = etpu_pwm_update; return (errorcode); } /******************************************************************************** * function : etpu_pwm_getpulsetime * * purpose: this function executes on the host cpu. * * this function is an application api to read the time stamp of the * * begining of the last peroid of the pwm output on the eptu channel. * ********************************************************************************/ int16_t etpu_pwm_getpulsetime(uint8_t channel, uint32_t * starttime) { int16_t errorcode = 0; uint32_t functframe = etpu.chan[channel].cr.b.cpba; uint32_t *pba_32 = &data_ram + (functframe << 1) + etpu_pse_ram_offset; // passing function parameter to etpu function frame *starttime = *(pba_32 + etpu_pwm_pulse_time_offset); return (errorcode); } this page intentionally left blank etpu host interface, rev. .1 freescale semiconductor 21 this page intentionally left blank etpu host interface, rev. .1 freescale semiconductor 22 this page intentionally left blank etpu host interface, rev. .1 freescale semiconductor 23 how to reach us: home page: www.freescale.com usa/europe or locations not listed: freescale semiconductor technical information center, ch370 1300 n. alma school road chandler, arizona 85224 1-800-521-6274 or 480-768-2130 europe, middle east, and africa: +44 1296 380 456 (english) +46 8 52200080 (english) +49 89 92103 559 (german) +33 1 69 35 48 48 (french) japan: freescale semiconductor japan ltd. technical information center 3-20-1, minami-azabu, minato-ku tokyo 106-0047, japan 0120-191014 or +81-3-3440-3569 asia/pacific: freescale semiconductor hong kong ltd. technical information center 2 dai king street tai po industrial estate tai po, n.t., hong kong 852-26668334 for literature requests only: freescale semiconductor literature distribution center p.o. box 5405 denver, colorado 80217 1-800-441-2447 or 303-675-2140 fax: 303-675-2150 information in this document is provided solely to enable system and software implementers to use freescale semiconductor products. there are no express or implied copyright licenses granted hereunder to design or fabricate any integrated circuits or integrated circuits based on the information in this document. freescale semiconductor reserves the right to make changes without further notice to any products herein. freescale semiconductor makes no warranty, representation or guarantee regarding the suitability of its products for any particular purpose, nor does freescale semiconductor assume any liability arising out of the application or use of any product or circuit, and specifically disclaims any and all liability, including without limitation consequential or incidental damages. ?typical? parameters that may be provided in freescale semiconductor data sheets and/or specifications can and do vary in different applications and actual performance may vary over time. all operating parameters, including ?typicals?, must be validated for each customer application by customer?s technical experts. freescale semiconductor does not convey any license under its patent rights nor the rights of others. freescale semiconductor products are not designed, intended, or authorized for use as components in systems intended for surgical implant into the body, or other applications intended to support or sustain life, or for any other application in which the failure of the freescale semiconductor product could create a situation where personal injury or death may occur. should buyer purchase or use freescale semiconductor products for any such unintended or unauthorized application, buyer shall indemnify and hold freescale semiconductor and its officers, employees, subsidiaries, affiliates, and distributors harmless against all claims, costs, damages, and expenses, and reasonable attorney fees arising out of, directly or indirectly, any claim of personal injury or death associated with such unintended or unauthorized use, even if such claim alleges that freescale semiconductor was negligent regarding the design or manufacture of the part. freescale? and the freescale logo are trademarks of freescale semiconductor, inc. all other product or service names are the property of their respective owners.? freescale semiconductor, inc. 2004. all rights reserved. AN2821 rev. 1 08/2004 |
Price & Availability of AN2821
![]() |
|
|
All Rights Reserved © IC-ON-LINE 2003 - 2022 |
[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy] |
Mirror Sites : [www.datasheet.hk]
[www.maxim4u.com] [www.ic-on-line.cn]
[www.ic-on-line.com] [www.ic-on-line.net]
[www.alldatasheet.com.cn]
[www.gdcy.com]
[www.gdcy.net] |