/*
 *  メインタスク
 */
void
main_task(intptr_t exinf)
{
#ifdef ROM
I2C_Init_t i2c_initd;
I2C_Handle_t *hi2c;
#endif
ADC_Init_t    aInit;
ADC_ChannelConf_t sConfig;
btstack_init_t btInit;
btstack_handle_t *hbtstack;
ER_UINT   ercd;
省略
#ifdef ROM
/*
 *  I2C初期化ポートはコンパイル・スイッチに従う
 */
    i2c_initd.Baudrate        = 100000;
i2c_initd.SpeedMode       = I2C_SPEED_FAST;
i2c_initd.OwnAddress      = 0;
i2c_initd.AddressingMode  = I2C_ADDRESSINGMODE_7BIT;
i2c_initd.GeneralCallMode = I2C_GENERALCALL_DISABLE;
i2c_initd.semid           = I2CTRS_SEM;
i2c_initd.semlock         = I2CLOC_SEM;
if((hi2c = i2c_init(I2C_PORTID, &i2c_initd)) == NULL){
/* Initialization Error */
syslog_0(LOG_ERROR, "I2C INIT !");
slp_tsk();
}
set_hi2c(hi2c);
#endif

/*
  *  ADCの初期化
 */
aInit.ClockPrescaler = 100;
aInit.FIFOMode       = 0;
aInit.ConvertCount = NUM_ADCBUF;
aInit.RxDmaChannel = -1;
if((hadc = adc_init(ADC1_PORTID, &aInit)) == NULL){
syslog_0(LOG_NOTICE, "adc_init ERROR");
slp_tsk();
}
hadc->xfercallback = adc_convCplt_callback;
hadc->errorcallback = adc_error_callback;
adc_set_int_buffer(hadc, (uint32_t *)uhADCxConvertedValue);
省略
    /*
 *  BLEスタート
 */
btInit.timeout   = 10;
btInit.lockid     = 0;
btInit.semid     = BTTRNS_SEM;
btInit.locksem   = CYW43LOCK_SEM;
btInit.transem   = CYW43TRNS_SEM;
if((hbtstack = btstack_init(&btInit)) == NULL) {
syslog_0(LOG_ERROR, "failed to initialise cyw43_arch");
slp_tsk();
}
l2cap_init();
sm_init();
att_server_init(profile_data, att_read_callback, att_write_callback);    
    /*
 *  BTstackパケットステート設定
 */
hci_event_callback_registration.callback = &packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
att_server_register_packet_handler(packet_handler);
    /*
 *  BTstackタイマ設定
 */
p2p_server_timer.process = &p2p_server_handler;
btstack_run_loop_set_timer(&p2p_server_timer, P2P_SERVER_PERIOD_MS);
btstack_run_loop_add_timer(&p2p_server_timer);
    /*
 *  HCIパワーオン
 */
hci_power_control(HCI_POWER_ON);

/*
 * BTstackポーリング開始
 */
btstack_dispatch(hbtstack);

/*
 *  BLE終了
 */
btstack_deinit(hbtstack);
#ifdef ROM
i2c_deinit(hi2c);
#endif
ercd = adc_deinit(hadc);
syslog_2(LOG_NOTICE, "## STOP[%08x] (%d) ##", &uhADCxConvertedValue, hadc->status);
slp_tsk();
//	SVC_PERROR(ext_ker());
}
