Esempio n. 1
0
static void _up_assert(int errorcode)
{
  /* Flush any buffered SYSLOG data */

  (void)syslog_flush();

  /* Are we in an interrupt handler or the idle task? */

  if (g_current_regs || this_task()->pid == 0)
    {
       (void)up_irq_save();
        for (; ; )
          {
#if CONFIG_BOARD_RESET_ON_ASSERT >= 1
            board_reset(0);
#endif
#ifdef CONFIG_ARCH_LEDS
            board_autoled_on(LED_PANIC);
            up_mdelay(250);
            board_autoled_off(LED_PANIC);
            up_mdelay(250);
#endif
          }
    }
  else
    {
#if CONFIG_BOARD_RESET_ON_ASSERT >= 2
      board_reset(0);
#endif
      exit(errorcode);
    }
}
Esempio n. 2
0
/**
\brief Replace the period of a running timer.
 */
void  opentimers_setPeriod(opentimer_id_t id,time_type_t timetype,uint32_t newDuration) {
   if        (timetype==TIME_MS) {
      opentimers_vars.timersBuf[id].period_ticks      = newDuration*PORT_TICS_PER_MS;
      opentimers_vars.timersBuf[id].wraps_remaining   = (newDuration*PORT_TICS_PER_MS/MAX_TICKS_IN_SINGLE_CLOCK);//65535=maxValue of uint16_t
   } else if (timetype==TIME_TICS) {
      opentimers_vars.timersBuf[id].period_ticks      = newDuration;
      opentimers_vars.timersBuf[id].wraps_remaining   = (newDuration/MAX_TICKS_IN_SINGLE_CLOCK);//65535=maxValue of uint16_t
   } else {
      // this should never happpen!
      
      // we can not print from within the drivers. Instead:
      // blink the error LED
      leds_error_blink();
      // reset the board
      board_reset();
   }
   if(opentimers_vars.timersBuf[id].wraps_remaining==0) {
      if        (timetype==TIME_MS){
         opentimers_vars.timersBuf[id].ticks_remaining   = newDuration*PORT_TICS_PER_MS;
      } else if (timetype==TIME_TICS){
         opentimers_vars.timersBuf[id].ticks_remaining   = newDuration;
      }
   } else {
      opentimers_vars.timersBuf[id].ticks_remaining = MAX_TICKS_IN_SINGLE_CLOCK;
   }
}
Esempio n. 3
0
// executed in ISR
void openserial_handleRxFrame() {
    uint8_t cmdByte;

    cmdByte = openserial_vars.inputBuf[0];
    // call hard-coded commands
    // FIXME: needs to be replaced by registered commands only
    switch (cmdByte) {
        case SERFRAME_PC2MOTE_SETROOT:
            idmanager_triggerAboutRoot();
            break;
        case SERFRAME_PC2MOTE_RESET:
            board_reset();
            break;
        case SERFRAME_PC2MOTE_DATA:
            openbridge_triggerData();
            break;
        case SERFRAME_PC2MOTE_TRIGGERSERIALECHO:
            openserial_handleEcho(
                &openserial_vars.inputBuf[1],
                openserial_vars.inputBufFillLevel-1
            );
            break;
        case SERFRAME_PC2MOTE_COMMAND:
            openserial_handleCommands();
            break;
    }
    // call registered commands
    if (openserial_vars.registeredCmd!=NULL && openserial_vars.registeredCmd->cmdId==cmdByte) {
        openserial_vars.registeredCmd->cb();
    }
}
Esempio n. 4
0
void test_board_san() {
    puts("test_board_san");
    board_t pos;
    char san[LEN_SAN];

    // Double pawn move.
    board_reset(&pos);
    board_san(&pos, move_make(SQ_H2, SQ_H4, kNone), san);
    assert(strcmp(san, "h4") == 0);

    // Promotion.
    assert(board_set_fen(&pos, "4k3/8/8/8/8/8/6p1/4K3 b - - 0 1"));
    board_san(&pos, move_make(SQ_G2, SQ_G1, kRook), san);
    assert(strcmp(san, "g1=R+") == 0);

    // Not ambiguous because of pin.
    assert(board_set_fen(&pos, "4k3/8/8/b7/8/2N3N1/8/4K3 w - - 0 1"));
    board_san(&pos, move_make(SQ_G3, SQ_E4, 0), san);
    puts(san);
    assert(strcmp(san, "Ne4") == 0);

    // Ambiguous.
    board_remove_piece_at(&pos, SQ_A5);
    board_san(&pos, move_make(SQ_G3, SQ_E4, 0), san);
    assert(strcmp(san, "Nge4") == 0);
}
Esempio n. 5
0
int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
/* Everything after the first generation of PQ3 parts has RSTCR */
#if defined(CONFIG_MPC8540) || defined(CONFIG_MPC8541) || \
    defined(CONFIG_MPC8555) || defined(CONFIG_MPC8560)
	unsigned long val, msr;

	/*
	 * Initiate hard reset in debug control register DBCR0
	 * Make sure MSR[DE] = 1.  This only resets the core.
	 */
	msr = mfmsr ();
	msr |= MSR_DE;
	mtmsr (msr);

	val = mfspr(DBCR0);
	val |= 0x70000000;
	mtspr(DBCR0,val);
#else
	volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);

	/* Attempt board-specific reset */
	board_reset();

	/* Next try asserting HRESET_REQ */
	out_be32(&gur->rstcr, 0x2);
	udelay(100);
#endif

	return 1;
}
Esempio n. 6
0
int do_reset(struct cmd_ctx *ctx, int argc, char * const argv[])
{
	puts ("resetting ...\n\n");
	board_reset();

	/* Not reached */
	return 0;
}
Esempio n. 7
0
void test_board_reset() {
    puts("test_board_reset");

    struct board pos;
    board_reset(&pos);
    assert(BB_E1 & pos.occupied[kKing]);
    assert(BB_C7 & pos.occupied[kPawn]);
}
Esempio n. 8
0
void board_system_reset(int status)
{
#if defined(BOARD_HAS_ON_RESET)
	board_on_reset(status);
#endif
	board_reset(status);

	while (1);
}
Esempio n. 9
0
kick_scheduler_t spi_isr() {
#ifdef SPI_IN_INTERRUPT_MODE   
   // save the byte just received in the RX buffer
   switch (spi_vars.returnType) {
      case SPI_FIRSTBYTE:
         if (spi_vars.numTxedBytes==0) {
            *spi_vars.pNextRxByte   = U0RXBUF;
         }
         break;
      case SPI_BUFFER:
         *spi_vars.pNextRxByte      = U0RXBUF;
         spi_vars.pNextRxByte++;
         break;
      case SPI_LASTBYTE:
         *spi_vars.pNextRxByte      = U0RXBUF;
         break;
   }
   
   // one byte less to go
   spi_vars.pNextTxByte++;
   spi_vars.numTxedBytes++;
   spi_vars.txBytesLeft--;
   
   if (spi_vars.txBytesLeft>0) {
      // write next byte to TX buffer
      U0TXBUF                = *spi_vars.pNextTxByte;
   } else {
      // put CS signal high to signal end of transmission to slave
      if (spi_vars.isLast==SPI_LAST) {
         P4OUT                 |=  0x04;
      }
      // SPI is not busy anymore
      spi_vars.busy             =  0;
      
      // SPI is done!
      if (spi_vars.callback!=NULL) {
         // call the callback
         spi_vars.spi_cb();
         // kick the OS
         return KICK_SCHEDULER;
      }
   }
   return DO_NOT_KICK_SCHEDULER;
#else
   // this should never happpen!
   
   // we can not print from within the BSP. Instead:
   // blink the error LED
   leds_error_blink();
   // reset the board
   board_reset();
   
   return DO_NOT_KICK_SCHEDULER; // we will not get here, statement to please compiler
#endif
}
Esempio n. 10
0
__dead void
boot(int howto)
{
	if (cold) {
		if ((howto & RB_USERREQ) == 0)
			howto |=  RB_HALT;
		goto haltsys;
	}

	/*
	 * If RB_NOSYNC was not specified sync the discs.
	 * Note: Unless cold is set to 1 here, syslogd will die during the
	 * unmount.  It looks like syslogd is getting woken up only to find
	 * that it cannot page part of the binary in as the filesystem has
	 * been unmounted.
	 */
	if ((howto & RB_NOSYNC) == 0)
		bootsync(howto);

	if_downall();

	uvm_shutdown();
	splhigh();
	cold = 1;

	if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
		dumpsys();

haltsys:
	config_suspend_all(DVACT_POWERDOWN);

	/* Make sure IRQ's are disabled */
	IRQdisable;

	if ((howto & RB_HALT) != 0) {
		if ((howto & RB_POWERDOWN) != 0) {
			board_powerdown();
			printf("WARNING: powerdown failed!\n");
		}

		printf("The operating system has halted.\n");
		printf("Please press any key to reboot.\n\n");
		cnpollc(1);
		cngetc();
		cnpollc(0);
	}

	printf("rebooting...\n");

	board_reset();
	cpu_reset();
	printf("reboot failed; spinning\n");
	for (;;) ;
	/* NOTREACHED */
}
Esempio n. 11
0
inline uint16_t radiotimer_getCapturedTime() {
   // this should never happpen!
   
   // we can not print from within the BSP. Instead:
   // blink the error LED
   leds_error_blink();
   // reset the board
   board_reset();
   
   return 0;// this line is never reached, but here to satisfy compiler
}
Esempio n. 12
0
int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
	/* Call the board specific reset actions first. */
	if(board_reset) {
		board_reset();
	}

	mbar_writeByte(MCF_RCM_RCR,
		       MCF_RCM_RCR_SOFTRST | MCF_RCM_RCR_FRCRSTOUT);
	return 0;
};
Esempio n. 13
0
File: game.c Progetto: Egomeh/BA2015
/**
 * @brief Resets the game and starts a new one.
 *
 * If you have many games to play, you should call this function
 * once a game is over, instead of allocating a new one.
 *
 * @param game the game to reset
 */
void game_reset(Game *game) {
  board_reset(game->board);
  game->game_over = 0;
  game->score = 0;
  game->current_piece_sequence_index = -1;
  game->last_move_info.removed_lines = 0;
  game->last_move_info.landing_height_bottom = 0;
  game->last_move_info.eliminated_bricks_in_last_piece = 0;
  game->last_move_info.oriented_piece = NULL;
  generate_next_piece(game);
}
Esempio n. 14
0
static void pmic_write_reg(unsigned bus, uint8_t reg, uint8_t val, int do_delay)
{
	if (i2c_writeb(bus, AS3722_I2C_ADDR, reg, val)) {
		printk(BIOS_ERR, "%s: reg = 0x%02X, value = 0x%02X failed!\n",
			__func__, reg, val);
		/* Reset the SoC on any PMIC write error */
		board_reset();
	} else {
		if (do_delay)
			udelay(500);
	}
}
Esempio n. 15
0
void test_board_attacks_to() {
    puts("test_board_attacks_to");

    struct board pos;
    board_reset(&pos);
    uint64_t attacks = board_attacks_to(&pos, SQ_F6);
    assert(attacks == (BB_G8 | BB_E7 | BB_G7));

    assert(board_set_fen(&pos, "r1bqk2r/pppp1Bpp/2n2n2/2b1p1N1/4P3/8/PPPP1PPP/RNBQK2R b KQkq - 0 5"));
    attacks = board_attacks_to(&pos, SQ_E8);
    assert(attacks & BB_F7);
}
Esempio n. 16
0
void test_board_checkers() {
    puts("test_board_checkers");

    struct board pos;
    board_reset(&pos);
    assert(!board_checkers(&pos, pos.turn));

    assert(board_set_fen(&pos, "r1bqk2r/pppp1Bpp/2n2n2/2b1p1N1/4P3/8/PPPP1PPP/RNBQK2R b KQkq - 0 5"));
    assert(pos.turn == false);
    uint64_t checkers = board_checkers(&pos, pos.turn);
    assert(checkers == BB_F7);
}
Esempio n. 17
0
void test_board_zobrist_hash() {
    puts("test_board_zobrist_hash");
    board_t pos;

    board_reset(&pos);
    assert(board_zobrist_hash(&pos, POLYGLOT) == 0x463b96181691fc9cULL);

    assert(board_set_fen(&pos, "rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq - 0 1"));
    assert(board_zobrist_hash(&pos, POLYGLOT) == 0x823c9b50fd114196ULL);

    assert(board_set_fen(&pos, "rnbqkbnr/ppp1p1pp/8/3pPp2/8/8/PPPPKPPP/RNBQ1BNR b kq - 1 3"));
    assert(board_zobrist_hash(&pos, POLYGLOT) == 0x652a607ca3f242c1ULL);
}
Esempio n. 18
0
void uif_cmd_dn (int argc, char **argv)
{
    int ret;
    FLASH->KEYR = 0x45670123;
    FLASH->KEYR = 0xCDEF89AB;
    USART_ITConfig(USART1, USART_IT_RXNE, DISABLE);
    ret = Ymodem_receive(ApplicationAddress, IMAGE_SIZE);
    if (ret > 0)
    {
        //FLASH_ProgramWord(0x800FFFC, 0xAA55AA55);
        mdelay(100);
        board_reset();
    }
    USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
}
Esempio n. 19
0
void reset_cpu(ulong ignored)
{
    at91_st_t *st = (at91_st_t *) ATMEL_BASE_ST;

    board_reset();

    /* Reset the cpu by setting up the watchdog timer */
    writel(AT91_ST_WDMR_RSTEN | AT91_ST_WDMR_EXTEN | AT91_ST_WDMR_WDV(2),
           &st->wdmr);
    writel(AT91_ST_CR_WDRST, &st->cr);
    /* and let it timeout */
    while (1)
        ;
    /* Never reached */
}
Esempio n. 20
0
void
do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
	volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
	volatile ccsr_gur_t *gur = &immap->im_gur;

	/* Attempt board-specific reset */
	board_reset();

	/* Next try asserting HRESET_REQ */
	out_be32(&gur->rstcr, MPC86xx_RSTCR_HRST_REQ);

	while (1)
		;
}
Esempio n. 21
0
void test_board_shredder_fen() {
    puts("test_board_shredder_fen");

    struct board pos;
    char fen[255];

    board_reset(&pos);
    board_shredder_fen(&pos, fen);
    assert(strcmp(fen, "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w HAha - 0 1") == 0);

    board_clear(&pos);
    board_set_piece_at(&pos, SQ_D1, kQueen, kWhite);
    board_set_piece_at(&pos, SQ_D8, kQueen, kBlack);
    board_shredder_fen(&pos, fen);
    assert(strcmp(fen, "3q4/8/8/8/8/8/8/3Q4 w - - 0 1") == 0);
}
Esempio n. 22
0
void perft(int depth) {
    Bitmap ms, ds;
    Bitmap rs;

    ms = get_ms();
    board_reset();
    movegen();
    rs = xperft(depth);
    ds = get_ms() - ms;

    printf("Total:%lu ", (long unsigned int) rs);
    if( ds ) {
        printf( " (%lu positions/second)", (long unsigned int) (rs * 1000 / ds));
    }
    printf( "\n");

}
Esempio n. 23
0
int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
#if defined(CONFIG_BOARD_RESET)
	board_reset();
#else
#if defined(CFG_4xx_RESET_TYPE)
	mtspr(dbcr0, CFG_4xx_RESET_TYPE << 28);
#else
	/*
	 * Initiate system reset in debug control register DBCR
	 */
	mtspr(dbcr0, 0x30000000);
#endif /* defined(CFG_4xx_RESET_TYPE) */
#endif /* defined(CONFIG_BOARD_RESET) */

	return 1;
}
Esempio n. 24
0
void test_board_parse_san() {
    puts("test_board_parse_san");
    board_t pos;
    move_t move;

    board_reset(&pos);
    assert(board_parse_san(&pos, "e4", &move));
    assert(move == move_make(SQ_E2, SQ_E4, 0));

    assert(board_set_fen(&pos, "r1bqkb1r/pppp1ppp/2n2n2/4p3/2B1P3/2N2N2/PPPP1PPP/R1BQK2R b KQkq - 5 4"));
    assert(board_parse_san(&pos, "Nxe4", &move));
    assert(move == move_make(SQ_F6, SQ_E4, 0));

    assert(board_set_fen(&pos, "r3r2R/pppb1kP1/n2p4/3Pp3/2P1P3/2N1K3/PP3P2/6R1 w - - 3 23"));
    assert(board_parse_san(&pos, "g8=Q+", &move));
    assert(move == move_make(SQ_G7, SQ_G8, kQueen));
}
Esempio n. 25
0
void test_initial_legal_moves() {
    puts("test_initial_legal_moves");

    board_t pos;
    board_reset(&pos);

    move_t moves[255];
    move_t *end = board_legal_moves(&pos, moves, BB_ALL, BB_ALL);
    for (move_t *current = moves; current < end; current++) {
        char san[LEN_SAN], uci[LEN_UCI];
        move_uci(*current, uci);
        board_san(&pos, *current, san);
        printf("- %s %s\n", uci, san);
    }

    assert(end - moves == 20);
}
Esempio n. 26
0
void test_board_attacks_from() {
    puts("test_board_attacks_from");

    uint64_t attacks;
    struct board pos;
    board_reset(&pos);

    attacks = board_attacks_from(&pos, SQ_B1);
    assert(attacks == (BB_A3 | BB_C3 | BB_D2));

    attacks = board_attacks_from(&pos, SQ_D1);
    assert(attacks == (BB_C1 | BB_C2 | BB_D2 | BB_E2 | BB_E1));

    assert(board_set_fen(&pos, "r1bqkbnr/1ppp1ppp/p1n5/1B2p3/4P3/5N2/PPPP1PPP/RNBQK2R w KQkq - 0 4"));
    attacks = board_attacks_from(&pos, SQ_H1);
    bb_print(attacks);
    assert(attacks == (BB_E1 | BB_F1 | BB_G1 | BB_H2));
}
Esempio n. 27
0
/*
 * main - Bootloader main entry function
 *
 * INPUT
 *     - argc: (not used)
 *     - argv: (not used)
 * OUTPUT
 *     0 when complete
 */
int main(int argc, char *argv[])
{
    (void)argc;
    (void)argv;

    clock_init();
    bootloader_init();

#if !defined(DEBUG_ON) && (MEMORY_PROTECT == 0)
#error "To compile release version, please set MEMORY_PROTECT flag"
#elif !defined(DEBUG_ON)
    /* Checks and sets memory protection */
    memory_protect();
#elif (MEMORY_PROTECT == 1)
#error "Can only compile release versions with MEMORY_PROTECT flag"
#endif

    /* Initialize stack guard with random value (-fstack_protector_all) */
    __stack_chk_guard = random32();

    led_func(SET_GREEN_LED);
    led_func(SET_RED_LED);

    dbg_print("\n\rKeepKey LLC, Copyright (C) 2015\n\r");
    dbg_print("BootLoader Version %d.%d.%d\n\r", BOOTLOADER_MAJOR_VERSION,
              BOOTLOADER_MINOR_VERSION, BOOTLOADER_PATCH_VERSION);

    if(is_fw_update_mode())
    {
        update_fw();
    }
    else
    {
        boot();
    }

#if DEBUG_LINK
    board_reset();
#else
    system_halt(); /* Loops forever */
#endif

    return(0); /* Should never get here */
}
Esempio n. 28
0
int parse_pgn(Board *board, const char *pgn) {
    board_reset(board);
    char *temp = calloc(strlen(pgn) + 1, sizeof(char));
    strcpy(temp, pgn);
    char *key;
    char *token = tokenize(temp, " ", &key);
    while (token) {
        Move move;
        if (parse_move(board, token, &move)) {
            make_move(board, &move);
        }
        else {
            return 0;
        }
        token = tokenize(NULL, " ", &key);
    }
    free(temp);
    return 1;
}
Esempio n. 29
0
 void scheduler_push_task(OpenMote* self, task_cbt cb, task_prio_t prio) {
   taskList_item_t*  taskContainer;
   taskList_item_t** taskListWalker;
   INTERRUPT_DECLARATION();
   
   DISABLE_INTERRUPTS();
   
   // find an empty task container
   taskContainer = &(self->scheduler_vars).taskBuf[0];
   while (taskContainer->cb!=NULL &&
          taskContainer<=&(self->scheduler_vars).taskBuf[TASK_LIST_DEPTH-1]) {
      taskContainer++;
   }
   if (taskContainer>&(self->scheduler_vars).taskBuf[TASK_LIST_DEPTH-1]) {
      // task list has overflown. This should never happpen!
   
      // we can not print from within the kernel. Instead:
      // blink the error LED
 leds_error_blink(self);
      // reset the board
 board_reset(self);
   }
   // fill that task container with this task
   taskContainer->cb              = cb;
   taskContainer->prio            = prio;
   
   // find position in queue
   taskListWalker                 = &(self->scheduler_vars).task_list;
   while (*taskListWalker!=NULL &&
          (*taskListWalker)->prio < taskContainer->prio) {
      taskListWalker              = (taskList_item_t**)&((*taskListWalker)->next);
   }
   // insert at that position
   taskContainer->next            = *taskListWalker;
   *taskListWalker                = taskContainer;
   // maintain debug stats
   (self->scheduler_dbg).numTasksCur++;
   if ((self->scheduler_dbg).numTasksCur>(self->scheduler_dbg).numTasksMax) {
      (self->scheduler_dbg).numTasksMax   = (self->scheduler_dbg).numTasksCur;
   }
   
   ENABLE_INTERRUPTS();
}
Esempio n. 30
0
/**
\brief The program starts executing here.
*/
int mote_main(void) {
   
   board_init();
   leds_error_on();
   
   debugpins_frame_set();    some_delay();
   debugpins_frame_toggle(); some_delay();
   debugpins_frame_toggle(); some_delay();
   debugpins_frame_clr();    some_delay();
   
   debugpins_slot_set();     some_delay();
   debugpins_slot_toggle();  some_delay();
   debugpins_slot_toggle();  some_delay();
   debugpins_slot_clr();     some_delay();
   
   debugpins_fsm_set();      some_delay();
   debugpins_fsm_toggle();   some_delay();
   debugpins_fsm_toggle();   some_delay();
   debugpins_fsm_clr();      some_delay();
   
   debugpins_task_set();     some_delay();
   debugpins_task_toggle();  some_delay();
   debugpins_task_toggle();  some_delay();
   debugpins_task_clr();     some_delay();
   
   debugpins_isr_set();      some_delay();
   debugpins_isr_toggle();   some_delay();
   debugpins_isr_toggle();   some_delay();
   debugpins_isr_clr();      some_delay();
   
   debugpins_radio_set();    some_delay();
   debugpins_radio_toggle(); some_delay();
   debugpins_radio_toggle(); some_delay();
   debugpins_radio_clr();    some_delay();
   
   board_reset();
   
   return 0;
}