KM3NeT CLB  2.0
KM3NeT CLB v2 Embedded Software
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
nano.c
1 /*
2  * KM3NeT CLB v2 Firmware
3  * ----------------------
4  *
5  * Copyright 2012-2015 KM3NeT Collaboration
6  *
7  * All Rights Reserved.
8  *
9  *
10  * File : nano.c
11  * Created : 25 mrt. 2015
12  * Author : Vincent van Beveren
13  */
14 #include "drv/wb/nano.h"
15 
16 #include <cfg_soc.h>
17 #include <lm32soc/lm32.h>
18 #include "kernel/scheduler.h"
19 
20 volatile static int _nanoDoneTaskId = -1;
21 
22 bool nanoConfig(uint32_t delay, uint32_t period, uint32_t width, uint32_t noOfPulses)
23 {
24  if (period < width) return errSet(ERROR(E_INVARGUMENT));
25  if (period == 0 || width == 0 || noOfPulses == 0) return errSet(ERROR(E_INVARGUMENT));
26  NANOB->PERIOD = period;
27  NANOB->WIDTH = width;
28  NANOB->COUNT = noOfPulses;
29  NANOB->DELAY = delay;
30  return true;
31 }
32 
33 
34 void nanoSetPulseDoneTask(int taskId) {
35  _nanoDoneTaskId = taskId;
36 }
37 
38 void IRQ_HANDLER(NANOB_IRQ) {
39  if (_nanoDoneTaskId >= 0) schdRunIRQ(_nanoDoneTaskId);
40 }
void nanoSetPulseDoneTask(int taskId)
Configures the task to run if a pulse is done.
Definition: nano.c:34
Defines the configuration of the LM32 SOC for the CLBv2.
bool nanoConfig(uint32_t delay, uint32_t period, uint32_t width, uint32_t noOfPulses)
Configures the nano-beacon.
Definition: nano.c:22
Low level routines for LM32, including interrupt handling.
Simple task scheduler for tasks.
#define NANOB
Nano-Beacon device.
Definition: dev_soc.h:73
Nanobeacon driver.
#define IRQ_HANDLER(IRQ)
Defines an IRQ handler.
Definition: lm32.h:47
#define E_INVARGUMENT
Generic error: invalid argument.
Definition: errorcode.h:112
void schdRunIRQ(int taskId)
Schedule a task from an IRQ.
Definition: scheduler.c:242
bool errSet(uint32_t code, const char *error, const char *name)
Sets an error.
#define ERROR(CODE,...)
Expands an error code to an error code with a description (if ERROR_W_DESCR is declared).