Esempio n. 1
0
void clearMMCCard()
{
    if (initMMC() == MMC_SUCCESS) // card found
    {
      //card_state |= 1;
      memset(&mmc_buffer,0,512);
      mmcReadRegister (10, 16);
      mmc_buffer[7]=0;

      /*Clear first 1000 blocks*/
      int blockClearCnt;
      for (blockClearCnt = 0; blockClearCnt < 2048; blockClearCnt++)
      {
          memset(&mmc_buffer,'0',512);
          mmcWriteBlock(512 * blockClearCnt);
      }

      /*
      // Fill first Block (0) with 'A'
      memset(&mmc_buffer,'0',512);    //set breakpoint and trace mmc_buffer contents
      mmcWriteBlock(0);
      // Fill second Block (1)-AbsAddr 512 with 'B'
      memset(&mmc_buffer,'1',512);
      mmcWriteBlock(512);

      // Read first Block back to buffer
      memset(&mmc_buffer,0x00,512);
      mmcReadBlock(0,512);

      // Read first Block back to buffer
      memset(&mmc_buffer,0x00,512);
      mmcReadBlock(512,512);
      */
    }
}
Esempio n. 2
0
//--------------- set blocklength 2^n ------------------------------------------------------
char mmcSetBlockLength (const unsigned long blocklength)
{
  //  char rValue = MMC_TIMEOUT_ERROR;
  //  char i = 0;
  // SS = LOW (on)
  CS_LOW ();
  // Set the block length to read
  //MMC_SET_BLOCKLEN =CMD16
  mmcSendCmd(MMC_SET_BLOCKLEN, blocklength, 0xFF);

  // get response from MMC - make sure that its 0x00 (R1 ok response format)
  if(mmcGetResponse()!=0x00)
  { initMMC();
    mmcSendCmd(MMC_SET_BLOCKLEN, blocklength, 0xFF);
    mmcGetResponse();
  }

  CS_HIGH ();

  // Send 8 Clock pulses of delay.
  spiSendByte(0xff);

  return MMC_SUCCESS;
} // Set block_length
Esempio n. 3
0
main(){
  int events=10; // number of events to generate
  int n, i;

  char *options[]={
    "-seed=1 -user -sdec -raw -rw=0",
    "-seed=1 -user -Emu=1.e7 -Enm=1.e6 -Ene=1.e6 -sdec -raw",
    "-seed=1 -user -sdec -raw -prop"
  };

  double r, z1=0, z2=0, h1=0, h2=0, nx=0, ny=0, nz=0, e1=0, e2=0, ec=0;

  initJre();

  // setStderr("mmc.log");
  printf("\nRunning %s\n", "tfa/Amanda (1)");
  initMMC(options[0], 1);

  for(n=0; n<events; n++){
    printf("Event %i\n", n);
    setStart(1);
    name="mu-";
    x=1;    // [m]
    y=2;    // [m]
    z=1000; // [m]
    theta=0;
    phi=0;
    e=2000; // [GeV]
    t=0;    // [s]
    propagate(name, x*1.e2, y*1.e2, z*1.e2, 180-theta, phi<180?phi+180:phi-180, e*1.e3, t);

    resultsOut();

    r=getDouble("r", 1);
    e=getDouble("e", 1);
    z1=getDouble("z1", 2);
    z2=getDouble("z2", 2);
    h1=getDouble("h1", 2);
    h2=getDouble("h2", 2);
    nx=getDouble("nx", 2);
    ny=getDouble("ny", 2);
    nz=getDouble("nz", 2);
    e1=getDouble("e1", 2);
    e2=getDouble("e2", 2);
    ec=getDouble("ec", 2);

    r*=1.e-2; e*=1.e-3;
    printf("%g %g %g %g %g %g %g %g %g %g %g %g\n", r, e, z1, z2, h1, h2, nx, ny, nz, e1, e2, ec);
    setStart(0);
    printf("EVENT WEIGHT = %g at %g\n", getDouble("fw", 2), getDouble("hw", 2));
    endProp();
  }
  deleteMMC();

  printf("\nRunning %s\n", "gen/AtmFlux (2)");
  initMMC(options[1], 2);
  for(n=0; n<events; n++){
    createNext();
    resultsOut();
    endProp();
  }
  deleteMMC();

  printf("\nRunning %s\n", "gen/AtmFlux (3)");
  initMMC(options[2], 3);
  for(n=0; n<events; n++){
    printf("Event %i\n", n);

    name="nu_tau";
    x=1;    // [m]
    y=2;    // [m]
    z=-5e6; // [m]
    theta=180;
    phi=0;
    e=1.e8; // [GeV]
    t=0;    // [s]
    propagate(name, x*1.e2, y*1.e2, z*1.e2, 180-theta, phi<180?phi+180:phi-180, e*1.e3, t);

    resultsOut();
    endProp();
  }
  deleteMMC();

  stopJre();
}
Esempio n. 4
0
//*--------------------------------------------------------------------------------------
//* Function Name       : Main
//* Object              : Software entry point
//* Input Parameters    : none.
//* Output Parameters   : none.
//*--------------------------------------------------------------------------------------
int main(void)
{
    char data[MSG_SIZE];
    unsigned int length;
    int stepCnt = 0;
    unsigned char str[10];

    /**** System init ****/
    //InitFrec();
    Init_CP_WP();
    //chek for CP and WP
    //CP - card present
    while(((AT91C_BASE_PIOA->PIO_PDSR) & BIT15)) { /*put your card present event here*/  }
    //WP - write protect
    //while(((AT91C_BASE_PIOA->PIO_PDSR) & BIT16)) { /*put your write protect event here*/ }

    if (initMMC() == MMC_SUCCESS)
    {
        //card_state |= 1;
        memset(&mmc_buffer,0,512);
        mmcReadRegister (10, 16);
        mmc_buffer[7]=0;
    }


    flashInit();

    Init_PWM();

    // Enable User Reset and set its minimal assertion to 960 us
    AT91C_BASE_RSTC->RSTC_RMR = AT91C_RSTC_URSTEN | (0x4<<8) | (unsigned int)(0xA5<<24);
    // Led init
    // First, enable the clock of the PIOB
    AT91F_PMC_EnablePeriphClock ( AT91C_BASE_PMC, 1 << AT91C_ID_PIOA ) ;
    //* to be outputs. No need to set these pins to be driven by the PIO because it is GPIO pins only.
    AT91F_PIO_CfgOutput( AT91C_BASE_PIOA, OUTPUT_MASK );
    //* Clear the LED's.
    /*
    AT91F_PIO_SetOutput( AT91C_BASE_PIOA, OUTPUT_MASK );
    AT91F_PIO_ClearOutput( AT91C_BASE_PIOA, OUTPUT_MASK );
    */


    // Init USB device
    AT91F_USB_Open();
    AT91F_PIO_ClearOutput( AT91C_BASE_PIOA, OUTPUT_MASK );
    // Init USB device
    // Wait for the end of enumeration
    setForce(40000);
    int pCDCEnablingCounter = 0;
    while (!pCDC.IsConfigured(&pCDC) && pCDCEnablingCounter < 2500000){ pCDCEnablingCounter++; };

    if (pCDCEnablingCounter < 2500000)
    {
        CDC = 1;
    }

    setForce(0);

    // Set Usart in interrupt
    //Usart_init();

    //Read and set settings
    memcpy(settings, OUR_FLASH_ADDR, 128);
    int i;memset(&mmc_buffer, 0x00, 512);
    int j;
    char *settingsBlocks[50];
    char settingsDelim[] = "~";
    char *settingsParts = strtok( settings, settingsDelim );
    i = 0;
    while( settingsParts != NULL )
    {
      settingsBlocks[i++] = settingsParts;
      settingsParts = strtok( NULL, settingsDelim );
    }
    for (j = 0; j < i; j++)
    {
       parseSettings(settingsBlocks[j]);
    }

    InitADC();

    Init_PWM();

    AT91F_PIO_CfgInput(AT91C_BASE_PIOA, SW1_MASK);
    AT91F_PIO_CfgInput(AT91C_BASE_PIOA, SW2_MASK);

    AT91F_PIO_SetOutput( AT91C_BASE_PIOA, LED_GREEN);
    AT91F_PIO_SetOutput( AT91C_BASE_PIOA, LED_YELLOW);
    setForce(0);

    //startBlinking(250000);

    /**** MMC CARD ****/

    init_extint();


    while (1)
    {
        cnt++;
        if (cnt > 50000)
        {
            cnt = 0;
            printTrace("COUNTER RESET\n");
        }
    }
}
Esempio n. 5
0
void    event_handler( event_type_t event_type, unidata_t   unidata ) 
{
   char str[32];
   unsigned char ch;
   static int err;
   
   switch(event_type)
   {
   case KBRD_EVT:
//      ltoa((int32_t)unidata, str, 10);
//      OLED_puts(0, 41, 0xff, font6x9, str);
     
      if(kbrd_pressed)
      {
         kbrd_pressed = 0;
         //display_node(kbrd_getch());
         ch = kbrd_getch();
         /*
      itoa((int16_t)ch, str, 16);
      OLED_clr(0, 41, 3 * 6, 9);
      OLED_puts(0, 41, 0xff, font6x9, str);
         */
         if(!(ch & 0x80))
         {
            ch = active.menu->action(ch);
            active.menu->display(ch);
            update_statusbar();
         }
         /*
         switch((ch = kbrd_getch()))
         {
         case 1:
         case 129:
            display(0, 0);
            break;
         case 16:
         case 144:
            display(1, 0);
            break;
         case 14:
            if((scroll_pos < (MSG_TABLE_SIZE - MSG_VIEW_SIZE)) && (scroll_pos < msg_count - 1))
            {
               scroll_pos ++;
               event_emit(LOW_PRIORITY, DISPLAY_EVT, 2);
            }
         case 142:
            break;
         case 13:
            if(scroll_pos)
            {
               scroll_pos--;
               event_emit(LOW_PRIORITY, DISPLAY_EVT, 2);
            }
         case 141:
            break;
         case 11:
            OLED_cls();
            err = initConfig();
            //sprintf(str, "initConfig res: %d", err);
            //OLED_puts(0, 0, 0xff, font6x9, str);
            OLED_puts(0, 0, 0xff, font6x9, (err ? "initConfig failed" : "initConfig success"));
            break;
         case 134:
            {
               struct LogEntry entry;
               
               err = STRG_SUCCESS;
               entry.timestamp  = 0;
               err += logAddEntry(&entry, "Msg 0");
               entry.timestamp  = 1000;
               err += logAddEntry(&entry, "Msg 1");
               entry.timestamp  = 2000;
               err += logAddEntry(&entry, "Msg 2");
               sprintf(str, "Error code: %d", err);
               OLED_puts(0, 2*9, 0xff, font6x9, str);
            }
            break;
         default:
            display(2, ch);
            break; // display(0, 0);
         }
         */
         
         /*
         OLED_puts(64 + 12, 41, 0xff, font6x9, "Key pressed ");
         itoa(kbrd_getch(), str, 10);
         OLED_puts(64 + 12 + sizeof("Key pressed ") * 6, 41, 0xff, font6x9, str);
         OLED_puts(64 + 12 + sizeof("Key pressed ") * 6 + strlen(str) * 6, 41, 0xff, font6x9, "   ");
         */
      }
      /*
      else
         OLED_puts(0, 41, 0xff, font6x9, "Key not pressed");
         */
      break;

   case INIT_EVT:
      //OLED_init();
      //init_kbrd();
      SPI_init();
      event_emit(LOW_PRIORITY, INIT_MMC_EVT, 0);
      break;

   case INIT_MMC_EVT:
      initMMC();
      err = initStorage();
      event_emit(LOW_PRIORITY, INIT_OLED_EVT, 0);
      break;

   case INIT_OLED_EVT:
      OLED_init();
      OLED_puts(0, 0 , 0xff, font6x9, "System initialization...");
      OLED_puts(0, 1 * 9 , 0xff, font6x9, "SPI     init'ed.");
      OLED_puts(0, 2 * 9 , 0xff, font6x9, "MMC     init'ed.");
      OLED_puts(0, 3 * 9 , 0xff, font6x9, "OLED    init'ed.");
      event_emit(LOW_PRIORITY, INIT_STORAGE_EVT, 0);
      break;

   case INIT_STORAGE_EVT:
      //err = initStorage();
      //OLED_puts(0, 4 * 9 , 0xff, font6x9, err ? "Storage init failed!" : "Storage init'ed.");
      format_str(str, 32, "Storage err: %d", err);
      OLED_puts(0, 4 * 9 , 0xff, font6x9, err ? str : "Storage init'ed.");
      /*
      format_str(str, 32, "ZoneCfg pos: %u", syscfg.zone_cfg_addr);
      OLED_puts(0, 5 * 9 , 0xff, font6x9, str);
      err = 1;
      */
      event_emit(LOW_PRIORITY, INIT_USER_IO_EVT, 0);
      break;

   case INIT_USER_IO_EVT:
      init_kbrd();
      menu_init(err ? MNU_INIT | MNU_DO_NOT_SHOW : MNU_INIT);
      //set_sys_time((uint64_t)20000);
      stimer_set(1, 1000);
      break;
   }
       /*
   else if(event_type == INIT_SEND_MSGS_EVT)
   {
       msg_t msg;
       struct msginfo minfo;

       uint16_t addr_attr = 0x0000;
       uint8_t  port_attr = PORT;

       //attr_write(0x02, &addr_attr);
       //attr_write(0x07, &port_attr);

       // This must be the code for us to say ZigZag (Node Dispatcher)
       // that we are interested in listening for messages and events
       msg = msg_new(0x00, 0x00, 0x01, 3, MFLAG_DEFAULT);
       if(msg < 0)
          OLED_puts(0, 0, 0xff, font6x9, "Error: msg_new");
       if(msg_info(msg, &minfo) != ENOERR)
          OLED_puts(0, 9, 0xff, font6x9, "Error: msg_info");
       ((unsigned char *)minfo.body_ptr)[0] = 0x02;
       ((unsigned char *)minfo.body_ptr)[1] = 0x00;
       ((unsigned char *)minfo.body_ptr)[2] = 0x00;
       if(msg_send(msg) != ENOERR)
          OLED_puts(0, 18, 0xff, font6x9, "Error: msg_send (1)");
       msg = msg_new(0x00, 0x00, 0x01, 2, MFLAG_DEFAULT);
       if(msg < 0)
          OLED_puts(0, 0, 0xff, font6x9, "Error: msg_new");
       if(msg_info(msg, &minfo) != ENOERR)
          OLED_puts(0, 9, 0xff, font6x9, "Error: msg_info");
       ((unsigned char *)minfo.body_ptr)[0] = 0x07;
       ((unsigned char *)minfo.body_ptr)[1] = (uint8_t)PORT;
//       ((unsigned char *)minfo.body_ptr)[2] = (uint8_t)(PORT >> 8);
       if(msg_send(msg) != ENOERR)
          OLED_puts(0, 18, 0xff, font6x9, "Error: msg_send (2)");
   }
          */
   /*
   else
   {
      //sprintf(str, "Evt: %u", (uint16_t)event_type);
      //OLED_puts(0, 0, 0xff, font6x9, str);
   }
   */
}