Ejemplo n.º 1
0
/****************************************************
 *  user_init()
 ****************************************************
 */
void user_init(void) {

  // Call the hardware-provided routines to print the
  // HELLO_MSG to the screen.  Must use this call because
  // the ESOS communications subsystems is not yet fully
  // initialized, since this call is in user_init()
  //
  // In general, users should call hardware-specific
  // function like this.
  __esos_unsafe_PutString( HELLO_MSG );

#ifdef __linux
  // register our little ESOS task to mimic MCU's TIMER T1 IRQ which kicks off
  // the ESOS S/W timers when they expire
  esos_RegisterTask( __simulated_isr );
#endif

  // configure our hardware to support to support our application
  CONFIG_LED1();
  esos_pic24_configI2C1(400);            //configure I2C for 400 KHz

  ESOS_INIT_SEMAPHORE(sem_ds1631Ready, 0);
  ESOS_INIT_SEMAPHORE(sem_dataReady, 0);
  ESOS_INIT_SEMAPHORE(sem_dataPrinted, 0);

  // user_init() should register at least one user task
  esos_RegisterTask(start_ds1631);
  esos_RegisterTask(listenForCommand);

  // register our callback function with ESOS to create a software timer
  esos_RegisterTimer( swTimerLED, 250);

} // end user_init()
void user_init(void) {
  esos_init_menu(); // initilize the menu, LCD and UI
  configECAN1(); // init can
  CHANGE_MODE_ECAN1(ECAN_MODE_NORMAL); // setup the CAN
  esos_pic24_configI2C1(400); // setup the I2C
  // used for my own curiosity for the SPI transmission
  CONFIG_RD2_AS_DIG_OUTPUT();
  _LATD2 = 1;
  u16_position = 0; // initial values
  u8_dutyCount = 0; // initial values
  u16_positionDACB = 0; // initial values
  u8_dutyCountDACB = 0; // initial values
  b_CANINUSE = 0;
  esos_create_menu(8); // setup the menu
  // see the .h file for details
  esos_insert_menu_title(TEAM, SET, SV3C, "team", '0');
  esos_insert_menu_title(WAVEFORM, SET, SV3C, "wvform", '0');
  esos_insert_menu_title(FREQ, SET, SVDATA, "freq", '0');
  esos_insert_menu_title(AMPLTD, SET, SVDATA, "ampltd", '0');
  esos_insert_menu_title(DUTY, SET, SVDATA, "duty", '0');
  esos_insert_menu_title(LM60, READ, NONE, "LM60", '0');
  esos_insert_menu_title(LEDSET, SET, SVDATA, "LEDs", '0');
  esos_insert_menu_title(ABOUT, STATIC, NONE, "About", '0');
  esos_setSV3C(TEAM, "APPLE  ", "CHERRY  ", "TEACHER");
  esos_setSV3C(WAVEFORM, "tri   ", "sine  ", "square ");
  esos_setSVDATA(FREQ, 64, 2047, FALSE, FALSE);
  esos_setSVDATA(AMPLTD, 0, 30, FALSE, FALSE);
  esos_setSVDATA(DUTY, 0, 100, FALSE, FALSE);
  esos_setSVDATA(LM60, 0, 100, FALSE, FALSE);
  esos_setSVDATA(LEDSET, 0, 1110, TRUE, TRUE);
  esos_setStaticInfo(ABOUT, "Developers DIGITAL FUNCTION SYNTHESIZER",
                     "James CPE Andrew EE John CPE Wyatt CPE");
  configSPI1(); // configure the spi
  configTimer2(); // configure timer 2
  configTimer3(); // configure timer 3
  esos_setSVDATAValue(DUTY, 50); // set the default duty cycle
  esos_setSVDATAValue(AMPLTD, 30); // set the default ampl
  esos_setSV3C_VALUE(TEAM, 1);
  esos_setSV3C_VALUE(WAVEFORM, 1);
  u8_currentMenuIndex = MY_ID; // initial index is set to MY_ID
  // enable the interrupts
  ESOS_REGISTER_PIC24_USER_INTERRUPT( ESOS_IRQ_PIC24_T2, ESOS_USER_IRQ_LEVEL1,
                                      _T2Interrupt);
  ESOS_ENABLE_PIC24_USER_INTERRUPT(ESOS_IRQ_PIC24_T2);
  ESOS_REGISTER_PIC24_USER_INTERRUPT( ESOS_IRQ_PIC24_T3, ESOS_USER_IRQ_LEVEL1,
                                      _T3Interrupt);
  ESOS_ENABLE_PIC24_USER_INTERRUPT(ESOS_IRQ_PIC24_T3);
  esos_RegisterTask(LEDS); // for change in LED states
  esos_RegisterTask(DACA); // for change in wave
  esos_RegisterTask(DACB); // for change in wave
  esos_RegisterTask(CAN_RX); // CAN RX
  esos_RegisterTask(CAN_TEMP_TX); // CAN TX
  esos_RegisterTask(SET_TEAM); // TEAM SETUP
  esos_RegisterTask(BUILD_LIST); // LIST
  esos_RegisterTask(UPDATE_TEMP); // UPDATES THE TEMP
} // end user_init()