コード例 #1
0
/**************************************************************************************************
 * @fn          main
 *
 * @brief       Start of application.
 *
 * @param       none
 *
 * @return      none
 **************************************************************************************************
 */
int main(void)
{
  /* Initialize hardware */
  HAL_BOARD_INIT();

  /* Initialze the HAL driver */
  HalDriverInit();

  /* Initialize MAC */
  MAC_Init();

  /* Initialize the operating system */
  osal_init_system();

  /* Enable interrupts */
  HAL_ENABLE_INTERRUPTS();

  /* Setup OSAL Timer */
  HalTimerConfig ( OSAL_TIMER,                         // 16bit timer3
                   HAL_TIMER_MODE_CTC,                 // Clear Timer on Compare
                   HAL_TIMER_CHANNEL_SINGLE,           // Channel 1 - default
                   HAL_TIMER_CH_MODE_OUTPUT_COMPARE,   // Output Compare mode
                   FALSE,                              // Use interrupt
                   MSA_Main_TimerCallBack);            // Channel Mode

  /* Setup Keyboard callback */
  HalKeyConfig(MSA_KEY_INT_ENABLED, MSA_Main_KeyCallback);

  /* Initialize UART */
  UartCnfg.baudRate = HAL_UART_BR_9600;
  UartCnfg.callBackFunc = HalUARTCBack;
  UartCnfg.flowControl = FALSE;
  UartCnfg.flowControlThreshold = 0;  /* max Buffer Size in Byte*/
  UartCnfg.idleTimeout = 200;

  /*
   * halUARTOpen provvederà tramite la funzione halUartAllocBuffers ad allocare e inizializzare
   * le strutture dati RxUART e TxUART.
   */

  UartCnfg.rx = RxUART;
  UartCnfg.tx = TxUART;
  UartCnfg.rx.maxBufSize = UART_MAX_BUFFER_SIZE;
  UartCnfg.tx.maxBufSize = UART_MAX_BUFFER_SIZE;
  UartCnfg.intEnable = TRUE ;  /* enable or disable the interrupts */
  UartCnfg.configured = TRUE;

  uint8 status = HalUARTOpen(HAL_UART_PORT, &UartCnfg); /* passo l'indirizzo di memoria della struttura dati
  	  	  	  	  	  	  	  	  	  	  UartCnfg, Passaggio per riferimento!!!*/




  /* Start OSAL */
  osal_start_system(); // No Return from here

  return 0;
}
コード例 #2
0
static void initTimer3() {
	if (isInitTimer3 == 0) {
		GPIO_LedsInit();
		HalTimerInit();
		HalTimerConfig(HAL_TIMER_0, HAL_TIMER_MODE_CTC, HAL_TIMER_CHANNEL_SINGLE, HAL_TIMER_CH_MODE_OUTPUT_COMPARE, TRUE, showsomething);
		isInitTimer3 = 1;
	}
	count = 0;
	flag = 0;
	IRLED = 0;
}
コード例 #3
0
ファイル: M160.c プロジェクト: KimiRaikking/z-stack
//-------------------------------------------------------------------
// GLOBAL FUNCTIONS
//-------------------------------------------------------------------
//-------------------------------------------------------------------
// @fn      M160_Init
// @brief    Set up timer 4 to generate an interrupt 1 kHz for PWM
// @return  none
//-------------------------------------------------------------------
void M160_Init(void)
{
    HAL_DO_OUTPUT();

    // Set prescaler divider value to 128 (8KHz)
    /*
    X_T4CTL |= 0x80;

    X_T4CTL &= ~(0x10); // Stop timer
    T4IE = 0; // Disable interrupt
    */
    uint8 status =
    HalTimerConfig(HAL_TIMER_0,
                   HAL_TIMER_MODE_CTC,
                   HAL_TIMER_CHANNEL_SINGLE,
                   HAL_TIMER_CH_MODE_OUTPUT_COMPARE,
                   1,
                   M160_Timer_Call_Back);
    HalTimerStart(HAL_TIMER_0,100);
}
コード例 #4
0
/*********************************************************************
 * @fn      SampleApp_Init
 *
 * @brief   Initialization function for the Generic App Task.
 *          This is called during initialization and should contain
 *          any application specific initialization (ie. hardware
 *          initialization/setup, table initialization, power up
 *          notificaiton ... ).
 *
 * @param   task_id - the ID assigned by OSAL.  This ID should be
 *                    used to send messages and set timers.
 *
 * @return  none
 */
void SampleApp_Init( uint8 task_id )
{
  SampleApp_TaskID = task_id; 
  SampleApp_NwkState = DEV_INIT;
  SampleApp_TransID = 0;
  MT_UartInit();//串口初始化
  MT_UartRegisterTaskID(task_id);//登记任务号
    
  
#ifdef MODE_ED //终端节点下才配置
/**************超声波***************/  
  
#define trig P0_1
#define echo P0_0

  P0DIR |= 0x02;		//P01输出trig
  P0DIR &= ~0x01;		//P00输入echo	
  trig=0;
  /*定时器配置*/ 


  HalTimerInit();
  HalTimerConfig(HAL_TIMER_0,
                 HAL_TIMER_MODE_CTC,
                 HAL_TIMER_CHANNEL_SINGLE,
                 HAL_TIMER_CH_MODE_OUTPUT_COMPARE,
                 TRUE,
                 timer_callback);
  /***********步进电机**************/
#define in1 P0_4
#define in2 P0_5
#define in3 P0_6
#define in4 P0_7  
  P0SEL &=~0xf0;
  P0DIR |= 0xf0;
  P0INP &=~0Xf0; //打开上拉

  in1=0;
  in2=0;
  in3=0;
  in4=0;
  /*测试*/
  int i=0;
  for(i=0;i<128;i++)
  {
    MotorCW();
  }

  for(i=0;i<128;i++)
  {
    MotorCCW();
  }        
  HalLedBlink( HAL_LED_2, 2,50, 500);

#endif
  // Device hardware initialization can be added here or in main() (Zmain.c).
  // If the hardware is application specific - add it here.
  // If the hardware is other parts of the device add it in main().

 #if defined ( BUILD_ALL_DEVICES )
  // The "Demo" target is setup to have BUILD_ALL_DEVICES and HOLD_AUTO_START
  // We are looking at a jumper (defined in SampleAppHw.c) to be jumpered
  // together - if they are - we will start up a coordinator. Otherwise,
  // the device will start as a router.
  if ( readCoordinatorJumper() )
    zgDeviceLogicalType = ZG_DEVICETYPE_COORDINATOR;
  else
    zgDeviceLogicalType = ZG_DEVICETYPE_ROUTER;
#endif // BUILD_ALL_DEVICES

#if defined ( HOLD_AUTO_START )
  // HOLD_AUTO_START is a compile option that will surpress ZDApp
  //  from starting the device and wait for the application to
  //  start the device.
  ZDOInitDevice(0);
#endif

  // Setup for the periodic message's destination address
  // Broadcast to everyone
  SampleApp_Periodic_DstAddr.addrMode = (afAddrMode_t)AddrBroadcast;
  SampleApp_Periodic_DstAddr.endPoint = SAMPLEAPP_ENDPOINT;
  SampleApp_Periodic_DstAddr.addr.shortAddr = 0xFFFF;

  // Setup for the flash command's destination address - Group 1
  SampleApp_Flash_DstAddr.addrMode = (afAddrMode_t)afAddrGroup;
  SampleApp_Flash_DstAddr.endPoint = SAMPLEAPP_ENDPOINT;
  SampleApp_Flash_DstAddr.addr.shortAddr = SAMPLEAPP_FLASH_GROUP;
  
  // 网蜂点对点通讯定义
    Point_To_Point_DstAddr.addrMode = (afAddrMode_t)Addr16Bit;//点播
    Point_To_Point_DstAddr.endPoint = SAMPLEAPP_ENDPOINT;
    Point_To_Point_DstAddr.addr.shortAddr = 0x0000; //发给协调器


  // Fill out the endpoint description.
  SampleApp_epDesc.endPoint = SAMPLEAPP_ENDPOINT;
  SampleApp_epDesc.task_id = &SampleApp_TaskID;
  SampleApp_epDesc.simpleDesc
            = (SimpleDescriptionFormat_t *)&SampleApp_SimpleDesc;
  SampleApp_epDesc.latencyReq = noLatencyReqs;

  // Register the endpoint description with the AF
  afRegister( &SampleApp_epDesc );

  // Register for all key events - This app will handle all key events
  RegisterForKeys( SampleApp_TaskID );

  // By default, all devices start out in Group 1
  SampleApp_Group.ID = 0x0001;
  osal_memcpy( SampleApp_Group.name, "Group 1", 7  );
  aps_AddGroup( SAMPLEAPP_ENDPOINT, &SampleApp_Group );

#if defined ( LCD_SUPPORTED )
  HalLcdWriteString( "SmartPark", HAL_LCD_LINE_1 );
#endif
}