Exemplo n.º 1
0
Arquivo: OS.c Projeto: tach4455/EE345M
// ******** OS_Suspend ************
// suspend execution of currently running thread
// scheduler will choose another thread to execute
// Can be used to implement cooperative multitasking
// Same function as OS_Sleep(0)
// input:  none
// output: none
void OS_Suspend(void) {

  long curPriority;
  unsigned long curTimeSlice;
  volatile int i;

  OS_DisableInterrupts();

  // Determines NextPt
  Scheduler();

  // Get priority of next thread and calculate timeslice
  curPriority = (*NextPt).priority;
  curTimeSlice = calcTimeSlice(curPriority);

  // Sets next systick period, does not rest counting
  SysTickPeriodSet(curTimeSlice);

  // Write to register forces systick to reset counting
  NVIC_ST_CURRENT_R = 0;

  IntPendSet(FAULT_PENDSV);
  OS_EnableInterrupts();

  return;
}
Exemplo n.º 2
0
BOOL FIFO_Get(TFIFO * const FIFO, uint8_t * const dataPtr)
{
  OS_DisableInterrupts();                         //Enter Critical Section

  if (FIFO->NbBytes != 0)
  {
    FIFO->NbBytes--;
    *dataPtr = FIFO->Buffer[FIFO->Start];
    FIFO->Start = (FIFO->Start + 1) % FIFO_SIZE;

    OS_EnableInterrupts();
    return (bTRUE);
  }

  OS_EnableInterrupts();
  return (bFALSE);
}
Exemplo n.º 3
0
BOOL FIFO_Put(TFIFO * const FIFO, const uint8_t data)
{
  OS_DisableInterrupts();                     //Enter Critical Section

  if (FIFO->NbBytes < FIFO_SIZE)              //Ensure that the buffer is not full before putting data within it
  {
    FIFO->NbBytes++; 				                  //Increment data counter
    FIFO->Buffer[FIFO->End] = data; 		      //Store data in the buffer
    FIFO->End = (FIFO->End + 1) % FIFO_SIZE; 	//increment end pointer within FIFO_SIZE

    OS_EnableInterrupts();
    return (bTRUE);
  }

  OS_EnableInterrupts();
  return (bFALSE);
}
Exemplo n.º 4
0
// ******** OS_Sleep ************
// place this thread into a dormant state
// input:  number of msec to sleep
// output: none
// You are free to select the time resolution for this function
// Sleep time is a multiple of context switch time period
// OS_Sleep(0) implements cooperative multitasking
void OS_Sleep(unsigned long sleepTime)
{
	OS_DisableInterrupts();
	threadRemover(&SleepPt, sleepTime * 2);
	sleepCount++;
	switched = 1;
	OS_Suspend();
	OS_EnableInterrupts();
}
Exemplo n.º 5
0
// ******** OS_Kill ************
// kill the currently running thread, release its TCB and stack
// input:  none
// output: none
void OS_Kill(void)
{
	OS_DisableInterrupts();
	threadRemover(&DeadPt, 0); //parameter 0 will be ignored
	deadCount++;
	switched = 1;
	OS_Suspend();
	OS_EnableInterrupts();

}
Exemplo n.º 6
0
void TriggerSensor0(void) {
    int i;
    OS_DisableInterrupts();
    GPIO_PORTB0 = 0x01;

    // delay 5 us
    for (i = 0; i < 75; i++);

    GPIO_PORTB0 = 0x00;
    GPIO_PORTB_DIR_R &= ~0x01;   // make PB0 in
    GPIO_PORTB_IM_R |= 0x01;		// enable PB0 interrupts
    OS_EnableInterrupts();
}
Exemplo n.º 7
0
// ******** OS_bWait ************
// Lab2 spinlock, set to 0
// Lab3 block if less than zero
// input:  pointer to a binary semaphore
// output: none
void OS_bWait(Sema4Type *semaPt)
{
	int32_t status;
	status = OS_StartCritical();
	while((*semaPt).Value == 0)
	{
		OS_Block(semaPt); //block and put into semaphore blocked list
		OS_Suspend();
		OS_EnableInterrupts();
		OS_DisableInterrupts();
	} //while someone has the semaphor
	(*semaPt).Value = 0; //take the semaphore
	EndCritical(status );
}
Exemplo n.º 8
0
// ******** OS_Wait ************
// decrement semaphore 
// Lab2 spinlock
// Lab3 block if less than zero
// input:  pointer to a counting semaphore
// output: none
void OS_Wait(Sema4Type *semaPt)
{
	uint32_t status;
	status = OS_StartCritical();
	(*semaPt).Value--; //decrease count
	if((*semaPt).Value < 0)
	{
		OS_Block(semaPt); //block and put into semaphore blocked list
		OS_Suspend();
		OS_EnableInterrupts();
		OS_DisableInterrupts();
	} 
	OS_EndCritical(status);
}
Exemplo n.º 9
0
void Ping_Init(void) {
    volatile unsigned long delay;
    OS_DisableInterrupts();
    SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOB; // activate port B
    delay = SYSCTL_RCGC2_R;
    // **** Port B Edge Trigger Initialization ****
    GPIO_PORTB_DIR_R |= 0x03;   // make PB0-1 out
    GPIO_PORTB_DEN_R |= 0x03;   // enable digital I/O on PB0-1
    GPIO_PORTB_PUR_R |= 0x03;		// enable pull up on PB0-1
    GPIO_PORTB_IEV_R |= 0x03;	  // make PB0-1 rising edge triggered
    GPIO_PORTB_IS_R &= ~0x03;		// make PB0-1 edge-sensitive
    GPIO_PORTB_ICR_R = 0x03;		// clear flag
    NVIC_PRI0_R = (NVIC_PRI1_R&0xFFFF00FF)|0x00006000;  // priority 3
    NVIC_EN0_R |= NVIC_EN0_INT1;

    OS_InitSemaphore(&Sensor0Free, 1);
    OS_InitSemaphore(&Sensor1Free, 1);
    OS_InitSemaphore(&Sensor0DataAvailable, 0);
    OS_InitSemaphore(&Sensor1DataAvailable, 0);

    OS_EnableInterrupts();
}