Contains the source code from the course work throughout my undergraduate Computer Engineering degree at Brigham Young University. There is a mixture of Go, Python, C, C++, Java, VHDL, Verilog, Matlab, Bash, Assembly, etc..
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

yakk.h 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #ifndef YAKK_H
  2. #define YAKK_H
  3. #include "yaku.h"
  4. #define null 0
  5. #define IDLETASKSTACKSIZE 512
  6. //Error Codes
  7. #define NEW_TASK_FAILED 1
  8. #define READY_QUEUE_EMPTY 2
  9. #define NEW_SEM_FAILED 3
  10. #define NEW_QUEUE_FAILED 4
  11. //Kernel Data Structures
  12. enum TaskState {T_BLOCKED, T_READY, T_RUNNING};
  13. enum KernelState {K_BLOCKED, K_RUNNING};
  14. typedef struct TCB {
  15. unsigned int tid;
  16. unsigned char priority;
  17. void* stackPointer;
  18. enum TaskState state;
  19. unsigned int delayCount;
  20. struct TCB* next;
  21. struct TCB* prev;
  22. } TCB;
  23. typedef struct TaskBlock {
  24. TCB TCBPool[MAX_TASKS+1];
  25. unsigned int nextFreeTCB;
  26. } TaskBlock;
  27. typedef struct PriorityQueue {
  28. TCB* head;
  29. TCB* tail;
  30. unsigned int size;
  31. } PriorityQueue;
  32. typedef struct DelayQueue {
  33. TCB* head;
  34. unsigned int size;
  35. } DelayQueue;
  36. typedef struct Semaphore {
  37. int value;
  38. PriorityQueue queue;
  39. } YKSEM;
  40. typedef struct SemBlock {
  41. YKSEM SemPool[MAX_SEMS];
  42. unsigned int nextFreeSem;
  43. } SemBlock;
  44. typedef struct MessageQueue {
  45. void** messages;
  46. unsigned int currentSize;
  47. unsigned int maxSize;
  48. PriorityQueue queue;
  49. } YKQ;
  50. typedef struct MessageQueueBlock {
  51. YKQ QueuePool[MAX_QUEUES];
  52. unsigned int nextFreeQueue;
  53. } MsgQueueBlock;
  54. //Kernel API
  55. void YKInitialize(void);
  56. void YKEnterMutex(void);
  57. void YKExitMutex(void);
  58. void YKIdleTask(void);
  59. void YKNewTask(void (* task) (void), void *taskStack, unsigned char priority);
  60. void YKDelayTask(unsigned count);
  61. void YKEnterISR(void);
  62. void YKExitISR(void);
  63. unsigned int YKGetISRCallDepth(void);
  64. void YKScheduler(void);
  65. void YKDispatcher(TCB* readyTask);
  66. void YKTickHandler(void);
  67. YKSEM* YKSemCreate(int initialValue);
  68. void YKSemPend(YKSEM* semaphore);
  69. void YKSemPost(YKSEM* semaphore);
  70. YKQ* YKQCreate(void** start, unsigned size);
  71. void* YKQPend(YKQ* queue);
  72. int YKQPost(YKQ* queue, void* msg);
  73. //YKEVENT* YKEventCreate(unsigned initialValue);
  74. //void YKEventSet(YKEVENT* event, unsigned eventMask);
  75. //void YKEVentReset(YKEVENT* event, unsigned eventMask);
  76. TCB* getNewTCB(void);
  77. YKSEM* getNewSem(void);
  78. YKQ* getNewQueue(void);
  79. void YKRun(void);
  80. unsigned int getYKCtxSwCount();
  81. unsigned int getYKIdelCount();
  82. void setYKIdelCount(int value);
  83. void setYKCtxSwCount(int value);
  84. unsigned int getYKTickNum();
  85. #endif