-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'assignments-base/assignment7'
- Loading branch information
Showing
7 changed files
with
158 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
assignment6 | ||
assignment7 |