WWW.DUMAIS.IO

SpeedTouch 780 DocumentationLast edited on Feb 25, 2012



SPA941 PhoneBookLast edited on Feb 25, 2012

Personal Directory

An annoying thing with that phone is that it is impossible to provision the phone directory automatically. The good thing is, you can fill the list from the web page of the phone. So then, with wireshark I looked at how this information is posted. All you need is the following script that will simulate a browser submitting the list of numbers. You might wanna check the list of input fields ID, I am not sure if they will be the same on each devices depending on firmware version.

$fields = Array("43311","43503","43439","44655","44591","44783","44719","44911","44847","45039",
"44975","44143","44079","44271","44207","44399","44335","44527","44463","37487","37423","37615",
"37551","37743","37679","37871","37807","36975","36911","37103","37039","37231","37167","37359",
"37295","38511","38447","38639","38575","38767","38703","38895","38831","37999","37935","38127",
"38063","38255","38191","38383","38319","39535","39471","39663","39599","39791","39727","39919",
"39855","39023","38959","39151","39087","39279","39215","39407","39343","40559","40495","40687",
"40623","40815","40751","40943","40879","40047","39983","40175","40111","40303","40239","40431",
"40367","33391","33327","33519","33455","33647","33583","33775","33711","32879","32815","33007",
"32943","33135","33071","33263","33199","34415");

$conn = mysql_connect("localhost","username","password");
mysql_select_db("dbname");
$query = "SELECT * FROM phonebook ORDER BY name;";
$result = mysql_query($query);

$i=0;
$list="";
$n = mysql_num_rows($result);
while ($record = mysql_fetch_assoc($result)) {
        $name = $record['name'];
        $phone = $record['phone'];
        $name = urlencode($name);
        $phone=urlencode($phone);
        $field = $fields[$i];
        $list .= "$field=n%3D$name%3Bp%3D$phone";

        $i++;
        if ($i<$n) $list .= "&";
}

system("wget --post-data '$list' http://192.168.0.107/pdir.spa -t 1");

Executing that script will fetch all entries in the mysql server and post them on the phone located at 192.168.0.107



NGW100 - Different problems and solutionsLast edited on Feb 25, 2012

AVR32 troubleshooting

In this section, I will describe different problems I ran into. Everytime I spend a lot of time trying to figure why something did not work, I will post the found solutions here.

Illegal opcode with conditional instructions

Everytime I was using "addhi" I got an illegal opcode exception. The worse thing was that I was using addhi inside and exception handler. This is because it seems that my CPU uses architecture revision 1. when looking at the isntruction set reference, you can see that these instructions are meant to be used on revision 2 architecture. It is a shame because I couldn't wait to use those.... oh well.

Unrecoverable exception on scall

Everytime I was using "scall", the "unrecoverable exception" was issued instead of EVBA+0x100. I found out that this is because EVBA was not alligned on a 8kb oundary

Copying to parallel flash using u-boot

The address ranges in the AT49BV642D datasheet are 16bit words! So when they say that the sector 23 resides from 0x80000 up to 0x87FFF, it really means from 0x100000 to 0x107FFF.

ASID field in page table

I could understand from the architecture document that the ASID field in a page table entry (from the TLB) is used by the MMU to match the current process ID. What I could not understand was that the ASID field is matched... against what? Yes it is matched against the processID but where is the current proces ID stored? It is in the TLBEHI register. so the TLBEHI[ASID] field should not only be filled before loading a page in the TLB, it should be loaded ALL the time since it will be used for the comparison as well.

Locking entries in TLB

When setting DLA or ILA in MMUCR, make sure you change DRP or IRP accordingly. If you lock the first entry and leave DRP (or IRP) to 0, you will never be able to write anything in the TLB

INTC not working properly, values written to IPR are read back as zero

Make sure that INTC is enabled in PBBMASK (See power manager)

Comparing a page with buffer on the dataflash always says that the page matches even though it is different

When I was reading a page (using 0x87) , then writting something else to buffer1. A buffer comparison always returned that the pages matched. To fix this, I am now using buffer2 to write and compare. It solves the problem but it doesn't make any sense.

MACB: RBQP increases when receiving frames but descriptor's ownership flag does not change

It is important to load RBQP with a physical address (not virtual address). Descriptors must also be loaded with physical addresses. Also, even if reading descriptors from the P2 segment (uncached memory), it is important to invalidate the cache ("cache r0[0],0b1011").



AVR32 assembly tipLast edited on Feb 25, 2012

Cool instructions

on this page, I will describe some instructions I found interesting on the AVR32 CPUs.

BFTEXU and SUBHS

Those two instructions are powerfull. BFTEXU allows you to extract 'n' bits starting at position 'm' in register 'X' and store the result in register 'Y' at position 0 and pad the rest with zeros. Basically, it does all that for you in 1 cycle only:

    bfextu  r5,r8,5,4

is the same as:

    mov    r5,r8
    lsr    r5,5
    mov    r8,0x0F
    and.w  r5,r8

SUBHS r,i will substract 'i' from 'r' and store the result in 'r' only if the carry flag is cleared. Otherwise, it will behave as a NOP. Knowing this, it would be easy to write a function that converts a 32bit number into its ascii representation. Assume that the follwing function takes 'r8' as the input number and we will output each char on the serial port from the MSB to LSB

    swap.b  r8
    mov     r4,4            ; we will do 4 iterations, one for each byte
1:  bfextu  r5,r8,4,4       ; get me the high nibble
    sub     r5,-48          ; substracting -48 is the same as adding 48 right?
    cp      r5,58           ; is the ascii char over '9'?
    subhs   r5,-7           ; if ascii overflowed '9', then add 7 to make it a letter
    rcall   sendSerial

    bfextu  r5,r8,0,4       ; get me the low nibble
    sub     r5,-48          ; substracting -48 is the same as adding 48 right?
    cp      r5,58           ; is the ascii char over '9'?
    subhs   r5,-7           ; if ascii overflowed '9', then add 7 to make it a letter
    rcall   sendSerial

    lsr     r8,8
    sub     r4,1
    brne    1b

BREV

When writing an FFT on a x86 architecture, you dream of having access to such an instruction. BREV allows you to transform 00000000000000000000000000100110 into 01100100000000000000000000000000. It is a bit reversal. I just did that in one cycle only with one instruction. Can you imagine doing that in C? looping through each bit, making shifts, 'OR' etc...

BLD

BLD r,n lets you take bit 'n' from register 'r' and store it in the carry flag. Having this in the carry flag lets you make a conditional branch the way you like without even having to compare anything. Without that instruction, you would need to 'AND' the register with a bit mask, compare the result with 0 and branch conditionally. With BLD, I don't even have to change any registers and I save "AND" step.



Using CouchDB with PHPLast edited on Feb 25, 2012

Introduction

Since couchdb provides a REST interface, it is tempting use AJAX to query the database directly to display data on your webpage. This is not always possible though. If my database runs on port 5555 then this means that my webpage will need access to port 5555 on my server. It's not always possible if firewalls are in the way. We know at least that port 80 should always be accessible. For several security reasons too, we might want the CouchDB to be hidden behind the public network and only accessible by the web server internally. Just as we would do with a SQL server.

Code

  • Retrieve a document
            $h = curl_init("http://server/db1/document1");
            curl_setopt($h, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($h, CURLOPT_CUSTOMREQUEST, "GET");
            $response = curl_exec($h);
            $obj = json_decode($response);
    
  • Create views
    Json file:
    {
       "language": "javascript",
       "views": {
           "view1": {
               "map": "function(doc){emit(doc._id,doc);}"
           },
           "view2": {
               "map": "function(doc){emit(doc._id,doc);}",
               "reduce": "function (key, values){return null;}"
           }
       }
    }
    
    PHP script:
        $json = file_get_contents("views.json");
    
        $h = curl_init("http://server/db1/_design/designdoc1");
        curl_setopt($h, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($h, CURLOPT_CUSTOMREQUEST, "PUT");
        curl_setopt($h, CURLOPT_POSTFIELDS,$json);
        curl_setopt($h, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
        $response = curl_exec($h);
    
    
  • Create doc
            $obj = array("field1"=>"val1","field2"=>"val2");
            $json = json_encode($obj);
            $h = curl_init("http://server/db1/document1");
            curl_setopt($h, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($h, CURLOPT_CUSTOMREQUEST, "PUT");
            curl_setopt($h, CURLOPT_POSTFIELDS,$json);
            curl_setopt($h, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
            $response = curl_exec($h);
    
  • Query a view
            $h = curl_init("http://server/db1/_design/document1/_view/view1?reduce=true&group=true");
            curl_setopt($h, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($h, CURLOPT_CUSTOMREQUEST, "GET");
            $response = curl_exec($h);
            $json=json_decode($response);
    

Retrieving attachments

Let's say we have an attachment that can be reachable at http://couchdbServer/database1/document1/image1.jpg. If "document1" is a blog post that show "image1", it is tempting to put a <img src=database1/document1/image1.jpg > But this is impossible, because that server is inaccessible from the outside world. So we might wanna do a proxy script:

$att = $_GET["a"];
$article = $_GET["art"];

$h = curl_init("http://".COUCHDB_SERVER."/".COUCHDB_DATABASE."/$article/$att");
curl_setopt($h, CURLOPT_RETURNTRANSFER, true);
curl_setopt($h, CURLOPT_CUSTOMREQUEST, "GET");
$response = curl_exec($h);

$contentType = curl_getinfo($h, CURLINFO_CONTENT_TYPE);

header("Content-type: $contentType");
echo $response;

That way we can use our image like this: <img src=attachment.php?doc=document1&attachment=image1.jpg >



Pages:12345678910111213