Ejemplo n.º 1
0
Archivo: main.c Proyecto: IOIOI/nRF51
/**@brief Function for application main entry.
 */
int main(void)
{
    uint32_t err_code;
    bool erase_bonds;

    // Initialize.
    timers_init();
    buttons_leds_init(&erase_bonds);
    ble_stack_init();
    device_manager_init(erase_bonds);
    gap_params_init();
    advertising_init();
    services_init();
    sensor_simulator_init();
    conn_params_init();

    ble_evt_pool      = osPoolCreate(osPool(ble_evt_pool));
    ble_stack_msg_box = osMessageCreate(osMessageQ(ble_stack_msg_box), NULL);

    // Start execution.
    ble_stack_thread_id = osThreadCreate(osThread(ble_stack_thread), NULL);
    UNUSED_VARIABLE(ble_stack_thread_id);
    application_timers_start();
    err_code = ble_advertising_start(BLE_ADV_MODE_FAST);
    APP_ERROR_CHECK(err_code);

    // Enter main loop.
    for (;; )
    {
        UNUSED_VARIABLE(osDelay(1000));
    }
}
Ejemplo n.º 2
0
/**
* @brief Create and Initialize mail queue
* @param  queue_def     reference to the mail queue definition obtain with \ref osMailQ
* @param   thread_id     thread ID (obtained by \ref osThreadCreate or \ref osThreadGetId) or NULL.
* @retval mail queue ID for reference by other functions or NULL in case of error.
* @note   MUST REMAIN UNCHANGED: \b osMailCreate shall be consistent in every CMSIS-RTOS.
*/
osMailQId osMailCreate (const osMailQDef_t *queue_def, osThreadId thread_id)
{
  (void) thread_id;
  
  osPoolDef_t pool_def = {queue_def->queue_sz, queue_def->item_sz};
  
  
  /* Create a mail queue control block */
  *(queue_def->cb) = pvPortMalloc(sizeof(struct os_mailQ_cb));
  if (*(queue_def->cb) == NULL) {
    return NULL;
  }
  (*(queue_def->cb))->queue_def = queue_def;
  
  /* Create a queue in FreeRTOS */
  (*(queue_def->cb))->handle = xQueueCreate(queue_def->queue_sz, sizeof(void *));
  if ((*(queue_def->cb))->handle == NULL) {
    vPortFree(*(queue_def->cb));
    return NULL;
  }
  
  /* Create a mail pool */
  (*(queue_def->cb))->pool = osPoolCreate(&pool_def);
  if ((*(queue_def->cb))->pool == NULL) {
    //TODO: Delete queue. How to do it in FreeRTOS?
    vPortFree(*(queue_def->cb));
    return NULL;
  }
  
  return *(queue_def->cb);
}
Ejemplo n.º 3
0
/**************************************************************************//**
 * @brief
 *   Main function is a CMSIS RTOS thread in itself
 *
 * @note
 *   This example uses threads, memory pool and message queue to demonstrate the
 *   usage of these CMSIS RTOS features. In this simple example, the same
 *   functionality could more easily be achieved by doing everything in the main
 *   loop.
 *****************************************************************************/
int main(void)
{
  int count = 0;

  /* Chip errata */
  CHIP_Init();

  /* Initialize CMSIS RTOS structures */
  /* create memory pool */
  mpool = osPoolCreate(osPool(mpool));
  /* create msg queue */
  msgBox = osMessageCreate(osMessageQ(msgBox), NULL);
  /* create thread 1 */
  osThreadCreate(osThread(PrintLcdThread), NULL);

  /* Infinite loop */
  while (1)
  {
    count = (count + 1) & 0xF;

    /* Send message to PrintLcdThread */
    /* Allocate memory for the message */
    lcdText_t *mptr = osPoolAlloc(mpool);
    /* Set the message content */
    (*mptr)[0] = count >= 10 ? '1' : '0';
    (*mptr)[1] = count % 10 + '0';
    (*mptr)[2] = '\0';
    /* Send message */
    osMessagePut(msgBox, (uint32_t) mptr, osWaitForever);

    /* Wait now for half a second */
    osDelay(500);
  }
}
Ejemplo n.º 4
0
/**@brief Function for application main entry.
 */
int main(void)
{
    uint32_t err_code;
    // Initialize.
    ble_stack_init();
    timers_init();
    APP_GPIOTE_INIT(1);
    err_code = bsp_init(BSP_INIT_LED | BSP_INIT_BUTTONS, APP_TIMER_TICKS(100, APP_TIMER_PRESCALER), NULL);
    APP_ERROR_CHECK(err_code);
    device_manager_init();
    gap_params_init();
    advertising_init();
    services_init();
    sensor_simulator_init();
    conn_params_init();

    ble_evt_pool      = osPoolCreate(osPool(ble_evt_pool));
    ble_stack_msg_box = osMessageCreate(osMessageQ(ble_stack_msg_box), NULL);

    // Start execution.
    ble_stack_thread_id = osThreadCreate(osThread(ble_stack_thread), NULL);
    UNUSED_VARIABLE(ble_stack_thread_id);
    application_timers_start();
    advertising_start();

    // Enter main loop.
    for (;; )
    {
        UNUSED_VARIABLE(osDelay(1000));
    }
}
Ejemplo n.º 5
0
/*----------------------------------------------------------------------------
 *   Main:
 *---------------------------------------------------------------------------*/
int main (void) {                     /* program execution starts here       */

  mpool = osPoolCreate(osPool(mpool));  /* create memory pool                */
  MsgBox = osMessageCreate(osMessageQ(MsgBox), NULL);  /* create msg queue   */

  tid_thread1 = osThreadCreate(osThread(send_thread), NULL);
  tid_thread2 = osThreadCreate(osThread(recv_thread), NULL);

  osDelay(osWaitForever);
  for (;;);
}
Ejemplo n.º 6
0
void tskEthernetManager(void const * argument)
{
	uint8_t preLinkStatus;
	uint8_t curLinkStatus;
	int8_t ret;
	sockMutexId = osMutexCreate(osMutex(sockMutex));
	spiMutexId = osMutexCreate(osMutex(spiMutex));
	NetMemPoolId = osPoolCreate(osPool(NetMemPool));

#if NETINFO_NTP_USE
	
	osThreadDef(ntptask, tskNTP, osPriorityBelowNormal, 0, 512);
	tskNTPId = osThreadCreate(osThread(ntptask), NULL);
#endif //NETINFO_NTP_USE

	wizSystemInit();
#if WIZSYSTEM_DEBUG
	printf("TASK: Ethernet manager start.\r\n");
#endif
	while(1)
	{
		osDelay(1000);// Every sec
		curLinkStatus = isLinked();
		if(preLinkStatus != curLinkStatus)
		{
			preLinkStatus = curLinkStatus;
			if(curLinkStatus)
			{
				leaseTime = 0;
			}
			else
			{
#if WIZSYSTEM_DEBUG
				printf("Ethernet Unliked. W5500 Reinitialize.\r\n");
				wizSystemInit(); //W5500 initialize
#endif
			}
		}
		if(NetInfo.dhcp == NETINFO_DHCP && DHCPLeasedTime+leaseTime < time(NULL))
		{
			ret = DHCPTimeOut(NETINFO_DHCP_TIMEOUT);
			if(ret == DHCP_IP_LEASED)
			{
				DHCPLeasedTime = time(NULL);
				return;
			}
			else
			{
				leaseTime = 0;
			}
		}
	}
}
Ejemplo n.º 7
0
/**************************************************************************//**
 * @brief
 *   Main function is a CMSIS RTOS thread in itself
 *
 * @note
 *   This example uses threads, memory pool and message queue to demonstrate the
 *   usage of these CMSIS RTOS features. In this simple example, the same
 *   functionality could more easily be achieved by doing everything in the main
 *   loop.
 *****************************************************************************/
int main(void)
{
  int count = 0;

  /* Chip errata */
  CHIP_Init();

  /* If first word of user data page is non-zero, enable eA Profiler trace */
  BSP_TraceProfilerSetup();

#if 0
  /* Reduce power consumption by disabling part of RAM */
  /* this requires changing linker script to avoid placing */
  /* data in RAM above 32kB. Blocks 1,2,3 are turn off. */
  EMU_MemPwrDown(_EMU_MEMCTRL_POWERDOWN_BLK123);
  BURTC->POWERDOWN   |= BURTC_POWERDOWN_RAM;     /* turn BURTC RAM off */
  LESENSE->POWERDOWN |= LESENSE_POWERDOWN_RAM;   /* turn off LESENSE RAM */
#endif

  /* Initialize CMSIS RTOS structures */
  /* create memory pool */
  mpool = osPoolCreate(osPool(mpool));
  /* create msg queue */
  msgBox = osMessageCreate(osMessageQ(msgBox), NULL);
  /* create thread 1 */
  osThreadCreate(osThread(PrintLcdThread), NULL);

  /* Infinite loop */
  while (1)
  {
    count = (count + 1) & 0xF;

    /* Send message to PrintLcdThread */
    /* Allocate memory for the message */
    lcdText_t *mptr = osPoolAlloc(mpool);
    /* Set the message content */
    (*mptr)[0] = count >= 10 ? '1' : '0';
    (*mptr)[1] = count % 10 + '0';
    (*mptr)[2] = '\0';
    /* Send message */
    osMessagePut(msgBox, (uint32_t) mptr, osWaitForever);

    /* Wait now for half a second */
    osDelay(500);
  }
}
Ejemplo n.º 8
0
/**************************************************************************//**
 * @brief
 *   Main function is a CMSIS RTOS thread in itself
 *
 * @note
 *   This example uses threads, memory pool and message queue to demonstrate the
 *   usage of these CMSIS RTOS features. In this simple example, the same
 *   functionality could more easily be achieved by doing everything in the main
 *   loop.
 *****************************************************************************/
int main(void)
{
  int count = 0;

  /* Chip errata */
  CHIP_Init();

  /* If first word of user data page is non-zero, enable eA Profiler trace */
  BSP_TraceProfilerSetup();

  /* Initialize LED driver */
  BSP_LedsInit();

  /* Initialize the LCD driver */
  SegmentLCD_Init(false);

  /* Initialize CMSIS RTOS structures */
  /* create memory pool */
  mpool = osPoolCreate(osPool(mpool));
  /* create msg queue */
  msgBox = osMessageCreate(osMessageQ(msgBox), NULL);
  /* create thread 1 */
  osThreadCreate(osThread(PrintLcdThread), NULL);

  /* Infinite loop */
  while (1)
  {
    count = (count+1)&0xF;
    BSP_LedsSet(count);

    /* Send message to PrintLcdThread */
    /* Allocate memory for the message */
    lcdText_t *mptr = osPoolAlloc(mpool);
    /* Set the message content */
    (*mptr)[0] = count>=10 ? '1' : '0';
    (*mptr)[1] = count%10 + '0';
    (*mptr)[2] = '\0';
    /* Send message */
    osMessagePut(msgBox, (uint32_t)mptr, osWaitForever);

    /* Wait now for half a second */
    osDelay(500);
  }
}
Ejemplo n.º 9
0
/**
* @brief  init bt mos
* 
* @param
* @return
*
*/
void blueAPIInit(void)
{
    pBlueAPIData = osMemoryClearAllocate(RAM_TYPE_DATA_ON, sizeof(TBlueAPI_Data));

    BLUEAPI_TRACE_PRINTF_0(BLUEAPI_TRACE_MASK_TRACE, "blueAPI: init instance...");

    pBlueAPIData->plinkDescriptorTableDon = osMemoryAllocate(RAM_TYPE_DATA_ON,
        sizeof(TBlueAPI_LinkDescriptor)*otp_str_data.gEfuse_UpperStack_s.num_link_don);
    pBlueAPIData->plinkDescriptorTableDoff = osMemoryAllocate(RAM_TYPE_DATA_OFF,
        sizeof(TBlueAPI_LinkDescriptor)*otp_str_data.gEfuse_UpperStack_s.num_link_doff);

    pBlueAPIData->pMCLDescriptorTableDon = osMemoryAllocate(RAM_TYPE_DATA_ON,
        sizeof(TBlueAPI_MCL)*otp_str_data.gEfuse_UpperStack_s.num_link_don);
    pBlueAPIData->pMCLDescriptorTableDoff = osMemoryAllocate(RAM_TYPE_DATA_OFF,
        sizeof(TBlueAPI_MCL)*otp_str_data.gEfuse_UpperStack_s.num_link_doff);

    pBlueAPIData->pMDLDescriptorTableDon = osMemoryAllocate(RAM_TYPE_DATA_ON,
        sizeof(TBlueAPI_MDL)*otp_str_data.gEfuse_UpperStack_s.num_link_don);
    pBlueAPIData->pMDLDescriptorTableDoff = osMemoryAllocate(RAM_TYPE_DATA_OFF,
        sizeof(TBlueAPI_MDL)*otp_str_data.gEfuse_UpperStack_s.num_link_doff);

    osCoroutineCreate(&blueAPIQueueID, (TCoroutineEntry)blueAPIEntry,(void *)pBlueAPIData);

    osPoolCreate(&pBlueAPIData->usBlueAPIPoolID, RAM_TYPE_DATA_OFF, TRUE, sizeof(TBlueAPI_UsMessage),
        (otp_str_data.gEfuse_UpperStack_s.num_link_don + otp_str_data.gEfuse_UpperStack_s.num_link_doff) * 3 + 3, 4);

    osPoolCreate(&pBlueAPIData->dsBlueAPIPoolID, RAM_TYPE_DATA_OFF, TRUE, sizeof(TBlueAPI_DsMessage),
        (otp_str_data.gEfuse_UpperStack_s.num_link_don + otp_str_data.gEfuse_UpperStack_s.num_link_doff) * 3 + 2, 4);

    PBlueAPI_DS pBlueAPI_DS = &pBlueAPIData->DataStore;

    uint16_t nvSize;
    uint16_t offset = offsetof(TBlueAPI_DSNVData, dataDyn);

    /* blueAPIStore_GetNVDataSize() need these values */
    pBlueAPI_DS->peerCount     = 4;
    pBlueAPI_DS->entriesSCount = 16;
    pBlueAPI_DS->entriesLCount = 8;
    nvSize                     = blueAPIStore_GetNVDataSize(pBlueAPIData);

    if ((pBlueAPI_DS->pNVData = osMemoryClearAllocate(RAM_TYPE_DATA_ON, nvSize)) == 0)
    {
        BLUEAPI_TRACE_PRINTF_1(BLUEAPI_TRACE_MASK_TRACE, "!!BTMOS: failed to allocate %d bytes", nvSize);

        /* send ActInfo when application registers */
        pBlueAPIData->stateCause = blueAPI_CauseInvalidParameter;
        return;
    }

    /*updata point of pPeers, pEntriesS, pEntriesL*/
    pBlueAPI_DS->pPeers = (PBlueAPI_DSPeer)((uint8_t *)(pBlueAPI_DS->pNVData) + offset);
    offset += sizeof(TBlueAPI_DSPeer) * pBlueAPI_DS->peerCount;

    pBlueAPI_DS->pEntriesS = (PBlueAPI_DSEntryS)((uint8_t *)(pBlueAPI_DS->pNVData) + offset);
    offset += sizeof(TBlueAPI_DSEntryS) * pBlueAPI_DS->entriesSCount;

    pBlueAPI_DS->pEntriesL = (PBlueAPI_DSEntryL)((uint8_t *)(pBlueAPI_DS->pNVData) + offset);
    offset  += sizeof(TBlueAPI_DSEntryL) * pBlueAPI_DS->entriesLCount;

    blueAPI_Main(pBlueAPIData);
    BLUEAPI_TRACE_PRINTF_0(BLUEAPI_TRACE_MASK_TRACE, "blueAPI: ...done!");
}
Ejemplo n.º 10
0
// Initialize command processing.
void commandInit(void)
{
	// Initialize the message and memory pool for command processing.
  commandMemPool = osPoolCreate(osPool(commandMemPool));
  commandQueue = osMessageCreate(osMessageQ(commandQueue), NULL);
}
// creates the memory pool and the message queues
void create_mem_pool_and_msg_queues(void){
	mem_pool = osPoolCreate(osPool(mem_pool)); 					  
	pitch_queue = osMessageCreate(osMessageQ(pitch_queue), NULL); 
	temp_queue = osMessageCreate(osMessageQ(temp_queue), NULL);
	keypad_queue = osMessageCreate(osMessageQ(keypad_queue), NULL);
}
Ejemplo n.º 12
0
// == Function Definitions ==
int main(void) {

  /* MCU Configuration----------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_DMA_Init();
  MX_USART1_UART_Init();
  MX_USART2_UART_Init();

  // Initialise global flags
  globalFlags.states.commState = COMM_STATE_AUTO;
  globalFlags.states.wifiState = GEN_STATE_READY; // Default to busy until initialised
  globalFlags.procedures.wifiProcedures = WIFI_PROC_NONE;

  /* USER CODE BEGIN RTOS_MUTEX */
  /* add mutexes, ... */
  /* USER CODE END RTOS_MUTEX */

  /* USER CODE BEGIN RTOS_SEMAPHORES */
  /* add semaphores, ... */
  /* USER CODE END RTOS_SEMAPHORES */

  /* USER CODE BEGIN RTOS_TIMERS */
  /* start timers, add new ones, ... */
  /* USER CODE END RTOS_TIMERS */

  /* Create the thread(s) */
  osThreadDef(bossTask, StartBossTask, osPriorityNormal, 0, 128);
  bossTaskHandle = osThreadCreate(osThread(bossTask), NULL);

  osThreadDef(USARTInTask, StartUSARTInTask, osPriorityNormal, 0, 128);
  USARTInTaskHandle = osThreadCreate(osThread(USARTInTask), NULL);

  osThreadDef(USARTOutTask, StartUSARTOutTask, osPriorityNormal, 0, 128);
  USARTOutTaskHandle = osThreadCreate(osThread(USARTOutTask), NULL);

  /* USER CODE BEGIN RTOS_QUEUES */
  // Generic messaging and string message memory pools
  genericMPool = osPoolCreate(osPool(genericMPool));
  strBufMPool = osPoolCreate(osPool(strBufMPool));

  // USART In Task String Queue
  msgQUSARTIn = osMessageCreate(osMessageQ(msgQUSARTIn), NULL);
  
  // USART Out Task Queue
  msgQUSARTOut = osMessageCreate(osMessageQ(msgQUSARTOut), NULL);

  // Boss Task Queue
  msgQBoss = osMessageCreate(osMessageQ(msgQBoss), NULL);
  
  /* USER CODE END RTOS_QUEUES */

  /* Start scheduler */
  osKernelStart();

  /* We should never get here as control is now taken by the scheduler */

  /* Infinite loop */
  while (1) {
    __asm("nop");
  }

}