* Replaced simple demo application with full ESC battery monitor demo application targeted for Atmel AT91SAM7X256 ARM7

git-svn-id: http://cmock.svn.sourceforge.net/svnroot/cmock/trunk@37 bf332499-1b4d-0410-844d-d2d48d5cc64c
This commit is contained in:
greg-williams
2008-11-07 02:17:20 +00:00
parent 9c42546a9e
commit b7d9479954
84 changed files with 4699 additions and 109 deletions
-5
View File
@@ -1,5 +0,0 @@
compiler: 'gcc.exe'
linker: 'gcc.exe'
path: 'c:/mingw/bin/'
compile_flags: '-c'
link_flags: ''
+7 -6
View File
@@ -1,4 +1,4 @@
$here = File.dirname(__FILE__)
$here = File.expand_path(File.dirname(__FILE__))
require 'rake'
require 'rake/clean'
@@ -8,7 +8,7 @@ require 'rakefile_helper'
include RakefileConstants
include RakefileHelpers
SYSTEST_TEST_FILES = FileList.new(SYSTEST_TEST_DIR + '*Test' + C_EXTENSION)
SYSTEST_TEST_FILES = FileList.new(SYSTEST_TEST_DIR + 'Test*' + C_EXTENSION)
COMPILER_CONFIGS = FileList.new('*.yml')
@@ -20,14 +20,14 @@ task :default => [ :clobber, 'tests:all', :app ]
desc "Build and run application"
task :app do
COMPILER_CONFIGS.each do |cfg_file|
build_and_run_application(yaml_read(cfg_file), 'MySwankApp')
build_application(yaml_read(cfg_file), 'Main')
end
end
namespace :tests do
desc "Run unit and system tests"
task :all => ['units', 'system', 'app']
task :all => [:clean, 'units', 'system', 'app']
Rake::TestTask.new('units') do |t|
t.pattern = 'test//unit/*_test.rb'
@@ -35,9 +35,10 @@ namespace :tests do
end
desc "Run system tests"
task :system do
task :system => [:clean] do
COMPILER_CONFIGS.each do |cfg_file|
run_systests(yaml_read(cfg_file), SYSTEST_TEST_FILES)
run_systests(yaml_read(cfg_file), SYSTEST_TEST_FILES)
report_summary
end
end
+44 -25
View File
@@ -1,6 +1,7 @@
require 'yaml'
require 'lib/cmock'
require 'auto/generate_test_runner'
require 'vendor/unity/auto/generate_test_runner'
require 'vendor/unity/auto/unity_test_summary'
def Kernel.is_windows?
processor, platform, *rest = RUBY_PLATFORM.split("-")
@@ -21,7 +22,7 @@ module RakefileConstants
UNITY_DIR = 'vendor/unity/src/'
SYSTEST_BASE = 'test/system/'
SYSTEST_SOURCE_DIR = SYSTEST_BASE + 'source/'
SYSTEST_SOURCE_DIR = SYSTEST_BASE + 'src/'
SYSTEST_TEST_DIR = SYSTEST_BASE + 'test/'
SYSTEST_MOCKS_DIR = SYSTEST_BASE + 'mocks/'
SYSTEST_BUILD_DIR = SYSTEST_BASE + 'build/'
@@ -54,11 +55,14 @@ module RakefileHelpers
return src_file
end
end
return ''
return nil
end
def compile(config, file)
def compile(config, file, defines=[])
cmd_str = "#{config["path"]}#{config["compiler"]} #{config["compile_flags"]} "
if !defines.nil? and defines.length > 0
defines.each { |define| cmd_str += "-D#{define} " }
end
if !config["path"].nil?
cmd_str += "-B#{config["path"]} "
end
@@ -98,44 +102,66 @@ module RakefileHelpers
return output
end
def report_summary
summary = UnityTestSummary.new
summary.set_root_path($here)
summary.set_targets(Dir["#{SYSTEST_BUILD_DIR}*.test*"])
summary.run
end
def run_systests(config, test_files)
puts 'Running system tests...'
test_defines = ['TEST']
test_files.each do |test|
obj_list = []
test_base = File.basename(test, C_EXTENSION)
headers = extract_headers(test)
headers.each do |header|
if header =~ /^Mock(.*)\.h/i
module_name = $1
report "Generating mock for module #{module_name}..."
cmock = CMock.new(mocks_path='test/system/mocks')
cmock.setup_mocks("test/system/source/#{module_name}.h")
cmock = CMock.new(SYSTEST_MOCKS_DIR, ['Types.h'])
cmock.setup_mocks("#{SYSTEST_SOURCE_DIR}#{module_name}.h")
end
compile(config, find_source_file(header))
obj_list << header.ext(OBJ_EXTENSION)
src_file = find_source_file(header)
if !src_file.nil?
compile(config, src_file, test_defines)
obj_list << header.ext(OBJ_EXTENSION)
end
end
# Generate and build the test runner
runner_name = test_base + '_Runner.c'
runner_path = SYSTEST_BUILD_DIR + runner_name
test_gen = UnityTestRunnerGenerator.new
test_gen.run(test, runner_path)
compile(config, runner_path)
test_gen.run(test, runner_path, ['Types'])
compile(config, runner_path, test_defines)
obj_list << runner_name.ext(OBJ_EXTENSION)
# Build the test file
compile(config, test)
compile(config, test, test_defines)
obj_list << test_base.ext(OBJ_EXTENSION)
link(config, test_base, obj_list)
execute(SYSTEST_BUILD_DIR + test_base + EXE_EXTENSION)
# Run test and generate results file
output = execute(SYSTEST_BUILD_DIR + test_base + EXE_EXTENSION)
test_results = SYSTEST_BUILD_DIR + test_base
if output.match(/OK$/m).nil?
test_results += '.testfail'
else
test_results += '.testpass'
end
File.open(test_results, 'w') do |f|
f.print output
end
end
end
def build_and_run_application(config, main)
def build_application(config, main)
obj_list = []
main_path = SYSTEST_SOURCE_DIR + main + '.c'
executable_path = SYSTEST_BUILD_DIR + main + EXE_EXTENSION
@@ -143,24 +169,17 @@ module RakefileHelpers
headers = extract_headers(main_path)
headers.each do |header|
if header =~ /^Mock(.*)\.h/i
module_name = $1
report "Generating mock for module #{module_name}..."
cmock = CMock.new(mocks_path='test/system/mocks')
cmock.setup_mocks("test/system/source/#{module_name}.h")
src_file = find_source_file(header)
if !src_file.nil?
compile(config, src_file)
obj_list << header.ext(OBJ_EXTENSION)
end
compile(config, find_source_file(header))
obj_list << header.ext(OBJ_EXTENSION)
end
compile(config, main_path)
obj_list << main_base.ext(OBJ_EXTENSION)
link(config, main_base, obj_list)
execute(SYSTEST_BUILD_DIR + main_base + EXE_EXTENSION)
end
end
-12
View File
@@ -1,12 +0,0 @@
#include <stdio.h>
#include "Simple.h"
#include "Stuff.h"
int main(void)
{
int a = 123, b = 456;
printf("What is %d + %d?\n", a, b);
Add(123, 456);
printf("Now that's swankadelic!\n");
return 0;
}
-9
View File
@@ -1,9 +0,0 @@
#include "Simple.h"
#include "Stuff.h"
int Add(int a, int b)
{
int answer = a + b;
ReportAnswer(answer);
return answer;
}
-6
View File
@@ -1,6 +0,0 @@
#ifndef _SIMPLE_H
#define _SIMPLE_H
int Add(int a, int b);
#endif // _SIMPLE_H
-6
View File
@@ -1,6 +0,0 @@
#include <stdio.h>
void ReportAnswer(int answer)
{
printf("The answer is %d.\n", answer);
}
-6
View File
@@ -1,6 +0,0 @@
#ifndef _STUFF_H
#define _STUFF_H
void ReportAnswer(int answer);
#endif // _STUFF_H
File diff suppressed because it is too large Load Diff
+18
View File
@@ -0,0 +1,18 @@
#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();
}
}
+7
View File
@@ -0,0 +1,7 @@
#ifndef _ADCCONDUCTOR_H
#define _ADCCONDUCTOR_H
void AdcConductor_Init(void);
void AdcConductor_Run(void);
#endif // _ADCCONDUCTOR_H
+27
View File
@@ -0,0 +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();
}
+9
View File
@@ -0,0 +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
+19
View File
@@ -0,0 +1,19 @@
#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;
}
+10
View File
@@ -0,0 +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
+16
View File
@@ -0,0 +1,16 @@
#include "Types.h"
#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));
}
+7
View File
@@ -0,0 +1,7 @@
#ifndef _ADCMODEL_H
#define _ADCMODEL_H
bool AdcModel_DoGetSample(void);
void AdcModel_ProcessInput(uint16 millivolts);
#endif // _ADCMODEL_H
+51
View File
@@ -0,0 +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);
}
+10
View File
@@ -0,0 +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
+22
View File
@@ -0,0 +1,22 @@
#include "Types.h"
#include "Executor.h"
#include "Model.h"
#include "UsartConductor.h"
#include "TimerConductor.h"
#include "AdcConductor.h"
void Executor_Init(void)
{
Model_Init();
UsartConductor_Init();
AdcConductor_Init();
TimerConductor_Init();
}
bool Executor_Run(void)
{
UsartConductor_Run();
TimerConductor_Run();
AdcConductor_Run();
return TRUE;
}
+9
View File
@@ -0,0 +1,9 @@
#ifndef _EXECUTOR_H
#define _EXECUTOR_H
#include "Types.h"
void Executor_Init(void);
bool Executor_Run(void);
#endif // _EXECUTOR_H
+43
View File
@@ -0,0 +1,43 @@
#include "Types.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());
}
#ifndef TEST
int main(void)
{
return AppMain();
}
#endif // TEST
+7
View File
@@ -0,0 +1,7 @@
#ifndef _MAIN_H_
#define _MAIN_H_
int AppMain(void);
int main(void);
#endif // _MAIN_H_
+10
View File
@@ -0,0 +1,10 @@
#include "Model.h"
#include "TaskScheduler.h"
#include "TemperatureFilter.h"
void Model_Init(void)
{
TaskScheduler_Init();
TemperatureFilter_Init();
}
+8
View File
@@ -0,0 +1,8 @@
#ifndef _MODEL_H
#define _MODEL_H
#include "Types.h"
void Model_Init(void);
#endif // _MODEL_H
+7
View File
@@ -0,0 +1,7 @@
#ifndef _MODELCONFIG_H
#define _MODELCONFIG_H
#define MASTER_CLOCK 48054857 // Master Clock
#define USART0_BAUDRATE 115200 // USART Baudrate
#endif // _MODELCONFIG_H
+72
View File
@@ -0,0 +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;
}
+11
View File
@@ -0,0 +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
+18
View File
@@ -0,0 +1,18 @@
#include "Types.h"
#include "TemperatureCalculator.h"
#include "math.h"
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;
// 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);
}
+6
View File
@@ -0,0 +1,6 @@
#ifndef _TEMPERATURECALCULATOR_H
#define _TEMPERATURECALCULATOR_H
float TemperatureCalculator_Calculate(uint16 millivolts);
#endif // _TEMPERATURECALCULATOR_H
+39
View File
@@ -0,0 +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);
}
}
+10
View File
@@ -0,0 +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
+15
View File
@@ -0,0 +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());
}
+9
View File
@@ -0,0 +1,9 @@
#ifndef _TIMERCONDUCTOR_H
#define _TIMERCONDUCTOR_H
#include "Types.h"
void TimerConductor_Init(void);
void TimerConductor_Run(void);
#endif // _TIMERCONDUCTOR_H
+51
View File
@@ -0,0 +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;
TIMER0_BASE->TC_CCR = AT91C_TC_CLKDIS;
TIMER0_BASE->TC_IDR = 0xffffffff;
dummy = TIMER0_BASE->TC_SR;
dummy = dummy;
}
void Timer_ConfigureMode(void)
{
TIMER0_BASE->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)
{
TIMER0_BASE->TC_RC = 469; // 10ms period for timer clock source of MCK/1024 with MCK=48054857
}
void Timer_EnableOutputPin(void)
{
PIOB_BASE->PIO_PDR = TIOA0_PIN_MASK;
}
void Timer_Enable(void)
{
TIMER0_BASE->TC_CCR = AT91C_TC_CLKEN;
}
void Timer_ConfigureInterruptHandler(void)
{
Timer_DisableInterrupt();
Timer_ResetSystemTime();
Timer_ConfigureInterrupt();
Timer_EnableInterrupt();
}
void Timer_Start(void)
{
TIMER0_BASE->TC_CCR = AT91C_TC_SWTRG;
}
+15
View File
@@ -0,0 +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
+15
View File
@@ -0,0 +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();
}
+8
View File
@@ -0,0 +1,8 @@
#ifndef _TIMERHARDWARE_H
#define _TIMERHARDWARE_H
#include "Types.h"
void TimerHardware_Init(void);
#endif // _TIMERHARDWARE_H
@@ -0,0 +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)
{
TIMER0_BASE->TC_IER = AT91C_TC_CPCS;
}
@@ -0,0 +1,13 @@
#ifndef _TIMERINTERRUPTCONFIGURATOR_H
#define _TIMERINTERRUPCONFIGURATOR_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
+25
View File
@@ -0,0 +1,25 @@
#include "Types.h"
#include "TimerInterruptHandler.h"
#include "TimerInterruptConfigurator.h"
static uint32 systemTime;
__monitor void Timer_SetSystemTime(uint32 time)
{
systemTime = time;
}
__monitor uint32 Timer_GetSystemTime(void)
{
return systemTime;
}
void Timer_InterruptHandler(void)
{
uint32 status = TIMER0_BASE->TC_SR;
if (status & AT91C_TC_CPCS)
{
systemTime += 10;
}
}
+8
View File
@@ -0,0 +1,8 @@
#ifndef _TIMERINTERRUPTHANDLER_H
#define _TIMERINTERRUPTHANDLER_H
__monitor void Timer_SetSystemTime(uint32 time);
__monitor uint32 Timer_GetSystemTime(void);
void Timer_InterruptHandler(void);
#endif // _TIMERINTERRUPTHANDLER_H
+9
View File
@@ -0,0 +1,9 @@
#include "Types.h"
#include "TimerModel.h"
#include "TaskScheduler.h"
void TimerModel_UpdateTime(uint32 systemTime)
{
TaskScheduler_Update(systemTime);
}
+8
View File
@@ -0,0 +1,8 @@
#ifndef _TIMERMODEL_H
#define _TIMERMODEL_H
#include "Types.h"
void TimerModel_UpdateTime(uint32 systemTime);
#endif // _TIMERMODEL_H
+111
View File
@@ -0,0 +1,111 @@
#ifndef _MYTYPES_H_
#define _MYTYPES_H_
#include <AT91SAM7X256.h>
#ifndef __monitor
#define __monitor
#endif
// Peripheral Helper Definitions
//#define USART_DEBUG
#define USART_0
// Debug USART
#ifdef USART_DEBUG
#define USART_CLOCK_ENABLE (AT91C_ID_SYS)
#define USART_TX_PIN (AT91C_PA28_DTXD)
#ifdef TEST
extern AT91S_USART UsartPeripheral;
#define USART_BASE ((AT91PS_USART) &UsartPeripheral)
#else
#define USART_BASE ((AT91PS_USART) AT91C_BASE_DBGU)
#endif // TEST
#endif // USART_DEBUG
// USART 0
#ifdef USART_0
#define USART_CLOCK_ENABLE (AT91C_ID_US0)
#define USART_TX_PIN (AT91C_PA1_TXD0)
#ifdef TEST
extern AT91S_USART UsartPeripheral;
#define USART_BASE ((AT91PS_USART) &UsartPeripheral)
#else
#define USART_BASE ((AT91PS_USART) AT91C_BASE_US0)
#endif // TEST
#endif // USART_0
// Timer/Counter 0
#define TIMER0_CLOCK_ENABLE (((uint32)0x1) << AT91C_ID_TC0)
#ifdef TEST
extern AT91S_TC Timer0Peripheral;
#define TIMER0_BASE ((AT91PS_TC) &Timer0Peripheral)
#else
#define TIMER0_BASE ((AT91PS_TC) AT91C_BASE_TC0)
#endif // TEST
// Parallel I/O Bank A
#define PIOA_CLOCK_ENABLE (((uint32)0x1) << AT91C_ID_PIOA)
#ifdef TEST
extern AT91S_PIO PioAPeripheral;
#define PIOA_BASE ((AT91PS_PIO) &PioAPeripheral)
#else
#define PIOA_BASE ((AT91PS_PIO) AT91C_BASE_PIOA)
#endif // TEST
// Parallel I/O Bank B
#define PIOB_CLOCK_ENABLE (((uint32)0x1) << AT91C_ID_PIOB)
#ifdef TEST
extern AT91S_PIO PioBPeripheral;
#define PIOB_BASE ((AT91PS_PIO) &PioBPeripheral)
#else
#define PIOB_BASE ((AT91PS_PIO) AT91C_BASE_PIOB)
#endif // TEST
// Timer/Counter Output Pin Assignment
#define TIOA0_PIN_MASK (((uint32)0x1) << 23)
// 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)
// MIN/MAX Definitions for Standard Types
#define INT8_MAX 127
#define INT8_MIN (-128)
#define UINT8_MAX 0xFFU
#define UINT8_MIN 0x00U
#define INT16_MAX 32767
#define INT16_MIN (-32768)
#define UINT16_MAX 0xFFFFU
#define UINT16_MIN 0x0000U
#define INT32_MAX 0x7FFFFFFF
#define INT32_MIN (-INT32_MAX - 1)
#define UINT32_MAX 0xFFFFFFFFU
#define UINT32_MIN 0x00000000U
#endif // _MYTYPES_H_
@@ -0,0 +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;
}
@@ -0,0 +1,6 @@
#ifndef _USARTBAUDRATEREGISTERCALCULATOR_H
#define _USARTBAUDRATEREGISTERCALCULATOR_H
uint8 UsartModel_CalculateBaudRateRegisterSetting(uint32 masterClock, uint32 baudRate);
#endif // _USARTBAUDRATEREGISTERCALCULATOR_H
+21
View File
@@ -0,0 +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);
}
}
+7
View File
@@ -0,0 +1,7 @@
#ifndef _USARTCONDUCTOR_H
#define _USARTCONDUCTOR_H
void UsartConductor_Init(void);
void UsartConductor_Run(void);
#endif // _USARTCONDUCTOR_H
+39
View File
@@ -0,0 +1,39 @@
#include "Types.h"
#include "UsartConfigurator.h"
void Usart_ConfigureUsartIO(void)
{
PIOA_BASE->PIO_ASR = USART_TX_PIN;
PIOA_BASE->PIO_BSR = 0;
PIOA_BASE->PIO_PDR = USART_TX_PIN;
}
void Usart_EnablePeripheralClock(void)
{
AT91C_BASE_PMC->PMC_PCER = ((uint32)1) << USART_CLOCK_ENABLE;
}
void Usart_Reset(void)
{
USART_BASE->US_IDR = 0xffffffff;
USART_BASE->US_CR = AT91C_US_RSTRX | AT91C_US_RSTTX | AT91C_US_RXDIS | AT91C_US_TXDIS;
}
void Usart_ConfigureMode(void)
{
USART_BASE->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)
{
USART_BASE->US_BRGR = baudRateRegisterSetting;
}
void Usart_Enable(void)
{
USART_BASE->US_CR = AT91C_US_TXEN;
}
+13
View File
@@ -0,0 +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
+22
View File
@@ -0,0 +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++);
}
}
+7
View File
@@ -0,0 +1,7 @@
#ifndef _USARTHARDWARE_H
#define _USARTHARDWARE_H
void UsartHardware_Init(uint8 baudRateRegisterSetting);
void UsartHardware_TransmitString(char* data);
#endif // _USARTHARDWARE_H
+34
View File
@@ -0,0 +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!";
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;
}
+8
View File
@@ -0,0 +1,8 @@
#ifndef _USARTMODEL_H
#define _USARTMODEL_H
uint8 UsartModel_GetBaudRateRegisterSetting(void);
char* UsartModel_GetFormattedTemperature(void);
char* UsartModel_GetWakeupMessage(void);
#endif // _USARTMODEL_H
+17
View File
@@ -0,0 +1,17 @@
#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
USART_BASE->US_THR = data;
#endif
}
+8
View File
@@ -0,0 +1,8 @@
#ifndef _USARTPUT_HAR_H
#define _USARTPUT_HAR_H
#include "Types.h"
void Usart_PutChar(char data);
#endif // _USARTPUT_HAR_H
@@ -0,0 +1,7 @@
#include "Types.h"
#include "UsartTransmitBufferStatus.h"
bool Usart_ReadyToTransmit(void)
{
return (USART_BASE->US_CSR & AT91C_US_TXRDY) > 0;
}
@@ -0,0 +1,8 @@
#ifndef _USARTTRANSMITBUFFERSTATUS_H
#define _USARTTRANSMITBUFFERSTATUS_H
#include "Types.h"
bool Usart_ReadyToTransmit(void);
#endif // _USARTTRANSMITBUFFERSTATUS_H
-34
View File
@@ -1,34 +0,0 @@
#include "unity.h"
#include "Simple.h"
#include "MockStuff.h"
#include <setjmp.h>
#include <stdio.h>
jmp_buf AbortFrame;
void setUp(void)
{
}
void tearDown(void)
{
}
void test_Simple_Add_ShouldSumValues(void)
{
ReportAnswer_Expect(5);
TEST_ASSERT_EQUAL( 5, Add( 2, 3));
ReportAnswer_Expect(5);
TEST_ASSERT_EQUAL( 5, Add( 1, 4));
ReportAnswer_Expect(5);
TEST_ASSERT_EQUAL( 5, Add( -2, 7));
ReportAnswer_Expect(100);
TEST_ASSERT_EQUAL(100, Add( 25, 75));
ReportAnswer_Expect(-10);
TEST_ASSERT_EQUAL(-10, Add(-90, 80));
}
+46
View File
@@ -0,0 +1,46 @@
#include "unity.h"
#include "Types.h"
#include "Types.h"
#include "AdcConductor.h"
#include "MockAdcModel.h"
#include "MockAdcHardware.h"
void setUp(void)
{
}
void tearDown(void)
{
}
void testInitShouldCallHardwareInit(void)
{
AdcHardware_Init_Expect();
AdcConductor_Init();
}
void testRunShouldNotDoAnythingIfItIsNotTime(void)
{
AdcModel_DoGetSample_ExpectAndReturn(FALSE);
AdcConductor_Run();
}
void testRunShouldNotPassAdcResultToModelIfSampleIsNotComplete(void)
{
AdcModel_DoGetSample_ExpectAndReturn(TRUE);
AdcHardware_GetSampleComplete_ExpectAndReturn(FALSE);
AdcConductor_Run();
}
void testRunShouldGetLatestSampleFromAdcAndPassItToModelAndStartNewConversionWhenItIsTime(void)
{
AdcModel_DoGetSample_ExpectAndReturn(TRUE);
AdcHardware_GetSampleComplete_ExpectAndReturn(TRUE);
AdcHardware_GetSample_ExpectAndReturn(293U);
AdcModel_ProcessInput_Expect(293U);
AdcHardware_StartConversion_Expect();
AdcConductor_Run();
}
+44
View File
@@ -0,0 +1,44 @@
#include "unity.h"
#include "Types.h"
#include "AdcHardware.h"
#include "MockAdcHardwareConfigurator.h"
#include "MockAdcTemperatureSensor.h"
void setUp(void)
{
}
void tearDown(void)
{
}
void testInitShouldDelegateToConfiguratorAndTemperatureSensor(void)
{
Adc_Reset_Expect();
Adc_ConfigureMode_Expect();
Adc_EnableTemperatureChannel_Expect();
Adc_StartTemperatureSensorConversion_Expect();
AdcHardware_Init();
}
void testGetSampleCompleteShouldReturn_FALSE_WhenTemperatureSensorSampleReadyReturns_FALSE(void)
{
Adc_TemperatureSensorSampleReady_ExpectAndReturn(FALSE);
TEST_ASSERT(!AdcHardware_GetSampleComplete());
}
void testGetSampleCompleteShouldReturn_TRUE_WhenTemperatureSensorSampleReadyReturns_TRUE(void)
{
Adc_TemperatureSensorSampleReady_ExpectAndReturn(TRUE);
TEST_ASSERT(AdcHardware_GetSampleComplete());
}
void testGetSampleShouldDelegateToAdcTemperatureSensor(void)
{
uint16 sample;
Adc_ReadTemperatureSensor_ExpectAndReturn(847);
sample = AdcHardware_GetSample();
TEST_ASSERT_EQUAL(847, sample);
}
@@ -0,0 +1,43 @@
#include "unity.h"
#include "Types.h"
#include "AdcHardwareConfigurator.h"
#include "AT91SAM7X256.h"
#include "ModelConfig.h"
AT91S_ADC AdcPeripheral;
void setUp(void)
{
}
void tearDown(void)
{
}
void testResetShouldResetTheAdcConverterPeripheral(void)
{
AT91C_BASE_ADC->ADC_CR = 0;
Adc_Reset();
TEST_ASSERT_EQUAL(AT91C_ADC_SWRST, AT91C_BASE_ADC->ADC_CR);
}
void testConfigureModeShouldSetAdcModeRegisterAppropriately(void)
{
uint32 prescaler = (MASTER_CLOCK / (2 * 2000000)) - 1; // 5MHz ADC clock
AT91C_BASE_ADC->ADC_MR = 0;
Adc_ConfigureMode();
TEST_ASSERT_EQUAL(prescaler, (AT91C_BASE_ADC->ADC_MR & AT91C_ADC_PRESCAL) >> 8);
}
void testEnableTemperatureChannelShouldEnableTheAppropriateAdcInput(void)
{
AT91C_BASE_ADC->ADC_CHER = 0;
Adc_EnableTemperatureChannel();
TEST_ASSERT_EQUAL(0x1 << 4, AT91C_BASE_ADC->ADC_CHER);
}
+33
View File
@@ -0,0 +1,33 @@
#include "unity.h"
#include "Types.h"
#include "AdcModel.h"
#include "MockTaskScheduler.h"
#include "MockTemperatureCalculator.h"
#include "MockTemperatureFilter.h"
void setUp(void)
{
}
void tearDown(void)
{
}
void testDoGetSampleShouldReturn_FALSE_WhenTaskSchedulerReturns_FALSE(void)
{
TaskScheduler_DoAdc_ExpectAndReturn(FALSE);
TEST_ASSERT_EQUAL(FALSE, AdcModel_DoGetSample());
}
void testDoGetSampleShouldReturn_TRUE_WhenTaskSchedulerReturns_TRUE(void)
{
TaskScheduler_DoAdc_ExpectAndReturn(TRUE);
TEST_ASSERT_EQUAL(TRUE, AdcModel_DoGetSample());
}
void testProcessInputShouldDelegateToTemperatureCalculatorAndPassResultToFilter(void)
{
TemperatureCalculator_Calculate_ExpectAndReturn(21473, 23.5f);
TemperatureFilter_ProcessInput_Expect(23.5f);
AdcModel_ProcessInput(21473);
}
@@ -0,0 +1,47 @@
#include "unity.h"
#include "Types.h"
#include "AdcTemperatureSensor.h"
#include "AT91SAM7X256.h"
AT91S_ADC AdcPeripheral;
void setUp(void)
{
}
void tearDown(void)
{
}
void testShouldStartTemperatureSensorConversionWhenTriggered(void)
{
AT91C_BASE_ADC->ADC_CR = 0;
Adc_StartTemperatureSensorConversion();
TEST_ASSERT_EQUAL(AT91C_ADC_START, AT91C_BASE_ADC->ADC_CR);
}
void testTemperatureSensorSampleReadyShouldReturnChannelConversionCompletionStatus(void)
{
AT91C_BASE_ADC->ADC_SR = 0;
TEST_ASSERT_EQUAL(FALSE, Adc_TemperatureSensorSampleReady());
AT91C_BASE_ADC->ADC_SR = ~AT91C_ADC_EOC4;
TEST_ASSERT_EQUAL(FALSE, Adc_TemperatureSensorSampleReady());
AT91C_BASE_ADC->ADC_SR = AT91C_ADC_EOC4;
TEST_ASSERT_EQUAL(TRUE, Adc_TemperatureSensorSampleReady());
AT91C_BASE_ADC->ADC_SR = 0xffffffff;
TEST_ASSERT_EQUAL(TRUE, Adc_TemperatureSensorSampleReady());
}
void testReadTemperatureSensorShouldFetchAndTranslateLatestReadingToMillivolts(void)
{
uint16 result;
// ADC bit weight at 10-bit resolution with 3.0V reference = 2.9296875 mV/LSB
AT91C_BASE_ADC->ADC_CDR4 = 138;
result = Adc_ReadTemperatureSensor();
TEST_ASSERT_EQUAL(404, result);
AT91C_BASE_ADC->ADC_CDR4 = 854;
result = Adc_ReadTemperatureSensor();
TEST_ASSERT_EQUAL(2502, result);
}
+34
View File
@@ -0,0 +1,34 @@
#include "unity.h"
#include "Types.h"
#include "Executor.h"
#include "MockModel.h"
#include "MockUsartConductor.h"
#include "MockAdcConductor.h"
#include "MockTimerConductor.h"
void setUp(void)
{
}
void tearDown(void)
{
}
void testInitShouldCallInitOfAllConductorsAndTheModel(void)
{
Model_Init_Expect();
UsartConductor_Init_Expect();
AdcConductor_Init_Expect();
TimerConductor_Init_Expect();
Executor_Init();
}
void testRunShouldCallRunForEachConductorAndReturnTrueAlways(void)
{
UsartConductor_Run_Expect();
TimerConductor_Run_Expect();
AdcConductor_Run_Expect();
TEST_ASSERT_EQUAL(TRUE, Executor_Run());
}
+24
View File
@@ -0,0 +1,24 @@
#include "unity.h"
#include "Types.h"
#include "MockExecutor.h"
#include "Main.h"
void setUp(void)
{
}
void tearDown(void)
{
}
void testMainShouldCallExecutorInitAndContinueToCallExecutorRunUntilHalted(void)
{
Executor_Init_Expect();
Executor_Run_ExpectAndReturn(TRUE);
Executor_Run_ExpectAndReturn(TRUE);
Executor_Run_ExpectAndReturn(TRUE);
Executor_Run_ExpectAndReturn(TRUE);
Executor_Run_ExpectAndReturn(FALSE);
AppMain();
}
+20
View File
@@ -0,0 +1,20 @@
#include "unity.h"
#include "Types.h"
#include "Model.h"
#include "MockTaskScheduler.h"
#include "MockTemperatureFilter.h"
void setUp(void)
{
}
void tearDown(void)
{
}
void testInitShouldCallSchedulerAndTemperatureFilterInit(void)
{
TaskScheduler_Init_Expect();
TemperatureFilter_Init_Expect();
Model_Init();
}
+104
View File
@@ -0,0 +1,104 @@
#include "unity.h"
#include "Types.h"
#include "TaskScheduler.h"
void setUp(void)
{
TaskScheduler_Init();
}
void tearDown(void)
{
}
void testShouldScheduleUsartTaskAfter1000ms(void)
{
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoUsart());
TaskScheduler_Update(999);
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoUsart());
TaskScheduler_Update(1000);
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoUsart());
}
void testShouldClearUsartDoFlagAfterReported(void)
{
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoUsart());
TaskScheduler_Update(1000);
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoUsart());
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoUsart());
}
void testShouldScheduleUsartTaskEvery1000ms(void)
{
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoUsart());
TaskScheduler_Update(1300);
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoUsart());
TaskScheduler_Update(2000);
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoUsart());
TaskScheduler_Update(3100);
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoUsart());
}
void testShouldScheduleUsartTaskOnlyOncePerPeriod(void)
{
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoUsart());
TaskScheduler_Update(1000);
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoUsart());
TaskScheduler_Update(1001);
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoUsart());
TaskScheduler_Update(1999);
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoUsart());
TaskScheduler_Update(2000);
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoUsart());
}
void testShouldScheduleAdcTaskAfter100ms(void)
{
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoAdc());
TaskScheduler_Update(99);
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoAdc());
TaskScheduler_Update(100);
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoAdc());
}
void testShouldClearAdcDoFlagAfterReported(void)
{
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoAdc());
TaskScheduler_Update(100);
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoAdc());
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoAdc());
}
void testShouldScheduleAdcTaskEvery100ms(void)
{
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoAdc());
TaskScheduler_Update(121);
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoAdc());
TaskScheduler_Update(200);
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoAdc());
TaskScheduler_Update(356);
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoAdc());
}
void testShouldScheduleAdcTaskOnlyOncePerPeriod(void)
{
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoAdc());
TaskScheduler_Update(100);
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoAdc());
TaskScheduler_Update(101);
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoAdc());
TaskScheduler_Update(199);
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoAdc());
TaskScheduler_Update(200);
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoAdc());
}
@@ -0,0 +1,33 @@
#include "unity.h"
#include "Types.h"
#include "TemperatureCalculator.h"
#include <math.h>
void setUp(void)
{
}
void tearDown(void)
{
}
void testTemperatureCalculatorShouldCalculateTemperatureFromMillivolts(void)
{
float result;
// 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
result = TemperatureCalculator_Calculate(1000);
TEST_ASSERT_FLOAT_WITHIN(0.01f, 25.0f, result);
result = TemperatureCalculator_Calculate(2985);
TEST_ASSERT_FLOAT_WITHIN(0.01f, 68.317f, result);
result = TemperatureCalculator_Calculate(3);
TEST_ASSERT_FLOAT_WITHIN(0.01f, -19.96f, result);
}
void testShouldReturnNegativeInfinityWhen_0_millivoltsInput(void)
{
TEST_ASSERT_EQUAL(-INFINITY, TemperatureCalculator_Calculate(0));
}
+69
View File
@@ -0,0 +1,69 @@
#include "unity.h"
#include "Types.h"
#include "TemperatureFilter.h"
#include <math.h>
void setUp(void)
{
TemperatureFilter_Init();
}
void tearDown(void)
{
}
void testShouldInitializeTemeratureToInvalidValue(void)
{
TemperatureFilter_Init();
TEST_ASSERT_FLOAT_WITHIN(0.0001f, -INFINITY, TemperatureFilter_GetTemperatureInCelcius());
}
void testShouldInitializeTemperatureAfterCallToInit(void)
{
TemperatureFilter_Init();
TemperatureFilter_ProcessInput(17.8f);
TEST_ASSERT_FLOAT_WITHIN(0.0001f, 17.8f, TemperatureFilter_GetTemperatureInCelcius());
TemperatureFilter_Init();
TemperatureFilter_ProcessInput(32.6f);
TEST_ASSERT_FLOAT_WITHIN(0.0001f, 32.6f, TemperatureFilter_GetTemperatureInCelcius());
}
void setValueAndVerifyResponse(float input, float response)
{
float actual;
TemperatureFilter_ProcessInput(input);
actual = TemperatureFilter_GetTemperatureInCelcius();
TEST_ASSERT_FLOAT_WITHIN(0.0001f, response, actual);
}
void testShouldWeightEachSubsequentValueBy25PercentAfterInitialValue(void)
{
TemperatureFilter_Init();
setValueAndVerifyResponse(0.0f, 0.0f);
setValueAndVerifyResponse(10.0f, 2.5f);
setValueAndVerifyResponse(10.0f, 4.375f);
setValueAndVerifyResponse(10.0f, 5.78125f);
TemperatureFilter_Init();
setValueAndVerifyResponse(100.0f, 100.0f);
setValueAndVerifyResponse(0.0f, 75.0f);
setValueAndVerifyResponse(0.0f, 56.25f);
setValueAndVerifyResponse(0.0f, 42.1875f);
}
void setInvalidTemperatureAndVerifyReinitialized(float invalidTemperature)
{
TemperatureFilter_Init();
TEST_WRAP(setValueAndVerifyResponse(100.0f, 100.0f));
TEST_WRAP(setValueAndVerifyResponse(invalidTemperature, -INFINITY));
TEST_WRAP(setValueAndVerifyResponse(14.3f, 14.3f));
}
void testShouldResetAverageIfPassedInfinityOrInvalidValue(void)
{
TEST_WRAP(setInvalidTemperatureAndVerifyReinitialized(-INFINITY));
TEST_WRAP(setInvalidTemperatureAndVerifyReinitialized(+INFINITY));
TEST_WRAP(setInvalidTemperatureAndVerifyReinitialized(+NAN));
TEST_WRAP(setInvalidTemperatureAndVerifyReinitialized(-NAN));
}
+32
View File
@@ -0,0 +1,32 @@
#include "unity.h"
#include "Types.h"
#include "TimerConductor.h"
#include "MockTimerHardware.h"
#include "MockTimerModel.h"
#include "MockTimerInterruptHandler.h"
void setUp(void)
{
}
void tearDown(void)
{
}
void testInitShouldCallHardwareInit(void)
{
TimerHardware_Init_Expect();
TimerConductor_Init();
}
void testRunShouldGetSystemTimeAndPassOnToModelForEventScheduling(void)
{
Timer_GetSystemTime_ExpectAndReturn(1230);
TimerModel_UpdateTime_Expect(1230);
TimerConductor_Run();
Timer_GetSystemTime_ExpectAndReturn(837460);
TimerModel_UpdateTime_Expect(837460);
TimerConductor_Run();
}
+112
View File
@@ -0,0 +1,112 @@
#include "unity.h"
#include "Types.h"
#include "TimerConfigurator.h"
#include "AT91SAM7X256.h"
#include "MockTimerInterruptConfigurator.h"
AT91S_PMC PmcPeripheral;
AT91S_TC Timer0Peripheral;
AT91S_PIO PioBPeripheral;
void setUp(void)
{
}
void tearDown(void)
{
}
void testEnablePeripheralClocksShouldEnableClockToTimer0Peripheral(void)
{
AT91C_BASE_PMC->PMC_PCER = 0;
Timer_EnablePeripheralClocks();
TEST_ASSERT_EQUAL(
TIMER0_CLOCK_ENABLE,
AT91C_BASE_PMC->PMC_PCER & TIMER0_CLOCK_ENABLE);
}
void testEnablePeripheralClocksShouldEnableClockToPIOBPeripheral(void)
{
AT91C_BASE_PMC->PMC_PCER = 0;
Timer_EnablePeripheralClocks();
TEST_ASSERT_EQUAL(
PIOB_CLOCK_ENABLE,
AT91C_BASE_PMC->PMC_PCER & PIOB_CLOCK_ENABLE);
}
void testResetShouldSetTimer0ClockDisableBit_DisableTimer0Interrupts_ClearStatusRegister(void)
{
TIMER0_BASE->TC_CCR = 0;
TIMER0_BASE->TC_IDR = 0;
TIMER0_BASE->TC_SR = 0xFFFFFFFF;
Timer_Reset();
TEST_ASSERT_EQUAL(0x00000002, TIMER0_BASE->TC_CCR);
TEST_ASSERT_EQUAL(0xffffffff, TIMER0_BASE->TC_IDR);
// CANNOT BE VERIFIED!! TEST_ASSERT_EQUAL(0X00000000, TIMER0_BASE->TC_SR);
}
void testEnableOutputPinShouldEnable_TIOA0_DigitalOutput(void)
{
PIOB_BASE->PIO_PDR = 0;
Timer_EnableOutputPin();
TEST_ASSERT_EQUAL(TIOA0_PIN_MASK, PIOB_BASE->PIO_PDR);
}
void testConfigureModeShouldConfigureTimer0ClockSourceForMasterClockDividedBy1024(void)
{
TIMER0_BASE->TC_CMR = 0;
Timer_ConfigureMode();
TEST_ASSERT_EQUAL(0x00000004, TIMER0_BASE->TC_CMR & 0x00000007);
}
void testConfigureModeShouldConfigureTimer0ForWaveGeneration(void)
{
TIMER0_BASE->TC_CMR = 0;
Timer_ConfigureMode();
TEST_ASSERT_EQUAL(0x00008000, TIMER0_BASE->TC_CMR & 0x00008000);
}
void testConfigureModeShouldConfigureTimer0ForUpModeWithAutomaticTriggerOnRCCompare(void)
{
TIMER0_BASE->TC_CMR = 0;
Timer_ConfigureMode();
TEST_ASSERT_EQUAL(0x00004000, TIMER0_BASE->TC_CMR & 0x00006000);
}
void testConfigureModeShouldConfigureTimer0ToToggleTIOAOnRCCompare(void)
{
TIMER0_BASE->TC_CMR = 0;
Timer_ConfigureMode();
TEST_ASSERT_EQUAL(0x000C0000, TIMER0_BASE->TC_CMR & 0x000C0000);
}
void testConfigurePeriodShouldConfigureRegisterCFor10msInterval(void)
{
TIMER0_BASE->TC_RC = 0;
Timer_ConfigurePeriod();
TEST_ASSERT_EQUAL(469, TIMER0_BASE->TC_RC);
}
void testEnableShouldSetEnableFlagForTimer0(void)
{
TIMER0_BASE->TC_CCR = 0;
Timer_Enable();
TEST_ASSERT_EQUAL_INT(1, TIMER0_BASE->TC_CCR);
}
void testConfigureInterruptHandler(void)
{
Timer_DisableInterrupt_Expect();
Timer_ResetSystemTime_Expect();
Timer_ConfigureInterrupt_Expect();
Timer_EnableInterrupt_Expect();
Timer_ConfigureInterruptHandler();
}
void testStartShouldSetSoftwareTriggerFlag(void)
{
TIMER0_BASE->TC_CCR = 0;
Timer_Start();
TEST_ASSERT_EQUAL(0x04, TIMER0_BASE->TC_CCR);
}
+26
View File
@@ -0,0 +1,26 @@
#include "unity.h"
#include "Types.h"
#include "TimerHardware.h"
#include "MockTimerConfigurator.h"
void setUp(void)
{
}
void tearDown(void)
{
}
void testInitShouldDelegateAppropriatelyToConfigurator(void)
{
Timer_EnablePeripheralClocks_Expect();
Timer_Reset_Expect();
Timer_ConfigureMode_Expect();
Timer_ConfigurePeriod_Expect();
Timer_EnableOutputPin_Expect();
Timer_Enable_Expect();
Timer_ConfigureInterruptHandler_Expect();
Timer_Start_Expect();
TimerHardware_Init();
}
@@ -0,0 +1,78 @@
#include "unity.h"
#include "Types.h"
#include "TimerInterruptConfigurator.h"
#include "MockTimerInterruptHandler.h"
#include "AT91SAM7X256.h"
AT91S_AIC AicPeripheral;
AT91S_TC Timer0Peripheral;
void setUp(void)
{
}
void tearDown(void)
{
}
void test_TIMER0_ID_MASK_ShouldBeCorrect(void)
{
TEST_ASSERT_EQUAL(((uint32)0x1) << AT91C_ID_TC0, TIMER0_ID_MASK);
}
void testDisableInterruptDisablesTimer0InterruptInTheInterruptController(void)
{
AT91C_BASE_AIC->AIC_IDCR = 0;
Timer_DisableInterrupt();
TEST_ASSERT_EQUAL(TIMER0_ID_MASK, AT91C_BASE_AIC->AIC_IDCR);
}
void testResetSystemTimeDelegatesTo_Timer_SetSystemTime_Appropriately(void)
{
Timer_SetSystemTime_Expect(0);
Timer_ResetSystemTime();
}
void testConfigureInterruptShouldSetInterruptHandlerAppropriately(void)
{
AT91C_BASE_AIC->AIC_SVR[AT91C_ID_TC0] = NULL;
Timer_ConfigureInterrupt();
TEST_ASSERT_EQUAL((uint32)Timer_InterruptHandler, AT91C_BASE_AIC->AIC_SVR[AT91C_ID_TC0]);
}
void testConfigureInterruptShouldSetInterruptLevelInSourceModeRegisterAppropriately(void)
{
AT91C_BASE_AIC->AIC_SMR[AT91C_ID_TC0] = 0;
Timer_ConfigureInterrupt();
TEST_ASSERT_EQUAL(
AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL,
AT91C_BASE_AIC->AIC_SMR[AT91C_ID_TC0] & 0x00000060);
}
void testConfigureInterruptShouldSetInterruptPriorityInSourceModeRegisterAppropriately(void)
{
AT91C_BASE_AIC->AIC_SMR[AT91C_ID_TC0] = 0;
Timer_ConfigureInterrupt();
TEST_ASSERT_EQUAL(1, AT91C_BASE_AIC->AIC_SMR[AT91C_ID_TC0] & 0x00000007);
}
void testConfigureInterruptShouldClearTimer0InterruptOnTheInterruptController(void)
{
AT91C_BASE_AIC->AIC_ICCR = 0;
Timer_ConfigureInterrupt();
TEST_ASSERT_EQUAL(TIMER0_ID_MASK, AT91C_BASE_AIC->AIC_ICCR);
}
void testConfigureInterruptShouldEnableCompareInterruptForRegisterC(void)
{
TIMER0_BASE->TC_IER = 0;
Timer_ConfigureInterrupt();
TEST_ASSERT_EQUAL(AT91C_TC_CPCS, TIMER0_BASE->TC_IER);
}
void testEnableInterruptShouldEnableTimer0InterruptsInInterruptCotroller(void)
{
AT91C_BASE_AIC->AIC_IECR = 0;
Timer_EnableInterrupt();
TEST_ASSERT_EQUAL(TIMER0_ID_MASK, AT91C_BASE_AIC->AIC_IECR);
}
@@ -0,0 +1,66 @@
#include "unity.h"
#include "Types.h"
#include "TimerInterruptHandler.h"
#include "AT91SAM7X256.h"
AT91S_TC Timer0Peripheral;
void setUp(void)
{
}
void tearDown(void)
{
}
void testSetAndGetSystemTime(void)
{
Timer_SetSystemTime(0);
TEST_ASSERT_EQUAL(0, Timer_GetSystemTime());
Timer_SetSystemTime(129837);
TEST_ASSERT_EQUAL(129837, Timer_GetSystemTime());
Timer_SetSystemTime(UINT32_MAX);
TEST_ASSERT_EQUAL(UINT32_MAX, Timer_GetSystemTime());
}
void testInterruptHandlerShouldIncrementSystemTimeOnlyIfStatusHasCompareRegisterCOverflowBitSet(void)
{
Timer_SetSystemTime(0);
TIMER0_BASE->TC_SR = 0;
Timer_InterruptHandler();
TEST_ASSERT_EQUAL(0, Timer_GetSystemTime());
Timer_SetSystemTime(0);
TIMER0_BASE->TC_SR = ~AT91C_TC_CPCS;
Timer_InterruptHandler();
TEST_ASSERT_EQUAL(0, Timer_GetSystemTime());
Timer_SetSystemTime(0);
TIMER0_BASE->TC_SR = AT91C_TC_CPCS;
Timer_InterruptHandler();
TEST_ASSERT(Timer_GetSystemTime() > 0);
Timer_SetSystemTime(0);
TIMER0_BASE->TC_SR = 0xffffffff;
Timer_InterruptHandler();
TEST_ASSERT(Timer_GetSystemTime() > 0);
}
void testInterruptHandlerShouldIncrementSystemTimerBy_10(void)
{
Timer_SetSystemTime(0);
TIMER0_BASE->TC_SR = AT91C_TC_CPCS;
Timer_InterruptHandler();
TEST_ASSERT_EQUAL(10, Timer_GetSystemTime());
TIMER0_BASE->TC_SR = AT91C_TC_CPCS;
Timer_InterruptHandler();
TEST_ASSERT_EQUAL(20, Timer_GetSystemTime());
Timer_SetSystemTime(39426857);
TIMER0_BASE->TC_SR = AT91C_TC_CPCS;
Timer_InterruptHandler();
TEST_ASSERT_EQUAL(39426867, Timer_GetSystemTime());
}
+18
View File
@@ -0,0 +1,18 @@
#include "unity.h"
#include "Types.h"
#include "TimerModel.h"
#include "MockTaskScheduler.h"
void setUp(void)
{
}
void tearDown(void)
{
}
void testUpdateTimeShouldDelegateToTaskScheduler(void)
{
TaskScheduler_Update_Expect(19387L);
TimerModel_UpdateTime(19387L);
}
@@ -0,0 +1,21 @@
#include "unity.h"
#include "Types.h"
#include "UsartBaudRateRegisterCalculator.h"
void setUp(void)
{
}
void tearDown(void)
{
}
void testCalculateBaudRateRegisterSettingShouldCalculateRegisterSettingAppropriately(void)
{
// BaudRate = MCK / (CD x 16) - per datasheet section 30.6.1.2 "Baud Rate Calculation Example"
TEST_ASSERT_EQUAL(26, UsartModel_CalculateBaudRateRegisterSetting(48000000, 115200));
TEST_ASSERT_EQUAL(6, UsartModel_CalculateBaudRateRegisterSetting(3686400, 38400));
TEST_ASSERT_EQUAL(23, UsartModel_CalculateBaudRateRegisterSetting(14318180, 38400));
TEST_ASSERT_EQUAL(20, UsartModel_CalculateBaudRateRegisterSetting(12000000, 38400));
TEST_ASSERT_EQUAL(13, UsartModel_CalculateBaudRateRegisterSetting(12000000, 56800));
}
+40
View File
@@ -0,0 +1,40 @@
#include "unity.h"
#include "Types.h"
#include "UsartConductor.h"
#include "MockUsartModel.h"
#include "MockUsartHardware.h"
#include "MockTaskScheduler.h"
void setUp(void)
{
}
void tearDown(void)
{
}
void testShouldInitializeHardwareWhenInitCalled(void)
{
UsartModel_GetBaudRateRegisterSetting_ExpectAndReturn(4);
UsartModel_GetWakeupMessage_ExpectAndReturn("Hey there!");
UsartHardware_TransmitString_Expect("Hey there!");
UsartHardware_Init_Expect(4);
UsartConductor_Init();
}
void testRunShouldNotDoAnythingIfSchedulerSaysItIsNotTimeYet(void)
{
TaskScheduler_DoUsart_ExpectAndReturn(FALSE);
UsartConductor_Run();
}
void testRunShouldGetCurrentTemperatureAndTransmitIfSchedulerSaysItIsTime(void)
{
TaskScheduler_DoUsart_ExpectAndReturn(TRUE);
UsartModel_GetFormattedTemperature_ExpectAndReturn("hey there");
UsartHardware_TransmitString_Expect("hey there");
UsartConductor_Run();
}
+77
View File
@@ -0,0 +1,77 @@
#include "unity.h"
#include "Types.h"
#include "UsartConfigurator.h"
AT91S_PIO PioAPeripheral;
AT91S_PMC PmcPeripheral;
AT91S_USART UsartPeripheral;
void setUp(void)
{
}
void tearDown(void)
{
}
void testConfigureUsartIOShouldConfigureUsartTxPinfForPeripheralIO(void)
{
PIOA_BASE->PIO_ASR = 0;
PIOA_BASE->PIO_BSR = 0xffffffff;
PIOA_BASE->PIO_PDR = 0;
Usart_ConfigureUsartIO();
TEST_ASSERT_EQUAL(USART_TX_PIN, PIOA_BASE->PIO_ASR);
TEST_ASSERT_EQUAL(0, PIOA_BASE->PIO_BSR);
TEST_ASSERT_EQUAL(USART_TX_PIN, PIOA_BASE->PIO_PDR);
}
void testEnablePeripheralClockShouldEnableClockToUsartPeripheral(void)
{
AT91C_BASE_PMC->PMC_PCER = 0;
Usart_EnablePeripheralClock();
TEST_ASSERT_EQUAL(((uint32)1) << USART_CLOCK_ENABLE, AT91C_BASE_PMC->PMC_PCER);
}
void testResetShouldDisableAllUsartInterrupts(void)
{
USART_BASE->US_IDR = 0;
Usart_Reset();
TEST_ASSERT_EQUAL(0xffffffff, USART_BASE->US_IDR);
}
void testResetShouldResetUsartTransmitterAndReceiver(void)
{
USART_BASE->US_CR = 0;
Usart_Reset();
TEST_ASSERT_EQUAL(AT91C_US_RSTRX | AT91C_US_RSTTX | AT91C_US_RXDIS | AT91C_US_TXDIS, USART_BASE->US_CR);
}
void testConfigureModeShouldSetUsartModeToAsynchronous(void)
{
uint32 asyncMode = (AT91C_US_USMODE_NORMAL |
AT91C_US_NBSTOP_1_BIT |
AT91C_US_PAR_NONE |
AT91C_US_CHRL_8_BITS |
AT91C_US_CLKS_CLOCK);
USART_BASE->US_MR = ~asyncMode;
Usart_ConfigureMode();
TEST_ASSERT_EQUAL(asyncMode, USART_BASE->US_MR);
}
void testSetBaudRateRegisterShouldSetUsartBaudRateRegisterToValuePassedAsParameter(void)
{
USART_BASE->US_BRGR = 0;
Usart_SetBaudRateRegister(3);
TEST_ASSERT_EQUAL(3, USART_BASE->US_BRGR);
Usart_SetBaudRateRegister(251);
TEST_ASSERT_EQUAL(251, USART_BASE->US_BRGR);
}
void testEnableShouldEnableUsart0Transmitter(void)
{
USART_BASE->US_CR = 0;
Usart_Enable();
TEST_ASSERT_EQUAL(AT91C_US_TXEN, USART_BASE->US_CR);
}
+37
View File
@@ -0,0 +1,37 @@
#include "unity.h"
#include "Types.h"
#include "UsartHardware.h"
#include "AT91SAM7X256.h"
#include "MockUsartConfigurator.h"
#include "MockUsartPutChar.h"
void setUp(void)
{
}
void tearDown(void)
{
}
void testInitShouldConfigureUsartPeripheralByCallingConfiguratorAppropriately(void)
{
Usart_ConfigureUsartIO_Expect();
Usart_EnablePeripheralClock_Expect();
Usart_Reset_Expect();
Usart_ConfigureMode_Expect();
Usart_SetBaudRateRegister_Expect(73);
Usart_Enable_Expect();
UsartHardware_Init(73);
}
void testTransmitStringShouldSendDesiredStringOutUsingUsart(void)
{
Usart_PutChar_Expect('h');
Usart_PutChar_Expect('e');
Usart_PutChar_Expect('l');
Usart_PutChar_Expect('l');
Usart_PutChar_Expect('o');
UsartHardware_TransmitString("hello");
}
+40
View File
@@ -0,0 +1,40 @@
#include "unity.h"
#include "Types.h"
#include "UsartModel.h"
#include "ModelConfig.h"
#include "MockTemperatureFilter.h"
#include "MockUsartBaudRateRegisterCalculator.h"
#include <math.h>
void setUp(void)
{
}
void tearDown(void)
{
}
void testGetBaudRateRegisterSettingShouldReturnAppropriateBaudRateRegisterSetting(void)
{
uint8 dummyRegisterSetting = 17;
UsartModel_CalculateBaudRateRegisterSetting_ExpectAndReturn(MASTER_CLOCK, USART0_BAUDRATE, dummyRegisterSetting);
TEST_ASSERT_EQUAL(dummyRegisterSetting, UsartModel_GetBaudRateRegisterSetting());
}
void testGetFormattedTemperatureFormatsTemperatureFromCalculatorAppropriately(void)
{
TemperatureFilter_GetTemperatureInCelcius_ExpectAndReturn(25.0f);
TEST_ASSERT_EQUAL_STRING("25.0 C\n", UsartModel_GetFormattedTemperature());
}
void testShouldReturnErrorMessageUponInvalidTemperatureValue(void)
{
TemperatureFilter_GetTemperatureInCelcius_ExpectAndReturn(-INFINITY);
TEST_ASSERT_EQUAL_STRING("Temperature sensor failure!\n", UsartModel_GetFormattedTemperature());
}
void testShouldReturnWakeupMessage(void)
{
TEST_ASSERT_EQUAL_STRING("It's Awesome Time!", UsartModel_GetWakeupMessage());
}
+43
View File
@@ -0,0 +1,43 @@
#include "unity.h"
#include "Types.h"
#include "UsartPutChar.h"
#include "MockUsartTransmitBufferStatus.h"
AT91S_USART UsartPeripheral;
void setUp(void)
{
}
void tearDown(void)
{
}
void testPutCharShouldWriteDesiredCharacterToUsartTransmitBuffer(void)
{
USART_BASE->US_THR = 0;
Usart_ReadyToTransmit_ExpectAndReturn(TRUE);
Usart_PutChar('x');
TEST_ASSERT_EQUAL('x', USART_BASE->US_THR);
Usart_ReadyToTransmit_ExpectAndReturn(TRUE);
Usart_PutChar('1');
TEST_ASSERT_EQUAL('1', USART_BASE->US_THR);
Usart_ReadyToTransmit_ExpectAndReturn(TRUE);
Usart_PutChar(':');
TEST_ASSERT_EQUAL(':', USART_BASE->US_THR);
}
void testPutCharShouldWaitUntilReadyToTransmitBeforeLoadingTransmitBufffer(void)
{
USART_BASE->US_THR = 0;
Usart_ReadyToTransmit_ExpectAndReturn(FALSE);
Usart_ReadyToTransmit_ExpectAndReturn(FALSE);
Usart_ReadyToTransmit_ExpectAndReturn(FALSE);
Usart_ReadyToTransmit_ExpectAndReturn(TRUE);
Usart_PutChar('x');
TEST_ASSERT_EQUAL('x', USART_BASE->US_THR);
}
@@ -0,0 +1,22 @@
#include "unity.h"
#include "Types.h"
#include "UsartTransmitBufferStatus.h"
AT91S_USART UsartPeripheral;
void setUp(void)
{
}
void tearDown(void)
{
}
void testReadyToTransmitShouldReturnStatusPerTransmitBufferReadyStatus(void)
{
USART_BASE->US_CSR = 0;
TEST_ASSERT(!Usart_ReadyToTransmit());
USART_BASE->US_CSR = AT91C_US_TXRDY;
TEST_ASSERT(Usart_ReadyToTransmit());
}