// os.h // Runs on LM4F120/TM4C123/MSP432 // A priority/blocking real-time operating system // Daniel Valvano // March 25, 2016 /* This example accompanies the book "Embedded Systems: Real Time Interfacing to ARM Cortex M Microcontrollers", ISBN: 978-1463590154, Jonathan Valvano, copyright (c) 2016 "Embedded Systems: Real-Time Operating Systems for ARM Cortex-M Microcontrollers", ISBN: 978-1466468863, , Jonathan Valvano, copyright (c) 2016 Programs 4.4 through 4.12, section 4.2 Copyright 2016 by Jonathan W. Valvano, valvano@mail.utexas.edu You may use, edit, run or distribute this file as long as the above copyright notice remains THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. VALVANO SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. For more information about my classes, my research, and my books, see http://users.ece.utexas.edu/~valvano/ */ #ifndef __OS_H #define __OS_H 1 // ******** OS_Init ************ // Initialize operating system, disable interrupts // Initialize OS controlled I/O: periodic interrupt, bus clock as fast as possible // Initialize OS global variables // Inputs: none // Outputs: none void OS_Init(void); //******** OS_AddThreads *************** // Add eight main threads to the scheduler // Inputs: function pointers to eight void/void main threads // priorites for each main thread (0 highest) // Outputs: 1 if successful, 0 if this thread can not be added // This function will only be called once, after OS_Init and before OS_Launch int OS_AddThreads(void(*thread0)(void), uint32_t p0, void(*thread1)(void), uint32_t p1, void(*thread2)(void), uint32_t p2, void(*thread3)(void), uint32_t p3, void(*thread4)(void), uint32_t p4, void(*thread5)(void), uint32_t p5, void(*thread6)(void), uint32_t p6, void(*thread7)(void), uint32_t p7); //******** OS_Launch *************** // Start the scheduler, enable interrupts // Inputs: number of clock cycles for each time slice // Outputs: none (does not return) // Errors: theTimeSlice must be less than 16,777,216 void OS_Launch(uint32_t theTimeSlice); //******** OS_Suspend *************** // Called by main thread to cooperatively suspend operation // Inputs: none // Outputs: none // Will be run again depending on sleep/block status void OS_Suspend(void); // ******** OS_Sleep ************ // place this thread into a dormant state // input: number of msec to sleep // output: none // OS_Sleep(0) implements cooperative multitasking void OS_Sleep(uint32_t sleepTime); // ******** OS_InitSemaphore ************ // Initialize counting semaphore // Inputs: pointer to a semaphore // initial value of semaphore // Outputs: none void OS_InitSemaphore(int32_t *semaPt, int32_t value); // ******** OS_Wait ************ // Decrement semaphore and block if less than zero // Lab2 spinlock (does not suspend while spinning) // Lab3 block if less than zero // Inputs: pointer to a counting semaphore // Outputs: none void OS_Wait(int32_t *semaPt); // ******** OS_Signal ************ // Increment semaphore // Lab2 spinlock // Lab3 wakeup blocked thread if appropriate // Inputs: pointer to a counting semaphore // Outputs: none void OS_Signal(int32_t *semaPt); // ******** OS_FIFO_Init ************ // Initialize FIFO. The "put" and "get" indices initially // are equal, which means that the FIFO is empty. Also // initialize semaphores to track properties of the FIFO // such as size and busy status for Put and Get operations, // which is important if there are multiple data producers // or multiple data consumers. // Inputs: none // Outputs: none void OS_FIFO_Init(void); // ******** OS_FIFO_Put ************ // Put an entry in the FIFO. Consider using a unique // semaphore to wait on busy status if more than one thread // is putting data into the FIFO and there is a chance that // this function may interrupt itself. // Inputs: data to be stored // Outputs: 0 if successful, -1 if the FIFO is full int OS_FIFO_Put(uint32_t data); // ******** OS_FIFO_Get ************ // Get an entry from the FIFO. Consider using a unique // semaphore to wait on busy status if more than one thread // is getting data from the FIFO and there is a chance that // this function may interrupt itself. // Inputs: none // Outputs: data retrieved uint32_t OS_FIFO_Get(void); // ******** OS_PeriodTrigger0_Init ************ // Initialize periodic timer interrupt to signal // Inputs: semaphore to signal // period in ms // priority level at 0 (highest) // Outputs: none void OS_PeriodTrigger0_Init(int32_t *semaPt, uint32_t period); // ******** OS_PeriodTrigger1_Init ************ // Initialize periodic timer interrupt to signal // Inputs: semaphore to signal // period in ms // priority level at 0 (highest) // Outputs: none void OS_PeriodTrigger1_Init(int32_t *semaPt, uint32_t period); // ******** OS_EdgeTrigger_Init ************ // Initialize button1, PD6, to signal on a falling edge interrupt // Inputs: semaphore to signal // priority // Outputs: none void OS_EdgeTrigger_Init(int32_t *semaPt, uint8_t priority); // ******** OS_EdgeTrigger_Restart ************ // restart button1 to signal on a falling edge interrupt // rearm interrupt // Inputs: none // Outputs: none void OS_EdgeTrigger_Restart(void); #endif