/*********************************** * File: netapi_sched.h * Purpose: netapi scheduler module ************************************************************** * FILE: netapi_sched.h * * DESCRIPTION: netapi sample event scheduler header file for * user space transport library * * REVISION HISTORY: rev 0.0.1 * * Copyright (c) Texas Instruments Incorporated 2010-2011 * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the * distribution. * * Neither the name of Texas Instruments Incorporated nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************/ #ifndef __NETAPI_SCHED__ #define __NETAPI_SCHED__ #include "netapi.h" /**************************** **********CONTEXT********** ****************************/ struct NETAPI_SCHED_HANDLE_Tag; typedef void (*NETAPI_SCHED_CB)(struct NETAPI_SCHED_HANDLE_Tag *h); typedef struct NETAPI_SCHED_CONFIG_Tag { int valid_flags; //which is being configured #define NETAPI_SCHED_DURATION 0x1 #define NETAPI_SCHED_POWER 0x2 #define NETAPI_SCHED_FINE 0x4 //future #define NETAPI_SCHED_CBV 0x8 //callback /*----duration------*/ uint64_t duration; //0=forever or #tics to run for #define NETAPI_SCHED_FOREVER 0L /*-----house callback-----*/ NETAPI_SCHED_CB house_cb; uint32_t interval; // how many poll loop intervals after which to call the house keeping function /*------power control-------*/ int power_control; //0= always on, >0 = duty cycle #define NETAPI_SCHED_POWER_ALWAYS_OFF 0 //drop to idle #define NETAPI_SCHED_POWER_ALWAYS_ON 100 //always runs, no drop to idle int idle_time; //in ticks /*-----fine control-----*/ //future.. } NETAPI_SCHED_CONFIG_T; /* the schedule context */ typedef struct NETAPI_SCHED_HANDLE_Tag { volatile int state; //0= shutdown, 1= shutting down, 2=active #define NETAPI_SCHED_STATE_SHUT 0 #define NETAPI_SCHED_STATE_SHUTTING 1 #define NETAPI_SCHED_STATE_ACTIVE 2 void * back; //pointer back to netapi handle NETAPI_SCHED_CONFIG_T config; uint64_t start; /* start time */ volatile int shutdown_reason; volatile uint64_t shutdown_time; } NETAPI_SCHED_HANDLE_T; /* how to shut down */ typedef struct NETAPI_SCHED_SHUTDOWN_Tag { int shutdown_type; #define NETAPI_SCHED_SHUTDOWN_NOW 0 #define NETAPI_SCHED_SHUTDOWN_TO 1 #define NETAPI_SCHED_SHUTDOWN_NEXT_IDLE 2 int timeout; //ticks from now to close } NETAPI_SCHED_SHUTDOWN_T; /**************************** **************API ********** ****************************/ /* open a scheduling contex */ NETAPI_SCHED_HANDLE_T * netapi_schedOpen(NETAPI_T n, NETAPI_SCHED_CONFIG_T * p_config, int *p_err); /* re-configure a scheduling context */ int netapi_schedControl(NETAPI_SCHED_HANDLE_T *s, NETAPI_SCHED_CONFIG_T *p_config, int *p_err); /* return codes for wait_for_events() */ #define NETAPI_SCHED_RETURN_ERR 0 //unknown, err #define NETAPI_SCHED_RETURN_TO 1 // returned after timeout #define NETAPI_SCHED_RETURN_SHUTDOWN 2 //returned after shutdown /* main entry point. caller gives up control to scheduler */ int netapi_schedWaitForEvents(NETAPI_SCHED_HANDLE_T *s, int * p_err); /* shutdown scheduler context */ int netapi_schedShutdown(NETAPI_SCHED_HANDLE_T * s, NETAPI_SCHED_SHUTDOWN_T * p_close, int *p_err); static NETAPI_T netapi_schedGetNetapiHandle(NETAPI_SCHED_HANDLE_T *s) { return (NETAPI_T)s->back;} #endif