Skip to content

Commit

Permalink
Merge remote-tracking branch 'assignments-base/assignment7'
Browse files Browse the repository at this point in the history
  • Loading branch information
traptibalgi committed Oct 15, 2024
2 parents e3809f7 + 19305ad commit 24af3a5
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Run unit test
run: ./unit-test.sh
full-test:
container: cuaesd/aesd-autotest:24-assignment6
container: cuaesd/aesd-autotest:24-assignment7
runs-on: self-hosted
steps:
- uses: actions/checkout@v2
Expand Down
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ set(CMAKE_C_FLAGS "-pthread")
set(AUTOTEST_SOURCES
test/assignment1/Test_hello.c
test/assignment1/Test_assignment_validate.c
test/assignment7/Test_circular_buffer.c

)
# A list of all files containing test code that is used for assignment validation
set(TESTED_SOURCE
../examples/autotest-validate/autotest-validate.c
../aesd-char-driver/aesd-circular-buffer.c
)
add_subdirectory(assignment-autotest)
9 changes: 9 additions & 0 deletions aesd-char-driver/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*.order
*.symvers
*.ko
.*.cmd
.tmp_versions*
*.mod.c
linux_source_cdt
*.mod
build
4 changes: 4 additions & 0 deletions aesd-char-driver/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# AESD Char Driver

Template source code for the AESD char driver used with assignments 8 and later

58 changes: 58 additions & 0 deletions aesd-char-driver/aesd-circular-buffer.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* @file aesd-circular-buffer.c
* @brief Functions and data related to a circular buffer imlementation
*
* @author Dan Walkes
* @date 2020-03-01
* @copyright Copyright (c) 2020
*
*/

#ifdef __KERNEL__
#include <linux/string.h>
#else
#include <string.h>
#endif

#include "aesd-circular-buffer.h"

/**
* @param buffer the buffer to search for corresponding offset. Any necessary locking must be performed by caller.
* @param char_offset the position to search for in the buffer list, describing the zero referenced
* character index if all buffer strings were concatenated end to end
* @param entry_offset_byte_rtn is a pointer specifying a location to store the byte of the returned aesd_buffer_entry
* buffptr member corresponding to char_offset. This value is only set when a matching char_offset is found
* in aesd_buffer.
* @return the struct aesd_buffer_entry structure representing the position described by char_offset, or
* NULL if this position is not available in the buffer (not enough data is written).
*/
struct aesd_buffer_entry *aesd_circular_buffer_find_entry_offset_for_fpos(struct aesd_circular_buffer *buffer,
size_t char_offset, size_t *entry_offset_byte_rtn )
{
/**
* TODO: implement per description
*/
return NULL;
}

/**
* Adds entry @param add_entry to @param buffer in the location specified in buffer->in_offs.
* If the buffer was already full, overwrites the oldest entry and advances buffer->out_offs to the
* new start location.
* Any necessary locking must be handled by the caller
* Any memory referenced in @param add_entry must be allocated by and/or must have a lifetime managed by the caller.
*/
void aesd_circular_buffer_add_entry(struct aesd_circular_buffer *buffer, const struct aesd_buffer_entry *add_entry)
{
/**
* TODO: implement per description
*/
}

/**
* Initializes the circular buffer described by @param buffer to an empty struct
*/
void aesd_circular_buffer_init(struct aesd_circular_buffer *buffer)
{
memset(buffer,0,sizeof(struct aesd_circular_buffer));
}
82 changes: 82 additions & 0 deletions aesd-char-driver/aesd-circular-buffer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* aesd-circular-buffer.h
*
* Created on: March 1st, 2020
* Author: Dan Walkes
*/

#ifndef AESD_CIRCULAR_BUFFER_H
#define AESD_CIRCULAR_BUFFER_H

#ifdef __KERNEL__
#include <linux/types.h>
#else
#include <stddef.h> // size_t
#include <stdint.h> // uintx_t
#include <stdbool.h>
#endif

#define AESDCHAR_MAX_WRITE_OPERATIONS_SUPPORTED 10

struct aesd_buffer_entry
{
/**
* A location where the buffer contents in buffptr are stored
*/
const char *buffptr;
/**
* Number of bytes stored in buffptr
*/
size_t size;
};

struct aesd_circular_buffer
{
/**
* An array of pointers to memory allocated for the most recent write operations
*/
struct aesd_buffer_entry entry[AESDCHAR_MAX_WRITE_OPERATIONS_SUPPORTED];
/**
* The current location in the entry structure where the next write should
* be stored.
*/
uint8_t in_offs;
/**
* The first location in the entry structure to read from
*/
uint8_t out_offs;
/**
* set to true when the buffer entry structure is full
*/
bool full;
};

extern struct aesd_buffer_entry *aesd_circular_buffer_find_entry_offset_for_fpos(struct aesd_circular_buffer *buffer,
size_t char_offset, size_t *entry_offset_byte_rtn );

extern void aesd_circular_buffer_add_entry(struct aesd_circular_buffer *buffer, const struct aesd_buffer_entry *add_entry);

extern void aesd_circular_buffer_init(struct aesd_circular_buffer *buffer);

/**
* Create a for loop to iterate over each member of the circular buffer.
* Useful when you've allocated memory for circular buffer entries and need to free it
* @param entryptr is a struct aesd_buffer_entry* to set with the current entry
* @param buffer is the struct aesd_buffer * describing the buffer
* @param index is a uint8_t stack allocated value used by this macro for an index
* Example usage:
* uint8_t index;
* struct aesd_circular_buffer buffer;
* struct aesd_buffer_entry *entry;
* AESD_CIRCULAR_BUFFER_FOREACH(entry,&buffer,index) {
* free(entry->buffptr);
* }
*/
#define AESD_CIRCULAR_BUFFER_FOREACH(entryptr,buffer,index) \
for(index=0, entryptr=&((buffer)->entry[index]); \
index<AESDCHAR_MAX_WRITE_OPERATIONS_SUPPORTED; \
index++, entryptr=&((buffer)->entry[index]))



#endif /* AESD_CIRCULAR_BUFFER_H */
2 changes: 1 addition & 1 deletion conf/assignment.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
assignment6
assignment7

0 comments on commit 24af3a5

Please sign in to comment.