Exemplo n.º 1
0
Arquivo: main.c Projeto: carlosap/IoT
//******************************************************************************************
//man start
//&main()
//
//   -   Program Starts HERE. Make sure to flip the correct state for the ACTIVE UART
//       instance. the CLI supports 5 UARTS and they are ACTIVE by setting the
//       flip_uart_use_state(0) function.
//
//Carlos A. Perez
//man end
//******************************************************************************************
int main (void)
{
     swplatform_init_stacks();
     SWITCH_TO_UART0
     show_ver();
     start_listen_thread();
     do
     {
         CHECK_IF_UART_MAIN_IS_ACTIVE   //Function Verifies State and Provides Interface Object- RS232 PC

         CHECK_IF_UART1_IS_ACTIVE       //Function Verifies State and Provides Interface Object- Uart1

         CHECK_IF_UART2_IS_ACTIVE      //Function Verifies State and Provides Interface Object- Uart2

         CHECK_IF_UART3_IS_ACTIVE      //Function Verifies State and Provides Interface Object- Uart3

         CHECK_IF_UART4_IS_ACTIVE      //Function Verifies State and Provides Interface Object- Uart4

     }while(strCmd != "quit");
     return 0;
}
Exemplo n.º 2
0
int init_memshare(char *proc_name, int size, int qsize)
{
	int ctrl_mode = 1;
	int retvalue = 0, index;
	print(LOG_INFO, "Init_memshare start for %s with size %d\n", proc_name,
	      size);

	if (initialized)
		return 1;
	/* a source proc is a must */
	if (proc_name == NULL)
		return 2;

	memset(my_proc, 0, PROC_NAME_SIZE);
	strncpy(my_proc, proc_name, PROC_NAME_SIZE - 1);

	/* If I don't set a qsize I'm considered to be a send proc only */
	if (size)
		send_only = 0;

	if (!send_only) {
		init_queues();
		seize_queue(&queue_index, "memshare", qsize);
	}

	/* clear the cache */
	init_mem_proc();

	/* start off by locking the ctrl lock */
	if ((lock_ctrl_sem = create_lock(SEM_CTRL_KEY, 1)) == -1) {
		print(LOG_ERR, "Unable to create ctrl lock\n");
		return 3;
	}

	while (lock(lock_ctrl_sem) < 0) ;
	print(LOG_DEBUG, "Ctrl locked (init) by %s, %d\n\n", proc_name,
	      lock_ctrl_sem);
	/*print(LOG_ERR, "%d trylock (init) key=%d, sem=%d\n",
	   try_lock1(lock_ctrl_sem), SEM_CTRL_KEY, lock_ctrl_sem); */

	/* map up the ctrl area */
	if ((shm_ctrl_ptr = get_shm(SHM_CTRL_KEY, CTRL_SIZE, &ctrl_mode)) == 0) {
		print(LOG_ERR, "Unable to alloc shared mem\n");
		while (unlock(lock_ctrl_sem) < 0) ;
		return 6;
	}

	if (get_index_for_proc(my_proc) != -1) {
		print(LOG_ERR, "Procname %s already exists\n", my_proc);
		while (unlock(lock_ctrl_sem) < 0) ;
		return 4;
	}

	if (!send_only) {

		if ((index = get_first_free()) < 0) {
			while (unlock(lock_ctrl_sem) < 0) ;
			print(LOG_ERR, "Max num of processes registered\n");
			return 4;
		}

		print(LOG_DEBUG, "Next free index is %d\n", index);

		retvalue = seize_index(index, size, my_proc);

		if (retvalue == -1) {
			while (unlock(lock_ctrl_sem) < 0) ;
			return 6;
		}
	} else {
		print(LOG_INFO, "%s is a send only proc\n", my_proc);
	}

	print(LOG_DEBUG, "Ctrl unlocked by %s\n\n", proc_name);
	while (unlock(lock_ctrl_sem) < 0) ;

	if (!send_only)
		start_listen_thread();
	print(LOG_DEBUG, "Init_memshare done for %s\n", my_proc);
	initialized = 1;
	return 0;
}