Jflash Source Analysis

Source: Internet
Author: User

Often is the board out of the question, often to give the board signal when you want to use ads to write a long program (I use arm)
often see the jflash of the program only know to reset the board, so I often want to read the source code of Jflash
Today, I finally put up a long unused source Insight, set up a project, began to read Jflash
The so-called dozen snakes dozen seven inches, read the program first read main
I started with main to Jflash anatomy
I read the code is a version of Windows, With VC to compile, I think the Linux version should also be similar, is to define a macro bar, this issue is not concerned about, the first focus on the program itself
Program is a large pile of not commented on the variable, maybe I was talents reason, I just can't see what those variables are for what use, skip it, First look at the following program
#ifdef __windows__
   //test operating system, if WinNT or Win2000 then get device driver H Andle
 osversioninfo osvi;
 osvi.dwosversioninfosize = sizeof (OSVERSIONINFO);
 getversionex (&OSVI);
 if (Osvi.dwplatformid = = ver_platform_win32_nt)
 {
         HANDLE H;

  h = CreateFile (" \\.\giveio ", Generic_read, 0, NULL,
      open_existing, File_attribute_normal, NULL);
  if (H = = Invalid_handle_value)
   error_out ("couldn ' t access Giveio device");
  closehandle (h);
 }
#endif
Copyright information is not said, the following is to detect whether the Giveio has been installed
if not installed, prompted couldn ' t access Giveio device
then invoke the Test_port () function, To find a port that can be used.
before parsing test_port (), we first introduce the same port programming with some introduction
Our PC generally has three ports, their IO address range is usually:
0x3bc-0x3be
0x378 - 0x37a
0x278-0x27a
In many computers, the same port that is usually connected to the JTAG is a 0x378-based address.
You can see a port with three IO addresses, the first is the data register address, and the second is the control register address, The third is the status register address. The Jflash code does not have the same port set, estimation is the use of the SPP (standard port) mode, in which the data register address to write data can be exported to the outside data, to the control register can also output signals to the outside, and the State register can return from high to low 5 bits of state signals, The highest level is the opposite of the signal logic, which makes me feel puzzled, but they say so, that's it.
Below we look at Test_port () code
NT Test_port (void)
{
 //search for valid parallel port

 if (io_access_on (LPT1)) {
  _outp (LPT1, 0x55);
  if ((int) _inp (LPT1) = = 0x55)
        {
             #ifdef DEBUG
             printf ("Parallel Com Port found at I/O address:%xn", LPT1);
            #endif
             return LPT1;
       }

<

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.