/* Cesar project {{{ * * Copyright (C) 2007 Spidcom * * <<>> * * }}} */ /** * \file main_example.c * \brief example of a main program of a station executable * \ingroup */ #include #include #include #include "common/std.h" #include "host/station/station.h" #include "hal/phy/phy.h" #include "hal/phy/maximus/inc/maximus_phy_ctx.h" // for 'phy_t' #include "mac/common/tonemask.h" extern station_ctx_t my_station; phy_t * phy; bool phy_rx_fc_cb (void *user, u32 rx_date, const u32 *fc_av) { diag_write_string("=> phy_rx_fc_cb\n"); phy_rx_prepare(phy, 1, PHY_COMBO_PARAMS (PHY_MOD_MINI_ROBO, PHY_FEC_RATE_1_2, PHY_PB_SIZE_136), PHY_GIL_567, 0, 1); return true; } bool phy_access_cb (void *user) { return true; } bool phy_access_conf_cb (void *user) { return true; } bool phy_pbdma_cb (void *user, u32 status_word) { return true; } bool phy_tx_false_alarm_cb (void *user) { return true; } bool phy_zero_cross_cb (void *user, u32 zero_cross_date) { return true; } void phy_deferred_cb (void *user) { return; } bool phy_extra_timer_cb (void *user) { return true; } typedef struct my_struct { int i1; int i2; bool b; } my_struct_t; typedef long long my_type_t; my_type_t my_param4; unsigned int my_param6 = 123; // 0x0000007B unsigned int my_param7 = 456; // 0x000001C8 bool my_param8 = false; bool my_param9 = true; unsigned short my_param10 = 0xFFEE; unsigned long my_param11 = 0xFFEEDDCC; unsigned long long my_param12 = 0xBBAA9988FFEEDDCCLL; void my_return_function (void *data) { static fcall_param_t return_param; static sci_msg_t return_msg; static unsigned char return_buffer[1024]; unsigned short *return_msg_id = (unsigned short *)data; /* init structures */ fcall_param_init(&return_param, "function_1_rsp", *return_msg_id); if (0 != sci_msg_init(&return_msg, return_buffer, 1024)) { station_log(&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_SCI, "%s: errno = %d", __FUNCTION__, errno); } /* do other tasks ... */ diag_write_string("=> my_return_function\n"); /* now make the return parameter list */ fcall_param_reset(&return_param); fcall_param_add(&return_param, &return_msg, "result_2", sizeof(my_type_t), &my_param4); fcall_return(my_station.fcall, &return_param, &return_msg); return; } int my_function1 (fcall_ctx_t *fcall, fcall_param_t **param, sci_msg_t **msg, void *data) { static unsigned short asynchronous_msg_id = 0; my_struct_t my_param1; int my_param2[10]; char my_param3[6]; int i; // for netclock message netclock_id_t id; static netclock_callback_t my_return_function_cb; /* get parameters content */ fcall_param_bind(*param, *msg, "param_1", sizeof(my_struct_t), &my_param1); fcall_param_bind(*param, *msg, "param_2", 10*sizeof(int), my_param2); fcall_param_bind(*param, *msg, "param_3", 6, (char*)my_param3); fcall_param_bind(*param, *msg, "param_4", sizeof(my_type_t), &my_param4); /* do other tasks ... */ diag_write_string("=> my_function1\n"); diag_printf("param 1 . i1 = %d\n", my_param1.i1); diag_printf("param 1 . i2 = %d\n", my_param1.i2); diag_printf("param 1 . b = %d\n", my_param1.b); diag_write_string("param 2 = "); for (i=0; i<10; i++) { diag_printf(" %d", my_param2[i]); } diag_write_string("\n"); diag_printf("param 3 = %s\n", my_param3); diag_printf("param 4 = %lld\n", my_param4); /* prepare the future asynchronous return */ fcall_param_set_async(*param, 1); asynchronous_msg_id = (*param)->msg_id; /* schedule the future my_return_function() call */ // send netclock message to Maximus to call my_return_function() if (-1 == netclock_schedule(my_station.netclock, &my_return_function_cb, NETWORK_CLOCK_TYPE_STATION, my_station.current_tick_tck+10, &my_return_function, (void*)&asynchronous_msg_id, &id)) { diag_printf("errno = %d\n", errno); } /* now return */ return 0; } int my_function2 (fcall_ctx_t *fcall, fcall_param_t **param, sci_msg_t **msg, void *data) { bool my_param5; char my_result1[] = "this is result 1\0"; /* get parameters content */ if (-1 == fcall_param_bind(*param, *msg, "param_5", sizeof(bool), &my_param5)) { diag_printf("errno = %d\n", errno); diag_printf("param nb = %d\n", (*param)->param_nb); } /* do other tasks ... */ diag_write_string("=> my_function2\n"); /* now make the return parameter list */ fcall_param_reset(*param); fcall_param_add(*param, *msg, "result_1", strlen(my_result1)+1, &my_result1); return 0; } void my_function_rsp (void *data) { static fcall_param_t return_param; static sci_msg_t return_msg; static unsigned char return_buffer[1024]; unsigned short *return_msg_id = (unsigned short *)data; /* init structures */ fcall_param_init(&return_param, "function_rsp", *return_msg_id); if (0 != sci_msg_init(&return_msg, return_buffer, 1024)) { station_log(&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_SCI, "%s: errno = %d", __FUNCTION__, errno); } /* do other tasks ... */ diag_write_string("=> my_function_rsp\n"); /* now make the return parameter list */ fcall_param_reset(&return_param); fcall_return(my_station.fcall, &return_param, &return_msg); return; } int my_function3 (fcall_ctx_t *fcall, fcall_param_t **param, sci_msg_t **msg, void *data) { static unsigned short asynchronous_msg_id = 0; /* do other tasks ... */ diag_write_string("=> my_function3\n"); /* prepare the future asynchronous return */ fcall_param_set_async(*param, 1); asynchronous_msg_id = (*param)->msg_id; /* call my_function_rsp() */ my_function_rsp((void*)&asynchronous_msg_id); return 0; } int my_function4 (fcall_ctx_t *fcall, fcall_param_t **param, sci_msg_t **msg, void *data) { static unsigned short asynchronous_msg_id = 0; /* do other tasks ... */ diag_write_string("=> my_function4\n"); /* prepare the future asynchronous return */ fcall_param_set_async(*param, 1); asynchronous_msg_id = (*param)->msg_id; /* call my_function_rsp() */ my_function_rsp((void*)&asynchronous_msg_id); return 0; } int my_function5 (fcall_ctx_t *fcall, fcall_param_t **param, sci_msg_t **msg, void *data) { static unsigned short asynchronous_msg_id = 0; /* do other tasks ... */ diag_write_string("=> my_function5\n"); /* prepare the future asynchronous return */ fcall_param_set_async(*param, 1); asynchronous_msg_id = (*param)->msg_id; /* call my_function_rsp() */ my_function_rsp((void*)&asynchronous_msg_id); return 0; } int set_tonemask (fcall_ctx_t *fcall, fcall_param_t **param, sci_msg_t **msg, void *data) { uint carrier_nb = 0; u32 tonemask[PHY_TONEMASK_WORDS] = {0}; diag_write_string("=> set_tonemask\n"); // Initialize the HAL PHY phy = phy_init ((void*)&my_param4, &phy_rx_fc_cb, &phy_access_cb, &phy_access_conf_cb, &phy_pbdma_cb, &phy_tx_false_alarm_cb, &phy_deferred_cb); phy_zero_cross_init (phy, &phy_zero_cross_cb); // Enable assertions on warnings phy->warning_assert = true; // Set TONEMASK carrier_nb = tonemask_default (tonemask); phy_set_tonemask (phy, tonemask, carrier_nb); /* now make the return parameter list */ fcall_param_reset(*param); return 0; } int prepare_rx (fcall_ctx_t *fcall, fcall_param_t **param, sci_msg_t **msg, void *data) { // Test with one PB of 128 octets static u8 first_pb_data[128]; static phy_pb_t first_pb; static u32 nek[4]; int i = 0; diag_write_string("=> prepare_rx\n"); // Activate RX phy_rx_activate(phy, true, my_station.current_tick_tck, true); // Set RX parameters phy_rx_param(phy, PHY_FC_MODE_HYBRID_1); // Start PBDMA memset(first_pb_data, '1', 128); first_pb.pb_rx.blk.data = first_pb_data; first_pb.pb_rx.blk.next = NULL; for (i=0; i<4; i++) { nek[i] = i; } phy_pbdma_start(phy, true /* bypass_aes */, nek, 1 /* nb_total */, 1 /* nb_pb_it */, &first_pb, NULL, true); /* now make the return parameter list */ fcall_param_reset(*param); return 0; } int uninit_phy (fcall_ctx_t *fcall, fcall_param_t **param, sci_msg_t **msg, void *data) { diag_write_string("=> uninit_phy\n"); // Uninitialize the HAL PHY phy_uninit (phy); /* now make the return parameter list */ fcall_param_reset(*param); return 0; } int function_to_call (fcall_ctx_t *fcall, fcall_param_t **param, sci_msg_t **msg, void *data) { diag_write_string("=> function_to_call\n"); /* now make the return parameter list */ fcall_param_reset(*param); return 0; } int main (void) { station_log_set_level(&my_station, STATION_LOG_DEBUG); station_log_set_mask(&my_station, STATION_LOGTYPE_ALL); my_station.pipe_log_fd = 1; fcall_register(my_station.fcall, "function_1", (void*)&my_function1, NULL); fcall_register(my_station.fcall, "function_2", (void*)&my_function2, NULL); fcall_register(my_station.fcall, "function_3", (void*)&my_function3, NULL); fcall_register(my_station.fcall, "function_4", (void*)&my_function4, NULL); fcall_register(my_station.fcall, "function_5", (void*)&my_function5, NULL); fcall_register(my_station.fcall, "set_tonemask", (void*)&set_tonemask, NULL); fcall_register(my_station.fcall, "prepare_rx", (void*)&prepare_rx, NULL); fcall_register(my_station.fcall, "uninit_phy", (void*)&uninit_phy, NULL); fcall_register(my_station.fcall, "function_to_call", (void*)&function_to_call, NULL); probe_register(my_station.probe, "param_6", sizeof(unsigned int), &my_param6); probe_register(my_station.probe, "param_7", sizeof(unsigned int), &my_param7); probe_register(my_station.probe, "param_8", sizeof(bool), &my_param8); probe_register(my_station.probe, "param_9", sizeof(bool), &my_param9); probe_register(my_station.probe, "param_10", sizeof(unsigned short), &my_param10); probe_register(my_station.probe, "param_11", sizeof(unsigned long), &my_param11); probe_register(my_station.probe, "param_12", sizeof(unsigned long long), &my_param12); return 0; }