fixed white space

This commit is contained in:
Mark VanderVoord
2016-01-04 20:00:32 -05:00
parent 3fa4de14be
commit 2ac0ccb27b
100 changed files with 8282 additions and 8282 deletions
File diff suppressed because it is too large Load Diff
+42 -42
View File
@@ -1,42 +1,42 @@
#include "Types.h"
#include "AdcConductor.h"
#include "AdcModel.h"
#include "AdcHardware.h"
void AdcConductor_Init(void)
{
AdcHardware_Init();
}
void AdcConductor_Run(void)
{
if (AdcModel_DoGetSample() && AdcHardware_GetSampleComplete())
{
AdcModel_ProcessInput(AdcHardware_GetSample());
AdcHardware_StartConversion();
}
}
bool AdcConductor_JustHereToTest(void)
{
EXAMPLE_STRUCT_T ExampleStruct;
ExampleStruct.x = 5;
ExampleStruct.y = 7;
return AdcModel_DoNothingExceptTestASpecialType(ExampleStruct);
}
bool AdcConductor_AlsoHereToTest(void)
{
EXAMPLE_STRUCT_T example = AdcModel_DoNothingExceptReturnASpecialType();
return ((example.x == 99) && (example.y == 1));
}
bool AdcConductor_YetAnotherTest(void)
{
uint32 example = 3;
return AdModel_DoNothingExceptTestPointers(&example);
}
#include "Types.h"
#include "AdcConductor.h"
#include "AdcModel.h"
#include "AdcHardware.h"
void AdcConductor_Init(void)
{
AdcHardware_Init();
}
void AdcConductor_Run(void)
{
if (AdcModel_DoGetSample() && AdcHardware_GetSampleComplete())
{
AdcModel_ProcessInput(AdcHardware_GetSample());
AdcHardware_StartConversion();
}
}
bool AdcConductor_JustHereToTest(void)
{
EXAMPLE_STRUCT_T ExampleStruct;
ExampleStruct.x = 5;
ExampleStruct.y = 7;
return AdcModel_DoNothingExceptTestASpecialType(ExampleStruct);
}
bool AdcConductor_AlsoHereToTest(void)
{
EXAMPLE_STRUCT_T example = AdcModel_DoNothingExceptReturnASpecialType();
return ((example.x == 99) && (example.y == 1));
}
bool AdcConductor_YetAnotherTest(void)
{
uint32 example = 3;
return AdModel_DoNothingExceptTestPointers(&example);
}
+11 -11
View File
@@ -1,11 +1,11 @@
#ifndef _ADCCONDUCTOR_H
#define _ADCCONDUCTOR_H
void AdcConductor_Init(void);
void AdcConductor_Run(void);
bool AdcConductor_JustHereToTest(void);
bool AdcConductor_AlsoHereToTest(void);
bool AdcConductor_YetAnotherTest(void);
#endif // _ADCCONDUCTOR_H
#ifndef _ADCCONDUCTOR_H
#define _ADCCONDUCTOR_H
void AdcConductor_Init(void);
void AdcConductor_Run(void);
bool AdcConductor_JustHereToTest(void);
bool AdcConductor_AlsoHereToTest(void);
bool AdcConductor_YetAnotherTest(void);
#endif // _ADCCONDUCTOR_H
+27 -27
View File
@@ -1,27 +1,27 @@
#include "Types.h"
#include "AdcHardware.h"
#include "AdcHardwareConfigurator.h"
#include "AdcTemperatureSensor.h"
void AdcHardware_Init(void)
{
Adc_Reset();
Adc_ConfigureMode();
Adc_EnableTemperatureChannel();
Adc_StartTemperatureSensorConversion();
}
void AdcHardware_StartConversion(void)
{
Adc_StartTemperatureSensorConversion();
}
bool AdcHardware_GetSampleComplete(void)
{
return Adc_TemperatureSensorSampleReady();
}
uint16 AdcHardware_GetSample(void)
{
return Adc_ReadTemperatureSensor();
}
#include "Types.h"
#include "AdcHardware.h"
#include "AdcHardwareConfigurator.h"
#include "AdcTemperatureSensor.h"
void AdcHardware_Init(void)
{
Adc_Reset();
Adc_ConfigureMode();
Adc_EnableTemperatureChannel();
Adc_StartTemperatureSensorConversion();
}
void AdcHardware_StartConversion(void)
{
Adc_StartTemperatureSensorConversion();
}
bool AdcHardware_GetSampleComplete(void)
{
return Adc_TemperatureSensorSampleReady();
}
uint16 AdcHardware_GetSample(void)
{
return Adc_ReadTemperatureSensor();
}
+9 -9
View File
@@ -1,9 +1,9 @@
#ifndef _ADCHARDWARE_H
#define _ADCHARDWARE_H
void AdcHardware_Init(void);
void AdcHardware_StartConversion(void);
bool AdcHardware_GetSampleComplete(void);
uint16 AdcHardware_GetSample(void);
#endif // _ADCHARDWARE_H
#ifndef _ADCHARDWARE_H
#define _ADCHARDWARE_H
void AdcHardware_Init(void);
void AdcHardware_StartConversion(void);
bool AdcHardware_GetSampleComplete(void);
uint16 AdcHardware_GetSample(void);
#endif // _ADCHARDWARE_H
@@ -1,18 +1,18 @@
#include "Types.h"
#include "AdcHardwareConfigurator.h"
#include "ModelConfig.h"
void Adc_Reset(void)
{
AT91C_BASE_ADC->ADC_CR = AT91C_ADC_SWRST;
}
void Adc_ConfigureMode(void)
{
AT91C_BASE_ADC->ADC_MR = (((uint32)11) << 8) | (((uint32)4) << 16);
}
void Adc_EnableTemperatureChannel(void)
{
AT91C_BASE_ADC->ADC_CHER = 0x10;
}
#include "Types.h"
#include "AdcHardwareConfigurator.h"
#include "ModelConfig.h"
void Adc_Reset(void)
{
AT91C_BASE_ADC->ADC_CR = AT91C_ADC_SWRST;
}
void Adc_ConfigureMode(void)
{
AT91C_BASE_ADC->ADC_MR = (((uint32)11) << 8) | (((uint32)4) << 16);
}
void Adc_EnableTemperatureChannel(void)
{
AT91C_BASE_ADC->ADC_CHER = 0x10;
}
@@ -1,10 +1,10 @@
#ifndef _ADCHARDWARECONFIGURATOR_H
#define _ADCHARDWARECONFIGURATOR_H
#include "Types.h"
void Adc_Reset(void);
void Adc_ConfigureMode(void);
void Adc_EnableTemperatureChannel(void);
#endif // _ADCHARDWARECONFIGURATOR_H
#ifndef _ADCHARDWARECONFIGURATOR_H
#define _ADCHARDWARECONFIGURATOR_H
#include "Types.h"
void Adc_Reset(void);
void Adc_ConfigureMode(void);
void Adc_EnableTemperatureChannel(void);
#endif // _ADCHARDWARECONFIGURATOR_H
+33 -33
View File
@@ -1,33 +1,33 @@
#include "AdcModel.h"
#include "TaskScheduler.h"
#include "TemperatureCalculator.h"
#include "TemperatureFilter.h"
bool AdcModel_DoGetSample(void)
{
return TaskScheduler_DoAdc();
}
void AdcModel_ProcessInput(uint16 millivolts)
{
TemperatureFilter_ProcessInput(TemperatureCalculator_Calculate(millivolts));
}
bool AdcModel_DoNothingExceptTestASpecialType(EXAMPLE_STRUCT_T ExampleStruct)
{
//This doesn't really do anything. it's only here to make sure I can compare a struct.
return FALSE;
}
bool AdModel_DoNothingExceptTestPointers(uint32* pExample)
{
//This doesn't really do anything. it's only here to make sure I can compare a pointer value.
return FALSE;
}
EXAMPLE_STRUCT_T AdcModel_DoNothingExceptReturnASpecialType(void)
{
EXAMPLE_STRUCT_T example; //again, this just is here to test that I can return a struct
example.x = 99;
example.y = 1;
return example;
}
#include "AdcModel.h"
#include "TaskScheduler.h"
#include "TemperatureCalculator.h"
#include "TemperatureFilter.h"
bool AdcModel_DoGetSample(void)
{
return TaskScheduler_DoAdc();
}
void AdcModel_ProcessInput(uint16 millivolts)
{
TemperatureFilter_ProcessInput(TemperatureCalculator_Calculate(millivolts));
}
bool AdcModel_DoNothingExceptTestASpecialType(EXAMPLE_STRUCT_T ExampleStruct)
{
//This doesn't really do anything. it's only here to make sure I can compare a struct.
return FALSE;
}
bool AdModel_DoNothingExceptTestPointers(uint32* pExample)
{
//This doesn't really do anything. it's only here to make sure I can compare a pointer value.
return FALSE;
}
EXAMPLE_STRUCT_T AdcModel_DoNothingExceptReturnASpecialType(void)
{
EXAMPLE_STRUCT_T example; //again, this just is here to test that I can return a struct
example.x = 99;
example.y = 1;
return example;
}
+13 -13
View File
@@ -1,13 +1,13 @@
#ifndef _ADCMODEL_H
#define _ADCMODEL_H
#include "Types.h"
bool AdcModel_DoGetSample(void);
void AdcModel_ProcessInput(uint16 millivolts);
bool AdcModel_DoNothingExceptTestASpecialType(EXAMPLE_STRUCT_T ExampleStruct);
bool AdModel_DoNothingExceptTestPointers(uint32* pExample);
EXAMPLE_STRUCT_T AdcModel_DoNothingExceptReturnASpecialType(void);
#endif // _ADCMODEL_H
#ifndef _ADCMODEL_H
#define _ADCMODEL_H
#include "Types.h"
bool AdcModel_DoGetSample(void);
void AdcModel_ProcessInput(uint16 millivolts);
bool AdcModel_DoNothingExceptTestASpecialType(EXAMPLE_STRUCT_T ExampleStruct);
bool AdModel_DoNothingExceptTestPointers(uint32* pExample);
EXAMPLE_STRUCT_T AdcModel_DoNothingExceptReturnASpecialType(void);
#endif // _ADCMODEL_H
+51 -51
View File
@@ -1,51 +1,51 @@
#include "Types.h"
#include "AdcTemperatureSensor.h"
static inline uint32 ConvertAdcCountsToPicovolts(uint32 counts);
static inline uint16 ConvertPicovoltsToMillivolts(uint32 picovolts);
//
// PUBLIC METHODS
//
void Adc_StartTemperatureSensorConversion(void)
{
AT91C_BASE_ADC->ADC_CR = AT91C_ADC_START;
}
bool Adc_TemperatureSensorSampleReady(void)
{
return ((AT91C_BASE_ADC->ADC_SR & AT91C_ADC_EOC4) == AT91C_ADC_EOC4);
}
uint16 Adc_ReadTemperatureSensor(void)
{
uint32 picovolts = ConvertAdcCountsToPicovolts(AT91C_BASE_ADC->ADC_CDR4);
return ConvertPicovoltsToMillivolts(picovolts);
}
//
// PRIVATE HELPERS
//
static inline uint32 ConvertAdcCountsToPicovolts(uint32 counts)
{
// ADC bit weight at 10-bit resolution with 3.0V reference = 2.9296875 mV/LSB
uint32 picovoltsPerAdcCount = 2929688;
// Shift decimal point by 6 places to preserve accuracy in fixed-point math
return counts * picovoltsPerAdcCount;
}
static inline uint16 ConvertPicovoltsToMillivolts(uint32 picovolts)
{
const uint32 halfMillivoltInPicovolts = 500000;
const uint32 picovoltsPerMillivolt = 1000000;
// Add 0.5 mV to result so that truncation yields properly rounded result
picovolts += halfMillivoltInPicovolts;
// Divide appropriately to convert to millivolts
return (uint16)(picovolts / picovoltsPerMillivolt);
}
#include "Types.h"
#include "AdcTemperatureSensor.h"
static inline uint32 ConvertAdcCountsToPicovolts(uint32 counts);
static inline uint16 ConvertPicovoltsToMillivolts(uint32 picovolts);
//
// PUBLIC METHODS
//
void Adc_StartTemperatureSensorConversion(void)
{
AT91C_BASE_ADC->ADC_CR = AT91C_ADC_START;
}
bool Adc_TemperatureSensorSampleReady(void)
{
return ((AT91C_BASE_ADC->ADC_SR & AT91C_ADC_EOC4) == AT91C_ADC_EOC4);
}
uint16 Adc_ReadTemperatureSensor(void)
{
uint32 picovolts = ConvertAdcCountsToPicovolts(AT91C_BASE_ADC->ADC_CDR4);
return ConvertPicovoltsToMillivolts(picovolts);
}
//
// PRIVATE HELPERS
//
static inline uint32 ConvertAdcCountsToPicovolts(uint32 counts)
{
// ADC bit weight at 10-bit resolution with 3.0V reference = 2.9296875 mV/LSB
uint32 picovoltsPerAdcCount = 2929688;
// Shift decimal point by 6 places to preserve accuracy in fixed-point math
return counts * picovoltsPerAdcCount;
}
static inline uint16 ConvertPicovoltsToMillivolts(uint32 picovolts)
{
const uint32 halfMillivoltInPicovolts = 500000;
const uint32 picovoltsPerMillivolt = 1000000;
// Add 0.5 mV to result so that truncation yields properly rounded result
picovolts += halfMillivoltInPicovolts;
// Divide appropriately to convert to millivolts
return (uint16)(picovolts / picovoltsPerMillivolt);
}
+10 -10
View File
@@ -1,10 +1,10 @@
#ifndef _ADCTEMPERATURESENSOR_H
#define _ADCTEMPERATURESENSOR_H
#include "Types.h"
void Adc_StartTemperatureSensorConversion(void);
bool Adc_TemperatureSensorSampleReady(void);
uint16 Adc_ReadTemperatureSensor(void);
#endif // _ADCTEMPERATURESENSOR_H
#ifndef _ADCTEMPERATURESENSOR_H
#define _ADCTEMPERATURESENSOR_H
#include "Types.h"
void Adc_StartTemperatureSensorConversion(void);
bool Adc_TemperatureSensorSampleReady(void);
uint16 Adc_ReadTemperatureSensor(void);
#endif // _ADCTEMPERATURESENSOR_H
+25 -25
View File
@@ -1,25 +1,25 @@
#include "Types.h"
#include "Executor.h"
#include "Model.h"
#include "UsartConductor.h"
#include "TimerConductor.h"
#include "AdcConductor.h"
#include "IntrinsicsWrapper.h"
void Executor_Init(void)
{
Model_Init();
UsartConductor_Init();
AdcConductor_Init();
TimerConductor_Init();
Interrupt_Enable();
}
bool Executor_Run(void)
{
UsartConductor_Run();
TimerConductor_Run();
AdcConductor_Run();
return TRUE;
}
#include "Types.h"
#include "Executor.h"
#include "Model.h"
#include "UsartConductor.h"
#include "TimerConductor.h"
#include "AdcConductor.h"
#include "IntrinsicsWrapper.h"
void Executor_Init(void)
{
Model_Init();
UsartConductor_Init();
AdcConductor_Init();
TimerConductor_Init();
Interrupt_Enable();
}
bool Executor_Run(void)
{
UsartConductor_Run();
TimerConductor_Run();
AdcConductor_Run();
return TRUE;
}
+9 -9
View File
@@ -1,9 +1,9 @@
#ifndef _EXECUTOR_H
#define _EXECUTOR_H
#include "Types.h"
void Executor_Init(void);
bool Executor_Run(void);
#endif // _EXECUTOR_H
#ifndef _EXECUTOR_H
#define _EXECUTOR_H
#include "Types.h"
void Executor_Init(void);
bool Executor_Run(void);
#endif // _EXECUTOR_H
+18 -18
View File
@@ -1,18 +1,18 @@
#include "IntrinsicsWrapper.h"
#ifdef __ICCARM__
#include <intrinsics.h>
#endif
void Interrupt_Enable(void)
{
#ifdef __ICCARM__
__enable_interrupt();
#endif
}
void Interrupt_Disable(void)
{
#ifdef __ICCARM__
__disable_interrupt();
#endif
}
#include "IntrinsicsWrapper.h"
#ifdef __ICCARM__
#include <intrinsics.h>
#endif
void Interrupt_Enable(void)
{
#ifdef __ICCARM__
__enable_interrupt();
#endif
}
void Interrupt_Disable(void)
{
#ifdef __ICCARM__
__disable_interrupt();
#endif
}
+7 -7
View File
@@ -1,7 +1,7 @@
#ifndef _INTRINSICS_WRAPPER_H
#define _INTRINSICS_WRAPPER_H
void Interrupt_Enable(void);
void Interrupt_Disable(void);
#endif // _INTRINSICS_WRAPPER_H
#ifndef _INTRINSICS_WRAPPER_H
#define _INTRINSICS_WRAPPER_H
void Interrupt_Enable(void);
void Interrupt_Disable(void);
#endif // _INTRINSICS_WRAPPER_H
+46 -46
View File
@@ -1,46 +1,46 @@
#include "Types.h"
#include "IntrinsicsWrapper.h"
#include "Executor.h"
#include "Model.h"
#include "TaskScheduler.h"
#include "TemperatureCalculator.h"
#include "TemperatureFilter.h"
#include "UsartConductor.h"
#include "UsartHardware.h"
#include "UsartConfigurator.h"
#include "UsartPutChar.h"
#include "UsartModel.h"
#include "UsartBaudRateRegisterCalculator.h"
#include "UsartTransmitBufferStatus.h"
#include "TimerConductor.h"
#include "TimerHardware.h"
#include "TimerConfigurator.h"
#include "TimerInterruptConfigurator.h"
#include "TimerInterruptHandler.h"
#include "TimerModel.h"
#include "AdcConductor.h"
#include "AdcHardware.h"
#include "AdcHardwareConfigurator.h"
#include "AdcTemperatureSensor.h"
#include "AdcModel.h"
int AppMain(void)
{
Executor_Init();
while(Executor_Run());
return 0;
}
#ifndef TEST
int main(void)
{
return AppMain();
}
#endif // TEST
#include "Types.h"
#include "IntrinsicsWrapper.h"
#include "Executor.h"
#include "Model.h"
#include "TaskScheduler.h"
#include "TemperatureCalculator.h"
#include "TemperatureFilter.h"
#include "UsartConductor.h"
#include "UsartHardware.h"
#include "UsartConfigurator.h"
#include "UsartPutChar.h"
#include "UsartModel.h"
#include "UsartBaudRateRegisterCalculator.h"
#include "UsartTransmitBufferStatus.h"
#include "TimerConductor.h"
#include "TimerHardware.h"
#include "TimerConfigurator.h"
#include "TimerInterruptConfigurator.h"
#include "TimerInterruptHandler.h"
#include "TimerModel.h"
#include "AdcConductor.h"
#include "AdcHardware.h"
#include "AdcHardwareConfigurator.h"
#include "AdcTemperatureSensor.h"
#include "AdcModel.h"
int AppMain(void)
{
Executor_Init();
while(Executor_Run());
return 0;
}
#ifndef TEST
int main(void)
{
return AppMain();
}
#endif // TEST
+7 -7
View File
@@ -1,7 +1,7 @@
#ifndef _MAIN_H_
#define _MAIN_H_
int AppMain(void);
int main(void);
#endif // _MAIN_H_
#ifndef _MAIN_H_
#define _MAIN_H_
int AppMain(void);
int main(void);
#endif // _MAIN_H_
+10 -10
View File
@@ -1,10 +1,10 @@
#include "Model.h"
#include "TaskScheduler.h"
#include "TemperatureFilter.h"
void Model_Init(void)
{
TaskScheduler_Init();
TemperatureFilter_Init();
}
#include "Model.h"
#include "TaskScheduler.h"
#include "TemperatureFilter.h"
void Model_Init(void)
{
TaskScheduler_Init();
TemperatureFilter_Init();
}
+8 -8
View File
@@ -1,8 +1,8 @@
#ifndef _MODEL_H
#define _MODEL_H
#include "Types.h"
void Model_Init(void);
#endif // _MODEL_H
#ifndef _MODEL_H
#define _MODEL_H
#include "Types.h"
void Model_Init(void);
#endif // _MODEL_H
+7 -7
View File
@@ -1,7 +1,7 @@
#ifndef _MODELCONFIG_H
#define _MODELCONFIG_H
#define MASTER_CLOCK 48054857 // Master Clock
#define USART0_BAUDRATE 115200 // USART Baudrate
#endif // _MODELCONFIG_H
#ifndef _MODELCONFIG_H
#define _MODELCONFIG_H
#define MASTER_CLOCK 48054857 // Master Clock
#define USART0_BAUDRATE 115200 // USART Baudrate
#endif // _MODELCONFIG_H
+72 -72
View File
@@ -1,72 +1,72 @@
#include "Types.h"
#include "TaskScheduler.h"
typedef struct _Task
{
bool doIt;
uint32 period;
uint32 startTime;
} Task;
typedef struct _TaskSchedulerInstance
{
Task usart;
Task adc;
} TaskSchedulerInstance;
static TaskSchedulerInstance this;
void TaskScheduler_Init(void)
{
this.usart.doIt = FALSE;
this.usart.startTime = 0;
//The correct period
this.usart.period = 1000;
this.adc.doIt = FALSE;
this.adc.startTime = 0;
this.adc.period = 100;
}
void TaskScheduler_Update(uint32 time)
{
if ((time - this.usart.startTime) >= this.usart.period)
{
this.usart.doIt = TRUE;
this.usart.startTime = time - (time % this.usart.period);
}
if ((time - this.adc.startTime) >= this.adc.period)
{
this.adc.doIt = TRUE;
this.adc.startTime = time - (time % this.adc.period);
}
}
bool TaskScheduler_DoUsart(void)
{
bool doIt = FALSE;
if (this.usart.doIt)
{
doIt = TRUE;
this.usart.doIt = FALSE;
}
return doIt;
}
bool TaskScheduler_DoAdc(void)
{
bool doIt = FALSE;
if (this.adc.doIt)
{
doIt = TRUE;
this.adc.doIt = FALSE;
}
return doIt;
}
#include "Types.h"
#include "TaskScheduler.h"
typedef struct _Task
{
bool doIt;
uint32 period;
uint32 startTime;
} Task;
typedef struct _TaskSchedulerInstance
{
Task usart;
Task adc;
} TaskSchedulerInstance;
static TaskSchedulerInstance this;
void TaskScheduler_Init(void)
{
this.usart.doIt = FALSE;
this.usart.startTime = 0;
//The correct period
this.usart.period = 1000;
this.adc.doIt = FALSE;
this.adc.startTime = 0;
this.adc.period = 100;
}
void TaskScheduler_Update(uint32 time)
{
if ((time - this.usart.startTime) >= this.usart.period)
{
this.usart.doIt = TRUE;
this.usart.startTime = time - (time % this.usart.period);
}
if ((time - this.adc.startTime) >= this.adc.period)
{
this.adc.doIt = TRUE;
this.adc.startTime = time - (time % this.adc.period);
}
}
bool TaskScheduler_DoUsart(void)
{
bool doIt = FALSE;
if (this.usart.doIt)
{
doIt = TRUE;
this.usart.doIt = FALSE;
}
return doIt;
}
bool TaskScheduler_DoAdc(void)
{
bool doIt = FALSE;
if (this.adc.doIt)
{
doIt = TRUE;
this.adc.doIt = FALSE;
}
return doIt;
}
+11 -11
View File
@@ -1,11 +1,11 @@
#ifndef _TASKSCHEDULER_H
#define _TASKSCHEDULER_H
#include "Types.h"
void TaskScheduler_Init(void);
void TaskScheduler_Update(uint32 time);
bool TaskScheduler_DoUsart(void);
bool TaskScheduler_DoAdc(void);
#endif // _TASKSCHEDULER_H
#ifndef _TASKSCHEDULER_H
#define _TASKSCHEDULER_H
#include "Types.h"
void TaskScheduler_Init(void);
void TaskScheduler_Update(uint32 time);
bool TaskScheduler_DoUsart(void);
bool TaskScheduler_DoAdc(void);
#endif // _TASKSCHEDULER_H
@@ -1,27 +1,27 @@
#include "Types.h"
#include "TemperatureCalculator.h"
#include <math.h>
#ifndef logl
#define logl log
#endif
float TemperatureCalculator_Calculate(uint16 millivolts)
{
const double supply_voltage = 3.0;
const double series_resistance = 5000;
const double coefficient_A = 316589.698;
const double coefficient_B = -0.1382009;
double sensor_voltage = ((double)millivolts / 1000);
double resistance;
if (millivolts == 0)
{
return -INFINITY;
}
// Series resistor is 5k Ohms; Reference voltage is 3.0V
// R(t) = A * e^(B*t); R is resistance of thermisor; t is temperature in C
resistance = ((supply_voltage * series_resistance) / sensor_voltage) - series_resistance;
return (float)(logl(resistance / coefficient_A) / coefficient_B);
}
#include "Types.h"
#include "TemperatureCalculator.h"
#include <math.h>
#ifndef logl
#define logl log
#endif
float TemperatureCalculator_Calculate(uint16 millivolts)
{
const double supply_voltage = 3.0;
const double series_resistance = 5000;
const double coefficient_A = 316589.698;
const double coefficient_B = -0.1382009;
double sensor_voltage = ((double)millivolts / 1000);
double resistance;
if (millivolts == 0)
{
return -INFINITY;
}
// Series resistor is 5k Ohms; Reference voltage is 3.0V
// R(t) = A * e^(B*t); R is resistance of thermisor; t is temperature in C
resistance = ((supply_voltage * series_resistance) / sensor_voltage) - series_resistance;
return (float)(logl(resistance / coefficient_A) / coefficient_B);
}
@@ -1,6 +1,6 @@
#ifndef _TEMPERATURECALCULATOR_H
#define _TEMPERATURECALCULATOR_H
float TemperatureCalculator_Calculate(uint16 millivolts);
#endif // _TEMPERATURECALCULATOR_H
#ifndef _TEMPERATURECALCULATOR_H
#define _TEMPERATURECALCULATOR_H
float TemperatureCalculator_Calculate(uint16 millivolts);
#endif // _TEMPERATURECALCULATOR_H
+39 -39
View File
@@ -1,39 +1,39 @@
#include "Types.h"
#include "TemperatureFilter.h"
#include <math.h>
static bool initialized;
static float temperatureInCelcius;
void TemperatureFilter_Init(void)
{
initialized = FALSE;
temperatureInCelcius = -INFINITY;
}
float TemperatureFilter_GetTemperatureInCelcius(void)
{
return temperatureInCelcius;
}
void TemperatureFilter_ProcessInput(float temperature)
{
if (!initialized)
{
temperatureInCelcius = temperature;
initialized = TRUE;
}
else
{
if (temperature == +INFINITY ||
temperature == -INFINITY ||
temperature == +NAN ||
temperature == -NAN)
{
initialized = FALSE;
temperature = -INFINITY;
}
temperatureInCelcius = (temperatureInCelcius * 0.75f) + (temperature * 0.25);
}
}
#include "Types.h"
#include "TemperatureFilter.h"
#include <math.h>
static bool initialized;
static float temperatureInCelcius;
void TemperatureFilter_Init(void)
{
initialized = FALSE;
temperatureInCelcius = -INFINITY;
}
float TemperatureFilter_GetTemperatureInCelcius(void)
{
return temperatureInCelcius;
}
void TemperatureFilter_ProcessInput(float temperature)
{
if (!initialized)
{
temperatureInCelcius = temperature;
initialized = TRUE;
}
else
{
if (temperature == +INFINITY ||
temperature == -INFINITY ||
temperature == +NAN ||
temperature == -NAN)
{
initialized = FALSE;
temperature = -INFINITY;
}
temperatureInCelcius = (temperatureInCelcius * 0.75f) + (temperature * 0.25);
}
}
+10 -10
View File
@@ -1,10 +1,10 @@
#ifndef _TEMPERATUREFILTER_H
#define _TEMPERATUREFILTER_H
#include "Types.h"
void TemperatureFilter_Init(void);
float TemperatureFilter_GetTemperatureInCelcius(void);
void TemperatureFilter_ProcessInput(float temperature);
#endif // _TEMPERATUREFILTER_H
#ifndef _TEMPERATUREFILTER_H
#define _TEMPERATUREFILTER_H
#include "Types.h"
void TemperatureFilter_Init(void);
float TemperatureFilter_GetTemperatureInCelcius(void);
void TemperatureFilter_ProcessInput(float temperature);
#endif // _TEMPERATUREFILTER_H
+15 -15
View File
@@ -1,15 +1,15 @@
#include "Types.h"
#include "TimerConductor.h"
#include "TimerModel.h"
#include "TimerHardware.h"
#include "TimerInterruptHandler.h"
void TimerConductor_Init(void)
{
TimerHardware_Init();
}
void TimerConductor_Run(void)
{
TimerModel_UpdateTime(Timer_GetSystemTime());
}
#include "Types.h"
#include "TimerConductor.h"
#include "TimerModel.h"
#include "TimerHardware.h"
#include "TimerInterruptHandler.h"
void TimerConductor_Init(void)
{
TimerHardware_Init();
}
void TimerConductor_Run(void)
{
TimerModel_UpdateTime(Timer_GetSystemTime());
}
+9 -9
View File
@@ -1,9 +1,9 @@
#ifndef _TIMERCONDUCTOR_H
#define _TIMERCONDUCTOR_H
#include "Types.h"
void TimerConductor_Init(void);
void TimerConductor_Run(void);
#endif // _TIMERCONDUCTOR_H
#ifndef _TIMERCONDUCTOR_H
#define _TIMERCONDUCTOR_H
#include "Types.h"
void TimerConductor_Init(void);
void TimerConductor_Run(void);
#endif // _TIMERCONDUCTOR_H
+51 -51
View File
@@ -1,51 +1,51 @@
#include "Types.h"
#include "TimerConfigurator.h"
#include "TimerInterruptConfigurator.h"
void Timer_EnablePeripheralClocks(void)
{
AT91C_BASE_PMC->PMC_PCER = TIMER0_CLOCK_ENABLE | PIOB_CLOCK_ENABLE;
}
void Timer_Reset(void)
{
uint32 dummy;
AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKDIS;
AT91C_BASE_TC0->TC_IDR = 0xffffffff;
dummy = AT91C_BASE_TC0->TC_SR;
dummy = dummy;
}
void Timer_ConfigureMode(void)
{
AT91C_BASE_TC0->TC_CMR = 0x000CC004; // ACPC=toggle TIOA on RC compare; mode=WAVE; WAVE_SEL=UP w/auto-trigger on RC compare; clock=MCK/1024
}
void Timer_ConfigurePeriod(void)
{
AT91C_BASE_TC0->TC_RC = 469; // 10ms period for timer clock source of MCK/1024 with MCK=48054857
}
void Timer_EnableOutputPin(void)
{
AT91C_BASE_PIOB->PIO_PDR = TIOA0_PIN_MASK;
}
void Timer_Enable(void)
{
AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKEN;
}
void Timer_ConfigureInterruptHandler(void)
{
Timer_DisableInterrupt();
Timer_ResetSystemTime();
Timer_ConfigureInterrupt();
Timer_EnableInterrupt();
}
void Timer_Start(void)
{
AT91C_BASE_TC0->TC_CCR = AT91C_TC_SWTRG;
}
#include "Types.h"
#include "TimerConfigurator.h"
#include "TimerInterruptConfigurator.h"
void Timer_EnablePeripheralClocks(void)
{
AT91C_BASE_PMC->PMC_PCER = TIMER0_CLOCK_ENABLE | PIOB_CLOCK_ENABLE;
}
void Timer_Reset(void)
{
uint32 dummy;
AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKDIS;
AT91C_BASE_TC0->TC_IDR = 0xffffffff;
dummy = AT91C_BASE_TC0->TC_SR;
dummy = dummy;
}
void Timer_ConfigureMode(void)
{
AT91C_BASE_TC0->TC_CMR = 0x000CC004; // ACPC=toggle TIOA on RC compare; mode=WAVE; WAVE_SEL=UP w/auto-trigger on RC compare; clock=MCK/1024
}
void Timer_ConfigurePeriod(void)
{
AT91C_BASE_TC0->TC_RC = 469; // 10ms period for timer clock source of MCK/1024 with MCK=48054857
}
void Timer_EnableOutputPin(void)
{
AT91C_BASE_PIOB->PIO_PDR = TIOA0_PIN_MASK;
}
void Timer_Enable(void)
{
AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKEN;
}
void Timer_ConfigureInterruptHandler(void)
{
Timer_DisableInterrupt();
Timer_ResetSystemTime();
Timer_ConfigureInterrupt();
Timer_EnableInterrupt();
}
void Timer_Start(void)
{
AT91C_BASE_TC0->TC_CCR = AT91C_TC_SWTRG;
}
+15 -15
View File
@@ -1,15 +1,15 @@
#ifndef _TIMERCONFIGURATOR_H
#define _TIMERCONFIGURATOR_H
#include "Types.h"
void Timer_EnablePeripheralClocks(void);
void Timer_Reset(void);
void Timer_ConfigureMode(void);
void Timer_ConfigurePeriod(void);
void Timer_EnableOutputPin(void);
void Timer_Enable(void);
void Timer_ConfigureInterruptHandler(void);
void Timer_Start(void);
#endif // _TIMERCONFIGURATOR_H
#ifndef _TIMERCONFIGURATOR_H
#define _TIMERCONFIGURATOR_H
#include "Types.h"
void Timer_EnablePeripheralClocks(void);
void Timer_Reset(void);
void Timer_ConfigureMode(void);
void Timer_ConfigurePeriod(void);
void Timer_EnableOutputPin(void);
void Timer_Enable(void);
void Timer_ConfigureInterruptHandler(void);
void Timer_Start(void);
#endif // _TIMERCONFIGURATOR_H
+15 -15
View File
@@ -1,15 +1,15 @@
#include "Types.h"
#include "TimerHardware.h"
#include "TimerConfigurator.h"
void TimerHardware_Init(void)
{
Timer_EnablePeripheralClocks();
Timer_Reset();
Timer_ConfigureMode();
Timer_ConfigurePeriod();
Timer_EnableOutputPin();
Timer_Enable();
Timer_ConfigureInterruptHandler();
Timer_Start();
}
#include "Types.h"
#include "TimerHardware.h"
#include "TimerConfigurator.h"
void TimerHardware_Init(void)
{
Timer_EnablePeripheralClocks();
Timer_Reset();
Timer_ConfigureMode();
Timer_ConfigurePeriod();
Timer_EnableOutputPin();
Timer_Enable();
Timer_ConfigureInterruptHandler();
Timer_Start();
}
+8 -8
View File
@@ -1,8 +1,8 @@
#ifndef _TIMERHARDWARE_H
#define _TIMERHARDWARE_H
#include "Types.h"
void TimerHardware_Init(void);
#endif // _TIMERHARDWARE_H
#ifndef _TIMERHARDWARE_H
#define _TIMERHARDWARE_H
#include "Types.h"
void TimerHardware_Init(void);
#endif // _TIMERHARDWARE_H
@@ -1,55 +1,55 @@
#include "Types.h"
#include "TimerInterruptConfigurator.h"
#include "TimerInterruptHandler.h"
static inline void SetInterruptHandler(void);
static inline void ConfigureInterruptSourceModeRegister(void);
static inline void ClearInterrupt(void);
static inline void EnableCompareInterruptForRegisterC(void);
void Timer_DisableInterrupt(void)
{
AT91C_BASE_AIC->AIC_IDCR = TIMER0_ID_MASK;
}
void Timer_ResetSystemTime(void)
{
Timer_SetSystemTime(0);
}
void Timer_ConfigureInterrupt(void)
{
SetInterruptHandler();
ConfigureInterruptSourceModeRegister();
ClearInterrupt();
EnableCompareInterruptForRegisterC();
}
void Timer_EnableInterrupt(void)
{
AT91C_BASE_AIC->AIC_IECR = TIMER0_ID_MASK;
}
//
// Helpers
//
static inline void SetInterruptHandler(void)
{
AT91C_BASE_AIC->AIC_SVR[AT91C_ID_TC0] = (uint32)Timer_InterruptHandler;
}
static inline void ConfigureInterruptSourceModeRegister(void)
{
AT91C_BASE_AIC->AIC_SMR[AT91C_ID_TC0] = 1;
}
static inline void ClearInterrupt(void)
{
AT91C_BASE_AIC->AIC_ICCR = TIMER0_ID_MASK;
}
static inline void EnableCompareInterruptForRegisterC(void)
{
AT91C_BASE_TC0->TC_IER = AT91C_TC_CPCS;
}
#include "Types.h"
#include "TimerInterruptConfigurator.h"
#include "TimerInterruptHandler.h"
static inline void SetInterruptHandler(void);
static inline void ConfigureInterruptSourceModeRegister(void);
static inline void ClearInterrupt(void);
static inline void EnableCompareInterruptForRegisterC(void);
void Timer_DisableInterrupt(void)
{
AT91C_BASE_AIC->AIC_IDCR = TIMER0_ID_MASK;
}
void Timer_ResetSystemTime(void)
{
Timer_SetSystemTime(0);
}
void Timer_ConfigureInterrupt(void)
{
SetInterruptHandler();
ConfigureInterruptSourceModeRegister();
ClearInterrupt();
EnableCompareInterruptForRegisterC();
}
void Timer_EnableInterrupt(void)
{
AT91C_BASE_AIC->AIC_IECR = TIMER0_ID_MASK;
}
//
// Helpers
//
static inline void SetInterruptHandler(void)
{
AT91C_BASE_AIC->AIC_SVR[AT91C_ID_TC0] = (uint32)Timer_InterruptHandler;
}
static inline void ConfigureInterruptSourceModeRegister(void)
{
AT91C_BASE_AIC->AIC_SMR[AT91C_ID_TC0] = 1;
}
static inline void ClearInterrupt(void)
{
AT91C_BASE_AIC->AIC_ICCR = TIMER0_ID_MASK;
}
static inline void EnableCompareInterruptForRegisterC(void)
{
AT91C_BASE_TC0->TC_IER = AT91C_TC_CPCS;
}
@@ -1,13 +1,13 @@
#ifndef _TIMERINTERRUPTCONFIGURATOR_H
#define _TIMERINTERRUPTCONFIGURATOR_H
#include "Types.h"
#define TIMER0_ID_MASK (((uint32)0x1) << AT91C_ID_TC0)
void Timer_DisableInterrupt(void);
void Timer_ResetSystemTime(void);
void Timer_ConfigureInterrupt(void);
void Timer_EnableInterrupt(void);
#endif // _TIMERINTERRUPTCONFIGURATOR_H
#ifndef _TIMERINTERRUPTCONFIGURATOR_H
#define _TIMERINTERRUPTCONFIGURATOR_H
#include "Types.h"
#define TIMER0_ID_MASK (((uint32)0x1) << AT91C_ID_TC0)
void Timer_DisableInterrupt(void);
void Timer_ResetSystemTime(void);
void Timer_ConfigureInterrupt(void);
void Timer_EnableInterrupt(void);
#endif // _TIMERINTERRUPTCONFIGURATOR_H
@@ -1,25 +1,25 @@
#include "Types.h"
#include "TimerInterruptHandler.h"
#include "TimerInterruptConfigurator.h"
static uint32 systemTime;
void Timer_SetSystemTime(uint32 time)
{
systemTime = time;
}
uint32 Timer_GetSystemTime(void)
{
return systemTime;
}
void Timer_InterruptHandler(void)
{
uint32 status = AT91C_BASE_TC0->TC_SR;
if (status & AT91C_TC_CPCS)
{
systemTime += 10;
}
}
#include "Types.h"
#include "TimerInterruptHandler.h"
#include "TimerInterruptConfigurator.h"
static uint32 systemTime;
void Timer_SetSystemTime(uint32 time)
{
systemTime = time;
}
uint32 Timer_GetSystemTime(void)
{
return systemTime;
}
void Timer_InterruptHandler(void)
{
uint32 status = AT91C_BASE_TC0->TC_SR;
if (status & AT91C_TC_CPCS)
{
systemTime += 10;
}
}
@@ -1,10 +1,10 @@
#ifndef _TIMERINTERRUPTHANDLER_H
#define _TIMERINTERRUPTHANDLER_H
#include "Types.h"
void Timer_SetSystemTime(uint32 time);
uint32 Timer_GetSystemTime(void);
void Timer_InterruptHandler(void);
#endif // _TIMERINTERRUPTHANDLER_H
#ifndef _TIMERINTERRUPTHANDLER_H
#define _TIMERINTERRUPTHANDLER_H
#include "Types.h"
void Timer_SetSystemTime(uint32 time);
uint32 Timer_GetSystemTime(void);
void Timer_InterruptHandler(void);
#endif // _TIMERINTERRUPTHANDLER_H
+9 -9
View File
@@ -1,9 +1,9 @@
#include "Types.h"
#include "TimerModel.h"
#include "TaskScheduler.h"
void TimerModel_UpdateTime(uint32 systemTime)
{
TaskScheduler_Update(systemTime);
}
#include "Types.h"
#include "TimerModel.h"
#include "TaskScheduler.h"
void TimerModel_UpdateTime(uint32 systemTime)
{
TaskScheduler_Update(systemTime);
}
+8 -8
View File
@@ -1,8 +1,8 @@
#ifndef _TIMERMODEL_H
#define _TIMERMODEL_H
#include "Types.h"
void TimerModel_UpdateTime(uint32 systemTime);
#endif // _TIMERMODEL_H
#ifndef _TIMERMODEL_H
#define _TIMERMODEL_H
#include "Types.h"
void TimerModel_UpdateTime(uint32 systemTime);
#endif // _TIMERMODEL_H
+103 -103
View File
@@ -1,103 +1,103 @@
#ifndef _MYTYPES_H_
#define _MYTYPES_H_
#include "AT91SAM7X256.h"
#include <math.h>
#ifndef __monitor
#define __monitor
#endif
// Peripheral Helper Definitions
#define USART0_CLOCK_ENABLE (AT91C_ID_US0)
#define USART0_TX_PIN (AT91C_PA1_TXD0)
#define TIMER0_CLOCK_ENABLE (((uint32)0x1) << AT91C_ID_TC0)
#define PIOA_CLOCK_ENABLE (((uint32)0x1) << AT91C_ID_PIOA)
#define PIOB_CLOCK_ENABLE (((uint32)0x1) << AT91C_ID_PIOB)
#define TIOA0_PIN_MASK (((uint32)0x1) << 23) // Timer/Counter Output Pin
// Application Type Definitions
typedef unsigned int uint32;
typedef int int32;
typedef unsigned short uint16;
typedef short int16;
typedef unsigned char uint8;
typedef char int8;
typedef char bool;
// Application Special Value Definitions
#ifndef TRUE
#define TRUE (1)
#endif
#ifndef FALSE
#define FALSE (0)
#endif
#ifndef NULL
#define NULL (0)
#endif // NULL
#define DONT_CARE (0)
#ifndef INFINITY
#define INFINITY (1.0 / 0.0)
#endif
#ifndef NAN
#define NAN (0.0 / 0.0)
#endif
// MIN/MAX Definitions for Standard Types
#ifndef INT8_MAX
#define INT8_MAX 127
#endif
#ifndef INT8_MIN
#define INT8_MIN (-128)
#endif
#ifndef UINT8_MAX
#define UINT8_MAX 0xFFU
#endif
#ifndef UINT8_MIN
#define UINT8_MIN 0x00U
#endif
#ifndef INT16_MAX
#define INT16_MAX 32767
#endif
#ifndef INT16_MIN
#define INT16_MIN (-32768)
#endif
#ifndef UINT16_MAX
#define UINT16_MAX 0xFFFFU
#endif
#ifndef UINT16_MIN
#define UINT16_MIN 0x0000U
#endif
#ifndef INT32_MAX
#define INT32_MAX 0x7FFFFFFF
#endif
#ifndef INT32_MIN
#define INT32_MIN (-INT32_MAX - 1)
#endif
#ifndef UINT32_MAX
#define UINT32_MAX 0xFFFFFFFFU
#endif
#ifndef UINT32_MIN
#define UINT32_MIN 0x00000000U
#endif
typedef struct _EXAMPLE_STRUCT_T
{
int x;
int y;
} EXAMPLE_STRUCT_T;
#endif // _MYTYPES_H_
#ifndef _MYTYPES_H_
#define _MYTYPES_H_
#include "AT91SAM7X256.h"
#include <math.h>
#ifndef __monitor
#define __monitor
#endif
// Peripheral Helper Definitions
#define USART0_CLOCK_ENABLE (AT91C_ID_US0)
#define USART0_TX_PIN (AT91C_PA1_TXD0)
#define TIMER0_CLOCK_ENABLE (((uint32)0x1) << AT91C_ID_TC0)
#define PIOA_CLOCK_ENABLE (((uint32)0x1) << AT91C_ID_PIOA)
#define PIOB_CLOCK_ENABLE (((uint32)0x1) << AT91C_ID_PIOB)
#define TIOA0_PIN_MASK (((uint32)0x1) << 23) // Timer/Counter Output Pin
// Application Type Definitions
typedef unsigned int uint32;
typedef int int32;
typedef unsigned short uint16;
typedef short int16;
typedef unsigned char uint8;
typedef char int8;
typedef char bool;
// Application Special Value Definitions
#ifndef TRUE
#define TRUE (1)
#endif
#ifndef FALSE
#define FALSE (0)
#endif
#ifndef NULL
#define NULL (0)
#endif // NULL
#define DONT_CARE (0)
#ifndef INFINITY
#define INFINITY (1.0 / 0.0)
#endif
#ifndef NAN
#define NAN (0.0 / 0.0)
#endif
// MIN/MAX Definitions for Standard Types
#ifndef INT8_MAX
#define INT8_MAX 127
#endif
#ifndef INT8_MIN
#define INT8_MIN (-128)
#endif
#ifndef UINT8_MAX
#define UINT8_MAX 0xFFU
#endif
#ifndef UINT8_MIN
#define UINT8_MIN 0x00U
#endif
#ifndef INT16_MAX
#define INT16_MAX 32767
#endif
#ifndef INT16_MIN
#define INT16_MIN (-32768)
#endif
#ifndef UINT16_MAX
#define UINT16_MAX 0xFFFFU
#endif
#ifndef UINT16_MIN
#define UINT16_MIN 0x0000U
#endif
#ifndef INT32_MAX
#define INT32_MAX 0x7FFFFFFF
#endif
#ifndef INT32_MIN
#define INT32_MIN (-INT32_MAX - 1)
#endif
#ifndef UINT32_MAX
#define UINT32_MAX 0xFFFFFFFFU
#endif
#ifndef UINT32_MIN
#define UINT32_MIN 0x00000000U
#endif
typedef struct _EXAMPLE_STRUCT_T
{
int x;
int y;
} EXAMPLE_STRUCT_T;
#endif // _MYTYPES_H_
@@ -1,18 +1,18 @@
#include "Types.h"
#include "UsartBaudRateRegisterCalculator.h"
uint8 UsartModel_CalculateBaudRateRegisterSetting(uint32 masterClock, uint32 baudRate)
{
uint32 registerSetting = ((masterClock * 10) / (baudRate * 16));
if ((registerSetting % 10) >= 5)
{
registerSetting = (registerSetting / 10) + 1;
}
else
{
registerSetting /= 10;
}
return (uint8)registerSetting;
}
#include "Types.h"
#include "UsartBaudRateRegisterCalculator.h"
uint8 UsartModel_CalculateBaudRateRegisterSetting(uint32 masterClock, uint32 baudRate)
{
uint32 registerSetting = ((masterClock * 10) / (baudRate * 16));
if ((registerSetting % 10) >= 5)
{
registerSetting = (registerSetting / 10) + 1;
}
else
{
registerSetting /= 10;
}
return (uint8)registerSetting;
}
@@ -1,6 +1,6 @@
#ifndef _USARTBAUDRATEREGISTERCALCULATOR_H
#define _USARTBAUDRATEREGISTERCALCULATOR_H
uint8 UsartModel_CalculateBaudRateRegisterSetting(uint32 masterClock, uint32 baudRate);
#endif // _USARTBAUDRATEREGISTERCALCULATOR_H
#ifndef _USARTBAUDRATEREGISTERCALCULATOR_H
#define _USARTBAUDRATEREGISTERCALCULATOR_H
uint8 UsartModel_CalculateBaudRateRegisterSetting(uint32 masterClock, uint32 baudRate);
#endif // _USARTBAUDRATEREGISTERCALCULATOR_H
+21 -21
View File
@@ -1,21 +1,21 @@
#include "Types.h"
#include "UsartConductor.h"
#include "UsartHardware.h"
#include "UsartModel.h"
#include "TaskScheduler.h"
void UsartConductor_Init(void)
{
UsartHardware_Init(UsartModel_GetBaudRateRegisterSetting());
UsartHardware_TransmitString(UsartModel_GetWakeupMessage());
}
void UsartConductor_Run(void)
{
char* temp;
if (TaskScheduler_DoUsart())
{
temp = UsartModel_GetFormattedTemperature();
UsartHardware_TransmitString(temp);
}
}
#include "Types.h"
#include "UsartConductor.h"
#include "UsartHardware.h"
#include "UsartModel.h"
#include "TaskScheduler.h"
void UsartConductor_Init(void)
{
UsartHardware_Init(UsartModel_GetBaudRateRegisterSetting());
UsartHardware_TransmitString(UsartModel_GetWakeupMessage());
}
void UsartConductor_Run(void)
{
char* temp;
if (TaskScheduler_DoUsart())
{
temp = UsartModel_GetFormattedTemperature();
UsartHardware_TransmitString(temp);
}
}
+7 -7
View File
@@ -1,7 +1,7 @@
#ifndef _USARTCONDUCTOR_H
#define _USARTCONDUCTOR_H
void UsartConductor_Init(void);
void UsartConductor_Run(void);
#endif // _USARTCONDUCTOR_H
#ifndef _USARTCONDUCTOR_H
#define _USARTCONDUCTOR_H
void UsartConductor_Init(void);
void UsartConductor_Run(void);
#endif // _USARTCONDUCTOR_H
+39 -39
View File
@@ -1,39 +1,39 @@
#include "Types.h"
#include "UsartConfigurator.h"
void Usart_ConfigureUsartIO(void)
{
AT91C_BASE_PIOA->PIO_ASR = USART0_TX_PIN;
AT91C_BASE_PIOA->PIO_BSR = 0;
AT91C_BASE_PIOA->PIO_PDR = USART0_TX_PIN;
}
void Usart_EnablePeripheralClock(void)
{
AT91C_BASE_PMC->PMC_PCER = ((uint32)1) << USART0_CLOCK_ENABLE;
}
void Usart_Reset(void)
{
AT91C_BASE_US0->US_IDR = 0xffffffff;
AT91C_BASE_US0->US_CR = AT91C_US_RSTRX | AT91C_US_RSTTX | AT91C_US_RXDIS | AT91C_US_TXDIS;
}
void Usart_ConfigureMode(void)
{
AT91C_BASE_US0->US_MR = AT91C_US_USMODE_NORMAL |
AT91C_US_NBSTOP_1_BIT |
AT91C_US_PAR_NONE |
AT91C_US_CHRL_8_BITS |
AT91C_US_CLKS_CLOCK;
}
void Usart_SetBaudRateRegister(uint8 baudRateRegisterSetting)
{
AT91C_BASE_US0->US_BRGR = baudRateRegisterSetting;
}
void Usart_Enable(void)
{
AT91C_BASE_US0->US_CR = AT91C_US_TXEN;
}
#include "Types.h"
#include "UsartConfigurator.h"
void Usart_ConfigureUsartIO(void)
{
AT91C_BASE_PIOA->PIO_ASR = USART0_TX_PIN;
AT91C_BASE_PIOA->PIO_BSR = 0;
AT91C_BASE_PIOA->PIO_PDR = USART0_TX_PIN;
}
void Usart_EnablePeripheralClock(void)
{
AT91C_BASE_PMC->PMC_PCER = ((uint32)1) << USART0_CLOCK_ENABLE;
}
void Usart_Reset(void)
{
AT91C_BASE_US0->US_IDR = 0xffffffff;
AT91C_BASE_US0->US_CR = AT91C_US_RSTRX | AT91C_US_RSTTX | AT91C_US_RXDIS | AT91C_US_TXDIS;
}
void Usart_ConfigureMode(void)
{
AT91C_BASE_US0->US_MR = AT91C_US_USMODE_NORMAL |
AT91C_US_NBSTOP_1_BIT |
AT91C_US_PAR_NONE |
AT91C_US_CHRL_8_BITS |
AT91C_US_CLKS_CLOCK;
}
void Usart_SetBaudRateRegister(uint8 baudRateRegisterSetting)
{
AT91C_BASE_US0->US_BRGR = baudRateRegisterSetting;
}
void Usart_Enable(void)
{
AT91C_BASE_US0->US_CR = AT91C_US_TXEN;
}
+13 -13
View File
@@ -1,13 +1,13 @@
#ifndef _USARTCONFIGURATOR_H
#define _USARTCONFIGURATOR_H
#include "Types.h"
void Usart_ConfigureUsartIO(void);
void Usart_EnablePeripheralClock(void);
void Usart_Reset(void);
void Usart_ConfigureMode(void);
void Usart_SetBaudRateRegister(uint8 baudRateRegisterSetting);
void Usart_Enable(void);
#endif // _USARTCONFIGURATOR_H
#ifndef _USARTCONFIGURATOR_H
#define _USARTCONFIGURATOR_H
#include "Types.h"
void Usart_ConfigureUsartIO(void);
void Usart_EnablePeripheralClock(void);
void Usart_Reset(void);
void Usart_ConfigureMode(void);
void Usart_SetBaudRateRegister(uint8 baudRateRegisterSetting);
void Usart_Enable(void);
#endif // _USARTCONFIGURATOR_H
+22 -22
View File
@@ -1,22 +1,22 @@
#include "Types.h"
#include "UsartHardware.h"
#include "UsartConfigurator.h"
#include "UsartPutChar.h"
void UsartHardware_Init(uint8 baudRateRegisterSetting)
{
Usart_ConfigureUsartIO();
Usart_EnablePeripheralClock();
Usart_Reset();
Usart_ConfigureMode();
Usart_SetBaudRateRegister(baudRateRegisterSetting);
Usart_Enable();
}
void UsartHardware_TransmitString(char* data)
{
while(*data != NULL)
{
Usart_PutChar(*data++);
}
}
#include "Types.h"
#include "UsartHardware.h"
#include "UsartConfigurator.h"
#include "UsartPutChar.h"
void UsartHardware_Init(uint8 baudRateRegisterSetting)
{
Usart_ConfigureUsartIO();
Usart_EnablePeripheralClock();
Usart_Reset();
Usart_ConfigureMode();
Usart_SetBaudRateRegister(baudRateRegisterSetting);
Usart_Enable();
}
void UsartHardware_TransmitString(char* data)
{
while(*data != NULL)
{
Usart_PutChar(*data++);
}
}
+9 -9
View File
@@ -1,9 +1,9 @@
#ifndef _USARTHARDWARE_H
#define _USARTHARDWARE_H
#include "Types.h"
void UsartHardware_Init(uint8 baudRateRegisterSetting);
void UsartHardware_TransmitString(char* data);
#endif // _USARTHARDWARE_H
#ifndef _USARTHARDWARE_H
#define _USARTHARDWARE_H
#include "Types.h"
void UsartHardware_Init(uint8 baudRateRegisterSetting);
void UsartHardware_TransmitString(char* data);
#endif // _USARTHARDWARE_H
+34 -34
View File
@@ -1,34 +1,34 @@
#include "Types.h"
#include "UsartModel.h"
#include "ModelConfig.h"
#include "UsartBaudRateRegisterCalculator.h"
#include "TemperatureFilter.h"
#include <stdio.h>
#include <math.h>
char formattedTemperature[32];
char* wakeup = "It's Awesome Time!\n";
uint8 UsartModel_GetBaudRateRegisterSetting(void)
{
return UsartModel_CalculateBaudRateRegisterSetting(MASTER_CLOCK, USART0_BAUDRATE);
}
char* UsartModel_GetFormattedTemperature(void)
{
float temperature = TemperatureFilter_GetTemperatureInCelcius();
if (temperature == -INFINITY)
{
sprintf(formattedTemperature, "%s", "Temperature sensor failure!\n");
}
else
{
sprintf(formattedTemperature, "%.1f C\n", temperature);
}
return formattedTemperature;
}
char* UsartModel_GetWakeupMessage(void)
{
return wakeup;
}
#include "Types.h"
#include "UsartModel.h"
#include "ModelConfig.h"
#include "UsartBaudRateRegisterCalculator.h"
#include "TemperatureFilter.h"
#include <stdio.h>
#include <math.h>
char formattedTemperature[32];
char* wakeup = "It's Awesome Time!\n";
uint8 UsartModel_GetBaudRateRegisterSetting(void)
{
return UsartModel_CalculateBaudRateRegisterSetting(MASTER_CLOCK, USART0_BAUDRATE);
}
char* UsartModel_GetFormattedTemperature(void)
{
float temperature = TemperatureFilter_GetTemperatureInCelcius();
if (temperature == -INFINITY)
{
sprintf(formattedTemperature, "%s", "Temperature sensor failure!\n");
}
else
{
sprintf(formattedTemperature, "%.1f C\n", temperature);
}
return formattedTemperature;
}
char* UsartModel_GetWakeupMessage(void)
{
return wakeup;
}
+10 -10
View File
@@ -1,10 +1,10 @@
#ifndef _USARTMODEL_H
#define _USARTMODEL_H
#include "Types.h"
uint8 UsartModel_GetBaudRateRegisterSetting(void);
char* UsartModel_GetFormattedTemperature(void);
char* UsartModel_GetWakeupMessage(void);
#endif // _USARTMODEL_H
#ifndef _USARTMODEL_H
#define _USARTMODEL_H
#include "Types.h"
uint8 UsartModel_GetBaudRateRegisterSetting(void);
char* UsartModel_GetFormattedTemperature(void);
char* UsartModel_GetWakeupMessage(void);
#endif // _USARTMODEL_H
+16 -16
View File
@@ -1,16 +1,16 @@
#include "Types.h"
#include "UsartPutChar.h"
#include "UsartTransmitBufferStatus.h"
#ifdef SIMULATE
#include <stdio.h>
#endif
void Usart_PutChar(char data)
{
while(!Usart_ReadyToTransmit());
#ifdef SIMULATE
printf("%c", data);
#else
AT91C_BASE_US0->US_THR = data;
#endif
}
#include "Types.h"
#include "UsartPutChar.h"
#include "UsartTransmitBufferStatus.h"
#ifdef SIMULATE
#include <stdio.h>
#endif
void Usart_PutChar(char data)
{
while(!Usart_ReadyToTransmit());
#ifdef SIMULATE
printf("%c", data);
#else
AT91C_BASE_US0->US_THR = data;
#endif
}
+8 -8
View File
@@ -1,8 +1,8 @@
#ifndef _USARTPUT_HAR_H
#define _USARTPUT_HAR_H
#include "Types.h"
void Usart_PutChar(char data);
#endif // _USARTPUT_HAR_H
#ifndef _USARTPUT_HAR_H
#define _USARTPUT_HAR_H
#include "Types.h"
void Usart_PutChar(char data);
#endif // _USARTPUT_HAR_H
@@ -1,7 +1,7 @@
#include "Types.h"
#include "UsartTransmitBufferStatus.h"
bool Usart_ReadyToTransmit(void)
{
return (AT91C_BASE_US0->US_CSR & AT91C_US_TXRDY) > 0;
}
#include "Types.h"
#include "UsartTransmitBufferStatus.h"
bool Usart_ReadyToTransmit(void)
{
return (AT91C_BASE_US0->US_CSR & AT91C_US_TXRDY) > 0;
}
@@ -1,8 +1,8 @@
#ifndef _USARTTRANSMITBUFFERSTATUS_H
#define _USARTTRANSMITBUFFERSTATUS_H
#include "Types.h"
bool Usart_ReadyToTransmit(void);
#endif // _USARTTRANSMITBUFFERSTATUS_H
#ifndef _USARTTRANSMITBUFFERSTATUS_H
#define _USARTTRANSMITBUFFERSTATUS_H
#include "Types.h"
bool Usart_ReadyToTransmit(void);
#endif // _USARTTRANSMITBUFFERSTATUS_H