teco-kit / Jennisense

A modularized open hardware, sensor drivers based on contiki for the JN51xx µController. A detailed description and how-to can be found in the wiki (see link below).
http://github.com/teco-kit/Jennisense/wiki
19 stars 16 forks source link

Sensors not detected for jndevkit #1

Open tglaria opened 11 years ago

tglaria commented 11 years ago

Tried to test the button example code on a 'sensor board' and no sensors are detected (printed the 'num_sensors' trhough the uart and it showed '0').


Well, I guess I just had to initialize the sensors process in PROCINIT for the jndevkit platform. With this, they are detected, but can't differenciate between the two buttons.

scholz commented 11 years ago

Hi tglaria,

thanks for making us aware of the missing initialization of uart and sensor process on jndevkit platform. i embedded your proposed fixes.

as we have multiple platforms we are trying to support at the same time i hope i haven't broken anything else with it - but i guess it will show up soon;).

regarding your button question, i have also updated the applications button example. on devkit the buttons connect the pins to ground i.e. when buttons are up the input pins are high when buttons are pressed the input pins are low. for button0 this means it is pressed when value->... shows 0 and 512 when both buttons are up.

hth, markus

tglaria commented 11 years ago

I'm aware about the several platforms you have, so errors are expected. I'll help as long as I can.

About the buttons, don't know when was the change made, but the way you're getting the button value it's wrong. In /cpu/jennic/dev/button-sensor.c at line 101, you have 'switch(type & __ builtin_popcount(PINS)) But "__ builtin_popcount(PINS)" is always 2 (0b10), o when you check for Button_0 (macro for 0b00), the resulting value for the switch is '0', which looks for the correct button value. Now, when you check for Button_1 (macro for 0b01), the resulting value for the switch is again '0', so it returns the state of Button_0 again.

Solution? Change "switch (type & __builtin_popcount(PINS))" with "switch (type)"

¿What was the idea of masking the selected button with the total number of buttons in existence?

Something similar happened with the LEDs, another 'mask' mistake.

You have to change "c&LEDS_ALL" with "c==LEDS_ALL" in /platform/jndevkit/leds-arch.c"

pscholl commented 11 years ago

__builtin_popcount() was there to let the compiler remove unneccasary case statement, should have been replaced with a proper bitmask. Anyhow, I checked the generated assembler code and the ba-elf-gcc does not do this optimization. Actually the assembler code looks really odd, so let me know if this actually works at all.

right for the LEDs, that had been defined differently in previous contiki versions.