Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit of a version of CSUD slightly more advanced than at http://www.cl.cam.ac.uk/freshers/raspberrypi/tutorials/os/. Since then, it has been modularised to remove dependencies from abstract code to concrete code.
- Loading branch information
0 parents
commit 8ad03ec
Showing
43 changed files
with
7,282 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Auto detect text files and perform LF normalization | ||
* text=auto | ||
|
||
# Custom for Visual Studio | ||
*.cs diff=csharp | ||
*.sln merge=union | ||
*.csproj merge=union | ||
*.vbproj merge=union | ||
*.fsproj merge=union | ||
*.dbproj merge=union | ||
|
||
# Standard to msysgit | ||
*.doc diff=astextplain | ||
*.DOC diff=astextplain | ||
*.docx diff=astextplain | ||
*.DOCX diff=astextplain | ||
*.dot diff=astextplain | ||
*.DOT diff=astextplain | ||
*.pdf diff=astextplain | ||
*.PDF diff=astextplain | ||
*.rtf diff=astextplain | ||
*.RTF diff=astextplain |
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,3 @@ | ||
build/ | ||
*.o | ||
*.a |
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,22 @@ | ||
Copyright (c) 2012 Alex Chadwick | ||
|
||
Permission is hereby granted, free of charge, to any person | ||
obtaining a copy of this software and associated documentation | ||
files (the "Software"), to deal in the Software without | ||
restriction, including without limitation the rights to use, | ||
copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following | ||
conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
OTHER DEALINGS IN THE SOFTWARE. |
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,41 @@ | ||
CSUD makefile arguments: | ||
|
||
CONFIG=(DEBUG|FINAL) | ||
DEBUG builds check more things, are more verbose, not optimise, etc. | ||
FINAL builds are faster, quieter, optimised. (default) | ||
TYPE=(STANDALONE|LOWLEVEL|DRIVER) | ||
STANDALONE builds have no external dependencies. | ||
LOWLEVEL builds have few external dependencies. (default) | ||
DRIVER builds have many external dependencies. | ||
TARGET=(RPI|NONE) | ||
RPI builds for the Raspberry Pi. Libs: ARM_V6, BCM2835, DWC. | ||
NONE builds for no system in particular. Libs: None. (default) | ||
GNU=* | ||
Specifies the cross compiler to use e.g. 'arm-none-eabi-'. Default is blank. | ||
BUILD=* | ||
Specifies the build directory. Default is 'build/'. | ||
SOURCE=* | ||
Specifies the source directory. Default is 'source/'. | ||
CONFIGDIR=* | ||
Specifies the configuration directory. Default is 'configuration/'. | ||
LIBNAME=* | ||
Specifies the target library name. Default is 'libcsud.a'. | ||
INCDIR=* | ||
Specifies the include directory. Default is 'include/'. Note, this is for | ||
the project headers, not system ones. | ||
LIB_HID=(0|1) | ||
Enables or disables the HID driver. Default specified in | ||
configuration/makefile.in. | ||
LIB_KBD=(0|1) | ||
Enables or disables the Keyboard driver. Default specified in | ||
configuration/makefile.in. | ||
LIB_HUB=(0|1) | ||
Enables or disables the Hub driver. Default specified in | ||
configuration/makefile.in. | ||
LIB_ARM_V6=(0|1) | ||
Enables or disables the ARMv6 platform code. Default is TARGET dependant. | ||
LIB_BCM2835=(0|1) | ||
Enables or disables the Broadcom2835 platform code. Default is TARGET | ||
dependant. | ||
LIB_DWC=(0|1) | ||
Enables or disables the DesignWare Core hcd. Default is TARGET dependant. |
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,33 @@ | ||
DIR := $(CONFIGDIR) | ||
|
||
ifeq ("$(CONFIG)", "DEBUG") | ||
CFLAGS += -DDEBUG | ||
else ifeq ("$(CONFIG)", "FINAL") | ||
CFLAGS += -DFINAL | ||
CFLAGS += -O2 | ||
CFLAGS += -Wno-strict-aliasing | ||
else | ||
CFLAGS += -DCONFIG_ERROR | ||
endif | ||
|
||
ifeq ("$(TYPE)", "STANDALONE") | ||
CFLAGS += -DTYPE_STANDALONE | ||
else ifeq ("$(TYPE)", "LOWLEVEL") | ||
CFLAGS += -DTYPE_LOWLEVEL | ||
else ifeq ("$(TYPE)", "DRIVER") | ||
CFLAGS += -DTYPE_DRIVER | ||
else | ||
CFLAGS += -DTYPE_ERROR | ||
endif | ||
|
||
ifeq ("$(TARGET)", "RPI") | ||
include $(DIR)rpi.in | ||
else ifeq ("$(TARGET)", "NONE") | ||
CFLAGS += -DTARGET_NONE | ||
else | ||
CFLAGS += -DTARGET_ERROR | ||
endif | ||
|
||
LIB_HID ?= 1 | ||
LIB_KBD ?= 1 | ||
LIB_HUB ?= 1 |
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,6 @@ | ||
LIB_ARM_V6 ?= 1 | ||
LIB_BCM2835 ?= 1 | ||
LIB_DWC ?= 1 | ||
CFLAGS += -DTARGET_RPI | ||
CFLAGS += -Wa,-march=armv6 | ||
CFLAGS += -Wa,-mcpu=arm1176jzf-s |
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,65 @@ | ||
/****************************************************************************** | ||
* configuration.h | ||
* by Alex Chadwick | ||
* | ||
* A light weight implementation of the USB protocol stack fit for a simple | ||
* driver. | ||
* | ||
* configuration.h contains definitions for all optional components | ||
* The makefile defines three main categories of definitions: | ||
* CONFIG: Whether or not this is a DEBUG driver | ||
* TARGET: The target system | ||
* TYPE: What sort of driver to compile (e.g. standalone) | ||
*****************************************************************************/ | ||
|
||
// Check we have a CONFIG. Valid choices are DEBUG and FINAL. If neither of | ||
// of these are specified, CONFIG_ERROR will be. If not, the haven't used the | ||
// makefile. | ||
#if defined DEBUG | ||
#elif defined FINAL | ||
#elif defined CONFIG_ERROR | ||
# error Please specify the CONFIG as either DEBUG or FINAL (default) | ||
#else | ||
# error Please ensure you compile the driver with the makefile provided | ||
#endif | ||
|
||
// Check we have a target. This should either be RPI or NONE. If neither of | ||
// these is specified, TARGET_ERROR will be. If not, the haven't used the | ||
// makefile. | ||
#if defined TARGET_RPI | ||
// Compiling for the Raspberry Pi (model B). | ||
// This is an ARM1176JZF-S, running ARMv6. | ||
// The chip is a Broadcom 2835 with a Designware OTG Core, mapped to | ||
// physical address 0x20980000 | ||
# define ARM | ||
# define ARM_V6 | ||
# define ENDIAN_LITTLE | ||
# define BROADCOM_2835 | ||
# define HCD_DESIGNWARE_20 | ||
# define HCD_DESIGNWARE_BASE ((void*)0x20980000) | ||
#elif defined TARGET_NONE | ||
// Compiling for no target architecture. This will rapidly run into errors. | ||
#elif defined TARGET_ERROR | ||
# error Please specify the TARGET as either RPI or NONE (default) | ||
#else | ||
# error Please ensure you compile the driver with the makefile provided | ||
#endif | ||
|
||
|
||
#if defined TYPE_STANDALONE | ||
// Disables all logging | ||
# define NO_LOG | ||
// Disables external memory management | ||
# define MEM_INTERNAL_MANAGER | ||
// Disables external memory reservation | ||
# define MEM_NO_RESERVE | ||
#elif defined TYPE_LOWLEVEL | ||
// Disables external memory management | ||
# define MEM_INTERNAL_MANAGER | ||
# define MEM_NO_RESERVE | ||
#elif defined TYPE_DRIVER | ||
#elif defined TYPE_ERROR | ||
# error Please specify the TYPE as either STANDALONE, LOWLEVEL (default) or DRIVER | ||
#else | ||
# error Please ensure you compile the driver with the makefile provided | ||
#endif |
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,149 @@ | ||
/****************************************************************************** | ||
* device/hid/hid.h | ||
* by Alex Chadwick | ||
* | ||
* A light weight implementation of the USB protocol stack fit for a simple | ||
* driver. | ||
* | ||
* device/hid/hid.h contains definitions relating to generic human interface | ||
* devices. Information about the hid reports is in device/hid/report.h. | ||
******************************************************************************/ | ||
#include <types.h> | ||
#include <usbd/device.h> | ||
|
||
/** | ||
\brief The human interface device descriptor information. | ||
The hid descriptor structure defined in the USB HID 1.11 manual in 6.2.1. | ||
*/ | ||
struct HidDescriptor { | ||
u8 DescriptorLength; // +0x0 | ||
enum DescriptorType DescriptorType : 8; // +0x1 | ||
u16 HidVersion; // (bcd version) +0x2 | ||
enum HidCountry { | ||
CountryNotSupported = 0, | ||
Arabic = 1, | ||
Belgian = 2, | ||
CanadianBilingual = 3, | ||
CanadianFrench = 4, | ||
CzechRepublic = 5, | ||
Danish = 6, | ||
Finnish = 7, | ||
French = 8, | ||
German = 9, | ||
Greek = 10, | ||
Hebrew = 11, | ||
Hungary = 12, | ||
International = 13, | ||
Italian = 14, | ||
Japan = 15, | ||
Korean = 16, | ||
LatinAmerican = 17, | ||
Dutch = 18, | ||
Norwegian = 19, | ||
Persian = 20, | ||
Poland= 21, | ||
Portuguese = 22, | ||
Russian = 23, | ||
Slovakian = 24, | ||
Spanish = 25, | ||
Swedish = 26, | ||
SwissFrench = 27, | ||
SwissGerman = 28, | ||
Switzerland = 29, | ||
Taiwan = 30, | ||
TurkishQ = 31, | ||
EnglishUk = 32, | ||
EnglishUs = 33, | ||
Yugoslavian = 34, | ||
TurkishF = 35, | ||
} Countrycode : 8; // +0x4 | ||
u8 DescriptorCount; // +0x5 | ||
struct { | ||
enum DescriptorType Type : 8; // +0x0 | ||
u16 Length; // +0x1 | ||
} OptionalDescriptors[]; // +0x6 (a number of optional descriptors up to DescriptorCount) | ||
}; | ||
|
||
/** | ||
\brief The possible types of hid reports. | ||
The possible hid reports defined in the USB HID 1.11 manual in 7.2.1. | ||
*/ | ||
enum HidReportType { | ||
Input = 1, | ||
Output = 2, | ||
Feature = 3, | ||
}; | ||
|
||
/** The DeviceDriver field in UsbDriverDataHeader for hid devices. */ | ||
#define DeviceDriverHid 0x48494430 | ||
|
||
/** | ||
\brief Hid specific data. | ||
The contents of the driver data field for hid devices. Chains to | ||
allow a stacked driver. | ||
*/ | ||
struct HidDevice { | ||
struct UsbDriverDataHeader Header; | ||
struct HidDescriptor *Descriptor; | ||
struct HidParserResult *ParserResult; | ||
struct UsbDriverDataHeader *DriverData; | ||
|
||
// HID event handlers | ||
void (*HidDetached)(struct UsbDevice* device); | ||
void (*HidDeallocate)(struct UsbDevice* device); | ||
}; | ||
|
||
#define HidUsageAttachCount 10 | ||
|
||
/** | ||
\brief Methods to attach an interface of particular hid desktop usage. | ||
The application desktop usage of the interface is the index into this array | ||
of methods. The array is populated by ConfigurationLoad(). | ||
*/ | ||
extern Result (*HidUsageAttach[HidUsageAttachCount])(struct UsbDevice *device, u32 interfaceNumber); | ||
|
||
/** | ||
\brief Retrieves a hid report. | ||
Performs a hid get report request as defined in in the USB HID 1.11 manual | ||
in 7.2.1. | ||
*/ | ||
Result HidGetReport(struct UsbDevice *device, enum HidReportType reportType, | ||
u8 reportId, u8 interface, u32 bufferLength, void* buffer); | ||
|
||
/** | ||
\brief Sends a hid report. | ||
Performs a hid set report request as defined in in the USB HID 1.11 manual | ||
in 7.2.2. | ||
*/ | ||
Result HidSetReport(struct UsbDevice *device, enum HidReportType reportType, | ||
u8 reportId, u8 interface, u32 bufferLength, void* buffer); | ||
|
||
/** | ||
\brief Updates the device with the values of a report. | ||
Writes back the current values of a report in memory to the device. | ||
Implemented using HidSetReport, not interrupts. | ||
*/ | ||
Result HidWriteDevice(struct UsbDevice *device, u8 report); | ||
|
||
/** | ||
\brief Updates a report with the values from the device. | ||
Reads the current values of a report from the device into memory. Implemented | ||
using HidGetReport not interrupts. | ||
*/ | ||
Result HidReadDevice(struct UsbDevice *device, u8 report); | ||
|
||
/** | ||
\brief Enumerates a device as a HID device. | ||
Checks a device to see if it appears to be a HID device, and, if so, loads | ||
its hid and report descriptors to see what it can do. | ||
*/ | ||
Result HidAttach(struct UsbDevice *device, u32 interfaceNumber); |
Oops, something went wrong.