Skip to content

Commit 55b0da3

Browse files
author
Daniel Jäckle
committed
Update system gpio and system timer.
1 parent e62770b commit 55b0da3

File tree

4 files changed

+73
-12
lines changed

4 files changed

+73
-12
lines changed

src/system/gpio.c

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Maintainer: Miguel Luis and Gregory Cristian
2626

2727
void GpioInit( Gpio_t *obj, PinNames pin, PinModes mode, PinConfigs config, PinTypes type, uint32_t value )
2828
{
29-
if( ( uint32_t )( pin >> 4 ) <= 6 )
29+
if( ( uint32_t )( pin >> 4 ) <= 6 )
3030
{
3131
GpioMcuInit( obj, pin, mode, config, type, value );
3232
}
@@ -41,7 +41,7 @@ void GpioInit( Gpio_t *obj, PinNames pin, PinModes mode, PinConfigs config, Pin
4141

4242
void GpioSetInterrupt( Gpio_t *obj, IrqModes irqMode, IrqPriorities irqPriority, GpioIrqHandler *irqHandler )
4343
{
44-
if( ( uint32_t )( obj->pin >> 4 ) <= 6 )
44+
if( ( uint32_t )( obj->pin >> 4 ) <= 6 )
4545
{
4646
GpioMcuSetInterrupt( obj, irqMode, irqPriority, irqHandler );
4747
}
@@ -56,7 +56,7 @@ void GpioSetInterrupt( Gpio_t *obj, IrqModes irqMode, IrqPriorities irqPriority,
5656

5757
void GpioRemoveInterrupt( Gpio_t *obj )
5858
{
59-
if( ( uint32_t )( obj->pin >> 4 ) <= 6 )
59+
if( ( uint32_t )( obj->pin >> 4 ) <= 6 )
6060
{
6161
//GpioMcuRemoveInterrupt( obj );
6262
}
@@ -71,7 +71,7 @@ void GpioRemoveInterrupt( Gpio_t *obj )
7171

7272
void GpioWrite( Gpio_t *obj, uint32_t value )
7373
{
74-
if( ( uint32_t )( obj->pin >> 4 ) <= 6 )
74+
if( ( uint32_t )( obj->pin >> 4 ) <= 6 )
7575
{
7676
GpioMcuWrite( obj, value );
7777
}
@@ -84,9 +84,24 @@ void GpioWrite( Gpio_t *obj, uint32_t value )
8484
}
8585
}
8686

87+
void GpioToggle( Gpio_t *obj )
88+
{
89+
if( ( uint32_t )( obj->pin >> 4 ) <= 6 )
90+
{
91+
GpioMcuToggle( obj );
92+
}
93+
else
94+
{
95+
#if defined( BOARD_IOE_EXT )
96+
// IOExt Pin
97+
GpioIoeWrite( obj, GpioIoeRead( obj ) ^ 1 );
98+
#endif
99+
}
100+
}
101+
87102
uint32_t GpioRead( Gpio_t *obj )
88103
{
89-
if( ( uint32_t )( obj->pin >> 4 ) <= 6 )
104+
if( ( uint32_t )( obj->pin >> 4 ) <= 6 )
90105
{
91106
return GpioMcuRead( obj );
92107
}

src/system/gpio.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ Maintainer: Miguel Luis and Gregory Cristian
2525
/*!
2626
* Board GPIO pin names
2727
*/
28-
typedef enum
28+
typedef enum
2929
{
3030
MCU_PINS,
3131
IOE_PINS,
32-
32+
3333
// Not connected
3434
NC = (int)0xFFFFFFFF
3535
}PinNames;
@@ -71,7 +71,7 @@ typedef enum
7171
{
7272
NO_IRQ = 0,
7373
IRQ_RISING_EDGE,
74-
IRQ_FALLING_EDGE,
74+
IRQ_FALLING_EDGE,
7575
IRQ_RISING_FALLING_EDGE
7676
}IrqModes;
7777

@@ -82,15 +82,15 @@ typedef enum
8282
{
8383
IRQ_VERY_LOW_PRIORITY = 0,
8484
IRQ_LOW_PRIORITY,
85-
IRQ_MEDIUM_PRIORITY,
85+
IRQ_MEDIUM_PRIORITY,
8686
IRQ_HIGH_PRIORITY,
8787
IRQ_VERY_HIGH_PRIORITY
8888
}IrqPriorities;
8989

9090
/*!
9191
* Structure for the GPIO
9292
*/
93-
typedef struct
93+
typedef struct
9494
{
9595
PinNames pin;
9696
uint16_t pinIndex;
@@ -144,6 +144,13 @@ void GpioRemoveInterrupt( Gpio_t *obj );
144144
*/
145145
void GpioWrite( Gpio_t *obj, uint32_t value );
146146

147+
/*!
148+
* \brief Toggle the value to the GPIO output
149+
*
150+
* \param [IN] obj Pointer to the GPIO object
151+
*/
152+
void GpioToggle( Gpio_t *obj );
153+
147154
/*!
148155
* \brief Reads the current GPIO input value
149156
*

src/system/timer.c

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,19 @@ static void TimerInsertNewHeadTimer( TimerEvent_t *obj, uint32_t remainingTime )
200200
void TimerIrqHandler( void )
201201
{
202202
uint32_t elapsedTime = 0;
203+
uint32_t compensation = 0;
203204

204205
elapsedTime = TimerGetValue( );
205206

206-
if( elapsedTime > TimerListHead->Timestamp )
207+
if( elapsedTime == TimerListHead->Timestamp )
207208
{
208209
TimerListHead->Timestamp = 0;
209210
}
211+
else if( elapsedTime > TimerListHead->Timestamp )
212+
{
213+
compensation = elapsedTime - TimerListHead->Timestamp;
214+
TimerListHead->Timestamp = 0;
215+
}
210216
else
211217
{
212218
TimerListHead->Timestamp -= elapsedTime;
@@ -225,6 +231,26 @@ void TimerIrqHandler( void )
225231
}
226232
}
227233

234+
while( TimerListHead != NULL )
235+
{
236+
if( compensation < TimerListHead->Timestamp )
237+
{
238+
TimerListHead->Timestamp = TimerListHead->Timestamp - compensation;
239+
break;
240+
}
241+
else
242+
{
243+
compensation = compensation - TimerListHead->Timestamp;
244+
TimerEvent_t* elapsedTimer = TimerListHead;
245+
TimerListHead = TimerListHead->Next;
246+
247+
if( elapsedTimer->Callback != NULL )
248+
{
249+
elapsedTimer->Callback( );
250+
}
251+
}
252+
}
253+
228254
// start the next TimerListHead if it exists
229255
if( TimerListHead != NULL )
230256
{
@@ -366,6 +392,11 @@ TimerTime_t TimerGetElapsedTime( TimerTime_t savedTime )
366392
return RtcComputeElapsedTime( savedTime );
367393
}
368394

395+
TimerTime_t TimerGetFutureTime( TimerTime_t eventInFuture )
396+
{
397+
return RtcComputeFutureEventTime( eventInFuture );
398+
}
399+
369400
static void TimerSetTimeout( TimerEvent_t *obj )
370401
{
371402
HasLoopedThroughMain = 0;

src/system/timer.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ void TimerReset( TimerEvent_t *obj );
8080
void TimerSetValue( TimerEvent_t *obj, uint32_t value );
8181

8282
/*!
83-
* \brief Read the current time (with the Month as the MSByte)
83+
* \brief Read the current time
8484
*
8585
* \retval time returns current time
8686
*/
@@ -94,6 +94,14 @@ TimerTime_t TimerGetCurrentTime( void );
9494
*/
9595
TimerTime_t TimerGetElapsedTime( TimerTime_t savedTime );
9696

97+
/*!
98+
* \brief Return the Time elapsed since a fix moment in Time
99+
*
100+
* \param [IN] eventInFuture fix moment in the future
101+
* \retval time returns difference between now and future event
102+
*/
103+
TimerTime_t TimerGetFutureTime( TimerTime_t eventInFuture );
104+
97105
/*!
98106
* \brief Manages the entry into ARM cortex deep-sleep mode
99107
*/

0 commit comments

Comments
 (0)