static jint nativeJAnt_Create(JNIEnv *env, jobject obj) { ANTStatus antStatus = ANT_STATUS_FAILED; (void)env; //unused warning (void)obj; //unused warning ANT_FUNC_START(); antStatus = ant_init(); if (antStatus) { ANT_DEBUG_D("failed to init ANT stack"); goto CLEANUP; } antStatus = set_ant_rx_callback(nativeJAnt_RxCallback); if (antStatus) { ANT_DEBUG_D("failed to set ANT rx callback"); goto CLEANUP; } antStatus = set_ant_state_callback(nativeJAnt_StateCallback); if (antStatus) { ANT_DEBUG_D("failed to set ANT state callback"); goto CLEANUP; } CLEANUP: ANT_FUNC_END(); return antStatus; }
int main(void) { WDTCTL=WDTPW | WDTHOLD; init_p1(); DCOCTL = 0; BCSCTL1 = 12; DCOCTL = 3; BCSCTL2 = 0; ant_phy_reset(); __bis_SR_register(GIE); SEND_MESSAGE_RESET_SYSTEM(); while (1) { check_tx_rx(); if (status_bits & STATUS_BIT_ANT_MESSAGE_RECEIVED) { ant_rx_interpret(); status_bits &= ~STATUS_BIT_ANT_MESSAGE_RECEIVED; } if (ant_cycles_since_last_torque_pulse > 10) { if (status_bits & STATUS_BIT_ANT_AWAKE) { ant_uninit(); //ant_phy_reset(); BCSCTL3 = 0; TACTL = 0; status_bits &= ~STATUS_BIT_ANT_AWAKE; } } else if (!(status_bits & STATUS_BIT_ANT_AWAKE)) { ant_init(); BCSCTL3 = LFXT1S_2; TACTL = TASSEL_1 | MC_2 | TACLR; status_bits |= STATUS_BIT_ANT_AWAKE; } /* if (ant_cycles_since_last_cadence_pulse==21) { SEND_MESSAGE_TORQUE_SUPPORT(ANT_SPORT_CHANNEL, 1 | 2, // autozero status 0xffff, offset); ant_cycles_since_last_cadence_pulse++; // hack, avoid retriggering } */ if (ant_cycles_since_last_cadence_pulse==23) { SEND_MESSAGE_SRM_ZERO_RESPONSE(ANT_SPORT_CHANNEL, offset); ant_cycles_since_last_cadence_pulse++; // hack, avoid retriggering } if (status_bits & STATUS_BIT_CALCULATE_REED_TIME) { status_bits &= ~STATUS_BIT_CALCULATE_REED_TIME; update_crank_time(); } LPM3; } }
uint8_t test_ant(uint8_t ev, uint16_t lparam, void* rparam) { switch(ev) { case EVENT_WINDOW_CREATED: rate = -1; onoff = 0; break; case EVENT_KEY_PRESSED: { if (lparam == KEY_ENTER) { if (onoff) ant_shutdown(); else ant_init(MODE_HRM); onoff ^= 1; } if (lparam == KEY_UP) { data++; if (data > 4) data = 4; if (onoff) ANT_ChannelPower(0, data); } if (lparam == KEY_DOWN) { if (data > 0) data--; if (onoff) ANT_ChannelPower(0, data); } window_invalid(NULL); break; } case EVENT_SPORT_DATA: { if (lparam == SPORTS_HEARTRATE) { rate = (int)rparam; } window_invalid(NULL); break; } case EVENT_WINDOW_PAINT: { tContext *pContext = (tContext*)rparam; GrContextForegroundSet(pContext, ClrBlack); GrRectFill(pContext, &client_clip); GrContextForegroundSet(pContext, ClrWhite); GrContextFontSet(pContext, (tFont*)&g_sFontGothic18); if (onoff) GrStringDraw(pContext, "ANT is on", -1, 32, 50, 0); else GrStringDraw(pContext, "ANT is off", -1, 32, 50, 0); char buf[32]; sprintf(buf, "Tx Power Level: %d", data); GrStringDraw(pContext, buf, -1, 5, 70, 0); if (rate != -1) { sprintf(buf, "heartrate: %d", rate); GrStringDraw(pContext, buf, -1, 5, 90, 0); } window_button(pContext, KEY_UP, "+"); window_button(pContext, KEY_DOWN, "-"); if (onoff) window_button(pContext, KEY_ENTER, "Off"); else window_button(pContext, KEY_ENTER, "On"); break; } case EVENT_WINDOW_CLOSING: if (onoff) ant_shutdown(); break; default: return 0; } return 1; }
/*--------------------------------------------------------------------------*/ int main(int argc, char **argv) { /* * Initalize hardware. */ msp430_cpu_init(); clock_init(); uart_init(9600); /* Must come before first printf */ /* xmem_init(); */ PRINTF("iWatch 0.10 build at " __TIME__ " " __DATE__ "\n"); UCSCTL8 &= ~BIT2; /* * Hardware initialization done! */ /* * Initialize Contiki and our processes. */ process_init(); process_start(&etimer_process, NULL); rtimer_init(); ctimer_init(); energest_init(); ENERGEST_ON(ENERGEST_TYPE_CPU); backlight_init(); battery_init(); SPI_FLASH_Init(); if (system_testing()) { clock_time_t t; backlight_on(200, 0); t = clock_seconds(); // sleep 1 while(clock_seconds() - t <= 3); printf("$$OK BACKLIGHT\n"); t = clock_seconds(); while(clock_seconds() - t <= 3); backlight_on(0, 0); motor_on(200, 0); // sleep 1s t = clock_seconds(); while(clock_seconds() - t <= 3); printf("$$OK MOTOR\n"); t = clock_seconds(); while(clock_seconds() - t <= 3); motor_on(0, 0); #if PRODUCT_W001 I2C_Init(); codec_init(); codec_bypass(1); // sleep 1s t = clock_seconds(); while(clock_seconds() - t <= 3); printf("$$OK MIC\n"); // sleep 1s t = clock_seconds(); while(clock_seconds() - t <= 3); codec_bypass(0); codec_shutdown(); #endif } int reason = CheckUpgrade(); window_init(reason); button_init(); rtc_init(); CFSFontWrapperLoad(); system_init(); // check system status and do factor reset if needed I2C_Init(); //codec_init(); //ant_init(); bluetooth_init(); #ifdef PRODUCT_W004 //bmx_init(); #else mpu6050_init(); #endif // check the button status if (button_snapshot() & (1 << BUTTON_UP)) { clock_time_t t; // delay 1 second // button up is pressed, we will set emerging flag motor_on(200, CLOCK_SECOND * 2); t = clock_seconds(); while(clock_seconds() - t <= 1); if (button_snapshot() & (1 << BUTTON_UP)) system_setemerging(); motor_on(0, 0); } if (!system_retail()) { bluetooth_discoverable(1); } #if PRODUCT_W001 if (system_testing()) ant_init(MODE_HRM); #endif system_restore(); // protocol_init(); // protocol_start(1); process_start(&system_process, NULL); /* * This is the scheduler loop. */ msp430_dco_required = 0; /* check firmware update */ if (reason == 0xff) { printf("Start Upgrade\n"); Upgrade(); // never return if sucessfully upgrade } watchdog_start(); while(1) { int r; do { /* Reset watchdog. */ watchdog_periodic(); r = process_run(); } while(r > 0); /* * Idle processing. */ int s = splhigh(); /* Disable interrupts. */ /* uart1_active is for avoiding LPM3 when still sending or receiving */ if(process_nevents() != 0) { splx(s); /* Re-enable interrupts. */ } else { static unsigned long irq_energest = 0; /* Re-enable interrupts and go to sleep atomically. */ ENERGEST_OFF(ENERGEST_TYPE_CPU); ENERGEST_ON(ENERGEST_TYPE_LPM); /* We only want to measure the processing done in IRQs when we are asleep, so we discard the processing time done when we were awake. */ energest_type_set(ENERGEST_TYPE_IRQ, irq_energest); watchdog_stop(); if (shutdown_mode) { system_shutdown(1); // never return LPM4; } if (msp430_dco_required) { __low_power_mode_0(); } else { __low_power_mode_3(); } /* We get the current processing time for interrupts that was done during the LPM and store it for next time around. */ __disable_interrupt(); irq_energest = energest_type_time(ENERGEST_TYPE_IRQ); __enable_interrupt(); watchdog_start(); ENERGEST_OFF(ENERGEST_TYPE_LPM); ENERGEST_ON(ENERGEST_TYPE_CPU); } } }