예제 #1
0
/**
 * @brief: a process that prints five numbers
 *         and then releases a memory block
 */
void proc2(void)
{
	int i = 0;
	int ret_val = 20;
	void *p_mem_blk;
	
	p_mem_blk = request_memory_block();
	set_process_priority(PID_P2, MEDIUM);
	while ( 1) {
		if ( i != 0 && i%5 == 0 ) {
			uart0_put_string("\n\r");
			ret_val = release_memory_block(p_mem_blk);
#ifdef DEBUG_0
			printf("proc2: ret_val=%d\n", ret_val);
#endif /* DEBUG_0 */
			if ( ret_val == -1 ) {
				break;
			}
		}
		uart0_put_char('0' + i%10);
		i++;
	}
	uart0_put_string("proc2: end of testing\n\r");
	set_process_priority(PID_P2, LOWEST);
	while ( 1 ) {
		release_processor();
	}
}
예제 #2
0
파일: main.c 프로젝트: ccqi/SE350-Lab
int main () {

	volatile uint8_t sec = 0;

	SystemInit();
	__disable_irq();
	timer_init(0); /* initialize timer 0 */
	
	/* 
	  uart polling is used in this example only to help
	  demonstrate timer interrupt programming.
	  In your final project, polling is NOT ALLOWED in i-processes.
	  Refer to the UART_irq example for interrupt driven UART.
	*/
	uart0_init();
	
	__enable_irq();

	while (1) {
		/* g_timer_count gets updated every 1ms */
		if (g_timer_count == 1000) { 
			uart0_put_char('0'+ sec);
			sec = (++sec)%10;
			g_timer_count = 0; /* reset the counter */
		}     
	}
}
예제 #3
0
파일: Queue.c 프로젝트: chrisjluc/SE350
void print(Queue* queue) {
    if (!isEmpty(queue)) {
        Node* node = queue->head;
        while (node != NULL) {
			PCB* pcb = (PCB*) node->data;
		    uart0_put_string("->");
            uart0_put_char('0' + pcb->m_pid);
            node = node->next;
        }
				uart0_put_string("\n\r");
    }
}
예제 #4
0
/**
 * @brief call back function for printf
 * NOTE: first paramter p is not used for now.
 */
void putc(void *p, char c)
{
  if (p != NULL) {
    if (active_uart == 0) {
      uart0_put_string("putc: first parameter needs to be NULL");
    } else {
      uart1_put_string("putc: first parameter needs to be NULL");
    }
  } else {
    if (active_uart == 0) {
      uart0_put_char(c);
    } else {
      uart1_put_char(c);
    }
  }
}
예제 #5
0
/**
 * @brief: a process that prints five uppercase letters
 *         and request a memory block.
 */
void proc1(void)
{
	int i = 0;
	void *p_mem_blk;
	while ( 1 ) {
		if ( i != 0 && i%5 == 0 ) {
			uart0_put_string("\n\r");
			p_mem_blk = request_memory_block();
#ifdef DEBUG_0
			printf("proc1: p_mem_blk=0x%x\n", p_mem_blk);
#endif /* DEBUG_0 */
		}
		uart0_put_char('A' + i%26);
		i++;
	}
}
예제 #6
0
/**
 * @brief: a process that prints 2x5 lowercase letters
 */
void proc1(void)
{
	int i = 0;
	int j;
	int counter = 0;
	int ret_val = 100;
	char *c;
	void *mem;
	MSG_BUF *msg;
	MSG_BUF *msg2;
	
	while ( 1 ) {
		
		if (i == 5) {
			msg = (MSG_BUF *)request_memory_block();
			strcpy(msg->mtext, "%Z");
			msg->mtype = DEFAULT;
			msg2 = (MSG_BUF *)request_memory_block();
			strcpy(msg2->mtext, "%C 9 2");
			msg2->mtype = DEFAULT;
			send_message(PID_A, msg);
			delayed_send(PID_SET_PRIO, msg2, ONE_SECOND*25);
		}
		
		if ( i != 0 && i%5 == 0 ) {
			uart0_put_string("\n\r");
			counter++;
			if ( counter == 4 ) {
				//ret_val = set_process_priority(PID_P2, HIGH);
				break;
			} else {
				ret_val = release_processor();
			}
#ifdef DEBUG_0
			printf("proc1: ret_val = %d \n", ret_val);
#endif /* DEBUG_0 */
		}
		
		uart0_put_char('a' + i%10);
		i++;
	}
	c = "proc1 end of testing\n\r";
	uart0_put_string(c);
	while ( 1 ) {
		release_processor();
	}
}