373a8c32b2
git-svn-id: file:///srv/dev-disk-by-uuid-17e88007-4d0c-45e0-8757-cacfcc458630/repositories/svn/Diplomarbeit@55 9fe90eed-be63-e94b-8204-d34ff4c2ff93
123 lines
4.8 KiB
C
123 lines
4.8 KiB
C
/* ---------------------------------------------------------------------------
|
|
* relay.c (c) 2008 Micro-key bv
|
|
* ---------------------------------------------------------------------------
|
|
* Micro-key bv
|
|
* Industrieweg 28, 9804 TG Noordhorn
|
|
* Postbus 92, 9800 AB Zuidhorn
|
|
* The Netherlands
|
|
* Tel: +31 594 503020
|
|
* Fax: +31 594 505825
|
|
* Email: support@microkey.nl
|
|
* Web: www.microkey.nl
|
|
* ---------------------------------------------------------------------------
|
|
* Description:
|
|
* ---------------------------------------------------------------------------
|
|
* Version(s): 0.1, Nov 10, 2008, MMi
|
|
* Creation.
|
|
* ---------------------------------------------------------------------------
|
|
*/
|
|
|
|
/* ---------------------------------------------------------------------------
|
|
* System include files
|
|
* ---------------------------------------------------------------------------
|
|
*/
|
|
/* Hardware Includes */
|
|
#include "LPC23xx.h"
|
|
#include "types.h"
|
|
|
|
/* FreeRTOS includes */
|
|
#include "FreeRTOS.h"
|
|
#include "Task.h"
|
|
#include "queue.h"
|
|
/* ---------------------------------------------------------------------------
|
|
* Application include files
|
|
* ---------------------------------------------------------------------------
|
|
*/
|
|
#include "relay.h"
|
|
#include "dio.h"
|
|
#include "ElecStatusCache.h"
|
|
//#include "dioISR.h"
|
|
//#include "armVIC.h"
|
|
|
|
/* ---------------------------------------------------------------------------
|
|
* Local constant and macro definitions
|
|
* ---------------------------------------------------------------------------
|
|
*/
|
|
#define PORT0_BASE_ADDR (FIO_BASE_ADDR) /* Fast IO Base Address */
|
|
#define PORT1_BASE_ADDR (FIO_BASE_ADDR + 0x20) /* Offset for Port2 */
|
|
|
|
#define DIR_OFFSET (0x00) /* Offset of 32Bit DID register */
|
|
#define MASK_OFFSET (0x10) /* Offset of 32bit MASK register*/
|
|
#define PIN_OFFSET (0x14) /* Offset of 32Bit PIN register */
|
|
#define SET_OFFSET (0x18) /* Offset of 32Bit SET register */
|
|
#define CLR_OFFSET (0x1C) /* Offset of 32Bit CLR register */
|
|
|
|
#define RLY_CHANNELS 6
|
|
/* ---------------------------------------------------------------------------
|
|
* Global variable definitions
|
|
* ---------------------------------------------------------------------------
|
|
*/
|
|
|
|
/* ---------------------------------------------------------------------------
|
|
* Local variable definitions
|
|
* ---------------------------------------------------------------------------
|
|
*/
|
|
t_input rly_inputPins[RLY_CHANNELS] =
|
|
{
|
|
{ PORT1_BASE_ADDR, BIT(26), NULL }, /* Relay Input 0 */
|
|
{ PORT1_BASE_ADDR, BIT(27), NULL }, /* Relay Input 1 */
|
|
{ PORT1_BASE_ADDR, BIT(28), NULL }, /* Relay Input 2 */
|
|
{ PORT1_BASE_ADDR, BIT(29), NULL }, /* Relay Input 3 */
|
|
{ PORT1_BASE_ADDR, BIT(30), NULL }, /* Relay Input 4 */
|
|
{ PORT1_BASE_ADDR, BIT(31), NULL }, /* Relay Input 5 */
|
|
|
|
};
|
|
/* ---------------------------------------------------------------------------
|
|
* Local function definitions
|
|
* ---------------------------------------------------------------------------
|
|
*/
|
|
|
|
void rlyInit(void)
|
|
{
|
|
UINT8 loopcnt;
|
|
volatile UINT32 *gpioRegister;
|
|
|
|
SCS |= (1UL<<0); /* GPIOM in SCS to fast IO */
|
|
|
|
/* Set registers for all Inputs in right Mode */
|
|
for (loopcnt=0; loopcnt < RLY_CHANNELS; loopcnt++)
|
|
{
|
|
/* Clear MASK register of corresponding Input */
|
|
gpioRegister = (UINT32 *)(rly_inputPins[loopcnt].portBaseAddr + MASK_OFFSET);
|
|
*gpioRegister &= ~(rly_inputPins[loopcnt].pinMask);
|
|
|
|
/* Set corresponding channel to direction INPUT */
|
|
gpioRegister = (UINT32 *)(rly_inputPins[loopcnt].portBaseAddr + DIR_OFFSET);
|
|
*gpioRegister &= ~(rly_inputPins[loopcnt].pinMask);
|
|
}
|
|
|
|
}
|
|
|
|
BOOLEAN rlyRead(UINT8 device, UINT8 channel)
|
|
{
|
|
BOOLEAN Result;
|
|
volatile UINT32 *gpioRegister;
|
|
|
|
/* Set pointer to corresponding channel register */
|
|
gpioRegister = (UINT32 *)(rly_inputPins[channel].portBaseAddr + PIN_OFFSET);
|
|
|
|
/* Receive Result from Register (Inputs are LOW-active) */
|
|
if (*gpioRegister & rly_inputPins[channel].pinMask)
|
|
{
|
|
/* Received a HIGH state, so INPUT is LOW or FALSE */
|
|
Result = FALSE;
|
|
}
|
|
else
|
|
{
|
|
/* Received a LOW state, so INPUT is HIGH or TRUE */
|
|
Result = TRUE;
|
|
}
|
|
|
|
return Result;
|
|
}
|