int main() { pal_init(/*numberof_threads*/); /*{ for _ in thread_syscalls }*/ pal_start_thread(&ec_thread_/*loop.index0*/); /*{ endfor }*/ pal_run(); return 0; }
void pbpal_init(pubnub_t *pb) { if (PUBNUB_BLOCKING_IO_SETTABLE) { pb->options.use_blocking_io = true; } pal_init(); pb->pal.socket = SOCKET_INVALID; pb->sock_state = STATE_NONE; pb->readlen = 0; buf_setup(pb); }
END_TEST START_TEST(c_pal_recognize_empty) { pal_init(); stroke_t stroke = { 0, 0, NULL }; ck_assert(PAL_TYPE_INDET == pal_recognize(&stroke)); pal_deinit(); }
END_TEST START_TEST(c_pal_recognize_40_points) { pal_init(); stroke_t stroke = { 40, 40, calloc(40, sizeof(point_t)) }; ck_assert(PAL_TYPE_INDET == pal_recognize(&stroke)); ck_assert(PAL_TYPE_INDET == pal_last_type()); pal_deinit(); }
} END_TEST //////////////////////////////////////////////////////////////////////////////// // ----------------------------- Simple Checks ------------------------------ // //////////////////////////////////////////////////////////////////////////////// START_TEST(c_pal_init_deinit) { // Just making sure things don't break out of the gate. pal_init(); ck_assert(PAL_TYPE_UNRUN == pal_last_type()); pal_deinit(); }
M2MConnectionHandlerPimpl::M2MConnectionHandlerPimpl(M2MConnectionHandler* base, M2MConnectionObserver &observer, M2MConnectionSecurity* sec, M2MInterface::BindingMode mode, M2MInterface::NetworkStack stack) :_base(base), _observer(observer), _security_impl(sec), _security(NULL), _use_secure_connection(false), _binding_mode(mode), _socket(0), _is_handshaking(false), _listening(true), _server_type(M2MConnectionObserver::LWM2MServer), _server_port(0), _listen_port(0), _running(false), _net_iface(0), _socket_state(ESocketStateDisconnected) { #ifndef PAL_NET_TCP_AND_TLS_SUPPORT if (is_tcp_connection()) { tr_error("ConnectionHandler: TCP support not available."); return; } #endif if(PAL_SUCCESS != pal_init()){ tr_error("PAL init failed."); } memset(&_address, 0, sizeof _address); memset(&_socket_address, 0, sizeof _socket_address); memset(&_ipV4Addr, 0, sizeof(palIpV4Addr_t)); memset(&_ipV6Addr, 0, sizeof(palIpV6Addr_t)); memset(&_recv_buffer, 0, BUFFER_LENGTH); connection_handler = this; eventOS_scheduler_mutex_wait(); if (M2MConnectionHandlerPimpl::_tasklet_id == -1) { M2MConnectionHandlerPimpl::_tasklet_id = eventOS_event_handler_create(&connection_event_handler, ESocketIdle); } eventOS_scheduler_mutex_release(); }
int main(int argc, char** argv) { int rc; const char* port = "80"; struct engine* eng; while ((rc = getopt(argc, argv, "hp:")) != -1) { switch (rc) { case 'p': port = optarg; break; case 'h': usage(0); break; default: usage(2); break; } } if (pal_init(&pal)) return -1; eng = engine_init(&pal); rc = web_init(eng, port); if (rc) { LOG(("Web server failed to start: (%d) %s\n", rc, strerror(rc))); return rc; } LOG(("Running engine\n")); web_run(); engine_run(); web_destroy(); engine_destroy(); pal_destroy(&pal); LOG(("Exited gracefully\n")); return 0; }
/** * @brief Initializes the TAL * * This function is called to initialize the TAL. The transceiver is * initialized, the TAL PIBs are set to their default values, and the TAL state * machine is set to TAL_IDLE state. * * @return MAC_SUCCESS if the transceiver state is changed to TRX_OFF and the * current device part number and version number are correct; * FAILURE otherwise */ retval_t tal_init(void) { /* Init the PAL and by this means also the transceiver interface */ if (pal_init() != MAC_SUCCESS) { return FAILURE; } if (trx_init() != MAC_SUCCESS) { return FAILURE; } #if (EXTERN_EEPROM_AVAILABLE == 1) pal_ps_get(EXTERN_EEPROM, EE_IEEE_ADDR, 8, &tal_pib.IeeeAddress); #else pal_ps_get(INTERN_EEPROM, EE_IEEE_ADDR, 8, &tal_pib.IeeeAddress); #endif /* * Do the reset stuff. * Set the default PIBs. * Generate random seed. */ if (internal_tal_reset(true) != MAC_SUCCESS) { return FAILURE; } #ifndef DISABLE_IEEE_ADDR_CHECK /* Check if a valid IEEE address is available. */ /* * This while loop is on purpose, since just in the * rare case that such an address is randomly * generated again, we must repeat this. */ while ((tal_pib.IeeeAddress == 0x0000000000000000) || (tal_pib.IeeeAddress == 0xFFFFFFFFFFFFFFFF) ) { /* * In case no valid IEEE address is available, a random * IEEE address will be generated to be able to run the * applications for demonstration purposes. * In production code this can be omitted. */ /* * The proper seed for function rand() has already been generated * in function tal_generate_rand_seed(). */ uint8_t *ptr_pib = (uint8_t *)&tal_pib.IeeeAddress; for (uint8_t i = 0; i < 8; i++) { *ptr_pib++ = (uint8_t)rand(); /* * Note: * Even if casting the 16 bit rand value back to 8 bit, * and running the loop 8 timers (instead of only 4 times) * may look cumbersome, it turns out that the code gets * smaller using 8-bit here. * And timing is not an issue at this place... */ } } #endif /* #ifndef DISABLE_IEEE_ADDR_CHECK */ /* * Configure interrupt handling. * Install handlers for the transceiver interrupts. */ pal_trx_irq_init_rx_end((FUNC_PTR)trx_rx_end_handler_cb); pal_trx_irq_init_tx_end((FUNC_PTR)trx_tx_end_handler_cb); pal_trx_irq_init_awake((FUNC_PTR)trx_awake_handler_cb); #if (defined BEACON_SUPPORT) || (defined ENABLE_TSTAMP) /* Configure time stamp interrupt. */ pal_trx_irq_init_tstamp((FUNC_PTR)trx_irq_timestamp_handler_cb); #endif /* (defined BEACON_SUPPORT) || (defined ENABLE_TSTAMP) */ /* Initialize the buffer management module and get a buffer to store reveived frames. */ bmm_buffer_init(); tal_rx_buffer = bmm_buffer_alloc(LARGE_BUFFER_SIZE); /* Init incoming frame queue */ #ifdef ENABLE_QUEUE_CAPACITY qmm_queue_init(&tal_incoming_frame_queue, TAL_INCOMING_FRAME_QUEUE_CAPACITY); #else qmm_queue_init(&tal_incoming_frame_queue); #endif /* ENABLE_QUEUE_CAPACITY */ #ifdef ENABLE_TFA tfa_init(); #endif return MAC_SUCCESS; } /* tal_init() */
/** * @brief Initializes the TAL * * This function is called to initialize the TAL. The transceiver is * initialized, the TAL PIBs are set to their default values, and the TAL state * machine is set to TAL_IDLE state. * * @return MAC_SUCCESS if the transceiver state is changed to TRX_OFF and the * current device part number and version number are correct; * FAILURE otherwise */ retval_t tal_init(void) { /* Init the PAL and by this means also the transceiver interface */ #ifdef ENABLE_RP /* * The ranging processor (RP) only performs a minimalistic * initialization here. */ pal_basic_init(); #else /* !ENABLE_RP */ if (pal_init() != MAC_SUCCESS) { return FAILURE; } if (trx_init() != MAC_SUCCESS) { return FAILURE; } #if (EXTERN_EEPROM_AVAILABLE == 1) pal_ps_get(EXTERN_EEPROM, EE_IEEE_ADDR, 8, &tal_pib.IeeeAddress); #else #if (USER_SIGN_AVAILABLE == 1) pal_ps_get(USER_SIGNATURE, USER_SIGNATURES_START + 2, 8, &tal_pib.IeeeAddress); //http://www.atmel.com/Images/Atmel-42172-Wireless-ZigBit-ATZB-X0-256-3-0-C_Datasheet.pdf #else pal_ps_get(INTERN_EEPROM, EE_IEEE_ADDR, 8, &tal_pib.IeeeAddress); #endif #endif /* * Do the reset stuff. * Set the default PIBs. * Generate random seed. */ if (internal_tal_reset(true) != MAC_SUCCESS) { return FAILURE; } #ifndef DISABLE_IEEE_ADDR_CHECK /* Check if a valid IEEE address is available. */ /* * This while loop is on purpose, since just in the * rare case that such an address is randomly * generated again, we must repeat this. */ while ((tal_pib.IeeeAddress == 0x0000000000000000) || (tal_pib.IeeeAddress == 0xFFFFFFFFFFFFFFFF)) { /* * In case no valid IEEE address is available, a random * IEEE address will be generated to be able to run the * applications for demonstration purposes. * In production code this can be omitted. */ /* * The proper seed for function rand() has already been generated * in function tal_generate_rand_seed(). */ uint8_t *ptr_pib = (uint8_t *)&tal_pib.IeeeAddress; for (uint8_t i = 0; i < 8; i++) { *ptr_pib++ = (uint8_t)rand(); /* * Note: * Even if casting the 16 bit rand value back to 8 bit, * and running the loop 8 timers (instead of only 4 times) * may look cumbersome, it turns out that the code gets * smaller using 8-bit here. * And timing is not an issue at this place... */ } } #endif /* #ifndef DISABLE_IEEE_ADDR_CHECK */ #endif /* ENABLE_RP */ /* * Configure interrupt handling. * Install a handler for the transceiver interrupt. */ pal_trx_irq_init(trx_irq_handler_cb); #ifndef ENABLE_RP pal_trx_irq_en(); /* Enable transceiver main interrupt. */ #endif #if ((defined BEACON_SUPPORT) || (defined ENABLE_TSTAMP)) && (DISABLE_TSTAMP_IRQ == 0) /* Configure time stamp interrupt. */ pal_trx_irq_init_tstamp(trx_irq_timestamp_handler_cb); #ifndef ENABLE_RP pal_trx_irq_en_tstamp(); /* Enable timestamp interrupt. */ #endif #endif /* Initialize the buffer management module and get a buffer to store received frames. */ bmm_buffer_init(); tal_rx_buffer = bmm_buffer_alloc(LARGE_BUFFER_SIZE); #if DEBUG > 0 if (tal_rx_buffer == NULL) { return FAILURE; } #endif /* Init incoming frame queue */ #ifdef ENABLE_QUEUE_CAPACITY qmm_queue_init(&tal_incoming_frame_queue, TAL_INCOMING_FRAME_QUEUE_CAPACITY); #else qmm_queue_init(&tal_incoming_frame_queue); #endif /* ENABLE_QUEUE_CAPACITY */ #ifdef ENABLE_TFA tfa_init(); #endif return MAC_SUCCESS; } /* tal_init() */
/* * \brief Initializes the TAL * * This function is called to initialize the TAL. The transceiver is * initialized, the TAL PIBs are set to their default values, and the TAL state * machine is set to TAL_IDLE state. * * \return MAC_SUCCESS if the transceiver state is changed to TRX_OFF and the * current device part number and version number are correct; * FAILURE otherwise */ retval_t tal_init(void) { /* Init the PAL and by this means also the transceiver interface */ if (pal_init() != MAC_SUCCESS) { return FAILURE; } if (trx_init() != MAC_SUCCESS) { return FAILURE; } if (tal_timer_init() != MAC_SUCCESS) { return FAILURE; } #ifdef ENABLE_STACK_NVM pal_ps_get(INTERN_EEPROM, EE_IEEE_ADDR, 8, &tal_pib.IeeeAddress); #endif /* * For systems including the AT86RF230B the random seed generation * cannot be done using a dedicated hardware feature. * Therefore all random seed generation needs to be done by special * means (e.g. utilization of ADC) that generate a random value only * within a certain range. * * In case the node already has a valid IEEE address (i.e. an IEEE * address which is different from 0x0000000000000000 or * 0xFFFFFFFFFFFFFFFF), this IEEE address (the lower 16 bit) * shall be used as seed for srand(), since each node should have a *unique * IEEE address. * In this case srand() is called directly and function *tal_generate_rand_seed() * is not called. * * Note: This behaviour is different in all other TALs, since in these * cases the seed for srand() is always generated based on transceiver * hardware support. */ #ifndef DISABLE_IEEE_ADDR_CHECK if ((tal_pib.IeeeAddress == 0x0000000000000000) || (tal_pib.IeeeAddress == 0xFFFFFFFFFFFFFFFF) ) { /* * Generate a seed for the random number generator in function *rand(). * This is required (for example) as seed for the CSMA-CA *algorithm. */ tal_generate_rand_seed(); /* * Now that we have generated a random seed, we can generate a *random * IEEE address for this node. */ do { /* * In case no valid IEEE address is available, a random * IEEE address will be generated to be able to run the * applications for demonstration purposes. * In production code this can be omitted. */ /* * The proper seed for function rand() has already been *generated * in function tal_generate_rand_seed(). */ uint8_t *ptr_pib = (uint8_t *)&tal_pib.IeeeAddress; for (uint8_t i = 0; i < 8; i++) { *ptr_pib++ = (uint8_t)rand(); /* * Note: * Even if casting the 16 bit rand value back to *8 bit, * and running the loop 8 timers (instead of *only 4 times) * may look cumbersome, it turns out that the *code gets * smaller using 8-bit here. * And timing is not an issue at this place... */ } } /* Check if a valid IEEE address is available. */ while ((tal_pib.IeeeAddress == 0x0000000000000000) || (tal_pib.IeeeAddress == 0xFFFFFFFFFFFFFFFF) ); } else { /* Valid IEEE address, so no need to generate a new random seed. **/ uint16_t cur_rand_seed = (uint16_t)tal_pib.IeeeAddress; srand(cur_rand_seed); } #else /* * No check for a valid IEEE address done, so directly create a seed * for srand(). */ tal_generate_rand_seed(); #endif /* * Do the reset stuff. * Set the default PIBs. */ if (internal_tal_reset(true) != MAC_SUCCESS) { return FAILURE; } pal_trx_reg_read(RG_IRQ_STATUS); /* clear pending irqs, dummy read */ /* * Configure interrupt handling. * Install a handler for the transceiver interrupt. */ pal_trx_irq_init((FUNC_PTR)trx_irq_handler_cb); pal_trx_irq_en(); /* Enable transceiver main interrupt. */ /* Initialize the buffer management module and get a buffer to store *reveived frames. */ bmm_buffer_init(); tal_rx_buffer = bmm_buffer_alloc(LARGE_BUFFER_SIZE); /* Init incoming frame queue */ #ifdef ENABLE_QUEUE_CAPACITY qmm_queue_init(&tal_incoming_frame_queue, TAL_INCOMING_FRAME_QUEUE_CAPACITY); #else qmm_queue_init(&tal_incoming_frame_queue); #endif /* ENABLE_QUEUE_CAPACITY */ return MAC_SUCCESS; } /* tal_init() */
void main_init(int argc, char *argv[]) { char t[512], *p; int c; int tapenext = 0, discnext = 0; startblit(); log_open(); log_info("main: starting %s", VERSION_STR); vid_fskipmax = 1; al_init_main(argc, argv); append_filename(t, exedir, "roms/tube/ReCo6502ROM_816", 511); if (!file_exists(t,FA_ALL,NULL) && selecttube == 4) selecttube = -1; curtube = selecttube; model_check(); for (c = 1; c < argc; c++) { // log_debug("%i : %s",c,argv[c]); /* if (!strcasecmp(argv[c],"-1770")) { I8271=0; WD1770=1; } else*/ //#ifndef WIN32 if (!strcasecmp(argv[c], "--help")) { printf("%s command line options :\n\n", VERSION_STR); printf("-mx - start as model x (see readme.txt for models)\n"); printf("-tx - start with tube x (see readme.txt for tubes)\n"); printf("-disc disc.ssd - load disc.ssd into drives :0/:2\n"); printf("-disc1 disc.ssd - load disc.ssd into drives :1/:3\n"); printf("-autoboot - boot disc in drive :0\n"); printf("-tape tape.uef - load tape.uef\n"); printf("-fasttape - set tape speed to fast\n"); printf("-s - scanlines display mode\n"); printf("-i - interlace display mode\n"); printf("-debug - start debugger\n"); printf("-allegro - use Allegro for video rendering\n"); exit(-1); } else //#endif if (!strcasecmp(argv[c], "-tape")) { tapenext = 2; } else if (!strcasecmp(argv[c], "-disc") || !strcasecmp(argv[c], "-disk")) { discnext = 1; } else if (!strcasecmp(argv[c], "-disc1")) { discnext = 2; } else if (argv[c][0] == '-' && (argv[c][1] == 'm' || argv[c][1] == 'M')) { sscanf(&argv[c][2], "%i", &curmodel); } else if (argv[c][0] == '-' && (argv[c][1] == 't' || argv[c][1] == 'T')) { sscanf(&argv[c][2], "%i", &curtube); } else if (!strcasecmp(argv[c], "-fasttape")) { fasttape = 1; } else if (!strcasecmp(argv[c], "-autoboot")) { autoboot = 150; } else if (argv[c][0] == '-' && (argv[c][1] == 'f' || argv[c][1]=='F')) { sscanf(&argv[c][2], "%i", &vid_fskipmax); if (vid_fskipmax < 1) vid_fskipmax = 1; if (vid_fskipmax > 9) vid_fskipmax = 9; } else if (argv[c][0] == '-' && (argv[c][1] == 's' || argv[c][1] == 'S')) { vid_scanlines = 1; } else if (!strcasecmp(argv[c], "-debug")) { debug_core = 1; } else if (!strcasecmp(argv[c], "-debugtube")) { debug_tube = 1; } else if (argv[c][0] == '-' && (argv[c][1] == 'i' || argv[c][1] == 'I')) { vid_interlace = 1; vid_linedbl = vid_scanlines = 0; } else if (tapenext) strcpy(tape_fn, argv[c]); else if (discnext) { strcpy(discfns[discnext-1], argv[c]); discnext = 0; } else { if ((p = strrchr(argv[c], '.')) && (!strcasecmp(p, ".uef") || !strcasecmp(p, ".csw"))) { strncpy(tape_fn, argv[c], sizeof tape_fn); tapenext = 0; } else { strncpy(discfns[0], argv[c], sizeof discfns[0]); discnext = 0; autoboot = 150; } } if (tapenext) tapenext--; } video_init(); mode7_makechars(); #ifndef WIN32 install_keyboard(); #endif install_timer(); mem_init(); ddnoise_init(); tapenoise_init(); sound_init(); al_init(); sid_init(); sid_settype(sidmethod, cursid); music5000_init(); adc_init(); #ifdef WIN32 pal_init(); #endif disc_init(); fdi_init(); scsi_init(); ide_init(); vdfs_init(); model_init(); midi_init(); main_reset(); install_int_ex(secint, MSEC_TO_TIMER(1000)); install_int_ex(int50, MSEC_TO_TIMER(20)); set_display_switch_mode(SWITCH_BACKGROUND); #ifdef WIN32 timeBeginPeriod(1); #endif oldmodel = curmodel; if (curtube == 3 || mouse_amx) install_mouse(); disc_load(0, discfns[0]); disc_load(1, discfns[1]); tape_load(tape_fn); if (defaultwriteprot) writeprot[0] = writeprot[1] = 1; endblit(); debug_start(); }
/** * @brief Initializes the TAL * * This function is called to initialize the TAL. The transceiver is * initialized, the TAL PIBs are set to their default values, and the TAL state * machine is set to TAL_IDLE state. * * @return MAC_SUCCESS if the transceiver state is changed to TRX_OFF and the * current device part number and version number are correct; * FAILURE otherwise */ retval_t tal_init(void) { /* Init the PAL and by this means also the transceiver interface */ if (pal_init() != MAC_SUCCESS) { return FAILURE; } /* Reset trx */ if (trx_reset(RFBOTH) != MAC_SUCCESS) { return FAILURE; } /* Check if RF215 is connected */ if ((trx_reg_read( RG_RF_PN) != 0x34) || (trx_reg_read( RG_RF_VN) != 0x01)) { return FAILURE; } /* Initialize trx */ trx_init(); if (tal_timer_init() != MAC_SUCCESS) { return FAILURE; } /* Initialize the buffer management */ bmm_buffer_init(); /* Configure both trx and set default PIB values */ for (uint8_t trx_id = 0; trx_id < NUM_TRX; trx_id++) { /* Configure transceiver */ trx_config((trx_id_t)trx_id); #ifdef RF215V1 /* Calibrate LO */ calibrate_LO((trx_id_t)trx_id); #endif /* Set the default PIB values */ init_tal_pib((trx_id_t)trx_id); /* see 'tal_pib.c' */ calculate_pib_values((trx_id_t)trx_id); /* * Write all PIB values to the transceiver * that are needed by the transceiver itself. */ write_all_tal_pib_to_trx((trx_id_t)trx_id); /* see 'tal_pib.c' **/ config_phy((trx_id_t)trx_id); tal_rx_buffer[trx_id] = bmm_buffer_alloc(LARGE_BUFFER_SIZE); if (tal_rx_buffer[trx_id] == NULL) { return FAILURE; } /* Init incoming frame queue */ qmm_queue_init(&tal_incoming_frame_queue[trx_id]); tal_state[trx_id] = TAL_IDLE; tx_state[trx_id] = TX_IDLE; } /* Init seed of rand() */ tal_generate_rand_seed(); #ifndef DISABLE_IEEE_ADDR_CHECK for (uint8_t trx_id = 0; trx_id < 2; trx_id++) { /* Check if a valid IEEE address is available. */ /* * This while loop is on purpose, since just in the * rare case that such an address is randomly * generated again, we must repeat this. */ while ((tal_pib[trx_id].IeeeAddress == 0x0000000000000000) || (tal_pib[trx_id].IeeeAddress == ((uint64_t)-1))) { /* * In case no valid IEEE address is available, a random * IEEE address will be generated to be able to run the * applications for demonstration purposes. * In production code this can be omitted. */ /* * The proper seed for function rand() has already been *generated * in function tal_generate_rand_seed(). */ uint8_t *ptr_pib = (uint8_t *)&tal_pib[trx_id].IeeeAddress; for (uint8_t i = 0; i < 8; i++) { *ptr_pib++ = (uint8_t)rand(); /* * Note: * Even if casting the 16 bit rand value back to *8 bit, * and running the loop 8 timers (instead of *only 4 times) * may look cumbersome, it turns out that the *code gets * smaller using 8-bit here. * And timing is not an issue at this place... */ } } } #endif #ifdef IQ_RADIO /* Init BB IRQ handler */ pal_trx_irq_flag_clr(RF215_BB); trx_irq_init(RF215_BB, bb_irq_handler_cb); pal_trx_irq_en(RF215_BB); /* Init RF IRQ handler */ pal_trx_irq_flag_clr(RF215_RF); trx_irq_init(RF215_RF, rf_irq_handler_cb); pal_trx_irq_en(RF215_RF); #else /* * Configure interrupt handling. * Install a handler for the radio and the baseband interrupt. */ pal_trx_irq_flag_clr(); trx_irq_init((FUNC_PTR)trx_irq_handler_cb); pal_trx_irq_en(); /* Enable transceiver main interrupt. */ #endif #if ((defined SUPPORT_FSK) && (defined SUPPORT_MODE_SWITCH)) init_mode_switch(); #endif return MAC_SUCCESS; } /* tal_init() */