To install ACI into the AscTec SDK 2.0, please download the ACI Device in C for AscTec SDK 2.0 from the AscTec SDK download page. Unpack it in the project folder. It includes the ACI Device in C (asctecCommIntfOnboard.c, asctecCommIntfOnboard.h, asctecDefinesOnboard.h), functions for writing and reading on the EEPROM (lpc_aci_eeprom.c, lpc_aci_eeprom.h, LPC2k_ee.h) and a modified makefile, only the source files for compiling were added.
Refresh the project in Eclipse and compile it again. There should be no errors.
ACI Device in C
The files asctecCommIntfOnboard.c, asctecCommIntfOnboard.h and asctecDefinesOnboard.h are the complete ACI for devices in C. We created a doxygen documentation, so you can easily find out the usage and sense of the different functions. You can find the latest code documentation here or you use doxygen to create it.
Writing and Reading on the EEPROM
The AscTec AutoPilot is using a LPC2148 micro controller. It has its own methods to save/read data on/from it. ACI does not have any dependencies on a specific micro controller and that's the reason why it does not have its own reading/writing methods. Therefore, we create the necessary functions for the AscTec SDK v2.0.
Let us take a look in the lpc_aci_eeprom.h Header file:
COUNT_PAGES defines the number of maximum pages on the EEPROM. You can set the number higher or lower. The micro controller saves its data in pages. If you write 3 full pages of data and if you are deleting only the first page, then other two are still existing. The size of each page is 256 bytes and is defined in LPC2k_ee.h. A page saves only the struct ee_data and its size is 256 bytes. It contains 254 bytes of saved data, a counter for the amount of data in the page (1 byte) and a flag. If there is more data on the next side ( 1 byte ), the flag is active low, which means that it is true, if it is 0.
The function lpc_aci_init() only initializes the data of the pages with 0xFF and sets all callbacks for ACI. Writing and reading data on the device are performed by the three functions lpc_aci_ReadParafromFlash(), lpc_aci_SavePara() and lpc_aci_WriteParatoFlash(). Reading and saving the data on the EEPROM has following structure:
First the ID, then the parameter type are saved (constant 3 bytes). Afterwards, the content of the data is saved, which size depends on the type. Then, new data is saved. The page gets full if one full structure (ID, type and data) will not fit anymore in the page. If you are only saving 4 bytes parameters, you can save on 36 of them.
Before we include any ACI code, we have to include the libraries in the header file. Open main.c and add following line in the Header files topic:
After that, you have to set first all necessary callbacks and set the reading and writing function to the right method. Let us start with the reading and writing functions.
Open the file uart.c, it includes the communication with the serial device. Find the function void uart0ISR(void) __irq , which now looks like:
Delete the content of case 1 and replace it with the following code:
These are the transmission functions in ACI. Now, we only have to add the receiving handler in case 2:
Now, the code looks like:
Save it and close the file. You don't need it anymore.
Define the callbacks
Now, we have to define the necessary callbacks in main. For that, we define a new function for the initialization of ACI.
At the bottom of main.c, let us describe it.
The main-loop is recalled back with a frequency of 1kHZ and so on, we are initializing ACI with aciInit(1000). After that, we set the LPC21xx reading/writing callbacks and the uart sending callback.
Finally, we add our function between the LED-Status and the loop in the main function.
In the next chapter of this tutorial, we will define the first variables, commands and parameters. But first, we will check if everything was correctly initialized.
For testing, we are going to use the ACI Tool, which you can download from the ACI download area. Connect your device with the AscTec USB adapter or XBee pair and start the ACI Tool. Use the arrow and enter key to navigate. Select Connect to serial device, type in the correct FTDI device (usually 0 if only one is connected) and then press enter. If the device can be opened, go on Check ACI Version on device and remote to see, if you receive the ACI info package which should be look similar like this:
This means, that the device can receive and send data to your PC. Now, you are able to check the software version. However you do not get any variables, commands and parameters yet. That will be the content of the next chapter.