├── README.md ├── task1.c ├── task2.cpp └── task3.c /README.md: -------------------------------------------------------------------------------- 1 | # Embedded-coding-challenge 2 | 3 | We will like to know your approach towards solving typical embedded software problems. 4 | 5 | Your challenge is to provide sample code for three independent tasks. This repository 6 | contains a source file for each of the three tasks with instructions appearing as header 7 | comments in the respective files. You may also see some skeleton code which you need to 8 | complete based on the instructions given in the source file. 9 | 10 | ## Deliverables 11 | 12 | - Sample code for Task 1, 2 and 3 (please see respective source files) 13 | - A Makefile which compiles complete programs for Task 1 and Task 2 with GNU C/C++ compiler 14 | - For Task 3 the above Makefile should just generate an object file, complete program is not needed. 15 | - Programs corresponding to Task 1 and Task 2 should be runable on a GNU/Linux PC such as a Ubuntu box. 16 | 17 | ## Time Limit 18 | 19 | You have 90 minutes to complete these tasks. 20 | 21 | ## What we'll look at 22 | 23 | - Structure of the code including flow and identifiable data structures 24 | - Consistent code formatting 25 | - Eye for writing efficient code suitable for running on constrained memory/cpu devices. 26 | 27 | ## Process 28 | 29 | When you're ready, please fork this repository and start writing code in your fork. You'll get extra points for committing often in small chunks. 30 | 31 | -------------------------------------------------------------------------------- /task1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* Task1 Description 5 | * ----------------- 6 | * You have to write a initialization routine for a UART device. The UART is a memmory 7 | * mapped device at the address 0xFC000000 on an embedded platform. 8 | * This peripheral is controlled by the following 32 bit registers (offsets given) 9 | 10 | * BRR: Baud rate register Offset: 0x4 11 | * BRR[0:3] Selects the baud rate as follows 12 | * - 0: 4800 13 | * - 1: 9600 14 | * - 2: 14400 15 | * - 3: 19200 16 | * - 4: 38400 17 | * - 5: 57600 18 | * - 6: 115200 19 | * - 7: 128000 20 | * - 8: 256000 21 | * 22 | * BRR[4:5] Selects parity as follows 23 | * - 0 Even Parity 24 | * - 1 Odd Parity 25 | * - 2 No Parity 26 | * 27 | * - BRR[8] Turning this bit on enables hardware flow control 28 | * 29 | * - BRR[12:15] Contains the number of stop bits 30 | * 31 | * TER: Transmit enable register Offset: 0x8 32 | * - Bit 23 in this register enables the transmit operation 33 | * 34 | * RER: Receive enabel register Offset: 0xC 35 | * - Bits 3 and 5 notify overrun and framing error and need to be cleared upon reset 36 | * 37 | * IER: Interrupt enable register Offset: 0x10 38 | * - Bit 14 and 15 enable TX and RX interrupts 39 | * 40 | * TDR: Transmit data register Offset: 0x14 41 | * - Contains data to be transmitted via UART 42 | * 43 | * RDR: Receive data register Offset: 0x18 44 | * - Contains data received via UART 45 | * 46 | * 47 | * You need to write an initialization routine for this UART in C with the following configuration. 48 | * 49 | * Baud Rate: 38400, stop bits 1, parity none, flow control none 50 | * TX and RX are interrupt based operations, with data registers cleared at the start of operation. 51 | * 52 | * You also need to supply a test case by constructing a dummy UART device which will receive memory operations 53 | * directed for the actual hardware device. This structure should be used to validate correct configuration of 54 | * UART. Your test program should be runable on a GNU/Linux PC. 55 | * 56 | **/ 57 | 58 | // Data structure containing UART parameters including base address and other settings. 59 | typedef struct UART_HANDLE UART_HANDLE; 60 | 61 | 62 | // Memory Operations, stubs for transcations on embedded platform 63 | // but route memory operations to a dummy UART buffer for unit-testing 64 | 65 | uint32_t stub_memread(uint32_t *mem_addr) 66 | { 67 | 68 | } 69 | 70 | 71 | void stub_memwrite(uint32_t *mem_addr, uint32_t val) 72 | { 73 | 74 | } 75 | 76 | // Fill this function 77 | void init_uart(UART_HANDLE *h) 78 | { 79 | 80 | } 81 | 82 | // Provide a test case for uart initialization function above 83 | int main(int argc, char *argv[]) 84 | { 85 | 86 | } 87 | -------------------------------------------------------------------------------- /task2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * Write a class in C++ which manages an pointer to memory block aligned at 16 bytes boundary. 5 | * The class should support unsigned, float and double data types for the memory pointer. 6 | * It should accept the size of memory block and produce a pointer to memory block of that size 7 | * with address aligned to 16bytes. The class should support copy and copy by assignment 8 | * construction of its objects. There should be an deference operator '*' which should return the 9 | * raw pointer maintained by the class. Please also provide a small main function to illustrate 10 | * the usage of this class. */ 11 | 12 | // Fill this class 13 | class AlignedPtr { 14 | 15 | }; 16 | 17 | 18 | // Instantiate above class in this function 19 | // Also demonstrate the usage of the class for 20 | // unsigned, float and double data types 21 | int main(int argc, char *argv[]) 22 | { 23 | 24 | } 25 | -------------------------------------------------------------------------------- /task3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* Task3 Description 5 | * ----------------- 6 | * 7 | * This file contains some sample Queue APIs for a pre-emptive, priority based scheduling RTOS. 8 | * You need to write parts of a multitasking application for this RTOS. Focus will be on two 9 | * tasks of interest, TaskA and TaskB. TaskA sends a message of the format 10 | * to a Queue. TaskB is responsible for retrieving messages from the same Queue. 11 | * TaskA sends messages asynchronously without waiting. While TaskB waits for 10 ticks in 12 | * case no message is available. 13 | 14 | * In addition to filling TaskA and TaskB functions, please identify any synchronization issues 15 | * faced by the application. You can put your thoughts as comments in the task functions. 16 | * Also propose a fault tolerant design for this application. Please state your assumptions 17 | * (if any) about the RTOS internals. 18 | * 19 | */ 20 | typedef struct RTOS_QUEUE RTOS_QUEUE; 21 | 22 | RTOS_QUEUE *RTOS_Create_Queue(size_t numElems, size_t perElemSize); 23 | int RTOS_SendTo_Queue(RTOS_QUEUE *txQueue, void *txBuffer, unsigned waitDurationTicks); 24 | int RTOS_RecvFrom_Queue(RTOS_QUEUE *rxQueue, void *rxBuffer, unsigned waitDurationTicks); 25 | 26 | RTOS_QUEUE *q; 27 | 28 | struct QMessage 29 | { 30 | uint8_t qID; 31 | char qData[20]; 32 | } qMessage; 33 | 34 | // TaskA function to be completed 35 | void TaskA(void *Params) 36 | { 37 | 38 | } 39 | 40 | // TaskB function to be completed 41 | void TaskB(void *Params) 42 | { 43 | 44 | } 45 | 46 | --------------------------------------------------------------------------------