Make Arduino timer stuff work on Contiki
New discovery: Contiki also uses timer 0. With almost the same interface as Arduino. So we now completely get rid of wiring.c (only the main file, the other wiring_xxx stay) and implement Arduino timer, delay, etc in terms of the corresponding Contiki routines. Verified that now delay works as expected. The LED in examples/osd/arduino-sketch blinks! Before this, the arduino_init routine in wiring.c destroyed the timer-0 initialization of contiki, making both, contiki timer implementation *and* contiki timer implementation fail if the arduino_init routine was called. Now both work. Squashed with following bug-fix commit.
This commit is contained in:
parent
08abd8807d
commit
c46d6afa39
7 changed files with 61 additions and 273 deletions
|
@ -62,6 +62,7 @@ led_pwm_handler
|
|||
const uint16_t *accept = NULL;
|
||||
uint16_t a_ctype = REST.type.APPLICATION_JSON;
|
||||
uint16_t c_ctype = REST.get_header_content_type (request);
|
||||
uint32_t tmp = 0;
|
||||
|
||||
/* Seems like accepted type is currently unsupported? */
|
||||
n_acc = REST.get_header_accept (request, &accept);
|
||||
|
@ -136,7 +137,11 @@ led_pwm_handler
|
|||
temp [sizeof (temp) - 1] = 0;
|
||||
}
|
||||
PRINTF ("GOT: %s\n", temp);
|
||||
pwm = atoi (temp);
|
||||
tmp = strtoul (temp, NULL, 10);
|
||||
if (tmp > 255) {
|
||||
tmp = 255;
|
||||
}
|
||||
pwm = tmp;
|
||||
PRINTF ("Setting: %d\n", pwm);
|
||||
REST.set_response_status(response, REST.status.CHANGED);
|
||||
} else {
|
||||
|
@ -181,6 +186,7 @@ led_period_handler
|
|||
const uint16_t *accept = NULL;
|
||||
uint16_t a_ctype = REST.type.APPLICATION_JSON;
|
||||
uint16_t c_ctype = REST.get_header_content_type (request);
|
||||
uint32_t tmp = 0;
|
||||
|
||||
/* Seems like accepted type is currently unsupported? */
|
||||
n_acc = REST.get_header_accept (request, &accept);
|
||||
|
@ -255,7 +261,14 @@ led_period_handler
|
|||
temp [sizeof (temp) - 1] = 0;
|
||||
}
|
||||
PRINTF ("GOT: %s\n", temp);
|
||||
period_100ms = (atoi (temp) + 50) / 100;
|
||||
tmp = (strtoul (temp, NULL, 10) + 50) / 100;
|
||||
if (tmp > 10) {
|
||||
tmp = 10;
|
||||
}
|
||||
if (tmp == 0) {
|
||||
tmp = 1;
|
||||
}
|
||||
period_100ms = tmp;
|
||||
PRINTF ("Setting: %dms\n", period_100ms * 100);
|
||||
REST.set_response_status(response, REST.status.CHANGED);
|
||||
} else {
|
||||
|
|
|
@ -28,20 +28,10 @@ void setup (void)
|
|||
|
||||
void loop (void)
|
||||
{
|
||||
static uint8_t last_pwm = 0;
|
||||
if (last_pwm != pwm) {
|
||||
last_pwm = pwm;
|
||||
analogWrite (LED_PIN, pwm);
|
||||
printf
|
||||
( "TCNT3: %04X TCCR3A: %04X TCCR3B: %04X TCCR3C: %04X OCR3C: %04X\n"
|
||||
, TCNT3, TCCR3A, TCCR3B, TCCR3C, OCR3C
|
||||
);
|
||||
}
|
||||
|
||||
// Originally I wanted to sleep here to make the LED blink.
|
||||
// Sleeping currently doesn't work, something turns off the chip.
|
||||
// Maybe a mechanism to guard agains proto-threads taking too long?
|
||||
//clock_wait (CLOCK_SECOND * period_100ms / 10);
|
||||
//analogWrite (LED_PIN, 0);
|
||||
//printf ("After write\n");
|
||||
/* Use 255 - pwm, LED on merkur-board is wired to +3.3V */
|
||||
analogWrite (LED_PIN, 255 - pwm);
|
||||
printf ("clock : %u\nmillis: %lu\n", clock_time (), millis ());
|
||||
delay (period_100ms * 100);
|
||||
analogWrite (LED_PIN, 255); /* OFF: LED on merkur-board is wired to +3.3V */
|
||||
delay (period_100ms * 100);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue